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

This class provides a token that identifies in a unique way objects on the persistent storage. More...

#include <Token.h>

Collaboration diagram for Token:

Classes

struct  OID_t

Public Member Functions

 Token ()
 Standard Constructor.
 Token (const Token *source)
 Constructor with data assignment.
 Token (Token &&source) noexcept
 Allow move.
virtual ~Token ()
 Standard destructor: release all allocated resources.
bool operator< (const Token &refToken) const
 Operator < to allow ordering.
bool operator> (const Token &refToken) const
 Operator > to allow ordering.
bool operator== (const Token &refToken) const
 Equality operator.
bool operator!= (const Token &refToken) const
 Equality operator.
virtual bool less (const Token &pTok) const
 Fast token comparison: operator less.
virtual bool equal (const Token &pTok) const
 Fast token comparison: operator equals.
int release ()
 Release token: Decrease reference count and eventually delete.
int addRef ()
 Increase reference count.
const GuiddbID () const
 Access database identifier.
TokensetDb (const Guid &db)
 Set database name.
TokensetDb (const std::string &db)
const std::string & contID () const
 Access container identifier.
TokensetCont (const std::string &cnt)
 Set container name.
const GuidclassID () const
 Access database identifier.
TokensetClassID (const Guid &cl_id)
 Access database identifier.
int technology () const
 Access technology type.
TokensetTechnology (int t)
 Set technology type.
const OID_toid () const
 Access object identifier.
OID_toid ()
 Access object identifier.
TokensetOid (const OID_t &oid)
 Set object identifier.
int type () const
 Access token type.
TokensetType (int t)
 Set token type.
const std::string & auxString () const
 Access auxiliary string.
TokensetAuxString (std::string &&auxString)
 Set auxiliary string.
void setAuxString (std::string_view auxString)
virtual const std::string toString () const
 Retrieve the string representation of the token.
virtual const std::string key () const
 Retrieve token key.
TokenfromString (const std::string_view from)
 Build from the string representation of a token.
const Tokenset (Token *pToken) const
 Set token information.
const TokensetData (Token *pToken) const
 Set all the data part of the token.

Static Public Member Functions

static int numInstances ()
 expose Token instance counter for debugging

Private Member Functions

 Token (const Token &copy)
 No copy allowed: put prototype to disable bit-wise copy.
Tokenoperator= (const Token &copy)
 No assignment allowed: put prototype to disable bit-wise assignment.

Private Attributes

int m_refCount
 Reference count.
unsigned int m_technology
 Technology identifier.
Guid m_dbID
 Database identifier.
std::string m_cntID
 Container identifier.
Guid m_classID
 Object global identifier.
OID_t m_oid
 Persistent object identifier.
int m_type
 Token type.
std::string m_auxString
 Auxiliary string.

Detailed Description

This class provides a token that identifies in a unique way objects on the persistent storage.

Definition at line 22 of file Token.h.

Constructor & Destructor Documentation

◆ Token() [1/4]

Token::Token ( const Token & copy)
private

No copy allowed: put prototype to disable bit-wise copy.

Copy constructor.

Definition at line 38 of file Token.cxx.

38 : m_refCount(1),
39 m_technology(copy.m_technology),
40 m_dbID(copy.m_dbID),
41 m_classID(copy.m_classID),
42 m_oid(copy.m_oid),
43 m_type(0) {
44 copy.setData(this);
45 s_numCount.fetch_add(1, std::memory_order_relaxed);
46}
static std::atomic< int > s_numCount
Definition Token.cxx:23
int m_refCount
Reference count.
Definition Token.h:113
Guid m_classID
Object global identifier.
Definition Token.h:121
unsigned int m_technology
Technology identifier.
Definition Token.h:115
OID_t m_oid
Persistent object identifier.
Definition Token.h:123
int m_type
Token type.
Definition Token.h:125
Guid m_dbID
Database identifier.
Definition Token.h:117
bool copy
Definition calibdata.py:26

◆ Token() [2/4]

Token::Token ( )

Standard Constructor.

