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

#include <SlidingWindowCombinerAlg.h>

Public Types

using WindowChannels_t = icarus::trigger::TriggerWindowChannels_t
 Type of optical detector channel list in a window. More...
 
using Windows_t = icarus::trigger::TriggerWindowDefs_t
 Type of content of all windows. More...
 
using TrackedTriggerGate_t = icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta >
 Trigger gate data type (tracks sources via sbn::OpDetWaveformMeta). More...
 

Public Member Functions

 SlidingWindowCombinerAlg (Windows_t const &windows, std::vector< raw::Channel_t > missingChannels={}, bool requireFullCoverage=true, std::string logCategory="SlidingWindowCombinerAlg")
 Constructor: learns about the window pattern (keeps a reference). More...
 
std::vector< TrackedTriggerGate_tcombine (std::vector< TrackedTriggerGate_t > const &gates) const
 Combines the gates according to the configured grouping. More...
 
bool isMissingChannel (raw::Channel_t channel) const
 Returns if channel is configured to be missing. More...
 

Private Types

using TriggerGateIndex_t = icarus::trigger::TriggerGateIndex< TrackedTriggerGate_t >
 

Private Member Functions

void checkInput (TriggerGateIndex_t const &gates) const
 Throws an exception if the gates are not suitable for input. More...
 
TrackedTriggerGate_t combineChannels (TriggerGateIndex_t const &gates, WindowChannels_t const &channels) const
 Returns the combination of the channels selected from the gates. More...
 
WindowChannels_t::const_iterator firstChannelPresent (WindowChannels_t const &channels) const
 Returns an iterator to the first of the channels which is not missing. More...
 

Static Private Member Functions

static bool mergeGateInto (TrackedTriggerGate_t &dest, TrackedTriggerGate_t const &input)
 
static Windows_t sortedWindowChannels (Windows_t const &windows)
 Returns windows with numerically sorted channel numbers. More...
 
static std::vector
< raw::Channel_t
sortChannels (std::vector< raw::Channel_t > channels)
 Returns a sorted copy of channels. More...
 
template<typename Cont , typename T >
static bool inList (Cont const &c, T const &value)
 Returns whether the container c has value. More...
 

Private Attributes

Windows_t const fWindowChannels
 Content of channels of each window. More...
 
std::vector< raw::Channel_tfMissingChannels
 Channels known (and required) to be missing (sorted). More...
 
bool const fRequireFullCoverage
 Whether to require all channels to be used. More...
 
std::string fLogCategory
 Category for messages to MessageFacility. More...
 

Detailed Description

Definition at line 43 of file SlidingWindowCombinerAlg.h.

Member Typedef Documentation

Trigger gate data type (tracks sources via sbn::OpDetWaveformMeta).

Definition at line 54 of file SlidingWindowCombinerAlg.h.

Definition at line 75 of file SlidingWindowCombinerAlg.h.

Type of optical detector channel list in a window.

Definition at line 47 of file SlidingWindowCombinerAlg.h.

Type of content of all windows.

Definition at line 50 of file SlidingWindowCombinerAlg.h.

Constructor & Destructor Documentation

icarus::trigger::SlidingWindowCombinerAlg::SlidingWindowCombinerAlg ( Windows_t const &  windows,
std::vector< raw::Channel_t missingChannels = {},
bool  requireFullCoverage = true,
std::string  logCategory = "SlidingWindowCombinerAlg" 
)

Constructor: learns about the window pattern (keeps a reference).

Definition at line 19 of file SlidingWindowCombinerAlg.cxx.

26  , fMissingChannels(sortChannels(std::move(missingChannels)))
27  , fRequireFullCoverage(requireFullCoverage)
28  , fLogCategory(std::move(logCategory))
29  {}
std::string fLogCategory
Category for messages to MessageFacility.
static Windows_t sortedWindowChannels(Windows_t const &windows)
Returns windows with numerically sorted channel numbers.
static std::vector< raw::Channel_t > sortChannels(std::vector< raw::Channel_t > channels)
Returns a sorted copy of channels.
std::vector< raw::Channel_t > fMissingChannels
Channels known (and required) to be missing (sorted).
bool const fRequireFullCoverage
Whether to require all channels to be used.
Windows_t const fWindowChannels
Content of channels of each window.

