Skip to content
Snippets Groups Projects
Commit 7ce57cd8 authored by Adam Edward Barton's avatar Adam Edward Barton
Browse files

Merge branch 'master-memory-leak-ParticleJetTools' into 'master'

BTagging + ParticleJetTools: Avoid using raw pointers in ParticleToJetAssociator

See merge request atlas/athena!38448
parents 9ba7d9fb e9abf9f0
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,7 @@ comments: A. Wildauer: 27.01.2005 rewritten into an AlgTool ...@@ -25,6 +25,7 @@ comments: A. Wildauer: 27.01.2005 rewritten into an AlgTool
#include "xAODJet/Jet.h" #include "xAODJet/Jet.h"
#include "xAODJet/JetContainer.h" #include "xAODJet/JetContainer.h"
#include <memory>
#include <vector> #include <vector>
#include <list> #include <list>
#include <string> #include <string>
...@@ -70,12 +71,12 @@ class ParticleToJetAssociator : public asg::AsgTool { ...@@ -70,12 +71,12 @@ class ParticleToJetAssociator : public asg::AsgTool {
// For the new way // For the new way
// FF: return the vector of associations // FF: return the vector of associations
template<typename ConstituentType, typename coll> template<typename ConstituentType, typename coll>
std::vector<ConstituentType*> std::vector< std::unique_ptr<ConstituentType> >
associateParticlesToJets(jetcollection_t* theJets, associateParticlesToJets(jetcollection_t* theJets,
const coll* particleContainer, const coll* particleContainer,
const std::string& constituentName) const; const std::string& constituentName) const;
template<typename ConstituentType, typename coll> template<typename ConstituentType, typename coll>
std::vector<ConstituentType*> std::vector< std::unique_ptr<ConstituentType> >
associateParticlesToJets(const xAOD::JetContainer* theJets, associateParticlesToJets(const xAOD::JetContainer* theJets,
const coll* particleContainer, const coll* particleContainer,
const std::string& constituentName) const; const std::string& constituentName) const;
...@@ -176,19 +177,19 @@ class ParticleToJetAssociator : public asg::AsgTool { ...@@ -176,19 +177,19 @@ class ParticleToJetAssociator : public asg::AsgTool {
// For the new way // For the new way
template<typename ConstituentType, typename coll> template<typename ConstituentType, typename coll>
inline std::vector<ConstituentType*> inline std::vector< std::unique_ptr<ConstituentType> >
ParticleToJetAssociator::associateParticlesToJets(jetcollection_t* theJets, ParticleToJetAssociator::associateParticlesToJets(jetcollection_t* theJets,
const coll* particleContainer, const coll* particleContainer,
const std::string& constituentName) const { const std::string& constituentName) const {
std::vector<ConstituentType*> vecTrackConst; std::vector< std::unique_ptr<ConstituentType> > vecTrackConst;
ATH_MSG_VERBOSE("Number of Jets : " << theJets->size()); ATH_MSG_VERBOSE("Number of Jets : " << theJets->size());
if (theJets->size()<1) return vecTrackConst; if (theJets->size()<1) return vecTrackConst;
ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size()); ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size());
for (jetcollection_t::iterator itr = theJets->begin(); itr != theJets->end(); ++itr) { for (jetcollection_t::iterator itr = theJets->begin(); itr != theJets->end(); ++itr) {
// NameType name(constituentName); // NameType name(constituentName);
vecTrackConst.push_back(new ConstituentType); vecTrackConst.push_back( std::make_unique<ConstituentType>() );
} }
int index(0); int index(0);
...@@ -275,19 +276,19 @@ template<typename ConstituentType, typename coll> ...@@ -275,19 +276,19 @@ template<typename ConstituentType, typename coll>
} }
template<typename ConstituentType, typename coll> template<typename ConstituentType, typename coll>
inline std::vector<ConstituentType*> inline std::vector< std::unique_ptr<ConstituentType> >
ParticleToJetAssociator::associateParticlesToJets(const xAOD::JetContainer * theJets, ParticleToJetAssociator::associateParticlesToJets(const xAOD::JetContainer * theJets,
const coll* particleContainer, const coll* particleContainer,
const std::string& constituentName) const { const std::string& constituentName) const {
std::vector<ConstituentType*> vecTrackConst; std::vector< std::unique_ptr<ConstituentType> > vecTrackConst;
ATH_MSG_VERBOSE("Number of Jets : " << theJets->size()); ATH_MSG_VERBOSE("Number of Jets : " << theJets->size());
if (theJets->size()<1) return vecTrackConst; if (theJets->size()<1) return vecTrackConst;
ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size()); ATH_MSG_VERBOSE("Number of Particles of Type " << constituentName << " : " << particleContainer->size());
for (xAOD::JetContainer::const_iterator itr = theJets->begin(); itr != theJets->end(); ++itr) { for (xAOD::JetContainer::const_iterator itr = theJets->begin(); itr != theJets->end(); ++itr) {
// NameType name(constituentName); // NameType name(constituentName);
vecTrackConst.push_back(new ConstituentType); vecTrackConst.push_back( std::make_unique<ConstituentType>() );
} }
int index(0); int index(0);
......
...@@ -156,7 +156,7 @@ namespace Analysis { ...@@ -156,7 +156,7 @@ namespace Analysis {
ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << tpContainer->size()); ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << tpContainer->size());
// compute the associations // compute the associations
std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs =
(*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( theJets, tpContainer, *tAssocNameIter ); (*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( theJets, tpContainer, *tAssocNameIter );
// then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist // then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist
...@@ -184,10 +184,6 @@ namespace Analysis { ...@@ -184,10 +184,6 @@ namespace Analysis {
++i; ++i;
} }
ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter); ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter);
//delete pointer created in associateParticlesToJets
for (i=0; i < assocs.size(); i++) {
delete assocs[i];
}
++tNameIter; ++tNameIter;
++tAssocNameIter; ++tAssocNameIter;
} }
...@@ -208,7 +204,7 @@ namespace Analysis { ...@@ -208,7 +204,7 @@ namespace Analysis {
} }
ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << muonContainer->size()); ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << muonContainer->size());
std::vector<std::vector<const xAOD::Muon*>*> assocs = std::vector< std::unique_ptr< std::vector<const xAOD::Muon*> > > assocs =
(*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( theJets, muonContainer, *muAssocNameIter ); (*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( theJets, muonContainer, *muAssocNameIter );
// then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist // then store them in the BTagging objects. Note that for this to work, the ElementLink from Jet to BTagging object must exist
...@@ -225,10 +221,6 @@ namespace Analysis { ...@@ -225,10 +221,6 @@ namespace Analysis {
++i; ++i;
} }
ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter); ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter);
//delete pointer created in associateParticlesToJets
for (i=0; i < assocs.size(); i++) {
delete assocs[i];
}
++muNameIter; ++muNameIter;
++muAssocNameIter; ++muAssocNameIter;
} }
...@@ -281,7 +273,7 @@ namespace Analysis { ...@@ -281,7 +273,7 @@ namespace Analysis {
ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << (*h_TrackContainerName).size()); ATH_MSG_VERBOSE("#BTAG# Number of TrackParticles in event: " << (*h_TrackContainerName).size());
// compute the associations // compute the associations
std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs =
(*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( jetContainer, &(*h_TrackContainerName), *tAssocNameIter ); (*tAssocIter)->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( jetContainer, &(*h_TrackContainerName), *tAssocNameIter );
// then store them in the BTagging objects. // then store them in the BTagging objects.
...@@ -297,10 +289,6 @@ namespace Analysis { ...@@ -297,10 +289,6 @@ namespace Analysis {
++i; ++i;
} }
ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter); ATH_MSG_VERBOSE("#BTAG# stored track-to jet associations under name " << *tAssocNameIter);
//delete pointer created in associateParticlesToJets
for (i=0; i < assocs.size(); i++) {
delete assocs[i];
}
++tAssocNameIter; ++tAssocNameIter;
} }
...@@ -329,7 +317,7 @@ namespace Analysis { ...@@ -329,7 +317,7 @@ namespace Analysis {
} }
ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << (*h_MuonContainerName).size()); ATH_MSG_DEBUG("#BTAG# Number of Muons in event: " << (*h_MuonContainerName).size());
std::vector<std::vector<const xAOD::Muon*>*> assocs = std::vector< std::unique_ptr< std::vector<const xAOD::Muon*> > > assocs =
(*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( jetContainer, &(*h_MuonContainerName), *muAssocNameIter ); (*muAssocIter)->associateParticlesToJets<std::vector<const xAOD::Muon*>, xAOD::MuonContainer>( jetContainer, &(*h_MuonContainerName), *muAssocNameIter );
// then store them in the BTagging objects. // then store them in the BTagging objects.
...@@ -345,10 +333,6 @@ namespace Analysis { ...@@ -345,10 +333,6 @@ namespace Analysis {
++i; ++i;
} }
ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter); ATH_MSG_VERBOSE("#BTAG# stored muon-to-jet associations under name " << *muAssocNameIter);
//delete pointer created in associateParticlesToJets
for (i=0; i < assocs.size(); i++) {
delete assocs[i];
}
++muNameIter; ++muNameIter;
++muAssocNameIter; ++muAssocNameIter;
} }
......
...@@ -69,7 +69,7 @@ namespace Analysis { ...@@ -69,7 +69,7 @@ namespace Analysis {
if (m_release == "21") { if (m_release == "21") {
// compute the associations // compute the associations
std::vector<std::vector<const xAOD::TrackParticle*>*> assocs = std::vector< std::unique_ptr< std::vector<const xAOD::TrackParticle*> > > assocs =
m_TrackToJetAssociator->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( h_JetCollectionName.ptr(), h_TrackParticleContainerName.ptr(), "'BTagTrackToJetAssociator ala 21" ); m_TrackToJetAssociator->associateParticlesToJets<std::vector<const xAOD::TrackParticle*>, xAOD::TrackParticleContainer>( h_JetCollectionName.ptr(), h_TrackParticleContainerName.ptr(), "'BTagTrackToJetAssociator ala 21" );
unsigned int i = 0; unsigned int i = 0;
......
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