LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
BranchID.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_Compatibility_BranchID_h
2 #define canvas_Persistency_Provenance_Compatibility_BranchID_h
3 
4 /*----------------------------------------------------------------------
5 
6 BranchID: A unique identifier for each branch.
7 
8 ----------------------------------------------------------------------*/
9 
10 #include <cstdlib>
11 #include <iosfwd>
12 #include <string>
13 
14 namespace art {
15 
16  class BranchID {
17  public:
18  using value_type = unsigned int;
19 
20  BranchID() = default;
21  explicit BranchID(std::string const& branchName)
22  : BranchID{toID(branchName)}
23  {}
24  explicit BranchID(value_type const id) : id_{id} {}
25 
26  void
27  setID(std::string const& branchName)
28  {
29  id_ = toID(branchName);
30  }
31  unsigned int
32  id() const
33  {
34  return id_;
35  }
36  bool
37  isValid() const
38  {
39  return id_ != 0;
40  }
41 
42  // This is for the use of tbb::hash<BranchID> (and possibly
43  // std::hash<BranchID>?)
44  explicit operator std::size_t() const
45  {
46  return static_cast<std::size_t>(id_);
47  }
48 
49  bool
50  operator<(BranchID const& rh) const
51  {
52  return id_ < rh.id_;
53  }
54  bool
55  operator>(BranchID const& rh) const
56  {
57  return id_ > rh.id_;
58  }
59  bool
60  operator==(BranchID const& rh) const
61  {
62  return id_ == rh.id_;
63  }
64  bool
65  operator!=(BranchID const& rh) const
66  {
67  return id_ != rh.id_;
68  }
69 
70  struct Hash {
71  std::size_t
72  operator()(BranchID const& bid) const
73  {
74  return bid.id(); // since the ID is already a checksum, don't
75  // worry about further hashing
76  }
77  };
78 
79  private:
80  static value_type toID(std::string const& branchName);
82  };
83 
84  std::ostream& operator<<(std::ostream& os, BranchID const& id);
85 }
86 #endif /* canvas_Persistency_Provenance_Compatibility_BranchID_h */
87 
88 // Local Variables:
89 // mode: c++
90 // End:
void setID(std::string const &branchName)
Definition: BranchID.h:27
std::size_t operator()(BranchID const &bid) const
Definition: BranchID.h:72
bool isValid() const
Definition: BranchID.h:37
value_type id_
Definition: BranchID.h:81
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
static value_type toID(std::string const &branchName)
Definition: BranchID.cc:9
BranchID(std::string const &branchName)
Definition: BranchID.h:21
BranchID(value_type const id)
Definition: BranchID.h:24
unsigned int value_type
Definition: BranchID.h:18
bool operator<(BranchID const &rh) const
Definition: BranchID.h:50
bool operator==(BranchID const &rh) const
Definition: BranchID.h:60
unsigned int id() const
Definition: BranchID.h:32
bool operator>(BranchID const &rh) const
Definition: BranchID.h:55
BranchID()=default
Definition: MVAAlg.h:12
bool operator!=(BranchID const &rh) const
Definition: BranchID.h:65