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