ECCE @ 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 
11 #include <algorithm>
12 #include <boost/container/flat_map.hpp>
13 #include <boost/container/flat_set.hpp>
14 #include <cstddef>
15 #include <utility>
16 
20 
21 namespace FW {
22 namespace detail {
23 // extract the geometry identifier from a variety of types
25  // explicit geometry identifier are just forwarded
26  constexpr Acts::GeometryID operator()(Acts::GeometryID geometryId) const {
27  return geometryId;
28  }
29  // encoded geometry ids are converted back to geometry identifiers.
31  return Acts::GeometryID(encoded);
32  }
33  // support elements in map-like structures.
34  template <typename T>
36  const std::pair<Acts::GeometryID, T>& mapItem) const {
37  return mapItem.first;
38  }
39  // support elements that implement `.geometryId()`.
40  template <typename T>
41  inline auto operator()(const T& thing) const
42  -> decltype(thing.geometryId(), Acts::GeometryID()) {
43  return thing.geometryId();
44  }
45 };
46 
48  // indicate that comparisons between keys and full objects are allowed.
50  // compare two elements using the automatic key extraction.
51  template <typename Left, typename Right>
52  constexpr bool operator()(Left&& lhs, Right&& rhs) const {
53  return GeometryIdGetter()(lhs) < GeometryIdGetter()(rhs);
54  }
55 };
56 } // namespace detail
57 
68 template <typename T>
69 using GeometryIdMultiset =
70  boost::container::flat_multiset<T, detail::CompareGeometryId>;
71 
85 template <typename T>
87 
89 template <typename T>
92  auto cmp = Acts::GeometryID().setVolume(volume);
93  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
95  // WARNING overflows to volume==0 if the input volume is the last one
96  cmp = Acts::GeometryID().setVolume(volume + 1u);
97  // optimize search by using the lower bound as start point. also handles
98  // volume overflows since the geo id would be located before the start of
99  // the upper edge search window.
100  auto end =
101  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
102  return makeRange(beg, end);
103 }
104 template <typename T>
105 inline auto selectVolume(const GeometryIdMultiset<T>& container,
106  Acts::GeometryID id) {
107  return selectVolume(container, id.volume());
108 }
109 
111 template <typename T>
115  auto cmp = Acts::GeometryID().setVolume(volume).setLayer(layer);
116  auto beg = std::lower_bound(container.begin(), container.end(), cmp,
118  // WARNING resets to layer==0 if the input layer is the last one
119  cmp = Acts::GeometryID().setVolume(volume).setLayer(layer + 1u);
120  // optimize search by using the lower bound as start point. also handles
121  // volume overflows since the geo id would be located before the start of
122  // the upper edge search window.
123  auto end =
124  std::lower_bound(beg, container.end(), cmp, detail::CompareGeometryId{});
125  return makeRange(beg, end);
126 }
127 template <typename T>
128 inline auto selectLayer(const GeometryIdMultiset<T>& container,
129  Acts::GeometryID id) {
130  return selectLayer(container, id.volume(), id.layer());
131 }
132 
134 template <typename T>
136  const GeometryIdMultiset<T>& container, Acts::GeometryID geoId) {
137  // module is the lowest level and defines a single geometry id value
138  return makeRange(container.equal_range(geoId));
139 }
140 template <typename T>
141 inline auto selectModule(const GeometryIdMultiset<T>& container,
144  Acts::GeometryID::Value module) {
145  return selectModule(
146  container,
147  Acts::GeometryID().setVolume(volume).setLayer(layer).setSensitive(
148  module));
149 }
150 
152 template <typename T>
153 inline GroupBy<typename GeometryIdMultiset<T>::const_iterator,
154  detail::GeometryIdGetter>
156  return makeGroupBy(container, detail::GeometryIdGetter());
157 }
158 
159 } // namespace FW