LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
ChargedSpacePointCreator.h
Go to the documentation of this file.
1 
13 #ifndef LARDATA_ARTDATAHELPER_CHARGEDSPACEPOINTCREATOR_H
14 #define LARDATA_ARTDATAHELPER_CHARGEDSPACEPOINTCREATOR_H
15 
16 // LArSoft libraries
19 
20 // framework libraries
25 
26 // C/C++ standard libraries
27 #include <vector>
28 #include <memory> // std::unique_ptr<>
29 #include <type_traits> // std::enable_if_t, ...
30 #include <cstdlib> // std::size_t
31 
32 
33 namespace recob {
34 
35  namespace details {
36 
37  template <typename T, typename = void>
38  struct is_art_module;
39 
40  template <typename T>
41  constexpr bool is_art_module_v = is_art_module<T>();
42 
43  } // namespace details
44 
45 
240 
241  public:
242 
243  //--- BEGIN Constructors ---------------------------------------------------
246 
258  (art::Event& event, std::string const& instanceName = {});
259 
270  template <typename Producer>
272  art::Event& event, Producer const& producer,
273  std::string const& instanceName = {},
274  std::enable_if_t<details::is_art_module_v<Producer>>* = nullptr
275  );
276 
278  //--- END Constructors ---------------------------------------------------
279 
280 
281  //--- BEGIN Insertion and finish operations --------------------------------
284 
286 
297  void add
298  (recob::SpacePoint const& spacePoint, recob::PointCharge const& charge);
299  void add(recob::SpacePoint&& spacePoint, recob::PointCharge&& charge);
301 
303 
318  void addAll(
319  std::vector<recob::SpacePoint>&& spacePoints,
320  std::vector<recob::PointCharge>&& charges
321  );
322  void addAll(
323  std::vector<recob::SpacePoint> const& spacePoints,
324  std::vector<recob::PointCharge> const& charges
325  );
327 
338  void put();
339 
340 
342  //--- END Insertion and finish operations --------------------------------
343 
344 
345  //--- BEGIN Queries and operations -----------------------------------------
348 
350  bool empty() const { return spent() || fSpacePoints->empty(); }
351 
353  std::size_t size() const { return spent()? 0U: fSpacePoints->size(); }
354 
356  void clear();
357 
359  bool spent() const { return !fSpacePoints; }
360 
362  bool canMakePointers() const { return bool(fSpacePointPtrMaker); }
363 
365  //--- END Queries and operations -------------------------------------------
366 
367 
368  //--- BEGIN Complimentary unchecked element access -------------------------
371 
373  recob::SpacePoint const& spacePoint(std::size_t i) const
374  { return fSpacePoints->operator[](i); }
375 
378  { return spacePoint(lastIndex()); }
379 
381  art::Ptr<recob::SpacePoint> spacePointPtr(std::size_t i) const;
382 
385  { return spacePointPtr(lastIndex()); }
386 
387 
389  recob::PointCharge const& charge(std::size_t i) const
390  { return fCharges->operator[](i); }
391 
394  { return charge(lastIndex()); }
395 
397  art::Ptr<recob::PointCharge> chargePtr(std::size_t i) const;
398 
401  { return chargePtr(lastIndex()); }
402 
404  //--- END Complimentary unchecked element access ---------------------------
405 
406 
407  //--- BEGIN Static constructor interface -----------------------------------
409 
431  static void produces
432  (art::ProducerBase& producer, std::string const& instanceName = {});
433 
435  //--- END Static constructor interface -------------------------------------
436 
437 
438  private:
440 
441  std::string fInstanceName;
442 
444  std::unique_ptr<std::vector<recob::SpacePoint>> fSpacePoints;
446  std::unique_ptr<art::PtrMaker<recob::SpacePoint>> fSpacePointPtrMaker;
448  std::unique_ptr<std::vector<recob::PointCharge>> fCharges;
450  std::unique_ptr<art::PtrMaker<recob::PointCharge>> fChargePtrMaker;
451 
453  std::size_t lastIndex() const { return size() - 1U; }
454 
455  }; // class ChargedSpacePointCollectionCreator
456 
457 } // namespace recob
458 
459 
460 //------------------------------------------------------------------------------
461 //--- template implementation
462 //------------------------------------------------------------------------------
463 namespace recob {
464 
465  namespace details {
466 
467  //--------------------------------------------------------------------------
468  template <typename T>
469  constexpr bool always_true_v = true;
470 
471  template <typename T, typename /* = void */>
472  struct is_art_module: public std::false_type {};
473 
474  template <typename T>
476  <T, std::enable_if_t<always_true_v<typename T::ModuleType>>>
477  : public std::true_type
478  {};
479 
480  //--------------------------------------------------------------------------
481 
482  } // namespace details
483 
484 } // namespace recob
485 
486 
487 //------------------------------------------------------------------------------
488 template <typename Producer>
490  art::Event& event,
491  Producer const& producer,
492  std::string const& instanceName /* = {} */,
493  std::enable_if_t<details::is_art_module_v<Producer>>* /* = nullptr */
494 )
495  : ChargedSpacePointCollectionCreator(event, instanceName)
496 {
497 
498  fSpacePointPtrMaker = std::make_unique<art::PtrMaker<recob::SpacePoint>>
499  (fEvent, producer, fInstanceName);
500  fChargePtrMaker = std::make_unique<art::PtrMaker<recob::PointCharge>>
501  (fEvent, producer, fInstanceName);
502 
503 } // ChargedSpacePointCollectionCreator(Producer)
504 
505 
506 //------------------------------------------------------------------------------
507 
508 #endif // LARDATA_ARTDATAHELPER_CHARGEDSPACEPOINTCREATOR_H
std::size_t size() const
Returns the number of space points currently in the collection.
Reconstruction base classes.
constexpr bool is_art_module_v
art::Event & fEvent
The event this object is bound to.
recob::PointCharge const & charge(std::size_t i) const
Returns the last inserted charge; undefined behaviour if empty().
std::size_t lastIndex() const
Returns the index of the last element (undefined if empty).
art::Ptr< recob::SpacePoint > lastSpacePointPtr() const
Returns an art pointer to the last inserted space point (no check!).
std::unique_ptr< std::vector< recob::SpacePoint > > fSpacePoints
Space point data.
std::string fInstanceName
Instance name of all the data products.
std::unique_ptr< art::PtrMaker< recob::SpacePoint > > fSpacePointPtrMaker
Space point pointer maker.
STL namespace.
Information about charge reconstructed in the active volume.
constexpr bool always_true_v
art::Ptr< recob::PointCharge > lastChargePtr() const
Returns an art pointer to the inserted charge (no check!).
ChargedSpacePointCollectionCreator(art::Event &event, std::string const &instanceName={})
Constructor binding this object to a specific art event.
bool spent() const
Returns whether put() has already been called.
recob::PointCharge const & lastCharge() const
Returns the last inserted charge; undefined behaviour if empty().
bool empty() const
Returns whether there are currently no space points in the collection.
recob::SpacePoint const & lastSpacePoint() const
Returns the last inserted space point; undefined behaviour if empty().
Creates a collection of space points with associated charge.
std::unique_ptr< std::vector< recob::PointCharge > > fCharges
Charge data.
bool canMakePointers() const
Returns whether art pointer making is enabled.
recob::SpacePoint const & spacePoint(std::size_t i) const
Returns the specified space point; undefined behaviour if not there.
vec_iX clear()
Event finding and building.
std::unique_ptr< art::PtrMaker< recob::PointCharge > > fChargePtrMaker
Charge pointer maker.
Charge reconstructed in the active volume.
Definition: PointCharge.h:31