ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HierarchicalGeometryContainerTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HierarchicalGeometryContainerTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 #include <iterator>
11 #include <stdexcept>
12 
14 
15 namespace {
16 
17 using Acts::GeometryID;
18 
19 struct Thing {
20  GeometryID id;
21  double value = 1.0;
22 
23  Thing(GeometryID i, double v) : id(i), value(v) {}
24 
25  constexpr auto geometryId() const { return id; }
26 };
27 
29 
30 // helper function to create geometry ids
31 GeometryID makeId(int volume, int layer = 0, int sensitive = 0) {
32  return GeometryID().setVolume(volume).setLayer(layer).setSensitive(sensitive);
33 }
34 
35 } // namespace
36 
37 BOOST_TEST_DONT_PRINT_LOG_VALUE(Container::Iterator)
38 
39 BOOST_AUTO_TEST_SUITE(HierarchicalGeometryContainer)
40 
41 BOOST_AUTO_TEST_CASE(ConstructDefault) {
42  Container c;
43  BOOST_TEST(c.begin() == c.end());
44  BOOST_TEST(c.empty());
45  BOOST_TEST(c.size() == 0u);
46 }
47 
48 BOOST_AUTO_TEST_CASE(ConstructNonUnique) {
49  std::vector<Thing> elements = {
50  {makeId(2, 4, 6), 1.0},
51  {makeId(3, 5), 1.0},
52  {makeId(3), 1.0},
53  // duplicate identifier
54  {makeId(2, 4, 6), 2.0},
55  };
56  BOOST_CHECK_THROW(Container(std::move(elements)), std::invalid_argument);
57 }
58 
60  Container c({
61  // entry for volume 2, layer 4, sensitive 6
62  {makeId(2, 4, 6), -23.0},
63  // entry for volume 2, layer 8
64  {makeId(2, 8), 5.0},
65  // entry for the whole volume 2
66  {makeId(2), 1.0},
67  // entry for volume 12, layer 16
68  // NOTE no entry for the volume as a whole
69  {makeId(12, 16), -1.0},
70  });
71 
72  // basic checks
73  BOOST_TEST(std::next(c.begin(), 4u) == c.end());
74  BOOST_TEST(not c.empty());
75  BOOST_TEST(c.size() == 4u);
76 
77  // find existing sensitive
78  {
79  auto ret = c.find(makeId(2, 4, 6));
80  BOOST_TEST(ret != c.end());
81  BOOST_TEST(ret->id == makeId(2, 4, 6));
82  }
83  // find non-existing sensitive, which has a set volume
84  {
85  auto ret = c.find(makeId(2, 4, 7));
86  BOOST_TEST(ret != c.end());
87  BOOST_TEST(ret->id == makeId(2));
88  }
89  // find non-existing layer id, which has a set volume
90  {
91  auto ret = c.find(makeId(2, 13));
92  BOOST_TEST(ret != c.end());
93  BOOST_TEST(ret->id == makeId(2));
94  }
95  // find non-existing sensitive id, which has a set layer
96  {
97  auto ret = c.find(makeId(2, 8, 13));
98  BOOST_TEST(ret != c.end());
99  BOOST_TEST(ret->id == makeId(2, 8));
100  }
101  // find existing layer
102  {
103  auto ret = c.find(makeId(2, 8));
104  BOOST_TEST(ret != c.end());
105  BOOST_TEST(ret->id == makeId(2, 8));
106  }
107  // find existing volume
108  {
109  auto ret = c.find(makeId(2));
110  BOOST_TEST(ret != c.end());
111  BOOST_TEST(ret->id == makeId(2));
112  }
113 
114  // find non-existing sensitive, which has a set layer
115  {
116  auto ret = c.find(makeId(12, 16, 20));
117  BOOST_TEST(ret != c.end());
118  BOOST_TEST(ret->id == makeId(12, 16));
119  }
120  // find existing layer
121  {
122  auto ret = c.find(makeId(12, 16));
123  BOOST_TEST(ret != c.end());
124  BOOST_TEST(ret->id == makeId(12, 16));
125  }
126  // find non-existing volume, which has only lower hierarchy elements
127  BOOST_TEST(c.find(makeId(12)) == c.end());
128 
129  // find non-existing sensitive, which has no higher hierarchy set
130  BOOST_TEST(c.find(makeId(3, 5, 7)) == c.end());
131  // find non-existing layer, which has no higher hierarchy set
132  BOOST_TEST(c.find(makeId(3, 5)) == c.end());
133  // find non-existing volume
134  BOOST_TEST(c.find(makeId(3)) == c.end());
135 }
136 
137 BOOST_AUTO_TEST_SUITE_END()