18 #include <unordered_map> 60 template <
typename Source,
typename Dest>
76 using Cache_t = std::unordered_map<art::ProductID, InProductCache_t, Hash_t>;
90 return AssnCache[src.
id()][src.
key()];
94 void clear() { AssnCache.clear(); }
111 template <
typename Source,
typename Dest>
195 template <
typename T>
212 template <
typename Source,
typename Dest>
218 return cache.AssnCache.at(src.id()).at(src.key());
220 catch (std::out_of_range) {
225 template <
typename Source,
typename Dest>
228 return cache.AssnCache.count(
id) > 0;
231 template <
typename Source,
typename Dest>
234 return hasProduct(ptr.
id());
237 template <
typename Source,
typename Dest>
244 auto assns_list =
event.getMany<
Assns_t>();
246 MF_LOG_DEBUG(
"FindAllP") <<
"Read(): read " << assns_list.size() <<
" association sets";
248 unsigned int count = 0;
251 count += Merge(handle);
253 MF_LOG_DEBUG(
"FindAllP") <<
"Read " << count <<
" associations for " << cache.NProductIDs()
259 template <
typename Source,
typename Dest>
263 return Add(event, assnTag);
266 template <
typename Source,
typename Dest>
274 <<
"no association found with input tag '" << assnTag <<
"'";
277 return Merge(handle);
280 template <
typename Source,
typename Dest>
287 unsigned int count = 0;
289 MF_LOG_DEBUG(
"FindAllP") <<
"Merge(): importing " << handle->size() <<
" associations from " 292 for (
auto const& assn : *handle) {
298 <<
"Empty pointer found in association " << handle.provenance();
306 if (src.
id() != LastProductID) {
307 LastProductID = src.
id();
308 AssnsList = &(cache.AssnCache[LastProductID]);
311 if (AssnsList->empty()) {
322 if (key >= AssnsList->size())
ResizeToPower2(*AssnsList, key + 1);
326 if (dest_cell.
isNonnull() && (dest_cell != dest)) {
328 <<
"Object Ptr" << src <<
" is associated with at least two objects: " << dest
329 <<
" and " << dest_cell;
335 MF_LOG_DEBUG(
"FindAllP") <<
"Merged " << count <<
" associations from " 336 << handle.provenance();
360 template <
typename T>
368 while (new_size < min_size)
379 #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.
Read("Flexi","livermore")
bool hasProduct(art::ProductID const &id) const
Returns whether there are associations from objects in product id.
A class holding many associations between objects.
DestPtr_t operator[](SourcePtr_t const &src) const
Returns the specified element of the cache.
#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
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
bool getByLabel(std::string const &label, std::string const &instance, Handle< PROD > &result) const
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
art::Ptr< Dest_t > const & operator[](art::Ptr< Dest_t > const &src) const
Returns the object associated to the specified one.
Event finding and building.