LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ChangeTrackers.h
Go to the documentation of this file.
1 
8 #ifndef UTIL_CHANGETRACKERS_H
9 #define UTIL_CHANGETRACKERS_H
10 
11 // LArSoft libraries
12 #include "larcoreobj/SimpleTypesAndConstants/geo_types.h" // geo::PlaneID
13 
14 // framework libraries
18 
19 // C/C++ standard libraries
20 #include <string> // std::to_string()
21 #include <ostream>
22 #include <type_traits> // std::enable_if_t
23 
24 
25 namespace util {
26 
33  public:
35  EventChangeTracker_t() = default;
36 
39 
41  EventChangeTracker_t(art::EventID const& evt_id): state{evt_id} {}
42 
46  bool same(EventChangeTracker_t const& as) const
47  { return as.eventID() == eventID(); }
48 
50  bool isValid() const { return eventID() != art::EventID(); }
51 
53  bool operator== (EventChangeTracker_t const& as) const { return same(as); }
54 
56  bool operator!= (EventChangeTracker_t const& than) const
57  { return !same(than); }
59 
63  void clear() { set(art::EventID()); }
64 
66  void set(art::EventID const& evt_id) { state.event_id = evt_id; }
67 
69  void set(art::Event const& evt) { set(evt.id()); }
70 
73  {
74  if (same(trk)) return false;
75  *this = trk;
76  return true;
77  }
79 
81  operator std::string() const
82  {
83  return "R:" + std::to_string(eventID().run())
84  + " S:" + std::to_string(eventID().subRun())
85  + " E:" + std::to_string(eventID().event());
86  }
87 
88 
89  protected:
91  art::EventID const& eventID() const { return state.event_id; }
92 
93 
94  private:
95  struct LocalState_t {
97  };
98 
100 
101  }; // EventChangeTracker_t
102 
103 
104  inline std::ostream& operator<<
105  (std::ostream& out, EventChangeTracker_t const& trk)
106  { out << std::string(trk); return out; }
107 
108 
109 
117  public:
118 
120  DataProductChangeTracker_t() = default;
121 
124  (art::Event const& evt, art::InputTag const& label):
125  EventChangeTracker_t(evt), state{label}
126  {}
127 
130  (art::EventID const& evt_id, art::InputTag const& label):
131  EventChangeTracker_t(evt_id), state{label}
132  {}
133 
134 
138  art::InputTag const& inputLabel() const { return state.input_label; }
139 
141  bool sameEvent(DataProductChangeTracker_t const& as) const
142  { return EventChangeTracker_t::same(as); }
143 
145  bool same(DataProductChangeTracker_t const& as) const
146  { return sameEvent(as) && (inputLabel() == as.inputLabel()); }
147 
149  bool isValid() const
150  {
151  return
152  EventChangeTracker_t::isValid() && !inputLabel().label().empty();
153  }
154 
157  { return same(as); }
158 
160  bool operator!= (DataProductChangeTracker_t const& than) const
161  { return !same(than); }
163 
164 
168  void clear()
169  { EventChangeTracker_t::clear(); SetInputLabel(art::InputTag()); }
170 
172  void set(art::Event const& evt, art::InputTag const& label)
173  { EventChangeTracker_t::set(evt); SetInputLabel(label); }
174 
176  bool update(DataProductChangeTracker_t const& new_prod)
177  {
178  if (same(new_prod)) return false;
179  *this = new_prod;
180  return true;
181  }
182 
184 
186  operator std::string() const
187  {
188  return EventChangeTracker_t::operator std::string()
189  + " I{" + inputLabel().encode() + "}";
190  }
191 
192  private:
193  struct LocalState_t {
195  }; // LocalState_t
196 
198 
199  void SetInputLabel(art::InputTag const& label)
200  { state.input_label = label; }
201 
202  }; // DataProductChangeTracker_t
203 
204 
205  inline std::ostream& operator<<
206  (std::ostream& out, DataProductChangeTracker_t const& trk)
207  { out << std::string(trk); return out; }
208 
209 
210 
219  public:
220 
222  PlaneDataChangeTracker_t() = default;
223 
226  art::Event const& evt, art::InputTag const& label, geo::PlaneID const& pid
227  ):
228  DataProductChangeTracker_t(evt, label), state{pid}
229  {}
230 
233  art::EventID const& evt_id, art::InputTag const& label,
234  geo::PlaneID const& pid
235  ):
236  DataProductChangeTracker_t(evt_id, label), state{pid}
237  {}
238 
239 
244 
246  geo::PlaneID const& planeID() const { return state.plane_id; }
247 
249  bool sameProduct(PlaneDataChangeTracker_t const& as) const
250  { return DataProductChangeTracker_t::same(as); }
251 
253  bool sameTPC(PlaneDataChangeTracker_t const& as) const
254  {
255  return sameEvent(as)
256  && (static_cast<geo::TPCID const&>(planeID()) == as.planeID());
257  }
258 
260  bool same(PlaneDataChangeTracker_t const& as) const
261  { return sameEvent(as) && (planeID() == as.planeID()); }
262 
264  bool isValid() const
265  { return DataProductChangeTracker_t::isValid() && planeID().isValid; }
266 
268  bool operator== (PlaneDataChangeTracker_t const& as) const
269  { return same(as); }
270 
272  bool operator!= (PlaneDataChangeTracker_t const& than) const
273  { return !same(than); }
275 
276 
280  void clear()
281  { DataProductChangeTracker_t::clear(); SetPlaneID(geo::PlaneID()); }
282 
284  void set(
285  art::Event const& evt, art::InputTag const& label, geo::PlaneID const& pid
286  )
287  { DataProductChangeTracker_t::set(evt, label); SetPlaneID(pid); }
288 
290  bool update(PlaneDataChangeTracker_t const& new_prod)
291  {
292  if (same(new_prod)) return false;
293  *this = new_prod;
294  return true;
295  }
296 
298 
300  operator std::string() const
301  {
302  return DataProductChangeTracker_t::operator std::string()
303  + " " + std::string(planeID());
304  }
305 
306  private:
307  struct LocalState_t {
309  }; // LocalState_t
310 
312 
313  void SetPlaneID(geo::PlaneID const& pid) { state.plane_id = pid; }
314 
315  }; // PlaneDataChangeTracker_t
316 
317 
318  inline std::ostream& operator<<
319  (std::ostream& out, PlaneDataChangeTracker_t const& trk)
320  { out << std::string(trk); return out; }
321 
322 
323 } // namespace util
324 
325 #endif // UTIL_CHANGETRACKERS_H
EventChangeTracker_t(art::Event const &evt)
Constructor: current event as specified.
void set(art::EventID const &evt_id)
Sets the current event ID.
art::EventID event_id
ID of the current event.
bool isValid() const
Returns whether there is a current event.
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:17
bool sameProduct(PlaneDataChangeTracker_t const &as) const
Returns whether we are in the same event (the rest could differ)
PlaneDataChangeTracker_t(art::EventID const &evt_id, art::InputTag const &label, geo::PlaneID const &pid)
Constructor: specifies current data product and TPC plane.
art::EventID const & eventID() const
Returns the current event ID (it might be made public...)
Detects the presence of a new event or data product.
The data type to uniquely identify a Plane.
Definition: geo_types.h:250
bool sameTPC(PlaneDataChangeTracker_t const &as) const
Returns whether we have the same data product and TPC as "as".
Detects the presence of a new event.
void clear()
Set a new event and data product label as current.
art::InputTag const & inputLabel() const
Returns whether we are in the same event (the rest could differ)
void clear()
Sets the current event ID.
bool update(EventChangeTracker_t const &trk)
Sets the current event, and returns true if it is changed.
void SetInputLabel(art::InputTag const &label)
void SetPlaneID(geo::PlaneID const &pid)
bool operator!=(EventChangeTracker_t const &than) const
Returns whether this tracker is in a different state than another.
EventChangeTracker_t()=default
Default constructor: no current event, next event is a new one.
bool isValid() const
Returns whether there is a data product and plane.
The data type to uniquely identify a TPC.
Definition: geo_types.h:195
Definition of data types for geometry description.
LocalState_t state
local state of the tracker (may inherit some more)
Detects the presence of a new event, data product or wire plane.
EventChangeTracker_t(art::EventID const &evt_id)
Constructor: current event as specified by the event ID.
bool update(PlaneDataChangeTracker_t const &new_prod)
Update to a new data product, return true if it has changed.
bool same(EventChangeTracker_t const &as) const
Returns whether this tracker is in the same state as another.
std::string to_string(Flag_t< Storage > const flag)
Convert a flag into a stream (shows its index).
Definition: BitMask.h:187
void clear()
Set a new event and data product label as current.
void set(art::Event const &evt, art::InputTag const &label)
Set a new event and data product label as current.
bool same(PlaneDataChangeTracker_t const &as) const
Returns whether we have the same plane data as "as".
bool same(DataProductChangeTracker_t const &as) const
Returns whether we have same data product as in "as".
TCEvent evt
Definition: DataStructs.cxx:5
bool update(DataProductChangeTracker_t const &new_prod)
Update to a new data product, return true if it has changed.
geo::PlaneID const & planeID() const
Returns the current plane ID.
EventID id() const
Definition: Event.h:56
bool isValid() const
Returns whether there is a current event and data product.
Event finding and building.
PlaneDataChangeTracker_t(art::Event const &evt, art::InputTag const &label, geo::PlaneID const &pid)
Constructor: specifies current data product and TPC plane.
bool sameEvent(DataProductChangeTracker_t const &as) const
Returns whether we are in the same event (the rest could differ)
bool operator==(EventChangeTracker_t const &as) const
Returns whether this tracker is in the same state as another.