ATLAS Offline Software
Guid.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <iostream>
8 
9 #include "uuid/uuid.h"
10 
11 //{ 0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
12 static constexpr Guid clid_null("00000000-0000-0000-0000-000000000000");
13 
14 const Guid& Guid::null() noexcept {
15  return clid_null;
16 }
17 
19 
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 }
27 
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 }
53 
54 bool Guid::isGuid(std::string_view sv) noexcept{
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 }
80 
81 bool Guid::operator==(std::string_view str) const {
82  return str.size() == Guid::string::stringSize() && *this == Guid(str);
83 }
84 
85 
86 std::ostream& operator<<(std::ostream& os, const Guid& rhs) {
87  auto buff = rhs.to_fixed_string();
88  os.write(buff.data(), buff.size());
89  return os;
90 }
91 
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
get_hdefs.buff
buff
Definition: get_hdefs.py:61
Guid::operator==
bool operator==(const Guid &) const =default
Guid::Guid
constexpr Guid()
Standard constructor.
Definition: Guid.h:41
Guid::initGuidGenMethod
static GuidGenMethod initGuidGenMethod()
Checks for POOL_GUID_TIME or POOL_GUID_RANDOM env variables.
Definition: Guid.cxx:20
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
Guid::string::stringSize
static constexpr int stringSize()
Definition: Guid.h:37
Guid::to_fixed_string
constexpr Guid::string to_fixed_string(bool uppercase=true) const
Definition: Guid.h:65
operator<<
std::ostream & operator<<(std::ostream &os, const Guid &rhs)
Definition: Guid.cxx:86
Guid::GuidGenByTime
@ GuidGenByTime
Definition: Guid.h:76
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:76
Guid::GuidGenMethod
GuidGenMethod
Definition: Guid.h:76
lumiFormat.i
int i
Definition: lumiFormat.py:85
Guid::GuidGenDefault
@ GuidGenDefault
Definition: Guid.h:76
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
pool_uuid.guid
guid
Definition: pool_uuid.py:112
Guid::null
static const Guid & null() noexcept
NULL-Guid: static class method.
Definition: Guid.cxx:14
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:25
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:77
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
LArCellConditions.sv
bool sv
Definition: LArCellConditions.py:45
str
Definition: BTagTrackIpAccessor.cxx:11
Guid.h
This file contains the class definition for the Guid class (migrated from POOL).
Guid::isGuid
static bool isGuid(std::string_view) noexcept
Definition: Guid.cxx:54
python.compressB64.c
def c
Definition: compressB64.py:93