ATLAS Offline Software
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Barcode::LegacyBarcodeSvc Class Reference

#include <LegacyBarcodeSvc.h>

Inheritance diagram for Barcode::LegacyBarcodeSvc:
Collaboration diagram for Barcode::LegacyBarcodeSvc:

Classes

struct  BarcodeInfo
 

Public Member Functions

 LegacyBarcodeSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Constructor with parameters. More...
 
virtual ~LegacyBarcodeSvc ()=default
 Destructor. More...
 
virtual StatusCode initialize () override
 Athena algorithm's interface methods. More...
 
virtual StatusCode initializeBarcodes (int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
 Construct and insert a new set of barcode members. More...
 
virtual StatusCode resetBarcodes (int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
 Reset barcodes. More...
 
virtual int newSecondaryParticle (int) override
 Generate a new unique barcode for a secondary particle above the simulation offset. More...
 
virtual int newGeneratedParticle (int) override
 Generate a new unique particle barcode below the simulation offset (for particles from pre-defined decays) More...
 
virtual int newSimulationVertex () override
 Generate a new unique vertex barcode above the simulation offset. More...
 
virtual int newGeneratedVertex () override
 Generate a new unique vertex barcode below the simulation offset. More...
 
virtual void registerLargestGeneratedParticleBC (int bc) override
 Inform the BarcodeSvc about the largest particle and vertex Barcodes in the event input. More...
 
virtual void registerLargestGeneratedVtxBC (int bc) override
 
virtual void registerLargestSecondaryParticleBC (int bc) override
 
virtual void registerLargestSimulationVtxBC (int bc) override
 
virtual int secondaryParticleBcOffset () const override
 Return the secondary particle and vertex offsets. More...
 
virtual int secondaryVertexBcOffset () const override
 Return the secondary vertex offset. More...
 

Private Types

using LegacyBarcodeSvcThreadMap_t = tbb::concurrent_unordered_map< std::thread::id, BarcodeInfo, std::hash< std::thread::id > >
 

Private Member Functions

BarcodeInfogetBarcodeInfo ()
 

Private Attributes

int m_firstVertex
 barcode information used for GenVertices More...
 
int m_vertexIncrement
 
int m_firstSecondary
 barcode information used for secondary GenParticles More...
 
int m_particleIncrement
 
LegacyBarcodeSvcThreadMap_t m_bcThreadMap
 

Detailed Description

This BarcodeService reproduces the barcode treatmend for MC12: http://acode-browser.usatlas.bnl.gov/lxr/source/atlas/Simulation/G4Sim/MCTruth/src/TruthStrategyManager.cxx

Author
Andreas.Salzburger -at- cern.ch , Elmar.Ritsch -at- cern.ch

Definition at line 32 of file LegacyBarcodeSvc.h.

Member Typedef Documentation

◆ LegacyBarcodeSvcThreadMap_t

using Barcode::LegacyBarcodeSvc::LegacyBarcodeSvcThreadMap_t = tbb::concurrent_unordered_map < std::thread::id, BarcodeInfo, std::hash<std::thread::id> >
private

Definition at line 96 of file LegacyBarcodeSvc.h.

Constructor & Destructor Documentation

◆ LegacyBarcodeSvc()

Barcode::LegacyBarcodeSvc::LegacyBarcodeSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Constructor with parameters.

Constructor.

Definition at line 11 of file LegacyBarcodeSvc.cxx.

◆ ~LegacyBarcodeSvc()

virtual Barcode::LegacyBarcodeSvc::~LegacyBarcodeSvc ( )
virtualdefault

Destructor.

Member Function Documentation

◆ getBarcodeInfo()

Barcode::LegacyBarcodeSvc::BarcodeInfo & Barcode::LegacyBarcodeSvc::getBarcodeInfo ( )
private

Definition at line 61 of file LegacyBarcodeSvc.cxx.

61  {
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 }

◆ initialize()

StatusCode Barcode::LegacyBarcodeSvc::initialize ( )
overridevirtual

Athena algorithm's interface methods.

framework methods

Definition at line 22 of file LegacyBarcodeSvc.cxx.

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 }

◆ initializeBarcodes()

StatusCode Barcode::LegacyBarcodeSvc::initializeBarcodes ( int  largestGeneratedParticleBC = 0,
int  largestGeneratedVertexBC = 0 
)
overridevirtual

Construct and insert a new set of barcode members.

To be called for every new thread.

Definition at line 34 of file LegacyBarcodeSvc.cxx.

34  {
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 }

◆ newGeneratedParticle()

int Barcode::LegacyBarcodeSvc::newGeneratedParticle ( int  )
overridevirtual

Generate a new unique particle barcode below the simulation offset (for particles from pre-defined decays)

Generate a new unique barcode for a particle produced in a pre-defined decay

Definition at line 149 of file LegacyBarcodeSvc.cxx.

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 
162  bc.currentGeneratedParticle = HepMC::UNDEFINED_ID;
163  }
164  if ( bc.currentGeneratedParticle > HepMC::SIM_BARCODE_THRESHOLD) {
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 }

