ATLAS Offline Software
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Guid Class Reference

This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number). More...

#include <Guid.h>

Collaboration diagram for Guid:

Public Types

enum  GuidGenMethod { GuidGenDefault, GuidGenRandom, GuidGenByTime }
 

Public Member Functions

constexpr Guid ()
 Standard constructor. More...
 
 Guid (bool assign)
 Standard constructor (With possible initialization) More...
 
constexpr Guid (std::string_view s)
 Constructor for Guid from string_view. More...
 
constexpr Guid (const char *s)
 
 Guid (const Guid &c)=default
 Copy constructor. More...
 
Guidoperator= (const Guid &c)=default
 
auto operator (const Guid &) const =default
 Magic spaceship operator. More...
 
bool operator== (const Guid &) const =default
 
bool operator== (std::string_view str) const
 
constexpr void toString (std::span< char, 36 > buf, bool uppercase=true) const noexcept
 Automatic conversion to string representation. More...
 
constexpr std::string toString (bool uppercase=true) const
 
constexpr GuidfromString (std::string_view s)
 Automatic conversion from string representation. More...
 
unsigned int data1 () const
 Allow accessors to member data. More...
 
unsigned short data2 () const
 
unsigned short data3 () const
 
unsigned char data4 (unsigned int i) const
 
void setData1 (unsigned int data)
 Allow modifiers for member data. More...
 
void setData2 (unsigned short data)
 
void setData3 (unsigned short data)
 
void setData4 (unsigned char data, unsigned int i)
 

Static Public Member Functions

static bool isGuid (std::string_view) noexcept
 
static const Guidnull () noexcept
 NULL-Guid: static class method. More...
 
static GuidGenMethod initGuidGenMethod ()
 Checks for POOL_GUID_TIME or POOL_GUID_RANDOM env variables. More...
 
static void create (Guid &guid, GuidGenMethod method=GuidGenDefault)
 Create a new Guid default method is currently Random, can be changed by param, API or environment. More...
 

Static Public Attributes

static const GuidGenMethod m_guidGenMethod = Guid::initGuidGenMethod()
 

Private Member Functions

constexpr void setToNull () noexcept
 

Private Attributes

unsigned int m_data1 {}
 
unsigned short m_data2 {}
 
unsigned short m_data3 {}
 
std::array< unsigned char, 8 > m_data4 {}
 

Friends

bool operator== (std::string_view str, const Guid &rhs)
 Equality operator. More...
 
bool operator!= (std::string_view str, const Guid &rhs)
 Non-equality operator. More...
 
std::ostream & operator<< (std::ostream &os, const Guid &rhs)
 Extraction operators. More...
 

Detailed Description

This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).

Definition at line 24 of file Guid.h.

Member Enumeration Documentation

◆ GuidGenMethod

Enumerator
GuidGenDefault 
GuidGenRandom 
GuidGenByTime 

Definition at line 55 of file Guid.h.

Constructor & Destructor Documentation

◆ Guid() [1/5]

constexpr Guid::Guid ( )
inlineconstexpr

Standard constructor.

Definition at line 27 of file Guid.h.

27 : m_data1(0U), m_data2(0U), m_data3(0U), m_data4() {}

◆ Guid() [2/5]

Guid::Guid ( bool  assign)
inlineexplicit

Standard constructor (With possible initialization)

Definition at line 29 of file Guid.h.

29 : Guid() { if (assign) create(*this); }

◆ Guid() [3/5]

constexpr Guid::Guid ( std::string_view  s)
inlineconstexpr

Constructor for Guid from string_view.

Definition at line 31 of file Guid.h.

31 { fromString(s); }

◆ Guid() [4/5]

constexpr Guid::Guid ( const char *  s)
inlineconstexpr

Definition at line 33 of file Guid.h.

33 { fromString(s); }

◆ Guid() [5/5]

Guid::Guid ( const Guid c)
default

Copy constructor.

Member Function Documentation

◆ create()

void Guid::create ( Guid guid,
GuidGenMethod  method = GuidGenDefault 
)
static

Create a new Guid default method is currently Random, can be changed by param, API or environment.

Create a new Guid.

Definition at line 29 of file Guid.cxx.

29  {
30  uuid_t me_;
32  switch(method) {
33  case GuidGenRandom:
34  ::uuid_generate(me_);
35  break;
36  case GuidGenByTime:
37  ::uuid_generate_time(me_);
38  break;
39  default:
40  ::uuid_generate(me_);
41  break;
42  }
43  unsigned int *d1 = (unsigned int*)me_;
44  unsigned short *d2 = (unsigned short*)(me_ + 4);
45  unsigned short *d3 = (unsigned short*)(me_ + 6);
46  guid.m_data1 = *d1;
47  guid.m_data2 = *d2;
48  guid.m_data3 = *d3;
49  for (unsigned int i = 0; i < 8; i++) {
50  guid.m_data4[i] = me_[i + 8];
51  }
52 }

