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

Associates each optical detector channel to a gate. More...

#include <SlidingWindowCombinerAlg.h>

Public Types

using TriggerGate_t = GateObject
 Type of gate the index lists. More...
 

Public Member Functions

 TriggerGateIndex (std::size_t expectedChannels=0U)
 
 TriggerGateIndex (std::vector< TriggerGate_t > const &gates)
 Initializes the index from all the gates in the specified collection. More...
 
void add (TriggerGate_t const &gate)
 
unsigned int nChannels () const
 Returns the total number of registered channels. More...
 
TriggerGate_t const * find (raw::Channel_t const channel) const
 Returns the gate corresponding to the specified channel. More...
 
TriggerGate_t const & operator[] (raw::Channel_t const channel) const
 

Private Member Functions

bool expandToHold (std::size_t chIndex)
 

Static Private Member Functions

static std::size_t channelIndex (raw::Channel_t channel)
 Converts a channel number into an index. More...
 

Private Attributes

std::vector< TriggerGate_t
const * > 
fGates
 Index of gates by channel number (the same gate may appear many times). More...
 

Detailed Description

template<typename GateObject>
class icarus::trigger::TriggerGateIndex< GateObject >

Associates each optical detector channel to a gate.

Definition at line 37 of file SlidingWindowCombinerAlg.h.

Member Typedef Documentation

template<typename GateObject >
using icarus::trigger::TriggerGateIndex< GateObject >::TriggerGate_t = GateObject

Type of gate the index lists.

Definition at line 330 of file TriggerDataUtils.h.

Constructor & Destructor Documentation

template<typename GateObject >
icarus::trigger::TriggerGateIndex< GateObject >::TriggerGateIndex ( std::size_t  expectedChannels = 0U)

Constructs an empty index expecting to be filled by expectedChannels registered channels.

Definition at line 663 of file TriggerDataUtils.h.

664 {
665  if (expectedChannels > 0) fGates.reserve(expectedChannels);
666 } // icarus::trigger::TriggerGateIndex::TriggerGateIndex(size_t)
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
template<typename GateObject >
icarus::trigger::TriggerGateIndex< GateObject >::TriggerGateIndex ( std::vector< TriggerGate_t > const &  gates)

Initializes the index from all the gates in the specified collection.

Definition at line 671 of file TriggerDataUtils.h.

672 {
673  for (TriggerGate_t const& gate: gates) add(gate);
674 } // icarus::trigger::TriggerGateIndex::TriggerGateIndex(gates)
GateObject TriggerGate_t
Type of gate the index lists.
void add(TriggerGate_t const &gate)

Member Function Documentation

template<typename GateObject >
void icarus::trigger::TriggerGateIndex< GateObject >::add ( TriggerGate_t const &  gate)

Adds a new gate to the index.

Exceptions
cet::exception("TriggerGateIndex") if it conflicts with a gate already added

Definition at line 680 of file TriggerDataUtils.h.

681 {
682 
683  for (raw::Channel_t const channel: gate.channels()) {
684  auto const chIndex = static_cast<std::size_t>(channel);
685 
686  if (expandToHold(chIndex) || !fGates[chIndex]) {
687  fGates[chIndex] = &gate;
688  }
689  else if (fGates[chIndex] != &gate) {
690  throw cet::exception("TriggerGateIndex") << "TriggerGateIndex::add(): "
691  << "A gate was already present for channel " << channel << ".\n";
692  }
693 
694  } // for
695 
696 } // icarus::trigger::TriggerGateIndex::add()
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
bool expandToHold(std::size_t chIndex)
template<typename GateObject >
std::size_t icarus::trigger::TriggerGateIndex< GateObject >::channelIndex ( raw::Channel_t  channel)
staticprivate

Converts a channel number into an index.

Definition at line 743 of file TriggerDataUtils.h.

744  { return static_cast<std::size_t>(channel); }
template<typename GateObject >
bool icarus::trigger::TriggerGateIndex< GateObject >::expandToHold ( std::size_t  chIndex)
private

Extends internal map with nullptr to hold at least chIndex.

Returns
whether an extension was performed

Definition at line 729 of file TriggerDataUtils.h.

730 {
731 
732  if (chIndex < fGates.size()) return false;
733 
734  fGates.resize(chIndex + 1U, nullptr);
735  return true;
736 
737 } // icarus::trigger::TriggerGateIndex::expandToHold()
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
template<typename GateObject >
auto icarus::trigger::TriggerGateIndex< GateObject >::find ( raw::Channel_t const  channel) const

Returns the gate corresponding to the specified channel.

Definition at line 708 of file TriggerDataUtils.h.

709 {
710  auto const chIndex = channelIndex(channel);
711  return (chIndex < nChannels())? fGates[chIndex]: nullptr;
712 } // icarus::trigger::TriggerGateIndex::find()
static std::size_t channelIndex(raw::Channel_t channel)
Converts a channel number into an index.
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
unsigned int nChannels() const
Returns the total number of registered channels.
template<typename GateObject >
unsigned int icarus::trigger::TriggerGateIndex< GateObject >::nChannels ( ) const

Returns the total number of registered channels.

Definition at line 701 of file TriggerDataUtils.h.

702  { return static_cast<unsigned int>(fGates.size()); }
std::vector< TriggerGate_t const * > fGates
Index of gates by channel number (the same gate may appear many times).
template<typename GateObject >
auto icarus::trigger::TriggerGateIndex< GateObject >::operator[] ( raw::Channel_t const  channel) const

Returns the gate corresponding to the specified channel.

Exceptions
std::out_of_rangeif the channel is not registered

Definition at line 718 of file TriggerDataUtils.h.

719 {
720  auto const gate = find(channel);
721  if (gate) return *gate;
722  throw std::out_of_range(std::to_string(channel));
723 } // icarus::trigger::TriggerGateIndex::operator[]()
TriggerGate_t const * find(raw::Channel_t const channel) const
Returns the gate corresponding to the specified channel.
std::string to_string(WindowPattern const &pattern)

Member Data Documentation

template<typename GateObject >
std::vector<TriggerGate_t const*> icarus::trigger::TriggerGateIndex< GateObject >::fGates
private

Index of gates by channel number (the same gate may appear many times).

Definition at line 357 of file TriggerDataUtils.h.


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