LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 
10 
11 #include <ostream>
12 
13 namespace art {
14  class SubRunID;
15 
16  std::ostream& operator<<(std::ostream& os, SubRunID const& iID);
17 }
18 
20 public:
21  constexpr SubRunID() noexcept;
22  SubRunID(RunID rID, SubRunNumber_t srID);
24 
25  RunID const& runID() const;
26  RunNumber_t run() const;
27  SubRunNumber_t subRun() const;
28 
29  bool isValid() const;
30  bool isFlush() const;
31 
32  SubRunID next() const;
33  SubRunID nextRun() const;
34  SubRunID previous() const;
35  SubRunID previousRun() const;
36 
37  static SubRunID maxSubRun();
38  static SubRunID firstSubRun();
39  static SubRunID firstSubRun(RunID const& rID);
40  static SubRunID invalidSubRun(RunID const& rID);
41  static constexpr SubRunID flushSubRun() noexcept;
42  static SubRunID flushSubRun(RunID const& rID);
43 
44  // Comparison operators.
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  bool operator>(SubRunID const& other) const;
50  bool operator>=(SubRunID const& other) const;
51 
52  friend std::ostream& operator<<(std::ostream& os, SubRunID const& iID);
53 
54 private:
55  struct FlushFlag {};
56 
57  explicit constexpr SubRunID(FlushFlag) noexcept;
58  SubRunID(RunID rID, FlushFlag);
59 
61 
62  void checkSane();
63 
66 };
67 
68 inline constexpr art::SubRunID::SubRunID() noexcept
69  : run_(), subRun_(IDNumber<Level::SubRun>::invalid())
70 {}
71 
73  : run_(rID), subRun_(inRangeOrInvalid(srID))
74 {
75  checkSane();
76 }
77 
78 inline art::RunID const&
80 {
81  return run_;
82 }
83 
84 inline art::RunNumber_t
86 {
87  return run_.run();
88 }
89 
92 {
93  return subRun_;
94 }
95 
96 inline bool
98 {
100 }
101 
102 inline bool
104 {
106 }
107 
109 
110 inline art::SubRunID
112 {
113  if (!isValid()) {
115  << "cannot increment invalid subrun number.";
117  return nextRun();
118  }
119  return SubRunID(run_, subRun_ + 1);
120 }
121 
122 inline art::SubRunID
124 {
126 }
127 
128 inline art::SubRunID
130 {
131  if (!isValid()) {
133  << "cannot decrement invalid subrun number.";
134  } else if (subRun_ == IDNumber<Level::SubRun>::first()) {
135  return previousRun();
136  }
137  return SubRunID(run_, subRun_ - 1);
138 }
139 
140 inline art::SubRunID
142 {
144 }
145 
146 inline art::SubRunID
148 {
150 }
151 
152 inline art::SubRunID
154 {
156 }
157 
158 inline art::SubRunID
160 {
162 }
163 
164 inline art::SubRunID
166 {
168 }
169 
170 inline constexpr art::SubRunID
172 {
173  return SubRunID{FlushFlag()};
174 }
175 
176 inline art::SubRunID
178 {
179  return SubRunID{rID, FlushFlag()};
180 }
181 
182 // Comparison operators.
183 inline bool
185 {
186  return other.run_ == run_ && other.subRun_ == subRun_;
187 }
188 
189 inline bool
191 {
192  return !(*this == other);
193 }
194 
196 
197 inline bool
199 {
202  if (run_ == other.run_) {
203  return op(subRun_, other.subRun_);
204  } else {
205  return run_ < other.run_;
206  }
207 }
208 
209 inline bool
211 {
212  return (*this < other) || (*this == other);
213 }
214 
215 inline bool
217 {
218  return (other < *this);
219 }
220 
221 inline bool
223 {
224  return !(*this < other);
225 }
226 
227 inline constexpr art::SubRunID::SubRunID(FlushFlag) noexcept
228  : run_(RunID::flushRun()), subRun_(IDNumber<Level::SubRun>::flush_value())
229 {}
230 
232  : run_(std::move(rID)), subRun_(IDNumber<Level::SubRun>::flush_value())
233 {}
234 
236  : run_(std::move(rID)), subRun_(inRangeOrInvalid(srID))
237 {
238  checkSane();
239 }
240 
241 inline art::SubRunNumber_t
243 {
246  << "Attempt to construct SubRunID with an invalid number.\n"
247  << "Maybe you want SubRunID::flushSubRun()?\n";
248  }
249  return sr;
250 }
251 
252 inline void
254 {
255  if (isValid() && !run_.isValid()) {
257  << "SubRunID is not meaningful with valid subRun and invalid Run.\n";
258  }
259 }
260 
261 #endif /* canvas_Persistency_Provenance_SubRunID_h */
262 
263 // Local Variables:
264 // mode: c++
265 // End:
bool operator>=(SubRunID const &other) const
Definition: SubRunID.h:222
RunID next() const
Definition: RunID.h:84
bool operator==(SubRunID const &other) const
Definition: SubRunID.h:184
friend std::ostream & operator<<(std::ostream &os, SubRunID const &iID)
Level
Definition: Level.h:13
STL namespace.
SubRunID previousRun() const
Definition: SubRunID.h:141
bool operator>(SubRunID const &other) const
Definition: SubRunID.h:216
RunNumber_t run() const
Definition: RunID.h:64
bool isValid() const
Definition: SubRunID.h:97
RunID const & runID() const
Definition: SubRunID.h:79
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
SubRunID next() const
Definition: SubRunID.h:111
RunID run_
Definition: SubRunID.h:64
static RunID maxRun()
Definition: RunID.h:110
RunNumber_t run() const
Definition: SubRunID.h:85
bool operator!=(SubRunID const &other) const
Definition: SubRunID.h:190
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
void checkSane()
Definition: SubRunID.h:253
SubRunID nextRun() const
Definition: SubRunID.h:123
SubRunNumber_t subRun_
Definition: SubRunID.h:65
bool operator<=(SubRunID const &other) const
Definition: SubRunID.h:210
static SubRunID firstSubRun()
Definition: SubRunID.h:153
RunID previous() const
Definition: RunID.h:97
bool isFlush() const
Definition: SubRunID.h:103
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static constexpr SubRunID flushSubRun() noexcept
Definition: SubRunID.h:171
SubRunID previous() const
Definition: SubRunID.h:129
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:165
bool isValid() const
Definition: RunID.h:70
Definition: MVAAlg.h:12
SubRunNumber_t inRangeOrInvalid(SubRunNumber_t sr)
Definition: SubRunID.h:242
constexpr SubRunID() noexcept
Definition: SubRunID.h:68
SubRunNumber_t subRun() const
Definition: SubRunID.h:91
static RunID firstRun()
Definition: RunID.h:116
static SubRunID maxSubRun()
Definition: SubRunID.h:147
bool operator<(SubRunID const &other) const
Definition: SubRunID.h:198
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120