◆ data1()

unsigned int Guid::data1 ( ) const
inline

Allow accessors to member data.

Definition at line 65 of file Guid.h.

65 { return m_data1; }

◆ data2()

unsigned short Guid::data2 ( ) const
inline

Definition at line 66 of file Guid.h.

66 { return m_data2; }

◆ data3()

unsigned short Guid::data3 ( ) const
inline

Definition at line 67 of file Guid.h.

67 { return m_data3; }

◆ data4()

unsigned char Guid::data4 ( unsigned int  i) const
inline

Definition at line 68 of file Guid.h.

68 { if (i < 8) return m_data4[i]; return 0; }

◆ fromString()

constexpr Guid & Guid::fromString ( std::string_view  s)
constexpr

Automatic conversion from string representation.

Definition at line 99 of file Guid.h.

99  {
100  // Trim any whitespace
101  if(std::is_constant_evaluated() && std::min(sv.find_first_not_of(' '), sv.size()) > 0){
102  throw std::runtime_error("Remove spaces from GUID");
103  }
104  sv.remove_prefix(std::min(sv.find_first_not_of(' '), sv.size()));
105  auto last_non_space = sv.find_last_not_of(' ');
106  if (last_non_space == std::string_view::npos) {
107  sv = {}; // String is empty or all spaces
108  } else {
109  if(std::is_constant_evaluated() && (sv.size() - last_non_space - 1)!=0){
110  throw std::runtime_error("Remove spaces from GUID");
111  }
112  sv.remove_suffix(sv.size() - last_non_space - 1);
113  }
114 
115  // Validate format
116  if (sv.size() != 36 ||
117  sv[8] != '-' || sv[13] != '-' || sv[18] != '-' || sv[23] != '-') {
118  setToNull();
119  if(std::is_constant_evaluated()){
120  throw std::runtime_error("failed to compile time parse GUID");
121  }
122  return *this;
123  }
124  bool success = true;
125  // Custom constexpr hex parser
126  auto parse_hex = [&success](std::string_view part) -> unsigned long long {
127  unsigned long long val = 0;
128  for (char c : part) {
129  val <<= 4; // Multiply by 16
130  if (c >= '0' && c <= '9') {
131  val += static_cast<unsigned long long>(c - '0');
132  } else if (c >= 'a' && c <= 'f') {
133  val += static_cast<unsigned long long>(10 + c - 'a');
134  } else if (c >= 'A' && c <= 'F') {
135  val += static_cast<unsigned long long>(10 + c - 'A');
136  } else {
137  success = false;
138  return 0;
139  }
140  }
141  return val;
142  };
143 
144  // Parse m_data1 (positions 0-7)
145  m_data1 = static_cast<unsigned int>(parse_hex(sv.substr(0, 8)));
146 
147  // Parse m_data2 (positions 9-12)
148  m_data2 = static_cast<unsigned short>(parse_hex(sv.substr(9, 4)));
149 
150  // Parse m_data3 (positions 14-17)
151  m_data3 = static_cast<unsigned short>(parse_hex(sv.substr(14, 4)));
152 
153 
154  // Parse m_data4 bytes
155  int pos = 19;
156  for(int i =0; i< 2; i++){
157  auto val = parse_hex(sv.substr(pos, 2));
158  m_data4[i] = static_cast<unsigned char>(val);
159  pos+=2;
160  }
161  //Skip the dash at pos 23
162  pos = 24;
163  for(int i =2; i< 8; i++){
164  auto val = parse_hex(sv.substr(pos, 2));
165  m_data4[i] = static_cast<unsigned char>(val);
166  pos+=2;
167  }
168 
169  if (!success) {
170  setToNull();
171  if(std::is_constant_evaluated()){
172  throw std::runtime_error("failed to compile time parse GUID");
173  }
174  }
175  return *this;
176 }

◆ initGuidGenMethod()

Guid::GuidGenMethod Guid::initGuidGenMethod ( )
static

Checks for POOL_GUID_TIME or POOL_GUID_RANDOM env variables.

Definition at line 20 of file Guid.cxx.

