Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GeometryContainers.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file GeometryContainers.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-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 #pragma once
10 
16 
17 #include <algorithm>
18 #include <cassert>
19 #include <cstddef>
20 #include <iostream>
21 #include <utility>
22 
23 #include <boost/container/flat_map.hpp>
24 #include <boost/container/flat_set.hpp>
25 
26 namespace ActsExamples {
27 namespace detail {
28 
29 // extract the geometry identifier from a variety of types
31  // explicit geometry identifier are just forwarded
33  Acts::GeometryIdentifier geometryId) const {
34  return geometryId;
35  }
36  // encoded geometry ids are converted back to geometry identifiers.
38  Acts::GeometryIdentifier::Value encoded) const {
39  return Acts::GeometryIdentifier(encoded);
40  }
41  // support elements in map-like structures.
42  template <typename T>
44  const std::pair<Acts::GeometryIdentifier, T>& mapItem) const {
45  return mapItem.first;
46  }
47  // support elements that implement `.geometryId()`.
48  template <typename T>
49  inline auto operator()(const T& thing) const
50  -> decltype(thing.geometryId(), Acts::GeometryIdentifier()) {
51  return thing.geometryId();
52  }
53  // support reference_wrappers around such types as well
54  template <typename T>
55  inline auto operator()(std::reference_wrapper<T> thing) const
56  -> decltype(thing.get().geometryId(), Acts::GeometryIdentifier()) {
57  return thing.get().geometryId();
58  }
59 };
60 
62  // indicate that comparisons between keys and full objects are allowed.
63  using is_transparent = void;
64  // compare two elements using the automatic key extraction.
65  template <typename Left, typename Right>
66  constexpr bool operator()(Left&& lhs, Right&& rhs) const {
68  }
69 };
70 
71 } // namespace detail
72 
83 template <typename T>
84 using GeometryIdMultiset =
85  boost::container::flat_multiset<T, detail::CompareGeometryId>;
86 
100 template <typename T>
101 using GeometryIdMultimap =
103 
105 template <typename T>
109  auto cmp = Acts::GeometryIdentifier().setVolume(volume);
110  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
112  // WARNING overflows to volume==0 if the input volume is the last one
113  cmp = Acts::GeometryIdentifier().setVolume(volume + 1u);
114  // optimize search by using the lower bound as start point. also handles
115  // volume overflows since the geo id would be located before the start of
116  // the upper edge search window.
117  auto end =
118  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
119  return makeRange(beg, end);
120 }
121 
123 template <typename T>
126  return selectVolume(container, id.volume());
127 }
128 
130 template <typename T>
135  auto cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer);
136  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
138  // WARNING resets to layer==0 if the input layer is the last one
139  cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer + 1u);
140  // optimize search by using the lower bound as start point. also handles
141  // volume overflows since the geo id would be located before the start of
142  // the upper edge search window.
143  auto end =
144  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
145  return makeRange(beg, end);
146 }
147 
148 // Select all elements within the given layer.
149 template <typename T>
152  return selectLayer(container, id.volume(), id.layer());
153 }
154 
156 template <typename T>
159  // module is the lowest level and defines a single geometry id value
160  return makeRange(container.equal_range(geoId));
161 }
162 
164 template <typename T>
169  return selectModule(
170  container,
171  Acts::GeometryIdentifier().setVolume(volume).setLayer(layer).setSensitive(
172  module));
173 }
174 
191 template <typename T>
192 inline Range<typename GeometryIdMultiset<T>::const_iterator>
194  Acts::GeometryIdentifier geoId) {
195  assert((geoId.boundary() == 0u) and "Boundary component must be zero");
196  assert((geoId.approach() == 0u) and "Approach component must be zero");
197 
198  if (geoId.sensitive() != 0u) {
199  return selectModule(container, geoId);
200  } else if (geoId.layer() != 0u) {
201  return selectLayer(container, geoId);
202  } else if (geoId.volume() != 0u) {
203  return selectVolume(container, geoId);
204  } else {
205  return makeRange(container.begin(), container.end());
206  }
207 }
208 
210 template <typename T>
211 inline GroupBy<typename GeometryIdMultiset<T>::const_iterator,
212  detail::GeometryIdGetter>
214  return makeGroupBy(container, detail::GeometryIdGetter());
215 }
216 
221 template <typename T>
227 
228  // pointer to the container
229  const Container* container = nullptr;
230 };
231 
232 } // namespace ActsExamples