CMS 3D CMS Logo

Guid.cc
Go to the documentation of this file.
1 // ====================================================================
2 //
3 // Guid.cpp
4 // --------------------------------------------------------------------
5 //
6 // Package : Persistent Guid to identify objects in the persistent
7 // world.
8 //
9 // Author : Markus Frank
10 //
11 // ====================================================================
12 #include "Guid.h"
13 #include <cstring>
14 #include <cassert>
15 
16 namespace edm {
18  void Guid::init(bool usetime) {
19  if (usetime) {
20  ::uuid_generate_time(data_);
21  } else {
22  // uuid_generate() defaults to uuid_generate_random() if /dev/urandom
23  // is available; if /dev/urandom is not available, then it is better
24  // to let uuid_generate() choose the best fallback rather than forcing
25  // use of an inferior source of randomness
26  ::uuid_generate(data_);
27  }
28  }
29 
30  std::string const Guid::toBinary() const { return std::string(reinterpret_cast<const char*>(data_), sizeof(data_)); }
31 
33  assert(source.size() == sizeof(data_));
34  std::memcpy(data_, source.data(), sizeof(data_));
35  return *this;
36  }
37 
38  std::string const Guid::toString() const {
39  char out[UUID_STR_LEN];
40  ::uuid_unparse(data_, out);
41  return std::string(out);
42  }
43 
44  // fromString is used only in a unit test, so performance is not critical.
46  auto err = ::uuid_parse(source.c_str(), data_);
47  assert(err == 0);
48  return *this;
49  }
50 
51  bool Guid::operator<(Guid const& g) const { return ::uuid_compare(data_, g.data_) < 0; }
52 } // namespace edm
edm::source
static const std::string source("source")
edm::Guid::fromBinary
Guid const & fromBinary(std::string const &s)
conversion from binary string representation
Definition: Guid.cc:32
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::cuda::assert
assert(be >=bs)
edm::Guid::toString
const std::string toString() const
conversion to formatted string reprentation
Definition: Guid.cc:38
edm::Guid::fromString
Guid const & fromString(std::string const &s)
conversion from formatted string representation
Definition: Guid.cc:45
edm::Guid::init
void init(bool usetime=false)
initialize a new Guid
Definition: Guid.cc:18
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::Guid::toBinary
const std::string toBinary() const
conversion to binary string reprentation
Definition: Guid.cc:30
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
edm::Guid
Definition: Guid.h:26
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
Guid.h
edm::Guid::operator<
bool operator<(Guid const &g) const
Smaller operator.
Definition: Guid.cc:51
g
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
edm::Guid::data_
uuid_t data_
Definition: Guid.h:68