20  {
21  char* envv = getenv("POOL_GUID_TIME");
22  if (envv != 0 && *envv) return GuidGenByTime;
23  envv = getenv("POOL_GUID_RANDOM");
24  if (envv != 0 && *envv) return GuidGenRandom;
25  return GuidGenDefault;
26 }

◆ isGuid()

bool Guid::isGuid ( std::string_view  sv)
staticnoexcept

Definition at line 54 of file Guid.cxx.

54  {
55  // The GUID must be exactly 36 characters long
56  if (sv.size() != 36) {
57  return false;
58  }
59 
60  // Check for hyphens at specific positions (0-based indices: 8, 13, 18, 23)
61  if (sv[8] != '-' || sv[13] != '-' || sv[18] != '-' || sv[23] != '-') {
62  return false;
63  }
64 
65  // Validate that all other characters are hexadecimal digits (0-9, a-f, A-F)
66  for (size_t i = 0; i < 36; ++i) {
67  // Skip hyphen positions
68  if (i == 8 || i == 13 || i == 18 || i == 23) {
69  continue;
70  }
71 
72  char c = sv[i];
73  // Check if it's a valid hex digit
74  if (!((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'))) {
75  return false;
76  }
77  }
78  return true;
79 }

◆ null()

const Guid & Guid::null ( )
staticnoexcept

NULL-Guid: static class method.

Definition at line 14 of file Guid.cxx.

14  {
15  return clid_null;
16 }

◆ operator()

auto Guid::operator ( const Guid ) const
default

Magic spaceship operator.

◆ operator=()

Guid& Guid::operator= ( const Guid c)
default

◆ operator==() [1/2]

bool Guid::operator== ( const Guid ) const
default

◆ operator==() [2/2]

bool Guid::operator== ( std::string_view  str) const

Definition at line 81 of file Guid.cxx.

81  {
82  return str.size() == 36 && *this == Guid(str);
83 }

◆ setData1()

void Guid::setData1 ( unsigned int  data)
inline

Allow modifiers for member data.

Definition at line 71 of file Guid.h.

71 { m_data1 = data; }

◆ setData2()

void Guid::setData2 ( unsigned short  data)
inline

Definition at line 72 of file Guid.h.

72 { m_data2 = data; }

◆ setData3()

void Guid::setData3 ( unsigned short  data)
inline

Definition at line 73 of file Guid.h.

73 { m_data3 = data; }

◆ setData4()

void Guid::setData4 ( unsigned char  data,
unsigned int  i 
)
inline

Definition at line 74 of file Guid.h.

74 { if (i < 8) m_data4[i] = data; }

◆ setToNull()

constexpr void Guid::setToNull ( )
constexprprivatenoexcept

Definition at line 91 of file Guid.h.

91  {
92  m_data1 = 0U;
93  m_data2 = 0U;
94  m_data3 = 0U;
95  m_data4.fill('\0');
96 }

◆ toString() [1/2]

constexpr std::string Guid::toString ( bool  uppercase = true) const
inlineconstexpr

Definition at line 44 of file Guid.h.

44  {
45  std::string buf(36, ' ');
46  toString(std::span<char, 36>(buf.data(), 36), uppercase);
47  return buf;
48  }

◆ toString() [2/2]

constexpr void Guid::toString ( std::span< char, 36 >  buf,
bool  uppercase = true 
) const
constexprnoexcept

Automatic conversion to string representation.

Definition at line 179 of file Guid.h.

179  {
180 
181  constexpr char lowhex[] = "0123456789abcdef";
182  constexpr char uphex[] = "0123456789ABCDEF";
183  const char *hex = uppercase ? uphex : lowhex;
184 
185  // Unrolled for m_data1 (8 hex digits)
186  unsigned int v1 = m_data1;
187  buf[0] = hex[(v1 >> 28) & 0xF];
188  buf[1] = hex[(v1 >> 24) & 0xF];
189  buf[2] = hex[(v1 >> 20) & 0xF];
190  buf[3] = hex[(v1 >> 16) & 0xF];
191  buf[4] = hex[(v1 >> 12) & 0xF];
192  buf[5] = hex[(v1 >> 8) & 0xF];
193  buf[6] = hex[(v1 >> 4) & 0xF];
194  buf[7] = hex[v1 & 0xF];
195  buf[8] = '-';
196 
197  // Unrolled for m_data2 (4 hex digits)
198  unsigned short v2 = m_data2;
199  buf[9] = hex[(v2 >> 12) & 0xF];
200  buf[10] = hex[(v2 >> 8) & 0xF];
201  buf[11] = hex[(v2 >> 4) & 0xF];
202  buf[12] = hex[v2 & 0xF];
203  buf[13] = '-';
204 
205  // Unrolled for m_data3 (4 hex digits)
206  unsigned short v3 = m_data3;
207  buf[14] = hex[(v3 >> 12) & 0xF];
208  buf[15] = hex[(v3 >> 8) & 0xF];
209  buf[16] = hex[(v3 >> 4) & 0xF];
210  buf[17] = hex[v3 & 0xF];
211  buf[18] = '-';
212 
213  // Unrolled for m_data4[0] and [1] (2+2 hex digits)
214  int pos = 19;
215  for(int i =0; i<2;i++){
216  unsigned char c = m_data4[i];
217  buf[pos] = hex[c >> 4];
218  buf[pos+1] = hex[c & 0xF];
219  pos +=2;
220  }
221  buf[23] = '-';
222  pos = 24;
223  // Unrolled for remaining m_data4[2..7] (6 pairs of hex digits)
224  for(int i =2; i<8;i++){
225  unsigned char c = m_data4[i];
226  buf[pos] = hex[c >> 4];
227  buf[pos+1] = hex[c & 0xF];
228  pos +=2;
229  }
230 
231 }

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( std::string_view  str,
const Guid rhs 
)
friend

Non-equality operator.

Definition at line 79 of file Guid.h.

79 { return !(rhs.operator==(str)); }

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const Guid rhs 
)
friend

Extraction operators.

Definition at line 86 of file Guid.cxx.

86  {
87  std::array<char, 36> buff;
88  rhs.toString(buff);
89  os.write(buff.data(), 36);
90  return os;
91 }

◆ operator==

bool operator== ( std::string_view  str,
const Guid rhs 
)
friend

Equality operator.

Definition at line 77 of file Guid.h.

77 { return (rhs.operator==(str)); }

Member Data Documentation

◆ m_data1

unsigned int Guid::m_data1 {}
private

Definition at line 85 of file Guid.h.

◆ m_data2

unsigned short Guid::m_data2 {}
private

Definition at line 86 of file Guid.h.

◆ m_data3

unsigned short Guid::m_data3 {}
private

Definition at line 87 of file Guid.h.

◆ m_data4

std::array<unsigned char,8> Guid::m_data4 {}
private

Definition at line 88 of file Guid.h.

◆ m_guidGenMethod

const Guid::GuidGenMethod Guid::m_guidGenMethod = Guid::initGuidGenMethod()
static

Definition at line 56 of file Guid.h.


The documentation for this class was generated from the following files:
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
get_hdefs.buff
buff
Definition: get_hdefs.py:61
Guid::toString
constexpr void toString(std::span< char, 36 > buf, bool uppercase=true) const noexcept
Automatic conversion to string representation.
Definition: Guid.h:179
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
Guid::Guid
constexpr Guid()
Standard constructor.
Definition: Guid.h:27
Guid::setToNull
constexpr void setToNull() noexcept
Definition: Guid.h:91
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
Guid::m_data3
unsigned short m_data3
Definition: Guid.h:87
Guid::GuidGenByTime
@ GuidGenByTime
Definition: Guid.h:55
Guid::create
static void create(Guid &guid, GuidGenMethod method=GuidGenDefault)
Create a new Guid default method is currently Random, can be changed by param, API or environment.
Definition: Guid.cxx:29
Guid::GuidGenRandom
@ GuidGenRandom
Definition: Guid.h:55
Guid::operator
auto operator(const Guid &) const =default
Magic spaceship operator.
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:26
Guid::GuidGenDefault
@ GuidGenDefault
Definition: Guid.h:55
python.CaloAddPedShiftConfig.str
str
Definition: CaloAddPedShiftConfig.py:42
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
pool_uuid.guid
guid
Definition: pool_uuid.py:112
Guid::m_data1
unsigned int m_data1
Definition: Guid.h:85
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
ReadCellNoiseFromCoolCompare.v2
v2
Definition: ReadCellNoiseFromCoolCompare.py:364
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
Guid::m_guidGenMethod
static const GuidGenMethod m_guidGenMethod
Definition: Guid.h:56
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
LArCellConditions.sv
bool sv
Definition: LArCellConditions.py:45
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147
str
Definition: BTagTrackIpAccessor.cxx:11
Guid::m_data4
std::array< unsigned char, 8 > m_data4
Definition: Guid.h:88
Guid::m_data2
unsigned short m_data2
Definition: Guid.h:86
python.compressB64.c
def c
Definition: compressB64.py:93
Guid::fromString
constexpr Guid & fromString(std::string_view s)
Automatic conversion from string representation.
Definition: Guid.h:99