Skip to content

Commit 51bb810

Browse files
authored
Cleanup IO logging and fix file converter python script (#1072)
Refactors more of the logging output and fixes the python file converters to be able to handle json files that come in the merged layout, but did not actually merge any portals, yet. This allows to use the script on the current G200 ITk files
1 parent f59c69f commit 51bb810

25 files changed

+291
-187
lines changed

core/include/detray/builders/detector_builder.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class detector_builder {
135135
// TODO: Add sorting, data deduplication etc. here later...
136136

137137
DETRAY_INFO_HOST("Detector building complete: " << name());
138+
DETRAY_VERBOSE_HOST("-> Built " << det.volumes().size() << " volumes");
139+
DETRAY_VERBOSE_HOST("-> Built " << det.surfaces().size()
140+
<< " surfaces");
138141

139142
return det;
140143
}
@@ -163,7 +166,8 @@ class detector_builder {
163166
/// Put the volumes into a search data structure
164167
template <typename... Args>
165168
DETRAY_HOST void set_volume_finder([[maybe_unused]] Args&&... args) {
166-
DETRAY_VERBOSE_HOST("Setting volume finder for detector " << name());
169+
DETRAY_VERBOSE_HOST("Setting volume finder for detector: '" << name()
170+
<< "'");
167171

168172
using vol_finder_t = typename detector_type::volume_finder;
169173

core/include/detray/builders/grid_builder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class grid_builder : public volume_decorator<detector_t> {
216216
det.accelerator_store().template size<gid>() - 1);
217217

218218
DETRAY_DEBUG_HOST("Accelerator link: " << vol_ptr->accel_link());
219-
DETRAY_DEBUG_HOST("Finished grid building: " << m_grid);
219+
// DETRAY_DEBUG_HOST("Finished grid building: " << m_grid);
220220

221221
DETRAY_VERBOSE_HOST("Successfully built "
222222
<< gid << " for volume: " << this->name());

core/include/detray/builders/homogeneous_material_builder.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class homogeneous_material_builder final : public volume_decorator<detector_t> {
5959
std::dynamic_pointer_cast<homogeneous_material_factory<detector_t>>(
6060
sf_factory);
6161
if (mat_factory) {
62-
DETRAY_VERBOSE_HOST("-> found " << DETRAY_TYPENAME(
62+
DETRAY_VERBOSE_HOST("-> found decoration: " << DETRAY_TYPENAME(
6363
homogeneous_material_factory<detector_t>));
6464
(*mat_factory)(this->surfaces(), m_materials);
6565
return;
@@ -68,7 +68,7 @@ class homogeneous_material_builder final : public volume_decorator<detector_t> {
6868
homogeneous_material_generator<detector_t>>(sf_factory);
6969
if (mat_generator) {
7070
DETRAY_VERBOSE_HOST(
71-
"-> found "
71+
"-> found decoration: "
7272
<< DETRAY_TYPENAME(homogeneous_material_generator<detector_t>));
7373
(*mat_generator)(this->surfaces(), m_materials);
7474
return;

core/include/detray/builders/homogeneous_material_factory.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,20 +128,20 @@ class material_data {
128128
/// Output stream operator for material_data
129129
DETRAY_HOST friend std::ostream &operator<<(std::ostream &os,
130130
const material_data &mat_data) {
131-
os << "material_data{sf_index: ";
131+
os << "material_data{\nsf_index: ";
132132
if (detail::is_invalid_value(mat_data.m_sf_index)) {
133133
os << "invalid";
134134
} else {
135135
os << mat_data.m_sf_index;
136136
}
137-
os << ", materials: [";
137+
os << ", materials: [\n";
138138
for (std::size_t i = 0; i < mat_data.m_mat.size(); ++i) {
139139
if (i > 0) {
140-
os << ", ";
140+
os << ",\n";
141141
}
142142
os << mat_data.m_mat[i];
143143
}
144-
os << "], thickness: [";
144+
os << "],\nthickness: [\n";
145145
for (std::size_t i = 0; i < mat_data.m_thickness.size(); ++i) {
146146
if (i > 0) {
147147
os << ", ";

core/include/detray/builders/material_map_builder.hpp

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,16 @@ class material_map_builder final : public volume_decorator<detector_t> {
8585
material_map_factory<detector_t, axis::multi_bin<DIM>>;
8686
auto mat_factory = std::dynamic_pointer_cast<sf_factory_t>(sf_factory);
8787
if (mat_factory) {
88-
DETRAY_VERBOSE_HOST("-> found " << DETRAY_TYPENAME(sf_factory_t));
88+
DETRAY_VERBOSE_HOST(
89+
"-> found decoration: " << DETRAY_TYPENAME(sf_factory_t));
8990
(*mat_factory)(this->surfaces(), m_bin_data, m_n_bins,
9091
m_axis_spans);
9192
}
9293
auto mat_generator =
9394
std::dynamic_pointer_cast<material_map_generator<detector_t>>(
9495
sf_factory);
9596
if (mat_generator) {
96-
DETRAY_VERBOSE_HOST("-> found " << DETRAY_TYPENAME(
97+
DETRAY_VERBOSE_HOST("-> found decoration: " << DETRAY_TYPENAME(
9798
material_map_generator<detector_t>));
9899
(*mat_generator)(this->surfaces(), this->masks(), m_bin_data,
99100
m_n_bins);
@@ -112,30 +113,34 @@ class material_map_builder final : public volume_decorator<detector_t> {
112113
auto build(detector_t& det,
113114
typename detector_t::geometry_context ctx = {}) ->
114115
typename detector_t::volume_type* override {
115-
DETRAY_DEBUG_HOST("Build material maps...");
116+
DETRAY_VERBOSE_HOST("Build material maps...");
116117

117118
// Ensure the material links are correct BEFORE the surfaces are built
118119
// and potentially added to an acceleration data structure
119120
update_material_links(det);
120121

121-
DETRAY_DEBUG_HOST("-> defer to contained builders");
122+
DETRAY_DEBUG_HOST(
123+
"-> Let underlying builders construct the volume using correct "
124+
"material links...");
122125
// Construct the surfaces
123126
typename detector_t::volume_type* vol_ptr =
124127
volume_decorator<detector_t>::build(det, ctx);
125-
DETRAY_DEBUG_HOST("-> back in build");
128+
DETRAY_DEBUG_HOST("-> Back in build");
126129

127130
// Build the material grid for every surface that has material
128131
dindex sf_idx = 0u;
129132
auto vol = tracking_volume{det, this->vol_index()};
133+
DETRAY_DEBUG_HOST("Build material maps for surfaces...");
130134
for (const auto& sf_desc : vol.surfaces()) {
131135

132-
DETRAY_DEBUG_HOST("-> sf_desc=" << sf_desc);
133-
134136
if (!surface_has_map(sf_idx)) {
135137
sf_idx++;
136138
continue;
137139
}
138140

141+
DETRAY_DEBUG_HOST("-> surface #" << sf_idx
142+
<< " sf_desc = " << sf_desc);
143+
139144
// Construct and append the material map for a given surface shape
140145
darray<std::vector<scalar_type>, DIM> axis_spans{};
141146
auto axis_spans_itr = m_axis_spans.find(sf_idx);
@@ -188,7 +193,7 @@ class material_map_builder final : public volume_decorator<detector_t> {
188193

189194
/// Set the correct global surface material link for this detector
190195
void update_material_links(const detector_t& det) {
191-
DETRAY_DEBUG_HOST("'update_material_links()' called");
196+
DETRAY_VERBOSE_HOST("Precompute material links...");
192197

193198
// The total number of surfaces that will be built by this builder
194199
const dindex n_surfaces{static_cast<dindex>(this->surfaces().size())};
@@ -202,18 +207,20 @@ class material_map_builder final : public volume_decorator<detector_t> {
202207
}
203208

204209
auto& sf_desc = this->surfaces().at(sf_idx);
210+
const auto id{sf_desc.material().id()};
205211

206-
DETRAY_DEBUG_HOST("- sf_desc=" << sf_desc);
212+
DETRAY_DEBUG_HOST("-> surface #" << sf_idx << " (mat. id = " << id
213+
<< ")");
207214

208-
const auto id{sf_desc.material().id()};
209215
if (!mat_type_count.contains(id)) {
210216
mat_type_count.emplace(id, 0u);
211217
} else {
212218
mat_type_count.at(id)++;
213219
}
214220

215-
DETRAY_DEBUG_HOST(" -> set_index (id=" << id << ") to: "
216-
<< mat_type_count.at(id));
221+
DETRAY_DEBUG_HOST(
222+
"--> set mat. index to: " << mat_type_count.at(id));
223+
217224
sf_desc.material().set_index(mat_type_count.at(id));
218225
}
219226

@@ -222,21 +229,19 @@ class material_map_builder final : public volume_decorator<detector_t> {
222229
det._materials.template apply<detail::material_coll_size>(
223230
size_map, std::make_index_sequence<materials_t::n_types>{});
224231

225-
DETRAY_DEBUG_HOST("Update the counts with the detector offset");
232+
DETRAY_DEBUG_HOST("Shift material indices by detector offset...");
226233
for (dindex sf_idx = 0u; sf_idx < n_surfaces; ++sf_idx) {
227234
if (!surface_has_map(sf_idx)) {
228235
continue;
229236
}
230237
auto& sf_desc = this->surfaces().at(sf_idx);
231-
DETRAY_DEBUG_HOST("- sf_desc=" << sf_desc);
232238

233-
DETRAY_DEBUG_HOST("sf_desc.material() = "
234-
<< sf_desc.material() << " ("
235-
<< sf_desc.material().id() << ")");
236239
auto coll_idx{static_cast<std::size_t>(sf_desc.material().id())};
237-
DETRAY_DEBUG_HOST("sf_desc.material() += size_map.at(coll_idx) --> "
238-
<< size_map.at(coll_idx));
239240
sf_desc.material() += size_map.at(coll_idx);
241+
242+
DETRAY_DEBUG_HOST("(Shift = " << size_map.at(coll_idx)
243+
<< "): material link = "
244+
<< sf_desc.material());
240245
}
241246
}
242247

@@ -321,6 +326,8 @@ struct add_sf_material_map {
321326

322327
// Not every mask shape might be used for material maps
323328
if constexpr (materials_t::template is_defined<non_owning_t>()) {
329+
DETRAY_VERBOSE_HOST("Filling material grid...");
330+
324331
// Add the material slabs to the grid
325332
for (const auto& bin : bin_data) {
326333
mat_grid.template populate<replace<>>(bin.local_bin_idx,
@@ -331,10 +338,8 @@ struct add_sf_material_map {
331338
constexpr auto gid{
332339
materials_t::template get_id<non_owning_t>()};
333340
mat_store.template push_back<gid>(mat_grid);
334-
DETRAY_DEBUG_HOST("Adding material grid with gid="
335-
<< gid << " mat_grid=" << mat_grid
336-
<< "(size is now "
337-
<< mat_store.template size<gid>() << ")");
341+
DETRAY_VERBOSE_HOST("Built material grid:" << gid << ":\n"
342+
<< mat_grid.axes());
338343

339344
// Return the index of the new material map
340345
return {gid, static_cast<dindex>(

core/include/detray/builders/material_map_factory.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class material_map_factory final : public factory_decorator<detector_t> {
109109
std::vector<std::vector<scalar_type>> &&axis_spans,
110110
std::vector<index_type> &&indices) {
111111

112-
DETRAY_DEBUG_HOST("Add map data");
112+
DETRAY_VERBOSE_HOST("Received material map data");
113113

114114
auto [sf_index, mat, thickness] = std::move(mat_data).get_data();
115115

@@ -150,7 +150,7 @@ class material_map_factory final : public factory_decorator<detector_t> {
150150
std::map<dindex, darray<std::size_t, N>> &n_bins,
151151
std::map<dindex, darray<std::vector<scalar_type>, N>> &axis_spans) {
152152

153-
DETRAY_DEBUG_HOST("Add material maps...");
153+
DETRAY_VERBOSE_HOST("Add material maps...");
154154

155155
using link_t = typename detector_t::surface_type::material_link;
156156

@@ -162,14 +162,16 @@ class material_map_factory final : public factory_decorator<detector_t> {
162162

163163
assert(surfaces.size() >= n_materials);
164164

165-
DETRAY_DEBUG_HOST("-> Have " << m_materials.size()
166-
<< " configured material maps to assign");
165+
DETRAY_VERBOSE_HOST("-> Have "
166+
<< m_materials.size()
167+
<< " configured material map(s) to assign");
167168

168169
// Add the material only to those surfaces that the data links against
169170
for (auto &[i, materials] : m_materials) {
170171
const auto sf_idx{static_cast<dindex>(i)};
171172

172-
DETRAY_DEBUG_HOST("-> sf=" << surfaces.at(sf_idx));
173+
DETRAY_DEBUG_HOST("--> #" << sf_idx
174+
<< " sf = " << surfaces.at(sf_idx));
173175

174176
// Copy the number of bins to the builder
175177
assert(m_n_bins.at(sf_idx).size() == N);
@@ -204,9 +206,11 @@ class material_map_factory final : public factory_decorator<detector_t> {
204206
}
205207

206208
auto map_id{m_links.at(sf_idx).first};
207-
DETRAY_DEBUG_HOST("-> material map factory sets map_id=" << map_id);
209+
DETRAY_DEBUG_HOST("--> Set surface material id: " << map_id);
208210
surfaces[sf_idx].material() = link_t{map_id, dindex_invalid};
209211
}
212+
213+
DETRAY_DEBUG_HOST("Finished");
210214
}
211215

212216
private:

core/include/detray/builders/surface_factory.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class surface_factory : public surface_factory_interface<detector_t> {
160160
// In case the surfaces container is prefilled with other surfaces
161161
const auto surfaces_offset{static_cast<dindex>(surfaces.size())};
162162

163-
DETRAY_VERBOSE_HOST("-> Have " << size() << " surfaces");
163+
DETRAY_VERBOSE_HOST("-> Adding " << size() << " surfaces");
164164

165165
// Nothing to construct
166166
if (size() == 0u) {

core/include/detray/builders/volume_builder.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ class volume_builder : public volume_builder_interface<detector_t> {
275275

276276
// Add only the portals to the brute force method
277277
DETRAY_VERBOSE_HOST(
278-
"-> Register portals/passives with brute force accelerator");
278+
"-> Register only portals/passives with brute force "
279+
"accelerator");
279280

280281
det._accelerators.template push_back<default_acc_id>(
281282
std::move(portals));

core/include/detray/propagator/propagator.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ struct propagator {
227227
for (unsigned int i = 0; i % 2 == 0 || propagation.is_alive(); ++i) {
228228

229229
if (i % 2 == 0) {
230-
DETRAY_DEBUG_HOST("Propagation step: " << i / 2);
230+
DETRAY_VERBOSE_HOST_DEVICE("Propagation step: %d", i / 2);
231+
DETRAY_VERBOSE_HOST_DEVICE("Path length: %f mm",
232+
stepping.path_length());
231233

232234
// Run all registered actors/aborters
233235
run_actors(actor_state_refs, propagation);
@@ -280,11 +282,11 @@ struct propagator {
280282
// Pass on the whether the propagation was successful
281283
DETRAY_VERBOSE_HOST("Finished propagation for track:\n" << track);
282284
if (is_complete(propagation)) {
283-
DETRAY_VERBOSE_HOST("Satus: COMPLETE");
285+
DETRAY_VERBOSE_HOST_DEVICE("Satus: COMPLETE");
284286
} else if (is_paused(propagation)) {
285-
DETRAY_VERBOSE_HOST("Satus: PAUSED");
287+
DETRAY_VERBOSE_HOST_DEVICE("Satus: PAUSED");
286288
} else {
287-
DETRAY_VERBOSE_HOST("Satus: ABORT");
289+
DETRAY_VERBOSE_HOST_DEVICE("Satus: ABORT");
288290
}
289291

290292
return is_complete(propagation) || is_paused(propagation);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct single_axis {
189189
os << "bounds: " << ax.bounds() << std::endl;
190190
os << "binning: " << ax.binning() << std::endl;
191191
os << "n-bins: " << ax.nbins() << std::endl;
192-
os << "min: " << ax.min() << ", max: " << ax.max();
192+
os << "span: [" << ax.min() << ", " << ax.max() << "]";
193193

194194
return os;
195195
}

0 commit comments

Comments
 (0)