◆ newGeneratedVertex()

int Barcode::LegacyBarcodeSvc::newGeneratedVertex ( )
overridevirtual

Generate a new unique vertex barcode below the simulation offset.

Generate a new unique vertex barcode for pre-defined decay vertices.

Definition at line 123 of file LegacyBarcodeSvc.cxx.

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 
135  bc.currentGeneratedVertex = HepMC::UNDEFINED_ID;
136  }
137  if ( bc.currentGeneratedVertex < -HepMC::SIM_BARCODE_THRESHOLD) {
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 }

◆ newSecondaryParticle()

int Barcode::LegacyBarcodeSvc::newSecondaryParticle ( int  )
overridevirtual

Generate a new unique barcode for a secondary particle above the simulation offset.

Generate a new unique barcode for a secondary particle.

Definition at line 101 of file LegacyBarcodeSvc.cxx.

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
107  if (bc.currentSecondaryParticle < HepMC::SIM_BARCODE_THRESHOLD)
108  {
109  ATH_MSG_WARNING("LegacyBarcodeSvc::newSecondaryParticle()"
110  << " will return a particle barcode of less than "
112  << bc.currentSecondaryParticle << ". Reset to "
114 
115  bc.currentSecondaryParticle = HepMC::UNDEFINED_ID;
116  }
117 
118  return bc.currentSecondaryParticle;
119 }

◆ newSimulationVertex()

int Barcode::LegacyBarcodeSvc::newSimulationVertex ( )
overridevirtual

Generate a new unique vertex barcode above the simulation offset.

Generate a new unique vertex simulated barcode.

Definition at line 80 of file LegacyBarcodeSvc.cxx.

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
86  if ( bc.currentSimulationVertex > -HepMC::SIM_BARCODE_THRESHOLD)
87  {
88  ATH_MSG_WARNING("LegacyBarcodeSvc::newSimulationVertex()"
89  << " will return a vertex barcode greater than "
91  << bc.currentSimulationVertex << ". Reset to "
93  bc.currentSimulationVertex = HepMC::UNDEFINED_ID;
94  }
95 
96  return bc.currentSimulationVertex;
97 }

◆ registerLargestGeneratedParticleBC()

void Barcode::LegacyBarcodeSvc::registerLargestGeneratedParticleBC ( int  bc)
overridevirtual

Inform the BarcodeSvc about the largest particle and vertex Barcodes in the event input.

Definition at line 175 of file LegacyBarcodeSvc.cxx.

175  {
176  ATH_MSG_DEBUG( "registering largest generated particle barcode" );
177  BarcodeInfo& barcodeInfo = getBarcodeInfo();
178  barcodeInfo.currentGeneratedParticle = bc;
179 }

◆ registerLargestGeneratedVtxBC()

void Barcode::LegacyBarcodeSvc::registerLargestGeneratedVtxBC ( int  bc)
overridevirtual

Definition at line 182 of file LegacyBarcodeSvc.cxx.

