Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-11 08:49:07

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