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 #ifndef GENERATORFILTERS_XAODTRUTHPARTICLESLIMMERPHOGEN_H
...@@ -29,11 +29,11 @@ public: ...@@ -29,11 +29,11 @@ public:
private: private:
/// The key for the output xAOD truth containers /// The key for the output xAOD truth containers
std::string m_xaodTruthParticleContainerNameGen; SG::WriteHandleKey<xAOD::TruthParticleContainer> m_xaodTruthParticleContainerNameGen{this, "xAODTruthParticleContainerNameGen", "TruthGen"};
std::string m_xaodTruthParticleContainerName; SG::ReadHandleKey<xAOD::TruthParticleContainer> m_xaodTruthParticleContainerName{this, "xAODTruthParticleContainerName", "TruthParticles"};
std::string m_xaodTruthEventContainerName; SG::ReadHandleKey<xAOD::TruthEventContainer> m_xaodTruthEventContainerName{this, "xAODTruthEventContainerName", "TruthEvents"};
ToolHandle<IMCTruthClassifier> m_classif; PublicToolHandle<IMCTruthClassifier> m_classif{this, "MCTruthClassifier", "MCTruthClassifier/DFCommonTruthClassifier"};
}; // class xAODTruthParticleSlimmerGen }; // class xAODTruthParticleSlimmerGen
#endif //GENERATORFILTERS_XAODTRUTHPARTICLESLIMMERPHOGEN_H #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" #include "AthenaKernel/errorcheck.h"
...@@ -23,54 +23,44 @@ ...@@ -23,54 +23,44 @@
xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc) xAODTruthParticleSlimmerGen::xAODTruthParticleSlimmerGen(const std::string &name, ISvcLocator *svcLoc)
: AthAlgorithm(name, 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() StatusCode xAODTruthParticleSlimmerGen::initialize()
{ {
ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName); ATH_CHECK(m_xaodTruthParticleContainerName.initialize());
ATH_MSG_INFO("xAOD output TruthParticleContainerGen name = " << m_xaodTruthParticleContainerNameGen); ATH_MSG_INFO("xAOD input TruthParticleContainer name = " << m_xaodTruthParticleContainerName.key());
ATH_CHECK(m_xaodTruthParticleContainerNameGen.initialize());
ATH_CHECK(m_classif.retrieve()); ATH_MSG_INFO("xAOD output TruthParticleContainerGen name = " << m_xaodTruthParticleContainerNameGen.key());
ATH_CHECK(m_xaodTruthEventContainerName.initialize());
ATH_CHECK(m_classif.retrieve());
return StatusCode::SUCCESS; return StatusCode::SUCCESS;
} }
StatusCode xAODTruthParticleSlimmerGen::execute() StatusCode xAODTruthParticleSlimmerGen::execute()
{ {
// If the containers already exists then assume that nothing needs to be done const EventContext& ctx = Gaudi::Hive::currentContext(); // As not re-entrant
if (evtStore()->contains<xAOD::TruthParticleContainer>(m_xaodTruthParticleContainerNameGen))
{
ATH_MSG_WARNING("xAOD Gen Truth Particles are already available in the event");
return StatusCode::SUCCESS;
}
// Create new output container // Create new output container
xAOD::TruthParticleContainer *xTruthParticleContainerGen = new xAOD::TruthParticleContainer(); SG::WriteHandle<xAOD::TruthParticleContainer> xTruthParticleContainerGen(m_xaodTruthParticleContainerNameGen, ctx);
CHECK(evtStore()->record(xTruthParticleContainerGen, m_xaodTruthParticleContainerNameGen)); ATH_CHECK(xTruthParticleContainerGen.record(std::make_unique<xAOD::TruthParticleContainer>(),
xAOD::TruthParticleAuxContainer *xTruthParticleAuxContainerGen = new xAOD::TruthParticleAuxContainer(); std::make_unique<xAOD::TruthParticleAuxContainer>()));
CHECK(evtStore()->record(xTruthParticleAuxContainerGen, m_xaodTruthParticleContainerNameGen + "Aux.")); ATH_MSG_INFO("Recorded TruthParticleContainerGen with key: " << m_xaodTruthParticleContainerNameGen.key());
xTruthParticleContainerGen->setStore(xTruthParticleAuxContainerGen);
ATH_MSG_INFO("Recorded TruthParticleContainerGen with key: " << m_xaodTruthParticleContainerNameGen);
// Retrieve full TruthParticle container // Retrieve full TruthParticle container
const xAOD::TruthParticleContainer *xTruthParticleContainer; SG::ReadHandle<xAOD::TruthParticleContainer> xTruthParticleContainer{m_xaodTruthParticleContainerName};
if (evtStore()->retrieve(xTruthParticleContainer, m_xaodTruthParticleContainerName).isFailure()) 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; return StatusCode::FAILURE;
} }
// Retrieve full TruthEventContainer container // Retrieve full TruthEventContainer container
const xAOD::TruthEventContainer *xTruthEventContainer=NULL; SG::ReadHandle<xAOD::TruthEventContainer> xTruthEventContainer{m_xaodTruthEventContainerName};
if (evtStore()->retrieve(xTruthEventContainer, m_xaodTruthEventContainerName).isFailure()) if ( !xTruthEventContainer.isValid() )
{ {
ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!"); ATH_MSG_ERROR("No TruthEvent collection with name " << m_xaodTruthEventContainerName << " found in StoreGate!");
return StatusCode::FAILURE; return StatusCode::FAILURE;
} }
// Loop over full TruthParticle container // Loop over full TruthParticle container
xAOD::TruthEventContainer::const_iterator itr; 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