Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:57

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s).
0012 #include "detray/geometry/tracking_volume.hpp"
0013 
0014 // System include(s)
0015 #include <memory>
0016 #include <string>
0017 #include <string_view>
0018 
0019 namespace detray {
0020 
0021 template <typename detector_t>
0022 class surface_factory_interface;
0023 
0024 template <typename detector_t>
0025 class volume_decorator;
0026 
0027 /// @brief Interface for volume builders (and volume builder decorators)
0028 template <typename detector_t>
0029 class volume_builder_interface {
0030   // Access protected methods
0031   friend class volume_decorator<detector_t>;
0032 
0033  public:
0034   using algebra_type = typename detector_t::algebra_type;
0035   using scalar_type = dscalar<algebra_type>;
0036 
0037   virtual ~volume_builder_interface() = default;
0038 
0039   /// @returns the global index for the volume
0040   /// @note the correct index is only available after calling @c init_vol
0041   DETRAY_HOST
0042   virtual auto vol_index() const -> dindex = 0;
0043 
0044   /// Toggles whether sensitive surfaces are added to the brute force method
0045   DETRAY_HOST
0046   virtual void has_accel(bool toggle) = 0;
0047 
0048   /// @returns whether sensitive surfaces are added to the brute force method
0049   DETRAY_HOST
0050   virtual bool has_accel() const = 0;
0051 
0052   /// Sets the name @param volume_name for the volume
0053   DETRAY_HOST
0054   virtual void set_name(std::string volume_name) = 0;
0055 
0056   /// @returns the name of the volume
0057   DETRAY_HOST
0058   virtual std::string_view name() = 0;
0059 
0060   /// @returns reading access to the volume
0061   DETRAY_HOST
0062   virtual auto operator()() const -> const
0063       typename detector_t::volume_type & = 0;
0064   DETRAY_HOST
0065   virtual auto operator()() -> typename detector_t::volume_type & = 0;
0066 
0067   /// @brief Adds a volume and all of its contents to a detector
0068   DETRAY_HOST
0069   virtual auto build(detector_t &det,
0070                      typename detector_t::geometry_context ctx = {}) ->
0071       typename detector_t::volume_type * = 0;
0072 
0073   /// @brief Add the transform for the volume placement - copy
0074   DETRAY_HOST
0075   virtual void add_volume_placement(
0076       const dtransform3D<algebra_type> &trf = {}) = 0;
0077 
0078   /// @brief Add the transform for the volume placement from the translation
0079   /// @param t. The rotation will be the identity matrix.
0080   DETRAY_HOST
0081   virtual void add_volume_placement(const dpoint3D<algebra_type> &t) = 0;
0082 
0083   /// @brief Add the transform for the volume placement from the translation
0084   /// @param t , the new x- and z-axis (@param x, @param z).
0085   DETRAY_HOST
0086   virtual void add_volume_placement(const dpoint3D<algebra_type> &t,
0087                                     const dvector3D<algebra_type> &x,
0088                                     const dvector3D<algebra_type> &z) = 0;
0089 
0090   /// @brief Add surfaces to the volume
0091   /// @returns the index range of the sensitives in the temporary surface
0092   /// container used by the factory ( gets final update in @c build() )
0093   DETRAY_HOST
0094   virtual void add_surfaces(
0095       std::shared_ptr<surface_factory_interface<detector_t>> sf_factory,
0096       typename detector_t::geometry_context ctx = {}) = 0;
0097 
0098  protected:
0099   /// Access to builder data
0100   /// @{
0101   virtual typename detector_t::surface_lookup_container &surfaces() = 0;
0102   virtual typename detector_t::transform_container &transforms() = 0;
0103   virtual typename detector_t::mask_container &masks() = 0;
0104   /// @}
0105 };
0106 
0107 /// @brief Decorator for the volume builder.
0108 ///
0109 /// Can be volume builders that introduce special sorting/memory layout, or
0110 /// accelerator builders, like the grid builder.
0111 template <typename detector_t>
0112 class volume_decorator : public volume_builder_interface<detector_t> {
0113  public:
0114   using scalar_t = dscalar<typename detector_t::algebra_type>;
0115 
0116   DETRAY_HOST
0117   explicit volume_decorator(
0118       std::unique_ptr<volume_builder_interface<detector_t>> vol_builder)
0119       : m_builder(std::move(vol_builder)) {
0120     assert(m_builder != nullptr);
0121   }
0122 
0123   DETRAY_HOST
0124   auto operator()() -> typename detector_t::volume_type & override {
0125     return m_builder->operator()();
0126   }
0127 
0128   DETRAY_HOST
0129   auto operator()() const -> const typename detector_t::volume_type & override {
0130     return m_builder->operator()();
0131   }
0132 
0133   DETRAY_HOST
0134   auto vol_index() const -> dindex override { return m_builder->vol_index(); }
0135 
0136   DETRAY_HOST
0137   void has_accel(bool toggle) override { m_builder->has_accel(toggle); };
0138 
0139   DETRAY_HOST
0140   bool has_accel() const override { return m_builder->has_accel(); }
0141 
0142   DETRAY_HOST
0143   void set_name(std::string volume_name) override {
0144     return m_builder->set_name(volume_name);
0145   }
0146 
0147   DETRAY_HOST std::string_view name() override { return m_builder->name(); }
0148 
0149   DETRAY_HOST
0150   auto build(detector_t &det,
0151              typename detector_t::geometry_context /*ctx*/ = {}) ->
0152       typename detector_t::volume_type * override {
0153     return m_builder->build(det);
0154   }
0155 
0156   DETRAY_HOST
0157   void add_volume_placement(
0158       const typename detector_t::transform3_type &trf = {}) override {
0159     return m_builder->add_volume_placement(trf);
0160   }
0161 
0162   DETRAY_HOST
0163   void add_volume_placement(
0164       const typename detector_t::point3_type &t) override {
0165     return m_builder->add_volume_placement(t);
0166   }
0167 
0168   DETRAY_HOST
0169   void add_volume_placement(
0170       const typename detector_t::point3_type &t,
0171       const typename detector_t::vector3_type &x,
0172       const typename detector_t::vector3_type &z) override {
0173     return m_builder->add_volume_placement(t, x, z);
0174   }
0175 
0176   DETRAY_HOST
0177   void add_surfaces(
0178       std::shared_ptr<surface_factory_interface<detector_t>> sf_factory,
0179       typename detector_t::geometry_context ctx = {}) override {
0180     return m_builder->add_surfaces(std::move(sf_factory), ctx);
0181   }
0182   /// @}
0183 
0184  protected:
0185   /// Access to underlying builder
0186   /// @{
0187   volume_builder_interface<detector_t> *get_builder() {
0188     return m_builder.get();
0189   }
0190   typename detector_t::surface_lookup_container &surfaces() override {
0191     return m_builder->surfaces();
0192   }
0193   typename detector_t::transform_container &transforms() override {
0194     return m_builder->transforms();
0195   }
0196   typename detector_t::mask_container &masks() override {
0197     return m_builder->masks();
0198   }
0199   /// @}
0200 
0201  private:
0202   std::unique_ptr<volume_builder_interface<detector_t>> m_builder;
0203 };
0204 
0205 }  // namespace detray