ATLAS Offline Software
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 
11 Barcode::LegacyBarcodeSvc::LegacyBarcodeSvc(const std::string& name,ISvcLocator* svc) :
12  base_class(name,svc),
13  m_firstVertex(-HepMC::SIM_BARCODE_THRESHOLD-1),
14  m_vertexIncrement(-1),
15  m_firstSecondary(HepMC::SIM_BARCODE_THRESHOLD+1),
16  m_particleIncrement(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 
27  ATH_CHECK( this->initializeBarcodes() );
28 
29  ATH_MSG_VERBOSE ("initialize() successful");
30  return StatusCode::SUCCESS;
31 }
32 
33 
34 StatusCode 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 {
82  BarcodeInfo& bc = getBarcodeInfo();
83  bc.currentSimulationVertex += m_vertexIncrement;
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 
96  return bc.currentSimulationVertex;
97 }
98 
99 
102 {
103  BarcodeInfo& bc = getBarcodeInfo();
104  bc.currentSecondaryParticle += m_particleIncrement;
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 {
125  BarcodeInfo& bc = getBarcodeInfo();
126  bc.currentGeneratedVertex += m_vertexIncrement;
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 "
140  << -HepMC::SIM_BARCODE_THRESHOLD << ": "
141  << bc.currentGeneratedVertex << ". Expect clashes with simulation vertices.");
142  }
143 
144  return bc.currentGeneratedVertex;
145 }
146 
147 
150 {
151  BarcodeInfo& bc = getBarcodeInfo();
152  bc.currentGeneratedParticle += m_particleIncrement;
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 "
167  << -HepMC::SIM_BARCODE_THRESHOLD << ": "
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 
190 }
191 
192 
194 }
195 
196 
199  return m_firstSecondary;
200 }
201 
202 
205  return m_firstVertex;
206 }
207 
208 
209 StatusCode Barcode::LegacyBarcodeSvc::resetBarcodes(int largestGeneratedParticleBC, int largestGeneratedVertexBC)
210 {
211  ATH_MSG_DEBUG( "resetBarcodes: resetting barcodes" );
212  BarcodeInfo& bc = getBarcodeInfo();
213  bc.currentSimulationVertex = m_firstVertex - m_vertexIncrement;
214  bc.currentSecondaryParticle = m_firstSecondary - m_particleIncrement;
215  bc.currentGeneratedVertex = largestGeneratedVertexBC;
216  bc.currentGeneratedParticle = largestGeneratedParticleBC;
217 
218  return StatusCode::SUCCESS;
219 }
HepMC::SIM_BARCODE_THRESHOLD
constexpr int SIM_BARCODE_THRESHOLD
Constant defining the barcode threshold for simulated particles, eg. can be used to separate generato...
Definition: MagicNumbers.h:29
Barcode::LegacyBarcodeSvc::registerLargestSecondaryParticleBC
virtual void registerLargestSecondaryParticleBC(int bc) override
Definition: LegacyBarcodeSvc.cxx:189
get_generator_info.result
result
Definition: get_generator_info.py:21
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
Barcode::LegacyBarcodeSvc::registerLargestSimulationVtxBC
virtual void registerLargestSimulationVtxBC(int bc) override
Definition: LegacyBarcodeSvc.cxx:193
Barcode::LegacyBarcodeSvc::resetBarcodes
virtual StatusCode resetBarcodes(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Reset barcodes.
Definition: LegacyBarcodeSvc.cxx:209
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
LegacyBarcodeSvc.h
Barcode::LegacyBarcodeSvc::newSecondaryParticle
virtual int newSecondaryParticle(int) override
Generate a new unique barcode for a secondary particle above the simulation offset.
Definition: LegacyBarcodeSvc.cxx:101
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentSimulationVertex
int currentSimulationVertex
Definition: LegacyBarcodeSvc.h:90
Barcode::LegacyBarcodeSvc::registerLargestGeneratedVtxBC
virtual void registerLargestGeneratedVtxBC(int bc) override
Definition: LegacyBarcodeSvc.cxx:182
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentGeneratedParticle
int currentGeneratedParticle
Definition: LegacyBarcodeSvc.h:93
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Barcode::LegacyBarcodeSvc::LegacyBarcodeSvc
LegacyBarcodeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition: LegacyBarcodeSvc.cxx:11
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Barcode::LegacyBarcodeSvc::newGeneratedVertex
virtual int newGeneratedVertex() override
Generate a new unique vertex barcode below the simulation offset.
Definition: LegacyBarcodeSvc.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
Barcode::LegacyBarcodeSvc::secondaryParticleBcOffset
virtual int secondaryParticleBcOffset() const override
Return the secondary particle and vertex offsets.
Definition: LegacyBarcodeSvc.cxx:198
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition: MagicNumbers.h:55
Barcode::LegacyBarcodeSvc::initializeBarcodes
virtual StatusCode initializeBarcodes(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Construct and insert a new set of barcode members.
Definition: LegacyBarcodeSvc.cxx:34
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentSecondaryParticle
int currentSecondaryParticle
Definition: LegacyBarcodeSvc.h:91
Barcode::LegacyBarcodeSvc::newSimulationVertex
virtual int newSimulationVertex() override
Generate a new unique vertex barcode above the simulation offset.
Definition: LegacyBarcodeSvc.cxx:80
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
MagicNumbers.h
Barcode::LegacyBarcodeSvc::registerLargestGeneratedParticleBC
virtual void registerLargestGeneratedParticleBC(int bc) override
Inform the BarcodeSvc about the largest particle and vertex Barcodes in the event input.
Definition: LegacyBarcodeSvc.cxx:175
Barcode::LegacyBarcodeSvc::secondaryVertexBcOffset
virtual int secondaryVertexBcOffset() const override
Return the secondary vertex offset.
Definition: LegacyBarcodeSvc.cxx:204
Barcode::LegacyBarcodeSvc::BarcodeInfo
Definition: LegacyBarcodeSvc.h:83
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HepMC
Definition: Barcode.h:14
Barcode::LegacyBarcodeSvc::getBarcodeInfo
BarcodeInfo & getBarcodeInfo()
Definition: LegacyBarcodeSvc.cxx:61
Barcode::LegacyBarcodeSvc::newGeneratedParticle
virtual int newGeneratedParticle(int) override
Generate a new unique particle barcode below the simulation offset (for particles from pre-defined de...
Definition: LegacyBarcodeSvc.cxx:149
Barcode::LegacyBarcodeSvc::initialize
virtual StatusCode initialize() override
Athena algorithm's interface methods.
Definition: LegacyBarcodeSvc.cxx:22
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentGeneratedVertex
int currentGeneratedVertex
Definition: LegacyBarcodeSvc.h:92