ProductID.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_ProductID_h
2 #define canvas_Persistency_Provenance_ProductID_h
3 
4 //=====================================================================
5 // ProductID: A unique identifier for each EDProduct within a process.
6 //=====================================================================
7 
8 #include "cetlib/crc32.h"
9 
10 #include <functional> // for std::hash
11 #include <iosfwd>
12 #include <string>
13 
14 namespace art {
15 
16  class ProductID {
17  public:
18  using value_type = unsigned int;
19 
20  constexpr ProductID() = default;
22  constexpr explicit ProductID(value_type const value) noexcept
23  : value_{value}
24  {}
25 
26  static constexpr ProductID
27  invalid() noexcept
28  {
29  return ProductID{};
30  }
31 
33 
34  constexpr bool
35  isValid() const noexcept
36  {
37  return value_ != 0u;
38  }
39 
40  constexpr auto
41  value() const noexcept
42  {
43  return value_;
44  }
45 
46  constexpr operator std::size_t() const noexcept
47  {
48  return static_cast<std::size_t>(value_);
49  }
50 
51  constexpr bool
52  operator<(ProductID const rh) const noexcept
53  {
54  return value_ < rh.value_;
55  }
56  constexpr bool
57  operator>(ProductID const rh) const noexcept
58  {
59  return rh < *this;
60  }
61  constexpr bool
62  operator==(ProductID const rh) const noexcept
63  {
64  return value_ == rh.value_;
65  }
66  constexpr bool
67  operator!=(ProductID const rh) const noexcept
68  {
69  return !(*this == rh);
70  }
71 
72  struct Hash {
73  constexpr std::size_t
74  operator()(ProductID const pid) const noexcept
75  {
76  return pid.value(); // since the ID is already a checksum, don't
77  // worry about further hashing
78  }
79  };
80 
81  private:
82  static value_type toID(std::string const& branchName);
83  friend class ProductIDStreamer;
84 
85  // Conveniently, the CRC32 value associated with an empty string
86  // is 0.
88  };
89 
90  std::ostream& operator<<(std::ostream& os, ProductID const id);
91 }
92 
93 namespace std {
94  template <>
95  struct hash<art::ProductID> {
96  constexpr std::size_t
97  operator()(art::ProductID const id) const noexcept
98  {
99  return id.value();
100  }
101  };
102 }
103 
104 #endif /* canvas_Persistency_Provenance_ProductID_h */
105 
106 // Local Variables:
107 // mode: c++
108 // End:
constexpr std::size_t operator()(ProductID const pid) const noexcept
Definition: ProductID.h:74
constexpr bool operator<(ProductID const rh) const noexcept
Definition: ProductID.h:52
TH2 * rh
Definition: drawXsec.C:5
friend class ProductIDStreamer
Definition: ProductID.h:83
constexpr ProductID()=default
constexpr ProductID(value_type const value) noexcept
Definition: ProductID.h:22
const XML_Char int const XML_Char * value
Definition: expat.h:331
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
constexpr bool isValid() const noexcept
Definition: ProductID.h:35
unsigned int value_type
Definition: ProductID.h:18
constexpr std::size_t operator()(art::ProductID const id) const noexcept
Definition: ProductID.h:97
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
static value_type toID(std::string const &branchName)
void setID(std::string const &canonicalProductName)
constexpr bool operator==(ProductID const rh) const noexcept
Definition: ProductID.h:62
constexpr auto value() const noexcept
Definition: ProductID.h:41
value_type value_
Definition: ProductID.h:87
constexpr bool operator>(ProductID const rh) const noexcept
Definition: ProductID.h:57
constexpr bool operator!=(ProductID const rh) const noexcept
Definition: ProductID.h:67
static constexpr ProductID invalid() noexcept
Definition: ProductID.h:27
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
enum BeamMode string