1 #ifndef canvas_Persistency_Common_detail_IPRHelper_h 2 #define canvas_Persistency_Common_detail_IPRHelper_h 14 #include <type_traits> 15 #include <unordered_map> 19 template <
typename ProdA,
typename ProdB,
typename Data>
23 :
tag{token.inputTag_}
28 template <
typename ProdA,
typename ProdB,
typename Data,
typename Tag>
33 std::is_convertible_v<Tag, InputTag> ||
36 "\n\nart error: The input tag or product token provided to the " 37 "smart-query object\n" 38 " constructor has a type that conflicts with that of the " 39 "smart-query object.\n");
45 template <
typename ProdA,
52 template <
typename DATA>
55 void init(
size_t size, std::vector<DATA const*>& data)
const;
56 template <
typename ASSNS>
57 void fill(ptrdiff_t assns_index,
60 std::vector<DATA const*>& data)
const;
62 void init(
size_t size,
std::vector<std::vector<DATA const*>>& data)
const;
63 template <
typename ASSNS>
64 void fill(ptrdiff_t assns_index,
70 template <
typename ASSNS>
77 template <
typename ProdB>
81 template <
typename Bcoll>
82 void init(
size_t size, Bcoll& bColl);
85 template <
typename Bcoll>
86 std::enable_if_t<std::is_same_v<typename Bcoll::value_type, ProdB const*>>
90 template <
typename Bcoll>
92 std::is_convertible_v<typename Bcoll::value_type, Ptr<ProdB>>>
95 template <
typename Bcoll>
96 void init(
size_t size, std::vector<Bcoll>& bColls)
const;
99 template <
typename Bcoll>
100 std::enable_if_t<std::is_same_v<typename Bcoll::value_type, ProdB const*>>
103 std::vector<Bcoll>& bColls)
const;
106 template <
typename Bcoll>
108 std::is_convertible_v<typename Bcoll::value_type, Ptr<ProdB>>>
111 std::vector<Bcoll>& bColls)
const;
119 template <
typename ProdA,
142 template <
typename Acoll,
typename Bcoll>
146 template <
typename Acoll,
typename Bcoll>
157 template <
typename ProdA,
162 template <
typename Acoll,
typename Bcoll>
169 return (*
this)(aColl, bColl, dummy);
198 template <
typename ProdA,
203 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>>
224 for (
auto const& apair : *assnsHandle) {
225 if (apair.first.isAvailable()) {
228 typename decltype(lookupCache)::mapped_type(apair.second,
counter));
236 for (
auto i =
cbegin(aColl),
e =
cend(aColl); i !=
e; ++i, ++bIndex) {
237 auto foundItems = lookupCache.equal_range(
239 if (foundItems.first != lookupCache.cend()) {
243 [&bh, &dh, &bColl, bIndex, &assnsHandle, &dColl](
auto const& itemPair) {
244 bh.fill(bIndex, itemPair.second.first, bColl);
245 dh.fill(itemPair.second.second, *assnsHandle, bIndex, dColl);
252 template <
typename DATA>
255 std::vector<DATA const*>& data)
const 257 data.assign(size, 0);
260 template <
typename DATA>
261 template <
typename ASSNS>
265 size_t const data_index,
266 std::vector<DATA const*>& data)
const 268 data[data_index] = &assns.data(assns_index);
271 template <
typename DATA>
280 template <
typename DATA>
281 template <
typename ASSNS>
284 ptrdiff_t
const assns_index,
286 size_t const data_index,
289 data[data_index].push_back(&assns.data(assns_index));
292 template <
typename DATA>
297 template <
typename DATA>
298 template <
typename ASSNS>
306 template <
typename ProdB>
308 : assnsTag_{assnsTag},
seen_()
311 template <
typename ProdB>
312 template <
typename Bcoll>
317 bColl.assign(size,
typename Bcoll::value_type{});
318 seen_.assign(size, uint8_t{});
322 template <
typename ProdB>
323 template <
typename Bcoll>
324 inline std::enable_if_t<
325 std::is_same_v<typename Bcoll::value_type, ProdB const*>>
331 if (
seen_[index] == uint8_t(1u)) {
333 <<
"Attempted to create a FindOne object for a one-many or many-many" 334 <<
" association specified in collection " <<
assnsTag_ <<
".\n";
336 bColl[index] = item.
get();
337 seen_[index] = uint8_t(1u);
340 <<
"Attempted to create a FindOne object where an associated item is " 341 <<
"\nunavailable.\n";
346 template <
typename ProdB>
347 template <
typename Bcoll>
348 inline std::enable_if_t<
349 std::is_convertible_v<typename Bcoll::value_type, art::Ptr<ProdB>>>
355 if (
seen_[index] == uint8_t(1u)) {
357 <<
"Attempted to create a FindOne object for a one-many or many-many" 358 <<
" association specified in collection " <<
assnsTag_ <<
".\n";
361 seen_[index] = uint8_t(1u);
364 template <
typename ProdB>
365 template <
typename Bcoll>
368 std::vector<Bcoll>& bColls)
const 374 template <
typename ProdB>
375 template <
typename Bcoll>
376 inline std::enable_if_t<
377 std::is_same_v<typename Bcoll::value_type, ProdB const*>>
380 std::vector<Bcoll>& bColls)
const 382 bColls[index].push_back(item ? item.
get() :
nullptr);
386 template <
typename ProdB>
387 template <
typename Bcoll>
388 inline std::enable_if_t<
389 std::is_convertible_v<typename Bcoll::value_type, art::Ptr<ProdB>>>
392 std::vector<Bcoll>& bColls)
const 394 bColls[index].push_back(item);
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
BcollHelper(InputTag const &assnsTag)
void init(size_t size, std::vector< DATA const * > &data) const
void init(size_t size, Bcoll &bColl)
std::conditional_t< std::is_void_v< Data >, IPRHelperDef, DATACOLL > dataColl_t
void fill(ptrdiff_t assns_index, ASSNS const &assns, size_t data_index, std::vector< DATA const * > &data) const
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
InputTag input_tag(Tag const &tag)
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
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::shared_ptr< art::Exception const > shared_exception_t
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
std::enable_if_t< std::is_same_v< typename Bcoll::value_type, ProdB const * > > fill(size_t index, Ptr< ProdB > const &item, Bcoll &bColl)
WANTED_POINTER ensurePointer(InputIterator it)
IPRHelper(EVENT const &e, InputTag const &tag)