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>
260 std::vector<art::Handle<Assns_t>> assns_list;
261 event.getManyByType(assns_list);
263 LOG_DEBUG(
"FindAllP") <<
"Read(): read " << assns_list.size()
264 <<
" association sets";
266 unsigned int count = 0;
269 count += Merge(handle);
271 LOG_DEBUG(
"FindAllP") <<
"Read " << count <<
" associations for " 272 << cache.NProductIDs() <<
" product IDs";
279 template <
typename Source,
typename Dest>
284 return Add(event, assnTag);
289 template <
typename Source,
typename Dest>
298 <<
"no association found with input tag '" << assnTag <<
"'";
301 return Merge(handle);
305 template <
typename Source,
typename Dest>
313 unsigned int count = 0;
315 LOG_DEBUG(
"FindAllP") <<
"Merge(): importing " << handle->size()
316 <<
" associations from " << handle.
provenance();
318 for (
auto const& assn: *handle) {
323 LOG_ERROR(
"FindAllP") <<
"Empty pointer found in association " 324 << handle.provenance();
332 if (src.
id() != LastProductID) {
333 LastProductID = src.
id();
334 AssnsList = &(cache.AssnCache[LastProductID]);
337 if (AssnsList->empty()) {
348 if (key >= AssnsList->size())
ResizeToPower2(*AssnsList, key + 1);
352 if (dest_cell.
isNonnull() && (dest_cell != dest)) {
354 <<
"Object Ptr" << src
355 <<
" is associated with at least two objects: " 356 << dest <<
" and " << dest_cell;
363 <<
"Merged " << count <<
" associations from " << handle.provenance();
392 template <
typename T>
399 while (new_size < min_size) new_size *= 2;
410 #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.
void clear()
Empties the cache.
result_type operator()(argument_type const &v) const
Cache_t AssnCache
association cache, keyed by product ID and index
#define LOG_ERROR(category)
Provenance const * provenance() const
Cache_t cache
set of associations, keyed by product ID and key
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
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
std::string value(boost::any const &)
LArSoft-specific namespace.
bool getByLabel(std::string const &label, std::string const &productInstanceName, Handle< PROD > &result) const
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.