182  {
183  ATH_MSG_DEBUG( "registering largest generated particle barcode" );
184  BarcodeInfo& barcodeInfo = getBarcodeInfo();
185  barcodeInfo.currentGeneratedVertex = bc;
186 }

◆ registerLargestSecondaryParticleBC()

void Barcode::LegacyBarcodeSvc::registerLargestSecondaryParticleBC ( int  bc)
overridevirtual

Definition at line 189 of file LegacyBarcodeSvc.cxx.

189  {
190 }

◆ registerLargestSimulationVtxBC()

void Barcode::LegacyBarcodeSvc::registerLargestSimulationVtxBC ( int  bc)
overridevirtual

Definition at line 193 of file LegacyBarcodeSvc.cxx.

193  {
194 }

◆ resetBarcodes()

StatusCode Barcode::LegacyBarcodeSvc::resetBarcodes ( int  largestGeneratedParticleBC = 0,
int  largestGeneratedVertexBC = 0 
)
overridevirtual

Reset barcodes.

To be called at the beginning of each event.

Definition at line 209 of file LegacyBarcodeSvc.cxx.

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 }

◆ secondaryParticleBcOffset()

int Barcode::LegacyBarcodeSvc::secondaryParticleBcOffset ( ) const
overridevirtual

Return the secondary particle and vertex offsets.

Return the secondary particle offset.

Definition at line 198 of file LegacyBarcodeSvc.cxx.

198  {
199  return m_firstSecondary;
200 }

◆ secondaryVertexBcOffset()

int Barcode::LegacyBarcodeSvc::secondaryVertexBcOffset ( ) const
overridevirtual

Return the secondary vertex offset.

Definition at line 204 of file LegacyBarcodeSvc.cxx.

204  {
205  return m_firstVertex;
206 }

Member Data Documentation

◆ m_bcThreadMap

LegacyBarcodeSvcThreadMap_t Barcode::LegacyBarcodeSvc::m_bcThreadMap
private

Definition at line 98 of file LegacyBarcodeSvc.h.

◆ m_firstSecondary

int Barcode::LegacyBarcodeSvc::m_firstSecondary
private

barcode information used for secondary GenParticles

Definition at line 80 of file LegacyBarcodeSvc.h.

◆ m_firstVertex

int Barcode::LegacyBarcodeSvc::m_firstVertex
private

barcode information used for GenVertices

Definition at line 76 of file LegacyBarcodeSvc.h.

◆ m_particleIncrement

int Barcode::LegacyBarcodeSvc::m_particleIncrement
private

Definition at line 81 of file LegacyBarcodeSvc.h.

◆ m_vertexIncrement

int Barcode::LegacyBarcodeSvc::m_vertexIncrement
private

Definition at line 77 of file LegacyBarcodeSvc.h.


The documentation for this class was generated from the following files:
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
get_generator_info.result
result
Definition: get_generator_info.py:21
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
Barcode::LegacyBarcodeSvc::m_particleIncrement
int m_particleIncrement
Definition: LegacyBarcodeSvc.h:81
Barcode::LegacyBarcodeSvc::m_bcThreadMap
LegacyBarcodeSvcThreadMap_t m_bcThreadMap
Definition: LegacyBarcodeSvc.h:98
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
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Barcode::LegacyBarcodeSvc::m_firstSecondary
int m_firstSecondary
barcode information used for secondary GenParticles
Definition: LegacyBarcodeSvc.h:80
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
Barcode::LegacyBarcodeSvc::BarcodeInfo
Definition: LegacyBarcodeSvc.h:83
Barcode::LegacyBarcodeSvc::m_vertexIncrement
int m_vertexIncrement
Definition: LegacyBarcodeSvc.h:77
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Barcode::LegacyBarcodeSvc::getBarcodeInfo
BarcodeInfo & getBarcodeInfo()
Definition: LegacyBarcodeSvc.cxx:61
Barcode::LegacyBarcodeSvc::m_firstVertex
int m_firstVertex
barcode information used for GenVertices
Definition: LegacyBarcodeSvc.h:76