1 #ifndef canvas_Persistency_Common_detail_IPRHelper_h 2 #define canvas_Persistency_Common_detail_IPRHelper_h 14 #include <type_traits> 15 #include <unordered_map> 43 template <
typename ProdA,
50 template <
typename DATA>
53 void init(
size_t size, std::vector<DATA const*>& data)
const;
54 template <
typename ASSNS>
55 void fill(ptrdiff_t assns_index,
58 std::vector<DATA const*>& data)
const;
60 void init(
size_t size,
std::vector<std::vector<DATA const*>>& data)
const;
61 template <
typename ASSNS>
62 void fill(ptrdiff_t assns_index,
68 template <
typename ASSNS>
75 template <
typename ProdB>
79 template <
typename Bcoll>
80 void init(
size_t size, Bcoll& bColl);
83 template <
typename Bcoll>
89 template <
typename Bcoll>
91 std::is_convertible<typename Bcoll::value_type, Ptr<ProdB>>
::value>
94 template <
typename Bcoll>
95 void init(
size_t size, std::vector<Bcoll>& bColls)
const;
98 template <
typename Bcoll>
103 std::vector<Bcoll>& bColls)
const;
106 template <
typename Bcoll>
108 std::is_convertible<typename Bcoll::value_type, Ptr<ProdB>>
::value>
111 std::vector<Bcoll>& bColls)
const;
120 template <
typename ProdA,
143 template <
typename Acoll,
typename Bcoll>
144 shared_exception_t operator()(Acoll
const& aColl, Bcoll& bColl)
const;
147 template <
typename Acoll,
typename Bcoll>
148 shared_exception_t operator()(Acoll
const& aColl,
158 template <
typename ProdA,
163 template <
typename Acoll,
typename Bcoll>
170 return (*
this)(aColl, bColl, dummy);
199 template <
typename ProdA,
204 template <
typename Acoll,
typename Bcoll>
212 typename EVENT::template HandleT<Assns<ProdA, ProdB, Data>> assnsHandle;
213 event_.getByLabel(assnsTag_, assnsHandle);
214 if (!assnsHandle.isValid()) {
215 return assnsHandle.whyFailed();
217 bh.
init(aColl.size(), bColl);
218 dh.
init(aColl.size(), dColl);
220 std::unordered_multimap<typename Ptr<ProdA>::const_pointer,
221 std::pair<Ptr<ProdB>, ptrdiff_t>>
223 ptrdiff_t counter{0};
224 for (
auto const& apair : *assnsHandle) {
225 if (apair.first.isAvailable()) {
228 typename decltype(lookupCache)::mapped_type(apair.second, counter));
237 auto foundItems = lookupCache.equal_range(
239 if (foundItems.first != lookupCache.cend()) {
243 [&bh, &dh, &bColl, bIndex, &assnsHandle, &dColl](
244 typename decltype(lookupCache)::const_reference itemPair) {
245 bh.
fill(bIndex, itemPair.second.first, bColl);
246 dh.
fill(itemPair.second.second, *assnsHandle, bIndex, dColl);
253 template <
typename DATA>
256 std::vector<DATA const*>& data)
const 258 data.assign(size, 0);
261 template <
typename DATA>
262 template <
typename ASSNS>
267 std::vector<DATA const*>& data)
const 269 data[data_index] = &assns.data(assns_index);
272 template <
typename DATA>
281 template <
typename DATA>
282 template <
typename ASSNS>
285 ptrdiff_t assns_index,
290 data[data_index].push_back(&assns.data(assns_index));
293 template <
typename DATA>
298 template <
typename DATA>
299 template <
typename ASSNS>
307 template <
typename ProdB>
309 : assnsTag_(assnsTag), seen_()
312 template <
typename ProdB>
313 template <
typename Bcoll>
318 bColl.assign(size,
typename Bcoll::value_type());
319 seen_.assign(size, uint8_t(0u));
323 template <
typename ProdB>
324 template <
typename Bcoll>
325 inline std::enable_if_t<
332 if (
seen_[index] == uint8_t(1u)) {
334 <<
"Attempted to create a FindOne object for a one-many or many-many" 335 <<
" association specified in collection " <<
assnsTag_ <<
".\n";
337 bColl[index] = item.
get();
338 seen_[index] = uint8_t(1u);
341 <<
"Attempted to create a FindOne object where an associated item is " 342 <<
"\nunavailable.\n";
347 template <
typename ProdB>
348 template <
typename Bcoll>
349 inline std::enable_if_t<
350 std::is_convertible<typename Bcoll::value_type, art::Ptr<ProdB>>
::value>
356 if (
seen_[index] == uint8_t(1u)) {
358 <<
"Attempted to create a FindOne object for a one-many or many-many" 359 <<
" association specified in collection " <<
assnsTag_ <<
".\n";
362 seen_[index] = uint8_t(1u);
365 template <
typename ProdB>
366 template <
typename Bcoll>
369 std::vector<Bcoll>& bColls)
const 375 template <
typename ProdB>
376 template <
typename Bcoll>
377 inline std::enable_if_t<
381 std::vector<Bcoll>& bColls)
const 383 bColls[index].push_back(item ? item.
get() :
nullptr);
387 template <
typename ProdB>
388 template <
typename Bcoll>
389 inline std::enable_if_t<
390 std::is_convertible<typename Bcoll::value_type, art::Ptr<ProdB>>
::value>
393 std::vector<Bcoll>& bColls)
const 395 bColls[index].push_back(item);
InputTag input_tag(InputTag const &tag)
BcollHelper(InputTag const &assnsTag)
void init(size_t size, std::vector< DATA const * > &data) const
std::conditional_t< std::is_void< Data >::value, IPRHelperDef, DATACOLL > dataColl_t
void init(size_t size, Bcoll &bColl)
void fill(ptrdiff_t assns_index, ASSNS const &assns, size_t data_index, std::vector< DATA const * > &data) const
std::enable_if_t< std::is_same< typename Bcoll::value_type, ProdB const * >::value > fill(size_t index, Ptr< ProdB > const &item, Bcoll &bColl)
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
shared_exception_t operator()(Acoll const &aColl, Bcoll &bColl) const
std::vector< uint8_t > seen_
void fill(const art::PtrVector< recob::Hit > &hits, int only_plane)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
std::string value(boost::any const &)
std::shared_ptr< art::Exception const > shared_exception_t
WANTED_POINTER ensurePointer(InputIterator it)
IPRHelper(EVENT const &e, InputTag const &tag)