Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Token.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cstdio>
8 #include <cstring>
9 #include <climits>
10 #include <atomic>
11 
12 static const char* const fmt_clid = "[CLID=";
13 static const char* const fmt_tech = "[TECH=%08X]";
14 static const char* const fmt_oid = "[OID=%016llX-%016llX]";
15 static const char* const fmt_oid_old = "[OID=%08llX-%08llX]";
16 static const int KEY_MASK = (~0u) << CHAR_BIT;
17 static std::atomic<int> s_numCount { 0 };
18 
19 int Token::numInstances() { return s_numCount; }
20 
22 Token::Token() : m_refCount(1),
23  m_technology(0),
24  m_dbID(Guid::null()),
25  m_classID(Guid::null()),
26  m_oid(OID_t(~0x0LL, ~0x0LL)),
27  m_type(0) {
28  s_numCount++;
29 }
30 
32 Token::Token(const Token& copy) : m_refCount(1),
33  m_technology(copy.m_technology),
34  m_dbID(copy.m_dbID),
35  m_classID(copy.m_classID),
36  m_oid(copy.m_oid),
37  m_type(0) {
38  copy.setData(this);
39  s_numCount++;
40 }
41 
43 Token::Token(const Token* source) : m_refCount(1),
44  m_technology(0),
45  m_dbID(Guid::null()),
46  m_classID(Guid::null()),
47  m_oid(OID_t(~0x0LL, ~0x0LL)),
48  m_type(0) {
49  if (source != 0) {
50  source->setData(this);
51  }
52  s_numCount++;
53 }
54 
57  : m_refCount (1),
58  m_technology (source.m_technology),
59  m_dbID (std::move (source.m_dbID)),
60  m_cntID (std::move (source.m_cntID)),
61  m_classID (std::move (source.m_classID)),
62  m_oid (std::move (source.m_oid)),
64  m_auxString (std::move (source.m_auxString))
65 {
66  s_numCount++;
67 }
68 
69 
71  s_numCount--;
72 }
73 
76  int cnt = --m_refCount;
77  if (0 >= cnt) {
78  delete this;
79  }
80  return cnt;
81 }
82 
85  if (&copy != this) {
86  copy.setData(this);
87  }
88  return *this;
89 }
90 
92 bool Token::equal(const Token& copy) const {
93  if (&copy != this) {
94  if (m_oid.second == copy.m_oid.second) {
95  if (m_classID == copy.m_classID) {
96  if (m_dbID == copy.m_dbID) {
97  if (m_cntID == copy.m_cntID) {
98  return true;
99  }
100  }
101  }
102  }
103  return false;
104  }
105  return true;
106 }
107 
109 bool Token::less(const Token& copy) const {
110  if (&copy != this) {
111  if (m_oid.second < copy.m_oid.second)
112  return true;
113  else if (m_oid.second > copy.m_oid.second)
114  return false;
115  if (!(m_classID == copy.m_classID)) {
116  return (m_classID < copy.m_classID);
117  }
118  if (!(m_dbID == copy.m_dbID)) {
119  return (m_dbID < copy.m_dbID);
120  }
121  int res = m_cntID.compare(copy.m_cntID);
122  if (res != 0) {
123  return (res < 0);
124  }
125  }
126  return false;
127 }
128 
129 const std::string Token::toString() const {
130  char text1[128];
131  int s1 = sprintf(text1, fmt_tech, m_technology);
132  char text2[128];
133  int s2 = sprintf(text2, fmt_oid, m_oid.first, m_oid.second);
134  std::string str = "[DB=";
135  str.reserve(32);
136  str += m_dbID.toString();
137  str += "][CNT=";
138  str += m_cntID;
139  str += "][CLID=";
140  str += m_classID.toString();
141  str += ']';
142  str.append(text1, s1);
143  str.append(text2, s2);
144  str += m_auxString;
145  return str;
146 }
147 
148 Token& Token::fromString(const std::string& source) {
149  m_auxString.clear();
150  for (const char* p1 = source.c_str(); p1; p1 = ::strchr(++p1,'[')) {
151  const char* p2 = ::strchr(p1, '=');
152  const char* p3 = ::strchr(p1, ']');
153  if (p2 != 0 && p3 != 0) {
154  if (::strncmp("[DB=", p1, 4) == 0) {
155  m_dbID.fromString(p1 + 4);
156  } else if (::strncmp("[CNT=", p1, 5) == 0) {
157  m_cntID.assign (p2+1, p3-p2-1);
158  } else if (::strncmp(fmt_oid, p1, 5) == 0) {
159  long long unsigned int first, second;
160  if (::strncmp("]", p1 + 22, 1) == 0) { // 5 + 8(int) + 1(minus) + 8(int) = 22
161  ::sscanf(p1, fmt_oid_old, &first, &second);
162  if (int(first) == ~0x0) first = ~0x0LL;
163  if (int(second) == ~0x0) second = ~0x0LL;
164  } else {
165  ::sscanf(p1, fmt_oid, &first, &second);
166  }
167  m_oid.first = first;
168  m_oid.second = second;
169  } else if (::strncmp(fmt_clid, p1, 6) == 0) {
170  m_classID.fromString(p1 + 6);
171  } else if (::strncmp(fmt_tech, p1, 6) == 0) {
172  ::sscanf(p1, fmt_tech, &m_technology);
173  } else {
174  while (*(p2 + 1) == '[' && p3 && *(++p3) != 0 && *p3 != ']') {
175  p3 = ::strchr(p3, ']');
176  }
177  if (!p3) p3 = source.c_str() + source.size();
178  m_auxString.append (p1, p3-p1);
179  m_auxString += ']';
180  }
181  }
182  }
183  return *this;
184 }
185 
187 const std::string Token::key() const {
188  char text[1024];
189  int s = ::sprintf(text, "][TECH=%08X]", m_technology & KEY_MASK);
190  std::string k = "[DB=";
191  k += m_dbID.toString();
192  k += "][CNT=";
193  k += m_cntID;
194  k += "][CLID=";
195  k += m_classID.toString();
196  k.append(text, s);
197  return k;
198 }
199 
200 const Token& Token::set(Token* pToken) const {
201  pToken->m_technology = m_technology;
202  pToken->m_dbID = m_dbID;
203  pToken->m_cntID = m_cntID;
204  pToken->m_classID = m_classID;
205  pToken->m_oid.first = m_oid.first;
206  return *this;
207 }
208 
209 const Token& Token::setData(Token* pToken) const {
210  this->set(pToken);
211  pToken->m_oid.second = m_oid.second;
212  pToken->m_type = m_type;
213  pToken->m_auxString = m_auxString;
214  return *this;
215 }
Token::m_type
int m_type
Token type.
Definition: Token.h:123
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Token::m_dbID
Guid m_dbID
Database identifier.
Definition: Token.h:115
TRTCalib_cfilter.p1
p1
Definition: TRTCalib_cfilter.py:130
Guid::toString
const std::string toString() const
Automatic conversion to string representation.
Definition: Guid.cxx:58
Token::m_technology
unsigned int m_technology
Technology identifier.
Definition: Token.h:113
Token::less
virtual bool less(const Token &pTok) const
Fast token comparison: operator less.
Definition: Token.cxx:109
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
Token::m_classID
Guid m_classID
Object global identifier.
Definition: Token.h:119
Token::m_cntID
std::string m_cntID
Container identifier.
Definition: Token.h:117
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
Token::OID_t
Definition: Token.h:24
Token::fromString
Token & fromString(const std::string &from)
Build from the string representation of a token.
Definition: Token.cxx:148
TRTCalib_cfilter.p2
p2
Definition: TRTCalib_cfilter.py:131
Token::operator=
Token & operator=(const Token &copy)
No assignment allowed: put prototype to disable bit-wise assignment.
Definition: Token.cxx:84
Token::equal
virtual bool equal(const Token &pTok) const
Fast token comparison: operator equals.
Definition: Token.cxx:92
python.CaloAddPedShiftConfig.str
str
Definition: CaloAddPedShiftConfig.py:42
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
Token::release
int release()
Release token: Decrease reference count and eventually delete.
Definition: Token.cxx:75
Token::m_oid
OID_t m_oid
Persistent object identifier.
Definition: Token.h:121
Token::toString
virtual const std::string toString() const
Retrieve the string representation of the token.
Definition: Token.cxx:129
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
Token::~Token
virtual ~Token()
Standard destructor: release all allocated resources.
Definition: Token.cxx:70
Token::m_auxString
std::string m_auxString
Auxiliary string.
Definition: Token.h:125
trigbs_pickEvents.cnt
cnt
Definition: trigbs_pickEvents.py:71
Token::Token
Token()
Standard Constructor.
Definition: Token.cxx:22
DeMoScan.first
bool first
Definition: DeMoScan.py:536
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
Guid::fromString
const Guid & fromString(const std::string &s)
Automatic conversion from string representation.
Definition: Guid.cxx:65
makeTransCanvas.text
text
Definition: makeTransCanvas.py:11
copySelective.source
string source
Definition: copySelective.py:32
str
Definition: BTagTrackIpAccessor.cxx:11
calibdata.copy
bool copy
Definition: calibdata.py:27
Token::numInstances
static int numInstances()
expose Token instance counter for debugging
Definition: Token.cxx:19
Token::m_refCount
int m_refCount
Reference count.
Definition: Token.h:111
Token::setData
const Token & setData(Token *pToken) const
Set all the data part of the token.
Definition: Token.cxx:209
TRTCalib_cfilter.p3
p3
Definition: TRTCalib_cfilter.py:132
Token::set
const Token & set(Token *pToken) const
Set token information.
Definition: Token.cxx:200
Token.h
This file contains the class definition for the Token class (migrated from POOL).
fitman.k
k
Definition: fitman.py:528
Token::key
virtual const std::string key() const
Retrieve token key.
Definition: Token.cxx:187