Member Function Documentation

void icarus::trigger::SlidingWindowCombinerAlg::checkInput ( TriggerGateIndex_t const &  gates) const
private

Throws an exception if the gates are not suitable for input.

Definition at line 56 of file SlidingWindowCombinerAlg.cxx.

57 {
58  /*
59  * Checks:
60  *
61  * * no gate is only partially contained in a window
62  * * no channel in the gates is skipped (optional)
63  *
64  */
65 
66  auto const isChannelInWindow
67  = [](raw::Channel_t channel, std::vector<raw::Channel_t> const& window)
68  { return std::binary_search(window.begin(), window.end(), channel); };
69 
70  std::set<TrackedTriggerGate_t const*> usedGates;
71  for (std::vector<raw::Channel_t> const& window: fWindowChannels) {
72 
73  for (raw::Channel_t const channel: window) {
74 
75  if (isMissingChannel(channel)) continue;
76 
77  //
78  // check that we have all the channels we need
79  //
80  TrackedTriggerGate_t const* gate = gateIndex.find(channel);
81  if (!gate) {
82  cet::exception e("SlidingWindowCombinerAlg");
83  e << "SlidingWindowCombinerAlg::checkInput(): No gate has channel "
84  << channel << ", required in the window including channels: ";
85  for (raw::Channel_t const channel: window) e << " " << channel;
86  e << ".\n";
87  throw e;
88  }
89 
90  //
91  // check that all channels of this gate are in this window
92  //
93  for (raw::Channel_t const gateChannel: gate->channels()) {
94  if (isChannelInWindow(gateChannel, window)) continue;
95 
96  cet::exception e("SlidingWindowCombinerAlg");
97  e << "SlidingWindowCombinerAlg::checkInput(): gate with channels {";
98  for (raw::Channel_t const channel: gate->channels())
99  e << " " << channel;
100  e << " } is not fully included in window including channels: ";
101  for (raw::Channel_t const channel: window) e << " " << channel;
102  e << " (" << gateChannel << " is missing).\n";
103  throw e;
104  } // for gate channels
105 
106  usedGates.insert(gate);
107  } // for channel in window
108 
109  } // for windows
110 
111  //
112  // check for channels that should be missing but are here
113  //
114  std::vector<raw::Channel_t> spuriousChannels;
115  for (raw::Channel_t const channel: fMissingChannels) {
116  if (gateIndex.find(channel)) spuriousChannels.push_back(channel);
117  } // for
118  if (!spuriousChannels.empty()) {
119  cet::exception e("SlidingWindowCombinerAlg");
120  e << "SlidingWindowCombinerAlg::checkInput(): "
121  << spuriousChannels.size() << " of the " << fMissingChannels.size()
122  << " supposedly missing channels are actually included:";
123  for (raw::Channel_t const channel: spuriousChannels) e << " " << channel;
124  e << "\n";
125  throw e;
126  }
127 
128  //
129  // check that all channels are here (except known missing ones)
130  //
131  if (fRequireFullCoverage) {
132  std::set<TrackedTriggerGate_t const*> allGates;
133  for (auto const channel: util::counter<raw::Channel_t >(gateIndex.nChannels())) {
134  if (isMissingChannel(channel)) continue;
135  allGates.insert(&(gateIndex[channel]));
136  }
137 
138  std::vector<TrackedTriggerGate_t const*> unusedGates;
139  std::set_difference(
140  allGates.cbegin(), allGates.cend(), usedGates.cbegin(), usedGates.cend(),
141  std::back_inserter(unusedGates)
142  );
143  if (!unusedGates.empty()) {
144  // we don't have much information to identify "which" gates...
145  cet::exception e("SlidingWindowCombinerAlg");
146  e << "SlidingWindowCombinerAlg::checkInput(): "
147  << "used only " << usedGates.size() << "/" << allGates.size()
148  << " input trigger gates, " << unusedGates.size() << " were not used:";
149  for (TrackedTriggerGate_t const* gate: unusedGates) {
150  e << "{";
151  for (raw::Channel_t const channel: gate->channels())
152  e << " ch:" << std::to_string(channel);
153  e << " }";
154  } // for
155  e << "\n";
156  throw e;
157  } // if unused
158  } // if full coverage
159 
160 } // icarus::trigger::SlidingWindowCombinerAlg::checkInput()
icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta > TrackedTriggerGate_t
Trigger gate data type (tracks sources via sbn::OpDetWaveformMeta).
bool isMissingChannel(raw::Channel_t channel) const
Returns if channel is configured to be missing.
std::string to_string(WindowPattern const &pattern)
std::vector< raw::Channel_t > fMissingChannels
Channels known (and required) to be missing (sorted).
do i e
bool const fRequireFullCoverage
Whether to require all channels to be used.
Windows_t const fWindowChannels
Content of channels of each window.
auto icarus::trigger::SlidingWindowCombinerAlg::combine ( std::vector< TrackedTriggerGate_t > const &  gates) const

