ATLAS Offline Software
Loading...
Searching...
No Matches
IDPVM::CachedGetAssocTruth Class Reference

#include <CachedGetAssocTruth.h>

Collaboration diagram for IDPVM::CachedGetAssocTruth:

Public Member Functions

 CachedGetAssocTruth ()=default
CachedGetAssocTruthoperator= (CachedGetAssocTruth &&)=default
 CachedGetAssocTruth (CachedGetAssocTruth &&)=default
 ~CachedGetAssocTruth ()=default
CachedGetAssocTruthoperator= (const CachedGetAssocTruth &)=delete
 copy and assignment are not possible
 CachedGetAssocTruth (const CachedGetAssocTruth &)=delete
void clear ()
 clear the cache
const xAOD::TruthParticleoperator() (const xAOD::TrackParticle *trackParticle)
 Get the associated truth particle, given a track particle.
const xAOD::TruthParticlegetTruth (const xAOD::TrackParticle *const trackParticle)

Static Public Member Functions

static void neededTrackParticleDecorations (std::vector< std::string > &decorations)

Private Attributes

std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > m_cache
 private cache container; map or unordered_map could be used

Static Private Attributes

static const std::string s_trackParticleLinkDecorationName

Detailed Description

Definition at line 21 of file CachedGetAssocTruth.h.

Constructor & Destructor Documentation

◆ CachedGetAssocTruth() [1/3]

IDPVM::CachedGetAssocTruth::CachedGetAssocTruth ( )
default

◆ CachedGetAssocTruth() [2/3]

IDPVM::CachedGetAssocTruth::CachedGetAssocTruth ( CachedGetAssocTruth && )
default

◆ ~CachedGetAssocTruth()

IDPVM::CachedGetAssocTruth::~CachedGetAssocTruth ( )
default

◆ CachedGetAssocTruth() [3/3]

IDPVM::CachedGetAssocTruth::CachedGetAssocTruth ( const CachedGetAssocTruth & )
delete

Member Function Documentation

◆ clear()

void IDPVM::CachedGetAssocTruth::clear ( )

clear the cache

Definition at line 17 of file CachedGetAssocTruth.cxx.

17 {
18 m_cache.clear();
19 }
std::unordered_map< const xAOD::TrackParticle *, const xAOD::TruthParticle * > m_cache
private cache container; map or unordered_map could be used

◆ getTruth()

const xAOD::TruthParticle * IDPVM::CachedGetAssocTruth::getTruth ( const xAOD::TrackParticle *const trackParticle)

Definition at line 29 of file CachedGetAssocTruth.cxx.

29 {
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);
39 static const SG::ConstAccessor<ElementTruthLink_t> truthParticleLinkAcc(s_trackParticleLinkDecorationName);
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 }
static const std::string s_trackParticleLinkDecorationName
TruthParticle_v1 TruthParticle
Typedef to implementation.

◆ neededTrackParticleDecorations()

void IDPVM::CachedGetAssocTruth::neededTrackParticleDecorations ( std::vector< std::string > & decorations)
static

Definition at line 23 of file CachedGetAssocTruth.cxx.

23 {
24 if (std::find(decorations.begin(),decorations.end(),s_trackParticleLinkDecorationName) == decorations.end()) {
25 decorations.push_back(s_trackParticleLinkDecorationName);
26 }
27 }

◆ operator()()

const xAOD::TruthParticle * IDPVM::CachedGetAssocTruth::operator() ( const xAOD::TrackParticle * trackParticle)

Get the associated truth particle, given a track particle.

Definition at line 53 of file CachedGetAssocTruth.cxx.

53 {
54 return getTruth(trackParticle);
55 }
const xAOD::TruthParticle * getTruth(const xAOD::TrackParticle *const trackParticle)

◆ operator=() [1/2]

CachedGetAssocTruth & IDPVM::CachedGetAssocTruth::operator= ( CachedGetAssocTruth && )
default

◆ operator=() [2/2]

CachedGetAssocTruth & IDPVM::CachedGetAssocTruth::operator= ( const CachedGetAssocTruth & )
delete

copy and assignment are not possible

Member Data Documentation

◆ m_cache

std::unordered_map<const xAOD::TrackParticle*, const xAOD::TruthParticle*> IDPVM::CachedGetAssocTruth::m_cache
private

private cache container; map or unordered_map could be used

Definition at line 39 of file CachedGetAssocTruth.h.

◆ s_trackParticleLinkDecorationName

const std::string IDPVM::CachedGetAssocTruth::s_trackParticleLinkDecorationName
staticprivate

Definition at line 40 of file CachedGetAssocTruth.h.


The documentation for this class was generated from the following files: