Skip to content

Commit 943a687

Browse files
committed
Implement mapped type registry
1 parent 51bb810 commit 943a687

File tree

27 files changed

+765
-153
lines changed

27 files changed

+765
-153
lines changed

core/include/detray/builders/homogeneous_material_builder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class homogeneous_material_builder final : public volume_decorator<detector_t> {
103103
sf.update_material(offset);
104104
DETRAY_DEBUG_HOST("-> material now: " << sf.material());
105105
}
106-
if constexpr (detector_t::materials::template is_defined<
106+
if constexpr (detector_t::materials::template contains<
107107
material_rod<scalar_type>>()) {
108108
if (sf.material().id() == material_id::e_rod) {
109109
DETRAY_DEBUG_HOST(
@@ -120,7 +120,7 @@ class homogeneous_material_builder final : public volume_decorator<detector_t> {
120120
<< m_materials.template size<material_id::e_slab>()
121121
<< " slabs into detector materials");
122122

123-
if constexpr (detector_t::materials::template is_defined<
123+
if constexpr (detector_t::materials::template contains<
124124
material_rod<scalar_type>>()) {
125125
DETRAY_DEBUG_HOST("-> Appending "
126126
<< m_materials.template size<material_id::e_rod>()

core/include/detray/builders/homogeneous_material_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ class homogeneous_material_factory final
359359
mat_idx = this->insert_in_container(mat_coll, mat_slab,
360360
m_links.at(sf_idx).second);
361361
}
362-
if constexpr (detector_t::materials::template is_defined<
362+
if constexpr (detector_t::materials::template contains<
363363
material_rod<scalar_type>>()) {
364364
if (m_links.at(sf_idx).first == material_id::e_rod) {
365365
auto &mat_coll =

core/include/detray/builders/homogeneous_material_generator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class homogeneous_material_generator final
184184
bool is_line{false};
185185
link_t mat_link;
186186

187-
if constexpr (detector_t::materials::template is_defined<
187+
if constexpr (detector_t::materials::template contains<
188188
material_rod<scalar_t>>()) {
189189

190190
using mask_id = typename detector_t::masks::id;

core/include/detray/builders/material_map_builder.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,8 @@ struct add_sf_material_map {
325325
typename decltype(mat_grid)::template type<false>;
326326

327327
// Not every mask shape might be used for material maps
328-
if constexpr (materials_t::template is_defined<non_owning_t>()) {
328+
if constexpr (materials_t::template contains<non_owning_t>()) {
329329
DETRAY_VERBOSE_HOST("Filling material grid...");
330-
331330
// Add the material slabs to the grid
332331
for (const auto& bin : bin_data) {
333332
mat_grid.template populate<replace<>>(bin.local_bin_idx,

core/include/detray/builders/material_map_generator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class material_map_generator final : public factory_decorator<detector_t> {
230230
const auto sf_idx{m_surface_range[0] + i};
231231

232232
// Skip line surfaces, if any are defined
233-
if constexpr (detector_t::materials::template is_defined<
233+
if constexpr (detector_t::materials::template contains<
234234
material_rod<scalar_t>>()) {
235235

236236
const mask_id sf_mask_id = sf.mask().id();

core/include/detray/builders/surface_factory.hpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -167,22 +167,23 @@ class surface_factory : public surface_factory_interface<detector_t> {
167167
return {surfaces_offset, surfaces_offset};
168168
}
169169

170-
constexpr auto mask_id = detector_t::masks::template get_id<
171-
mask<mask_shape_t, algebra_t, volume_link_t>>();
172-
if constexpr (static_cast<std::size_t>(mask_id) >=
173-
detector_t::masks::n_types) {
170+
using mask_t = mask<mask_shape_t, algebra_t, volume_link_t>;
171+
172+
if constexpr (!detector_t::masks::template contains<mask_t>()) {
174173
std::stringstream err_str{};
175-
err_str << "Cannot match shape type to mask ID: Found "
176-
<< mask_shape_t::name << " at mask id " << mask_id;
174+
err_str << "Could not find mask type '" << mask_shape_t::name
175+
<< "' in detector";
177176

178177
DETRAY_FATAL_HOST(err_str.str());
179178
throw std::invalid_argument(err_str.str());
180179
} else {
181-
182180
using surface_t = typename detector_t::surface_type;
183181
using mask_link_t = typename surface_t::mask_link;
184182
using material_link_t = typename surface_t::material_link;
185183

184+
constexpr auto mask_id{
185+
detector_t::masks::template get_id<mask_t>()};
186+
186187
// The material will be added in a later step
187188
constexpr auto no_material{surface_t::material_id::e_none};
188189

core/include/detray/core/detail/multi_store.hpp

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class multi_store {
6363
/// @{
6464
using value_types = type_registry<ID, detail::get_value_t<Ts>...>;
6565
template <ID id>
66-
using get_type = typename value_types::template get_type<id>::type;
66+
using get_type = typename value_types::template get_type<id>;
6767
template <typename T>
68-
using get_id = typename value_types::template get_index<T>;
68+
static constexpr ids get_id{value_types::template get_id<T>()};
6969
/// @}
7070

7171
/// Underlying tuple container that can handle vecmem views
@@ -131,43 +131,49 @@ class multi_store {
131131
/// @returns the collections iterator at the start position.
132132
template <ID id = ID{0}>
133133
DETRAY_HOST_DEVICE constexpr auto begin(const context_type & /*ctx*/ = {}) {
134-
return detail::get<value_types::to_index(id)>(m_tuple_container)
134+
return detail::get<value_types::template to_index<id>()>(
135+
m_tuple_container)
135136
.begin();
136137
}
137138

138139
/// @returns the collections iterator sentinel.
139140
template <ID id = ID{0}>
140141
DETRAY_HOST_DEVICE constexpr auto end(const context_type & /*ctx*/ = {}) {
141-
return detail::get<value_types::to_index(id)>(m_tuple_container).end();
142+
return detail::get<value_types::template to_index<id>()>(
143+
m_tuple_container)
144+
.end();
142145
}
143146

144147
/// @returns a data collection by @tparam ID - const
145148
template <ID id>
146149
DETRAY_HOST_DEVICE constexpr decltype(auto) get(
147150
const context_type & /*ctx*/ = {}) const noexcept {
148-
return detail::get<value_types::to_index(id)>(m_tuple_container);
151+
return detail::get<value_types::template to_index<id>()>(
152+
m_tuple_container);
149153
}
150154

151155
/// @returns a data collection by @tparam ID - non-const
152156
template <ID id>
153157
DETRAY_HOST_DEVICE constexpr decltype(auto) get(
154158
const context_type & /*ctx*/ = {}) noexcept {
155-
return detail::get<value_types::to_index(id)>(m_tuple_container);
159+
return detail::get<value_types::template to_index<id>()>(
160+
m_tuple_container);
156161
}
157162

158163
/// @returns the size of a data collection by @tparam ID
159164
template <ID id>
160165
DETRAY_HOST_DEVICE constexpr auto size(
161166
const context_type & /*ctx*/ = {}) const noexcept -> dindex {
162167
return static_cast<dindex>(
163-
detail::get<value_types::to_index(id)>(m_tuple_container).size());
168+
detail::get<value_types::template to_index<id>()>(m_tuple_container)
169+
.size());
164170
}
165171

166172
/// @returns the number of elements in all collections
167173
template <std::size_t current_idx = 0>
168174
DETRAY_HOST_DEVICE auto total_size(const context_type &ctx = {},
169175
dindex n = 0u) const noexcept -> dindex {
170-
n += size<value_types::to_id(current_idx)>(ctx);
176+
n += size<value_types::template to_id<current_idx>()>(ctx);
171177

172178
if constexpr (current_idx < sizeof...(Ts) - 1) {
173179
return total_size<current_idx + 1>(ctx, n);
@@ -179,15 +185,16 @@ class multi_store {
179185
template <ID id>
180186
DETRAY_HOST_DEVICE constexpr auto empty(
181187
const context_type & /*ctx*/ = {}) const noexcept -> bool {
182-
return detail::get<value_types::to_index(id)>(m_tuple_container)
188+
return detail::get<value_types::template to_index<id>()>(
189+
m_tuple_container)
183190
.empty();
184191
}
185192

186193
/// @returns true if every collection in container is empty.
187194
template <std::size_t current_idx = 0>
188195
DETRAY_HOST_DEVICE constexpr bool all_empty(const context_type &ctx = {},
189196
bool is_empty = true) const {
190-
is_empty &= empty<value_types::to_id(current_idx)>(ctx);
197+
is_empty &= empty<value_types::template to_id<current_idx>()>(ctx);
191198

192199
if constexpr (current_idx < sizeof...(Ts) - 1) {
193200
return all_empty<current_idx + 1>(ctx, is_empty);
@@ -198,13 +205,14 @@ class multi_store {
198205
/// Removes and destructs all elements in a specific collection.
199206
template <ID id>
200207
DETRAY_HOST void clear(const context_type & /*ctx*/) {
201-
detail::get<value_types::to_index(id)>(m_tuple_container).clear();
208+
detail::get<value_types::template to_index<id>()>(m_tuple_container)
209+
.clear();
202210
}
203211

204212
/// Removes and destructs all elements in the container.
205213
template <std::size_t current_idx = 0>
206214
DETRAY_HOST void clear_all(const context_type &ctx = {}) {
207-
clear<value_types::to_id(current_idx)>(ctx);
215+
clear<value_types::template to_id<current_idx>()>(ctx);
208216

209217
if constexpr (current_idx < sizeof...(Ts) - 1) {
210218
clear_all<current_idx + 1>(ctx);
@@ -214,14 +222,16 @@ class multi_store {
214222
/// Reserve memory of size @param n for a collection given by @tparam id
215223
template <ID id>
216224
DETRAY_HOST void reserve(std::size_t n, const context_type & /*ctx*/) {
217-
detail::get<value_types::to_index(id)>(m_tuple_container).reserve(n);
225+
detail::get<value_types::template to_index<id>()>(m_tuple_container)
226+
.reserve(n);
218227
}
219228

220229
/// Resize the underlying container to @param n for a collection given by
221230
/// @tparam id
222231
template <ID id>
223232
DETRAY_HOST void resize(std::size_t n, const context_type & /*ctx*/) {
224-
detail::get<value_types::to_index(id)>(m_tuple_container).resize(n);
233+
detail::get<value_types::template to_index<id>()>(m_tuple_container)
234+
.resize(n);
225235
}
226236

227237
/// Add a new element to a collection
@@ -236,7 +246,8 @@ class multi_store {
236246
DETRAY_HOST constexpr auto push_back(
237247
const T &arg,
238248
const context_type & /*ctx*/ = {}) noexcept(false) -> void {
239-
auto &coll = detail::get<value_types::to_index(id)>(m_tuple_container);
249+
auto &coll = detail::get<value_types::template to_index<id>()>(
250+
m_tuple_container);
240251
return coll.push_back(arg);
241252
}
242253

@@ -251,7 +262,8 @@ class multi_store {
251262
template <ID id, typename... Args>
252263
DETRAY_HOST constexpr decltype(auto) emplace_back(
253264
const context_type & /*ctx*/ = {}, Args &&...args) noexcept(false) {
254-
auto &coll = detail::get<value_types::to_index(id)>(m_tuple_container);
265+
auto &coll = detail::get<value_types::template to_index<id>()>(
266+
m_tuple_container);
255267
return coll.emplace_back(std::forward<Args>(args)...);
256268
}
257269

@@ -291,7 +303,8 @@ class multi_store {
291303
template <std::size_t current_idx = 0>
292304
DETRAY_HOST void append(const multi_store &other,
293305
const context_type &ctx = {}) noexcept(false) {
294-
auto &coll = other.template get<value_types::to_id(current_idx)>();
306+
auto &coll =
307+
other.template get<value_types::template to_id<current_idx>>();
295308
insert(coll, ctx);
296309

297310
if constexpr (current_idx < sizeof...(Ts) - 1) {
@@ -309,7 +322,8 @@ class multi_store {
309322
template <std::size_t current_idx = 0>
310323
DETRAY_HOST void append(multi_store &&other,
311324
const context_type &ctx = {}) noexcept(false) {
312-
auto &coll = other.template get<value_types::to_id(current_idx)>();
325+
auto &coll =
326+
other.template get<value_types::template to_id<current_idx>()>();
313327
insert(std::move(coll), ctx);
314328

315329
if constexpr (current_idx < sizeof...(Ts) - 1) {

core/include/detray/geometry/mask.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class mask {
196196
///
197197
/// @returns an intersection status e_inside / e_outside
198198
template <concepts::point point_t>
199-
DETRAY_HOST_DEVICE constexpr dbool<algebra_type> is_inside(
199+
DETRAY_HOST_DEVICE constexpr dbool<algebra_t> is_inside(
200200
const point_t& loc_p,
201201
const scalar_type tol =
202202
std::numeric_limits<scalar_type>::epsilon()) const {

core/include/detray/navigation/intersection/ray_cylinder_portal_intersector.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313
#include "detray/definitions/math.hpp"
1414
#include "detray/definitions/units.hpp"
1515
#include "detray/geometry/coordinates/concentric_cylindrical2D.hpp"
16-
#include "detray/geometry/coordinates/cylindrical2D.hpp"
1716
#include "detray/navigation/intersection/intersection.hpp"
18-
#include "detray/navigation/intersection/ray_cylinder_intersector.hpp"
1917
#include "detray/tracks/ray.hpp"
20-
#include "detray/utils/quadratic_equation.hpp"
2118

2219
// System include(s)
2320
#include <type_traits>

core/include/detray/navigation/navigator.hpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,44 @@ class navigator {
907907
return is_init;
908908
}
909909

910+
/// @brief Jump to the next candidate. only possible if stepsize is zero!
911+
///
912+
/// In case of surface overlaps, allow the navigator to advance to the
913+
/// current target, without updating the track position
914+
///
915+
/// @param navigation the current navigation state
916+
/// @param cfg the navigation configuration
917+
DETRAY_HOST_DEVICE inline void jump_to_next(
918+
state &navigation, const navigation::config &cfg) const {
919+
920+
assert(navigation.status() > navigation::status::e_on_target);
921+
922+
// Make sure it is possible to jump ahead
923+
if (navigation.trust_level() != navigation::trust_level::e_full ||
924+
!(navigation.is_on_surface() &&
925+
(math::fabs(navigation()) <= cfg.path_tolerance)) ||
926+
navigation.n_candidates() <= 1u ||
927+
navigation.target().sf_desc.barcode().is_invalid()) {
928+
// Instance of 'distance to next' smaller than path tolerance after
929+
// navigation update and not 'on surface' => This is not an overlap,
930+
// so abort the navigaiton
931+
navigation.abort(
932+
"Navigator: Not possible to jump to next candidate");
933+
}
934+
935+
// If the next target is "on surface", the state will automatically
936+
// advance to it
937+
update_navigation_state(navigation, cfg);
938+
939+
// Not a full navigator update: reduce trust level
940+
navigation.set_high_trust();
941+
942+
// Leave for debugging
943+
// navigation.run_inspector(cfg, point3_type{0.f, 0.f, 0.f},
944+
// vector3_type{0.f, 0.f, 0.f},
945+
// "Jumped to next: ");
946+
}
947+
910948
private:
911949
/// Helper method to update the candidates (surface intersections)
912950
/// based on an externally provided trust level. Will (re-)initialize the

0 commit comments

Comments
 (0)