Standard Constructor(1): Empty constructor.

Definition at line 28 of file Token.cxx.

28 : m_refCount(1),
29 m_technology(0),
32 m_oid(OID_t(~0x0LL, ~0x0LL)),
33 m_type(0) {
34 s_numCount.fetch_add(1, std::memory_order_relaxed);
35}
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition Guid.cxx:14

◆ Token() [3/4]

Token::Token ( const Token * source)
explicit

Constructor with data assignment.

Copy constructor.

Definition at line 49 of file Token.cxx.

49 : m_refCount(1),
50 m_technology(0),
53 m_oid(OID_t(~0x0LL, ~0x0LL)),
54 m_type(0) {
55 if (source != 0) {
56 source->setData(this);
57 }
58 s_numCount.fetch_add(1, std::memory_order_relaxed);
59}

◆ Token() [4/4]

Token::Token ( Token && source)
explicitnoexcept

Allow move.

Move constructor.

Definition at line 62 of file Token.cxx.

63 : m_refCount (1),
64 m_technology (source.m_technology),
65 m_dbID (std::move (source.m_dbID)),
66 m_cntID (std::move (source.m_cntID)),
67 m_classID (std::move (source.m_classID)),
68 m_oid (std::move (source.m_oid)),
69 m_type (source.m_type),
70 m_auxString (std::move (source.m_auxString))
71{
72 s_numCount.fetch_add(1, std::memory_order_relaxed);
73}
std::string m_auxString
Auxiliary string.
Definition Token.h:127
std::string m_cntID
Container identifier.
Definition Token.h:119

◆ ~Token()

Token::~Token ( )
virtual

Standard destructor: release all allocated resources.

Definition at line 76 of file Token.cxx.

76 {
77 s_numCount.fetch_sub(1, std::memory_order_relaxed);
78}

Member Function Documentation

◆ addRef()

int Token::addRef ( )
inline

Increase reference count.

Definition at line 63 of file Token.h.

63{ return ++m_refCount; }

◆ auxString()

const std::string & Token::auxString ( ) const
inline

Access auxiliary string.

Definition at line 92 of file Token.h.

92{ return m_auxString; }

◆ classID()

const Guid & Token::classID ( ) const
inline

Access database identifier.

Definition at line 74 of file Token.h.

74{ return m_classID; }

◆ contID()

const std::string & Token::contID ( ) const
inline

Access container identifier.

Definition at line 70 of file Token.h.

70{ return m_cntID; }

◆ dbID()

const Guid & Token::dbID ( ) const
inline

Access database identifier.

Definition at line 65 of file Token.h.

65{ return m_dbID; }

◆ equal()

bool Token::equal ( const Token & pTok) const
virtual

Fast token comparison: operator equals.

Equality operator.

Definition at line 98 of file Token.cxx.

98 {
99 if (&copy != this) {
100 if (m_oid.second == copy.m_oid.second) {
101 if (m_classID == copy.m_classID) {
102 if (m_dbID == copy.m_dbID) {
103 if (m_cntID == copy.m_cntID) {
104 return true;
105 }
106 }
107 }
108 }
109 return false;
110 }
111 return true;
112}

◆ fromString()

Token & Token::fromString ( const std::string_view from)

Build from the string representation of a token.

Definition at line 169 of file Token.cxx.

