LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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 <cstddef> // for size_t
9 #include <functional> // for std::hash
10 #include <iosfwd>
11 #include <string>
12 
13 namespace art {
14 
15  class ProductID {
16  public:
17  using value_type = unsigned int;
18 
19  constexpr ProductID() = default;
20  explicit ProductID(std::string const& canonicalProductName);
21  constexpr explicit ProductID(value_type const value) noexcept
22  : value_{value}
23  {}
24 
25  static constexpr ProductID
26  invalid() noexcept
27  {
28  return ProductID{};
29  }
30 
31  void setID(std::string const& canonicalProductName);
32 
33  constexpr bool
34  isValid() const noexcept
35  {
36  return value_ != 0u;
37  }
38 
39  constexpr auto
40  value() const noexcept
41  {
42  return value_;
43  }
44 
45  constexpr operator std::size_t() const noexcept
46  {
47  return static_cast<std::size_t>(value_);
48  }
49 
50  constexpr bool
51  operator<(ProductID const rh) const noexcept
52  {
53  return value_ < rh.value_;
54  }
55  constexpr bool
56  operator>(ProductID const rh) const noexcept
57  {
58  return rh < *this;
59  }
60  constexpr bool
61  operator==(ProductID const rh) const noexcept
62  {
63  return value_ == rh.value_;
64  }
65  constexpr bool
66  operator!=(ProductID const rh) const noexcept
67  {
68  return !(*this == rh);
69  }
70 
71  struct Hash {
72  constexpr std::size_t
73  operator()(ProductID const pid) const noexcept
74  {
75  return pid.value(); // since the ID is already a checksum, don't
76  // worry about further hashing
77  }
78  };
79 
80  private:
81  static value_type toID(std::string const& branchName);
82  friend class ProductIDStreamer;
83 
84  // Conveniently, the CRC32 value associated with an empty string
85  // is 0.
87  };
88 
89  std::ostream& operator<<(std::ostream& os, ProductID const id);
90 }
91 
92 namespace std {
93  template <>
94  struct hash<art::ProductID> {
95  constexpr std::size_t
96  operator()(art::ProductID const id) const noexcept
97  {
98  return id.value();
99  }
100  };
101 }
102 
103 #endif /* canvas_Persistency_Provenance_ProductID_h */
104 
105 // Local Variables:
106 // mode: c++
107 // End:
constexpr std::size_t operator()(ProductID const pid) const noexcept
Definition: ProductID.h:73
constexpr bool operator<(ProductID const rh) const noexcept
Definition: ProductID.h:51
friend class ProductIDStreamer
Definition: ProductID.h:82
constexpr ProductID()=default
constexpr ProductID(value_type const value) noexcept
Definition: ProductID.h:21
STL namespace.
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
constexpr bool isValid() const noexcept
Definition: ProductID.h:34
unsigned int value_type
Definition: ProductID.h:17
constexpr std::size_t operator()(art::ProductID const id) const noexcept
Definition: ProductID.h:96
std::string canonicalProductName(std::string const &friendlyClassName, std::string const &moduleLabel, std::string const &productInstanceName, std::string const &processName)
void setID(std::string const &canonicalProductName)
Definition: ProductID.cc:13
static value_type toID(std::string const &branchName)
Definition: ProductID.cc:19
constexpr bool operator==(ProductID const rh) const noexcept
Definition: ProductID.h:61
constexpr auto value() const noexcept
Definition: ProductID.h:40
value_type value_
Definition: ProductID.h:86
constexpr bool operator>(ProductID const rh) const noexcept
Definition: ProductID.h:56
constexpr bool operator!=(ProductID const rh) const noexcept
Definition: ProductID.h:66
static constexpr ProductID invalid() noexcept
Definition: ProductID.h:26
Definition: MVAAlg.h:12