18 #include <unordered_map> 64 template <
typename Source,
typename Dest>
81 = std::unordered_map<art::ProductID, InProductCache_t, Hash_t>;
95 {
return AssnCache[src.
id()][src.
key()]; }
98 void clear() { AssnCache.clear(); }
116 template <
typename Source,
typename Dest>
130 { Read(event, assnTag); }
208 template <
typename T>
228 template <
typename Source,
typename Dest>
234 return cache.AssnCache.at(src.id()).at(src.key());
236 catch (std::out_of_range) {
242 template <
typename Source,
typename Dest>
245 {
return cache.AssnCache.count(
id) > 0; }
248 template <
typename Source,
typename Dest>
251 {
return hasProduct(ptr.
id()); }
254 template <
typename Source,
typename Dest>
262 auto assns_list =
event.getMany<
Assns_t>();
264 MF_LOG_DEBUG(
"FindAllP") <<
"Read(): read " << assns_list.size()
265 <<
" association sets";
267 unsigned int count = 0;
270 count += Merge(handle);
272 MF_LOG_DEBUG(
"FindAllP") <<
"Read " << count <<
" associations for " 273 << cache.NProductIDs() <<
" product IDs";
280 template <
typename Source,
typename Dest>
285 return Add(event, assnTag);
290 template <
typename Source,
typename Dest>
299 <<
"no association found with input tag '" << assnTag <<
"'";
302 return Merge(handle);
306 template <
typename Source,
typename Dest>
314 unsigned int count = 0;
316 MF_LOG_DEBUG(
"FindAllP") <<
"Merge(): importing " << handle->size()
317 <<
" associations from " << handle.
provenance();
319 for (
auto const& assn: *handle) {
324 MF_LOG_ERROR(
"FindAllP") <<
"Empty pointer found in association " 325 << handle.provenance();
333 if (src.
id() != LastProductID) {
334 LastProductID = src.
id();
335 AssnsList = &(cache.AssnCache[LastProductID]);
338 if (AssnsList->empty()) {
349 if (key >= AssnsList->size())
ResizeToPower2(*AssnsList, key + 1);
355 <<
"Object Ptr" << src
356 <<
" is associated with at least two objects: " 357 << dest <<
" and " << dest_cell;
364 <<
"Merged " << count <<
" associations from " << handle.provenance();
393 template <
typename T>
400 while (new_size < min_size) new_size *= 2;
411 #endif // FINDALLP_H 1
Namespace for general, non-LArSoft-specific utilities.
FindAllP(art::Event &event, art::InputTag assnTag)
Constructor: reads one association from the specified event.
unsigned int Merge(art::Handle< Assns_t > &handle)
Adds all associations in the specified handle; returns their number.
bool hasProduct(art::ProductID const &id) const
Returns whether there are associations from objects in product id.
A class holding many associations between objects.
#define MF_LOG_ERROR(category)
void clear()
Empties the cache.
result_type operator()(argument_type const &v) const
Cache_t AssnCache
association cache, keyed by product ID and index
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
Provenance const * provenance() const
Cache_t cache
set of associations, keyed by product ID and key
key_type key() const noexcept
bool isNull() const noexcept
FindAllP(art::Event &event)
Constructor: reads all associations from the specified event.
std::vector< DestPtr_t > InProductCache_t
type for a cache of dest products for a given source product ID
ProductID id() const noexcept
unsigned int Add(art::Event &event, art::InputTag const &assnTag)
Reads the specified association from the event.
unsigned int Read(art::Event &event)
Reads all the associations from the event.
Query object reading all the associations between two classes.
void ResizeToPower2(std::vector< T > &v, size_t min_size)
Resizes a vector to a size power of 2, with a minimum size.
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
bool isNonnull() const noexcept
LArSoft-specific namespace.
Hash functions for art and larsoft objects.
std::unordered_map< art::ProductID, InProductCache_t, Hash_t > Cache_t
type for the complete cache, keyed by source product ID
size_t NProductIDs() const
Event finding and building.