12#include "detray/definitions/detail/qualifiers.hpp"
13#include "detray/utils/grid/concepts.hpp"
14#include "detray/utils/grid/grid.hpp"
17#include <vecmem/memory/memory_resource.hpp>
30template <concepts::gr
id gr
id_t,
typename =
void>
34template <
typename axes_t,
typename bin_t,
35 template <std::
size_t>
class serializer_t>
53 typename multi_axis_t::edge_offset_container_type;
63 using difference_type = std::ptrdiff_t;
65 using pointer = grid_t *;
66 using reference = grid_t &;
67 using iterator_category = detray::ranges::bidirectional_iterator_tag;
72 : m_i{i}, m_grid_coll{grid_coll} {}
74 constexpr iterator(
const iterator &other) =
default;
75 constexpr iterator(iterator &&other)
noexcept =
default;
76 constexpr iterator &
operator=(
const iterator &rhs)
noexcept =
default;
80 constexpr auto operator==(
const iterator &rhs)
const ->
bool {
81 return (m_i == rhs.m_i);
86 constexpr auto operator++() -> iterator & {
93 constexpr auto operator--() -> iterator & {
113 detail::get_view_t<bin_container_type>,
114 detail::get_view_t<edge_offset_container_type>,
115 detail::get_view_t<edges_container_type>>;
119 dmulti_view<dvector_view<const size_type>,
120 detail::get_view_t<const bin_container_type>,
121 detail::get_view_t<const edge_offset_container_type>,
122 detail::get_view_t<const edges_container_type>>;
126 dmulti_buffer<dvector_buffer<size_type>,
127 detail::get_buffer_t<bin_container_type>,
128 detail::get_buffer_t<edge_offset_container_type>,
129 detail::get_buffer_t<edges_container_type>>;
138 : m_bin_offsets(resource),
140 m_bin_edge_offsets(resource),
141 m_bin_edges(resource) {}
152 : m_bin_offsets(std::move(offs)),
153 m_bins(std::move(bins)),
154 m_bin_edge_offsets(std::move(edge_offs)),
155 m_bin_edges(std::move(edges)) {}
159 template <concepts::device_view coll_view_t>
161 : m_bin_offsets(detail::
get<0>(view.m_view)),
162 m_bins(detail::
get<1>(view.m_view)),
163 m_bin_edge_offsets(detail::
get<2>(view.m_view)),
164 m_bin_edges(detail::
get<3>(view.m_view)) {}
169 : m_bin_offsets(std::move(other.m_bin_offsets)),
170 m_bins(std::move(other.m_bins)),
171 m_bin_edge_offsets(std::move(other.m_bin_edge_offsets)),
172 m_bin_edges(std::move(other.m_bin_edges)) {}
179 if (
this != &other) {
180 m_bin_offsets = std::move(other.m_bin_offsets);
181 m_bins = std::move(other.m_bins);
182 m_bin_edge_offsets = std::move(other.m_bin_edge_offsets);
183 m_bin_edges = std::move(other.m_bin_edges);
191 return static_cast<dindex>(m_bin_offsets.size());
196 constexpr auto begin()
const {
return iterator{*
this, 0u}; }
200 constexpr auto end()
const {
return iterator{*
this,
size()}; }
204 constexpr auto empty() const noexcept ->
bool {
205 return m_bin_offsets.empty();
211 constexpr void resize(std::size_t )
noexcept { }
216 constexpr void reserve(std::size_t )
noexcept { }
221 m_bin_offsets.clear();
223 m_bin_edge_offsets.clear();
229 template <
typename... Args>
230 DETRAY_HOST_DEVICE
constexpr void insert(Args &&...) noexcept {
237 return m_bin_offsets;
249 return m_bin_edge_offsets;
264 return grid_t(&m_bins,
265 multi_axis_t(m_bin_edge_offsets, m_bin_edges, axes_offset),
275 return grid_t(&m_bins,
276 multi_axis_t(m_bin_edge_offsets, m_bin_edges, axes_offset),
277 m_bin_offsets.at(i));
282 return view_type{detray::get_data(m_bin_offsets), detray::get_data(m_bins),
283 detray::get_data(m_bin_edge_offsets),
284 detray::get_data(m_bin_edges)};
291 detray::get_data(m_bin_offsets), detray::get_data(m_bins),
292 detray::get_data(m_bin_edge_offsets), detray::get_data(m_bin_edges)};
297 template <
typename other_gr
id_t>
298 requires std::constructible_from<typename grid_t::template type<true>,
300 DETRAY_HOST
constexpr auto push_back(
const other_grid_t &gr)
noexcept(
false)
303 m_bin_offsets.push_back(
static_cast<size_type>(m_bins.size()));
306 insert_bin_data(m_bins, gr.bins());
310 const auto &bin_edge_offsets = gr.axes().bin_edge_offsets();
311 m_bin_edge_offsets.insert(m_bin_edge_offsets.end(),
312 bin_edge_offsets.begin(), bin_edge_offsets.end());
315 auto bin_edges_offset{
static_cast<dindex>(m_bin_edges.size())};
318 const auto start_idx{m_bin_edge_offsets.size() -
grid_t::dim};
319 for (std::size_t i = start_idx; i < m_bin_edge_offsets.size(); ++i) {
320 auto &bin_entry_range = m_bin_edge_offsets.at(i);
321 bin_entry_range.shift(bin_edges_offset);
325 const auto &bin_edges = gr.axes().bin_edges();
326 m_bin_edges.insert(m_bin_edges.end(), bin_edges.begin(), bin_edges.end());
331 DETRAY_HOST
void insert_bin_data(
332 vector_type<typename grid_t::bin_type> &bin_data,
333 const typename grid_t::template type<true>::bin_storage &grid_bins) {
334 bin_data.insert(bin_data.end(), grid_bins.begin(), grid_bins.end());
339 template <
typename container_t>
340 DETRAY_HOST
void insert_bin_data(
341 detray::detail::dynamic_bin_container<bin_t, container_t> &bin_data,
342 const grid_t::template type<true>::bin_storage &grid_bins) {
343 bin_data.append(grid_bins);
347 vector_type<size_type> m_bin_offsets{};
349 bin_container_type m_bins{};
351 edge_offset_container_type m_bin_edge_offsets{};
353 edges_container_type m_bin_edges{};
constexpr auto offsets() const -> const vector_type< size_type > &
Definition grid_collection.hpp:236
auto get_data() -> view_type
Definition grid_collection.hpp:281
dmulti_view< dvector_view< size_type >, detail::get_view_t< bin_container_type >, detail::get_view_t< edge_offset_container_type >, detail::get_view_t< edges_container_type > > view_type
Vecmem based grid collection view type.
Definition grid_collection.hpp:112
auto get_data() const -> const_view_type
Definition grid_collection.hpp:289
grid_collection()=default
Make grid collection default constructible: Empty.
constexpr auto size() const noexcept -> dindex
Definition grid_collection.hpp:190
typename multi_axis_t::edges_container_type edges_container_type
Contains all bin edges for all axes.
Definition grid_collection.hpp:55
constexpr auto empty() const noexcept -> bool
Definition grid_collection.hpp:204
grid_collection(coll_view_t &view)
Device-side construction from a vecmem based view type.
Definition grid_collection.hpp:160
typename multi_axis_t::edge_offset_container_type edge_offset_container_type
Offsets into the bin edges container.
Definition grid_collection.hpp:52
grid_collection & operator=(grid_collection &&other) noexcept
Move assignment.
Definition grid_collection.hpp:177
auto operator[](const size_type i) const -> grid_t
Create grid from container pointers - const.
Definition grid_collection.hpp:262
typename grid_t::bin_container_type bin_container_type
Backend storage type for the grid.
Definition grid_collection.hpp:50
constexpr auto axes_storage() const -> const edge_offset_container_type &
Definition grid_collection.hpp:248
grid_collection(vector_type< size_type > &&offs, bin_container_type &&bins, edge_offset_container_type &&edge_offs, edges_container_type &&edges)
Create grid collection from existing data - move.
Definition grid_collection.hpp:149
constexpr void resize(std::size_t) noexcept
Resize the underlying containers.
Definition grid_collection.hpp:211
constexpr auto bin_storage() const -> const bin_container_type &
Definition grid_collection.hpp:242
constexpr auto push_back(const other_grid_t &gr) noexcept(false) -> void
Add a new grid.
Definition grid_collection.hpp:300
constexpr void clear() noexcept
Removes all data from the grid collection containers.
Definition grid_collection.hpp:220
grid_t value_type
Non-owning grid type stored in the collection.
Definition grid_collection.hpp:45
grid_collection(grid_collection &&other) noexcept
Move constructor.
Definition grid_collection.hpp:168
grid_collection(vecmem::memory_resource *resource)
Create empty grid collection from specific vecmem memory resource.
Definition grid_collection.hpp:137
constexpr auto bin_edges_storage() const -> const edges_container_type &
Definition grid_collection.hpp:254
constexpr auto end() const
Definition grid_collection.hpp:200
constexpr void reserve(std::size_t) noexcept
Reserve memory.
Definition grid_collection.hpp:216
dindex size_type
Index type used to address collection elements.
Definition grid_collection.hpp:47
dmulti_buffer< dvector_buffer< size_type >, detail::get_buffer_t< bin_container_type >, detail::get_buffer_t< edge_offset_container_type >, detail::get_buffer_t< edges_container_type > > buffer_type
Vecmem based buffer type.
Definition grid_collection.hpp:125
auto at(const size_type i) const -> grid_t
Create grid from container pointers with range check.
Definition grid_collection.hpp:273
constexpr void insert(Args &&...) noexcept
Insert a number of grids.
Definition grid_collection.hpp:230
typename multi_axis_t::template vector_type< T > vector_type
Container type used for vectors of type T in this collection.
Definition grid_collection.hpp:58
dmulti_view< dvector_view< const size_type >, detail::get_view_t< const bin_container_type >, detail::get_view_t< const edge_offset_container_type >, detail::get_view_t< const edges_container_type > > const_view_type
Vecmem based grid collection view type.
Definition grid_collection.hpp:118
constexpr auto begin() const
Definition grid_collection.hpp:196
A collection of grids that can be moved to device as part of the detector.
Definition grid_collection.hpp:31
An N-dimensional grid for object storage.
Definition grid.hpp:38
typename bin_storage::bin_container_type bin_container_type
Definition grid.hpp:76
axes_t axes_type
Definition grid.hpp:54
static constexpr bool is_owning
Whether this grid owns its axis and bin storage.
Definition grid.hpp:69
static constexpr unsigned int dim
Definition grid.hpp:41
Detray include(s).
Definition array_operators.hpp:18
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr array_t< scalar1_t, 2 > operator*(const array_t< scalar1_t, 2 > &a, scalar2_t s)
Multiply an array-backed vector by a scalar.
Definition array_operators.hpp:26
const auto & get(const detray::tuple< Ts... > &t) noexcept
Get a tuple element by index from a const tuple.
Definition tuple.hpp:152
constexpr bool operator==(const Fastor::Tensor< S, N > &lhs, const Fastor::Tensor< S, N > &rhs)
Compare two Fastor vectors component-wise for exact equality.
Definition fastor.hpp:35