Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-19 09:40:42

0001 //@author: initial implementation Sandro Wenzel (July 2018)
0002 #ifndef VOLUMES_SUNPLACEDVOLUME_IMPLAS_H_
0003 #define VOLUMES_SUNPLACEDVOLUME_IMPLAS_H_
0004 
0005 #include "VecGeom/base/Global.h"
0006 #include "VecGeom/volumes/UnplacedVolume.h"
0007 #include "VecGeom/management/VolumeFactory.h"
0008 #include "VecGeom/volumes/PlacedVolImplHelper.h"
0009 #include "VecGeom/volumes/SpecializedPlacedVolImplHelper.h"
0010 #include "VecGeom/volumes/kernel/ImplAsImplementation.h"
0011 #include "VecGeom/base/Assert.h"
0012 #include <type_traits>
0013 
0014 namespace vecgeom {
0015 
0016 VECGEOM_DEVICE_DECLARE_CONV_TEMPLATE_2t(class, SUnplacedImplAs, typename, typename);
0017 
0018 inline namespace VECGEOM_IMPL_NAMESPACE {
0019 
0020 // A wrapper class which generically implements a specialization of UnplacedBase
0021 // implemented in terms of another **existing** implementing volume ImplementingUnplaced.
0022 template <typename UnplacedBase, typename ImplementingUnplaced>
0023 class SUnplacedImplAs : public UnplacedBase {
0024   // static VECGEOM_ASSERT(make sure UnplacedBase is an UnplacedVolume
0025 
0026 public:
0027   using UnplacedStruct_t = typename ImplementingUnplaced::UnplacedStruct_t;
0028 
0029   template <typename... Args>
0030   SUnplacedImplAs(Args... args) : UnplacedBase(args...)
0031   {
0032     fImplPtr = new ImplementingUnplaced(args...);
0033   }
0034 
0035   // implement the important unplaced volume interfaces
0036   VECCORE_ATT_HOST_DEVICE
0037   bool Contains(Vector3D<Precision> const &p) const override { return fImplPtr->ImplementingUnplaced::Contains(p); }
0038 
0039   VECCORE_ATT_HOST_DEVICE
0040   EnumInside Inside(Vector3D<Precision> const &p) const override { return fImplPtr->ImplementingUnplaced::Inside(p); }
0041 
0042   // DistanceToOut
0043   VECCORE_ATT_HOST_DEVICE
0044   Precision DistanceToOut(Vector3D<Precision> const &p, Vector3D<Precision> const &d,
0045                           Precision step_max = kInfLength) const override
0046   {
0047     return fImplPtr->ImplementingUnplaced::DistanceToOut(p, d, step_max);
0048   }
0049 
0050   // SafetyToOut
0051   VECCORE_ATT_HOST_DEVICE
0052   Precision SafetyToOut(Vector3D<Precision> const &p) const override
0053   {
0054     return fImplPtr->ImplementingUnplaced::SafetyToOut(p);
0055   }
0056 
0057   VECCORE_ATT_HOST_DEVICE
0058   Precision SafetyToIn(Vector3D<Precision> const &position) const override
0059   {
0060     return fImplPtr->ImplementingUnplaced::SafetyToIn(position);
0061   }
0062 
0063   // ---------------- SamplePointOnSurface ----------------------------------------------------------
0064   Vector3D<Precision> SamplePointOnSurface() const override
0065   {
0066     return fImplPtr->ImplementingUnplaced::SamplePointOnSurface();
0067   }
0068 
0069   // ----------------- Extent --------------------------------------------------------------------
0070   VECCORE_ATT_HOST_DEVICE
0071   void Extent(Vector3D<Precision> &aMin, Vector3D<Precision> &aMax) const override
0072   {
0073     fImplPtr->ImplementingUnplaced::Extent(aMin, aMax);
0074   }
0075 
0076   using StructType = decltype(std::declval<ImplementingUnplaced>().GetStruct());
0077   VECCORE_ATT_HOST_DEVICE
0078   StructType GetStruct() const { return fImplPtr->ImplementingUnplaced::GetStruct(); }
0079 
0080 private:
0081   // select target specialization helpers with SFINAE
0082   template <typename IUnplaced, typename ImplementingKernel>
0083   VPlacedVolume *changeTypeKeepTransformation(VPlacedVolume const *p) const
0084   {
0085     auto c = VolumeFactory::ChangeTypeKeepTransformation<SpecializedVolImplHelper, ImplementingKernel>(p);
0086     return c;
0087   }
0088 
0089   VPlacedVolume *SpecializedVolume(LogicalVolume const *const volume, Transformation3D const *const transformation,
0090                                    VPlacedVolume *const placement = NULL) const override
0091   {
0092     auto p = fImplPtr->ImplementingUnplaced::SpecializedVolume(volume, transformation, placement);
0093 
0094     using ImplementingKernel = IndirectImplementation<SUnplacedImplAs<UnplacedBase, ImplementingUnplaced>,
0095                                                       typename ImplementingUnplaced::Kernel>;
0096 
0097     // the right function to use will be selected with SFINAE and enable_if
0098     return changeTypeKeepTransformation<ImplementingUnplaced, ImplementingKernel>(p);
0099     // TODO: original p is no longer needed in principle: delete and deregister from GeoManager
0100     // delete p;
0101   }
0102 
0103   ImplementingUnplaced *fImplPtr;
0104 };
0105 } // namespace VECGEOM_IMPL_NAMESPACE
0106 } // namespace vecgeom
0107 
0108 #endif /* VOLUMES_SUNPLACEDVOLUME_IMPLAS_H_ */