Combines the gates according to the configured grouping.

Definition at line 34 of file SlidingWindowCombinerAlg.cxx.

36 {
37 
38  TriggerGateIndex_t gateIndex { gates };
39 
40  checkInput(gateIndex);
41 
42  std::vector<TrackedTriggerGate_t> combinedGates;
43  for (std::vector<raw::Channel_t> const& channels: fWindowChannels) {
44  assert(!channels.empty());
45 
46  combinedGates.push_back(combineChannels(gateIndex, channels));
47 
48  } // for
49 
50  return combinedGates;
51 } // icarus::trigger::SlidingWindowCombinerAlg::combine()
void checkInput(TriggerGateIndex_t const &gates) const
Throws an exception if the gates are not suitable for input.
icarus::trigger::TriggerGateIndex< TrackedTriggerGate_t > TriggerGateIndex_t
TrackedTriggerGate_t combineChannels(TriggerGateIndex_t const &gates, WindowChannels_t const &channels) const
Returns the combination of the channels selected from the gates.
Windows_t const fWindowChannels
Content of channels of each window.
auto icarus::trigger::SlidingWindowCombinerAlg::combineChannels ( TriggerGateIndex_t const &  gates,
WindowChannels_t const &  channels 
) const
private

Returns the combination of the channels selected from the gates.

Definition at line 165 of file SlidingWindowCombinerAlg.cxx.

