All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
icarus::trigger::OpDetWaveformMetaMatcher< Event > Class Template Reference

Object to facilitate the discovery of the raw::OpDetWaveform a sbn::OpDetWaveformMeta objects comes from. More...

#include <OpDetWaveformMetaMatcher.h>

Classes

struct  CmpFirst
 Compares a sbn::OpDetWaveformMeta<tt>and an element ofWaveformMetaAssns_t`. More...
 

Public Member Functions

 OpDetWaveformMetaMatcher (Event const &event)
 Constructor: associates to the specified art event. More...
 
art::Ptr< raw::OpDetWaveformfetchAssociatedWaveform (art::Ptr< sbn::OpDetWaveformMeta > const &meta)
 Returns the waveform associated to meta, or a null pointer if not found. More...
 
art::Ptr< raw::OpDetWaveformoperator ()(art
 

Private Types

using Event_t = Event
 Type of the framework event to read data from. More...
 
using WaveformMetaAssns_t = art::Assns< sbn::OpDetWaveformMeta, raw::OpDetWaveform >
 Type of associations used in this algorithm,. More...
 

Private Member Functions

WaveformMetaAssns_t const * loadAssociations (art::ProductID const &pid)
 
art::Ptr< raw::OpDetWaveformfindAssociatedWaveform (art::Ptr< sbn::OpDetWaveformMeta > const &meta, WaveformMetaAssns_t const &assns) const
 Returns the waveform associated to meta if in assns or a null pointer. More...
 

Private Attributes

Event_t const & fEvent
 Event to read associations from. More...
 
std::unordered_map
< art::ProductID,
WaveformMetaAssns_t const * > 
fAssns
 All associations discovered so far. More...
 

Detailed Description

template<typename Event>
class icarus::trigger::OpDetWaveformMetaMatcher< Event >

Object to facilitate the discovery of the raw::OpDetWaveform a sbn::OpDetWaveformMeta objects comes from.

Template Parameters
Eventtype of the framework event to read data products from

This algorithm will look in the associated art event for the raw::OpDetWaveform associated to any specified sbn::OpDetWaveformMeta.

The sbn::OpDetWaveformMeta object must be specified by art pointer. The algorithm assumes that the module that created the sbn::OpDetWaveformMeta object also created an association between it and the original raw::OpDetWaveform, and will read that association.

Example:

icarus::trigger::OpDetWaveformMetaMatcher waveformMetaMatcher{ event };
art::Assns<OpticalTriggerGateData_t, raw::OpDetWaveform> waveAssns;
for (auto const [ gatePtr, metaPtr ]: metaAssns)
waveAssns.addSingle(gatePtr, waveformMetaMatcher(metaPtr));

will fill waveAssns with one gate/waveform association for each gate/metadata association in metaAssns. Note that, in this simple example, if no waveform pointer is matched to a metadata item, a null pointer to waveform is stored in the association.

Definition at line 34 of file OpDetWaveformMetaMatcher.h.

Member Typedef Documentation

template<typename Event >
using icarus::trigger::OpDetWaveformMetaMatcher< Event >::Event_t = Event
private

Type of the framework event to read data from.

Definition at line 65 of file OpDetWaveformMetaMatcher.h.

template<typename Event >
using icarus::trigger::OpDetWaveformMetaMatcher< Event >::WaveformMetaAssns_t = art::Assns<sbn::OpDetWaveformMeta, raw::OpDetWaveform>
private

Type of associations used in this algorithm,.

Definition at line 69 of file OpDetWaveformMetaMatcher.h.

Constructor & Destructor Documentation

template<typename Event >
icarus::trigger::OpDetWaveformMetaMatcher< Event >::OpDetWaveformMetaMatcher ( Event const &  event)

Constructor: associates to the specified art event.

Definition at line 135 of file OpDetWaveformMetaMatcher.h.

136  : fEvent(event)
137  {}
Event_t const & fEvent
Event to read associations from.

Member Function Documentation

template<typename Event >
art::Ptr< raw::OpDetWaveform > icarus::trigger::OpDetWaveformMetaMatcher< Event >::fetchAssociatedWaveform ( art::Ptr< sbn::OpDetWaveformMeta > const &  meta)

Returns the waveform associated to meta, or a null pointer if not found.

Definition at line 144 of file OpDetWaveformMetaMatcher.h.

145 {
146 
147  WaveformMetaAssns_t const* assns = loadAssociations(meta.id());
148  return assns
149  ? findAssociatedWaveform(meta, *assns): art::Ptr<raw::OpDetWaveform>{};
150 
151 } // icarus::trigger::OpDetWaveformMetaMatcher<>::fetchAssociatedWaveform()
art::Ptr< raw::OpDetWaveform > findAssociatedWaveform(art::Ptr< sbn::OpDetWaveformMeta > const &meta, WaveformMetaAssns_t const &assns) const
Returns the waveform associated to meta if in assns or a null pointer.
art::Assns< sbn::OpDetWaveformMeta, raw::OpDetWaveform > WaveformMetaAssns_t
Type of associations used in this algorithm,.
WaveformMetaAssns_t const * loadAssociations(art::ProductID const &pid)
template<typename Event >
art::Ptr< raw::OpDetWaveform > icarus::trigger::OpDetWaveformMetaMatcher< Event >::findAssociatedWaveform ( art::Ptr< sbn::OpDetWaveformMeta > const &  meta,
WaveformMetaAssns_t const &  assns 
) const
private

Returns the waveform associated to meta if in assns or a null pointer.

Definition at line 186 of file OpDetWaveformMetaMatcher.h.

189  {
190 
191  auto const key = meta.key();
192 
193  // try our luck: 1-1 association?
194  if ((assns.size() > key) && (assns.at(key).first == meta))
195  return assns[key].second;
196 
197  // nope, go binary search
198  if (auto itAssn = std::lower_bound(assns.begin(), assns.end(), meta, CmpFirst{});
199  itAssn != assns.end()
200  ) {
201  if (itAssn->first == meta) return itAssn->second;
202  }
203 
204  // still nope, go linear search
205  for (auto const& assn: assns) if (assn.first == meta) return assn.second;
206 
207  // still nope, not found!
208  return {};
209 
210 } // icarus::trigger::OpDetWaveformMetaMatcher::fetchAssociatedWaveform()
template<typename Event >
auto icarus::trigger::OpDetWaveformMetaMatcher< Event >::loadAssociations ( art::ProductID const &  pid)
private

Loads the association including pid.

Returns
pointer to the associations containing pid, nullptr if n/a.

Definition at line 157 of file OpDetWaveformMetaMatcher.h.

158 {
159 
160  // if already there, the better
161  if (auto const itAssns = fAssns.find(pid); itAssns != fAssns.end())
162  return itAssns->second;
163 
164  // let's start optimistic: we won't find it
165  auto& assnCache = (fAssns[pid] = nullptr);
166 
167  try {
168  art::InputTag const tag = util::inputTagOf(fEvent, pid);
169 
170  auto const assnsHandle = fEvent.template getHandle<WaveformMetaAssns_t>(tag);
171  if (!assnsHandle.isValid()) return nullptr;
172  return assnCache = assnsHandle.product();
173  }
174  catch (art::Exception const& e) {
175  if (e.categoryCode() == art::errors::ProductNotFound) return nullptr;
176  throw;
177  }
178 
179 
180 } // icarus::trigger::OpDetWaveformMetaMatcher<>::loadAssociations()
std::unordered_map< art::ProductID, WaveformMetaAssns_t const * > fAssns
All associations discovered so far.
Event_t const & fEvent
Event to read associations from.
art::InputTag inputTagOf(Event const &event, art::ProductID const &productID)
Reads and returns the input tag of the producer of productID.
Definition: CanvasUtils.h:108
do i e
template<typename Event >
art::Ptr<raw::OpDetWaveform> icarus::trigger::OpDetWaveformMetaMatcher< Event >::operator ( )
inline

Definition at line 120 of file OpDetWaveformMetaMatcher.h.

122  { return fetchAssociatedWaveform(meta); }
art::Ptr< raw::OpDetWaveform > fetchAssociatedWaveform(art::Ptr< sbn::OpDetWaveformMeta > const &meta)
Returns the waveform associated to meta, or a null pointer if not found.

Member Data Documentation

template<typename Event >
std::unordered_map<art::ProductID, WaveformMetaAssns_t const*> icarus::trigger::OpDetWaveformMetaMatcher< Event >::fAssns
private

All associations discovered so far.

Definition at line 98 of file OpDetWaveformMetaMatcher.h.

template<typename Event >
Event_t const& icarus::trigger::OpDetWaveformMetaMatcher< Event >::fEvent
private

Event to read associations from.

Definition at line 95 of file OpDetWaveformMetaMatcher.h.


The documentation for this class was generated from the following file: