ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaBarCodeImpl Class Reference

#include <AthenaBarCodeImpl.h>

Inheritance diagram for AthenaBarCodeImpl:
Collaboration diagram for AthenaBarCodeImpl:

Public Member Functions

virtual ~AthenaBarCodeImpl ()=default
 AthenaBarCodeImpl ()
 AthenaBarCodeImpl (const AthenaBarCodeImpl &)
AthenaBarCodeImploperator= (const AthenaBarCodeImpl &)
AthenaBarCode_t getAthenaBarCode () const
void setAthenaBarCode (AthenaBarCode_t id)
bool hasSameAthenaBarCode (const IAthenaBarCode &obj) const
bool hasSameAthenaBarCodeExceptVersion (const IAthenaBarCode &obj) const
AthenaBarCodeVersion_t getVersion () const
void newVersion ()
void setVersion (AthenaBarCodeVersion_t newversion)
std::ostream & dump (std::ostream &out) const
bool createdInCurrentJob () const
AthenaBarCode_t getReserveBits () const
void setReserveBits (AthenaBarCode_t id)

Static Public Member Functions

static void setDefaultHash (const char *jobid)

Static Public Attributes

static const unsigned short TotalBits = 64
static const unsigned short UUIDBits = 32
static const unsigned short CounterBits = 26
static const unsigned short VersionBits = 4
static const unsigned short ReserveBits = 2
static const unsigned short SUUIDBits = 0
static const unsigned short SCounterBits = UUIDBits
static const unsigned short SVersionBits = UUIDBits+CounterBits
static const unsigned short SReserveBits = UUIDBits+CounterBits+VersionBits

Protected Member Functions

void setBits (unsigned short startbit, unsigned short nbits, AthenaBarCode_t id, AthenaBarCode_t &bc) const
AthenaBarCode_t getBits (unsigned short startbit, unsigned short nbits) const
void initABC () const

Private Member Functions

AthenaBarCode_t combineWithUUIDHash (const AthenaBarCode_t &) const
void setUUIDHash (AthenaBarCode_t uuidhash)
AthenaBarCode_t hasUUIDHash () const
AthenaBarCode_t getUUIDHash () const

Static Private Member Functions

static AthenaBarCode_t hashUUID (const char *)
static AthenaBarCode_t getDefaultHash (const char *jobid=nullptr)
static AthenaBarCode_t makeDefaultHash (const char *jobid)

Private Attributes

std::atomic< AthenaBarCode_tm_barcode

Static Private Attributes

static std::atomic< AthenaBarCode_tm_barcodeCounter = 0

Friends

class AthenaBarCodeCnv_p1

Detailed Description

Definition at line 37 of file AthenaBarCodeImpl.h.

Constructor & Destructor Documentation

◆ ~AthenaBarCodeImpl()

virtual AthenaBarCodeImpl::~AthenaBarCodeImpl ( )
virtualdefault

◆ AthenaBarCodeImpl() [1/2]

AthenaBarCodeImpl::AthenaBarCodeImpl ( )

Definition at line 91 of file AthenaBarCodeImpl.cxx.

93{
94}
std::atomic< AthenaBarCode_t > m_barcode
static const AthenaBarCode_t UNDEFINEDBARCODE

◆ AthenaBarCodeImpl() [2/2]

AthenaBarCodeImpl::AthenaBarCodeImpl ( const AthenaBarCodeImpl & other)

Definition at line 96 of file AthenaBarCodeImpl.cxx.

97 : m_barcode (static_cast<AthenaBarCode_t>(other.m_barcode))
98{
99}
uint64_t AthenaBarCode_t
barcode for all INav4Mom classes

Member Function Documentation

◆ combineWithUUIDHash()

AthenaBarCode_t AthenaBarCodeImpl::combineWithUUIDHash ( const AthenaBarCode_t & hash) const
inlineprivate

Definition at line 119 of file AthenaBarCodeImpl.h.

120 {
121
123 AthenaBarCode_t lowerh = ~tmp >> (TotalBits
124 - UUIDBits);
125 AthenaBarCode_t higherh = ~tmp << (UUIDBits);
126
127 AthenaBarCode_t lower = m_barcode & lowerh;
128 AthenaBarCode_t higher = hash & higherh;
129
130 /*
131 std::cout << "AthenaBarCodeImpl::combineWithHash::hash=" << std::hex
132 << hash << " lower=" << lower << " higher=" << higher << " lowerh="
133 << lowerh << " higherh=" << higherh << " barcode=" << (lower
134 | higher) << std::endl;
135 */
136 return lower | higher;
137
138}
static const unsigned short UUIDBits
static const unsigned short TotalBits

◆ createdInCurrentJob()

bool AthenaBarCodeImpl::createdInCurrentJob ( ) const

Definition at line 181 of file AthenaBarCodeImpl.cxx.

181 {
183 initABC();
184
185 //FIXME: it is possible that m_defaultHash is not yet initialized.
186 return getUUIDHash() == getDefaultHash();
187}
AthenaBarCode_t getUUIDHash() const
static AthenaBarCode_t getDefaultHash(const char *jobid=nullptr)

