Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-18 09:33:11

0001 // This file is part of VecGeom and is distributed under the
0002 // conditions in the file LICENSE.txt in the top directory.
0003 // For the full list of authors see CONTRIBUTORS.txt and `git log`.
0004 
0005 /// \brief A collection of template helpers to automize implementation
0006 ///        of UnplacedVolume interfaces.
0007 /// \file volumes/UnplacedVolumeImplHelper.h
0008 /// \author First version created by Sandro Wenzel
0009 
0010 #ifndef VOLUMES_UNPLACEDVOLUMEIMPLHELPER_H_
0011 #define VOLUMES_UNPLACEDVOLUMEIMPLHELPER_H_
0012 
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/volumes/UnplacedVolume.h"
0015 #include "VecGeom/management/VolumeFactory.h"
0016 
0017 namespace vecgeom {
0018 
0019 inline namespace VECGEOM_IMPL_NAMESPACE {
0020 
0021 /*!
0022  * A template class with the aim to automatically implement
0023  * interfaces of UnplacedVolume by connecting them to the separately
0024  * available (reusable) kernels.
0025  *
0026  * This is an application of the CRT pattern in order to reduce
0027  * repeating code.
0028  */
0029 template <class Implementation, class BaseUnplVol = VUnplacedVolume>
0030 class UnplacedVolumeImplHelper : public BaseUnplVol {
0031 
0032 public:
0033   using UnplacedStruct_t = typename Implementation::UnplacedStruct_t;
0034   using UnplacedVolume_t = typename Implementation::UnplacedVolume_t;
0035 
0036   // bring in constructors
0037   using BaseUnplVol::BaseUnplVol;
0038   // bring in some members from base (to avoid name hiding)
0039   using BaseUnplVol::DistanceToIn;
0040   using BaseUnplVol::DistanceToOut;
0041   using BaseUnplVol::SafetyToIn;
0042   using BaseUnplVol::SafetyToOut;
0043 
0044   VECCORE_ATT_HOST_DEVICE
0045   VECGEOM_FORCE_INLINE
0046   virtual Precision DistanceToOut(Vector3D<Precision> const &p, Vector3D<Precision> const &d,
0047                                   Precision step_max = kInfLength) const override
0048   {
0049     VECGEOM_ASSERT(d.IsNormalized() && " direction not normalized in call to  DistanceToOut ");
0050     Precision output = kInfLength;
0051     Implementation::template DistanceToOut<>(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, d, step_max,
0052                                              output);
0053 
0054 // detect -inf responses which are often an indication for a real bug
0055 #ifndef VECCORE_CUDA
0056     VECGEOM_ASSERT(!((output < 0.) && std::isinf((Precision)output)));
0057 #endif
0058     return output;
0059   }
0060 
0061   VECCORE_ATT_HOST_DEVICE
0062   VECGEOM_FORCE_INLINE
0063   virtual bool Contains(Vector3D<Precision> const &p) const override
0064   {
0065     bool output(false);
0066     Implementation::Contains(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, output);
0067     return output;
0068   }
0069 
0070   VECCORE_ATT_HOST_DEVICE
0071   VECGEOM_FORCE_INLINE
0072   virtual EnumInside Inside(Vector3D<Precision> const &p) const override
0073   {
0074     Inside_t output(0);
0075     Implementation::Inside(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, output);
0076     return (EnumInside)output;
0077   }
0078 
0079   VECCORE_ATT_HOST_DEVICE
0080   virtual Precision DistanceToIn(Vector3D<Precision> const &p, Vector3D<Precision> const &d,
0081                                  const Precision step_max = kInfLength) const override
0082   {
0083     VECGEOM_ASSERT(d.IsNormalized() && " direction not normalized in call to  DistanceToOut ");
0084     Precision output(kInfLength);
0085     Implementation::DistanceToIn(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, d, step_max, output);
0086     return output;
0087   }
0088 
0089   VECCORE_ATT_HOST_DEVICE
0090   virtual Precision SafetyToOut(Vector3D<Precision> const &p) const override
0091   {
0092     Precision output(kInfLength);
0093     Implementation::SafetyToOut(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, output);
0094     return output;
0095   }
0096 
0097   VECCORE_ATT_HOST_DEVICE
0098   virtual Precision SafetyToIn(Vector3D<Precision> const &p) const override
0099   {
0100     Precision output(kInfLength);
0101     Implementation::SafetyToIn(((UnplacedVolume_t *)this)->UnplacedVolume_t::GetStruct(), p, output);
0102     return output;
0103   }
0104 
0105   virtual int MemorySize() const override { return sizeof(*this); }
0106 };
0107 } // namespace VECGEOM_IMPL_NAMESPACE
0108 } // namespace vecgeom
0109 
0110 #endif /* VOLUMES_UnplacedVolumeImplHelper_H_ */