ATLAS Offline Software
AthenaBarCodeImpl.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENABARCODEIMPL_H
8 #define ATHENABARCODEIMPL_H
9 
18 // //
20 
21 // STL includes
22 
23 #include <inttypes.h>
24 
25 #include <iosfwd>
26 #include <atomic>
27 
28 #include <AthenaKernel/IAthenaBarCode.h> //for static const data memebers
30 //
31 // Universal Object Identifier for all INav4Mom Objects
32 //
34 
35 class StatusCode;
36 
38  friend class AthenaBarCodeCnv_p1;
39 
40 public:
41  static const unsigned short TotalBits = 64;
42 
43  static const unsigned short UUIDBits = 32;
44  static const unsigned short CounterBits = 26;
45  static const unsigned short VersionBits = 4;
46  static const unsigned short ReserveBits = 2;
47 
48  static const unsigned short SUUIDBits = 0;
49  static const unsigned short SCounterBits = UUIDBits;
50  static const unsigned short SVersionBits = UUIDBits+CounterBits;
51  static const unsigned short SReserveBits = UUIDBits+CounterBits+VersionBits;
52 
53 
54 public:
55  //Constructors
56 
57  virtual ~AthenaBarCodeImpl() = default;
58 
62 
63 public:
64  //Public setter and getters
67 
68 public:
69  //Comparing & Versioning Control
70  bool hasSameAthenaBarCode(const IAthenaBarCode &obj) const;
72 
74  void newVersion();
75  void setVersion(AthenaBarCodeVersion_t newversion);
76 
77  std::ostream& dump(std::ostream& out) const;
78 
79  //True if the athenabarcode is created in this job, meaning a newly created object. False if the object is read from a file.
80  bool createdInCurrentJob() const;
81 
82  //Handle reserved bits, mainly for read back of older version of AthenaBarCode when the configuration of #bits for UUID,counter and version bits are different from the current one.
85 
86  // Used to set the default hash when JobIDSvc is not being used.
87  // Should not be called within Athena.
88  static void setDefaultHash (const char* jobid);
89 
90 protected:
91  void setBits(unsigned short startbit,unsigned short nbits,AthenaBarCode_t id,
92  AthenaBarCode_t& bc) const;
93  AthenaBarCode_t getBits(unsigned short startbit,unsigned short nbits) const ;
94  void initABC() const ;
95 
96 private:
97  //UUID related
99  static AthenaBarCode_t hashUUID(const char *);
100 
101  void setUUIDHash(AthenaBarCode_t uuidhash);
104 
105  static AthenaBarCode_t getDefaultHash (const char* jobid = nullptr);
106  static AthenaBarCode_t makeDefaultHash (const char* jobid);
107 
108  //data fields
109  static std::atomic<AthenaBarCode_t> m_barcodeCounter;
110  mutable std::atomic<AthenaBarCode_t> m_barcode;
111 
112 };
113 
115  m_barcode = combineWithUUIDHash(uuidhash);
116 }
117 
118 
120  const AthenaBarCode_t &hash) const {
121 
122  AthenaBarCode_t tmp = 0;
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 }
139 
140 #endif // not NAVIGATION_ATHENABARCODE_H
AthenaBarCodeImpl::setReserveBits
void setReserveBits(AthenaBarCode_t id)
Definition: AthenaBarCodeImpl.cxx:223
AthenaBarCodeImpl::m_barcodeCounter
static std::atomic< AthenaBarCode_t > m_barcodeCounter
Definition: AthenaBarCodeImpl.h:109
AthenaBarCodeImpl::AthenaBarCodeImpl
AthenaBarCodeImpl()
Definition: AthenaBarCodeImpl.cxx:91
AthenaBarCodeImpl::m_barcode
std::atomic< AthenaBarCode_t > m_barcode
Definition: AthenaBarCodeImpl.h:110
AthenaBarCodeImpl::SUUIDBits
static const unsigned short SUUIDBits
Definition: AthenaBarCodeImpl.h:48
AthenaBarCodeImpl::hashUUID
static AthenaBarCode_t hashUUID(const char *)
Definition: AthenaBarCodeImpl.cxx:190
AthenaBarCodeImpl::UUIDBits
static const unsigned short UUIDBits
Definition: AthenaBarCodeImpl.h:43
AthenaBarCodeImpl
Definition: AthenaBarCodeImpl.h:37
AthenaBarCodeCnv_p1
Definition: AthenaBarCodeCnv_p1.h:20
AthenaBarCodeImpl::CounterBits
static const unsigned short CounterBits
Definition: AthenaBarCodeImpl.h:44
IAthenaBarCode.h
AthenaBarCodeImpl::SVersionBits
static const unsigned short SVersionBits
Definition: AthenaBarCodeImpl.h:50
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
AthenaBarCodeImpl::~AthenaBarCodeImpl
virtual ~AthenaBarCodeImpl()=default
AthenaBarCodeImpl::setUUIDHash
void setUUIDHash(AthenaBarCode_t uuidhash)
Definition: AthenaBarCodeImpl.h:114
AthenaBarCodeImpl::setBits
void setBits(unsigned short startbit, unsigned short nbits, AthenaBarCode_t id, AthenaBarCode_t &bc) const
Definition: AthenaBarCodeImpl.cxx:260
AthenaBarCodeImpl::getUUIDHash
AthenaBarCode_t getUUIDHash() const
Definition: AthenaBarCodeImpl.cxx:244
AthenaBarCodeImpl::setAthenaBarCode
void setAthenaBarCode(AthenaBarCode_t id)
Definition: AthenaBarCodeImpl.cxx:211
AthenaBarCodeImpl::hasUUIDHash
AthenaBarCode_t hasUUIDHash() const
Definition: AthenaBarCodeImpl.cxx:239
AthenaBarCode_t
uint64_t AthenaBarCode_t
barcode for all INav4Mom classes
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:44
AthenaBarCodeImpl::TotalBits
static const unsigned short TotalBits
Definition: AthenaBarCodeImpl.h:41
AthenaBarCodeImpl::newVersion
void newVersion()
Definition: AthenaBarCodeImpl.cxx:138
AthenaBarCodeImpl::getDefaultHash
static AthenaBarCode_t getDefaultHash(const char *jobid=nullptr)
Definition: AthenaBarCodeImpl.cxx:304
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
AthenaBarCodeImpl::getReserveBits
AthenaBarCode_t getReserveBits() const
Definition: AthenaBarCodeImpl.cxx:216
AthenaBarCodeImpl::hasSameAthenaBarCodeExceptVersion
bool hasSameAthenaBarCodeExceptVersion(const IAthenaBarCode &obj) const
Definition: AthenaBarCodeImpl.cxx:120
AthenaBarCodeImpl::SReserveBits
static const unsigned short SReserveBits
Definition: AthenaBarCodeImpl.h:51
AthenaBarCodeImpl::getBits
AthenaBarCode_t getBits(unsigned short startbit, unsigned short nbits) const
Definition: AthenaBarCodeImpl.cxx:249
AthenaBarCodeImpl::initABC
void initABC() const
Definition: AthenaBarCodeImpl.cxx:24
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
IAthenaBarCode
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:48
AthenaBarCodeImpl::SCounterBits
static const unsigned short SCounterBits
Definition: AthenaBarCodeImpl.h:49
AthenaBarCodeImpl::combineWithUUIDHash
AthenaBarCode_t combineWithUUIDHash(const AthenaBarCode_t &) const
Definition: AthenaBarCodeImpl.h:119
AthenaBarCodeImpl::getAthenaBarCode
AthenaBarCode_t getAthenaBarCode() const
Definition: AthenaBarCodeImpl.cxx:203
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
AthenaBarCodeImpl::hasSameAthenaBarCode
bool hasSameAthenaBarCode(const IAthenaBarCode &obj) const
Definition: AthenaBarCodeImpl.cxx:110
AthenaBarCodeImpl::makeDefaultHash
static AthenaBarCode_t makeDefaultHash(const char *jobid)
Definition: AthenaBarCodeImpl.cxx:312
AthenaBarCodeImpl::setDefaultHash
static void setDefaultHash(const char *jobid)
Definition: AthenaBarCodeImpl.cxx:298
AthenaBarCodeVersion_t
AthenaBarCode_t AthenaBarCodeVersion_t
Definition: AthenaKernel/AthenaKernel/IAthenaBarCode.h:46
AthenaBarCodeImpl::createdInCurrentJob
bool createdInCurrentJob() const
Definition: AthenaBarCodeImpl.cxx:181
AthenaBarCodeImpl::dump
std::ostream & dump(std::ostream &out) const
Definition: AthenaBarCodeImpl.cxx:172
python.PyAthena.obj
obj
Definition: PyAthena.py:135
AthenaBarCodeImpl::VersionBits
static const unsigned short VersionBits
Definition: AthenaBarCodeImpl.h:45
AthenaBarCodeImpl::setVersion
void setVersion(AthenaBarCodeVersion_t newversion)
Definition: AthenaBarCodeImpl.cxx:157
AthenaBarCodeImpl::operator=
AthenaBarCodeImpl & operator=(const AthenaBarCodeImpl &)
Definition: AthenaBarCodeImpl.cxx:101
AthenaBarCodeImpl::getVersion
AthenaBarCodeVersion_t getVersion() const
Definition: AthenaBarCodeImpl.cxx:131
AthenaBarCodeImpl::ReserveBits
static const unsigned short ReserveBits
Definition: AthenaBarCodeImpl.h:46