All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
readout_types_test.cc
Go to the documentation of this file.
1 /**
2  * @file readout_types_test.cc
3  * @brief Test of readout_types.h types
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date June 19th, 2015
6  */
7 
8 // Define the following non-zero to exclude include code that is required
9 // not to be compilable
10 #ifndef READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
11 # define READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS 1
12 #endif // !READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
13 
14 // Boost libraries
15 /*
16  * Boost Magic: define the name of the module;
17  * and do that before the inclusion of Boost unit test headers
18  * because it will change what they provide.
19  * Among the those, there is a main() function and some wrapping catching
20  * unhandled exceptions and considering them test failures, and probably more.
21  * This also makes fairly complicate to receive parameters from the command line
22  * (for example, a random seed).
23  */
24 #define BOOST_TEST_MODULE ( readout_types_test )
25 #include "boost/test/unit_test.hpp"
26 
27 // LArSoft libraries
29 
30 
31 //------------------------------------------------------------------------------
32 template <typename ID>
33 constexpr bool assertGeoIDlevel()
34  { return geo::details::geoElementLevel<ID>() == ID::Level; }
35 
36 //------------------------------------------------------------------------------
37 // compile-time tests:
38 //
39 // consistency check between levels
40 static_assert(assertGeoIDlevel<readout::TPCsetID>());
41 static_assert(assertGeoIDlevel<readout::ROPID>());
42 static_assert(!geo::details::isTopGeoElementID<readout::TPCsetID>);
43 static_assert(!geo::details::isTopGeoElementID<readout::ROPID>);
44 
45 static_assert(std::is_same_v<readout::TPCsetID::ID_t<0U>, readout::CryostatID>);
46 static_assert(std::is_same_v<readout::TPCsetID::ID_t<1U>, readout::TPCsetID>);
47 static_assert(std::is_same_v<readout::TPCsetID::UpperID_t<0U>, readout::TPCsetID>);
48 static_assert(std::is_same_v<readout::TPCsetID::UpperID_t<1U>, readout::CryostatID>);
49 static_assert(std::is_same_v<readout::ROPID::ID_t<0U>, readout::CryostatID>);
50 static_assert(std::is_same_v<readout::ROPID::ID_t<1U>, readout::TPCsetID>);
51 static_assert(std::is_same_v<readout::ROPID::ID_t<2U>, readout::ROPID>);
52 static_assert(std::is_same_v<readout::ROPID::UpperID_t<0U>, readout::ROPID>);
53 static_assert(std::is_same_v<readout::ROPID::UpperID_t<1U>, readout::TPCsetID>);
54 static_assert(std::is_same_v<readout::ROPID::UpperID_t<2U>, readout::CryostatID>);
55 
56 static_assert(readout::TPCsetID{0,1}.getIndex <0U>() == 0);
57 static_assert(readout::TPCsetID{0,1}.getIndex <1U>() == 1);
58 static_assert(readout::TPCsetID{0,1}.getRelIndex<0U>() == 1);
59 static_assert(readout::TPCsetID{0,1}.getRelIndex<1U>() == 0);
60 static_assert(readout::ROPID{0,1,2} .getIndex <0U>() == 0);
61 static_assert(readout::ROPID{0,1,2} .getIndex <1U>() == 1);
62 static_assert(readout::ROPID{0,1,2} .getIndex <2U>() == 2);
63 static_assert(readout::ROPID{0,1,2} .getRelIndex<0U>() == 2);
64 static_assert(readout::ROPID{0,1,2} .getRelIndex<1U>() == 1);
65 static_assert(readout::ROPID{0,1,2} .getRelIndex<2U>() == 0);
66 
67 // IDs must not be convertible to integers
68 static_assert(
69  !std::is_convertible
71  "readout::CryostatID can be implicitly converted to an integral type"
72  );
73 
74 static_assert(
75  !std::is_convertible
77  "readout::TPCsetID can be implicitly converted to an integral type"
78  );
79 static_assert(
81  "readout::TPCsetID can be implicitly converted to an integral type"
82  );
83 
84 static_assert(
85  !std::is_convertible
87  "readout::ROPID can be implicitly converted to an integral type"
88  );
89 static_assert(
91  "readout::ROPID can be implicitly converted to an integral type"
92  );
93 static_assert(
95  "readout::ROPID can be implicitly converted to an integral type"
96  );
97 
98 
99 //------------------------------------------------------------------------------
100 // run-time tests:
101 //
102 void TestIDvalidity(readout::CryostatID const& id, bool answer) {
103  // - check isValid
104  BOOST_TEST(id.isValid == answer);
105  // - check operator!
106  BOOST_TEST(!id == !answer);
107  // - check operator bool
108  BOOST_TEST((bool)id == answer);
109 } // TestIDvalidity()
110 
111 /// Test comparison operators
112 template <typename TESTID, typename REFID = TESTID>
113 void TestCompareSmallerID(TESTID const& id, REFID const& smaller) {
114  BOOST_TEST(!(id < smaller) );
115  BOOST_TEST(!(id == smaller) );
116  BOOST_TEST( id != smaller );
117  BOOST_TEST( smaller < id );
118  BOOST_TEST(smaller.cmp(id) < 0);
119  BOOST_TEST(id.cmp(smaller) > 0);
120 } // TestCompareSmallerID()
121 
122 /// Test comparison operators
123 template <typename TESTID, typename REFID = TESTID>
124 void TestCompareSameID(TESTID const& id, REFID const& same) {
125  BOOST_TEST(!(id < same) );
126  BOOST_TEST( id == same );
127  BOOST_TEST(!(id != same) );
128  BOOST_TEST(!(same < id) );
129  BOOST_TEST(same.cmp(id) == 0);
130  BOOST_TEST(id.cmp(same) == 0);
131 } // TestCompareSameID()
132 
133 /// Test comparison operators
134 template <typename TESTID>
135 void TestCompareSelfID(TESTID const& id)
136  { return TestCompareSameID(id, id); }
137 
138 /// Test comparison operators
139 template <typename TESTID, typename REFID = TESTID>
140 void TestCompareLargerID(TESTID const& id, REFID const& larger) {
141  BOOST_TEST( id < larger );
142  BOOST_TEST( id != larger );
143  BOOST_TEST(!(id == larger) );
144  BOOST_TEST(!(larger < id) );
145  BOOST_TEST(larger.cmp(id) > 0);
146  BOOST_TEST(id.cmp(larger) < 0);
147 } // TestCompareLargerID()
148 
149 
150 /// Test comparison operators
151 template <typename TESTID, typename REFID = TESTID>
153  TESTID const& id,
154  REFID const& smaller,
155  REFID const& same,
156  REFID const& larger
157 ) {
158  TestCompareSmallerID(id, smaller);
159  TestCompareSameID(id, same);
160  TestCompareSelfID(id);
161  TestCompareLargerID(id, larger);
162 } // TestCryostatComparison()
163 
164 
166 
167  BOOST_TEST_MESSAGE("Testing default-constructed cryostat ID");
168 
170 
171  // a default-constructed ID is invalid:
172  TestIDvalidity(cid, false);
173 
174 /* // feature not added
175  // test assignment from ID_t
176  cid = 1;
177  BOOST_TEST(cid.Cryostat == 1);
178 */
179 
180 } // test_CryostatID_defaultConstructor()
181 
182 
184 
185  BOOST_TEST_CHECKPOINT("Testing cryostat ID constructed with an integer");
186 
187  readout::CryostatID cid(1);
188 
189  // an explicitly constructed ID is valid:
190  TestIDvalidity(cid, true);
191 
192  // check the ID value
193  BOOST_TEST(cid.Cryostat == readout::CryostatID::CryostatID_t(1));
194 
195  // test comparison operators
196  // (exercise copy constructor too)
197  readout::CryostatID smaller_cid(0), same_cid(cid), larger_cid(2);
198 
199  TestIDcomparison(cid, smaller_cid, same_cid, larger_cid);
200 
201 
202  // make sure the ID with cryostat 0 is fine (it's not a bad ID!)
203  BOOST_TEST_CHECKPOINT("Testing cryostat ID constructed with an integer 0");
204 
205  readout::CryostatID first_cid(0);
206  TestIDvalidity(cid, true);
207 
208  // check the ID value
209  BOOST_TEST(first_cid.Cryostat == readout::CryostatID::CryostatID_t(0));
210 
211 } // test_CryostatID_directConstructor()
212 
213 
214 
216 
217  BOOST_TEST_CHECKPOINT("Testing default-constructed TPC set ID");
218 
219  readout::TPCsetID sid;
220 
221  // a default-constructed ID is invalid:
222  TestIDvalidity(sid, false);
223 
224 } // test_TPCsetID_defaultConstructor()
225 
226 
228 
229  BOOST_TEST_CHECKPOINT("Testing integral-constructed TPC set ID");
230 
231 #if READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
232  BOOST_TEST_MESSAGE(" (test skipped)");
233 #else
234  readout::TPCsetID sid(1);
235 
236  BOOST_TEST_MESSAGE("TPCsetID(1) = " << std::string(sid));
237 
239 
240  BOOST_TEST_MESSAGE("int(TPCsetID(1)) = " << what);
241 
242 #endif // READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
243 
244 } // test_TPCsetID_integralConstructor()
245 
246 
248 
249  BOOST_TEST_CHECKPOINT("Testing ID-constructed TPC set ID");
250 
251  readout::CryostatID cid(1);
252  readout::TPCsetID sid(cid, 15);
253 
254  // an explicitly constructed ID is valid:
255  TestIDvalidity(sid, true);
256 
257  // check the ID value
258  BOOST_TEST(sid.Cryostat == readout::CryostatID::CryostatID_t( 1));
259  BOOST_TEST(sid.TPCset == readout::TPCsetID::TPCsetID_t(15));
260 
261  // test comparison operators (exercise copy constructor too)
262  // - with TPC ID
263  BOOST_TEST_CHECKPOINT("Testing comparison with TPC set ID");
264  readout::TPCsetID smaller_sid(cid, sid.TPCset - 1), same_sid(sid),
265  larger_sid(cid, sid.TPCset + 1);
266 
267  TestIDcomparison(sid, smaller_sid, same_sid, larger_sid);
268 
269 } // test_TPCsetID_nestedConstructor()
270 
271 
273 
274  BOOST_TEST_CHECKPOINT("Testing TPC set ID constructed with indices");
275 
276  readout::TPCsetID sid(1, 15);
277 
278  // an explicitly constructed ID is valid:
279  TestIDvalidity(sid, true);
280 
281  BOOST_TEST_CHECKPOINT("Testing comparison with same cryostat ID");
282 
283  readout::TPCsetID smaller_sid(1, 14), same_sid(1, 15), larger_sid(1, 16);
284  TestIDcomparison(sid, smaller_sid, same_sid, larger_sid);
285 
286  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID");
287  readout::TPCsetID smaller_cid(0, 16), larger_cid(2, 14);
288  TestCompareSmallerID(sid, smaller_cid);
289  TestCompareLargerID(sid, larger_cid);
290 
291  // test setting and accessing a single index
292  BOOST_TEST(sid.getIndex<0U>() == 1);
293  sid.writeIndex<0U>() = 2;
294  BOOST_TEST(sid.getIndex<0U>() == 2);
295 
296  BOOST_TEST(sid.getIndex<1U>() == 15);
297  sid.writeIndex<1U>() = 19;
298  BOOST_TEST(sid.getIndex<1U>() == 19);
299 
300  // make sure the ID with TPC set 0 is fine (it's not a bad ID!)
301  BOOST_TEST_CHECKPOINT("Testing TPC set ID constructed with a TPC set #0");
302 
303  readout::TPCsetID first_sid(0, 0);
304  TestIDvalidity(first_sid, true);
305 
306  // - check the ID value
307  BOOST_TEST(first_sid.Cryostat == readout::CryostatID::CryostatID_t(0));
308  BOOST_TEST(first_sid.TPCset == readout::TPCsetID::TPCsetID_t(0));
309 
310 
311 } // test_TPCsetID_directConstructor()
312 
313 
314 
316 
317  BOOST_TEST_CHECKPOINT("Testing default-constructed ROP ID");
318 
319  readout::ROPID rid;
320 
321  // a default-constructed ID is invalid:
322  TestIDvalidity(rid, false);
323 
324 } // test_ROPID_defaultConstructor()
325 
326 
328 
329  BOOST_TEST_CHECKPOINT("Testing integral-constructed ROP ID");
330 
331 #if READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
332  BOOST_TEST_MESSAGE(" (test skipped)");
333 #else
334  readout::ROPID rid(1);
335 
336  BOOST_TEST_MESSAGE("ROPID(1) = " << std::string(rid));
337 
338  readout::ROPID::ROPID_t what = rid;
339 
340  BOOST_TEST_MESSAGE("int(ROPID(1)) = " << what);
341 
342 #endif // READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
343 
344 } // test_ROPID_integralConstructor()
345 
346 
348 
349  BOOST_TEST_CHECKPOINT("Testing ID-constructed ROP ID");
350 
351  readout::TPCsetID sid(1, 15);
352  readout::ROPID rid(sid, 32);
353 
354  // an explicitly constructed ID is valid:
355  TestIDvalidity(rid, true);
356 
357  // check the ID value
358  BOOST_TEST(rid.Cryostat == readout::CryostatID::CryostatID_t( 1));
359  BOOST_TEST(rid.TPCset == readout::TPCsetID::TPCsetID_t(15));
360  BOOST_TEST(rid.ROP == readout::ROPID::ROPID_t(32));
361 
362  // test comparison operators (exercise copy constructor too)
363  BOOST_TEST_CHECKPOINT("Testing comparison with ROP ID");
364  readout::ROPID smaller_rid(sid, rid.ROP - 1), same_rid(rid),
365  larger_rid(sid, rid.ROP + 1);
366 
367  TestIDcomparison(rid, smaller_rid, same_rid, larger_rid);
368 
369 } // test_ROPID_nestedConstructor()
370 
371 
373 
374  BOOST_TEST_CHECKPOINT("Testing ROP ID constructed with indices");
375 
376  readout::ROPID rid(1, 15, 32);
377 
378  // an explicitly constructed ID is valid:
379  TestIDvalidity(rid, true);
380 
381  // check the ID value
382  BOOST_TEST(rid.Cryostat == readout::CryostatID::CryostatID_t( 1));
383  BOOST_TEST(rid.TPCset == readout::TPCsetID::TPCsetID_t(15));
384  BOOST_TEST(rid.ROP == readout::ROPID::ROPID_t(32));
385 
386  BOOST_TEST_CHECKPOINT("Testing comparison with same TPC set ID");
387 
389  smaller_rid(1, 15, 31), same_rid(1, 15, 32), larger_rid(1, 15, 33);
390  TestIDcomparison(rid, smaller_rid, same_rid, larger_rid);
391 
392  BOOST_TEST_CHECKPOINT("Testing comparison with different TPC set ID (1)");
393  readout::ROPID smaller_sid1(1, 14, 33), larger_sid1(1, 16, 31);
394  TestCompareSmallerID(rid, smaller_sid1);
395  TestCompareLargerID(rid, larger_sid1);
396  BOOST_TEST_CHECKPOINT("Testing comparison with different TPC set ID (2)");
397  readout::ROPID smaller_sid2(1, 14, 32), larger_sid2(1, 16, 32);
398  TestCompareSmallerID(rid, smaller_sid2);
399  TestCompareLargerID(rid, larger_sid2);
400 
401  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID");
402  readout::ROPID smaller_cid1(0, 15, 33), larger_cid1(2, 15, 31);
403  TestCompareSmallerID(rid, smaller_cid1);
404  TestCompareLargerID(rid, larger_cid1);
405  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID (2)");
406  readout::ROPID smaller_cid2(0, 15, 32), larger_cid2(2, 15, 32);
407  TestCompareSmallerID(rid, smaller_cid2);
408  TestCompareLargerID(rid, larger_cid2);
409 
410  // test setting and accessing a single index
411  BOOST_TEST(rid.getIndex<0U>() == 1);
412  rid.writeIndex<0U>() = 2;
413  BOOST_TEST(rid.getIndex<0U>() == 2);
414 
415  BOOST_TEST(rid.getIndex<1U>() == 15);
416  rid.writeIndex<1U>() = 19;
417  BOOST_TEST(rid.getIndex<1U>() == 19);
418 
419  BOOST_TEST(rid.getIndex<2U>() == 32);
420  rid.writeIndex<2U>() = 76;
421  BOOST_TEST(rid.getIndex<2U>() == 76);
422 
423  // make sure the ID with TPC 0 is fine (it's not a bad ID!)
424  BOOST_TEST_CHECKPOINT("Testing ROP ID constructed with a ROP #0");
425 
426  readout::ROPID first_rid(0, 0, 0);
427  TestIDvalidity(first_rid, true);
428 
429  // - check the ID value
430  BOOST_TEST(first_rid.Cryostat == readout::CryostatID::CryostatID_t(0));
431  BOOST_TEST(first_rid.TPCset == readout::TPCsetID::TPCsetID_t(0));
432  BOOST_TEST(first_rid.ROP == readout::ROPID::ROPID_t(0));
433 
434 } // test_ROPID_directConstructor()
435 
436 
437 
438 
439 //
440 // CryostatID test
441 //
442 BOOST_AUTO_TEST_CASE(CryostatIDtest) {
445 }
446 
447 //
448 // TPCsetID test
449 //
450 BOOST_AUTO_TEST_CASE(TPCsetIDtest) {
455 }
456 
457 //
458 // ROPID test
459 //
465 }
466 
BOOST_AUTO_TEST_CASE(AllTests)
void TestCompareSelfID(TESTID const &id)
Test comparison operators.
void test_ROPID_directConstructor()
Classes identifying readout-related concepts.
void test_ROPID_integralConstructor()
constexpr auto getRelIndex() const
Returns the index Above levels higher than Level.
unsigned int ROPID_t
Type for the ID number.
void TestCompareSameID(TESTID const &id, REFID const &same)
Test comparison operators.
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
constexpr auto getIndex() const
Returns the index level Index of this type.
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
CryostatID_t Cryostat
Index of cryostat.
Definition: geo_types.h:212
details::AbsIDtype< L, ThisID_t > ID_t
Type of the ID with the specified level L.
Definition: readout_types.h:78
void TestIDvalidity(geo::CryostatID const &id, bool answer)
auto & writeIndex()
Returns the index level Index of this type.
constexpr auto getIndex() const
Returns the index level Index of this type.
void test_ROPID_nestedConstructor()
ROPID_t ROP
Index of the readout plane within its TPC set.
void TestCompareSmallerID(TESTID const &id, REFID const &smaller)
Test comparison operators.
void test_TPCsetID_integralConstructor()
constexpr auto getRelIndex() const
Returns the index Above levels higher than Level.
Class identifying a set of planes sharing readout channels.
details::RelIDtype< A, ThisID_t > UpperID_t
Type of the ID A levels above this one.
Definition: readout_types.h:82
TPCsetID_t TPCset
Index of the TPC set within its cryostat.
Definition: readout_types.h:90
void test_CryostatID_directConstructor()
void test_CryostatID_defaultConstructor()
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void test_TPCsetID_defaultConstructor()
details::AbsIDtype< L, ThisID_t > ID_t
Type of the ID with the specified level L.
void test_TPCsetID_nestedConstructor()
void TestCompareLargerID(TESTID const &id, REFID const &larger)
Test comparison operators.
constexpr bool assertGeoIDlevel()
temporary value
void test_ROPID_defaultConstructor()
auto & writeIndex()
Returns the index level Index of this type.
void test_TPCsetID_directConstructor()
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
details::RelIDtype< A, ThisID_t > UpperID_t
Type of the ID A levels above this one.