RunID.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_RunID_h
2 #define canvas_Persistency_Provenance_RunID_h
3 
4 //
5 // A RunID represents a unique period of operation of the data
6 // acquisition system, which we call a "run".
7 //
8 // Each RunID contains a fixed-size unsigned integer, the run number.
9 //
10 
12 #include "canvas/Utilities/Level.h"
13 #include <iosfwd>
14 
15 namespace art {
16  class RunID;
17 
18  std::ostream& operator<<(std::ostream& os, art::RunID const& iID);
19 }
20 
21 class art::RunID {
22 public:
23  constexpr RunID() noexcept;
24  explicit RunID(RunNumber_t i);
25 
26  RunNumber_t run() const;
27 
28  bool isValid() const;
29  bool isFlush() const;
30 
31  RunID next() const;
32  RunID previous() const;
33 
34  static RunID maxRun();
35  static RunID firstRun();
36  static constexpr RunID flushRun() noexcept;
37 
38  // Comparison operators.
39  bool operator==(RunID const& other) const;
40  bool operator!=(RunID const& other) const;
41  bool operator<(RunID const& other) const;
42  bool operator<=(RunID const& other) const;
43  bool operator>(RunID const& other) const;
44  bool operator>=(RunID const& other) const;
45 
46  friend std::ostream& operator<<(std::ostream& os, RunID const& iID);
47 
48 private:
49  struct FlushFlag {};
50 
51  explicit constexpr RunID(FlushFlag) noexcept;
52 
55 };
56 
57 inline constexpr art::RunID::RunID() noexcept
58  : run_(IDNumber<Level::Run>::invalid())
59 {}
60 
62 
63 inline art::RunNumber_t
65 {
66  return run_;
67 }
68 
69 inline bool
71 {
72  return (run_ != IDNumber<Level::Run>::invalid());
73 }
74 
75 inline bool
77 {
79 }
80 
82 
83 inline art::RunID
85 {
86  if (!isValid()) {
88  << "cannot increment invalid run number.";
89  } else if (run_ == IDNumber<Level::Run>::max_natural()) {
91  << "cannot increment maximum run number.";
92  }
93  return RunID(run_ + 1);
94 }
95 
96 inline art::RunID
98 {
99  if (!isValid()) {
101  << "cannot decrement minimum run number.";
102  } else if (run_ == IDNumber<Level::Run>::max_natural()) {
104  << "cannot increment maximum run number.";
105  }
106  return RunID(run_ - 1);
107 }
108 
109 inline art::RunID
111 {
113 }
114 
115 inline art::RunID
117 {
119 }
120 
121 inline constexpr art::RunID
123 {
124  return RunID(FlushFlag());
125 }
126 
127 // Comparison operators.
128 inline bool
130 {
131  return other.run_ == run_;
132 }
133 
134 inline bool
136 {
137  return !(*this == other);
138 }
139 
141 
142 inline bool
144 {
146  return op(run_, other.run_);
147 }
148 
149 inline bool
151 {
152  return (*this < other) || (*this == other);
153 }
154 
155 inline bool
157 {
158  return (other < *this);
159 }
160 
161 inline bool
163 {
164  return !(*this < other);
165 }
166 
167 inline art::RunNumber_t
169 {
170  if (r == IDNumber<Level::Run>::invalid() ||
171  (r >= IDNumber<Level::Run>::first() &&
173  return r;
174  } else {
176  << "Attempt to construct RunID with an invalid number.\n"
177  << "Maybe you want RunID::flushRun()?\n";
178  }
179 }
180 
181 inline constexpr art::RunID::RunID(FlushFlag) noexcept
183 {}
184 
185 #endif /* canvas_Persistency_Provenance_RunID_h */
186 
187 // Local Variables:
188 // mode: c++
189 // End:
bool operator>=(RunID const &other) const
Definition: RunID.h:162
bool isFlush() const
Definition: RunID.h:76
RunID next() const
Definition: RunID.h:84
RunNumber_t inRangeOrInvalid(RunNumber_t r)
Definition: RunID.h:168
Level
Definition: Level.h:13
bool operator==(RunID const &other) const
Definition: RunID.h:129
RunNumber_t run() const
Definition: RunID.h:64
Definition: Run.h:17
bool operator!=(RunID const &other) const
Definition: RunID.h:135
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
static RunID maxRun()
Definition: RunID.h:110
bool operator>(RunID const &other) const
Definition: RunID.h:156
static constexpr RunID flushRun() noexcept
Definition: RunID.h:122
bool operator<(RunID const &other) const
Definition: RunID.h:143
RunNumber_t run_
Definition: RunID.h:54
RunID previous() const
Definition: RunID.h:97
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool operator<=(RunID const &other) const
Definition: RunID.h:150
bool isValid() const
Definition: RunID.h:70
static RunID firstRun()
Definition: RunID.h:116
friend std::ostream & operator<<(std::ostream &os, RunID const &iID)
constexpr RunID() noexcept
Definition: RunID.h:57
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120