◆ dump()

std::ostream & AthenaBarCodeImpl::dump ( std::ostream & out) const

Definition at line 172 of file AthenaBarCodeImpl.cxx.

172 {
174 initABC();
175
176 out << "\n[AthenaBarCode]= " << std::hex << (m_barcode) << std::dec << std::endl;
177 return out;
178}

◆ getAthenaBarCode()

AthenaBarCode_t AthenaBarCodeImpl::getAthenaBarCode ( ) const

Definition at line 203 of file AthenaBarCodeImpl.cxx.

203 {
205 initABC();
206
207 return m_barcode;
208}

◆ getBits()

AthenaBarCode_t AthenaBarCodeImpl::getBits ( unsigned short startbit,
unsigned short nbits ) const
protected

Definition at line 249 of file AthenaBarCodeImpl.cxx.

249 {
250
252 //now m_barcode=aaaaaxxaa;
253 tmp = m_barcode << (startbit); //tmp=xxaa00000;
254 tmp = tmp >> (TotalBits - nbits); //tmp=0000000xx
255
256 return tmp;
257}

◆ getDefaultHash()

AthenaBarCode_t AthenaBarCodeImpl::getDefaultHash ( const char * jobid = nullptr)
staticprivate

Definition at line 304 of file AthenaBarCodeImpl.cxx.

305{
306 static const AthenaBarCode_t defaultHash = makeDefaultHash (jobid);
307 return defaultHash;
308}
static AthenaBarCode_t makeDefaultHash(const char *jobid)

◆ getReserveBits()

AthenaBarCode_t AthenaBarCodeImpl::getReserveBits ( ) const

Definition at line 216 of file AthenaBarCodeImpl.cxx.

216 {
218 initABC();
220}
static const unsigned short ReserveBits
AthenaBarCode_t getBits(unsigned short startbit, unsigned short nbits) const
static const unsigned short SReserveBits

◆ getUUIDHash()

AthenaBarCode_t AthenaBarCodeImpl::getUUIDHash ( ) const
private

Definition at line 244 of file AthenaBarCodeImpl.cxx.

244 {
245 return getBits(SUUIDBits, UUIDBits);
246}
static const unsigned short SUUIDBits

◆ getVersion()

AthenaBarCodeVersion_t AthenaBarCodeImpl::getVersion ( ) const

Definition at line 131 of file AthenaBarCodeImpl.cxx.

131 {
133 initABC();
135}
static const unsigned short SVersionBits
static const unsigned short VersionBits

◆ hashUUID()

AthenaBarCode_t AthenaBarCodeImpl::hashUUID ( const char * guid)
staticprivate

Definition at line 190 of file AthenaBarCodeImpl.cxx.

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

◆ hasSameAthenaBarCode()

bool AthenaBarCodeImpl::hasSameAthenaBarCode ( const IAthenaBarCode & obj) const

Definition at line 110 of file AthenaBarCodeImpl.cxx.

110 {
112 initABC();
113
114 if (obj.getAthenaBarCode() == m_barcode)
115 return true;
116 return false;
117}

◆ hasSameAthenaBarCodeExceptVersion()

bool AthenaBarCodeImpl::hasSameAthenaBarCodeExceptVersion ( const IAthenaBarCode & obj) const

Definition at line 120 of file AthenaBarCodeImpl.cxx.

120 {
122 initABC();
123
124 if ((obj.getAthenaBarCode()) >> (ReserveBits + VersionBits) == m_barcode
126 return true;
127 return false;
128}

◆ hasUUIDHash()

AthenaBarCode_t AthenaBarCodeImpl::hasUUIDHash ( ) const
private

Definition at line 239 of file AthenaBarCodeImpl.cxx.

239 {
240 return getUUIDHash();
241}

◆ initABC()

void AthenaBarCodeImpl::initABC ( ) const
protected

Definition at line 24 of file AthenaBarCodeImpl.cxx.

24 {
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
37
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 {
74 }
75 catch (const GaudiException& Exception) {
76 throw std::runtime_error("AthenaBarCodeImpl::Can not set UUID Hash Bits");
77 }
78
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}
void setBits(unsigned short startbit, unsigned short nbits, AthenaBarCode_t id, AthenaBarCode_t &bc) const
static const unsigned short CounterBits
static const unsigned short SCounterBits
static std::atomic< AthenaBarCode_t > m_barcodeCounter
int barcode(const T *p)
Definition Barcode.h:16

◆ makeDefaultHash()

AthenaBarCode_t AthenaBarCodeImpl::makeDefaultHash ( const char * jobid)
staticprivate

Definition at line 312 of file AthenaBarCodeImpl.cxx.

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}
uuid_t JobID_t
Definition IJobIDSvc.h:20
const unsigned char * PJobID_t
Definition IJobIDSvc.h:21
static Double_t sc
static AthenaBarCode_t hashUUID(const char *)
::StatusCode StatusCode
StatusCode definition for legacy code.
std::string getenv(const std::string &variableName)
get an environment variable

◆ newVersion()

