Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-23 09:29:54

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 Declaration of the logical volume.
0006 /// \file LogicalVolume.h
0007 /// \author created by Johannes de Fine Licht, Sandro Wenzel (CERN)
0008 
0009 #ifndef VECGEOM_VOLUMES_LOGICALVOLUME_H_
0010 #define VECGEOM_VOLUMES_LOGICALVOLUME_H_
0011 
0012 #include "VecGeom/base/Cuda.h"
0013 #include "VecGeom/base/Global.h"
0014 #include "VecGeom/base/Vector.h"
0015 #include "VecGeom/volumes/UnplacedVolume.h"
0016 
0017 #include <string>
0018 #include <list>
0019 #include <set>
0020 #include <typeindex>
0021 #include <typeinfo>
0022 
0023 class TGeoShape;
0024 
0025 namespace vecgeom {
0026 
0027 VECGEOM_DEVICE_FORWARD_DECLARE(class LogicalVolume;);
0028 VECGEOM_DEVICE_FORWARD_DECLARE(class VPlacedVolume;);
0029 VECGEOM_DEVICE_FORWARD_DECLARE(class VLevelLocator;);
0030 VECGEOM_DEVICE_FORWARD_DECLARE(class VSafetyEstimator;);
0031 VECGEOM_DEVICE_FORWARD_DECLARE(class VNavigator;);
0032 
0033 VECGEOM_DEVICE_DECLARE_CONV(class, LogicalVolume);
0034 class GeoManager;
0035 
0036 inline namespace VECGEOM_IMPL_NAMESPACE {
0037 
0038 class VLevelLocator;
0039 class VSafetyEstimator;
0040 class VNavigator;
0041 typedef VPlacedVolume const *Daughter;
0042 
0043 /**
0044  * \brief Class responsible for storing the list of daughter volumes
0045  *        of an unplaced volume and various associated properties.
0046  *
0047  *  A logical volume adds various properties to unplaced volumes, notably
0048  *  the list of daughter volumes it contains. As such a logical volume
0049  *  describes an un-positioned sub-tree of the geometry hierarchy.
0050  *  The class also holds various pointers to structures associated with
0051  *  unplaced volumes, such as those used by simulation engines for tracking.
0052  *  This class follows largely the class existing in Geant4: G4LogicalVolume.
0053  */
0054 class LogicalVolume {
0055   friend class vecgeom::GeoManager;
0056 
0057 private:
0058   /// Pointer to concrete unplaced volume/shape
0059   VUnplacedVolume const *fUnplacedVolume;
0060 
0061   unsigned int fId; ///< global id of logical volume object
0062 
0063   std::string *fLabel; ///< name of logical volume
0064 
0065   static int gIdCount; ///< a static class counter
0066 
0067   //--- The following pointers are used by VecGeom itself ---
0068 
0069   VLevelLocator const *fLevelLocator;       ///< A locator class for this logical volume.
0070   VSafetyEstimator const *fSafetyEstimator; ///< A safety estimator class for this logical volume.
0071   VNavigator const *fNavigator;             ///< Pointer to attached VecGeom navigator.
0072 
0073   /// The container of daughter (placed) volumes which are placed inside this logical volume
0074   Vector<Daughter> *fDaughters;
0075 
0076   using CudaDaughter_t = cuda::VPlacedVolume const *;
0077   friend class CudaManager;
0078 
0079   // possibility to change pointer of daughter volumes ( can be used by GeoManager )
0080   //  void SetDaughter(unsigned int i, VPlacedVolume const *pvol);
0081 
0082 public:
0083   /// Standard constructor taking a name and an unplaced volume (NOT CUDA compatible)
0084   LogicalVolume(char const *const label, VUnplacedVolume const *const unplaced_vol);
0085 
0086   /// Standard constructor taking an unplaced volume
0087   LogicalVolume(VUnplacedVolume const *const unplaced_vol) : LogicalVolume("", unplaced_vol) {}
0088 
0089 #ifndef VECCORE_CUDA
0090   /// copy operators deleted
0091   LogicalVolume(LogicalVolume const &other)            = delete;
0092   LogicalVolume *operator=(LogicalVolume const &other) = delete;
0093 
0094 #else
0095   VECCORE_ATT_DEVICE
0096   LogicalVolume(VUnplacedVolume const *const unplaced_vol, unsigned int id, Vector<Daughter> *GetDaughter);
0097 #endif
0098 
0099   ~LogicalVolume();
0100 
0101   /// Returns the unplaced volume
0102   VECCORE_ATT_HOST_DEVICE
0103   VECGEOM_FORCE_INLINE
0104   VUnplacedVolume const *GetUnplacedVolume() const { return fUnplacedVolume; }
0105 
0106   // will be deprecated in favour of better encapsulation of internal storage
0107   /// Returns the list of daughter volumes
0108   VECCORE_ATT_HOST_DEVICE
0109   VECGEOM_FORCE_INLINE
0110   Vector<Daughter> const &GetDaughters() const { return *fDaughters; }
0111 
0112   // will be deprecated in favour of better encapsulation of internal storage
0113   /// Returns pointer to the list of daughter volumes
0114   VECCORE_ATT_HOST_DEVICE
0115   VECGEOM_FORCE_INLINE
0116   Vector<Daughter> const *GetDaughtersp() const { return fDaughters; }
0117 
0118   /// Returns pointer to the list of daughter volumes
0119   VECCORE_ATT_HOST_DEVICE
0120   VECGEOM_FORCE_INLINE
0121   Vector<Daughter> *GetDaughtersp() { return fDaughters; }
0122 
0123   /// Returns user request for caching transformations
0124   VECCORE_ATT_HOST_DEVICE
0125   VECGEOM_FORCE_INLINE
0126   bool IsReqCaching() const { return false; }
0127 
0128   //  VECCORE_ATT_HOST_DEVICE
0129   //  VECGEOM_FORCE_INLINE
0130   //  VPlacedVolume const* GetDaughter(unsigned int i) const { return daughters_->operator[](i); }
0131   //
0132   //  VECCORE_ATT_HOST_DEVICE
0133   //  VECGEOM_FORCE_INLINE
0134   //  unsigned int GetNDaughters() const { return daughters_->size(); }
0135 
0136   /// Returns the total number of placeds volume contained in this logical volume AND below.
0137   size_t GetNTotal() const;
0138 
0139   /// Returns value of static instance counter
0140   static unsigned int GetIdCount() { return (unsigned int)gIdCount; }
0141 
0142   /// Returns the level locator (used by VecGeom navigation).
0143   VECCORE_ATT_HOST_DEVICE
0144   VECGEOM_FORCE_INLINE
0145   VLevelLocator const *GetLevelLocator() const { return fLevelLocator; }
0146 
0147   /// Sets the level locator (used by VecGeom navigation).
0148   VECCORE_ATT_HOST_DEVICE
0149   VECGEOM_FORCE_INLINE
0150   void SetLevelLocator(VLevelLocator const *locator) { fLevelLocator = locator; }
0151 
0152   /// Returns the safety estimator (used by VecGeom navigation).
0153   VECCORE_ATT_HOST_DEVICE
0154   VECGEOM_FORCE_INLINE
0155   VSafetyEstimator const *GetSafetyEstimator() const { return fSafetyEstimator; }
0156 
0157   /// Sets the safety estimator (used by VecGeom navigation).
0158   VECCORE_ATT_HOST_DEVICE
0159   VECGEOM_FORCE_INLINE
0160   void SetSafetyEstimator(VSafetyEstimator const *est) { fSafetyEstimator = est; }
0161 
0162   /// Returns the navigator for this logical volume (used by VecGeom navigation).
0163   VECCORE_ATT_HOST_DEVICE
0164   VECGEOM_FORCE_INLINE
0165   VNavigator const *GetNavigator() const { return fNavigator; }
0166 
0167   /// Sets the navigator for this logical volume (used by VecGeom navigation).
0168   VECCORE_ATT_HOST_DEVICE
0169   VECGEOM_FORCE_INLINE
0170   void SetNavigator(VNavigator const *n) { fNavigator = n; }
0171 
0172   /// Returns the id of this logical volume.
0173   VECCORE_ATT_HOST_DEVICE
0174   VECGEOM_FORCE_INLINE
0175   unsigned int id() const { return fId; }
0176 
0177   /// Returns the name of this logical volume.
0178   VECCORE_ATT_HOST_DEVICE
0179   const char *GetName() const
0180   {
0181 #ifndef VECCORE_CUDA
0182     return fLabel->c_str();
0183 #else
0184     return "- Names unavailable on GPU -";
0185 #endif
0186   }
0187   /// Returns the name of this logical volume as string.
0188   std::string const &GetLabel() const { return *fLabel; }
0189 
0190   /// Sets the name/label of this logical volume.
0191   void SetLabel(char const *const label)
0192   {
0193     if (fLabel) delete fLabel;
0194     fLabel = new std::string(label);
0195   }
0196 
0197   /// Print the daughter information of this logical volume with a given indentation.
0198   VECCORE_ATT_HOST_DEVICE
0199   void Print(const int indent = 0) const;
0200 
0201   /// Print the daughter information of this logical volume and of all containing daughters
0202   /// up to a certain depth
0203   VECCORE_ATT_HOST_DEVICE
0204   void PrintContent(const int depth = 0) const;
0205 
0206   /// Produce a labeled placed volume out of this logical volume by using a given transformation.
0207   VPlacedVolume *Place(char const *const label, Transformation3D const *const transformation) const;
0208 
0209   /// Produce a placed volume out of this logical volume by using a given transformation.
0210   VPlacedVolume *Place(Transformation3D const *const transformation) const;
0211 
0212   /// Produce a labeled placed volume out of this logical volume with identity transformation.
0213   VPlacedVolume *Place(char const *const label) const;
0214 
0215   /// Produce a trivially placed volume out of this logical volume with identity transformation.
0216   VPlacedVolume *Place() const;
0217 
0218   /// Adds/places a named daughter volume inside this logical volume.
0219   /// @param label Name of placed daughter volume.
0220   /// @param volume The logical volume to be added to the list of daughter volumes.
0221   /// @param transformation The transformation used to place the daughter.
0222   VPlacedVolume const *PlaceDaughter(char const *const label, LogicalVolume *const volume,
0223                                      Transformation3D const *const transformation);
0224 
0225   /// Adds/places a daughter volume inside this logical volume.
0226   /// @param volume The logical volume to be added to the list of daughter volumes.
0227   /// @param transformation The transformation used to place the daughter.
0228   VPlacedVolume const *PlaceDaughter(LogicalVolume *const volume, Transformation3D const *const transformation);
0229 
0230   /// Adds/places an already existing placed daughter volume
0231   void PlaceDaughter(VPlacedVolume *const placed);
0232 
0233   /// Returns true of at least one of the daughters is an assembly.
0234   bool ContainsAssembly() const;
0235 
0236   friend std::ostream &operator<<(std::ostream &os, LogicalVolume const &vol);
0237 
0238 #ifdef VECGEOM_CUDA_INTERFACE
0239   DevicePtr<cuda::LogicalVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const unplaced_vol, int id,
0240                                            DevicePtr<cuda::Vector<CudaDaughter_t>> GetDaughter) const;
0241   DevicePtr<cuda::LogicalVolume> CopyToGpu(DevicePtr<cuda::VUnplacedVolume> const unplaced_vol, int id,
0242                                            DevicePtr<cuda::Vector<CudaDaughter_t>> GetDaughter,
0243                                            DevicePtr<cuda::LogicalVolume> const gpu_ptr) const;
0244 #endif
0245 
0246 private:
0247   std::set<LogicalVolume *> GetSetOfDaughterLogicalVolumes() const;
0248 
0249 }; // End class
0250 
0251 #ifdef VECCORE_CUDA
0252 inline LogicalVolume::LogicalVolume(char const *const, VUnplacedVolume const *const)
0253 {
0254   assert(0 && "Cannot construct in CUDA");
0255 }
0256 #endif
0257 
0258 } // namespace VECGEOM_IMPL_NAMESPACE
0259 } // namespace vecgeom
0260 
0261 #endif // VECGEOM_VOLUMES_LOGICALVOLUME_H_