LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
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 
56  explicit constexpr SubRunID(FlushFlag);
57  SubRunID(RunID rID, FlushFlag);
58 
60 
61  void checkSane();
62 
65 };
66 
67 inline constexpr art::SubRunID::SubRunID()
68  : run_(), subRun_(IDNumber<Level::SubRun>::invalid())
69 {}
70 
72  : run_(rID), subRun_(inRangeOrInvalid(srID))
73 {
74  checkSane();
75 }
76 
77 inline art::RunID const&
79 {
80  return run_;
81 }
82 
83 inline art::RunNumber_t
85 {
86  return run_.run();
87 }
88 
91 {
92  return subRun_;
93 }
94 
95 inline bool
97 {
99 }
100 
101 inline bool
103 {
105 }
106 
108 
109 inline art::SubRunID
111 {
112  if (!isValid()) {
114  << "cannot increment invalid subrun number.";
116  return nextRun();
117  }
118  return SubRunID(run_, subRun_ + 1);
119 }
120 
121 inline art::SubRunID
123 {
125 }
126 
127 inline art::SubRunID
129 {
130  if (!isValid()) {
132  << "cannot decrement invalid subrun number.";
133  } else if (subRun_ == IDNumber<Level::SubRun>::first()) {
134  return previousRun();
135  }
136  return SubRunID(run_, subRun_ - 1);
137 }
138 
139 inline art::SubRunID
141 {
143 }
144 
145 inline art::SubRunID
147 {
149 }
150 
151 inline art::SubRunID
153 {
155 }
156 
157 inline art::SubRunID
159 {
161 }
162 
163 inline art::SubRunID
165 {
167 }
168 
169 inline constexpr art::SubRunID
171 {
172  return SubRunID(FlushFlag());
173 }
174 
175 inline art::SubRunID
177 {
178  return SubRunID(rID, FlushFlag());
179 }
180 
181 // Comparison operators.
182 inline bool
184 {
185  return other.run_ == run_ && other.subRun_ == subRun_;
186 }
187 
188 inline bool
190 {
191  return !(*this == other);
192 }
193 
195 
196 inline bool
198 {
201  if (run_ == other.run_) {
202  return op(subRun_, other.subRun_);
203  } else {
204  return run_ < other.run_;
205  }
206 }
207 
208 inline bool
210 {
211  return (*this < other) || (*this == other);
212 }
213 
214 inline bool
216 {
217  return (other < *this);
218 }
219 
220 inline bool
222 {
223  return !(*this < other);
224 }
225 
227  : run_(RunID::flushRun()), subRun_(IDNumber<Level::SubRun>::flush_value())
228 {}
229 
231  : run_(std::move(rID)), subRun_(IDNumber<Level::SubRun>::flush_value())
232 {}
233 
235  : run_(std::move(rID)), subRun_(inRangeOrInvalid(srID))
236 {
237  checkSane();
238 }
239 
240 inline art::SubRunNumber_t
242 {
243  if (sr == IDNumber<Level::SubRun>::invalid() ||
244 #ifdef __clang__
245 #pragma clang diagnostic push
246 #pragma clang diagnostic ignored "-Wtautological-compare"
247 #endif
249 #ifdef __clang__
250 #pragma clang diagnostic pop
251 #endif
253  return sr;
254  } else {
256  << "Attempt to construct SubRunID with an invalid number.\n"
257  << "Maybe you want SubRunID::flushSubRun()?\n";
258  }
259 }
260 
261 inline void
263 {
264  if (isValid() && !run_.isValid()) {
266  << "SubRunID is not meaningful with valid subRun and invalid Run.\n";
267  }
268 }
269 
270 #endif /* canvas_Persistency_Provenance_SubRunID_h */
271 
272 // Local Variables:
273 // mode: c++
274 // 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:221
RunID next() const
Definition: RunID.h:83
bool operator==(SubRunID const &other) const
Definition: SubRunID.h:183
friend std::ostream & operator<<(std::ostream &os, SubRunID const &iID)
Level
Definition: Level.h:12
STL namespace.
SubRunID previousRun() const
Definition: SubRunID.h:140
bool operator>(SubRunID const &other) const
Definition: SubRunID.h:215
static constexpr SubRunID flushSubRun()
Definition: SubRunID.h:170
RunNumber_t run() const
Definition: RunID.h:63
bool isValid() const
Definition: SubRunID.h:96
RunID const & runID() const
Definition: SubRunID.h:78
SubRunID next() const
Definition: SubRunID.h:110
RunID run_
Definition: SubRunID.h:63
static RunID maxRun()
Definition: RunID.h:109
RunNumber_t run() const
Definition: SubRunID.h:84
bool operator!=(SubRunID const &other) const
Definition: SubRunID.h:189
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
void checkSane()
Definition: SubRunID.h:262
SubRunID nextRun() const
Definition: SubRunID.h:122
SubRunNumber_t subRun_
Definition: SubRunID.h:64
bool operator<=(SubRunID const &other) const
Definition: SubRunID.h:209
static SubRunID firstSubRun()
Definition: SubRunID.h:152
RunID previous() const
Definition: RunID.h:96
bool isFlush() const
Definition: SubRunID.h:102
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
SubRunID previous() const
Definition: SubRunID.h:128
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:164
bool isValid() const
Definition: RunID.h:69
HLT enums.
SubRunNumber_t inRangeOrInvalid(SubRunNumber_t sr)
Definition: SubRunID.h:241
SubRunNumber_t subRun() const
Definition: SubRunID.h:90
static RunID firstRun()
Definition: RunID.h:115
constexpr SubRunID()
Definition: SubRunID.h:67
static SubRunID maxSubRun()
Definition: SubRunID.h:146
bool operator<(SubRunID const &other) const
Definition: SubRunID.h:197
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119