LArSoft  v07_13_02
Liquid Argon Software toolkit - http://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 "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  ProductID() = default;
21  explicit ProductID(std::string const& canonicalProductName);
22  explicit ProductID(value_type const value);
23 
24  static ProductID
26  {
27  return ProductID{};
28  }
29 
30  void setID(std::string const& canonicalProductName);
31 
32  bool
33  isValid() const
34  {
35  return value_ != 0u;
36  }
37  auto
38  value() const
39  {
40  return value_;
41  }
42 
43  bool
44  operator<(ProductID const rh) const
45  {
46  return value_ < rh.value_;
47  }
48  bool
49  operator>(ProductID const rh) const
50  {
51  return rh < *this;
52  }
53  bool
54  operator==(ProductID const rh) const
55  {
56  return value_ == rh.value_;
57  }
58  bool
59  operator!=(ProductID const rh) const
60  {
61  return !(*this == rh);
62  }
63 
64  struct Hash {
65  std::size_t
66  operator()(ProductID const pid) const
67  {
68  return pid.value(); // since the ID is already a checksum, don't
69  // worry about further hashing
70  }
71  };
72 
73  private:
74  static value_type toID(std::string const& branchName);
75  friend class ProductIDStreamer;
76 
77  // Conveniently, the CRC32 value associated with an empty string
78  // is 0.
80  };
81 
82  std::ostream& operator<<(std::ostream& os, ProductID const id);
83 }
84 
85 namespace std {
86  template <>
87  struct hash<art::ProductID> {
88  std::size_t
90  {
91  return id.value();
92  }
93  };
94 }
95 
96 #endif /* canvas_Persistency_Provenance_ProductID_h */
97 
98 // Local Variables:
99 // mode: c++
100 // End:
std::size_t operator()(ProductID const pid) const
Definition: ProductID.h:66
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
bool operator==(ProductID const rh) const
Definition: ProductID.h:54
bool operator!=(ProductID const rh) const
Definition: ProductID.h:59
friend class ProductIDStreamer
Definition: ProductID.h:75
STL namespace.
bool operator<(ProductID const rh) const
Definition: ProductID.h:44
bool operator>(ProductID const rh) const
Definition: ProductID.h:49
bool isValid() const
Definition: ProductID.h:33
ProductID()=default
unsigned int value_type
Definition: ProductID.h:18
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:15
static value_type toID(std::string const &branchName)
Definition: ProductID.cc:21
auto value() const
Definition: ProductID.h:38
value_type value_
Definition: ProductID.h:79
HLT enums.
static ProductID invalid()
Definition: ProductID.h:25
std::size_t operator()(art::ProductID id) const
Definition: ProductID.h:89