Skip to content

Commit 4abd90e

Browse files
author
Vakho Tsulaia
committed
First steps towards making single_store context-aware
1. Several changes in the single_store class - Added a couple of new methods allowing to insert all transforms corresponding to a new context in one go - Added a couple of temporary auxiliary methods (`dump_info()` and `dummy()`) - Removed the [] operator (expected that the calls to it will be replaced with the calls to `at()`) 2. Some temporary changes in the data_context class Set the default value for the context to 9999. This is to find the callers who don't pass the explicit value for the context when calling `single_store::at()` 3. Migrated the clients of `single_store::operator[]()` to `single_store::at()` 4. Also declared `single_store::begin()` and `single_store::end()` methods at `const`
1 parent 3633db7 commit 4abd90e

File tree

7 files changed

+49
-21
lines changed

7 files changed

+49
-21
lines changed

core/include/detray/builders/cylinder_portal_generator.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class cylinder_portal_generator final
336336
double mean{0.};
337337

338338
for (const auto &sf_desc : surfaces) {
339-
const auto &trf = transforms[sf_desc.transform()];
339+
const auto &trf = transforms.at(sf_desc.transform());
340340
mean += getter::perp(trf.translation());
341341
}
342342

core/include/detray/core/detail/data_context.hpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ class data_context {
2828
DETRAY_HOST_DEVICE
2929
explicit data_context(dindex value) : m_data{value} {}
3030

31+
DETRAY_HOST_DEVICE
32+
bool operator == (const data_context& other) {
33+
return m_data==other.m_data;
34+
}
35+
3136
/// @returns the index to find the data for the context - const
3237
DETRAY_HOST_DEVICE
3338
dindex get() const { return m_data; }
3439

3540
private:
36-
dindex m_data{0};
41+
dindex m_data{9999};
3742
};
3843

3944
} // namespace detail

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

+37-14
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ class single_store {
109109

110110
/// @returns the collections iterator at the start position.
111111
DETRAY_HOST_DEVICE
112-
constexpr auto begin(const context_type & /*ctx*/ = {}) {
112+
constexpr auto begin(const context_type & /*ctx*/ = {}) const {
113113
return m_container.begin();
114114
}
115115

116116
/// @returns the collections iterator sentinel.
117117
DETRAY_HOST_DEVICE
118-
constexpr auto end(const context_type & /*ctx*/ = {}) {
118+
constexpr auto end(const context_type & /*ctx*/ = {}) const {
119119
return m_container.end();
120120
}
121121

@@ -132,30 +132,25 @@ class single_store {
132132
return m_container;
133133
}
134134

135-
/// Elementwise access. Needs @c operator[] for storage type - non-const
136-
DETRAY_HOST_DEVICE
137-
constexpr decltype(auto) operator[](const dindex i) {
138-
return m_container[i];
139-
}
140-
141-
/// Elementwise access. Needs @c operator[] for storage type - const
142-
DETRAY_HOST_DEVICE
143-
constexpr decltype(auto) operator[](const dindex i) const {
144-
return m_container[i];
135+
/// Temporary dummy method
136+
DETRAY_HOST_DEVICE void dummy() const {
137+
printf("Dummy\n");
145138
}
146139

147140
/// @returns context based access to an element (also range checked)
148141
DETRAY_HOST_DEVICE
149142
constexpr auto at(const dindex i,
150-
const context_type & /*ctx*/) const noexcept
143+
const context_type & ctx = {}) const noexcept
151144
-> const T & {
145+
if(ctx.get()==9999) dummy(); // Just to check if anybody calling at() without passing the context value
152146
return m_container.at(i);
153147
}
154148

155149
/// @returns context based access to an element (also range checked)
156150
DETRAY_HOST_DEVICE
157-
constexpr auto at(const dindex i, const context_type & /*ctx*/) noexcept
151+
constexpr auto at(const dindex i, const context_type & ctx = {}) noexcept
158152
-> T & {
153+
if(ctx.get()==9999) dummy(); // Just to check if anybody calling at() without passing the context value
159154
return m_container.at(i);
160155
}
161156

@@ -276,9 +271,37 @@ class single_store {
276271
return detray::get_data(m_container);
277272
}
278273

274+
DETRAY_HOST void fix_context_size() {
275+
m_context_size = static_cast<dindex>(m_container.size());
276+
m_n_contexts = 1;
277+
}
278+
279+
template <typename U>
280+
DETRAY_HOST auto add_context(container_t<U> &&new_data) noexcept(false)
281+
-> void {
282+
if(m_n_contexts != 0
283+
&& new_data.size() == m_context_size) {
284+
insert(std::move(new_data));
285+
m_n_contexts++;
286+
}
287+
else {
288+
// ToDo: Error?
289+
}
290+
}
291+
292+
#include <iostream>
293+
DETRAY_HOST void dump_info() const {
294+
std::cout << "SINGLE STORE *** \n"
295+
<< "Container size " << m_container.size() << "\n"
296+
<< "Context size " << m_context_size << "\n"
297+
<< "N Contexts " << m_n_contexts << std::endl;
298+
}
299+
279300
private:
280301
/// The underlying container implementation
281302
base_type m_container;
303+
dindex m_context_size{0};
304+
dindex m_n_contexts{0};
282305
};
283306

284307
} // namespace detray

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
@@ -129,7 +129,7 @@ class geometry_writer {
129129
vol_data.index = detail::basic_converter::convert(vol_desc.index());
130130
vol_data.name = name;
131131
vol_data.transform =
132-
convert<detector_t>(det.transform_store()[vol_desc.transform()]);
132+
convert<detector_t>(det.transform_store().at(vol_desc.transform()));
133133
vol_data.type = vol_desc.id();
134134

135135
// Count the surfaces belonging to this volume

0 commit comments

Comments
 (0)