diff --git a/Generators/GeneratorFilters/GeneratorFilters/xAODTruthParticleSlimmerGen.h b/Generators/GeneratorFilters/GeneratorFilters/xAODTruthParticleSlimmerGen.h index f40c80692a4c1a4ca1f056ac53fb28a6208952d9..007fbe16cf4e5a1868c2f73e611c245e2f81bcf6 100644 --- a/Generators/GeneratorFilters/GeneratorFilters/xAODTruthParticleSlimmerGen.h +++ b/Generators/GeneratorFilters/GeneratorFilters/xAODTruthParticleSlimmerGen.h @@ -1,5 +1,5 @@ /* - 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 diff --git a/Generators/GeneratorFilters/src/xAODTruthParticleSlimmerGen.cxx b/Generators/GeneratorFilters/src/xAODTruthParticleSlimmerGen.cxx index 110b57505a8a734a61fc5809108181a4367ff06e..4c7afd5777e2f023ae034ef26d2171da70e96a60 100644 --- a/Generators/GeneratorFilters/src/xAODTruthParticleSlimmerGen.cxx +++ b/Generators/GeneratorFilters/src/xAODTruthParticleSlimmerGen.cxx @@ -1,5 +1,5 @@ /* - 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;