File indexing completed on 2026-07-26 08:22:01
0001
0002
0003
0004
0005
0006
0007
0008 #pragma once
0009
0010
0011 #include "traccc/definitions/qualifiers.hpp"
0012
0013
0014 #include <detray/definitions/algorithms.hpp>
0015 #include <detray/utils/invalid_values.hpp>
0016
0017
0018 #include <vecmem/containers/data/jagged_vector_buffer.hpp>
0019 #include <vecmem/containers/data/jagged_vector_view.hpp>
0020 #include <vecmem/containers/data/vector_buffer.hpp>
0021 #include <vecmem/containers/data/vector_view.hpp>
0022 #include <vecmem/containers/device_vector.hpp>
0023 #include <vecmem/containers/jagged_device_vector.hpp>
0024
0025
0026 #include <algorithm>
0027 #include <limits>
0028
0029 namespace traccc {
0030
0031
0032
0033
0034
0035
0036
0037
0038 template <template <typename...> class vector_t = vecmem::vector,
0039 template <typename...> class jagged_vector_t = vecmem::jagged_vector,
0040 template <typename, std::size_t> class array_t = std::array,
0041 typename value_t = unsigned int, bool kSORT = false,
0042 unsigned int kDIM = 1u>
0043 struct replace_populator {
0044 DETRAY_HOST_DEVICE
0045 explicit replace_populator(
0046 const value_t invalid = detray::detail::invalid_value<value_t>())
0047 : m_invalid(invalid) {}
0048
0049 value_t m_invalid;
0050
0051 using bare_value = value_t;
0052 using store_value = value_t;
0053 using serialized_storage = vector_t<store_value>;
0054
0055 using vector_view_type = vecmem::data::vector_view<store_value>;
0056 using const_vector_view_type = vecmem::data::vector_view<const store_value>;
0057 using vector_data_type = vecmem::data::vector_view<store_value>;
0058 using const_vector_data_type = vecmem::data::vector_view<const store_value>;
0059 using vector_buffer_type = vecmem::data::vector_buffer<store_value>;
0060 using buffer_size_type = typename vector_view_type::size_type;
0061
0062
0063
0064
0065
0066
0067 DETRAY_HOST_DEVICE
0068 void operator()(store_value &stored, bare_value &&bvalue) const {
0069 stored = std::move(bvalue);
0070 }
0071
0072
0073
0074
0075
0076
0077
0078 DETRAY_HOST_DEVICE
0079 vector_t<bare_value> sequence(store_value &stored) const {
0080 if (stored != m_invalid) {
0081 return {stored};
0082 }
0083 return {};
0084 }
0085
0086
0087
0088
0089
0090
0091
0092 DETRAY_HOST_DEVICE
0093 void shift(store_value &stored, const bare_value &offset) const {
0094 stored += offset;
0095 }
0096
0097
0098
0099 DETRAY_HOST_DEVICE
0100 store_value init() const { return m_invalid; }
0101 };
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114 template <template <typename...> class vector_t = vecmem::vector,
0115 template <typename...> class jagged_vector_t = vecmem::jagged_vector,
0116 template <typename, std::size_t> class array_t = std::array,
0117 typename value_t = unsigned int, bool kSORT = false,
0118 unsigned int kDIM = 1u>
0119 struct complete_populator {
0120 DETRAY_HOST_DEVICE
0121 explicit complete_populator(
0122 const value_t invalid = detray::detail::invalid_value<value_t>())
0123 : m_invalid(invalid) {}
0124
0125 value_t m_invalid;
0126
0127 using bare_value = value_t;
0128 using store_value = array_t<bare_value, kDIM>;
0129 using serialized_storage = vector_t<store_value>;
0130
0131 using vector_view_type = vecmem::data::vector_view<store_value>;
0132 using const_vector_view_type = vecmem::data::vector_view<const store_value>;
0133 using vector_data_type = vecmem::data::vector_view<store_value>;
0134 using const_vector_data_type = vecmem::data::vector_view<const store_value>;
0135 using vector_buffer_type = vecmem::data::vector_buffer<store_value>;
0136 using buffer_size_type = typename vector_view_type::size_type;
0137
0138
0139
0140
0141
0142
0143 DETRAY_HOST_DEVICE
0144 void operator()(store_value &stored, bare_value &&bvalue) const {
0145 for (auto &val : stored) {
0146 if (val == m_invalid) {
0147 val = std::move(bvalue);
0148 break;
0149 }
0150 }
0151 if constexpr (kSORT) {
0152 detray::sequential_sort(stored.begin(), stored.end());
0153 }
0154 }
0155
0156
0157
0158
0159
0160
0161
0162 DETRAY_HOST_DEVICE
0163 vector_t<bare_value> sequence(store_value &stored) const {
0164 vector_t<bare_value> s;
0165 s.reserve(kDIM);
0166 for (const auto &val : stored) {
0167 if (val != m_invalid) {
0168 s.push_back(val);
0169 }
0170 }
0171 return s;
0172 }
0173
0174
0175
0176
0177
0178
0179
0180 DETRAY_HOST_DEVICE
0181 void shift(store_value &stored, const bare_value &offset) const {
0182 std::ranges::for_each(stored, [&](auto &d) { d += offset; });
0183 }
0184
0185
0186
0187 DETRAY_HOST_DEVICE
0188 store_value init() const {
0189 store_value init_bin;
0190 for (auto &val : init_bin) {
0191 val = m_invalid;
0192 }
0193 return init_bin;
0194 }
0195 };
0196
0197
0198
0199
0200
0201
0202
0203
0204 template <template <typename...> class vector_t = vecmem::vector,
0205 template <typename...> class jagged_vector_t = vecmem::jagged_vector,
0206 template <typename, std::size_t> class array_t = std::array,
0207 typename value_t = unsigned int, bool kSORT = false,
0208 unsigned int kDIM = 1u>
0209 struct attach_populator {
0210 DETRAY_HOST_DEVICE
0211 explicit attach_populator(
0212 const value_t invalid = detray::detail::invalid_value<value_t>())
0213 : m_invalid(invalid) {}
0214
0215 value_t m_invalid;
0216
0217 using bare_value = value_t;
0218 using store_value = vector_t<bare_value>;
0219 using serialized_storage = jagged_vector_t<bare_value>;
0220
0221 using vector_view_type = vecmem::data::jagged_vector_view<bare_value>;
0222 using const_vector_view_type =
0223 vecmem::data::jagged_vector_view<const bare_value>;
0224 using vector_data_type = vecmem::data::jagged_vector_data<bare_value>;
0225 using const_vector_data_type =
0226 vecmem::data::jagged_vector_data<const bare_value>;
0227 using vector_buffer_type = vecmem::data::jagged_vector_buffer<bare_value>;
0228 using buffer_size_type = std::vector<typename vector_view_type::size_type>;
0229
0230
0231
0232
0233
0234
0235 DETRAY_HOST
0236 void operator()(store_value &stored, bare_value &&bvalue) const {
0237 stored.push_back(std::move(bvalue));
0238 if (kSORT) {
0239 std::ranges::sort(stored);
0240 }
0241 }
0242
0243
0244
0245
0246
0247
0248 #if defined(__CUDACC__)
0249 DETRAY_DEVICE
0250 void operator()(store_value stored, bare_value &&bvalue) const {
0251 stored.push_back(std::move(bvalue));
0252 }
0253 #endif
0254
0255
0256
0257
0258
0259
0260
0261 DETRAY_HOST_DEVICE
0262 vector_t<bare_value> sequence(store_value &stored) const { return stored; }
0263
0264
0265
0266
0267
0268
0269
0270 DETRAY_HOST_DEVICE
0271 void shift(store_value &stored, const bare_value &offset) const {
0272 std::ranges::for_each(stored, [&](auto &d) { d += offset; });
0273 }
0274
0275
0276
0277 DETRAY_HOST_DEVICE
0278 store_value init() const { return {}; }
0279 };
0280
0281 }