EIC 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 
14 
15 #include <algorithm>
16 #include <cstddef>
17 #include <utility>
18 
19 #include <boost/container/flat_map.hpp>
20 #include <boost/container/flat_set.hpp>
21 
22 namespace ActsExamples {
23 namespace detail {
24 // extract the geometry identifier from a variety of types
26  // explicit geometry identifier are just forwarded
28  Acts::GeometryIdentifier geometryId) const {
29  return geometryId;
30  }
31  // encoded geometry ids are converted back to geometry identifiers.
33  Acts::GeometryIdentifier::Value encoded) const {
34  return Acts::GeometryIdentifier(encoded);
35  }
36  // support elements in map-like structures.
37  template <typename T>
39  const std::pair<Acts::GeometryIdentifier, T>& mapItem) const {
40  return mapItem.first;
41  }
42  // support elements that implement `.geometryId()`.
43  template <typename T>
44  inline auto operator()(const T& thing) const
45  -> decltype(thing.geometryId(), Acts::GeometryIdentifier()) {
46  return thing.geometryId();
47  }
48 };
49 
51  // indicate that comparisons between keys and full objects are allowed.
53  // compare two elements using the automatic key extraction.
54  template <typename Left, typename Right>
55  constexpr bool operator()(Left&& lhs, Right&& rhs) const {
56  return GeometryIdGetter()(lhs) < GeometryIdGetter()(rhs);
57  }
58 };
59 } // namespace detail
60 
71 template <typename T>
72 using GeometryIdMultiset =
73  boost::container::flat_multiset<T, detail::CompareGeometryId>;
74 
88 template <typename T>
89 using GeometryIdMultimap =
91 
93 template <typename T>
95  const GeometryIdMultiset<T>& container,
97  auto cmp = Acts::GeometryIdentifier().setVolume(volume);
98  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
100  // WARNING overflows to volume==0 if the input volume is the last one
101  cmp = Acts::GeometryIdentifier().setVolume(volume + 1u);
102  // optimize search by using the lower bound as start point. also handles
103  // volume overflows since the geo id would be located before the start of
104  // the upper edge search window.
105  auto end =
106  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
107  return makeRange(beg, end);
108 }
109 template <typename T>
110 inline auto selectVolume(const GeometryIdMultiset<T>& container,
112  return selectVolume(container, id.volume());
113 }
114 
116 template <typename T>
118  const GeometryIdMultiset<T>& container,
121  auto cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer);
122  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
124  // WARNING resets to layer==0 if the input layer is the last one
125  cmp = Acts::GeometryIdentifier().setVolume(volume).setLayer(layer + 1u);
126  // optimize search by using the lower bound as start point. also handles
127  // volume overflows since the geo id would be located before the start of
128  // the upper edge search window.
129  auto end =
130  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
131  return makeRange(beg, end);
132 }
133 template <typename T>
134 inline auto selectLayer(const GeometryIdMultiset<T>& container,
136  return selectLayer(container, id.volume(), id.layer());
137 }
138 
140 template <typename T>
142  const GeometryIdMultiset<T>& container, Acts::GeometryIdentifier geoId) {
143  // module is the lowest level and defines a single geometry id value
144  return makeRange(container.equal_range(geoId));
145 }
146 template <typename T>
147 inline auto selectModule(const GeometryIdMultiset<T>& container,
151  return selectModule(
152  container,
153  Acts::GeometryIdentifier().setVolume(volume).setLayer(layer).setSensitive(
154  module));
155 }
156 
158 template <typename T>
159 inline GroupBy<typename GeometryIdMultiset<T>::const_iterator,
160  detail::GeometryIdGetter>
162  return makeGroupBy(container, detail::GeometryIdGetter());
163 }
164 
165 } // namespace ActsExamples