diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvElectronD0Tool.h b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvElectronD0Tool.h index c9706099ca91661dccb25d4a0c2c2ad833eb8bc2..1f4e8d0e3d9b951378d2c8106b0c8ec12b89934a 100644 --- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvElectronD0Tool.h +++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/LongLivedParticleDPDMaker/RpvElectronD0Tool.h @@ -16,6 +16,8 @@ // DerivationFramework includes #include "DerivationFrameworkInterfaces/IAugmentationTool.h" +#include "xAODEgamma/ElectronContainer.h" +#include "StoreGate/ReadHandleKey.h" namespace DerivationFramework { @@ -43,7 +45,7 @@ namespace DerivationFramework { virtual StatusCode addBranches() const; private: - std::string m_collName; + SG::ReadHandleKey<xAOD::ElectronContainer> m_collName { this, "ElectronContainerKey", "Electrons", ""}; std::string m_sgPrefix; }; diff --git a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx index 6f0fac01a517f90054312d11b5a4c09001ef4960..9d39324afe55bd9d4da1aa8245f56d3adbdd4a86 100644 --- a/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx +++ b/PhysicsAnalysis/SUSYPhys/LongLivedParticleDPDMaker/src/RpvElectronD0Tool.cxx @@ -10,7 +10,6 @@ // Writes result to SG for later selection by string parser #include "LongLivedParticleDPDMaker/RpvElectronD0Tool.h" -#include "xAODEgamma/ElectronContainer.h" #include <vector> #include <string> @@ -19,11 +18,9 @@ DerivationFramework::RpvElectronD0Tool::RpvElectronD0Tool( const std::string& t, const std::string& n, const IInterface* p ) : AthAlgTool(t,n,p), - m_collName("Electrons"), m_sgPrefix("") { declareInterface<DerivationFramework::IAugmentationTool>(this); - declareProperty("CollectionName", m_collName); declareProperty("SGPrefix", m_sgPrefix); } @@ -35,6 +32,7 @@ DerivationFramework::RpvElectronD0Tool::~RpvElectronD0Tool() { StatusCode DerivationFramework::RpvElectronD0Tool::initialize() { ATH_MSG_VERBOSE("initialize() ..."); + ATH_CHECK(m_collName.initialize()); return StatusCode::SUCCESS; } StatusCode DerivationFramework::RpvElectronD0Tool::finalize() @@ -48,14 +46,16 @@ StatusCode DerivationFramework::RpvElectronD0Tool::addBranches() const { // Retrieve data - const xAOD::ElectronContainer* electrons = evtStore()->retrieve< const xAOD::ElectronContainer >( m_collName ); - if( ! electrons ) { + SG::ReadHandle<xAOD::ElectronContainer> electrons(m_collName); + if( !electrons.isValid() ) { ATH_MSG_ERROR("Couldn't retrieve e-gamma container with key: " << m_collName); return StatusCode::FAILURE; } - // Make a vector for the cut results - std::vector<float>* d0vec = new std::vector<float>(); + // Write decision to SG for access by downstream algs + std::string sgKey(m_sgPrefix+"D0"); + SG::WriteHandle< std::vector<float> > d0vec(sgKey); + ATH_CHECK(d0vec.record(std::make_unique< std::vector<float> >())); // Loop over electrons, set decisions for (xAOD::ElectronContainer::const_iterator eIt = electrons->begin(); eIt!=electrons->end(); ++eIt) { @@ -67,16 +67,6 @@ StatusCode DerivationFramework::RpvElectronD0Tool::addBranches() const d0vec->push_back(d0); } - - // Write decision to SG for access by downstream algs - std::string sgKey(m_sgPrefix+"D0"); - - if (evtStore()->contains<std::vector<float> >(sgKey)) { - ATH_MSG_ERROR("Tool is attempting to write a StoreGate key " << sgKey << " which already exists. Please use a different key"); - delete d0vec; // avoid mem leak - return StatusCode::FAILURE; - } - CHECK(evtStore()->record(d0vec, sgKey)); return StatusCode::SUCCESS;