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 <cstdint>
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();
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();
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);
52 
55 };
56 
57 inline constexpr art::RunID::RunID() : run_(IDNumber<Level::Run>::invalid()) {}
58 
60 
61 inline art::RunNumber_t
63 {
64  return run_;
65 }
66 
67 inline bool
69 {
70  return (run_ != IDNumber<Level::Run>::invalid());
71 }
72 
73 inline bool
75 {
77 }
78 
80 
81 inline art::RunID
83 {
84  if (!isValid()) {
86  << "cannot increment invalid run number.";
87  } else if (run_ == IDNumber<Level::Run>::max_natural()) {
89  << "cannot increment maximum run number.";
90  }
91  return RunID(run_ + 1);
92 }
93 
94 inline art::RunID
96 {
97  if (!isValid()) {
99  << "cannot decrement minimum run number.";
100  } else if (run_ == IDNumber<Level::Run>::max_natural()) {
102  << "cannot increment maximum run number.";
103  }
104  return RunID(run_ - 1);
105 }
106 
107 inline art::RunID
109 {
111 }
112 
113 inline art::RunID
115 {
117 }
118 
119 inline constexpr art::RunID
121 {
122  return RunID(FlushFlag());
123 }
124 
125 // Comparison operators.
126 inline bool
128 {
129  return other.run_ == run_;
130 }
131 
132 inline bool
134 {
135  return !(*this == other);
136 }
137 
139 
140 inline bool
142 {
144  return op(run_, other.run_);
145 }
146 
147 inline bool
149 {
150  return (*this < other) || (*this == other);
151 }
152 
153 inline bool
155 {
156  return (other < *this);
157 }
158 
159 inline bool
161 {
162  return !(*this < other);
163 }
164 
165 inline art::RunNumber_t
167 {
168  if (r == IDNumber<Level::Run>::invalid() ||
169  (r >= IDNumber<Level::Run>::first() &&
171  return r;
172  } else {
174  << "Attempt to construct RunID with an invalid number.\n"
175  << "Maybe you want RunID::flushRun()?\n";
176  }
177 }
178 
179 inline constexpr art::RunID::RunID(FlushFlag)
181 {}
182 
183 #endif /* canvas_Persistency_Provenance_RunID_h */
184 
185 // Local Variables:
186 // mode: c++
187 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
bool operator>=(RunID const &other) const
Definition: RunID.h:160
bool isFlush() const
Definition: RunID.h:74
static constexpr RunID flushRun()
Definition: RunID.h:120
RunID next() const
Definition: RunID.h:82
RunNumber_t inRangeOrInvalid(RunNumber_t r)
Definition: RunID.h:166
Level
Definition: Level.h:12
bool operator==(RunID const &other) const
Definition: RunID.h:127
RunNumber_t run() const
Definition: RunID.h:62
Definition: Run.h:31
bool operator!=(RunID const &other) const
Definition: RunID.h:133
static RunID maxRun()
Definition: RunID.h:108
bool operator>(RunID const &other) const
Definition: RunID.h:154
bool operator<(RunID const &other) const
Definition: RunID.h:141
RunNumber_t run_
Definition: RunID.h:54
RunID previous() const
Definition: RunID.h:95
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool operator<=(RunID const &other) const
Definition: RunID.h:148
bool isValid() const
Definition: RunID.h:68
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
constexpr RunID()
Definition: RunID.h:57
static RunID firstRun()
Definition: RunID.h:114
friend std::ostream & operator<<(std::ostream &os, RunID const &iID)
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119