ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
material_map_writer.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 CERN for the benefit of the ACTS project
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/io/backend/detail/grid_writer.hpp"
13#include "detray/io/backend/detail/type_info.hpp"
14#include "detray/io/backend/homogeneous_material_writer.hpp"
15#include "detray/io/frontend/payloads.hpp"
16#include "detray/material/material_slab.hpp"
17
18// System include(s)
19#include <string_view>
20
21namespace detray::io {
22
26class material_map_writer : public detail::grid_writer {
27 using base_type = detail::grid_writer;
28 using grid_writer_t = base_type;
29 using mat_writer_t = homogeneous_material_writer;
30
31 public:
33 static constexpr std::string_view tag = "material_maps";
34
38
40 using base_type::base_type;
41
47 template <class detector_t>
48 static auto header_to_payload(const detector_t& det,
49 const std::string_view det_name) {
50 return grid_writer_t::header_to_payload(tag, det.material_store(),
51 det_name);
52 }
53
59 template <class detector_t>
61 const detector_t& det, const typename detector_t::name_map& /*unused*/) {
62 using algebra_t = typename detector_t::algebra_type;
64
65 payload_type grids_data;
66
67 for (const auto& vol_desc : det.volumes()) {
68 // Volume local surface indices
69 dindex offset{dindex_invalid};
70
72 auto vol = tracking_volume{det, vol_desc};
73 for (const auto& sf_desc : vol.surfaces()) {
74 if (sf_desc.index() < offset) {
75 offset = sf_desc.index();
76 }
77
78 const auto& mat_link = sf_desc.material();
79 // Don't look at empty links
80 if (mat_link.is_invalid() ||
81 mat_link.id() == detector_t::material::id::e_none) {
82 continue;
83 }
84
85 // Do not attempt to convert homogeneous material
87 if (mat_link.id() == detector_t::material::id::e_material_slab) {
88 continue;
89 }
90 }
92 if (mat_link.id() == detector_t::material::id::e_material_rod) {
93 continue;
94 }
95 }
96
97 // How to convert a material slab in the grid
98 auto mat_converter = [&sf_desc](const material_t& mat) {
99 return mat_writer_t::to_payload<algebra_t>(mat, sf_desc.index());
100 };
101
102 // Generate the payload
103 grid_writer_t::to_payload(det.material_store(), mat_link,
104 vol_desc.index(), sf_desc.index() - offset,
105 grids_data, mat_converter);
106 }
107 }
108
109 return grids_data;
110 }
111};
112
113} // namespace detray::io
Homogeneous material writer backend.
Definition homogeneous_material_writer.hpp:32
static payload_type to_payload(const detector_t &det, const typename detector_t::name_map &)
Convert the material description of a detector det into its io payload.
Definition homogeneous_material_writer.hpp:100
Material maps writer backend.
Definition material_map_writer.hpp:26
static constexpr std::string_view tag
Tag the writer as "material_map".
Definition material_map_writer.hpp:33
static auto header_to_payload(const detector_t &det, const std::string_view det_name)
Convert the header information into its payload.
Definition material_map_writer.hpp:48
detector_grids_payload< surface_material_payload, io::material_id > payload_type
Payload type that the reader processes.
Definition material_map_writer.hpp:36
static payload_type to_payload(const detector_t &det, const typename detector_t::name_map &)
Convert the material description of a detector det into its io payload.
Definition material_map_writer.hpp:60
Facade for a detray detector volume.
Definition tracking_volume.hpp:44
Check for the the presence of material rods in a detector definition.
Definition concepts.hpp:146
Check for the the presence of material slabs in a detector definition.
Definition concepts.hpp:141
The following enums are global for all detectors.
Definition concepts.hpp:18
unsigned int dindex
Default index type.
Definition indexing.hpp:18
constexpr dindex dindex_invalid
Global invalid index definition.
Definition indexing.hpp:21
A payload for the grid collections of a detector.
Definition payloads.hpp:344
Slab structure to be mapped on the mask (plane, cylinder).
Definition material_slab.hpp:25