ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
Barcode
BarcodeServices
src
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
5
#include "
LegacyBarcodeSvc.h
"
6
// framework include
7
#include "
TruthUtils/MagicNumbers.h
"
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
22
StatusCode
Barcode::LegacyBarcodeSvc::initialize
()
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
61
Barcode::LegacyBarcodeSvc::BarcodeInfo
&
Barcode::LegacyBarcodeSvc::getBarcodeInfo
() {
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."
);
66
Barcode::LegacyBarcodeSvc::BarcodeInfo
barcodeInfo =
BarcodeInfo
(-
HepMC::SIM_BARCODE_THRESHOLD
,
HepMC::SIM_BARCODE_THRESHOLD
, 0, 0);
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
80
int
Barcode::LegacyBarcodeSvc::newSimulationVertex
()
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 "
90
<< -
HepMC::SIM_BARCODE_THRESHOLD
<<
": "
91
<< bc.
currentSimulationVertex
<<
". Reset to "
92
<<
HepMC::UNDEFINED_ID
);
93
bc.
currentSimulationVertex
=
HepMC::UNDEFINED_ID
;
94
}
95
96
return
bc.
currentSimulationVertex
;
97
}
98
99
101
int
Barcode::LegacyBarcodeSvc::newSecondaryParticle
(
int
)
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 "
111
<<
HepMC::SIM_BARCODE_THRESHOLD
<<
": "
112
<< bc.
currentSecondaryParticle
<<
". Reset to "
113
<<
HepMC::UNDEFINED_ID
);
114
115
bc.
currentSecondaryParticle
=
HepMC::UNDEFINED_ID
;
116
}
117
118
return
bc.
currentSecondaryParticle
;
119
}
120
121
123
int
Barcode::LegacyBarcodeSvc::newGeneratedVertex
()
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 "
133
<<
HepMC::UNDEFINED_ID
);
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
}
146
147
149
int
Barcode::LegacyBarcodeSvc::newGeneratedParticle
(
int
)
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 "
160
<<
HepMC::UNDEFINED_ID
);
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
}
173
174
175
void
Barcode::LegacyBarcodeSvc::registerLargestGeneratedParticleBC
(
int
bc ) {
176
ATH_MSG_DEBUG
(
"registering largest generated particle barcode"
);
177
BarcodeInfo
& barcodeInfo =
getBarcodeInfo
();
178
barcodeInfo.
currentGeneratedParticle
= bc;
179
}
180
181
182
void
Barcode::LegacyBarcodeSvc::registerLargestGeneratedVtxBC
(
int
bc ) {
183
ATH_MSG_DEBUG
(
"registering largest generated particle barcode"
);
184
BarcodeInfo
& barcodeInfo =
getBarcodeInfo
();
185
barcodeInfo.
currentGeneratedVertex
= bc;
186
}
187
188
189
void
Barcode::LegacyBarcodeSvc::registerLargestSecondaryParticleBC
(
int
/* bc */
) {
190
}
191
192
193
void
Barcode::LegacyBarcodeSvc::registerLargestSimulationVtxBC
(
int
/* bc */
) {
194
}
195
196
198
int
Barcode::LegacyBarcodeSvc::secondaryParticleBcOffset
()
const
{
199
return
m_firstSecondary
;
200
}
201
202
204
int
Barcode::LegacyBarcodeSvc::secondaryVertexBcOffset
()
const
{
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
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
LegacyBarcodeSvc.h
MagicNumbers.h
Barcode::LegacyBarcodeSvc::getBarcodeInfo
BarcodeInfo & getBarcodeInfo()
Definition
LegacyBarcodeSvc.cxx:61
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::secondaryParticleBcOffset
virtual int secondaryParticleBcOffset() const override
Return the secondary particle and vertex offsets.
Definition
LegacyBarcodeSvc.cxx:198
Barcode::LegacyBarcodeSvc::initialize
virtual StatusCode initialize() override
Athena algorithm's interface methods.
Definition
LegacyBarcodeSvc.cxx:22
Barcode::LegacyBarcodeSvc::m_firstVertex
int m_firstVertex
barcode information used for GenVertices
Definition
LegacyBarcodeSvc.h:76
Barcode::LegacyBarcodeSvc::registerLargestGeneratedVtxBC
virtual void registerLargestGeneratedVtxBC(int bc) override
Definition
LegacyBarcodeSvc.cxx:182
Barcode::LegacyBarcodeSvc::newGeneratedVertex
virtual int newGeneratedVertex() override
Generate a new unique vertex barcode below the simulation offset.
Definition
LegacyBarcodeSvc.cxx:123
Barcode::LegacyBarcodeSvc::resetBarcodes
virtual StatusCode resetBarcodes(int largestGeneratedParticleBC=0, int largestGeneratedVertexBC=0) override
Reset barcodes.
Definition
LegacyBarcodeSvc.cxx:209
Barcode::LegacyBarcodeSvc::m_particleIncrement
int m_particleIncrement
Definition
LegacyBarcodeSvc.h:81
Barcode::LegacyBarcodeSvc::LegacyBarcodeSvc
LegacyBarcodeSvc(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters.
Definition
LegacyBarcodeSvc.cxx:11
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::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::m_vertexIncrement
int m_vertexIncrement
Definition
LegacyBarcodeSvc.h:77
Barcode::LegacyBarcodeSvc::secondaryVertexBcOffset
virtual int secondaryVertexBcOffset() const override
Return the secondary vertex offset.
Definition
LegacyBarcodeSvc.cxx:204
Barcode::LegacyBarcodeSvc::registerLargestSimulationVtxBC
virtual void registerLargestSimulationVtxBC(int bc) override
Definition
LegacyBarcodeSvc.cxx:193
Barcode::LegacyBarcodeSvc::m_firstSecondary
int m_firstSecondary
barcode information used for secondary GenParticles
Definition
LegacyBarcodeSvc.h:80
Barcode::LegacyBarcodeSvc::registerLargestSecondaryParticleBC
virtual void registerLargestSecondaryParticleBC(int bc) override
Definition
LegacyBarcodeSvc.cxx:189
Barcode::LegacyBarcodeSvc::newSimulationVertex
virtual int newSimulationVertex() override
Generate a new unique vertex barcode above the simulation offset.
Definition
LegacyBarcodeSvc.cxx:80
Barcode::LegacyBarcodeSvc::m_bcThreadMap
LegacyBarcodeSvcThreadMap_t m_bcThreadMap
Definition
LegacyBarcodeSvc.h:98
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
HepMC
Definition
Barcode.h:13
HepMC::UNDEFINED_ID
constexpr int UNDEFINED_ID
Definition
MagicNumbers.h:57
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:38
Barcode::LegacyBarcodeSvc::BarcodeInfo
Definition
LegacyBarcodeSvc.h:83
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentGeneratedVertex
int currentGeneratedVertex
Definition
LegacyBarcodeSvc.h:92
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentSimulationVertex
int currentSimulationVertex
Definition
LegacyBarcodeSvc.h:90
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentSecondaryParticle
int currentSecondaryParticle
Definition
LegacyBarcodeSvc.h:91
Barcode::LegacyBarcodeSvc::BarcodeInfo::currentGeneratedParticle
int currentGeneratedParticle
Definition
LegacyBarcodeSvc.h:93
Generated on
for ATLAS Offline Software by
1.17.0