From a8511f459d4fa6905a5b364f8774a8273dfd970a Mon Sep 17 00:00:00 2001 From: James Richard Catmore <james.catmore@cern.ch> Date: Fri, 3 Feb 2023 22:29:41 +0100 Subject: [PATCH] Two changes from the review: - dereferencing the WriteHandles and passing by pointer rather than reference - removing superfluous std::string conversions --- .../TruthDecayCollectionMaker.h | 8 ++--- .../src/TruthDecayCollectionMaker.cxx | 30 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthDecayCollectionMaker.h b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthDecayCollectionMaker.h index cb8d2a55a0b..045d9835274 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthDecayCollectionMaker.h +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/DerivationFrameworkMCTruth/TruthDecayCollectionMaker.h @@ -58,11 +58,11 @@ namespace DerivationFramework { std::string m_collectionName; //!< Output collection name stem int m_generations; //!< Number of generations after the particle in question to keep // Helper functions for building up the decay product collections - int addTruthParticle( const xAOD::TruthParticle& old_part, SG::WriteHandle<xAOD::TruthParticleContainer>& part_cont, - SG::WriteHandle<xAOD::TruthVertexContainer>& vert_cont, std::vector<int>& seen_particles, + int addTruthParticle( const xAOD::TruthParticle& old_part, xAOD::TruthParticleContainer* part_cont, + xAOD::TruthVertexContainer* vert_cont, std::vector<int>& seen_particles, const int generations=-1) const; - int addTruthVertex( const xAOD::TruthVertex& old_vert, SG::WriteHandle<xAOD::TruthParticleContainer>& part_cont, - SG::WriteHandle<xAOD::TruthVertexContainer>& vert_cont, std::vector<int>& seen_particles, + int addTruthVertex( const xAOD::TruthVertex& old_vert, xAOD::TruthParticleContainer* part_cont, + xAOD::TruthVertexContainer* vert_cont, std::vector<int>& seen_particles, const int generations=-1) const; bool id_ok( const xAOD::TruthParticle& part ) const; }; diff --git a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/src/TruthDecayCollectionMaker.cxx b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/src/TruthDecayCollectionMaker.cxx index 2ac95bd36eb..625f1c3302f 100644 --- a/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/src/TruthDecayCollectionMaker.cxx +++ b/PhysicsAnalysis/DerivationFramework/DerivationFrameworkMCTruth/src/TruthDecayCollectionMaker.cxx @@ -58,10 +58,10 @@ StatusCode DerivationFramework::TruthDecayCollectionMaker::initialize() ATH_MSG_FATAL("No base name provided for the new truth particle/vertex containers"); return StatusCode::FAILURE; } else {ATH_MSG_INFO("Base name for new truth particle/vertex containers: " << m_collectionName );} - m_outputParticlesKey = std::string(m_collectionName) + "Particles"; + m_outputParticlesKey = m_collectionName + "Particles"; ATH_CHECK(m_outputParticlesKey.initialize()); ATH_MSG_INFO("New truth particles container key: " << m_outputParticlesKey.key() ); - m_outputVerticesKey = std::string(m_collectionName) + "Vertices"; + m_outputVerticesKey = m_collectionName + "Vertices"; ATH_CHECK(m_outputVerticesKey.initialize()); ATH_MSG_INFO("New truth vertices container key: " << m_outputVerticesKey.key() ); @@ -95,15 +95,15 @@ StatusCode DerivationFramework::TruthDecayCollectionMaker::addBranches() const return StatusCode::FAILURE; } - // Create the new particle containers - SG::WriteHandle<xAOD::TruthParticleContainer> newParticleCollection(m_outputParticlesKey, ctx); - ATH_CHECK(newParticleCollection.record(std::make_unique<xAOD::TruthParticleContainer>(), - std::make_unique<xAOD::TruthParticleAuxContainer>())); + // Create the new particle containers and WriteHandles + SG::WriteHandle<xAOD::TruthParticleContainer> newParticlesWriteHandle(m_outputParticlesKey, ctx); + ATH_CHECK(newParticlesWriteHandle.record(std::make_unique<xAOD::TruthParticleContainer>(), + std::make_unique<xAOD::TruthParticleAuxContainer>())); ATH_MSG_DEBUG( "Recorded new TruthParticleContainer with key: " << (m_outputParticlesKey.key())); - // Create the new vertex containers - SG::WriteHandle<xAOD::TruthVertexContainer> newVertexCollection(m_outputVerticesKey, ctx); - ATH_CHECK(newVertexCollection.record(std::make_unique<xAOD::TruthVertexContainer>(), - std::make_unique<xAOD::TruthVertexAuxContainer>())); + // Create the new vertex containers and WriteHandles + SG::WriteHandle<xAOD::TruthVertexContainer> newVerticesWriteHandle(m_outputVerticesKey, ctx); + ATH_CHECK(newVerticesWriteHandle.record(std::make_unique<xAOD::TruthVertexContainer>(), + std::make_unique<xAOD::TruthVertexAuxContainer>())); ATH_MSG_DEBUG( "Recorded new TruthVertexContainer with key: " << (m_outputVerticesKey.key())); // List of barcodes for particles in our collection already. Because of the way we recurse, @@ -114,15 +114,15 @@ StatusCode DerivationFramework::TruthDecayCollectionMaker::addBranches() const for (const auto * part : *truthParticles){ // If this passes my cuts, keep it if (id_ok(*part)){ - addTruthParticle( *part, newParticleCollection, newVertexCollection, seen_particles , m_generations ); + addTruthParticle( *part, newParticlesWriteHandle.ptr(), newVerticesWriteHandle.ptr(), seen_particles , m_generations ); } } // Loop over the initial truth particle collection return StatusCode::SUCCESS; } int DerivationFramework::TruthDecayCollectionMaker::addTruthParticle( const xAOD::TruthParticle& old_part, - SG::WriteHandle<xAOD::TruthParticleContainer>& part_cont, - SG::WriteHandle<xAOD::TruthVertexContainer>& vert_cont, + xAOD::TruthParticleContainer* part_cont, + xAOD::TruthVertexContainer* vert_cont, std::vector<int>& seen_particles, const int generations) const { // See if we've seen it - note, could also do this with a unary function on the container itself @@ -186,8 +186,8 @@ int DerivationFramework::TruthDecayCollectionMaker::addTruthParticle( const xAOD } int DerivationFramework::TruthDecayCollectionMaker::addTruthVertex( const xAOD::TruthVertex& old_vert, - SG::WriteHandle<xAOD::TruthParticleContainer>& part_cont, - SG::WriteHandle<xAOD::TruthVertexContainer>& vert_cont, + xAOD::TruthParticleContainer* part_cont, + xAOD::TruthVertexContainer* vert_cont, std::vector<int>& seen_particles, const int generations) const { // Make a new vertex and add it to the container -- GitLab