9 #ifndef ICARUSCODE_PMT_TRIGGER_UTILITIES_OPDETWAVEFORMMETAMATCHER_H
10 #define ICARUSCODE_PMT_TRIGGER_UTILITIES_OPDETWAVEFORMMETAMATCHER_H
22 #include "canvas/Persistency/Common/Assns.h"
23 #include "canvas/Persistency/Common/Ptr.h"
24 #include "canvas/Persistency/Provenance/ProductID.h"
28 #include <unordered_map>
33 namespace icarus::trigger {
62 template <
typename Event>
69 = art::Assns<sbn::OpDetWaveformMeta, raw::OpDetWaveform>;
74 using Assn_t =
typename WaveformMetaAssns_t::assn_t;
77 template <
typename A,
typename B>
81 {
return cmp(a.first, b.first); }
84 {
return cmp(a.first, b); }
87 {
return cmp(a, b.first); }
90 {
return a.key() < b.key(); }
98 std::unordered_map<art::ProductID, WaveformMetaAssns_t const*>
fAssns;
107 art::Ptr<sbn::OpDetWaveformMeta>
const& meta,
119 (art::Ptr<sbn::OpDetWaveformMeta>
const& meta);
121 (art::Ptr<sbn::OpDetWaveformMeta>
const& meta)
133 template <
typename Event>
141 template <
typename Event>
142 art::Ptr<raw::OpDetWaveform>
144 (art::Ptr<sbn::OpDetWaveformMeta>
const& meta)
149 ? findAssociatedWaveform(meta, *assns): art::Ptr<raw::OpDetWaveform>{};
155 template <
typename Event>
161 if (
auto const itAssns = fAssns.find(pid); itAssns != fAssns.end())
162 return itAssns->second;
165 auto& assnCache = (fAssns[pid] =
nullptr);
170 auto const assnsHandle = fEvent.template getHandle<WaveformMetaAssns_t>(tag);
171 if (!assnsHandle.isValid())
return nullptr;
172 return assnCache = assnsHandle.product();
174 catch (art::Exception
const&
e) {
175 if (e.categoryCode() == art::errors::ProductNotFound)
return nullptr;
184 template <
typename Event>
185 art::Ptr<raw::OpDetWaveform>
187 art::Ptr<sbn::OpDetWaveformMeta>
const& meta,
191 auto const key = meta.key();
194 if ((assns.size() > key) && (assns.at(key).first == meta))
195 return assns[key].second;
198 if (
auto itAssn = std::lower_bound(assns.begin(), assns.end(), meta,
CmpFirst{});
199 itAssn != assns.end()
201 if (itAssn->first == meta)
return itAssn->second;
205 for (
auto const& assn: assns)
if (assn.first == meta)
return assn.second;
215 #endif // ICARUSCODE_PMT_TRIGGER_UTILITIES_OPDETWAVEFORMMETAMATCHER_H
A trigger gate data object for optical detector electronics.
art::InputTag inputTagOf(Event const &event, art::ProductID const &productID)
Reads and returns the input tag of the producer of productID.
Helper functions based on art/canvas.