LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
ChargedSpacePointCreator.cpp
Go to the documentation of this file.
1 
10 // class header
12 
13 // framework libraries
14 #include "cetlib_except/exception.h"
15 
16 // C/C++ standard libraries
17 #include <utility> // std::move()
18 #include <iterator> // std::back_inserter()
19 #include <cassert>
20 
21 
22 //------------------------------------------------------------------------------
24  (art::Event& event, std::string const& instanceName /* = {} */)
25  : fEvent(event)
26  , fInstanceName(instanceName)
27  , fSpacePoints(std::make_unique<std::vector<recob::SpacePoint>>())
28  , fCharges(std::make_unique<std::vector<recob::PointCharge>>())
29  {}
30 
31 
32 //------------------------------------------------------------------------------
34  (recob::SpacePoint const& spacePoint, recob::PointCharge const& charge)
35 {
36  // if these assertion fail, add() is being called after put()
37  assert(fSpacePoints);
38  assert(fCharges);
39 
40  fSpacePoints->push_back(spacePoint);
41  fCharges->push_back(charge);
42 
43  assert(fSpacePoints->size() == fCharges->size());
44 
45 } // recob::ChargedSpacePointCollectionCreator::add(copy)
46 
47 
48 //------------------------------------------------------------------------------
50  (recob::SpacePoint&& spacePoint, recob::PointCharge&& charge)
51 {
52  // if these assertion fail, add() is being called after put()
53  assert(fSpacePoints);
54  assert(fCharges);
55 
56  fSpacePoints->push_back(std::move(spacePoint));
57  fCharges->push_back(std::move(charge));
58 
59  assert(fSpacePoints->size() == fCharges->size());
60 
61 } // recob::ChargedSpacePointCollectionCreator::add()
62 
63 
64 //------------------------------------------------------------------------------
66  std::vector<recob::SpacePoint>&& spacePoints,
67  std::vector<recob::PointCharge>&& charges
68  )
69 {
70  // if these assertion fail, addAll() is being called after put()
71  assert(fSpacePoints);
72  assert(fCharges);
73 
74  if (spacePoints.size() != charges.size()) {
75  throw cet::exception("ChargedSpacePointCollectionCreator")
76  << "Input collections of inconsistent size:"
77  << " " << spacePoints.size() << " (space points)"
78  << "and " << charges.size() << " (charges)"
79  << "\n";
80  }
81  if (empty()) {
82  *fSpacePoints = std::move(spacePoints);
83  *fCharges = std::move(charges);
84  }
85  else {
86  fSpacePoints->reserve(fSpacePoints->size() + spacePoints.size());
87  for (auto&& obj: spacePoints) fSpacePoints->push_back(std::move(obj));
88  spacePoints.clear();
89 
90  fCharges->reserve(fCharges->size() + charges.size());
91  for (auto&& obj: charges) fCharges->push_back(std::move(obj));
92  charges.clear();
93  }
94 
95  assert(fSpacePoints->size() == fCharges->size());
96 
97 } // recob::ChargedSpacePointCollectionCreator::addAll()
98 
99 
100 //------------------------------------------------------------------------------
102  std::vector<recob::SpacePoint> const& spacePoints,
103  std::vector<recob::PointCharge> const& charges
104  )
105 {
106  // if these assertion fail, addAll() is being called after put()
107  assert(fSpacePoints);
108  assert(fCharges);
109 
110 
111  if (spacePoints.size() != charges.size()) {
112  throw cet::exception("ChargedSpacePointCollectionCreator")
113  << "Input collections of inconsistent size:"
114  << " " << spacePoints.size() << " (space points)"
115  << "and " << charges.size() << " (charges)"
116  << "\n";
117  }
118  fSpacePoints->reserve(fSpacePoints->size() + spacePoints.size());
119  std::copy
120  (spacePoints.begin(), spacePoints.end(), std::back_inserter(*fSpacePoints));
121 
122  fCharges->reserve(fCharges->size() + charges.size());
123  std::copy(charges.begin(), charges.end(), std::back_inserter(*fCharges));
124 
125  assert(fSpacePoints->size() == fCharges->size());
126 
127 } // recob::ChargedSpacePointCollectionCreator::addAll()
128 
129 
130 //------------------------------------------------------------------------------
133 
134  fEvent.put(std::move(fSpacePoints), fInstanceName);
135  fEvent.put(std::move(fCharges), fInstanceName);
136 
137  assert(spent());
138  assert(empty());
139 } // recob::ChargedSpacePointCollectionCreator::put()
140 
141 
142 //------------------------------------------------------------------------------
144 
145  if (fSpacePoints) fSpacePoints->clear();
146  if (fCharges) fCharges->clear();
147 
148  assert(empty());
149 
150 } // recob::ChargedSpacePointCollectionCreator::clear()
151 
152 
153 //------------------------------------------------------------------------------
156  (std::size_t i) const
157 {
158  return fSpacePointPtrMaker
159  ? (*fSpacePointPtrMaker)(i): art::Ptr<recob::SpacePoint>{};
160 } // recob::ChargedSpacePointCollectionCreator::spacePointPtr()
161 
162 
163 //------------------------------------------------------------------------------
166  (std::size_t i) const
167 {
168  return fChargePtrMaker? (*fChargePtrMaker)(i): art::Ptr<recob::PointCharge>{};
169 } // recob::ChargedSpacePointCollectionCreator::chargePtr()
170 
171 
172 //------------------------------------------------------------------------------
174  (art::ProducerBase& producer, std::string const& instanceName)
175 {
176 
177  producer.produces<std::vector<recob::SpacePoint>>(instanceName);
178  producer.produces<std::vector<recob::PointCharge>>(instanceName);
179 
180 } // recob::ChargedSpacePointCollectionCreator::produces()
181 
182 
183 //------------------------------------------------------------------------------
art::Ptr< recob::SpacePoint > spacePointPtr(std::size_t i) const
Returns an art pointer to the specified space point (no check done!).
art::Event & fEvent
The event this object is bound to.
std::unique_ptr< std::vector< recob::SpacePoint > > fSpacePoints
Space point data.
std::string fInstanceName
Instance name of all the data products.
void produces(std::string const &instanceName={}, Persistable const persistable=Persistable::Yes)
std::unique_ptr< art::PtrMaker< recob::SpacePoint > > fSpacePointPtrMaker
Space point pointer maker.
static void produces(art::ProducerBase &producer, std::string const &instanceName={})
Declares the data products being produced.
ProductID put(std::unique_ptr< PROD > &&product)
Definition: Event.h:102
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.
bool empty() const
Returns whether there are currently no space points in the collection.
art::Ptr< recob::PointCharge > chargePtr(std::size_t i) const
Returns an art pointer to the specified charge (no check done!).
std::unique_ptr< std::vector< recob::PointCharge > > fCharges
Charge data.
void addAll(std::vector< recob::SpacePoint > &&spacePoints, std::vector< recob::PointCharge > &&charges)
Inserts all the space points and associated data from the vectors into the collection.
Helpers to create space points with associated charge.
void put()
Puts all data products into the event, leaving the creator empty().
void clear()
Removes all data from the collection, making it empty().
void add(recob::SpacePoint const &spacePoint, recob::PointCharge const &charge)
Inserts the specified space point and associated data into the collection.
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
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