ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
Navigation
src
AthenaBarCodeImpl.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include <sstream>
6
7
#include "GaudiKernel/ServiceHandle.h"
8
9
#include "
AthenaKernel/IJobIDSvc.h
"
10
11
#include "
Navigation/AthenaBarCodeImpl.h
"
12
13
#include "GaudiKernel/IMessageSvc.h"
14
#include "GaudiKernel/MsgStream.h"
15
#include "
AthenaKernel/getMessageSvc.h
"
16
17
#include <iostream>
18
#include <cstdlib>
19
20
#include "uuid/uuid.h"
21
22
std::atomic<AthenaBarCode_t>
AthenaBarCodeImpl::m_barcodeCounter
= 0;
23
24
void
AthenaBarCodeImpl::initABC
()
const
{
25
26
//This function will be call the first time any "access" function is called
27
//using const type because those "access" functions might be const
28
//Will only change mutable variables
29
30
// std::cout<<"Calling AthenaBarCodeImpl::AthenaBarCodeImpl() "<<std::endl;
31
32
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
33
//Set counter part
34
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
35
36
const
AthenaBarCode_t
counter =
m_barcodeCounter
++;
37
38
AthenaBarCode_t
barcode =
IAthenaBarCode::UNDEFINEDBARCODE
;
39
40
try
{
41
setBits
(
SCounterBits
,
CounterBits
, counter & ((1u<<
CounterBits
)-1),
42
barcode);
43
}
44
catch
(
const
GaudiException& Exception) {
45
throw
std::runtime_error(
46
"AthenaBarCodeImpl::Can not Set Counter Bit, Counter Overflow"
);
47
}
48
49
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
50
//Set reserve part
51
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
52
try
{
53
setBits
(
SReserveBits
,
ReserveBits
, 0, barcode);
54
}
55
catch
(
const
GaudiException& Exception) {
56
throw
std::runtime_error(
57
"AthenaBarCodeImpl::Can not initialize Reserve Bit"
);
58
}
59
60
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
61
//Set Version part
62
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
63
try
{
64
setBits
(
SVersionBits
,
VersionBits
, 0, barcode);
65
}
66
catch
(
const
GaudiException& Exception) {
67
throw
std::runtime_error(
68
"AthenaBarCodeImpl::Can not initialize Version Bit"
);
69
}
70
71
72
try
{
73
setBits
(
SUUIDBits
,
UUIDBits
,
getDefaultHash
(), barcode);
74
}
75
catch
(
const
GaudiException& Exception) {
76
throw
std::runtime_error(
"AthenaBarCodeImpl::Can not set UUID Hash Bits"
);
77
}
78
79
m_barcode
= barcode;
80
81
/* std::cout << "[AthenaBarCodeImpl::m_barcode,m_defaultHash,m_barcodeCounter]= "
82
<< std::hex
83
<< (m_barcode)<< "\t"
84
<< m_defaultHash<< "\t"
85
<< (m_barcodeCounter)<<"\t"
86
<< std::dec
87
<< std::endl;
88
*/
89
}
90
91
AthenaBarCodeImpl::AthenaBarCodeImpl
()
92
:
m_barcode
(
IAthenaBarCode
::UNDEFINEDBARCODE)
93
{
94
}
95
96
AthenaBarCodeImpl::AthenaBarCodeImpl
(
const
AthenaBarCodeImpl
& other)
97
:
m_barcode
(static_cast<
AthenaBarCode_t
>(other.
m_barcode
))
98
{
99
}
100
101
AthenaBarCodeImpl
&
AthenaBarCodeImpl::operator=
(
const
AthenaBarCodeImpl
& other)
102
{
103
if
(
this
!= &other) {
104
m_barcode
=
static_cast<
AthenaBarCode_t
>
(other.m_barcode);
105
}
106
return
*
this
;
107
}
108
109
bool
110
AthenaBarCodeImpl::hasSameAthenaBarCode
(
const
IAthenaBarCode
&obj)
const
{
111
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
112
initABC
();
113
114
if
(obj.getAthenaBarCode() ==
m_barcode
)
115
return
true
;
116
return
false
;
117
}
118
119
bool
120
AthenaBarCodeImpl::hasSameAthenaBarCodeExceptVersion
(
const
IAthenaBarCode
&obj)
const
{
121
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
122
initABC
();
123
124
if
((obj.getAthenaBarCode()) >> (
ReserveBits
+
VersionBits
) ==
m_barcode
125
>> (
ReserveBits
+
VersionBits
))
126
return
true
;
127
return
false
;
128
}
129
130
AthenaBarCodeVersion_t
131
AthenaBarCodeImpl::getVersion
()
const
{
132
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
133
initABC
();
134
return
getBits
(
SVersionBits
,
VersionBits
);
135
}
136
137
void
138
AthenaBarCodeImpl::newVersion
() {
139
140
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
141
initABC
();
142
143
AthenaBarCodeVersion_t
currversion =
getVersion
();
144
145
try
{
146
AthenaBarCode_t
bc =
m_barcode
;
147
setBits
(
SVersionBits
,
VersionBits
, currversion + 1, bc);
148
m_barcode
= bc;
149
}
150
catch
(
const
GaudiException& Exception) {
151
throw
std::runtime_error(
152
"AthenaBarCodeImpl::newVersion()::Version Overflow"
);
153
}
154
}
155
156
void
157
AthenaBarCodeImpl::setVersion
(
AthenaBarCodeVersion_t
ver) {
158
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
159
initABC
();
160
161
try
{
162
AthenaBarCode_t
bc =
m_barcode
;
163
setBits
(
SVersionBits
,
VersionBits
, ver, bc);
164
m_barcode
= bc;
165
}
166
catch
(
const
GaudiException& Exception) {
167
throw
std::runtime_error(
"AthenaBarCodeImpl::newVersion()::Version Too big"
);
168
}
169
}
170
171
std::ostream&
172
AthenaBarCodeImpl::dump
(std::ostream& out)
const
{
173
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
174
initABC
();
175
176
out <<
"\n[AthenaBarCode]= "
<< std::hex << (
m_barcode
) << std::dec << std::endl;
177
return
out;
178
}
179
180
bool
181
AthenaBarCodeImpl::createdInCurrentJob
()
const
{
182
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
183
initABC
();
184
185
//FIXME: it is possible that m_defaultHash is not yet initialized.
186
return
getUUIDHash
() ==
getDefaultHash
();
187
}
188
189
AthenaBarCode_t
190
AthenaBarCodeImpl::hashUUID
(
const
char
*guid) {
191
const
int
maxdigs = 16;
192
AthenaBarCode_t
tmp1 =
static_cast<
AthenaBarCode_t
>
(2166136261UL);
193
194
for
(
int
i = 0; i < maxdigs; i++) {
195
tmp1 ^= (
AthenaBarCode_t
)(guid[i]);
196
tmp1 *= 16777619UL;
197
}
198
199
return
(tmp1 << (
TotalBits
-
UUIDBits
)) >> (
TotalBits
-
UUIDBits
);
200
}
201
202
AthenaBarCode_t
203
AthenaBarCodeImpl::getAthenaBarCode
()
const
{
204
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
205
initABC
();
206
207
return
m_barcode
;
208
}
209
210
void
211
AthenaBarCodeImpl::setAthenaBarCode
(
AthenaBarCode_t
id
) {
212
m_barcode
= id;
213
}
214
215
AthenaBarCode_t
216
AthenaBarCodeImpl::getReserveBits
()
const
{
217
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
218
initABC
();
219
return
getBits
(
SReserveBits
,
ReserveBits
);
220
}
221
222
void
223
AthenaBarCodeImpl::setReserveBits
(
AthenaBarCode_t
id
) {
224
if
(
m_barcode
==
IAthenaBarCode::UNDEFINEDBARCODE
)
225
initABC
();
226
227
try
{
228
AthenaBarCode_t
bc =
m_barcode
;
229
setBits
(
SReserveBits
,
ReserveBits
,
id
, bc);
230
m_barcode
= bc;
231
}
232
catch
(
const
GaudiException& Exception) {
233
throw
std::runtime_error(
234
"AthenaBarCodeImpl::newVersion()::Version Overflow"
);
235
}
236
}
237
238
AthenaBarCode_t
239
AthenaBarCodeImpl::hasUUIDHash
()
const
{
240
return
getUUIDHash
();
241
}
242
243
AthenaBarCode_t
244
AthenaBarCodeImpl::getUUIDHash
()
const
{
245
return
getBits
(
SUUIDBits
,
UUIDBits
);
246
}
247
248
AthenaBarCode_t
249
AthenaBarCodeImpl::getBits
(
unsigned
short
startbit,
unsigned
short
nbits)
const
{
250
251
AthenaBarCode_t
tmp;
252
//now m_barcode=aaaaaxxaa;
253
tmp =
m_barcode
<< (startbit);
//tmp=xxaa00000;
254
tmp = tmp >> (
TotalBits
- nbits);
//tmp=0000000xx
255
256
return
tmp;
257
}
258
259
void
260
AthenaBarCodeImpl::setBits
(
unsigned
short
startbit,
unsigned
short
nbits,
261
AthenaBarCode_t
id
,
262
AthenaBarCode_t
& bc)
const
263
{
264
AthenaBarCode_t
tmp;
265
AthenaBarCode_t
tmp2;
266
tmp2 = 0;
267
268
if
((
id
) >= ((~tmp2) >> (
TotalBits
- nbits))) {
269
270
IMessageSvc *msgsvc =
Athena::getMessageSvc
();
271
if
(msgsvc) {
272
MsgStream
msg
(msgsvc,
"AthenaBarCodeImpl"
);
273
msg
<< MSG::WARNING <<
"setBits::bit to be set:"
<<
id
274
<<
" is larger than limit:"
<< ((~tmp2) >> (
TotalBits
- nbits))
275
<<
endmsg
;
276
}
277
else
{
278
std::cout <<
"setBits::bit to be set:"
<<
id
<<
" is larger than limit:"
279
<< ((~tmp2) >> (
TotalBits
- nbits)) << std::endl;
280
}
281
throw
std::runtime_error(
"AthenaBarCodeImpl::setBit Failed"
);
282
}
283
285
tmp = (
id
<< (
TotalBits
- nbits - startbit));
//tmp=00000xx00
286
tmp2 = ((~tmp2) >> (
TotalBits
- nbits));
//tmp2=000000011
287
288
tmp2 = (tmp2 << (
TotalBits
- nbits - startbit));
//tmp2=000001100
289
tmp2 = (~tmp2);
//tmp2=111110011
290
291
//now m_barcode=aaaaayyaa
292
bc &= tmp2;
//m_barcode=aaaaa00aa
293
bc |= tmp;
//m_barcode=aaaaaxxaa
294
295
}
296
297
void
298
AthenaBarCodeImpl::setDefaultHash
(
const
char
* jobid) {
299
getDefaultHash
(jobid);
300
}
301
302
303
AthenaBarCode_t
304
AthenaBarCodeImpl::getDefaultHash
(
const
char
* jobid
/*= nullptr*/
)
305
{
306
static
const
AthenaBarCode_t
defaultHash =
makeDefaultHash
(jobid);
307
return
defaultHash;
308
}
309
310
311
AthenaBarCode_t
312
AthenaBarCodeImpl::makeDefaultHash
(
const
char
* jobid)
313
{
314
if
(jobid) {
315
return
AthenaBarCodeImpl::hashUUID
(jobid);
316
}
317
318
// First look for a uuid as an environment variable.
319
// This can be set in cases where we don't have the full
320
// Gaudi/Athena environment available (eg, ARA), and we
321
// don't want to try to create JobIDSvc. This has to be
322
// communicated in some way external to this library,
323
// as we may end up here while initializing the dictionary
324
// for this library.
325
const
char
* env_uuid = getenv (
"_ATHENABARCODEIMPL_JOBUUID"
);
326
if
(env_uuid) {
327
return
AthenaBarCodeImpl::hashUUID
(env_uuid);
328
}
329
330
// std::cout<<"no UUID stored, generating."<<std::endl;
331
332
ServiceHandle<IJobIDSvc>
p_jobidsvc(
"JobIDSvc"
,
"JobIDSvc"
);
333
StatusCode
sc
= p_jobidsvc.retrieve();
334
if
(!
sc
.isSuccess() || 0 == p_jobidsvc) {
335
//FIXME
336
//use uuid instead if service not available
337
JobID_t
JobID;
338
uuid_generate(JobID);
339
return
AthenaBarCodeImpl::hashUUID
((
const
char
*) JobID);
340
/* std::cout << "Could not find JobIDSvc, using uuid directly"
341
<<"jobid "<<o.str()
342
<< std::endl;*/
343
}
344
345
PJobID_t
pjobid = p_jobidsvc->getJobID();
346
return
AthenaBarCodeImpl::hashUUID
((
const
char
*) pjobid);
347
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
AthenaBarCodeImpl.h
AthenaBarCode_t
uint64_t AthenaBarCode_t
barcode for all INav4Mom classes
Definition
AthenaKernel/AthenaKernel/IAthenaBarCode.h:44
AthenaBarCodeVersion_t
AthenaBarCode_t AthenaBarCodeVersion_t
Definition
AthenaKernel/AthenaKernel/IAthenaBarCode.h:46
IJobIDSvc.h
JobID_t
uuid_t JobID_t
Definition
IJobIDSvc.h:20
PJobID_t
const unsigned char * PJobID_t
Definition
IJobIDSvc.h:21
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
AthenaBarCodeImpl::initABC
void initABC() const
Definition
AthenaBarCodeImpl.cxx:24
AthenaBarCodeImpl::ReserveBits
static const unsigned short ReserveBits
Definition
AthenaBarCodeImpl.h:46
AthenaBarCodeImpl::setBits
void setBits(unsigned short startbit, unsigned short nbits, AthenaBarCode_t id, AthenaBarCode_t &bc) const
Definition
AthenaBarCodeImpl.cxx:260
AthenaBarCodeImpl::newVersion
void newVersion()
Definition
AthenaBarCodeImpl.cxx:138
AthenaBarCodeImpl::makeDefaultHash
static AthenaBarCode_t makeDefaultHash(const char *jobid)
Definition
AthenaBarCodeImpl.cxx:312
AthenaBarCodeImpl::SUUIDBits
static const unsigned short SUUIDBits
Definition
AthenaBarCodeImpl.h:48
AthenaBarCodeImpl::setReserveBits
void setReserveBits(AthenaBarCode_t id)
Definition
AthenaBarCodeImpl.cxx:223
AthenaBarCodeImpl::hasUUIDHash
AthenaBarCode_t hasUUIDHash() const
Definition
AthenaBarCodeImpl.cxx:239
AthenaBarCodeImpl::getUUIDHash
AthenaBarCode_t getUUIDHash() const
Definition
AthenaBarCodeImpl.cxx:244
AthenaBarCodeImpl::UUIDBits
static const unsigned short UUIDBits
Definition
AthenaBarCodeImpl.h:43
AthenaBarCodeImpl::setDefaultHash
static void setDefaultHash(const char *jobid)
Definition
AthenaBarCodeImpl.cxx:298
AthenaBarCodeImpl::getBits
AthenaBarCode_t getBits(unsigned short startbit, unsigned short nbits) const
Definition
AthenaBarCodeImpl.cxx:249
AthenaBarCodeImpl::m_barcode
std::atomic< AthenaBarCode_t > m_barcode
Definition
AthenaBarCodeImpl.h:110
AthenaBarCodeImpl::AthenaBarCodeImpl
AthenaBarCodeImpl()
Definition
AthenaBarCodeImpl.cxx:91
AthenaBarCodeImpl::CounterBits
static const unsigned short CounterBits
Definition
AthenaBarCodeImpl.h:44
AthenaBarCodeImpl::SCounterBits
static const unsigned short SCounterBits
Definition
AthenaBarCodeImpl.h:49
AthenaBarCodeImpl::getDefaultHash
static AthenaBarCode_t getDefaultHash(const char *jobid=nullptr)
Definition
AthenaBarCodeImpl.cxx:304
AthenaBarCodeImpl::hasSameAthenaBarCodeExceptVersion
bool hasSameAthenaBarCodeExceptVersion(const IAthenaBarCode &obj) const
Definition
AthenaBarCodeImpl.cxx:120
AthenaBarCodeImpl::getVersion
AthenaBarCodeVersion_t getVersion() const
Definition
AthenaBarCodeImpl.cxx:131
AthenaBarCodeImpl::setAthenaBarCode
void setAthenaBarCode(AthenaBarCode_t id)
Definition
AthenaBarCodeImpl.cxx:211
AthenaBarCodeImpl::SVersionBits
static const unsigned short SVersionBits
Definition
AthenaBarCodeImpl.h:50
AthenaBarCodeImpl::createdInCurrentJob
bool createdInCurrentJob() const
Definition
AthenaBarCodeImpl.cxx:181
AthenaBarCodeImpl::getAthenaBarCode
AthenaBarCode_t getAthenaBarCode() const
Definition
AthenaBarCodeImpl.cxx:203
AthenaBarCodeImpl::dump
std::ostream & dump(std::ostream &out) const
Definition
AthenaBarCodeImpl.cxx:172
AthenaBarCodeImpl::setVersion
void setVersion(AthenaBarCodeVersion_t newversion)
Definition
AthenaBarCodeImpl.cxx:157
AthenaBarCodeImpl::VersionBits
static const unsigned short VersionBits
Definition
AthenaBarCodeImpl.h:45
AthenaBarCodeImpl::TotalBits
static const unsigned short TotalBits
Definition
AthenaBarCodeImpl.h:41
AthenaBarCodeImpl::operator=
AthenaBarCodeImpl & operator=(const AthenaBarCodeImpl &)
Definition
AthenaBarCodeImpl.cxx:101
AthenaBarCodeImpl::SReserveBits
static const unsigned short SReserveBits
Definition
AthenaBarCodeImpl.h:51
AthenaBarCodeImpl::hashUUID
static AthenaBarCode_t hashUUID(const char *)
Definition
AthenaBarCodeImpl.cxx:190
AthenaBarCodeImpl::getReserveBits
AthenaBarCode_t getReserveBits() const
Definition
AthenaBarCodeImpl.cxx:216
AthenaBarCodeImpl::m_barcodeCounter
static std::atomic< AthenaBarCode_t > m_barcodeCounter
Definition
AthenaBarCodeImpl.h:109
AthenaBarCodeImpl::hasSameAthenaBarCode
bool hasSameAthenaBarCode(const IAthenaBarCode &obj) const
Definition
AthenaBarCodeImpl.cxx:110
IAthenaBarCode
Definition
AthenaKernel/AthenaKernel/IAthenaBarCode.h:48
IAthenaBarCode::UNDEFINEDBARCODE
static const AthenaBarCode_t UNDEFINEDBARCODE
Definition
AthenaKernel/AthenaKernel/IAthenaBarCode.h:52
ServiceHandle
Definition
ClusterMakerTool.h:36
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition
getMessageSvc.cxx:20
msg
MsgStream & msg
Definition
testRead.cxx:32
Generated on
for ATLAS Offline Software by
1.17.0