SubRunID.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_SubRunID_h
2 #define canvas_Persistency_Provenance_SubRunID_h
3 
4 // A SubRunID represents a unique period within a run.
5 
7 
8 #include <cstdint>
9 #include <ostream>
10 
11 namespace art {
12  class SubRunID;
13 
14  std::ostream& operator<<(std::ostream& os, SubRunID const& iID);
15 }
16 
18 public:
19  constexpr SubRunID();
20  SubRunID(RunID rID, SubRunNumber_t srID);
22 
23  RunID const& runID() const;
24  RunNumber_t run() const;
25  SubRunNumber_t subRun() const;
26 
27  bool isValid() const;
28  bool isFlush() const;
29 
30  SubRunID next() const;
31  SubRunID nextRun() const;
32  SubRunID previous() const;
33  SubRunID previousRun() const;
34 
35  static SubRunID maxSubRun();
36  static SubRunID firstSubRun();
37  static SubRunID firstSubRun(RunID const& rID);
38  static SubRunID invalidSubRun(RunID const& rID);
39  static constexpr SubRunID flushSubRun();
40  static SubRunID flushSubRun(RunID const& rID);
41 
42  // Comparison operators.
43  bool operator==(SubRunID const& other) const;
44  bool operator!=(SubRunID const& other) const;
45  bool operator<(SubRunID const& other) const;
46  bool operator<=(SubRunID const& other) const;
47  bool operator>(SubRunID const& other) const;
48  bool operator>=(SubRunID const& other) const;
49 
50  friend std::ostream& operator<<(std::ostream& os, SubRunID const& iID);
51 
52 private:
53  struct FlushFlag {};
54 
55  explicit constexpr SubRunID(FlushFlag);
56  SubRunID(RunID rID, FlushFlag);
57 
59 
60  void checkSane();
61 
64 };
65 
66 inline constexpr art::SubRunID::SubRunID()
68 {}
69 
71  : run_(rID), subRun_(inRangeOrInvalid(srID))
72 {
73  checkSane();
74 }
75 
76 inline art::RunID const&
78 {
79  return run_;
80 }
81 
82 inline art::RunNumber_t
84 {
85  return run_.run();
86 }
87 
90 {
91  return subRun_;
92 }
93 
94 inline bool
96 {
98 }
99 
100 inline bool
102 {
104 }
105 
107 
108 inline art::SubRunID
110 {
111  if (!isValid()) {
113  << "cannot increment invalid subrun number.";
115  return nextRun();
116  }
117  return SubRunID(run_, subRun_ + 1);
118 }
119 
120 inline art::SubRunID
122 {
124 }
125 
126 inline art::SubRunID
128 {
129  if (!isValid()) {
131  << "cannot decrement invalid subrun number.";
132  } else if (subRun_ == IDNumber<Level::SubRun>::first()) {
133  return previousRun();
134  }
135  return SubRunID(run_, subRun_ - 1);
136 }
137 
138 inline art::SubRunID
140 {
142 }
143 
144 inline art::SubRunID
146 {
148 }
149 
150 inline art::SubRunID
152 {
154 }
155 
156 inline art::SubRunID
158 {
160 }
161 
162 inline art::SubRunID
164 {
166 }
167 
168 inline constexpr art::SubRunID
170 {
171  return SubRunID(FlushFlag());
172 }
173 
174 inline art::SubRunID
176 {
177  return SubRunID(rID, FlushFlag());
178 }
179 
180 // Comparison operators.
181 inline bool
183 {
184  return other.run_ == run_ && other.subRun_ == subRun_;
185 }
186 
187 inline bool
189 {
190  return !(*this == other);
191 }
192 
194 
195 inline bool
197 {
200  if (run_ == other.run_) {
201  return op(subRun_, other.subRun_);
202  } else {
203  return run_ < other.run_;
204  }
205 }
206 
207 inline bool
209 {
210  return (*this < other) || (*this == other);
211 }
212 
213 inline bool
215 {
216  return (other < *this);
217 }
218 
219 inline bool
221 {
222  return !(*this < other);
223 }
224 
226  : run_(RunID::flushRun()), subRun_(IDNumber<Level::SubRun>::flush_value())
227 {}
228 
230  : run_(std::move(rID)), subRun_(IDNumber<Level::SubRun>::flush_value())
231 {}
232 
234  : run_(std::move(rID)), subRun_(inRangeOrInvalid(srID))
235 {
236  checkSane();
237 }
238 
239 inline art::SubRunNumber_t
241 {
242  if (sr == IDNumber<Level::SubRun>::invalid() ||
243 #ifdef __clang__
244 #pragma clang diagnostic push
245 #pragma clang diagnostic ignored "-Wtautological-compare"
246 #endif
248 #ifdef __clang__
249 #pragma clang diagnostic pop
250 #endif
252  return sr;
253  } else {
255  << "Attempt to construct SubRunID with an invalid number.\n"
256  << "Maybe you want SubRunID::flushSubRun()?\n";
257  }
258 }
259 
260 inline void
262 {
263  if (isValid() && !run_.isValid()) {
265  << "SubRunID is not meaningful with valid subRun and invalid Run.\n";
266  }
267 }
268 
269 #endif /* canvas_Persistency_Provenance_SubRunID_h */
270 
271 // Local Variables:
272 // mode: c++
273 // End:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
bool operator>=(SubRunID const &other) const
Definition: SubRunID.h:220
RunID next() const
Definition: RunID.h:82
bool operator==(SubRunID const &other) const
Definition: SubRunID.h:182
friend std::ostream & operator<<(std::ostream &os, SubRunID const &iID)
Level
Definition: Level.h:12
SubRunID previousRun() const
Definition: SubRunID.h:139
bool operator>(SubRunID const &other) const
Definition: SubRunID.h:214
static constexpr SubRunID flushSubRun()
Definition: SubRunID.h:169
RunNumber_t run() const
Definition: RunID.h:62
bool isValid() const
Definition: SubRunID.h:95
RunID const & runID() const
Definition: SubRunID.h:77
SubRunID next() const
Definition: SubRunID.h:109
RunID run_
Definition: SubRunID.h:62
static RunID maxRun()
Definition: RunID.h:108
RunNumber_t run() const
Definition: SubRunID.h:83
bool operator!=(SubRunID const &other) const
Definition: SubRunID.h:188
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
void checkSane()
Definition: SubRunID.h:261
caf::StandardRecord * sr
SubRunID nextRun() const
Definition: SubRunID.h:121
SubRunNumber_t subRun_
Definition: SubRunID.h:63
bool operator<=(SubRunID const &other) const
Definition: SubRunID.h:208
static SubRunID firstSubRun()
Definition: SubRunID.h:151
RunID previous() const
Definition: RunID.h:95
bool isFlush() const
Definition: SubRunID.h:101
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
SubRunID previous() const
Definition: SubRunID.h:127
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:163
bool isValid() const
Definition: RunID.h:68
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
SubRunNumber_t inRangeOrInvalid(SubRunNumber_t sr)
Definition: SubRunID.h:240
SubRunNumber_t subRun() const
Definition: SubRunID.h:89
static RunID firstRun()
Definition: RunID.h:114
constexpr SubRunID()
Definition: SubRunID.h:66
static SubRunID maxSubRun()
Definition: SubRunID.h:145
bool operator<(SubRunID const &other) const
Definition: SubRunID.h:196
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119