Skip to content

Commit e4dbe80

Browse files
authored
Dropped elementwise access to single_store (acts-project#857)
Replaced all calls to single_store::operator[]() with calls to single_store::at()
1 parent e3724d6 commit e4dbe80

File tree

15 files changed

+39
-46
lines changed

15 files changed

+39
-46
lines changed

core/include/detray/builders/cylinder_portal_generator.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ class cylinder_portal_generator final
360360
double mean{0.};
361361

362362
for (const auto &sf_desc : surfaces) {
363-
const auto &trf = transforms[sf_desc.transform()];
363+
const auto &trf = transforms.at(sf_desc.transform());
364364
mean += getter::perp(trf.translation());
365365
}
366366

core/include/detray/builders/detail/bin_association.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static inline void bin_association(const context_t & /*context*/,
166166
}
167167

168168
// Unroll the mask container and generate vertices
169-
const auto &transform = transforms[sf.transform()];
169+
const auto &transform = transforms.at(sf.transform());
170170

171171
auto vertices_per_masks = surface_masks.template visit<
172172
detail::vertexer<point2_t, point3_t>>(sf.mask());

core/include/detray/core/detail/single_store.hpp

+10-18
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ class single_store {
105105
return m_container.empty();
106106
}
107107

108-
/// @returns the collections iterator at the start position.
108+
/// @returns the collections iterator at the start position
109109
DETRAY_HOST_DEVICE
110-
constexpr auto begin(const context_type & /*ctx*/ = {}) {
110+
constexpr auto begin(const context_type & /*ctx*/ = {}) const {
111111
return m_container.begin();
112112
}
113113

114-
/// @returns the collections iterator sentinel.
114+
/// @returns the collections iterator sentinel
115115
DETRAY_HOST_DEVICE
116-
constexpr auto end(const context_type & /*ctx*/ = {}) {
116+
constexpr auto end(const context_type & /*ctx*/ = {}) const {
117117
return m_container.end();
118118
}
119119

@@ -130,30 +130,22 @@ class single_store {
130130
return m_container;
131131
}
132132

133-
/// Elementwise access. Needs @c operator[] for storage type - non-const
134-
DETRAY_HOST_DEVICE
135-
constexpr decltype(auto) operator[](const dindex i) {
136-
return m_container[i];
137-
}
138-
139-
/// Elementwise access. Needs @c operator[] for storage type - const
140-
DETRAY_HOST_DEVICE
141-
constexpr decltype(auto) operator[](const dindex i) const {
142-
return m_container[i];
143-
}
144-
145133
/// @returns context based access to an element (also range checked)
146134
DETRAY_HOST_DEVICE
147135
constexpr auto at(const dindex i,
148-
const context_type & /*ctx*/) const noexcept
136+
const context_type &ctx = {}) const noexcept
149137
-> const T & {
138+
[[maybe_unused]] context_type tmp_ctx{
139+
ctx}; // Temporary measure to avoid warnings
150140
return m_container.at(i);
151141
}
152142

153143
/// @returns context based access to an element (also range checked)
154144
DETRAY_HOST_DEVICE
155-
constexpr auto at(const dindex i, const context_type & /*ctx*/) noexcept
145+
constexpr auto at(const dindex i, const context_type &ctx = {}) noexcept
156146
-> T & {
147+
[[maybe_unused]] context_type tmp_ctx{
148+
ctx}; // Temporary measure to avoid warnings
157149
return m_container.at(i);
158150
}
159151

core/include/detray/core/detector.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void set_transform(detector_t &det, const transform3_t &trf, unsigned int i) {
4141
<< "WARNING: Modifying transforms in the detector will be deprecated! "
4242
"Please, use a separate geometry context in this case"
4343
<< std::endl;
44-
det._transforms[i] = trf;
44+
det._transforms.at(i) = trf;
4545
}
4646
} // namespace detail
4747

core/include/detray/geometry/tracking_volume.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class tracking_volume {
8787
DETRAY_HOST_DEVICE
8888
constexpr auto transform() const -> const
8989
typename detector_t::transform3_type & {
90-
return m_detector.transform_store()[m_desc.transform()];
90+
return m_detector.transform_store().at(m_desc.transform());
9191
}
9292

9393
/// @returns the center point of the volume.

core/include/detray/navigation/intersection_kernel.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct intersection_initialize {
5454
using mask_t = typename mask_group_t::value_type;
5555
using algebra_t = typename mask_t::algebra_type;
5656

57-
const auto &ctf = contextual_transforms[surface.transform()];
57+
const auto &ctf = contextual_transforms.at(surface.transform());
5858

5959
// Run over the masks that belong to the surface (only one can be hit)
6060
for (const auto &mask :
@@ -143,7 +143,7 @@ struct intersection_update {
143143
using mask_t = typename mask_group_t::value_type;
144144
using algebra_t = typename mask_t::algebra_type;
145145

146-
const auto &ctf = contextual_transforms[sfi.sf_desc.transform()];
146+
const auto &ctf = contextual_transforms.at(sfi.sf_desc.transform());
147147

148148
// Run over the masks that belong to the surface
149149
for (const auto &mask :

core/include/detray/utils/grid/grid.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class grid_impl {
276276
const track_t &track, const config_t &cfg) const {
277277

278278
// Track position in grid coordinates
279-
const auto &trf = det.transform_store()[volume.transform()];
279+
const auto &trf = det.transform_store().at(volume.transform());
280280
const auto loc_pos = project(trf, track.pos(), track.dir());
281281

282282
// Grid lookup

io/include/detray/io/common/geometry_writer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class geometry_writer {
128128
vol_data.index = detail::basic_converter::convert(vol_desc.index());
129129
vol_data.name = name;
130130
vol_data.transform =
131-
convert<detector_t>(det.transform_store()[vol_desc.transform()]);
131+
convert<detector_t>(det.transform_store().at(vol_desc.transform()));
132132
vol_data.type = vol_desc.id();
133133

134134
// Count the surfaces belonging to this volume

tests/integration_tests/cpu/builders/homogeneous_material_builder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ GTEST_TEST(detray_builders, detector_builder_with_material) {
257257
// Check the volume placement
258258
typename detector_t::transform3_type trf{t};
259259
EXPECT_TRUE(vol.transform() == trf);
260-
EXPECT_TRUE(d.transform_store()[0u] == trf);
260+
EXPECT_TRUE(d.transform_store().at(0u) == trf);
261261

262262
EXPECT_EQ(d.surfaces().size(), 7u);
263263
EXPECT_EQ(d.mask_store().template size<mask_id::e_rectangle2>(), 3u);

tests/integration_tests/cpu/builders/volume_builder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ GTEST_TEST(detray_builders, tracking_volume_construction) {
208208

209209
// Check the volume placement
210210
typename detector_t::transform3_type trf{t};
211-
EXPECT_TRUE(d.transform_store()[first_trf] == trf);
211+
EXPECT_TRUE(d.transform_store().at(first_trf) == trf);
212212

213213
// Check the acceleration data structure link
214214
dtyped_index<accel_id, dindex> acc_link{accel_id::e_default, 1u};

tests/integration_tests/cpu/propagator/jacobian_validation.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ std::pair<euler_rotation<algebra_type>, std::array<scalar, 3u>> tilt_surface(
326326

327327
const auto& sf = det.surface(sf_id);
328328
const auto& trf_link = sf.transform();
329-
auto& trf = det.transform_store()[trf_link];
329+
auto& trf = det.transform_store().at(trf_link);
330330

331331
euler_rotation<algebra_type> euler;
332332
euler.alpha = alpha;
@@ -620,7 +620,7 @@ bound_track_parameters<algebra_type> get_initial_parameter(
620620

621621
const auto& departure_sf = det.surface(0u);
622622
const auto& trf_link = departure_sf.transform();
623-
const auto& departure_trf = det.transform_store()[trf_link];
623+
const auto& departure_trf = det.transform_store().at(trf_link);
624624
const auto& mask_link = departure_sf.mask();
625625
const auto& departure_mask =
626626
det.mask_store().template get<mask_id>().at(mask_link.index());
@@ -985,7 +985,7 @@ bound_param_vector_type get_displaced_bound_vector_helix(
985985

986986
const auto& destination_sf = det.surface(1u);
987987
const auto& trf_link = destination_sf.transform();
988-
const auto& destination_trf = det.transform_store()[trf_link];
988+
const auto& destination_trf = det.transform_store().at(trf_link);
989989
const auto& mask_link = destination_sf.mask();
990990
const auto& destination_mask =
991991
det.mask_store().template get<mask_id>().at(mask_link.index());
@@ -1047,7 +1047,7 @@ void evaluate_jacobian_difference_helix(
10471047

10481048
const auto& destination_sf = det.surface(1u);
10491049
const auto& trf_link = destination_sf.transform();
1050-
const auto& destination_trf = det.transform_store()[trf_link];
1050+
const auto& destination_trf = det.transform_store().at(trf_link);
10511051
const auto& mask_link = destination_sf.mask();
10521052
const auto& destination_mask =
10531053
det.mask_store().template get<mask_id>().at(mask_link.index());

tests/unit_tests/cpu/builders/detector_builder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ GTEST_TEST(detray_builders, detector_builder) {
114114
// Check the volume placements for both volumes
115115
typename detector_t::transform3_type identity{};
116116
EXPECT_TRUE(vol0.transform() == identity);
117-
EXPECT_TRUE(d.transform_store()[0u] == identity);
117+
EXPECT_TRUE(d.transform_store().at(0u) == identity);
118118
typename detector_t::transform3_type trf{t};
119119
EXPECT_TRUE(vol1.transform() == trf);
120-
EXPECT_TRUE(d.transform_store()[4u] == trf);
120+
EXPECT_TRUE(d.transform_store().at(4u) == trf);
121121

122122
EXPECT_EQ(d.surfaces().size(), 12u);
123123
EXPECT_EQ(d.mask_store().template size<mask_id::e_portal_cylinder2>(), 0u);

tests/unit_tests/cpu/core/containers.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ GTEST_TEST(detray_core, single_store) {
5757
EXPECT_EQ(store.size(), 4u);
5858

5959
// Check access to the data
60-
EXPECT_NEAR(store[0], 1., tol_double);
61-
EXPECT_NEAR(store[2], 10.5, tol_double);
60+
EXPECT_NEAR(store.at(0, ctx), 1., tol_double);
61+
EXPECT_NEAR(store.at(2, ctx), 10.5, tol_double);
6262
EXPECT_NEAR(store.at(1, ctx), 2., tol_double);
6363
EXPECT_NEAR(store.at(3, ctx), 7.6, tol_double);
6464
}

tests/unit_tests/cpu/navigation/intersection/intersection_kernel.cpp

+9-8
Original file line numberDiff line numberDiff line change
@@ -169,17 +169,18 @@ GTEST_TEST(detray_intersection, intersection_kernel_ray) {
169169

170170
if (sfi_init[i].sf_desc.mask().id() == e_rectangle2) {
171171
global =
172-
rect.to_global_frame(transform_store[0], sfi_init[i].local);
172+
rect.to_global_frame(transform_store.at(0), sfi_init[i].local);
173173
} else if (sfi_init[i].sf_desc.mask().id() == e_trapezoid2) {
174174
global =
175-
trap.to_global_frame(transform_store[1], sfi_init[i].local);
175+
trap.to_global_frame(transform_store.at(1), sfi_init[i].local);
176176
} else if (sfi_init[i].sf_desc.mask().id() == e_annulus2) {
177177
global =
178-
annl.to_global_frame(transform_store[2], sfi_init[i].local);
178+
annl.to_global_frame(transform_store.at(2), sfi_init[i].local);
179179
} else if (sfi_init[i].sf_desc.mask().id() == e_cylinder2) {
180-
global = cyl.to_global_frame(transform_store[3], sfi_init[i].local);
180+
global =
181+
cyl.to_global_frame(transform_store.at(3), sfi_init[i].local);
181182
} else if (sfi_init[i].sf_desc.mask().id() == e_cylinder2_portal) {
182-
global = cyl_portal.to_global_frame(transform_store[4],
183+
global = cyl_portal.to_global_frame(transform_store.at(4),
183184
sfi_init[i].local);
184185
}
185186

@@ -284,13 +285,13 @@ GTEST_TEST(detray_intersection, intersection_kernel_helix) {
284285

285286
if (surface.mask().id() == e_rectangle2) {
286287
global =
287-
rect.to_global_frame(transform_store[0], sfi_helix[0].local);
288+
rect.to_global_frame(transform_store.at(0), sfi_helix[0].local);
288289
} else if (surface.mask().id() == e_trapezoid2) {
289290
global =
290-
trap.to_global_frame(transform_store[1], sfi_helix[0].local);
291+
trap.to_global_frame(transform_store.at(1), sfi_helix[0].local);
291292
} else if (surface.mask().id() == e_annulus2) {
292293
global =
293-
annl.to_global_frame(transform_store[2], sfi_helix[0].local);
294+
annl.to_global_frame(transform_store.at(2), sfi_helix[0].local);
294295
}
295296

296297
ASSERT_NEAR(global[0], expected_points[sf_idx][0], is_close);

tests/unit_tests/device/cuda/container_cuda.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ TEST(container_cuda, single_store) {
5959
EXPECT_EQ(mng_store.size(), 4u);
6060

6161
// Check the host-side access to the data
62-
EXPECT_NEAR(mng_store[0], 1., tol);
63-
EXPECT_NEAR(mng_store[2], 10.5, tol);
62+
EXPECT_NEAR(mng_store.at(0, ctx), 1., tol);
63+
EXPECT_NEAR(mng_store.at(2, ctx), 10.5, tol);
6464
EXPECT_NEAR(mng_store.at(1, ctx), 2., tol);
6565
EXPECT_NEAR(mng_store.at(3, ctx), 7.6, tol);
6666

0 commit comments

Comments
 (0)