169 {
170 m_auxString.clear();
171 size_t pos = 0;
172 while (pos < src.size()) {
173 size_t start = src.find('[', pos);
174 if (start == std::string_view::npos) break;
175 size_t eq = src.find('=', start);
176 size_t end = src.find(']', start);
177 if (eq != std::string_view::npos && end != std::string_view::npos) {
178 std::string_view label = src.substr(start, eq - start + 1);
179 if (label == LABEL_DB) {
180 m_dbID.fromString(src.substr(eq + 1, end - eq - 1));
181 } else if (label == LABEL_CNT) {
182 m_cntID = std::string(src.substr(eq + 1, end - eq - 1));
183 } else if (label == LABEL_CLID) {
184 m_classID.fromString(src.substr(eq + 1, end - eq - 1));
185 } else if (label == LABEL_TECH) {
186 std::string_view num_str = src.substr(eq + 1, end - eq - 1);
187 int tech = 0;
188 std::from_chars(num_str.data(), num_str.data() + num_str.size(), tech, 16);
189 m_technology = tech;
190 } else if (label == LABEL_OID) {
191 std::string_view oid_str = src.substr(eq + 1, end - eq - 1);
192 size_t dash = oid_str.find('-');
193 if (dash != std::string_view::npos) {
194 std::string_view first_str = oid_str.substr(0, dash);
195 std::string_view second_str = oid_str.substr(dash + 1);
196
197 // Check if this is legacy format (8 digits) vs modern format (16 digits)
198 // Legacy format: 5 + 8 + 1 + 8 + 1 = 23 characters total for [OID=XXXXXXXX-XXXXXXXX]
199 // Modern format: 5 + 16 + 1 + 16 + 1 = 39 characters total for [OID=XXXXXXXXXXXXXXXX-XXXXXXXXXXXXXXXX]
200 bool is_legacy = (end - start + 1) == 23; // Total bracket length check
201
202 uint64_t first = 0;
203 uint64_t second = 0;
204 std::from_chars(first_str.data(), first_str.data() + first_str.size(), first, 16);
205 std::from_chars(second_str.data(), second_str.data() + second_str.size(), second, 16);
206
207 if (is_legacy) {
208 // Handle legacy format: extend 32-bit ~0x0 to 64-bit ~0x0LL
209 if (static_cast<uint32_t>(first) == ~0x0U) first = ~0x0ULL;
210 if (static_cast<uint32_t>(second) == ~0x0U) second = ~0x0ULL;
211 }
212
213 m_oid.first = static_cast<long long int>(first);
214 m_oid.second = static_cast<long long int>(second);
215 }
216 } else {
217 m_auxString += src.substr(start, end - start + 1);
218 }
219 pos = end + 1;
220 } else {
221 break;
222 }
223 }
224 return *this;
225}
constexpr std::string_view LABEL_DB
Definition Token.cxx:16
constexpr std::string_view LABEL_TECH
Definition Token.cxx:19
constexpr std::string_view LABEL_CLID
Definition Token.cxx:18
constexpr std::string_view LABEL_CNT
Definition Token.cxx:17
constexpr std::string_view LABEL_OID
Definition Token.cxx:20
std::string label(const std::string &format, int i)
Definition label.h:19
bool first
Definition DeMoScan.py:534
setEventNumber uint32_t

◆ key()

const std::string Token::key ( ) const
virtual

Retrieve token key.

Retrieve the string representation of the token.

Definition at line 228 of file Token.cxx.

228 {
229 //Do not replace with std::format unless it is found to be more performant
230 // m_technology & KEY_MASK yields an unsigned int -> 8 hex digits
231 CxxUtils::HexString<"[TECH={}]"> techHex(m_technology & KEY_MASK);
232
233 std::string res;
234 // "[DB=" (4) + Guid (36) + "][CNT=" (6) + CNT + "][CLID=" (7) + Guid (36) + "]" (1)
235 res.reserve(4 + 36 + 6 + m_cntID.size() + 7 + 36 + 1 + techHex.size());
236
237 res += "[DB=";
238 size_t pos = res.size();
239 res.resize(pos + 36);
240 m_dbID.toString(std::span<char, 36>(res.data() + pos, 36));
241
242 res += "][CNT=";
243 res += m_cntID;
244
245 res += "][CLID=";
246 pos = res.size();
247 res.resize(pos + 36);
248 m_classID.toString(std::span<char, 36>(res.data() + pos, 36));
249 res += ']';
250
251 res += static_cast<std::string_view>(techHex);
252
253 return res;
254}
std::pair< std::vector< unsigned int >, bool > res
static const int KEY_MASK
Definition Token.cxx:22

◆ less()

bool Token::less ( const Token & pTok) const
virtual

Fast token comparison: operator less.

