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  explicit constexpr EventID(FlushFlag);
70  EventID(RunID rID, FlushFlag);
71  EventID(SubRunID srID, FlushFlag);
72 
74 
77 };
78 
79 inline constexpr art::EventID::EventID()
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 
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:
std::ostream & operator<<(std::ostream &os, EDAnalyzer::Table< T > const &t)
Definition: EDAnalyzer.h:184
bool operator<(EventID const &other) const
Definition: EventID.h:254
bool operator==(EventID const &other) const
Definition: EventID.h:240
RunID const & runID() const
Definition: EventID.h:92
static EventID firstEvent()
Definition: EventID.h:190
bool operator>(EventID const &other) const
Definition: EventID.h:265
static constexpr EventID invalidEvent()
Definition: EventID.h:202
bool isValid() const
Definition: EventID.h:122
EventID nextSubRun(EventNumber_t first=IDNumber< Level::Event >::first()) const
Definition: EventID.h:147
Level
Definition: Level.h:12
EventNumber_t inRangeOrInvalid(EventNumber_t e)
Definition: EventID.h:297
SubRunID previousRun() const
Definition: SubRunID.h:139
RunNumber_t run() const
Definition: EventID.h:98
bool operator!=(EventID const &other) const
Definition: EventID.h:246
static constexpr EventID flushEvent()
Definition: EventID.h:221
bool isValid() const
Definition: SubRunID.h:95
EventID nextRun() const
Definition: EventID.h:153
static EventID maxEvent()
Definition: EventID.h:184
RunID const & runID() const
Definition: SubRunID.h:77
SubRunID next() const
Definition: SubRunID.h:109
EventID previous() const
Definition: EventID.h:159
SubRunID const & subRunID() const
Definition: EventID.h:104
RunNumber_t run() const
Definition: SubRunID.h:83
IDNumber_t< Level::SubRun > SubRunNumber_t
Definition: IDNumber.h:118
SubRunID nextRun() const
Definition: SubRunID.h:121
EventID next() const
Definition: EventID.h:134
static SubRunID firstSubRun()
Definition: SubRunID.h:151
constexpr EventID()
Definition: EventID.h:79
SubRunID subRun_
Definition: EventID.h:75
EventNumber_t event() const
Definition: EventID.h:116
EventID previousSubRun() const
Definition: EventID.h:172
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
SubRunNumber_t subRun() const
Definition: EventID.h:110
SubRunID previous() const
Definition: SubRunID.h:127
bool operator<=(EventID const &other) const
Definition: EventID.h:271
static SubRunID invalidSubRun(RunID const &rID)
Definition: SubRunID.h:163
IDNumber_t< Level::Event > EventNumber_t
Definition: IDNumber.h:117
TRandom3 r(0)
Service to store calibration data products (CDP) in the SQLite3 metadatabase of a file...
Definition: FillParentInfo.h:8
EventID previousRun() const
Definition: EventID.h:178
SubRunNumber_t subRun() const
Definition: SubRunID.h:89
static SubRunID maxSubRun()
Definition: SubRunID.h:145
Float_t e
Definition: plot.C:35
bool operator>=(EventID const &other) const
Definition: EventID.h:277
EventNumber_t event_
Definition: EventID.h:76
friend std::ostream & operator<<(std::ostream &os, EventID const &iID)
bool isFlush() const
Definition: EventID.h:128
static constexpr Double_t sr
Definition: Munits.h:164
IDNumber_t< Level::Run > RunNumber_t
Definition: IDNumber.h:119