void AthenaBarCodeImpl::newVersion ( )

Definition at line 138 of file AthenaBarCodeImpl.cxx.

138 {
139
141 initABC();
142
143 AthenaBarCodeVersion_t currversion = getVersion();
144
145 try {
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}
AthenaBarCode_t AthenaBarCodeVersion_t
AthenaBarCodeVersion_t getVersion() const

◆ operator=()

AthenaBarCodeImpl & AthenaBarCodeImpl::operator= ( const AthenaBarCodeImpl & other)

Definition at line 101 of file AthenaBarCodeImpl.cxx.

102{
103 if (this != &other) {
104 m_barcode = static_cast<AthenaBarCode_t>(other.m_barcode);
105 }
106 return *this;
107}

◆ setAthenaBarCode()

void AthenaBarCodeImpl::setAthenaBarCode ( AthenaBarCode_t id)

Definition at line 211 of file AthenaBarCodeImpl.cxx.

◆ setBits()

void AthenaBarCodeImpl::setBits ( unsigned short startbit,
unsigned short nbits,
AthenaBarCode_t id,
AthenaBarCode_t & bc ) const
protected

now id=0000000xx;

Definition at line 260 of file AthenaBarCodeImpl.cxx.

263{
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}
#define endmsg
IMessageSvc * getMessageSvc(bool quiet=false)
MsgStream & msg
Definition testRead.cxx:32

◆ setDefaultHash()

void AthenaBarCodeImpl::setDefaultHash ( const char * jobid)
static

Definition at line 298 of file AthenaBarCodeImpl.cxx.

298 {
299 getDefaultHash (jobid);
300}

◆ setReserveBits()

void AthenaBarCodeImpl::setReserveBits ( AthenaBarCode_t id)

Definition at line 223 of file AthenaBarCodeImpl.cxx.

223 {
225 initABC();
226
227 try {
230 m_barcode = bc;
231 }
232 catch (const GaudiException& Exception) {
233 throw std::runtime_error(
234 "AthenaBarCodeImpl::newVersion()::Version Overflow");
235 }
236}

◆ setUUIDHash()

void AthenaBarCodeImpl::setUUIDHash ( AthenaBarCode_t uuidhash)
inlineprivate

Definition at line 114 of file AthenaBarCodeImpl.h.

114 {
115 m_barcode = combineWithUUIDHash(uuidhash);
116}
AthenaBarCode_t combineWithUUIDHash(const AthenaBarCode_t &) const

◆ setVersion()

void AthenaBarCodeImpl::setVersion ( AthenaBarCodeVersion_t newversion)

Definition at line 157 of file AthenaBarCodeImpl.cxx.

157 {
159 initABC();
160
161 try {
164 m_barcode = bc;
165 }
166 catch (const GaudiException& Exception) {
167 throw std::runtime_error("AthenaBarCodeImpl::newVersion()::Version Too big");
168 }
169}

◆ AthenaBarCodeCnv_p1

friend class AthenaBarCodeCnv_p1
friend

Definition at line 38 of file AthenaBarCodeImpl.h.

Member Data Documentation

◆ CounterBits

const unsigned short AthenaBarCodeImpl::CounterBits = 26
static

Definition at line 44 of file AthenaBarCodeImpl.h.

◆ m_barcode

std::atomic<AthenaBarCode_t> AthenaBarCodeImpl::m_barcode
mutableprivate

Definition at line 110 of file AthenaBarCodeImpl.h.

◆ m_barcodeCounter

std::atomic< AthenaBarCode_t > AthenaBarCodeImpl::m_barcodeCounter = 0
staticprivate

Definition at line 109 of file AthenaBarCodeImpl.h.

◆ ReserveBits

const unsigned short AthenaBarCodeImpl::ReserveBits = 2
static

Definition at line 46 of file AthenaBarCodeImpl.h.

◆ SCounterBits

const unsigned short AthenaBarCodeImpl::SCounterBits = UUIDBits
static

Definition at line 49 of file AthenaBarCodeImpl.h.

◆ SReserveBits

const unsigned short AthenaBarCodeImpl::SReserveBits = UUIDBits+CounterBits+VersionBits
static

Definition at line 51 of file AthenaBarCodeImpl.h.

◆ SUUIDBits

const unsigned short AthenaBarCodeImpl::SUUIDBits = 0
static

Definition at line 48 of file AthenaBarCodeImpl.h.

◆ SVersionBits

const unsigned short AthenaBarCodeImpl::SVersionBits = UUIDBits+CounterBits
static

Definition at line 50 of file AthenaBarCodeImpl.h.

◆ TotalBits

const unsigned short AthenaBarCodeImpl::TotalBits = 64
static

Definition at line 41 of file AthenaBarCodeImpl.h.

◆ UUIDBits

const unsigned short AthenaBarCodeImpl::UUIDBits = 32
static

Definition at line 43 of file AthenaBarCodeImpl.h.

◆ VersionBits

const unsigned short AthenaBarCodeImpl::VersionBits = 4
static

Definition at line 45 of file AthenaBarCodeImpl.h.


The documentation for this class was generated from the following files: