All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DetectorTimingTypes_test.cc
Go to the documentation of this file.
1 /**
2  * @file DetectorTimingTypes_test.cc
3  * @brief Test of `detinfo::DetectorTimings` with `DetectorClocksStandard`.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date June 27, 2019
6  */
7 
8 // Boost libraries
9 #define BOOST_TEST_MODULE ( DetectorTimingTypes_test )
10 #include <boost/test/unit_test.hpp>
11 
12 // LArSoft libraries
16 #include "larcorealg/CoreUtils/DebugUtils.h" // lar::debug::::static_assert_on<>
17 #include "larcorealg/CoreUtils/MetaUtils.h" // util::is_same_decay_v
19 
20 // C/C++ standard libraries
21 #include <type_traits> // std::decay_t<>, std::is_same_v<>
22 
23 
24 //------------------------------------------------------------------------------
25 //--- static tests
26 //------------------------------------------------------------------------------
27 
28 static_assert(!detinfo::timescales::is_tick_v<double>);
29 static_assert
30  (!detinfo::timescales::is_tick_v<util::quantities::second>);
31 static_assert
32  ( detinfo::timescales::is_tick_v<util::quantities::tick>);
33 static_assert
34  ( detinfo::timescales::is_tick_v<util::quantities::tick_d>);
35 static_assert
36  (!detinfo::timescales::is_tick_v<detinfo::timescales::optical_time>);
37 static_assert
38  ( detinfo::timescales::is_tick_v<detinfo::timescales::optical_tick>);
39 static_assert
40  ( detinfo::timescales::is_tick_v<detinfo::timescales::optical_time_ticks>);
41 
42 //------------------------------------------------------------------------------
43 static_assert(
45  ::same_category_as<detinfo::timescales::optical_time>
46  );
47 static_assert(
49  ::category_compatible_with<detinfo::timescales::optical_time>
50  );
51 static_assert(
53  ::same_category_as<detinfo::timescales::optical_tick>
54  );
55 static_assert(
57  ::category_compatible_with<detinfo::timescales::optical_tick>
58  );
59 
60 
61 //------------------------------------------------------------------------------
62 static_assert(
63  detinfo::timescales::optical_time::category_compatible_with
65  );
66 static_assert(
67  detinfo::timescales::optical_time::category_compatible_with
69  );
70 static_assert(
71  detinfo::timescales::optical_time::category_compatible_with
73  );
74 static_assert(
75  detinfo::timescales::optical_time::category_compatible_with
77  );
78 static_assert(
79  detinfo::timescales::optical_time::category_compatible_with
81  );
82 static_assert(
83  detinfo::timescales::optical_time::category_compatible_with
85  );
86 static_assert(
87  detinfo::timescales::optical_time::category_compatible_with
89  );
90 static_assert(
91  !detinfo::timescales::optical_time::category_compatible_with
93  );
94 
95 
96 // -----------------------------------------------------------------------------
97 // optical type static tests
98 // -----------------------------------------------------------------------------
99 static_assert(std::is_same_v<
103  >);
104 static_assert(std::is_same_v<
108  >);
109 
110 
111 // -----------------------------------------------------------------------------
113 {
114  using namespace util::quantities::time_literals;
115  using namespace detinfo::timescales;
116 
117  using traits_t = timescale_traits<OpticalTimeCategory>;
118 
119  BOOST_TEST_MESSAGE("Testing category: " << traits_t::name());
120 
121  using time_point_t = traits_t::time_point_t;
122  using time_interval_t = traits_t::time_interval_t;
123 
124  //
125  // time points and intervals
126  //
127  time_point_t p { 10.0_us };
128  time_point_t p2 { 5.0_us };
129 
130  time_interval_t dt { 500_ns };
131 
132  static_assert(util::is_same_decay_v<decltype(p + dt), time_point_t>);
133  BOOST_TEST(p + dt == 10.5_us);
134  static_assert(util::is_same_decay_v<decltype(p + 500_ns), time_point_t>);
135  BOOST_TEST(p + 500_ns == 10.5_us);
136 
137  static_assert(util::is_same_decay_v<decltype(p - dt), time_point_t>);
138  BOOST_TEST(p - dt == 9.5_us);
139  static_assert(util::is_same_decay_v<decltype(p - 500_ns), time_point_t>);
140  BOOST_TEST(p - 500_ns == 9.5_us);
141 
142  static_assert(util::is_same_decay_v<decltype(p - p2), time_interval_t>);
143  BOOST_TEST(p - p2 == 5.0_us);
144 } // test_time_operations()
145 
146 
147 // -----------------------------------------------------------------------------
149 {
150  using namespace util::quantities::electronics_literals;
151  using namespace detinfo::timescales;
152 
153  using traits_t = timescale_traits<OpticalTimeCategory>;
154 
155  BOOST_TEST_MESSAGE("Testing category: " << traits_t::name());
156 
157  using tick_t = traits_t::tick_t;
158  using tick_interval_t = traits_t::tick_interval_t;
159 
160  //
161  // ticks
162  //
163  tick_t tick { 100.0_tick };
164  tick_t tick2 { 50.0_tick };
165 
166  tick_interval_t dtick { 30_tick };
167 
168  static_assert(util::is_same_decay_v<decltype(tick + dtick), tick_t>);
169  BOOST_TEST(tick + dtick == 130.0_tick);
170  static_assert(util::is_same_decay_v<decltype(tick + 30.0_tick), tick_t>);
171  BOOST_TEST(tick + 30.0_tick == 130.0_tick);
172 
173  static_assert(util::is_same_decay_v<decltype(tick - dtick), tick_t>);
174  BOOST_TEST(tick - dtick == 70.0_tick);
175  static_assert(util::is_same_decay_v<decltype(tick - 30.0_tick), tick_t>);
176  BOOST_TEST(tick - 30.0_tick == 70.0_tick);
177 
178  static_assert(util::is_same_decay_v<decltype(tick - tick2), tick_interval_t>);
179  BOOST_TEST(tick - tick2 == 50_tick);
180 } // test_integral_tick_operations()
181 
182 
183 // -----------------------------------------------------------------------------
185 {
186  using namespace util::quantities::electronics_literals;
187  using namespace detinfo::timescales;
188  using traits_t = timescale_traits<OpticalTimeCategory>;
189 
190  BOOST_TEST_MESSAGE("Testing category: " << traits_t::name());
191 
192  using tick_d_t = traits_t::tick_d_t;
193  using tick_interval_d_t = traits_t::tick_interval_d_t;
194 
195  //
196  // ticks
197  //
198  tick_d_t tick { 100.5_tickd };
199  tick_d_t tick2 { 50.0_tickd };
200 
201  tick_interval_d_t dtick { 30_tickd };
202 
203  static_assert(util::is_same_decay_v<decltype(tick + dtick), tick_d_t>);
204  BOOST_TEST(tick + dtick == 130.5_tickd);
205  static_assert(util::is_same_decay_v<decltype(tick + 30.0_tickd), tick_d_t>);
206  BOOST_TEST(tick + 30.0_tickd == 130.5_tickd);
207 
208  static_assert(util::is_same_decay_v<decltype(tick - dtick), tick_d_t>);
209  BOOST_TEST(tick - dtick == 70.5_tickd);
210  static_assert(util::is_same_decay_v<decltype(tick - 30.0_tickd), tick_d_t>);
211  BOOST_TEST(tick - 30.0_tickd == 70.5_tickd);
212 
213  static_assert
214  (util::is_same_decay_v<decltype(tick - tick2), tick_interval_d_t>);
215  BOOST_TEST(tick - tick2 == 50.5_tickd);
216 
217 
218  /// Type of a point in time, measured in ticks.
219  using ClockTick_t = optical_tick;
220 
221  /// Type of a time interval, measured in ticks.
222  using ClockTicks_t = optical_time_ticks;
223 
224  ClockTick_t mytick { 10_tick };
225  ClockTicks_t mydelay { 5_tick };
226 
227  ClockTick_t delayedTick = mytick + mydelay;
228  BOOST_TEST(delayedTick == 15_tick);
229 } // test_real_tick_operations()
230 
231 // ---------------------------------------------------------------------------
232 
233 BOOST_AUTO_TEST_SUITE(DetectorTimingTypes_test)
234 
235 BOOST_AUTO_TEST_CASE(OpticalTime_testcase)
236 {
240 }
241 
242 BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(AllTests)
Basic C++ metaprogramming utilities.
constexpr auto is_same_decay_v
Whether T and U are the same type, after being applied std::decay.
Definition: MetaUtils.h:263
pdgs p
Definition: selectors.fcl:22
void test_time_operations()
A collection of traits for a time scale.
timescale_traits< OpticalTimeCategory >::tick_interval_d_t optical_time_ticks_d
timescale_traits< OpticalTimeCategory >::tick_interval_t optical_time_ticks
Timing types for optical detector time scale.
tick_as<> tick
Tick number, represented by std::ptrdiff_t.
Definition: electronics.h:75
timescale_traits< OpticalTimeCategory >::time_point_t optical_time
A point in time on the optical detector electronics time scale.
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Category for electronics time scale.
Dimensioned variables related to electronics.
timescale_traits< OpticalTimeCategory >::tick_t optical_tick
Functions to help debugging by instrumenting code.
void test_real_tick_operations()
Dimensioned variables representing space or time quantities.
Data types for detinfo::DetectorTimings.
timescale_traits< OpticalTimeCategory >::tick_d_t optical_tick_d
then echo fcl name
void test_integral_tick_operations()
timescale_traits< ElectronicsTimeCategory >::time_point_t electronics_time
A point in time on the electronics time scale.