12#include "detray/builders/volume_builder.hpp"
13#include "detray/builders/volume_builder_interface.hpp"
14#include "detray/core/concepts.hpp"
15#include "detray/core/detector.hpp"
16#include "detray/utils/detector_statistics.hpp"
17#include "detray/utils/logging.hpp"
20#include <vecmem/memory/memory_resource.hpp>
39 template <
typename...>
class volume_data_t = std::vector>
40class detector_builder {
51 DETRAY_HOST detector_builder() { DETRAY_VERBOSE_HOST(
"New builder created"); }
55 DETRAY_HOST
void set_name(std::string det_name) {
56 m_detector_name = std::move(det_name);
57 DETRAY_VERBOSE_HOST(
"Set detector name: " << m_detector_name);
61 DETRAY_HOST std::string_view
name()
const {
return m_detector_name; }
68 template <
typename... Args>
71 DETRAY_VERBOSE_HOST(
"Adding new volume: " << m_volumes.size());
73 m_volumes.push_back(std::make_unique<volume_builder_t<detector_type>>(
74 id,
static_cast<dindex>(m_volumes.size()),
75 std::forward<Args>(args)...));
77 return m_volumes.back().get();
82 return static_cast<dindex>(m_volumes.size());
88 DETRAY_HOST
bool has_volume(
const std::size_t volume_idx)
const {
89 return volume_idx < m_volumes.size();
96 template <
class builder_t>
100 m_volumes[volume_idx] =
101 std::make_unique<builder_t>(std::move(m_volumes[volume_idx]));
104 return dynamic_cast<builder_t*
>(m_volumes[volume_idx].get());
110 template <
class builder_t>
113 assert(v_builder !=
nullptr);
124 return m_volumes[volume_idx].get();
133 auto build(vecmem::memory_resource& resource,
135 DETRAY_INFO_HOST(
"Building detector: \"" <<
name() <<
"\"... ");
136 DETRAY_INFO_HOST(
"-> type: " << DETRAY_TYPENAME(metadata_t));
140 DETRAY_VERBOSE_HOST(
"Have " << m_volumes.size()
141 <<
" configured volume builders");
142 DETRAY_VERBOSE_HOST(
"Start building the volumes...");
143 for (
auto& vol_builder : m_volumes) {
144 DETRAY_VERBOSE_HOST(
"-> Build: " << vol_builder->name());
145 vol_builder->build(det, opt);
152 DETRAY_INFO_HOST(
"-> Built " << det.
volumes().size() <<
" volumes");
153 DETRAY_INFO_HOST(
"-> Built " << det.
surfaces().size() <<
" surfaces:");
160 <<
" surface grids");
165 <<
" material maps");
169 DETRAY_INFO_HOST(
"-> Built homogeneous material:");
173 DETRAY_INFO_HOST(
"Detector building complete: " <<
name());
185 auto build(vecmem::memory_resource& resource,
188 DETRAY_VERBOSE_HOST(
"detray: filling names for detector " <<
name());
195 for (
auto& vol_builder : m_volumes) {
197 std::string{vol_builder->name()});
200 return build(resource, opt);
205 std::string m_detector_name{
"detray_detector"};
207 volume_data_t<std::unique_ptr<volume_builder_interface<detector_type>>>
The detector definition.
Definition detector.hpp:59
typename metadata::algebra_type algebra_type
Definition detector.hpp:87
auto volumes() const -> const vector_type< volume_type > &
Definition detector.hpp:234
detray::name_map name_map
Definition detector.hpp:101
auto surfaces() const -> const surface_lookup_container &
Definition detector.hpp:286
auto build(vecmem::memory_resource &resource, const volume_builder_options &opt) -> detector_type
Assembles the final detector from the volumes builders and allocates the detector containers with the...
Definition detector_builder.hpp:133
auto n_volumes() const -> dindex
Definition detector_builder.hpp:81
dscalar< algebra_type > scalar_type
Scalar type used for geometry values.
Definition detector_builder.hpp:49
void set_name(std::string det_name)
Set the name of the detector under construction to det_name.
Definition detector_builder.hpp:55
typename detector_type::algebra_type algebra_type
Algebra backend used by the detector geometry.
Definition detector_builder.hpp:47
bool has_volume(const std::size_t volume_idx) const
Definition detector_builder.hpp:88
detail::detector< metadata_t, host_container_types > detector_type
Detector type produced from the configured metadata.
Definition detector_builder.hpp:45
std::string_view name() const
Definition detector_builder.hpp:61
auto new_volume(const volume_id id, Args &&... args) -> volume_builder_interface< detector_type > *
Add a new volume builder that will build a volume of the shape given by id.
Definition detector_builder.hpp:69
auto decorate(dindex volume_idx) -> builder_t *
Decorate a volume builder at position volume_idx with more functionality.
Definition detector_builder.hpp:97
auto operator[](dindex volume_idx) -> volume_builder_interface< detector_type > *
Access a particular volume builder by volume index volume_idx.
Definition detector_builder.hpp:122
auto build(vecmem::memory_resource &resource, const volume_builder_options &opt, typename detector_type::name_map &name_map) -> detector_type
Assembles the final detector and fill an externally provided name map name_map.
Definition detector_builder.hpp:185
auto decorate(const volume_builder_interface< detector_type > *v_builder) -> builder_t *
Decorate a volume builder v_builder with more functionality.
Definition detector_builder.hpp:111
Interface for volume builders (and volume builder decorators).
Definition volume_builder_interface.hpp:66
Provides basic functionality to build detector volumes.
Definition volume_builder.hpp:36
Check for the the presence of homogeneous material types in a detector definition.
Definition concepts.hpp:152
Check for the the presence of material maps in a detector definition.
Definition concepts.hpp:158
Check for the the presence of surface grids in a detector definition.
Definition concepts.hpp:136
Detray include(s).
Definition array_operators.hpp:18
std::size_t n_material_rods(const detector_t &det)
Definition detector_statistics.hpp:105
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
volume_id
Shape of a detector volume.
Definition geometry.hpp:27
std::size_t n_material_slabs(const detector_t &det)
Definition detector_statistics.hpp:94
std::size_t n_sensitives(const detector_t &det)
Definition detector_statistics.hpp:36
unsigned int dindex
Default index type.
Definition indexing.hpp:18
std::size_t n_passives(const detector_t &det)
Definition detector_statistics.hpp:48
std::size_t n_portals(const detector_t &det)
Definition detector_statistics.hpp:24
std::size_t n_surface_grids(const detector_t &det)
Definition detector_statistics.hpp:81
std::size_t n_material_maps(const detector_t &det)
Definition detector_statistics.hpp:87
Map volume indices to volume names and vice versa.
Definition name_map.hpp:23
void set_detector_name(const std::string_view name)
set the name of the detector
Definition name_map.hpp:26
void emplace(dindex idx, const std::string &name)
emplace a new index <-> name mapping
Definition name_map.hpp:56
bool empty() const
Definition name_map.hpp:36
Options for the volume builder classes.
Definition volume_builder_interface.hpp:29