167 {
168  assert(!channels.empty());
169 
170  auto iChannel = firstChannelPresent(channels);
171  auto const cend = channels.end();
172  if (iChannel == cend) return {}; // empty gate, no channels inside
173 
174  TrackedTriggerGate_t const& firstGate = gates[*iChannel];
175 
176  // add the first gate
177  TrackedTriggerGate_t gate { firstGate };
178 
179  mf::LogTrace(fLogCategory) << "Input: " << firstGate;
180  while (++iChannel != cend) {
181  if (isMissingChannel(*iChannel)) continue;
182 
183  TrackedTriggerGate_t const& inputGate = gates[*iChannel];
184 
185  mf::LogTrace(fLogCategory) << "Input: " << inputGate;
186  mergeGateInto(gate, inputGate);
187 
188  } // while
189  mf::LogTrace(fLogCategory) << "Output: " << gate;
190 
191  return gate;
192 
193 } // icarus::trigger::SlidingWindowCombinerAlg::combineChannel()
icarus::trigger::TrackedOpticalTriggerGate< sbn::OpDetWaveformMeta > TrackedTriggerGate_t
Trigger gate data type (tracks sources via sbn::OpDetWaveformMeta).
std::string fLogCategory
Category for messages to MessageFacility.
bool isMissingChannel(raw::Channel_t channel) const
Returns if channel is configured to be missing.
auto cend(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:579
WindowChannels_t::const_iterator firstChannelPresent(WindowChannels_t const &channels) const
Returns an iterator to the first of the channels which is not missing.
static bool mergeGateInto(TrackedTriggerGate_t &dest, TrackedTriggerGate_t const &input)
auto icarus::trigger::SlidingWindowCombinerAlg::firstChannelPresent ( WindowChannels_t const &  channels) const
private

Returns an iterator to the first of the channels which is not missing.

Definition at line 198 of file SlidingWindowCombinerAlg.cxx.

199 {
200  auto iChannel = channels.begin();
201  auto const cend = channels.end();
202  while (iChannel != cend) if (!isMissingChannel(*iChannel)) return iChannel;
203  return cend;
204 } // icarus::trigger::SlidingWindowCombinerAlg::firstChannelPresent()
bool isMissingChannel(raw::Channel_t channel) const
Returns if channel is configured to be missing.
auto cend(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:579
template<typename Cont , typename T >
static bool icarus::trigger::SlidingWindowCombinerAlg::inList ( Cont const &  c,
T const &  value 
)
inlinestaticprivate

Returns whether the container c has value.

Definition at line 114 of file SlidingWindowCombinerAlg.h.

115  { auto cend = c.end(); return std::find(c.begin(), cend, value) != cend; }
auto cend(FixedBins< T, C > const &) noexcept
Definition: FixedBins.h:579
temporary value
bool icarus::trigger::SlidingWindowCombinerAlg::isMissingChannel ( raw::Channel_t  channel) const
inline

Returns if channel is configured to be missing.

Definition at line 125 of file SlidingWindowCombinerAlg.h.

126 {
127  return std::find(fMissingChannels.begin(), fMissingChannels.end(), channel)
128  != fMissingChannels.end();
129 } // icarus::trigger::SlidingWindowCombinerAlg::isMissingChannel()
std::vector< raw::Channel_t > fMissingChannels
Channels known (and required) to be missing (sorted).
bool icarus::trigger::SlidingWindowCombinerAlg::mergeGateInto ( TrackedTriggerGate_t dest,
TrackedTriggerGate_t const &  input 
)
staticprivate

Adds the gate data of input to dest, unless it's already included.

Returns
whether the addition happened

Definition at line 209 of file SlidingWindowCombinerAlg.cxx.

210 {
211  // loose check: assumes channel sets of all possible inputs do not overlap
212  // and checks whether the destination has already any one of input channels
213  auto const& channels = dest.gate().channels();
214  if (inList(channels, *(input.gate().channels().begin()))) return false;
215 
216  dest = icarus::trigger::sumGates(std::move(dest), input);
217 
218  return true;
219 
220 } // icarus::trigger::SlidingWindowCombinerAlg::mergeGateInto()
auto sumGates(GateColl const &gates)
Sums all the gates in a collection.
static bool inList(Cont const &c, T const &value)
Returns whether the container c has value.
auto icarus::trigger::SlidingWindowCombinerAlg::sortChannels ( std::vector< raw::Channel_t channels)
staticprivate

Returns a sorted copy of channels.

Definition at line 235 of file SlidingWindowCombinerAlg.cxx.

236 {
237  std::sort(channels.begin(), channels.end());
238  return channels;
239 } // icarus::trigger::SlidingWindowCombinerAlg::sortChannels
auto icarus::trigger::SlidingWindowCombinerAlg::sortedWindowChannels ( Windows_t const &  windows)
staticprivate

Returns windows with numerically sorted channel numbers.

Definition at line 225 of file SlidingWindowCombinerAlg.cxx.

226 {
227  Windows_t newWindows { windows };
228  for (auto& window: newWindows) std::sort(window.begin(), window.end());
229  return newWindows;
230 } // icarus::trigger::SlidingWindowCombinerAlg::sortWindowChannels()
icarus::trigger::TriggerWindowDefs_t Windows_t
Type of content of all windows.

Member Data Documentation

std::string icarus::trigger::SlidingWindowCombinerAlg::fLogCategory
private

Category for messages to MessageFacility.

Definition at line 86 of file SlidingWindowCombinerAlg.h.

std::vector<raw::Channel_t> icarus::trigger::SlidingWindowCombinerAlg::fMissingChannels
private

Channels known (and required) to be missing (sorted).

Definition at line 81 of file SlidingWindowCombinerAlg.h.

bool const icarus::trigger::SlidingWindowCombinerAlg::fRequireFullCoverage
private

Whether to require all channels to be used.

Definition at line 84 of file SlidingWindowCombinerAlg.h.

Windows_t const icarus::trigger::SlidingWindowCombinerAlg::fWindowChannels
private

Content of channels of each window.

Definition at line 78 of file SlidingWindowCombinerAlg.h.


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