trout
Phlex-based reconstruction framework for the SHiP experiment.
Loading...
Searching...
No Matches
GeometryContainers.hpp
Go to the documentation of this file.
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9// Trimmed copy from the ACTS Examples framework: only GeometryIdMultiset,
10// its accessor, and selectModule are used here; the volume/layer selectors,
11// groupByModule, and the Athena id bimap were dropped.
12
13#pragma once
14
15#include "Acts/Geometry/GeometryIdentifier.hpp"
16#include "Acts/Utilities/PointerTraits.hpp"
17#include "Range.hpp"
18
19#include <boost/container/flat_set.hpp>
20#include <utility>
21
22namespace ActsExamples {
23namespace detail {
25template <typename ObjType>
26concept GeometryIdObj = requires(const ObjType& obj) {
27 { obj.geometryId() } -> std::same_as<Acts::GeometryIdentifier>;
28};
29
30template <typename ObjType>
32 Acts::PointerConcept<ObjType> && GeometryIdObj<typename Acts::RemovePointer<ObjType>::type>;
33
35template <typename ObjType>
36concept TimedObj = requires(const ObjType& obj) {
37 { obj.time() };
38};
39
40template <typename ObjType>
41concept TimedObjPtr =
42 Acts::PointerConcept<ObjType> && TimedObj<typename Acts::RemovePointer<ObjType>::type>;
43
44// extract the geometry identifier from a variety of types
46 // explicit geometry identifier are just forwarded
47 constexpr Acts::GeometryIdentifier operator()(Acts::GeometryIdentifier geometryId) const {
48 return geometryId;
49 }
50 // encoded geometry ids are converted back to geometry identifiers.
51 constexpr Acts::GeometryIdentifier operator()(Acts::GeometryIdentifier::Value encoded) const {
52 return Acts::GeometryIdentifier(encoded);
53 }
54 // support elements in map-like structures.
55 template <typename T>
56 constexpr Acts::GeometryIdentifier operator()(
57 const std::pair<Acts::GeometryIdentifier, T>& mapItem) const {
58 return mapItem.first;
59 }
60 // Support pointer to object that implement `.geometryId()`.
61 template <GeometryIdPtrObj T>
62 constexpr Acts::GeometryIdentifier operator()(const T& thing) const {
63 return thing->geometryId();
64 }
65 // support elements that implement `.geometryId()`.
66 template <GeometryIdObj T>
67 inline auto operator()(const T& thing) const {
68 return thing.geometryId();
69 }
70 // support reference_wrappers around such types as well
71 template <GeometryIdObj T>
72 inline auto operator()(std::reference_wrapper<T> thing) const
73 -> decltype(thing.get().geometryId(), Acts::GeometryIdentifier()) {
74 return thing.get().geometryId();
75 }
76};
77
79 // indicate that comparisons between keys and full objects are allowed.
80 using is_transparent = void;
81
83 template <TimedObj Left, TimedObj Right>
84 constexpr bool operator()(const Left& lhs, const Right& rhs) const {
85 const auto lId = GeometryIdGetter()(lhs);
86 const auto rId = GeometryIdGetter()(rhs);
87 if (lId == rId) {
88 return lhs.time() < rhs.time();
89 }
90 return lId < rId;
91 }
92 template <TimedObjPtr Left, TimedObjPtr Right>
93 constexpr bool operator()(const Left& lhs, const Right& rhs) const {
94 return (*this)(*lhs, *rhs);
95 }
96 // compare two elements using the automatic key extraction.
97 template <typename Left, typename Right>
98 constexpr bool operator()(Left&& lhs, Right&& rhs) const {
99 return GeometryIdGetter()(lhs) < GeometryIdGetter()(rhs);
100 }
101};
102
103} // namespace detail
104
115template <typename T>
116using GeometryIdMultiset = boost::container::flat_multiset<T, detail::CompareGeometryId>;
117
119template <typename T>
121 const GeometryIdMultiset<T>& container, Acts::GeometryIdentifier geoId) {
122 // module is the lowest level and defines a single geometry id value
123 return makeRange(container.equal_range(geoId));
124}
125
127template <typename T>
128inline auto selectModule(const GeometryIdMultiset<T>& container,
129 Acts::GeometryIdentifier::Value volume,
130 Acts::GeometryIdentifier::Value layer,
131 Acts::GeometryIdentifier::Value sensitive) {
132 return selectModule(
133 container,
134 Acts::GeometryIdentifier().withVolume(volume).withLayer(layer).withSensitive(sensitive));
135}
136
141template <typename T>
144 using Key = Acts::GeometryIdentifier;
147
148 // pointer to the container
149 const Container* container = nullptr;
150};
151
152} // namespace ActsExamples
A wrapper around a pair of iterators to simplify range-based loops.
Definition Range.hpp:27
Concept to define objects that have a geometryId getter method.
Definition GeometryContainers.hpp:26
Concept to define objects to pointer that have a geometryId getter method.
Definition GeometryContainers.hpp:31
Concept to define a pointer to an object which carries time.
Definition GeometryContainers.hpp:41
Concept to define an object which carries time.
Definition GeometryContainers.hpp:36
Definition GeometryContainers.hpp:23
Definition GeometryContainers.hpp:22
Range< typename GeometryIdMultiset< T >::const_iterator > selectModule(const GeometryIdMultiset< T > &container, Acts::GeometryIdentifier geoId)
Select all elements for the given module / sensitive surface.
Definition GeometryContainers.hpp:120
boost::container::flat_multiset< T, detail::CompareGeometryId > GeometryIdMultiset
Store elements that know their detector geometry id, e.g.
Definition GeometryContainers.hpp:116
Range< Iterator > makeRange(const Iterator &begin, const Iterator &end)
Definition Range.hpp:46
The accessor for the GeometryIdMultiset container.
Definition GeometryContainers.hpp:142
typename GeometryIdMultiset< T >::value_type Value
Definition GeometryContainers.hpp:145
Acts::GeometryIdentifier Key
Definition GeometryContainers.hpp:144
typename GeometryIdMultiset< T >::const_iterator Iterator
Definition GeometryContainers.hpp:146
const Container * container
Definition GeometryContainers.hpp:149
GeometryIdMultiset< T > Container
Definition GeometryContainers.hpp:143
Definition GeometryContainers.hpp:78
constexpr bool operator()(const Left &lhs, const Right &rhs) const
Comparator that sorts objects with the same geometry id by time.
Definition GeometryContainers.hpp:84
constexpr bool operator()(Left &&lhs, Right &&rhs) const
Definition GeometryContainers.hpp:98
void is_transparent
Definition GeometryContainers.hpp:80
Definition GeometryContainers.hpp:45
constexpr Acts::GeometryIdentifier operator()(Acts::GeometryIdentifier geometryId) const
Definition GeometryContainers.hpp:47
constexpr Acts::GeometryIdentifier operator()(const std::pair< Acts::GeometryIdentifier, T > &mapItem) const
Definition GeometryContainers.hpp:56
auto operator()(const T &thing) const
Definition GeometryContainers.hpp:67
constexpr Acts::GeometryIdentifier operator()(Acts::GeometryIdentifier::Value encoded) const
Definition GeometryContainers.hpp:51
constexpr Acts::GeometryIdentifier operator()(const T &thing) const
Definition GeometryContainers.hpp:62
auto operator()(std::reference_wrapper< T > thing) const -> decltype(thing.get().geometryId(), Acts::GeometryIdentifier())
Definition GeometryContainers.hpp:72