LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
EventID.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Provenance_EventID_h
2 #define canvas_Persistency_Provenance_EventID_h
3 
4 // An EventID labels an unique readout of the data acquisition system,
5 // which we call an "event".
6 
10 #include "canvas/Utilities/Level.h"
11 
12 #include <iosfwd>
13 
14 namespace art {
15  class EventID;
16 
17  std::ostream& operator<<(std::ostream& os, EventID const& iID);
18 }
19 
20 class art::EventID {
21 public:
22  constexpr EventID() noexcept;
24 
25  // This needs to be done in enough places in the framework that this
26  // constructor should be public.
27  EventID(SubRunID const& sID, EventNumber_t e);
28 
29  RunID const& runID() const;
30  RunNumber_t run() const;
31  SubRunID const& subRunID() const;
32  SubRunNumber_t subRun() const;
33  EventNumber_t event() const;
34 
35  bool isValid() const;
36  bool isFlush() const;
37 
38  EventID next() const;
41  EventID nextRun() const;
42  EventID previous() const;
43  EventID previousSubRun() const;
44  EventID previousRun() const;
45 
46  static EventID maxEvent();
47  static EventID firstEvent();
48  static EventID firstEvent(SubRunID const& srID);
49  static constexpr EventID invalidEvent() noexcept;
50  static EventID invalidEvent(RunID rID);
51  static EventID invalidEvent(SubRunID const& srID);
52  static constexpr EventID flushEvent() noexcept;
53  static EventID flushEvent(RunID rID);
54  static EventID flushEvent(SubRunID srID);
55 
56  // Comparison operators.
57  bool operator==(EventID const& other) const;
58  bool operator!=(EventID const& other) const;
59  bool operator<(EventID const& other) const;
60  bool operator>(EventID const& other) const;
61  bool operator<=(EventID const& other) const;
62  bool operator>=(EventID const& other) const;
63 
64  friend std::ostream& operator<<(std::ostream& os, EventID const& iID);
65 
66 private:
67  struct FlushFlag {};
68 
69  explicit constexpr EventID(FlushFlag) noexcept;
70  EventID(RunID rID, FlushFlag);
71  EventID(SubRunID srID, FlushFlag);
72 
74 
77 };
78 
79 inline constexpr art::EventID::EventID() noexcept
80  : subRun_(), event_(IDNumber<Level::Event>::invalid())
81 {}
82 
84  : subRun_(r, sr), event_(inRangeOrInvalid(e))
85 {}
86 
88  : subRun_(sID), event_(inRangeOrInvalid(e))
89 {}
90 
91 inline art::RunID const&
93 {
94  return subRun_.runID();
95 }
96 
97 inline art::RunNumber_t
99 {
100  return subRun_.run();
101 }
102 
103 inline art::SubRunID const&
105 {
106  return subRun_;
107 }
108 
109 inline art::SubRunNumber_t
111 {
112  return subRun_.subRun();
113 }
114 
115 inline art::EventNumber_t
117 {
118  return event_;
119 }
120 
121 inline bool
123 {
125 }
126 
127 inline bool
129 {
131 }
132 
133 inline art::EventID
135 {
136  if (!isValid()) {
138  << "Cannot increment invalid event number.\n";
140  return nextSubRun();
141  } else {
142  return EventID{subRun_, event_ + 1u};
143  }
144 }
145 
146 inline art::EventID
148 {
149  return EventID{subRun_.next(), first};
150 }
151 
152 inline art::EventID
154 {
156 }
157 
158 inline art::EventID
160 {
161  if (!isValid()) {
163  << "cannot decrement invalid event number.";
164  } else if (event_ == IDNumber<Level::Event>::first()) {
165  return previousSubRun();
166  } else {
167  return EventID{subRun_, event_ - 1u};
168  }
169 }
170 
171 inline art::EventID
173 {
175 }
176 
177 inline art::EventID
179 {
181 }
182 
183 inline art::EventID
185 {
187 }
188 
189 inline art::EventID
191 {
193 }
194 
195 inline art::EventID
197 {
198  return EventID{srID, IDNumber<Level::Event>::first()};
199 }
200 
201 inline constexpr art::EventID
203 {
204  return EventID{};
205 }
206 
207 inline art::EventID
209 {
210  return EventID{SubRunID::invalidSubRun(rID),
212 }
213 
214 inline art::EventID
216 {
218 }
219 
220 inline constexpr art::EventID
222 {
223  return EventID{FlushFlag()};
224 }
225 
226 inline art::EventID
228 {
229  return EventID{rID, FlushFlag()};
230 }
231 
232 inline art::EventID
234 {
235  return EventID{srID, FlushFlag()};
236 }
237 
238 // Comparison operators.
239 inline bool
241 {
242  return other.subRun_ == subRun_ && other.event_ == event_;
243 }
244 
245 inline bool
247 {
248  return !(*this == other);
249 }
250 
252 
253 inline bool
255 {
257  if (subRun_ == other.subRun_) {
258  return op(event_, other.event_);
259  } else {
260  return subRun_ < other.subRun_;
261  }
262 }
263 
264 inline bool
266 {
267  return (other < *this);
268 }
269 
270 inline bool
272 {
273  return (*this < other) || (*this == other);
274 }
275 
276 inline bool
278 {
279  return !(*this < other);
280 }
281 
282 inline constexpr art::EventID::EventID(FlushFlag) noexcept
283  : subRun_(SubRunID::flushSubRun())
284  , event_(IDNumber<Level::Event>::flush_value())
285 {}
286 
288  : subRun_(SubRunID::flushSubRun(rID))
289  , event_(IDNumber<Level::Event>::flush_value())
290 {}
291 
293  : subRun_(std::move(srID)), event_(IDNumber<Level::Event>::flush_value())
294 {}
295 
296 inline art::EventNumber_t
298 {
299  if (e == IDNumber<Level::Event>::invalid() ||
301  return e;
302  } else {
304  << "Attempt to construct an EventID with an invalid number.\n"
305  << "Maybe you want EventID::flushEvent()?\n";
306  }
307 }
308 
309 #endif /* canvas_Persistency_Provenance_EventID_h */
310 
311 // Local Variables:
312 // mode: c++
313 // End:
EventID previous() const
Definition: EventID.h:159
bool isValid() const
Definition: EventID.h:122
RunID const & runID() const
Definition: EventID.h:92
TRandom r
Definition: spectrum.C:23
static constexpr EventID flushEvent() noexcept
Definition: EventID.h:221
SubRunID const & subRunID() const
Definition: EventID.h:104
EventID next() const
Definition: EventID.h:134
bool operator<(EventID const &other) const
Definition: EventID.h:254
static EventID maxEvent()
Definition: EventID.h:184
Level
Definition: Level.h:13
STL namespace.
bool operator>=(EventID const &other) const
Definition: EventID.h:277
EventNumber_t inRangeOrInvalid(EventNumber_t e)
Definition: EventID.h:297
SubRunID previousRun() const
Definition: SubRunID.h:141
EventID previousRun() const
Definition: EventID.h:178
bool isFlush() const
Definition: EventID.h:128
bool operator>(EventID const &other) const
Definition: EventID.h:265
RunNumber_t run() const
Definition: EventID.h:98
bool isValid() const
Definition: SubRunID.h:97
bool operator!=(EventID const &other) const
Definition: EventID.h:246
RunID const & runID() const
Definition: SubRunID.h:79
std::ostream & operator<<(std::ostream &os, const GroupSelector &gs)
SubRunID next() const
Definition: SubRunID.h:111
RunNumber_t run() const
Definition: SubRunID.h:85
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:119
SubRunID nextRun() const
Definition: SubRunID.h:123
EventID nextSubRun(EventNumber_t first=IDNumber< Level::Event >::first()) const
Definition: EventID.h:147
static SubRunID firstSubRun()
Definition: SubRunID.h:153
constexpr EventID() noexcept
Definition: EventID.h:79
SubRunID subRun_
Definition: EventID.h:75
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool operator==(EventID const &other) const
Definition: EventID.h:240
SubRunID previous() const
Definition: SubRunID.h:129
static constexpr EventID invalidEvent() noexcept
Definition: EventID.h:202
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:165
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:118
Definition: MVAAlg.h:12
EventNumber_t event() const
Definition: EventID.h:116
bool operator<=(EventID const &other) const
Definition: EventID.h:271
SubRunNumber_t subRun() const
Definition: SubRunID.h:91
static SubRunID maxSubRun()
Definition: SubRunID.h:147
EventID previousSubRun() const
Definition: EventID.h:172
EventID nextRun() const
Definition: EventID.h:153
Float_t e
Definition: plot.C:35
static EventID firstEvent()
Definition: EventID.h:190
EventNumber_t event_
Definition: EventID.h:76
friend std::ostream & operator<<(std::ostream &os, EventID const &iID)
SubRunNumber_t subRun() const
Definition: EventID.h:110
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:120