ATLAS Offline Software
Loading...
Searching...
No Matches
CachedGetAssocTruth.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
10
11 #include "CachedGetAssocTruth.h"
14
15namespace IDPVM {
16 void
18 m_cache.clear();
19 }
20
21 const std::string CachedGetAssocTruth::s_trackParticleLinkDecorationName("truthParticleLink");
22
23 void CachedGetAssocTruth::neededTrackParticleDecorations(std::vector<std::string> &decorations) {
24 if (std::find(decorations.begin(),decorations.end(),s_trackParticleLinkDecorationName) == decorations.end()) {
25 decorations.push_back(s_trackParticleLinkDecorationName);
26 }
27 }
30 if (not trackParticle) {
31 return nullptr;
32 }
33 auto pCache = m_cache.find(trackParticle);
34 if (pCache != m_cache.end()) {
35 return pCache->second;
36 }
37 using ElementTruthLink_t = ElementLink<xAOD::TruthParticleContainer>;
38 const xAOD::TruthParticle* result(nullptr);
40 // 0. is there any truth?
41 if (truthParticleLinkAcc.isAvailable(*trackParticle)) {
42 // 1. ..then get link
43 const ElementTruthLink_t ptruthContainer = truthParticleLinkAcc(*trackParticle);
44 if (ptruthContainer.isValid()) {
45 result = *ptruthContainer;
46 }
47 }
48 m_cache[trackParticle] = result;
49 return result;
50 }
51
54 return getTruth(trackParticle);
55 }
56
57}
Helper class to provide constant type-safe access to aux data.
const xAOD::TruthParticle * operator()(const xAOD::TrackParticle *trackParticle)
Get the associated truth particle, given a track particle.
std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > m_cache
private cache container; map or unordered_map could be used
static void neededTrackParticleDecorations(std::vector< std::string > &decorations)
static const std::string s_trackParticleLinkDecorationName
const xAOD::TruthParticle * getTruth(const xAOD::TrackParticle *const trackParticle)
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
Class to retrieve associated truth from a track, implementing a cached response.
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.