LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 
11 #include <cstdint>
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();
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;
39  EventID nextSubRun(
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();
50  static EventID invalidEvent(RunID rID);
51  static EventID invalidEvent(SubRunID const& srID);
52  static constexpr EventID flushEvent();
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 
70  explicit constexpr EventID(FlushFlag);
71  EventID(RunID rID, FlushFlag);
72  EventID(SubRunID srID, FlushFlag);
73 
75 
78 };
79 
80 inline constexpr art::EventID::EventID()
81  : subRun_(), event_(IDNumber<Level::Event>::invalid())
82 {}
83 
85  : subRun_(r, sr), event_(inRangeOrInvalid(e))
86 {}
87 
89  : subRun_(sID), event_(inRangeOrInvalid(e))
90 {}
91 
92 inline art::RunID const&
94 {
95  return subRun_.runID();
96 }
97 
98 inline art::RunNumber_t
100 {
101  return subRun_.run();
102 }
103 
104 inline art::SubRunID const&
106 {
107  return subRun_;
108 }
109 
110 inline art::SubRunNumber_t
112 {
113  return subRun_.subRun();
114 }
115 
116 inline art::EventNumber_t
118 {
119  return event_;
120 }
121 
122 inline bool
124 {
126 }
127 
128 inline bool
130 {
132 }
133 
134 inline art::EventID
136 {
137  if (!isValid()) {
139  << "Cannot increment invalid event number.\n";
141  return nextSubRun();
142  } else {
143  return EventID{subRun_, event_ + 1u};
144  }
145 }
146 
147 inline art::EventID
149 {
150  return EventID{subRun_.next(), first};
151 }
152 
153 inline art::EventID
155 {
157 }
158 
159 inline art::EventID
161 {
162  if (!isValid()) {
164  << "cannot decrement invalid event number.";
165  } else if (event_ == IDNumber<Level::Event>::first()) {
166  return previousSubRun();
167  } else {
168  return EventID{subRun_, event_ - 1u};
169  }
170 }
171 
172 inline art::EventID
174 {
176 }
177 
178 inline art::EventID
180 {
182 }
183 
184 inline art::EventID
186 {
188 }
189 
190 inline art::EventID
192 {
194 }
195 
196 inline art::EventID
198 {
199  return EventID{srID, IDNumber<Level::Event>::first()};
200 }
201 
202 inline constexpr art::EventID
204 {
205  return EventID{};
206 }
207 
208 inline art::EventID
210 {
211  return EventID{SubRunID::invalidSubRun(rID),
213 }
214 
215 inline art::EventID
217 {
219 }
220 
221 inline constexpr art::EventID
223 {
224  return EventID{FlushFlag()};
225 }
226 
227 inline art::EventID
229 {
230  return EventID{rID, FlushFlag()};
231 }
232 
233 inline art::EventID
235 {
236  return EventID{srID, FlushFlag()};
237 }
238 
239 // Comparison operators.
240 inline bool
242 {
243  return other.subRun_ == subRun_ && other.event_ == event_;
244 }
245 
246 inline bool
248 {
249  return !(*this == other);
250 }
251 
253 
254 inline bool
256 {
258  if (subRun_ == other.subRun_) {
259  return op(event_, other.event_);
260  } else {
261  return subRun_ < other.subRun_;
262  }
263 }
264 
265 inline bool
267 {
268  return (other < *this);
269 }
270 
271 inline bool
273 {
274  return (*this < other) || (*this == other);
275 }
276 
277 inline bool
279 {
280  return !(*this < other);
281 }
282 
284  : subRun_(SubRunID::flushSubRun())
285  , event_(IDNumber<Level::Event>::flush_value())
286 {}
287 
289  : subRun_(SubRunID::flushSubRun(rID))
290  , event_(IDNumber<Level::Event>::flush_value())
291 {}
292 
294  : subRun_(std::move(srID)), event_(IDNumber<Level::Event>::flush_value())
295 {}
296 
297 inline art::EventNumber_t
299 {
300  if (e == IDNumber<Level::Event>::invalid() ||
302  return e;
303  } else {
305  << "Attempt to construct an EventID with an invalid number.\n"
306  << "Maybe you want EventID::flushEvent()?\n";
307  }
308 }
309 
310 #endif /* canvas_Persistency_Provenance_EventID_h */
311 
312 // Local Variables:
313 // mode: c++
314 // End:
EventID previous() const
Definition: EventID.h:160
bool isValid() const
Definition: EventID.h:123
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
RunID const & runID() const
Definition: EventID.h:93
SubRunID const & subRunID() const
Definition: EventID.h:105
EventID next() const
Definition: EventID.h:135
static constexpr EventID invalidEvent()
Definition: EventID.h:203
bool operator<(EventID const &other) const
Definition: EventID.h:255
static EventID maxEvent()
Definition: EventID.h:185
Level
Definition: Level.h:12
STL namespace.
bool operator>=(EventID const &other) const
Definition: EventID.h:278
EventNumber_t inRangeOrInvalid(EventNumber_t e)
Definition: EventID.h:298
SubRunID previousRun() const
Definition: SubRunID.h:140
EventID previousRun() const
Definition: EventID.h:179
bool isFlush() const
Definition: EventID.h:129
bool operator>(EventID const &other) const
Definition: EventID.h:266
RunNumber_t run() const
Definition: EventID.h:99
bool isValid() const
Definition: SubRunID.h:96
static constexpr EventID flushEvent()
Definition: EventID.h:222
bool operator!=(EventID const &other) const
Definition: EventID.h:247
RunID const & runID() const
Definition: SubRunID.h:78
SubRunID next() const
Definition: SubRunID.h:110
RunNumber_t run() const
Definition: SubRunID.h:84
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
SubRunID nextRun() const
Definition: SubRunID.h:122
EventID nextSubRun(EventNumber_t first=IDNumber< Level::Event >::first()) const
Definition: EventID.h:148
static SubRunID firstSubRun()
Definition: SubRunID.h:152
SubRunID subRun_
Definition: EventID.h:76
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool operator==(EventID const &other) const
Definition: EventID.h:241
SubRunID previous() const
Definition: SubRunID.h:128
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:164
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
HLT enums.
EventNumber_t event() const
Definition: EventID.h:117
bool operator<=(EventID const &other) const
Definition: EventID.h:272
SubRunNumber_t subRun() const
Definition: SubRunID.h:90
constexpr EventID()
Definition: EventID.h:80
static SubRunID maxSubRun()
Definition: SubRunID.h:146
EventID previousSubRun() const
Definition: EventID.h:173
EventID nextRun() const
Definition: EventID.h:154
Float_t e
Definition: plot.C:34
static EventID firstEvent()
Definition: EventID.h:191
EventNumber_t event_
Definition: EventID.h:77
friend std::ostream & operator<<(std::ostream &os, EventID const &iID)
SubRunNumber_t subRun() const
Definition: EventID.h:111
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119