ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
volume_builder_interface.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/core/concepts.hpp"
13#include "detray/geometry/tracking_volume.hpp"
14
15// System include(s)
16#include <memory>
17#include <string>
18#include <string_view>
19
20namespace detray {
21
22template <concepts::detector detector_t>
24
25template <concepts::detector detector_t>
27
32 bool m_deduplicate{true};
35 bool m_sort{true};
36
40 constexpr bool deduplicate() const { return m_deduplicate; }
43 constexpr bool sort() const { return m_sort; }
45
50 constexpr volume_builder_options &deduplicate(bool toggle) {
51 m_deduplicate = toggle;
52 return *this;
53 }
54
57 constexpr volume_builder_options &sort(bool toggle) {
58 m_sort = toggle;
59 return *this;
60 }
61
62};
63
65template <concepts::detector detector_t>
67 // Access protected methods
68 friend class volume_decorator<detector_t>;
69
70 public:
72 using algebra_type = typename detector_t::algebra_type;
75
76 virtual ~volume_builder_interface() = default;
77
80 DETRAY_HOST
81 virtual auto vol_index() const -> dindex = 0;
82
85 DETRAY_HOST
86 virtual void has_accel(bool toggle) = 0;
87
89 DETRAY_HOST
90 virtual bool has_accel() const = 0;
91
94 DETRAY_HOST
95 virtual void set_name(std::string volume_name) = 0;
96
98 DETRAY_HOST
99 virtual std::string_view name() = 0;
100
103 DETRAY_HOST
104 virtual auto operator()() const -> const
105 typename detector_t::volume_type & = 0;
108 DETRAY_HOST
109 virtual auto operator()() -> typename detector_t::volume_type & = 0;
110
116 DETRAY_HOST
117 virtual auto build(detector_t &det, const volume_builder_options &opt,
118 typename detector_t::geometry_context ctx = {}) ->
119 typename detector_t::volume_type * = 0;
120
123 DETRAY_HOST
125 const dtransform3D<algebra_type> &trf = {}) = 0;
126
130 DETRAY_HOST
132
138 DETRAY_HOST
141 const dvector3D<algebra_type> &z) = 0;
142
146 DETRAY_HOST
147 virtual void add_surfaces(
148 std::shared_ptr<surface_factory_interface<detector_t>> sf_factory,
149 typename detector_t::geometry_context ctx = {}) = 0;
150
151 protected:
155 virtual typename detector_t::surface_lookup_container &surfaces() = 0;
158 virtual typename detector_t::transform_container &transforms() = 0;
161 virtual typename detector_t::mask_container &masks() = 0;
163};
164
169template <concepts::detector detector_t>
170class volume_decorator : public volume_builder_interface<detector_t> {
171 public:
174
177 DETRAY_HOST
179 std::unique_ptr<volume_builder_interface<detector_t>> vol_builder)
180 : m_builder(std::move(vol_builder)) {
181 assert(m_builder != nullptr);
182 }
183
186 DETRAY_HOST
187 auto operator()() -> typename detector_t::volume_type & override {
188 return m_builder->operator()();
189 }
190
193 DETRAY_HOST
194 auto operator()() const -> const typename detector_t::volume_type & override {
195 return m_builder->operator()();
196 }
197
200 DETRAY_HOST
201 auto vol_index() const -> dindex override { return m_builder->vol_index(); }
202
205 DETRAY_HOST
206 void has_accel(bool toggle) override { m_builder->has_accel(toggle); };
207
210 DETRAY_HOST
211 bool has_accel() const override { return m_builder->has_accel(); }
212
215 DETRAY_HOST
216 void set_name(std::string volume_name) override {
217 return m_builder->set_name(volume_name);
218 }
219
222 DETRAY_HOST std::string_view name() override { return m_builder->name(); }
223
228 DETRAY_HOST
229 auto build(detector_t &det, const volume_builder_options &opt,
230 typename detector_t::geometry_context /*ctx*/ = {}) ->
231 typename detector_t::volume_type * override {
232 return m_builder->build(det, opt);
233 }
234
237 DETRAY_HOST
239 const typename detector_t::transform3_type &trf = {}) override {
240 return m_builder->add_volume_placement(trf);
241 }
242
245 DETRAY_HOST
247 const typename detector_t::point3_type &t) override {
248 return m_builder->add_volume_placement(t);
249 }
250
255 DETRAY_HOST
257 const typename detector_t::point3_type &t,
258 const typename detector_t::vector3_type &x,
259 const typename detector_t::vector3_type &z) override {
260 return m_builder->add_volume_placement(t, x, z);
261 }
262
266 DETRAY_HOST
268 std::shared_ptr<surface_factory_interface<detector_t>> sf_factory,
269 typename detector_t::geometry_context ctx = {}) override {
270 return m_builder->add_surfaces(std::move(sf_factory), ctx);
271 }
272
273 protected:
279 return m_builder.get();
280 }
281
283 typename detector_t::surface_lookup_container &surfaces() override {
284 return m_builder->surfaces();
285 }
286
288 typename detector_t::transform_container &transforms() override {
289 return m_builder->transforms();
290 }
291
293 typename detector_t::mask_container &masks() override {
294 return m_builder->masks();
295 }
296
297
298 private:
299 std::unique_ptr<volume_builder_interface<detector_t>> m_builder;
300};
301
302} // namespace detray
How to generate surfaces with their corresponding masks and transforms.
Definition surface_factory_interface.hpp:120
Interface for volume builders (and volume builder decorators).
Definition volume_builder_interface.hpp:66
dscalar< algebra_type > scalar_type
Scalar type used by the detector's algebra.
Definition volume_builder_interface.hpp:74
virtual void set_name(std::string volume_name)=0
Sets the name volume_name for the volume.
virtual detector_t::transform_container & transforms()=0
Returns mutable access to the builder's transforms.
virtual detector_t::surface_lookup_container & surfaces()=0
Access to builder data.
typename detector_t::algebra_type algebra_type
Algebra type used by the detector.
Definition volume_builder_interface.hpp:72
virtual void add_volume_placement(const dpoint3D< algebra_type > &t, const dvector3D< algebra_type > &x, const dvector3D< algebra_type > &z)=0
Add the transform for the volume placement from the translation t , the new x- and z-axis (x,...
virtual auto vol_index() const -> dindex=0
virtual void add_volume_placement(const dpoint3D< algebra_type > &t)=0
Add the transform for the volume placement from the translation t.
virtual auto build(detector_t &det, const volume_builder_options &opt, typename detector_t::geometry_context ctx={}) -> typename detector_t::volume_type *=0
Adds a volume and all of its contents to a detector.
virtual void add_surfaces(std::shared_ptr< surface_factory_interface< detector_t > > sf_factory, typename detector_t::geometry_context ctx={})=0
Add surfaces to the volume.
virtual detector_t::mask_container & masks()=0
Returns mutable access to the builder's masks.
virtual void has_accel(bool toggle)=0
Toggles whether sensitive surfaces are added to the brute force method.
virtual void add_volume_placement(const dtransform3D< algebra_type > &trf={})=0
Add the transform for the volume placement - copy.
virtual std::string_view name()=0
Decorator for the volume builder.
Definition volume_builder_interface.hpp:170
dscalar< typename detector_t::algebra_type > scalar_t
Scalar type used by the detector's algebra.
Definition volume_builder_interface.hpp:173
auto operator()() const -> const typename detector_t::volume_type &override
Returns const access to the wrapped volume.
Definition volume_builder_interface.hpp:194
void add_volume_placement(const typename detector_t::point3_type &t, const typename detector_t::vector3_type &x, const typename detector_t::vector3_type &z) override
Adds a placement using a translation and its x- and z-axes.
Definition volume_builder_interface.hpp:256
detector_t::transform_container & transforms() override
Returns mutable access to the wrapped builder's transforms.
Definition volume_builder_interface.hpp:288
std::string_view name() override
Returns the wrapped volume's name.
Definition volume_builder_interface.hpp:222
void set_name(std::string volume_name) override
Sets the wrapped volume's name.
Definition volume_builder_interface.hpp:216
volume_decorator(std::unique_ptr< volume_builder_interface< detector_t > > vol_builder)
Wraps a volume builder.
Definition volume_builder_interface.hpp:178
void add_volume_placement(const typename detector_t::transform3_type &trf={}) override
Adds a placement transform to the wrapped builder.
Definition volume_builder_interface.hpp:238
volume_builder_interface< detector_t > * get_builder()
Access to underlying builderReturns a pointer to the wrapped builder.
Definition volume_builder_interface.hpp:278
detector_t::surface_lookup_container & surfaces() override
Returns mutable access to the wrapped builder's surface lookup container.
Definition volume_builder_interface.hpp:283
detector_t::mask_container & masks() override
Returns mutable access to the wrapped builder's masks.
Definition volume_builder_interface.hpp:293
void add_surfaces(std::shared_ptr< surface_factory_interface< detector_t > > sf_factory, typename detector_t::geometry_context ctx={}) override
Adds surfaces through the wrapped builder's factory interface.
Definition volume_builder_interface.hpp:267
auto operator()() -> typename detector_t::volume_type &override
Returns the mutable volume being built.
Definition volume_builder_interface.hpp:187
void add_volume_placement(const typename detector_t::point3_type &t) override
Adds a placement using a translation and identity rotation.
Definition volume_builder_interface.hpp:246
auto build(detector_t &det, const volume_builder_options &opt, typename detector_t::geometry_context={}) -> typename detector_t::volume_type *override
Builds the wrapped volume in the detector.
Definition volume_builder_interface.hpp:229
bool has_accel() const override
Returns whether sensitive surfaces are added to brute force lookup.
Definition volume_builder_interface.hpp:211
void has_accel(bool toggle) override
Forwards the brute-force acceleration setting to the wrapped builder.
Definition volume_builder_interface.hpp:206
auto vol_index() const -> dindex override
Returns the index assigned by the wrapped builder.
Definition volume_builder_interface.hpp:201
Detray include(s).
Definition array_operators.hpp:18
get_scalar_t< A, T > dscalar
Scalar type for algebra A and value type T.
Definition algebra.hpp:64
unsigned int dindex
Default index type.
Definition indexing.hpp:18
get_vector3D_t< A, T > dvector3D
Three-dimensional vector type for algebra A and value type T.
Definition algebra.hpp:80
get_transform3D_t< A, T > dtransform3D
Three-dimensional transform type for algebra A and value type T.
Definition algebra.hpp:84
get_point3D_t< A, T > dpoint3D
Three-dimensional point type for algebra A and value type T.
Definition algebra.hpp:72
Options for the volume builder classes.
Definition volume_builder_interface.hpp:29
constexpr volume_builder_options & deduplicate(bool toggle)
Setters.
Definition volume_builder_interface.hpp:50
constexpr volume_builder_options & sort(bool toggle)
Sets whether global sorting is enabled.
Definition volume_builder_interface.hpp:57
bool m_deduplicate
Globally deduplicate identical data that is added by a builder to the detector.
Definition volume_builder_interface.hpp:32
constexpr bool sort() const
Returns whether global sorting is enabled.
Definition volume_builder_interface.hpp:43
bool m_sort
Globally sort data including the one that is added by a builder to the detector.
Definition volume_builder_interface.hpp:35
constexpr bool deduplicate() const
Getters.
Definition volume_builder_interface.hpp:40