ATLAS Offline Software
Loading...
Searching...
No Matches
LegacyBarcodeSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6// framework include
8
9
11Barcode::LegacyBarcodeSvc::LegacyBarcodeSvc(const std::string& name,ISvcLocator* svc) :
12 base_class(name,svc),
13 m_firstVertex(-HepMC::SIM_BARCODE_THRESHOLD-1),
15 m_firstSecondary(HepMC::SIM_BARCODE_THRESHOLD+1),
17{
18}
19
20
23{
24 ATH_MSG_VERBOSE ("initialize() ...");
25 ATH_MSG_DEBUG( "LegacyBarcodeSvc start of initialize in thread ID: " << std::this_thread::get_id() );
26
28
29 ATH_MSG_VERBOSE ("initialize() successful");
30 return StatusCode::SUCCESS;
31}
32
33
34StatusCode Barcode::LegacyBarcodeSvc::initializeBarcodes(int largestGeneratedParticleBC, int largestGeneratedVertexBC) {
35 static std::mutex barcodeMutex;
36 std::lock_guard<std::mutex> barcodeLock(barcodeMutex);
37 ATH_MSG_DEBUG( name() << "::initializeBarcodes()" );
38
39 // look for pair containing barcode info using the thread ID
40 // if it doesn't exist, construct one and insert it.
41 const auto tid = std::this_thread::get_id();
42 auto bcPair = m_bcThreadMap.find(tid);
43 if ( bcPair == m_bcThreadMap.end() ) {
44 auto result = m_bcThreadMap.insert( std::make_pair( tid, BarcodeInfo(-HepMC::SIM_BARCODE_THRESHOLD, HepMC::SIM_BARCODE_THRESHOLD, largestGeneratedVertexBC, largestGeneratedParticleBC) ) );
45 if (result.second) {
46 ATH_MSG_DEBUG( "initializeBarcodes: initialized new barcodes for thread ID " << tid );
47 ATH_CHECK( this->resetBarcodes(largestGeneratedParticleBC, largestGeneratedVertexBC) );
48 ATH_MSG_DEBUG( "initializeBarcodes: reset new barcodes for thread ID " << tid );
49 } else {
50 ATH_MSG_ERROR( "initializeBarcodes: failed to initialize new barcode for thread ID " << tid );
51 }
52 } else {
53 ATH_MSG_DEBUG( "initializeBarcodes: barcodes for this thread ID found, did not construct new" );
54 ATH_CHECK( this->resetBarcodes(largestGeneratedParticleBC, largestGeneratedVertexBC) );
55 ATH_MSG_DEBUG( "initializeBarcodes: reset existing barcodes for thread ID " << tid );
56 }
57 return StatusCode::SUCCESS;
58}
59
60
62 const auto tid = std::this_thread::get_id();
63 auto bcPair = m_bcThreadMap.find(tid);
64 if ( bcPair == m_bcThreadMap.end() ) {
65 ATH_MSG_WARNING( "getBarcodeInfo: failed to find BarcodeInfo for thread ID " << tid << ", created a new one." );
67 auto result = m_bcThreadMap.insert( std::make_pair( tid, barcodeInfo ) );
68 if (result.second) {
69 auto bcPair = m_bcThreadMap.find(tid);
70 return bcPair->second;
71 }
72 ATH_MSG_ERROR ( "getBarcodeInfo: could not add a the new BarcodeInfo object to the map!" );
73 return m_bcThreadMap.begin()->second;
74 }
75 return bcPair->second;
76}
77
78
81{
84 // a naive underflog checking based on the fact that vertex
85 // barcodes should never be positive
87 {
88 ATH_MSG_WARNING("LegacyBarcodeSvc::newSimulationVertex()"
89 << " will return a vertex barcode greater than "
91 << bc.currentSimulationVertex << ". Reset to "
94 }
95
97}
98
99
102{
105 // a naive overflow checking based on the fact that particle
106 // barcodes should never be negative
108 {
109 ATH_MSG_WARNING("LegacyBarcodeSvc::newSecondaryParticle()"
110 << " will return a particle barcode of less than "
112 << bc.currentSecondaryParticle << ". Reset to "
114
116 }
117
118 return bc.currentSecondaryParticle;
119}
120
121
124{
127 // a naive underflog checking based on the fact that vertex
128 // barcodes should never be positive
129 if ( bc.currentGeneratedVertex > 0) {
130 ATH_MSG_WARNING("LegacyBarcodeSvc::newGeneratedVertex()"
131 << " will return a vertex barcode greater than 0: "
132 << bc.currentGeneratedVertex << ". Reset to "
134
136 }
138 ATH_MSG_ERROR("LegacyBarcodeSvc::newGeneratedVertex()"
139 << " will return a vertex barcode below "
141 << bc.currentGeneratedVertex << ". Expect clashes with simulation vertices.");
142 }
143
144 return bc.currentGeneratedVertex;
145}
146
147
150{
153 // a naive overflow checking based on the fact that particle
154 // barcodes should never be negative
155 if (bc.currentGeneratedParticle < 0)
156 {
157 ATH_MSG_WARNING("LegacyBarcodeSvc::newGeneratedParticle()"
158 << " will return a particle barcode of less than 0: "
159 << bc.currentGeneratedParticle << ". Reset to "
161
163 }
165 ATH_MSG_ERROR("LegacyBarcodeSvc::newGeneratedParticle()"
166 << " will return a particle barcode below "
168 << bc.currentGeneratedParticle << ". Expect clashes with simulation particles.");
169 }
170
171 return bc.currentGeneratedParticle;
172}
173
174
176 ATH_MSG_DEBUG( "registering largest generated particle barcode" );
177 BarcodeInfo& barcodeInfo = getBarcodeInfo();
178 barcodeInfo.currentGeneratedParticle = bc;
179}
180
181
183 ATH_MSG_DEBUG( "registering largest generated particle barcode" );
184 BarcodeInfo& barcodeInfo = getBarcodeInfo();
185 barcodeInfo.currentGeneratedVertex = bc;
186}
187
188
191
192
195
196
201
202
207
208
209StatusCode Barcode::LegacyBarcodeSvc::resetBarcodes(int largestGeneratedParticleBC, int largestGeneratedVertexBC)
210{
211 ATH_MSG_DEBUG( "resetBarcodes: resetting barcodes" );
215 bc.currentGeneratedVertex = largestGeneratedVertexBC;
216 bc.currentGeneratedParticle = largestGeneratedParticleBC;
217
218 return StatusCode::SUCCESS;
219}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
virtual void registerLargestGeneratedParticleBC(int bc) override
Inform the BarcodeSvc about the largest particle and vertex Barcodes in the event input.
virtual int secondaryParticleBcOffset() const override
Return the secondary particle and vertex offsets.
virtual StatusCode initialize() override
Athena algorithm's interface methods.
int m_firstVertex
barcode information used for GenVertices
virtual void registerLargestGeneratedVtxBC(int bc) override
virtual int newGeneratedVertex() override
Generate a new unique vertex barcode below the simulation offset.
virtual StatusCode resetBarcodes(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Reset barcodes.
LegacyBarcodeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
virtual int newSecondaryParticle(int) override
Generate a new unique barcode for a secondary particle above the simulation offset.
virtual StatusCode initializeBarcodes(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Construct and insert a new set of barcode members.
virtual int secondaryVertexBcOffset() const override
Return the secondary vertex offset.
virtual void registerLargestSimulationVtxBC(int bc) override
int m_firstSecondary
barcode information used for secondary GenParticles
virtual void registerLargestSecondaryParticleBC(int bc) override
virtual int newSimulationVertex() override
Generate a new unique vertex barcode above the simulation offset.
LegacyBarcodeSvcThreadMap_t m_bcThreadMap
virtual int newGeneratedParticle(int) override
Generate a new unique particle barcode below the simulation offset (for particles from pre-defined de...
constexpr int UNDEFINED_ID
constexpr int SIM_BARCODE_THRESHOLD
Constant defining the barcode threshold for simulated particles, eg. can be used to separate generato...