7 #ifndef ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERDATAUTILS_H
8 #define ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERDATAUTILS_H
22 #include "art/Persistency/Common/PtrMaker.h"
23 #include "canvas/Persistency/Common/Assns.h"
24 #include "canvas/Persistency/Common/Ptr.h"
25 #include "canvas/Utilities/InputTag.h"
26 #include "cetlib_except/exception.h"
35 #include <type_traits>
39 namespace icarus::trigger {
114 template <
typename Gates>
115 std::vector<icarus::trigger::OpticalTriggerGateData_t>
208 template <
typename OpDetInfo = sbn::OpDetWaveformMeta>
210 std::vector<icarus::trigger::OpticalTriggerGateData_t>,
211 art::Assns<icarus::trigger::OpticalTriggerGateData_t, OpDetInfo>
215 art::PtrMaker<icarus::trigger::OpticalTriggerGateData_t>
const& makeGatePtr,
288 template <
typename OpDetInfo>
289 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
291 std::vector<icarus::trigger::OpticalTriggerGateData_t>
const& gates,
292 art::Assns<icarus::trigger::OpticalTriggerGateData_t, OpDetInfo>
const& gateToWaveformInfo
297 template <
typename OpDetInfo = sbn::OpDetWaveformMeta>
318 template <
typename OpDetInfo = sbn::OpDetWaveformMeta,
typename Event>
319 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
325 template <
typename GateObject>
357 std::vector<TriggerGate_t const*>
fGates;
452 template <
typename OpDetInfo >
470 template <
typename ConsumesCollector>
478 template <
typename Event>
479 std::vector<TriggerGates_t>
read(Event
const& event)
const;
480 template <
typename Event>
481 std::vector<TriggerGates_t>
operator() (Event
const& event)
const
482 {
return read(event); }
493 template <
typename Gates>
494 std::vector<icarus::trigger::OpticalTriggerGateData_t>
499 std::vector<TriggerGateData_t> gateData;
502 gateData.push_back(std::move(gate));
510 template <
typename OpDetInfo >
512 std::vector<icarus::trigger::OpticalTriggerGateData_t>,
513 art::Assns<icarus::trigger::OpticalTriggerGateData_t, OpDetInfo>
517 art::PtrMaker<icarus::trigger::OpticalTriggerGateData_t>
const& makeGatePtr,
526 art::Assns<TriggerGateData_t, OpDetInfo> gateToWaveforms;
530 if (!gate.tracking().hasTracked())
continue;
537 art::Ptr<TriggerGateData_t>
const& gatePtr = makeGatePtr(iGate);
538 for (OpDetInfo
const* waveform: gate.tracking().getTracked()) {
540 gateToWaveforms.addSingle(gatePtr, opDetInfoPtrs.at(waveform));
549 std::vector<TriggerGateData_t> gateData
552 return { std::move(gateData), std::move(gateToWaveforms) };
558 template <
typename OpDetInfo>
559 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
561 std::vector<icarus::trigger::OpticalTriggerGateData_t>
const& gates,
562 art::Assns<icarus::trigger::OpticalTriggerGateData_t, OpDetInfo>
const& gateToWaveformInfo
565 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
568 auto iGateToWaveform = gateToWaveformInfo.begin();
569 auto const gwend = gateToWaveformInfo.end();
579 while (iGateToWaveform != gwend) {
580 if (iGateToWaveform->first.key() == iGate)
break;
584 while (iGateToWaveform != gwend) {
585 if (iGateToWaveform->first.key() != iGate)
break;
587 OpDetInfo
const& wfInfo = *(iGateToWaveform->second);
590 trackedGate.
gate().addChannel(wfInfo.ChannelNumber());
591 trackedGate.tracking().add(&wfInfo);
596 allGates.push_back(std::move(trackedGate));
607 template <
typename OpDetInfo >
608 template <
typename ConsumesCollector>
610 (ConsumesCollector& collector)
const
615 collector.template consumes<std::vector<OpticalTriggerGateData_t>>(fDataTag);
616 collector.template consumes<art::Assns<OpticalTriggerGateData_t, OpDetInfo>>
623 template <
typename OpDetInfo >
624 template <
typename Event>
625 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
632 =
event.template getProduct<std::vector<OpticalTriggerGateData_t>>(fDataTag);
633 auto const& gateToWaveforms =
event.template getProduct
634 <art::Assns<OpticalTriggerGateData_t, OpDetInfo>>(fDataTag);
639 catch (cet::exception
const&
e) {
640 throw cet::exception(
"readTriggerGates",
"", e)
641 <<
"readTriggerGates() encountered an error while reading data products from '"
642 << fDataTag.encode() <<
"'\n";
649 template <
typename OpDetInfo ,
typename Event>
650 std::vector<icarus::trigger::TrackedOpticalTriggerGate<OpDetInfo>>
652 (Event
const& event, art::InputTag
const& dataTag)
661 template <
typename GateObject>
663 (std::size_t expectedChannels )
665 if (expectedChannels > 0) fGates.reserve(expectedChannels);
669 template <
typename GateObject>
671 (std::vector<TriggerGate_t>
const& gates)
678 template <
typename GateObject>
684 auto const chIndex =
static_cast<std::size_t
>(channel);
686 if (expandToHold(chIndex) || !fGates[chIndex]) {
687 fGates[chIndex] = &gate;
689 else if (fGates[chIndex] != &gate) {
690 throw cet::exception(
"TriggerGateIndex") <<
"TriggerGateIndex::add(): "
691 <<
"A gate was already present for channel " << channel <<
".\n";
700 template <
typename GateObject>
702 {
return static_cast<unsigned int>(fGates.size()); }
706 template <
typename GateObject>
710 auto const chIndex = channelIndex(channel);
711 return (chIndex < nChannels())? fGates[chIndex]:
nullptr;
716 template <
typename GateObject>
720 auto const gate = find(channel);
721 if (gate)
return *gate;
727 template <
typename GateObject>
729 (std::size_t chIndex)
732 if (chIndex < fGates.size())
return false;
734 fGates.resize(chIndex + 1U,
nullptr);
741 template <
typename GateObject>
744 {
return static_cast<std::size_t
>(channel); }
749 #endif // ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERDATAUTILS_H
static std::size_t channelIndex(raw::Channel_t channel)
Converts a channel number into an index.
TriggerGateIndex(std::size_t expectedChannels=0U)
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
std::vector< TriggerGates_t > operator()(Event const &event) const
Definition of util::enumerate().
A wrapper to trigger gate objects tracking the input of operations.
auto gatesIn(TrackingGateColl &trackingGates)
TriggerGate_t const * find(raw::Channel_t const channel) const
Returns the gate corresponding to the specified channel.
std::vector< icarus::trigger::OpticalTriggerGateData_t > transformIntoOpticalTriggerGate(Gates &&gates)
Returns the trigger gates in serializable format.
void declareConsumes(ConsumesCollector &collector) const
Declares to the collector the data products that are going to be read.
Assembles and returns trigger gates from serialized data.
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
art::InputTag fDataTag
Data tag of the data products being read.
OpDetInfo OpDetWaveformMeta_t
Type of associated information.
A trigger gate data object for optical detector electronics.
icarus::trigger::ReadoutTriggerGate< TriggerGateTick_t, TriggerGateTicks_t, raw::Channel_t > OpticalTriggerGateData_t
Type of trigger gate data serialized into art data products.
art::InputTag const & inputTag() const
Returns the input tag the data is read from.
bool expandToHold(std::size_t chIndex)
GateObject TriggerGate_t
Type of gate the index lists.
TriggerGate_t const & operator[](raw::Channel_t const channel) const
TriggerGate_t const & gate() const &
Returns the enclosed gate.
std::vector< TriggerGates_t > read(Event const &event) const
Reads the configured data product from the specified event.
std::string to_string(WindowPattern const &pattern)
Associates each optical detector channel to a gate.
A simple alias for a most commonly used TrackedTriggerGate type.
std::vector< icarus::trigger::TrackedOpticalTriggerGate< OpDetInfo > > FillTriggerGates(std::vector< icarus::trigger::OpticalTriggerGateData_t > const &gates, art::Assns< icarus::trigger::OpticalTriggerGateData_t, OpDetInfo > const &gateToWaveformInfo)
Creates a gate object out of trigger gate data products.
unsigned int nChannels() const
Returns the total number of registered channels.
TriggerGateReader(art::InputTag dataTag)
Constructor: configure to read the data with the specified tag.
void add(TriggerGate_t const &gate)
std::vector< icarus::trigger::TrackedOpticalTriggerGate< OpDetInfo > > ReadTriggerGates(Event const &event, art::InputTag const &dataTag)
Assembles and returns trigger gates from serialized data.
util::DataProductPointerMap_t< sbn::OpDetWaveformMeta > OpDetWaveformMetaDataProductMap_t
Map util::DataProductPointerMap_t for sbn::OpDetWaveformMeta objects.
details::DataProductPointerMap_t< T > DataProductPointerMap_t
Type of map for data product pointers to art pointers.
Utilities to map data pointer elements to their art::Ptr.
util::DataProductPointerMap_t< raw::OpDetWaveform > OpDetWaveformDataProductMap_t
Map util::DataProductPointerMap_t for raw::OpDetWaveform objects.