Operator to allow ordering.

Definition at line 115 of file Token.cxx.

115 {
116 if (&copy != this) {
117 if (m_oid.second < copy.m_oid.second)
118 return true;
119 else if (m_oid.second > copy.m_oid.second)
120 return false;
121 if (!(m_classID == copy.m_classID)) {
122 return (m_classID < copy.m_classID);
123 }
124 if (!(m_dbID == copy.m_dbID)) {
125 return (m_dbID < copy.m_dbID);
126 }
127 int res = m_cntID.compare(copy.m_cntID);
128 if (res != 0) {
129 return (res < 0);
130 }
131 }
132 return false;
133}

◆ numInstances()

int Token::numInstances ( )
static

expose Token instance counter for debugging

Definition at line 25 of file Token.cxx.

25{ return s_numCount; }

◆ oid() [1/2]

OID_t & Token::oid ( )
inline

Access object identifier.

Definition at line 84 of file Token.h.

84{ return m_oid; }

◆ oid() [2/2]

const OID_t & Token::oid ( ) const
inline

Access object identifier.

Definition at line 82 of file Token.h.

82{ return m_oid; }

◆ operator!=()

bool Token::operator!= ( const Token & refToken) const
inline

Equality operator.

Definition at line 55 of file Token.h.

55{ return !equal(refToken); }
virtual bool equal(const Token &pTok) const
Fast token comparison: operator equals.
Definition Token.cxx:98

◆ operator<()

bool Token::operator< ( const Token & refToken) const
inline

Operator < to allow ordering.

Definition at line 46 of file Token.h.

46{ return less(refToken); }
virtual bool less(const Token &pTok) const
Fast token comparison: operator less.
Definition Token.cxx:115

◆ operator=()

Token & Token::operator= ( const Token & copy)
private

No assignment allowed: put prototype to disable bit-wise assignment.

Assignment operator.

Definition at line 90 of file Token.cxx.

90 {
91 if (&copy != this) {
92 copy.setData(this);
93 }
94 return *this;
95}

◆ operator==()

bool Token::operator== ( const Token & refToken) const
inline

Equality operator.

Definition at line 53 of file Token.h.

53{ return equal(refToken); }

◆ operator>()

bool Token::operator> ( const Token & refToken) const
inline

Operator > to allow ordering.

Definition at line 48 of file Token.h.

48 {
49 if (less(refToken)) return false;
50 return !equal(refToken);
51 }

◆ release()

int Token::release ( )

Release token: Decrease reference count and eventually delete.

Definition at line 81 of file Token.cxx.

81 {
82 int cnt = --m_refCount;
83 if (0 >= cnt) {
84 delete this;
85 }
86 return cnt;
87}

◆ set()

const Token & Token::set ( Token * pToken) const

Set token information.

Definition at line 256 of file Token.cxx.

256 {
257 pToken->m_technology = m_technology;
258 pToken->m_dbID = m_dbID;
259 pToken->m_cntID = m_cntID;
260 pToken->m_classID = m_classID;
261 pToken->m_oid.first = m_oid.first;
262 return *this;
263}

◆ setAuxString() [1/2]

Token & Token::setAuxString ( std::string && auxString)
inline

Set auxiliary string.

Definition at line 94 of file Token.h.

94{ m_auxString = std::move(auxString); return *this; }
const std::string & auxString() const
Access auxiliary string.
Definition Token.h:92

◆ setAuxString() [2/2]

void Token::setAuxString ( std::string_view auxString)
inline

Definition at line 95 of file Token.h.

◆ setClassID()

Token & Token::setClassID ( const Guid & cl_id)
inline

Access database identifier.

Definition at line 76 of file Token.h.

76{ m_classID = cl_id; return *this; }

◆ setCont()

Token & Token::setCont ( const std::string & cnt)
inline

Set container name.

Definition at line 72 of file Token.h.

72{ m_cntID = cnt; return *this; }

◆ setData()

const Token & Token::setData ( Token * pToken) const

Set all the data part of the token.

Definition at line 265 of file Token.cxx.

265 {
266 this->set(pToken);
267 pToken->m_oid.second = m_oid.second;
268 pToken->m_type = m_type;
269 pToken->m_auxString = m_auxString;
270 return *this;
271}
const Token & set(Token *pToken) const
Set token information.
Definition Token.cxx:256

◆ setDb() [1/2]

Token & Token::setDb ( const Guid & db)
inline

Set database name.

Definition at line 67 of file Token.h.

◆ setDb() [2/2]

Token & Token::setDb ( const std::string & db)
inline

Definition at line 68 of file Token.h.

68{ m_dbID.fromString(db); return *this; }

◆ setOid()

Token & Token::setOid ( const OID_t & oid)
inline

Set object identifier.

Definition at line 86 of file Token.h.

86{ m_oid = oid; return *this; }
const OID_t & oid() const
Access object identifier.
Definition Token.h:82

◆ setTechnology()

Token & Token::setTechnology ( int t)
inline

Set technology type.

Definition at line 80 of file Token.h.

80{ m_technology = t; return *this; }

◆ setType()

Token & Token::setType ( int t)
inline

Set token type.

Definition at line 90 of file Token.h.

90{ m_type = t; return *this; }

◆ technology()

int Token::technology ( ) const
inline

Access technology type.

Definition at line 78 of file Token.h.

78{ return m_technology; }

◆ toString()

const std::string Token::toString ( ) const
virtual

Retrieve the string representation of the token.

Definition at line 135 of file Token.cxx.

135 {
136// Pre-compute the hex representations using the format strings
137 CxxUtils::HexString<"[TECH={}]"> techHex(m_technology);
138 CxxUtils::HexString<"[OID={}-"> oid1Hex(static_cast<uint64_t>(m_oid.first));
139 CxxUtils::HexString<"{}]"> oid2Hex(static_cast<uint64_t>(m_oid.second));
140
141 std::string res;
142 // Reserve exact capacity to prevent reallocations.
143 // "[DB=" (4) + Guid (36) + "][CNT=" (6) + CNT + "][CLID=" (7) + Guid (36) + "]" (1)
144 res.reserve(4 + 36 + 6 + m_cntID.size() + 7 + 36 + 1 +
145 techHex.size() + oid1Hex.size() + oid2Hex.size() + m_auxString.size());
146
147 res += "[DB=";
148 size_t pos = res.size();
149 res.resize(pos + 36);
150 m_dbID.toString(std::span<char, 36>(res.data() + pos, 36));
151
152 res += "][CNT=";
153 res += m_cntID;
154
155 res += "][CLID=";
156 pos = res.size();
157 res.resize(pos + 36);
158 m_classID.toString(std::span<char, 36>(res.data() + pos, 36));
159 res += ']';
160
161 res += static_cast<std::string_view>(techHex);
162 res += static_cast<std::string_view>(oid1Hex);
163 res += static_cast<std::string_view>(oid2Hex);
164 res += m_auxString;
165
166 return res;
167}

◆ type()

int Token::type ( ) const
inline

Access token type.

Definition at line 88 of file Token.h.

88{ return m_type; }

Member Data Documentation

◆ m_auxString

std::string Token::m_auxString
private

Auxiliary string.

Definition at line 127 of file Token.h.

◆ m_classID

Guid Token::m_classID
private

Object global identifier.

Definition at line 121 of file Token.h.

◆ m_cntID

std::string Token::m_cntID
private

Container identifier.

Definition at line 119 of file Token.h.

◆ m_dbID

Guid Token::m_dbID
private

Database identifier.

Definition at line 117 of file Token.h.

◆ m_oid

OID_t Token::m_oid
private

Persistent object identifier.

Definition at line 123 of file Token.h.

◆ m_refCount

int Token::m_refCount
private

Reference count.

Definition at line 113 of file Token.h.

◆ m_technology

unsigned int Token::m_technology
private

Technology identifier.

Definition at line 115 of file Token.h.

◆ m_type

int Token::m_type
private

Token type.

Definition at line 125 of file Token.h.


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