12
12
#include " detray/builders/detector_builder.hpp"
13
13
#include " detray/builders/grid_factory.hpp"
14
14
#include " detray/definitions/indexing.hpp"
15
+ #include " detray/io/common/detail/basic_converter.hpp"
15
16
#include " detray/io/common/detail/type_info.hpp"
16
- #include " detray/io/common/io_interface.hpp"
17
17
#include " detray/io/frontend/payloads.hpp"
18
18
#include " detray/utils/ranges.hpp"
19
19
#include " detray/utils/type_list.hpp"
27
27
28
28
namespace detray ::io::detail {
29
29
30
- // / @brief Abstract base class for surface grid readers
30
+ // / @brief Grid reader backend
31
31
// /
32
- // / @tparam detector_t the detector the grid belongs to
33
32
// / @tparam value_t bin entry type
34
33
// / @tparam grid_builder_t the grid builder to be used
35
34
// / @tparam CAP the storage capacity of a single bin
36
35
// / @tparam DIM the dimension of the grid
37
36
// / @tparam bin_filler_t helper to fill all bins of a grid
38
37
// / @tparam serializer_t memory layout of the grid
39
- template <class detector_t , typename value_t ,
38
+ template <typename value_t ,
40
39
template <typename , typename , typename , typename >
41
40
class grid_builder_t ,
42
41
typename CAP = std::integral_constant<std::size_t , 0 >,
43
42
typename DIM = std::integral_constant<std::size_t , 2 >,
44
43
typename bin_filler_t = fill_by_pos,
45
44
template <std::size_t > class serializer_t = simple_serializer>
46
- class grid_reader : public reader_interface < detector_t > {
45
+ class grid_reader {
47
46
48
- using base_type = reader_interface<detector_t >;
49
47
// / IO accelerator ids do not need to coincide with the detector ids,
50
48
// / because they are shared with ACTS
51
49
using acc_type = io::accel_id;
52
- using algebra_t = typename detector_t ::transform3;
53
- using scalar_t = typename algebra_t ::scalar_type;
54
50
55
51
static constexpr std::size_t dim{DIM ()};
56
52
static constexpr std::size_t bin_capacity{CAP ()};
57
53
58
54
public:
59
- // / Same constructors for this class as for base_type
60
- using base_type::base_type;
61
-
62
- protected:
63
- // / Deserialize the detector grids @param grids_data from their IO payload
64
- template <typename content_t , typename grid_id_t >
65
- static void deserialize (
55
+ // / Convert the detector grids @param grids_data from their IO payload
56
+ template <typename detector_t , typename content_t , typename grid_id_t >
57
+ static void convert (
66
58
detector_builder<typename detector_t ::metadata, volume_builder>
67
59
&det_builder,
68
60
const detector_grids_payload<content_t , grid_id_t > &grids_data) {
69
61
70
- // Deserialize the grids volume by volume
62
+ // Convert the grids volume by volume
71
63
for (const auto &[_, grid_data_coll] : grids_data.grids ) {
72
64
for (const auto &[i, grid_data] :
73
65
detray::views::enumerate (grid_data_coll)) {
@@ -81,8 +73,9 @@ class grid_reader : public reader_interface<detector_t> {
81
73
}
82
74
83
75
// Don't start at zero, since that is the brute force method
84
- deserialize (bounds, binnings, std::make_pair (i + 1 , grid_data),
85
- det_builder);
76
+ convert<detector_t >(bounds, binnings,
77
+ std::make_pair (i + 1 , grid_data),
78
+ det_builder);
86
79
}
87
80
}
88
81
}
@@ -96,18 +89,17 @@ class grid_reader : public reader_interface<detector_t> {
96
89
// /
97
90
// / @param bound_ids runtime queue of bounds type ids (read from file)
98
91
// / @param binning_ids runtime queue of binning type ids (read from file)
99
- template <typename bounds_ts = types::list<>,
92
+ template <typename detector_t , typename bounds_ts = types::list<>,
100
93
typename binning_ts = types::list<>, typename ... Ts>
101
- static void deserialize (std::queue<axis::bounds> &bound_ids,
102
- std::queue<axis::binning> &binning_ids,
103
- Ts &&... data) {
94
+ static void convert (std::queue<axis::bounds> &bound_ids,
95
+ std::queue<axis::binning> &binning_ids, Ts &&... data) {
104
96
using namespace axis ;
105
97
106
98
constexpr std::size_t n_bounds_types{types::size<bounds_ts>};
107
99
108
100
// Base case: If the bounds types are filled, continue with the binnings
109
101
if constexpr (n_bounds_types == dim) {
110
- return deserialize< bounds_ts, binning_ts>(
102
+ return convert< detector_t , bounds_ts, binning_ts>(
111
103
binning_ids, std::forward<Ts>(data)...);
112
104
} else if (!bound_ids.empty ()) {
113
105
// The axis label, e.g. x, y or z by number
@@ -122,18 +114,18 @@ class grid_reader : public reader_interface<detector_t> {
122
114
case bounds::e_closed: {
123
115
using new_bounds_ts =
124
116
types::push_back<bounds_ts, closed<lb>>;
125
- return deserialize< new_bounds_ts, binning_ts>(
117
+ return convert< detector_t , new_bounds_ts, binning_ts>(
126
118
bound_ids, binning_ids, std::forward<Ts>(data)...);
127
119
}
128
120
case bounds::e_open: {
129
121
using new_bounds_ts = types::push_back<bounds_ts, open <lb>>;
130
- return deserialize< new_bounds_ts, binning_ts>(
122
+ return convert< detector_t , new_bounds_ts, binning_ts>(
131
123
bound_ids, binning_ids, std::forward<Ts>(data)...);
132
124
}
133
125
case bounds::e_circular: {
134
126
using new_bounds_ts =
135
127
types::push_back<bounds_ts, circular<lb>>;
136
- return deserialize< new_bounds_ts, binning_ts>(
128
+ return convert< detector_t , new_bounds_ts, binning_ts>(
137
129
bound_ids, binning_ids, std::forward<Ts>(data)...);
138
130
}
139
131
// Test some edge cases
@@ -155,19 +147,20 @@ class grid_reader : public reader_interface<detector_t> {
155
147
// / identified from the IO ids so far (start with empty list)
156
148
// /
157
149
// / @param binning_ids runtime queue of binning type ids (read from file)
158
- template <typename bounds_ts, typename binning_ts, typename ... Ts,
150
+ template <typename detector_t , typename bounds_ts, typename binning_ts,
151
+ typename ... Ts,
159
152
std::enable_if_t <types::size<bounds_ts> == dim, bool > = true >
160
- static void deserialize (std::queue<axis::binning> &binning_ids,
161
- Ts &&... data) {
153
+ static void convert (std::queue<axis::binning> &binning_ids, Ts &&... data) {
162
154
163
155
using namespace axis ;
164
156
157
+ using scalar_t = typename detector_t ::scalar_type;
165
158
using regular_binning_t = regular<host_container_types, scalar_t >;
166
159
using irregular_binning_t = irregular<host_container_types, scalar_t >;
167
160
168
161
// Base case: If the binning types are filled, continue with the frame
169
162
if constexpr (types::size<binning_ts> == dim) {
170
- return deserialize< bounds_ts, binning_ts>(
163
+ return convert< detector_t , bounds_ts, binning_ts>(
171
164
std::forward<Ts>(data)...);
172
165
} else if (!binning_ids.empty ()) {
173
166
@@ -178,13 +171,13 @@ class grid_reader : public reader_interface<detector_t> {
178
171
case binning::e_regular: {
179
172
using new_binning_ts =
180
173
types::push_back<binning_ts, regular_binning_t >;
181
- return deserialize< bounds_ts, new_binning_ts>(
174
+ return convert< detector_t , bounds_ts, new_binning_ts>(
182
175
binning_ids, std::forward<Ts>(data)...);
183
176
}
184
177
case binning::e_irregular: {
185
178
using new_binning_ts =
186
179
types::push_back<binning_ts, irregular_binning_t >;
187
- return deserialize< bounds_ts, new_binning_ts>(
180
+ return convert< detector_t , bounds_ts, new_binning_ts>(
188
181
binning_ids, std::forward<Ts>(data)...);
189
182
}
190
183
// Test some edge cases
@@ -206,15 +199,18 @@ class grid_reader : public reader_interface<detector_t> {
206
199
// /
207
200
// / @param grid_data grid IO payload (read from file)
208
201
// / @param det_builder gather the grid data and build the final volume
209
- template <typename bounds_ts, typename binning_ts, typename content_t ,
202
+ template <typename detector_t , typename bounds_ts, typename binning_ts,
203
+ typename content_t ,
210
204
std::enable_if_t <types::size<bounds_ts> == dim and
211
205
types::size<binning_ts> == dim,
212
206
bool > = true >
213
- static void deserialize (
207
+ static void convert (
214
208
const std::pair<dindex, grid_payload<content_t >> &grid_data,
215
209
detector_builder<typename detector_t ::metadata, volume_builder>
216
210
&det_builder) {
217
211
212
+ using algebra_t = typename detector_t ::transform3;
213
+
218
214
// Throw expection if the accelerator link type id is invalid
219
215
auto print_error = [](io::accel_id grid_link) -> void {
220
216
if (grid_link == io::accel_id::unknown) {
@@ -238,17 +234,17 @@ class grid_reader : public reader_interface<detector_t> {
238
234
switch (grid_data.second .grid_link .type ) {
239
235
// rectangle, trapezoid, (triangle) grids
240
236
case io::accel_id::cartesian2_grid: {
241
- return deserialize< cartesian2<algebra_t >>(
237
+ return convert< detector_t , cartesian2<algebra_t >>(
242
238
grid_data, det_builder, bounds, binnings);
243
239
}
244
240
// ring/disc, annulus grids
245
241
case io::accel_id::polar2_grid: {
246
- return deserialize< polar2<algebra_t >>(
242
+ return convert< detector_t , polar2<algebra_t >>(
247
243
grid_data, det_builder, bounds, binnings);
248
244
}
249
245
// 2D cylinder grid
250
246
case io::accel_id::cylinder2_grid: {
251
- return deserialize< cylindrical2<algebra_t >>(
247
+ return convert< detector_t , cylindrical2<algebra_t >>(
252
248
grid_data, det_builder, bounds, binnings);
253
249
}
254
250
default : {
@@ -260,12 +256,12 @@ class grid_reader : public reader_interface<detector_t> {
260
256
switch (grid_data.second .grid_link .type ) {
261
257
// cuboid grid
262
258
case io::accel_id::cuboid3_grid: {
263
- return deserialize< cartesian3<algebra_t >>(
259
+ return convert< detector_t , cartesian3<algebra_t >>(
264
260
grid_data, det_builder, bounds, binnings);
265
261
}
266
262
// 3D cylinder grid
267
263
case io::accel_id::cylinder3_grid: {
268
- return deserialize< cylindrical3<algebra_t >>(
264
+ return convert< detector_t , cylindrical3<algebra_t >>(
269
265
grid_data, det_builder, bounds, binnings);
270
266
}
271
267
default : {
@@ -279,22 +275,23 @@ class grid_reader : public reader_interface<detector_t> {
279
275
}
280
276
281
277
// / @brief End of recursion: build the grid from the @param grid_data
282
- template <typename local_frame_t , typename content_t , typename ... bounds_ts ,
283
- typename ... binning_ts,
278
+ template <typename detector_t , typename local_frame_t , typename content_t ,
279
+ typename ... bounds_ts, typename ... binning_ts,
284
280
std::enable_if_t <sizeof ...(bounds_ts) == dim and
285
281
sizeof ...(binning_ts) == dim,
286
282
bool > = true >
287
- static void deserialize (
283
+ static void convert (
288
284
const std::pair<dindex, grid_payload<content_t >> &grid_idx_and_data,
289
285
detector_builder<typename detector_t ::metadata, volume_builder>
290
286
&det_builder,
291
287
types::list<bounds_ts...>, types::list<binning_ts...>) {
292
288
289
+ using scalar_t = typename detector_t ::scalar_type;
290
+
293
291
// Assemble the grid type
294
292
using axes_t =
295
293
axis::multi_axis<false , local_frame_t ,
296
294
axis::single_axis<bounds_ts, binning_ts>...>;
297
- // Ok for now: Only have this serializer
298
295
using bin_t =
299
296
std::conditional_t <bin_capacity == 0 , bins::dynamic_array<value_t >,
300
297
bins::static_array<value_t , bin_capacity>>;
@@ -304,7 +301,8 @@ class grid_reader : public reader_interface<detector_t> {
304
301
" Grid dimension does not meet dimension of grid reader" );
305
302
306
303
const auto &[sf_type, grid_data] = grid_idx_and_data;
307
- const auto volume_idx{base_type::deserialize (grid_data.owner_link )};
304
+ const auto volume_idx{
305
+ detail::basic_converter::convert (grid_data.owner_link )};
308
306
309
307
// Error output
310
308
std::stringstream err_stream;
0 commit comments