Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-29 08:51:37

0001 //------------------------------- -*- C++ -*- -------------------------------//
0002 // Copyright Celeritas contributors: see top-level COPYRIGHT file for details
0003 // SPDX-License-Identifier: (Apache-2.0 OR MIT)
0004 //---------------------------------------------------------------------------//
0005 //! \file orange/OrangeParams.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <string>
0010 #include <vector>
0011 
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/LabelIdMultiMap.hh"
0014 #include "corecel/data/CollectionMirror.hh"
0015 #include "corecel/data/ParamsDataInterface.hh"
0016 #include "corecel/io/Label.hh"
0017 #include "geocel/BoundingBox.hh"
0018 #include "geocel/GeoParamsInterface.hh"
0019 
0020 #include "OrangeData.hh"
0021 #include "OrangeTypes.hh"
0022 
0023 class G4VPhysicalVolume;
0024 
0025 namespace celeritas
0026 {
0027 struct OrangeInput;
0028 
0029 //---------------------------------------------------------------------------//
0030 /*!
0031  * Persistent model data for an ORANGE geometry.
0032  *
0033  * This class initializes and manages the data used by ORANGE (surfaces,
0034  * volumes) and provides a host-based interface for them.
0035  */
0036 class OrangeParams final : public GeoParamsSurfaceInterface,
0037                            public ParamsDataInterface<OrangeParamsData>
0038 {
0039   public:
0040     //!@{
0041     //! \name Type aliases
0042     using SurfaceMap = LabelIdMultiMap<SurfaceId>;
0043     using UniverseMap = LabelIdMultiMap<UniverseId>;
0044     //!@}
0045 
0046   public:
0047     // Construct from a JSON or GDML file (if JSON or Geant4 are enabled)
0048     explicit OrangeParams(std::string const& filename);
0049 
0050     // Construct in-memory from Geant4
0051     explicit OrangeParams(G4VPhysicalVolume const*);
0052 
0053     // ADVANCED usage: construct from explicit host data
0054     explicit OrangeParams(OrangeInput&& input);
0055 
0056     // Default destructor to anchor vtable
0057     ~OrangeParams() final;
0058 
0059     // Moving would leave the class in an unspecified state
0060     CELER_DELETE_COPY_MOVE(OrangeParams);
0061 
0062     //! Whether safety distance calculations are accurate and precise
0063     bool supports_safety() const final { return supports_safety_; }
0064 
0065     //! Outer bounding box of geometry
0066     BBox const& bbox() const final { return bbox_; }
0067 
0068     // Maximum universe depth
0069     inline size_type max_depth() const final;
0070 
0071     //// LABELS AND MAPPING ////
0072 
0073     // Get surface metadata
0074     inline SurfaceMap const& surfaces() const final;
0075 
0076     // Get universe metadata
0077     inline UniverseMap const& universes() const;
0078 
0079     // Get volume metadata
0080     inline VolumeMap const& volumes() const final;
0081 
0082     // Get (physical) volume instance metadata
0083     inline VolInstanceMap const& volume_instances() const final;
0084 
0085     // Get the volume ID corresponding to a Geant4 logical volume
0086     inline VolumeId find_volume(G4LogicalVolume const* volume) const final;
0087 
0088     // Get the Geant4 physical volume corresponding to a volume instance ID
0089     inline GeantPhysicalInstance
0090     id_to_geant(VolumeInstanceId vol_id) const final;
0091 
0092     //// DATA ACCESS ////
0093 
0094     //! Reference to CPU geometry data
0095     HostRef const& host_ref() const final { return data_.host_ref(); }
0096 
0097     //! Reference to managed GPU geometry data
0098     DeviceRef const& device_ref() const final { return data_.device_ref(); }
0099 
0100   private:
0101     // Host metadata/access
0102     SurfaceMap surf_labels_;
0103     UniverseMap univ_labels_;
0104     VolumeMap vol_labels_;
0105     VolInstanceMap vol_instances_;
0106     BBox bbox_;
0107     bool supports_safety_{};
0108 
0109     // Host/device storage and reference
0110     CollectionMirror<OrangeParamsData> data_;
0111 };
0112 
0113 //---------------------------------------------------------------------------//
0114 
0115 extern template class CollectionMirror<OrangeParamsData>;
0116 extern template class ParamsDataInterface<OrangeParamsData>;
0117 
0118 //---------------------------------------------------------------------------//
0119 // INLINE DEFINITIONS
0120 //---------------------------------------------------------------------------//
0121 /*!
0122  * Maximum universe depth.
0123  */
0124 size_type OrangeParams::max_depth() const
0125 {
0126     return this->host_ref().scalars.max_depth;
0127 }
0128 
0129 //---------------------------------------------------------------------------//
0130 /*!
0131  * Get surface metadata.
0132  */
0133 auto OrangeParams::surfaces() const -> SurfaceMap const&
0134 {
0135     return surf_labels_;
0136 }
0137 
0138 //---------------------------------------------------------------------------//
0139 /*!
0140  * Get universe metadata.
0141  */
0142 auto OrangeParams::universes() const -> UniverseMap const&
0143 {
0144     return univ_labels_;
0145 }
0146 
0147 //---------------------------------------------------------------------------//
0148 /*!
0149  * Get volume metadata.
0150  */
0151 auto OrangeParams::volumes() const -> VolumeMap const&
0152 {
0153     return vol_labels_;
0154 }
0155 
0156 //---------------------------------------------------------------------------//
0157 /*!
0158  * Get volume instance metadata.
0159  */
0160 auto OrangeParams::volume_instances() const -> VolInstanceMap const&
0161 {
0162     return vol_instances_;
0163 }
0164 
0165 //---------------------------------------------------------------------------//
0166 /*!
0167  * Locate the volume ID corresponding to a Geant4 volume.
0168  *
0169  * \todo Implement using \c g4org::Converter
0170  */
0171 VolumeId OrangeParams::find_volume(G4LogicalVolume const*) const
0172 {
0173     return VolumeId{};
0174 }
0175 
0176 //---------------------------------------------------------------------------//
0177 /*!
0178  * Get the Geant4 physical volume corresponding to a volume instance ID.
0179  *
0180  * \todo Implement using \c g4org::Converter
0181  */
0182 GeantPhysicalInstance OrangeParams::id_to_geant(VolumeInstanceId) const
0183 {
0184     return {};
0185 }
0186 
0187 //---------------------------------------------------------------------------//
0188 }  // namespace celeritas