ATLAS Offline Software
Guid.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <cstdio>
8 #include <cstring>
9 #include <cstdlib>
10 
11 #include "uuid/uuid.h"
12 
13 static const char* const fmt_Guid = "%08X-%04hX-%04hX-%02hhX%02hhX-%02hhX%02hhX%02hhX%02hhX%02hhX%02hhX";
14 
15 //{ 0x0,0x0,0x0,{0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0}};
16 static const Guid clid_null(std::string("00000000-0000-0000-0000-000000000000"));
17 
18 const Guid& Guid::null() {
19  return clid_null;
20 }
21 
23 
25  char* envv = getenv("POOL_GUID_TIME");
26  if (envv != 0 && *envv) return GuidGenByTime;
27  envv = getenv("POOL_GUID_RANDOM");
28  if (envv != 0 && *envv) return GuidGenRandom;
29  return GuidGenDefault;
30 }
31 
34  uuid_t me_;
36  switch(method) {
37  case GuidGenRandom:
38  ::uuid_generate(me_);
39  break;
40  case GuidGenByTime:
41  ::uuid_generate_time(me_);
42  break;
43  default:
44  ::uuid_generate(me_);
45  break;
46  }
47  unsigned int *d1 = (unsigned int*)me_;
48  unsigned short *d2 = (unsigned short*)(me_ + 4);
49  unsigned short *d3 = (unsigned short*)(me_ + 6);
50  guid.m_data1 = *d1;
51  guid.m_data2 = *d2;
52  guid.m_data3 = *d3;
53  for (unsigned int i = 0; i < 8; i++) {
54  guid.m_data4[i] = me_[i + 8];
55  }
56 }
57 
58 const std::string Guid::toString() const {
59  char text[128];
60  int s = ::sprintf(text, fmt_Guid, m_data1, m_data2, m_data3,
61  m_data4[0], m_data4[1], m_data4[2], m_data4[3], m_data4[4], m_data4[5], m_data4[6], m_data4[7]);
62  return std::string(text, s);
63 }
64 
65 const Guid& Guid::fromString(const std::string& source) {
66  if (::sscanf(source.c_str(), fmt_Guid, &m_data1, &m_data2, &m_data3,
67  &m_data4[0], &m_data4[1], &m_data4[2], &m_data4[3], &m_data4[4], &m_data4[5], &m_data4[6], &m_data4[7]) != 11) {
68  m_data1 = 0U;
69  m_data2 = 0U;
70  m_data3 = 0U;
71  for (unsigned int i = 0; i < 8; i++) {
72  m_data4[i] = '\0';
73  }
74  }
75  return *this;
76 }
77 
78 bool Guid::operator<(const Guid& g) const {
79  return ::memcmp(&g.m_data1, &m_data1, 16) < 0;
80 }
RunTileTBRec.method
method
Definition: RunTileTBRec.py:73
Guid::null
static const Guid & null()
NULL-Guid: static class method.
Definition: Guid.cxx:18
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
Guid::m_data4
unsigned char m_data4[8]
Definition: Guid.h:99
Guid::initGuidGenMethod
static GuidGenMethod initGuidGenMethod()
Checks for POOL_GUID_TIME or POOL_GUID_RANDOM env variables.
Definition: Guid.cxx:24
dq_defect_virtual_defect_validation.d1
d1
Definition: dq_defect_virtual_defect_validation.py:79
Guid::toString
const std::string toString() const
Automatic conversion to string representation.
Definition: Guid.cxx:58
Guid::m_data3
unsigned short m_data3
Definition: Guid.h:98
Guid::GuidGenByTime
@ GuidGenByTime
Definition: Guid.h:67
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:33
Guid::GuidGenRandom
@ GuidGenRandom
Definition: Guid.h:67
Guid::GuidGenMethod
GuidGenMethod
Definition: Guid.h:67
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
Guid::GuidGenDefault
@ GuidGenDefault
Definition: Guid.h:67
pool_uuid.guid
guid
Definition: pool_uuid.py:112
Guid::operator<
bool operator<(const Guid &g) const
Smaller operator.
Definition: Guid.cxx:78
Guid::m_data1
unsigned int m_data1
Definition: Guid.h:96
Guid
This class provides a encapsulation of a GUID/UUID/CLSID/IID data structure (128 bit number).
Definition: Guid.h:20
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:68
dq_defect_virtual_defect_validation.d2
d2
Definition: dq_defect_virtual_defect_validation.py:81
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
Guid::m_data2
unsigned short m_data2
Definition: Guid.h:97
Guid.h
This file contains the class definition for the Guid class (migrated from POOL).