14 #include "art/Framework/Core/ProducesCollector.h"
15 #include "art/Framework/Principal/Event.h"
16 #include "cetlib_except/exception.h"
26 (art::Event& event, std::string
const& instanceName )
28 , fInstanceName(instanceName)
29 , fSpacePoints(std::make_unique<std::vector<recob::SpacePoint>>())
30 , fCharges(std::make_unique<std::vector<recob::PointCharge>>())
38 std::string
const& instanceName )
42 (event, instanceName);
43 creator.
fChargePtrMaker = std::make_unique<art::PtrMaker<recob::PointCharge>>
44 (event, instanceName);
57 fSpacePoints->push_back(spacePoint);
58 fCharges->push_back(charge);
60 assert(fSpacePoints->size() == fCharges->size());
73 fSpacePoints->push_back(std::move(spacePoint));
74 fCharges->push_back(std::move(charge));
76 assert(fSpacePoints->size() == fCharges->size());
83 std::vector<recob::SpacePoint>&& spacePoints,
84 std::vector<recob::PointCharge>&& charges
91 if (spacePoints.size() != charges.size()) {
92 throw cet::exception(
"ChargedSpacePointCollectionCreator")
93 <<
"Input collections of inconsistent size:"
94 <<
" " << spacePoints.size() <<
" (space points)"
95 <<
"and " << charges.size() <<
" (charges)"
104 for (
auto&& obj: spacePoints)
fSpacePoints->push_back(std::move(obj));
108 for (
auto&& obj: charges)
fCharges->push_back(std::move(obj));
119 std::vector<recob::SpacePoint>
const& spacePoints,
120 std::vector<recob::PointCharge>
const& charges
124 assert(fSpacePoints);
128 if (spacePoints.size() != charges.size()) {
129 throw cet::exception(
"ChargedSpacePointCollectionCreator")
130 <<
"Input collections of inconsistent size:"
131 <<
" " << spacePoints.size() <<
" (space points)"
132 <<
"and " << charges.size() <<
" (charges)"
135 fSpacePoints->reserve(fSpacePoints->size() + spacePoints.size());
137 (spacePoints.begin(), spacePoints.end(), std::back_inserter(*fSpacePoints));
139 fCharges->reserve(fCharges->size() + charges.size());
140 std::copy(charges.begin(), charges.end(), std::back_inserter(*fCharges));
142 assert(fSpacePoints->size() == fCharges->size());
151 fEvent.put(std::move(fSpacePoints), fInstanceName);
152 fEvent.put(std::move(fCharges), fInstanceName);
162 if (fSpacePoints) fSpacePoints->clear();
163 if (fCharges) fCharges->clear();
171 art::Ptr<recob::SpacePoint>
173 (std::size_t i)
const
175 return fSpacePointPtrMaker
176 ? (*fSpacePointPtrMaker)(i): art::Ptr<recob::SpacePoint>{};
181 art::Ptr<recob::PointCharge>
183 (std::size_t i)
const
185 return fChargePtrMaker? (*fChargePtrMaker)(i): art::Ptr<recob::PointCharge>{};
191 (art::ProducesCollector& producesCollector, std::string
const& instanceName)
194 producesCollector.produces<std::vector<recob::SpacePoint>>(instanceName);
195 producesCollector.produces<std::vector<recob::PointCharge>>(instanceName);
art::Ptr< recob::SpacePoint > spacePointPtr(std::size_t i) const
Returns an art pointer to the specified space point (no check done!).
std::unique_ptr< std::vector< recob::SpacePoint > > fSpacePoints
Space point data.
static void produces(art::ProducesCollector &producesCollector, std::string const &instanceName={})
Declares the data products being produced.
std::unique_ptr< art::PtrMaker< recob::SpacePoint > > fSpacePointPtrMaker
Space point pointer maker.
ChargedSpacePointCollectionCreator(art::Event &event, std::string const &instanceName={})
Constructor binding this object to a specific art event.
bool empty() const
Returns whether there are currently no space points in the collection.
static ChargedSpacePointCollectionCreator forPtrs(art::Event &event, std::string const &instanceName={})
Static function binding a new object to a specific art event.
Creates a collection of space points with associated charge.
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().
bool empty(FixedBins< T, C > const &) noexcept
void add(recob::SpacePoint const &spacePoint, recob::PointCharge const &charge)
Inserts the specified space point and associated data into the collection.
std::unique_ptr< art::PtrMaker< recob::PointCharge > > fChargePtrMaker
Charge pointer maker.
Charge reconstructed in the active volume.