All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackedTriggerGate_test.cc
Go to the documentation of this file.
1 /**
2  * @file TrackedTriggerGate_test.cc
3  * @brief Unit test for some utilities in `TrackedTriggerGate.h`
4  * @date January 13, 2022
5  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
6  * @see icaruscode/PMT/Trigger/Utilities/TrackedTriggerGate.h
7  *
8  * Largely incomplete.
9  */
10 
11 // ICARUS libraries
13 #include "icaruscode/IcarusObj/OpDetWaveformMeta.h" // sbn::OpDetWaveformMeta
14 
15 
16 // LArSoft libraries
19 
20 // Boost libraries
21 #define BOOST_TEST_MODULE ( TrackedTriggerGate_test )
22 #include <boost/test/unit_test.hpp>
23 
24 // C/C++ standard libraries
25 #include <utility> // std::as_const(), std::move()
26 #include <type_traits> // std::is_same_v
27 
28 
29 // -----------------------------------------------------------------------------
30 // --- static tests
31 // -----------------------------------------------------------------------------
32 
33 void static_tests() {
34 
36 
39  GateData_t gateData;
40 
41  //
42  // gateIn()
43  //
44  static_assert(std::is_same_v<
45  decltype(gateIn(trackedGate)),
47  >);
48  static_assert(std::is_same_v<
49  decltype(gateIn(std::as_const(trackedGate))),
51  >);
52  static_assert(std::is_same_v<
53  decltype(gateIn(std::move(trackedGate))),
55  >);
56 
57  static_assert(std::is_same_v<
58  decltype(gateIn(gate)),
60  >);
61  static_assert(std::is_same_v<
62  decltype(gateIn(std::as_const(gate))),
64  >);
65  static_assert(std::is_same_v<
66  decltype(gateIn(std::move(gate))),
68  >);
69 
70  //
71  // gateDataIn()
72  //
73  static_assert(std::is_same_v<
74  decltype(gateDataIn(trackedGate)),
75  GateData_t&
76  >);
77  static_assert(std::is_same_v<
78  decltype(gateDataIn(std::as_const(trackedGate))),
79  GateData_t const&
80  >);
81  static_assert(std::is_same_v<
82  decltype(gateDataIn(std::move(trackedGate))),
83  GateData_t&&
84  >);
85  static_assert(std::is_same_v<
86  decltype(gateDataIn(gate)),
87  GateData_t&
88  >);
89  static_assert(std::is_same_v<
90  decltype(gateDataIn(std::as_const(gate))),
91  GateData_t const&
92  >);
93  static_assert(std::is_same_v<
94  decltype(gateDataIn(std::move(gate))),
95  GateData_t&&
96  >);
97 
98  static_assert(std::is_same_v<
99  decltype(gateDataIn(gateData)),
100  GateData_t&
101  >);
102  static_assert(std::is_same_v<
103  decltype(gateDataIn(std::as_const(gateData))),
104  GateData_t const&
105  >);
106  static_assert(std::is_same_v<
107  decltype(gateDataIn(std::move(gateData))),
108  GateData_t&&
109  >);
110 
111  //
112  // ok, now some non-static tests just for safety
113  //
114  BOOST_TEST(gateIn(trackedGate) == trackedGate.gate());
115  BOOST_TEST(gateIn(gate) == gate);
116  BOOST_TEST(gateDataIn(trackedGate) == trackedGate.gate().gateLevels());
117  BOOST_TEST(gateDataIn(gate) == gate.gateLevels());
118  BOOST_TEST(gateDataIn(gateData) == gateData);
119 
120 } // static_tests()
121 
122 
123 // -----------------------------------------------------------------------------
124 // --- other tests
125 // -----------------------------------------------------------------------------
127 
128  /*
129  * This test is a copy from TriggerGateData unit test.
130  * It's basically a placeholder, since the real tests are the static ones.
131  */
132 
134  icarus::trigger::OpticalTriggerGateData_t& gate = trackedGate.gate();
135 
136  BOOST_CHECK((gate.alwaysClosed()));
137 
138  /*
139  * ^ 12 34
140  * 4 | === 20 ===
141  * 3 | -4 4 10 == === 26
142  * 2 | === 2 === == 15 === === 40
143  * 1 | == 7=== 17 23=== 29== 37 ===
144  * 0-*=======---=|=---,----,----,----,----,----,===-,-===,--===============
145  * -10 -5 0 5 10 20 30 40 50
146  */
147 
148  gate.openBetween(-4, -1, 2); // -> 2
149  gate.openAt ( 2); // -> 1
150  gate.openAt ( 4); // -> 2
151  gate.closeAt( 7); // -> 1
152  gate.openAt (10); // -> 2
153  gate.openAt (12, 2); // -> 4
154  gate.closeAt(15); // -> 3
155  gate.closeAt(17); // -> 2
156  gate.openAt (20); // -> 3
157  gate.closeAt(23, 2); // -> 1
158  gate.openAt (26); // -> 2
159  gate.closeAt(29); // -> 1
160  gate.closeAt(31); // -> 0
161  gate.openAt (34, 4); // -> 4
162  gate.closeAt(37, 4); // -> 0
163  gate.openAt (40); // -> 1
164  gate.closeAt(43); // -> 0
165 
166  BOOST_CHECK((!gate.alwaysClosed()));
167  BOOST_TEST((gate.openingCount(-9) == 0));
168  BOOST_TEST((gate.openingCount(-8) == 0));
169  BOOST_TEST((gate.openingCount(-7) == 0));
170  BOOST_TEST((gate.openingCount(-6) == 0));
171  BOOST_TEST((gate.openingCount(-5) == 0));
172  BOOST_TEST((gate.openingCount(-4) == 2));
173  BOOST_TEST((gate.openingCount(-3) == 2));
174  BOOST_TEST((gate.openingCount(-2) == 2));
175  BOOST_TEST((gate.openingCount(-1) == 0));
176  BOOST_TEST((gate.openingCount( 0) == 0));
177  BOOST_TEST((gate.openingCount( 1) == 0));
178  BOOST_TEST((gate.openingCount( 2) == 1));
179  BOOST_TEST((gate.openingCount( 3) == 1));
180  BOOST_TEST((gate.openingCount( 4) == 2));
181  BOOST_TEST((gate.openingCount( 5) == 2));
182  BOOST_TEST((gate.openingCount( 6) == 2));
183  BOOST_TEST((gate.openingCount( 7) == 1));
184  BOOST_TEST((gate.openingCount( 8) == 1));
185  BOOST_TEST((gate.openingCount( 9) == 1));
186  BOOST_TEST((gate.openingCount(10) == 2));
187  BOOST_TEST((gate.openingCount(11) == 2));
188  BOOST_TEST((gate.openingCount(12) == 4));
189  BOOST_TEST((gate.openingCount(13) == 4));
190  BOOST_TEST((gate.openingCount(14) == 4));
191  BOOST_TEST((gate.openingCount(15) == 3));
192  BOOST_TEST((gate.openingCount(16) == 3));
193  BOOST_TEST((gate.openingCount(17) == 2));
194  BOOST_TEST((gate.openingCount(18) == 2));
195  BOOST_TEST((gate.openingCount(19) == 2));
196  BOOST_TEST((gate.openingCount(20) == 3));
197  BOOST_TEST((gate.openingCount(21) == 3));
198  BOOST_TEST((gate.openingCount(22) == 3));
199  BOOST_TEST((gate.openingCount(23) == 1));
200  BOOST_TEST((gate.openingCount(24) == 1));
201  BOOST_TEST((gate.openingCount(25) == 1));
202  BOOST_TEST((gate.openingCount(26) == 2));
203  BOOST_TEST((gate.openingCount(27) == 2));
204  BOOST_TEST((gate.openingCount(28) == 2));
205  BOOST_TEST((gate.openingCount(29) == 1));
206  BOOST_TEST((gate.openingCount(30) == 1));
207  BOOST_TEST((gate.openingCount(31) == 0));
208  BOOST_TEST((gate.openingCount(32) == 0));
209  BOOST_TEST((gate.openingCount(33) == 0));
210  BOOST_TEST((gate.openingCount(34) == 4));
211  BOOST_TEST((gate.openingCount(35) == 4));
212  BOOST_TEST((gate.openingCount(36) == 4));
213  BOOST_TEST((gate.openingCount(37) == 0));
214  BOOST_TEST((gate.openingCount(38) == 0));
215  BOOST_TEST((gate.openingCount(39) == 0));
216  BOOST_TEST((gate.openingCount(40) == 1));
217  BOOST_TEST((gate.openingCount(41) == 1));
218  BOOST_TEST((gate.openingCount(42) == 1));
219  BOOST_TEST((gate.openingCount(43) == 0));
220  BOOST_TEST((gate.openingCount(44) == 0));
221  BOOST_TEST((gate.openingCount(45) == 0));
222  BOOST_TEST((gate.openingCount(46) == 0));
223  BOOST_TEST((gate.openingCount(47) == 0));
224  BOOST_TEST((gate.openingCount(48) == 0));
225  BOOST_TEST((gate.openingCount(49) == 0));
226 
227  BOOST_TEST((gate.findMaxOpen( ) == 12));
228  BOOST_TEST((gate.findMaxOpen(12) == 12));
229  BOOST_TEST((gate.findMaxOpen(13) == 13));
230  BOOST_TEST((gate.findMaxOpen(14) == 14));
231  BOOST_TEST((gate.findMaxOpen(15) == 34));
232 
233  auto [ lower2031, upper2031 ] = gate.openingRange(20, 30);
234  BOOST_TEST((lower2031 == 1));
235  BOOST_TEST((upper2031 == 4));
236 
237 } // TrackedTriggerGate_test()
238 
239 
240 // -----------------------------------------------------------------------------
241 // BEGIN Test cases -----------------------------------------------------------
242 // -----------------------------------------------------------------------------
243 BOOST_AUTO_TEST_CASE(TrackedTriggerGate_testcase) {
244 
245  static_tests();
246 
248 
249 } // BOOST_AUTO_TEST_CASE(TrackedTriggerGate_testcase)
250 
251 
252 // -----------------------------------------------------------------------------
253 // END Test cases -------------------------------------------------------------
254 // -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
Base_t GateData_t
Type for gate data access.
void TrackedTriggerGate_test()
A wrapper to trigger gate objects tracking the input of operations.
Derivative information from raw::OpDetWaveform data.
void static_tests()
GateData_t const & gateLevels() const
Access to the underlying gate level data.
void closeAt(ClockTick_t tick, OpeningDiff_t count)
Close this gate at the specified time (decrease the opening by count).
void openBetween(ClockTick_t start, ClockTick_t end, OpeningDiff_t count=1)
Open this gate at specified start tick, and close it at end tick.
Logical multi-level gate associated to one or more readout channels.
OpeningCount_t openingCount(ClockTick_t tick) const
Returns the opening count of the gate at the specified tick.
Functions to help debugging by instrumenting code.
void openAt(ClockTick_t tick, OpeningDiff_t count)
Open this gate at the specified time (increase the opening by count).
TriggerGate_t const & gate() const &
Returns the enclosed gate.
Data types for detinfo::DetectorTimings.
ClockTick_t findMaxOpen(ClockTick_t start=MinTick, ClockTick_t end=MaxTick) const
Returns the tick at which the gate has the maximum opening.
A simple alias for a most commonly used TrackedTriggerGate type.
decltype(auto) gateDataIn(Gate &&gate)
Returns the trigger data (a TriggerGateData) from the specofied gate.
bool alwaysClosed() const
Returns whether this gate never opened.
std::pair< OpeningCount_t, OpeningCount_t > openingRange(ClockTick_t start, ClockTick_t end) const
Returns the range of trigger opening values in the specified range.
decltype(auto) gateIn(Gate &&gate)
Returns the trigger gate (a ReadoutTriggerGate) from the specified gate.