Skip to content
Snippets Groups Projects
Commit 96e26c8b authored by John Chapman's avatar John Chapman
Browse files

xAODTruthParticleSlimmerGen: migration to Read/WriteHandleKeys

parent 12c11cf9
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/
#ifndef GENERATORFILTERS_XAODTRUTHPARTICLESLIMMERPHOGEN_H
......@@ -29,11 +29,11 @@ public:
private:
/// The key for the output xAOD truth containers
std::string m_xaodTruthParticleContainerNameGen;
std::string m_xaodTruthParticleContainerName;
std::string m_xaodTruthEventContainerName;
SG::WriteHandleKey<xAOD::TruthParticleContainer> m_xaodTruthParticleContainerNameGen{this, "xAODTruthParticleContainerNameGen", "TruthGen"};
SG::ReadHandleKey<xAOD::TruthParticleContainer> m_xaodTruthParticleContainerName{this, "xAODTruthParticleContainerName", "TruthParticles"};
SG::ReadHandleKey<xAOD::TruthEventContainer> m_xaodTruthEventContainerName{this, "xAODTruthEventContainerName", "TruthEvents"};
ToolHandle<IMCTruthClassifier> m_classif;
PublicToolHandle<IMCTruthClassifier> m_classif{this, "MCTruthClassifier", "MCTruthClassifier/DFCommonTruthClassifier"};
}; // class xAODTruthParticleSlimmerGen
#endif //GENERATORFILTERS_XAODTRUTHPARTICLESLIMMERPHOGEN_H
/*
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
*/
#include "AthenaKernel/errorcheck.h"
......@@ -23,54 +23,44 @@
xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc)
: AthAlgorithm(name, svcLoc)
, m_classif("MCTruthClassifier/DFCommonTruthClassifier")
{
declareProperty("xAODTruthParticleContainerName", m_xaodTruthParticleContainerName = "TruthParticles");
declareProperty("xAODTruthParticleContainerNameGen", m_xaodTruthParticleContainerNameGen = "TruthGen");
declareProperty("xAODTruthEventContainerName", m_xaodTruthEventContainerName = "TruthEvents");
}
StatusCode xAODTruthParticleSlimmerGen::initialize()
{
ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName);
ATH_MSG_INFO("xAOD output TruthParticleContainerGen name = " << m_xaodTruthParticleContainerNameGen);
ATH_CHECK(m_classif.retrieve());
ATH_CHECK(m_xaodTruthParticleContainerName.initialize());
ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName.key());
ATH_CHECK(m_xaodTruthParticleContainerNameGen.initialize());
ATH_MSG_INFO("xAOD output TruthParticleContainerGen name = " << m_xaodTruthParticleContainerNameGen.key());
ATH_CHECK(m_xaodTruthEventContainerName.initialize());
ATH_CHECK(m_classif.retrieve());
return StatusCode::SUCCESS;
}
StatusCode xAODTruthParticleSlimmerGen::execute()
{
// If the containers already exists then assume that nothing needs to be done
if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNameGen))
{
ATH_MSG_WARNING("xAOD Gen Truth Particles are already available in the event");
return StatusCode::SUCCESS;
}
const EventContext& ctx = Gaudi::Hive::currentContext(); // As not re-entrant
// Create new output container
xAOD::TruthParticleContainer *xTruthParticleContainerGen = new xAOD::TruthParticleContainer();
CHECK(evtStore()->record(xTruthParticleContainerGen, m_xaodTruthParticleContainerNameGen));
xAOD::TruthParticleAuxContainer *xTruthParticleAuxContainerGen = new xAOD::TruthParticleAuxContainer();
CHECK(evtStore()->record(xTruthParticleAuxContainerGen, m_xaodTruthParticleContainerNameGen + "Aux."));
xTruthParticleContainerGen->setStore(xTruthParticleAuxContainerGen);
ATH_MSG_INFO("Recorded TruthParticleContainerGen with key: " << m_xaodTruthParticleContainerNameGen);
SG::WriteHandle<xAOD::TruthParticleContainer> xTruthParticleContainerGen(m_xaodTruthParticleContainerNameGen, ctx);
ATH_CHECK(xTruthParticleContainerGen.record(std::make_unique<xAOD::TruthParticleContainer>(),
std::make_unique<xAOD::TruthParticleAuxContainer>()));
ATH_MSG_INFO("Recorded TruthParticleContainerGen with key: " << m_xaodTruthParticleContainerNameGen.key());
// Retrieve full TruthParticle container
const xAOD::TruthParticleContainer *xTruthParticleContainer;
if (evtStore()->retrieve(xTruthParticleContainer, m_xaodTruthParticleContainerName).isFailure())
SG::ReadHandle<xAOD::TruthParticleContainer> xTruthParticleContainer{m_xaodTruthParticleContainerName};
if ( !xTruthParticleContainer.isValid() )
{
ATH_MSG_ERROR("No TruthParticle collection with name " << m_xaodTruthParticleContainerName << " found in StoreGate!");
ATH_MSG_ERROR("No TruthParticle collection with name " << m_xaodTruthParticleContainerName.key() << " found in StoreGate!");
return StatusCode::FAILURE;
}
// Retrieve full TruthEventContainer container
const xAOD::TruthEventContainer *xTruthEventContainer=NULL;
if (evtStore()->retrieve(xTruthEventContainer, m_xaodTruthEventContainerName).isFailure())
{
SG::ReadHandle<xAOD::TruthEventContainer> xTruthEventContainer{m_xaodTruthEventContainerName};
if ( !xTruthEventContainer.isValid() )
{
ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!");
return StatusCode::FAILURE;
}
}
// Loop over full TruthParticle container
xAOD::TruthEventContainer::const_iterator itr;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment