LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 <ostream>
21 #include <string> // std::to_string()
22 #include <type_traits> // std::enable_if_t
23 
24 namespace util {
25 
32  public:
34  EventChangeTracker_t() = default;
35 
38 
40  EventChangeTracker_t(art::EventID const& evt_id) : state{evt_id} {}
41 
45  bool same(EventChangeTracker_t const& as) const { return as.eventID() == eventID(); }
46 
48  bool isValid() const { return eventID() != art::EventID(); }
49 
51  bool operator==(EventChangeTracker_t const& as) const { return same(as); }
52 
54  bool operator!=(EventChangeTracker_t const& than) const { return !same(than); }
56 
60  void clear() { set(art::EventID()); }
61 
63  void set(art::EventID const& evt_id) { state.event_id = evt_id; }
64 
66  void set(art::Event const& evt) { set(evt.id()); }
67 
70  {
71  if (same(trk)) return false;
72  *this = trk;
73  return true;
74  }
76 
78  operator std::string() const
79  {
80  return "R:" + std::to_string(eventID().run()) + " S:" + std::to_string(eventID().subRun()) +
81  " E:" + std::to_string(eventID().event());
82  }
83 
84  protected:
86  art::EventID const& eventID() const { return state.event_id; }
87 
88  private:
89  struct LocalState_t {
91  };
92 
94 
95  }; // EventChangeTracker_t
96 
97  inline std::ostream& operator<<(std::ostream& out, EventChangeTracker_t const& trk)
98  {
99  out << std::string(trk);
100  return out;
101  }
102 
110  public:
112  DataProductChangeTracker_t() = default;
113 
116  : EventChangeTracker_t(evt), state{label}
117  {}
118 
121  : EventChangeTracker_t(evt_id), state{label}
122  {}
123 
127  art::InputTag const& inputLabel() const { return state.input_label; }
128 
130  bool sameEvent(DataProductChangeTracker_t const& as) const
131  {
132  return EventChangeTracker_t::same(as);
133  }
134 
136  bool same(DataProductChangeTracker_t const& as) const
137  {
138  return sameEvent(as) && (inputLabel() == as.inputLabel());
139  }
140 
142  bool isValid() const
143  {
144  return EventChangeTracker_t::isValid() && !inputLabel().label().empty();
145  }
146 
148  bool operator==(DataProductChangeTracker_t const& as) const { return same(as); }
149 
151  bool operator!=(DataProductChangeTracker_t const& than) const { return !same(than); }
153 
157  void clear()
158  {
160  SetInputLabel(art::InputTag());
161  }
162 
164  void set(art::Event const& evt, art::InputTag const& label)
165  {
167  SetInputLabel(label);
168  }
169 
171  bool update(DataProductChangeTracker_t const& new_prod)
172  {
173  if (same(new_prod)) return false;
174  *this = new_prod;
175  return true;
176  }
177 
179 
181  operator std::string() const
182  {
183  return EventChangeTracker_t::operator std::string() + " I{" + inputLabel().encode() + "}";
184  }
185 
186  private:
187  struct LocalState_t {
189  }; // LocalState_t
190 
192 
193  void SetInputLabel(art::InputTag const& label) { state.input_label = label; }
194 
195  }; // DataProductChangeTracker_t
196 
197  inline std::ostream& operator<<(std::ostream& out, DataProductChangeTracker_t const& trk)
198  {
199  out << std::string(trk);
200  return out;
201  }
202 
211  public:
213  PlaneDataChangeTracker_t() = default;
214 
217  art::InputTag const& label,
218  geo::PlaneID const& pid)
219  : DataProductChangeTracker_t(evt, label), state{pid}
220  {}
221 
224  art::InputTag const& label,
225  geo::PlaneID const& pid)
226  : DataProductChangeTracker_t(evt_id, label), state{pid}
227  {}
228 
233 
235  geo::PlaneID const& planeID() const { return state.plane_id; }
236 
238  bool sameProduct(PlaneDataChangeTracker_t const& as) const
239  {
241  }
242 
244  bool sameTPC(PlaneDataChangeTracker_t const& as) const
245  {
246  return sameEvent(as) && (static_cast<geo::TPCID const&>(planeID()) == as.planeID());
247  }
248 
250  bool same(PlaneDataChangeTracker_t const& as) const
251  {
252  return sameEvent(as) && (planeID() == as.planeID());
253  }
254 
256  bool isValid() const { return DataProductChangeTracker_t::isValid() && planeID().isValid; }
257 
259  bool operator==(PlaneDataChangeTracker_t const& as) const { return same(as); }
260 
262  bool operator!=(PlaneDataChangeTracker_t const& than) const { return !same(than); }
264 
268  void clear()
269  {
271  SetPlaneID(geo::PlaneID());
272  }
273 
275  void set(art::Event const& evt, art::InputTag const& label, geo::PlaneID const& pid)
276  {
278  SetPlaneID(pid);
279  }
280 
282  bool update(PlaneDataChangeTracker_t const& new_prod)
283  {
284  if (same(new_prod)) return false;
285  *this = new_prod;
286  return true;
287  }
288 
290 
292  operator std::string() const
293  {
294  return DataProductChangeTracker_t::operator std::string() + " " + std::string(planeID());
295  }
296 
297  private:
298  struct LocalState_t {
300  }; // LocalState_t
301 
303 
304  void SetPlaneID(geo::PlaneID const& pid) { state.plane_id = pid; }
305 
306  }; // PlaneDataChangeTracker_t
307 
308  inline std::ostream& operator<<(std::ostream& out, PlaneDataChangeTracker_t const& trk)
309  {
310  out << std::string(trk);
311  return out;
312  }
313 
314 } // namespace util
315 
316 #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:26
bool sameProduct(PlaneDataChangeTracker_t const &as) const
Returns whether we are in the same event (the rest could differ)
bool operator==(PlaneDataChangeTracker_t const &as) const
Returns whether data product and TPC plane are the same as in "as".
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:463
bool sameTPC(PlaneDataChangeTracker_t const &as) const
Returns whether we have the same data product and TPC as "as".
bool operator!=(DataProductChangeTracker_t const &than) const
Returns whether the event or input label are different than in "than".
bool operator!=(PlaneDataChangeTracker_t const &than) const
Returns whether data product or TPC plane are different than in "than".
bool operator==(DataProductChangeTracker_t const &as) const
Returns whether the event and input label are the same as in "as".
Detects the presence of a new event.
void clear()
Set a new event and data product label as current.
std::ostream & operator<<(std::ostream &out, EventChangeTracker_t const &trk)
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)
decltype(auto) constexpr to_string(T &&obj)
ADL-aware version of std::to_string.
void SetPlaneID(geo::PlaneID const &pid)
DataProductChangeTracker_t(art::Event const &evt, art::InputTag const &label)
Constructor: specifies current event and data product label.
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:381
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.
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".
DataProductChangeTracker_t(art::EventID const &evt_id, art::InputTag const &label)
Constructor: specifies current event ID and data product label.
bool same(DataProductChangeTracker_t const &as) const
Returns whether we have same data product as in "as".
TCEvent evt
Definition: DataStructs.cxx:8
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.cc:23
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.