All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TriggerGateDataFormatting.h
Go to the documentation of this file.
1 /**
2  * @file icaruscode/PMT/Trigger/Utilities/TriggerGateDataFormatting.h
3  * @brief Utilities for `TriggerGateData` printout.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date July 13, 2021
6  */
7 
8 #ifndef ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEDATAFORMATTING_H
9 #define ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEDATAFORMATTING_H
10 
11 
12 // ICARUS libraries
13 #include "icarusalg/Utilities/IntegerRanges.h" // icarus::makeIntegerRanges()
15 
16 // C/C++ standard libraries
17 #include <ostream>
18 
19 
20 namespace icarus::trigger {
21 
22  namespace details {
23 
24  /// Container of a single gate (base class).
25  template <typename Gate>
26  struct GateWrapper {
27  Gate const& gate;
28  };
29  template <typename Gate>
30  GateWrapper(Gate const&) ->GateWrapper<Gate>;
31 
32  /// Wrapper to format a gate as "compact".
33  template <typename Gate>
34  struct CompactFormatter: GateWrapper<Gate> {};
35 
36  /// Implementation of `compactdump()` printout of a gate.
37  /// @see `compactdump()`
38  template <typename Gate>
39  std::ostream& operator<<
40  (std::ostream& out, CompactFormatter<Gate> const& wrap);
41 
42  } // namespace details
43 
44 
45  /**
46  * @brief Manipulator-like function for compact format of trigger gates.
47  * @tparam Tick template type `Tick` for `ReadoutTriggerGate`
48  * @tparam TickInterval template type `TickInterval` for `ReadoutTriggerGate`
49  * @tparam ChannelIDType template type `ChannelIDType` for `ReadoutTriggerGate`
50  * @param gate the gate to be formatted
51  * @return a wrapper with the parameters to format the gate
52  *
53  * This helper function is always used in the context of the insertion of a
54  * trigger gate data object into an output stream:
55  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp}
56  * #include "icaruscode/PMT/Trigger/Utilities/TriggerGateDataFormatting.h"
57  * #include "sbnobj/ICARUS/PMT/Trigger/Data/OpticalTriggerGate.h"
58  * #include "larcorealg/CoreUtils/enumerate.h"
59  * #include <iostream>
60  *
61  * // ...
62  *
63  * std::vector<icarus::trigger::OpticalTriggerGate> LVDSgates;
64  *
65  * // ...
66  *
67  * for (auto const& [ iGate, gate ]: util::enumerate(LVDSgates))
68  * std::cout << "[" << iGate << "] " << compactdump(gate) << std::endl;
69  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70  * The loop will print all the `LVDSgates` in "compact" mode, one per line,
71  * prepended by their position in the collection.
72  *
73  * Technical note: `compactdump()` in the example is found by the compiler via
74  * Koenig lookup.
75  *
76  */
77  template <typename Tick, typename TickInterval, typename ChannelIDType>
78  auto compactdump
81  { return { details::GateWrapper{ gate } }; }
82 
83 
84 } // namespace icarus::trigger
85 
86 
87 // -----------------------------------------------------------------------------
88 // -- template implementation
89 // -----------------------------------------------------------------------------
90 
91 template <typename Gate>
92 std::ostream& icarus::trigger::details::operator<<
93  (std::ostream& out, CompactFormatter<Gate> const& wrap)
94 {
95  auto const& gate { wrap.gate };
96 
97  out << "[";
98  if (gate.hasChannel()) {
99  out << "channel: " << gate.channel();
100  }
101  else if (gate.hasChannels()) {
102  out << gate.nChannels() << " channels: "
103  << icarus::makeIntegerRanges(gate.channels());
104  }
105  else out << "no channel";
106  out << "] " << gate.gateLevels();
107 
108  return out;
109 } // icarus::trigger::operator<< (GateWrapper)
110 
111 
112 // -----------------------------------------------------------------------------
113 
114 
115 #endif // ICARUSCODE_PMT_TRIGGER_UTILITIES_TRIGGERGATEDATAFORMATTING_H
ChannelID_t channel() const
Returns the channel associated to the gate data.
Class compacting a list of integers.
IntegerRanges< typename Coll::value_type, CheckGrowing > makeIntegerRanges(Coll const &coll)
Logical multi-level gate associated to one or more readout channels.
GateWrapper(Gate const &) -> GateWrapper< Gate >
Wrapper to format a gate as &quot;compact&quot;.
Container of a single gate (base class).
A trigger gate data object associated to one or more channels.
auto compactdump(ReadoutTriggerGate< Tick, TickInterval, ChannelIDType > const &gate) -> details::CompactFormatter< ReadoutTriggerGate< Tick, TickInterval, ChannelIDType >>
Manipulator-like function for compact format of trigger gates.