ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
brute_force.hpp
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#pragma once
10
11// Detray include(s).
12#include "detray/core/concepts.hpp"
13#include "detray/core/detail/container_buffers.hpp"
14#include "detray/core/detail/container_views.hpp"
15#include "detray/definitions/algorithms.hpp"
16#include "detray/definitions/containers.hpp"
17#include "detray/definitions/detail/qualifiers.hpp"
18#include "detray/definitions/indexing.hpp"
19#include "detray/navigation/accelerators/search_window.hpp"
20#include "detray/utils/logging.hpp"
21#include "detray/utils/ranges.hpp"
22
23// VecMem include(s).
24#include <vecmem/memory/memory_resource.hpp>
25
26// System include(s)
27#include <type_traits>
28
29namespace detray {
30
37template <class value_t, typename container_t = host_container_types>
39 public:
41 template <typename T>
42 using vector_type = typename container_t::template vector_type<T>;
45
50 : public detray::ranges::subrange<const vector_type<value_t>> {
54 using value_type = value_t;
56 using query_type = bool;
57
59 brute_forcer() = default;
60
64 DETRAY_HOST_DEVICE constexpr brute_forcer(
65 const vector_type<value_t>& surfaces, const dindex_range& range)
66 : base(surfaces, range) {}
67
69 DETRAY_HOST_DEVICE constexpr auto search(query_type /*p*/) const {
70 return *this;
71 }
72
74 template <concepts::arithmetic window_size_t>
75 DETRAY_HOST_DEVICE constexpr auto search(
76 query_type /*p*/, search_window<window_size_t, 2> /*win_size*/) const {
77 return *this;
78 }
79
81 template <concepts::detector detector_t, typename track_t,
82 concepts::arithmetic window_size_t>
83 DETRAY_HOST_DEVICE constexpr auto search(
84 const detector_t& /*det*/,
85 const typename detector_t::volume_type& /*volume*/,
86 const track_t& /*track*/,
87 const search_window<window_size_t, 2>& /*win_size*/,
88 const typename detector_t::geometry_context& /*ctx*/) const {
89 DETRAY_DEBUG_HOST("Brute force search...");
90 return *this;
91 }
92
96 DETRAY_HOST_DEVICE constexpr value_t at(const dindex i) const {
97 return (*this)[i];
98 }
99
102 DETRAY_HOST_DEVICE constexpr value_t& at(const dindex i) {
103 return (*this)[i];
104 }
105
107 DETRAY_HOST_DEVICE constexpr auto all() const { return *this; }
108
110 DETRAY_HOST_DEVICE auto all() { return *this; }
111
113 DETRAY_HOST
114 friend std::ostream& operator<<(std::ostream& os, const brute_forcer& bf) {
115 for (const auto& entry : bf.all()) {
116 os << entry << std::endl;
117 }
118
119 return os;
120 }
121 };
122
125
127 using view_type = dmulti_view<dvector_view<size_type>, dvector_view<value_t>>;
130 dmulti_view<dvector_view<const size_type>, dvector_view<const value_t>>;
133 dmulti_buffer<dvector_buffer<size_type>, dvector_buffer<value_t>>;
134
137 // Start of first subrange
138 m_offsets.push_back(0u);
139 };
140
143 DETRAY_HOST
144 explicit constexpr brute_force_collection(vecmem::memory_resource* resource)
145 : m_offsets(resource), m_surfaces(resource) {
146 // Start of first subrange
147 m_offsets.push_back(0u);
148 }
149
152 DETRAY_HOST
153 explicit constexpr brute_force_collection(vecmem::memory_resource& resource)
154 : brute_force_collection(&resource) {}
155
158 template <concepts::device_view coll_view_t>
159 DETRAY_HOST_DEVICE explicit brute_force_collection(coll_view_t& view)
160 : m_offsets(detail::get<0>(view.m_view)),
161 m_surfaces(detail::get<1>(view.m_view)) {}
162
164 DETRAY_HOST const auto& offsets() const { return m_offsets; }
165
167 DETRAY_HOST auto& offsets() { return m_offsets; }
168
170 DETRAY_HOST_DEVICE
171 constexpr auto size() const noexcept -> size_type {
172 // The start index of the first range is always present
173 return static_cast<dindex>(m_offsets.size()) - 1u;
174 }
175
177 DETRAY_HOST_DEVICE
178 constexpr auto empty() const noexcept -> bool {
179 return size() == size_type{0};
180 }
181
183 DETRAY_HOST_DEVICE
184 auto all() const -> const vector_type<value_t>& { return m_surfaces; }
185
187 DETRAY_HOST_DEVICE
188 auto all() -> vector_type<value_t>& { return m_surfaces; }
189
193 DETRAY_HOST_DEVICE
194 auto operator[](const size_type i) const -> value_type {
195 return {m_surfaces, dindex_range{m_offsets[i], m_offsets[i + 1u]}};
196 }
197
201 DETRAY_HOST_DEVICE
202 auto operator[](const size_type i) -> value_type {
203 return {m_surfaces, dindex_range{m_offsets[i], m_offsets[i + 1u]}};
204 }
205
208 template <detray::ranges::range sf_container_t>
209 requires std::is_same_v<typename sf_container_t::value_type, value_t>
210 DETRAY_HOST auto push_back(const sf_container_t& surfaces) noexcept(false)
211 -> void {
212 m_surfaces.reserve(m_surfaces.size() + surfaces.size());
213 m_surfaces.insert(m_surfaces.end(), surfaces.begin(), surfaces.end());
214 // End of this range is the start of the next range
215 m_offsets.push_back(static_cast<dindex>(m_surfaces.size()));
216 }
217
221 DETRAY_HOST auto erase(typename vector_type<value_t>::iterator pos) noexcept(
222 false) {
223 // Remove one element
224 auto next = m_surfaces.erase(pos);
225
226 // Update the upper bound of the range and all following ranges
227 const auto idx{static_cast<std::size_t>(pos - m_surfaces.begin())};
228 auto offset = detray::upper_bound(m_offsets.begin(), m_offsets.end(), idx);
229 for (auto itr = offset; itr != m_offsets.end(); ++itr) {
230 --(*itr);
231 }
232
233 return next;
234 }
235
237 DETRAY_HOST
238 constexpr auto get_data() noexcept -> view_type {
239 return view_type{detray::get_data(m_offsets), detray::get_data(m_surfaces)};
240 }
241
243 DETRAY_HOST
244 constexpr auto get_data() const noexcept -> const_view_type {
245 return const_view_type{detray::get_data(m_offsets),
246 detray::get_data(m_surfaces)};
247 }
248
249 private:
251 vector_type<size_type> m_offsets{};
253 vector_type<value_t> m_surfaces{};
254};
255
256} // namespace detray
auto operator[](const size_type i) -> value_type
Create brute force surface finder from surface container - const.
Definition brute_force.hpp:202
brute_forcer value_type
Query result representing a volume's brute-force surface range.
Definition brute_force.hpp:124
dmulti_view< dvector_view< const size_type >, dvector_view< const value_t > > const_view_type
Const view type for offsets and stored surface descriptors.
Definition brute_force.hpp:129
dmulti_buffer< dvector_buffer< size_type >, dvector_buffer< value_t > > buffer_type
Buffer type used to transfer offsets and stored descriptors.
Definition brute_force.hpp:132
constexpr brute_force_collection(vecmem::memory_resource &resource)
Constructor from memory resource.
Definition brute_force.hpp:153
constexpr brute_force_collection()
Default constructor.
Definition brute_force.hpp:136
auto erase(typename vector_type< value_t >::iterator pos) noexcept(false)
Remove surface from collection.
Definition brute_force.hpp:221
constexpr auto get_data() const noexcept -> const_view_type
Definition brute_force.hpp:244
constexpr auto empty() const noexcept -> bool
Definition brute_force.hpp:178
auto operator[](const size_type i) const -> value_type
Create brute force surface finder from surface container - const.
Definition brute_force.hpp:194
auto & offsets()
Definition brute_force.hpp:167
auto push_back(const sf_container_t &surfaces) noexcept(false) -> void
Add a new surface collection.
Definition brute_force.hpp:210
const auto & offsets() const
Definition brute_force.hpp:164
brute_force_collection(coll_view_t &view)
Device-side construction from a vecmem based view type.
Definition brute_force.hpp:159
auto all() -> vector_type< value_t > &
Definition brute_force.hpp:188
auto all() const -> const vector_type< value_t > &
Definition brute_force.hpp:184
typename container_t::template vector_type< T > vector_type
Device/host vector type used to store values.
Definition brute_force.hpp:42
constexpr auto get_data() noexcept -> view_type
Definition brute_force.hpp:238
dindex size_type
Index type used for collection sizes and volume slots.
Definition brute_force.hpp:44
dmulti_view< dvector_view< size_type >, dvector_view< value_t > > view_type
View type for offsets and stored surface descriptors.
Definition brute_force.hpp:127
constexpr brute_force_collection(vecmem::memory_resource *resource)
Constructor from memory resource.
Definition brute_force.hpp:144
constexpr auto size() const noexcept -> size_type
Definition brute_force.hpp:171
Arithmetic types.
Definition concepts.hpp:21
Check if a type can be used as a detector.
Definition concepts.hpp:47
Detray include(s).
Definition array_operators.hpp:18
detail::index_range< dindex > dindex_range
Index ranges and sequences.
Definition indexing.hpp:24
unsigned int dindex
Default index type.
Definition indexing.hpp:18
darray< window_size_t, DIM > search_window
Size around a query point for which to do the search in an acceleration structure.
Definition search_window.hpp:24
const auto & get(const detray::tuple< Ts... > &t) noexcept
Get a tuple element by index from a const tuple.
Definition tuple.hpp:152
auto upper_bound(forw_iter_t first, sentinel_t last, const Value &value)
upper_bound implementation for host/device
Definition algorithms.hpp:88
A nested surface finder that returns all surfaces in a range (brute force).
Definition brute_force.hpp:50
auto all()
Definition brute_force.hpp:110
constexpr brute_forcer(const vector_type< value_t > &surfaces, const dindex_range &range)
Construct a range over the surfaces belonging to one volume.
Definition brute_force.hpp:64
friend std::ostream & operator<<(std::ostream &os, const brute_forcer &bf)
Definition brute_force.hpp:114
constexpr auto search(const detector_t &, const typename detector_t::volume_type &, const track_t &, const search_window< window_size_t, 2 > &, const typename detector_t::geometry_context &) const
Definition brute_force.hpp:83
brute_forcer()=default
Default constructor.
bool query_type
Query value accepted by the brute-force search interface.
Definition brute_force.hpp:56
constexpr value_t & at(const dindex i)
Return a mutable surface at a position in this volume's range.
Definition brute_force.hpp:102
constexpr value_t at(const dindex i) const
Return the surface at a position in this volume's range.
Definition brute_force.hpp:96
constexpr auto search(query_type) const
Definition brute_force.hpp:69
constexpr auto search(query_type, search_window< window_size_t, 2 >) const
Definition brute_force.hpp:75
value_t value_type
Surface descriptor stored in the collection.
Definition brute_force.hpp:54
constexpr auto all() const
Definition brute_force.hpp:107
detray::ranges::subrange< const vector_type< value_t > > base
Range base providing iteration over the selected surfaces.
Definition brute_force.hpp:52
interface type to construct a subrange_view with CTAD
Definition subrange.hpp:90