12#include "detray/core/concepts.hpp"
13#include "detray/definitions/indexing.hpp"
14#include "detray/geometry/mask.hpp"
15#include "detray/geometry/surface.hpp"
16#include "detray/io/backend/detail/basic_converter.hpp"
17#include "detray/io/backend/detail/type_info.hpp"
18#include "detray/io/frontend/payloads.hpp"
19#include "detray/utils/grid/concepts.hpp"
36 static constexpr std::string_view
tag =
"geometry";
46 template <detray::concepts::detector detector_t>
48 const std::string_view det_name) {
51 header_data.
common = detail::basic_converter::to_payload(det_name,
tag);
54 auto& geo_sub_header = header_data.
sub_header.value();
55 geo_sub_header.n_volumes = det.volumes().size();
56 geo_sub_header.n_surfaces = det.surfaces().size();
66 template <detray::concepts::detector detector_t>
68 const typename detector_t::name_map& names) {
70 det_data.
volumes.reserve(det.volumes().size());
72 for (
const auto& vol : det.volumes()) {
73 if (names.contains(vol.index())) {
87 template <detray::concepts::detector detector_t>
89 const typename detector_t::transform3_type& trf) {
92 const auto& t = trf.translation();
93 const auto& x = trf.x();
94 const auto& y = trf.y();
95 const auto& z = trf.z();
97 trf_data.
tr = {t[0], t[1], t[2]};
98 trf_data.
rot = {x[0], x[1], x[2], y[0], y[1], y[2], z[0], z[1], z[2]};
107 template <
typename mask_t>
108 requires(!std::is_same_v<typename mask_t::shape, void>)
112 mask_data.
shape = io::detail::get_id<typename mask_t::shape>();
115 detail::basic_converter::to_payload(m.volume_link());
117 mask_data.
boundaries.resize(mask_t::boundaries::e_size);
118 std::ranges::copy(m.values(), std::begin(mask_data.
boundaries));
128 template <detray::concepts::detector detector_t>
130 std::size_t sf_idx) {
131 using algebra_t =
typename detector_t::algebra_type;
138 sf_data.
masks = sf.template visit_mask<get_mask_link_payload>();
141 sf.template visit_material<get_material_link_payload<algebra_t>>();
154 template <detray::concepts::detector detector_t>
156 const typename detector_t::volume_type& vol_desc,
const detector_t& det,
157 const std::string_view name) {
160 vol_data.
index = detail::basic_converter::to_payload(vol_desc.index());
161 vol_data.
name = name;
164 vol_data.
type = vol_desc.id();
167 std::size_t sf_idx{0};
169 for (
const auto& sf_desc : det.surfaces()) {
170 if (sf_desc.volume() == vol_desc.index()) {
177 const auto& link = vol_desc.accel_link();
179 if (link.size() > 1u) {
184 for (
unsigned int i = 1u; i < link.size(); ++i) {
185 const auto& l = link[i];
186 if (!l.is_invalid()) {
188 det.accelerator_store().template visit<get_acc_link_payload>(l);
198 struct get_mask_link_payload {
199 template <
typename mask_group_t,
typename idx_range_t>
200 inline auto operator()(
const mask_group_t& mask_group,
201 const idx_range_t& idx_range)
const {
202 std::vector<mask_payload> payloads{};
213 template <detray::concepts::algebra algebra_t>
214 struct get_material_link_payload {
215 template <
typename material_group_t,
typename index_t>
216 constexpr auto operator()(
const material_group_t& ,
217 const index_t& index)
const {
218 using material_t =
typename material_group_t::value_type;
221 if constexpr (detray::concepts::grid<material_t>) {
222 return detail::basic_converter::to_payload(
223 io::detail::get_id<material_t>(), index);
225 return detail::basic_converter::to_payload(
226 io::detail::get_id<algebra_t, material_t>(), index);
232 struct get_acc_link_payload {
233 template <
typename acc_group_t,
typename index_t>
234 constexpr auto operator()(
const acc_group_t& ,
235 const index_t& index)
const {
236 using accel_t =
typename acc_group_t::value_type;
238 auto id{acc_links_payload::type_id::unknown};
241 if constexpr (detray::concepts::surface_grid<accel_t>) {
242 id = io::detail::get_id<accel_t>();
245 return detail::basic_converter::to_payload(
id, index);
Facade for a detray detector surface.
Definition surface.hpp:36
constexpr auto source() const
Definition surface.hpp:146
constexpr auto transform(const context &ctx) const -> const transform3_type &
Definition surface.hpp:197
constexpr auto id() const -> surface_id
Definition surface.hpp:131
constexpr auto identifier() const -> geometry::identifier
Definition surface.hpp:110
constexpr bool has_material() const
Definition surface.hpp:170
Tracking geometry writer backend.
Definition geometry_writer.hpp:33
static surface_payload to_payload(const geometry::surface< detector_t > &sf, std::size_t sf_idx)
Convert a detector surface sf into its io payload.
Definition geometry_writer.hpp:129
static volume_payload to_payload(const typename detector_t::volume_type &vol_desc, const detector_t &det, const std::string_view name)
Convert a detector volume and its contents to its IO representation.
Definition geometry_writer.hpp:155
static payload_type to_payload(const detector_t &det, const typename detector_t::name_map &names)
Convert a detector det into its io payload.
Definition geometry_writer.hpp:67
static mask_payload to_payload(const mask_t &m)
Convert a surface mask m into its io payload.
Definition geometry_writer.hpp:109
static geo_header_payload header_to_payload(const detector_t &det, const std::string_view det_name)
Convert the header information into its payload.
Definition geometry_writer.hpp:47
detector_payload payload_type
Payload type that the reader processes.
Definition geometry_writer.hpp:39
static transform_payload to_payload(const typename detector_t::transform3_type &trf)
Convert a surface transform trf into its io payload.
Definition geometry_writer.hpp:88
static constexpr std::string_view tag
Tag the writer as "geometry".
Definition geometry_writer.hpp:36
Mask a region on a surface and link it to a volume.
Definition mask.hpp:46
The following enums are global for all detectors.
Definition concepts.hpp:18
header_payload< geo_sub_header_payload > geo_header_payload
a payload for the geometry file header
Definition payloads.hpp:91
A payload for a detector geometry.
Definition payloads.hpp:355
std::vector< volume_payload > volumes
Material payloads grouped by detector volume.
Definition payloads.hpp:357
A payload object for surface masks.
Definition payloads.hpp:135
mask_shape shape
Shape used to interpret the boundary values.
Definition payloads.hpp:144
single_link_payload volume_link
Sensitive/passive surface: Mother volume index, Portal: Volume the portal leads into,...
Definition payloads.hpp:147
std::vector< io::scalar > boundaries
Boundary values according to boundaries enum of the shape in shape.
Definition payloads.hpp:149
A payload for surfaces.
Definition payloads.hpp:153
std::optional< std::uint64_t > identifier
Write the surface identifier as an additional information.
Definition payloads.hpp:166
detray::surface_id type
Either sensitive, passive or portal.
Definition payloads.hpp:169
std::optional< material_link_payload > material
Write the material link of the surface as additional information.
Definition payloads.hpp:162
transform_payload transform
Placement transform of the surface.
Definition payloads.hpp:158
std::optional< std::size_t > index_in_coll
Position of the surface in the volume surface container.
Definition payloads.hpp:156
std::vector< mask_payload > masks
Mask definitions attached to the surface.
Definition payloads.hpp:160
std::uint64_t source
Identifier of the source object (e.g. value of ACTS::GeometryIdentifier).
Definition payloads.hpp:164
A payload for volumes.
Definition payloads.hpp:173
std::vector< surface_payload > surfaces
Surfaces belonging to this volume.
Definition payloads.hpp:181
detray::volume_id type
Geometric shape or category of the volume.
Definition payloads.hpp:177
single_link_payload index
Index of the volume in the detector volume container.
Definition payloads.hpp:183
transform_payload transform
Placement transform of the volume.
Definition payloads.hpp:179
std::string name
Detector-local volume name.
Definition payloads.hpp:175
std::optional< std::vector< acc_links_payload > > acc_links
Optional accelerator data structures.
Definition payloads.hpp:185
interface type to construct a subrange_view with CTAD
Definition subrange.hpp:90