Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 09:03:19

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/LevelStateAccessor.hh
0006 // NOTE: this file is used by SCALE ORANGE; leave it public
0007 //---------------------------------------------------------------------------//
0008 #pragma once
0009 
0010 #include "OrangeData.hh"
0011 #include "OrangeTypes.hh"
0012 
0013 namespace celeritas
0014 {
0015 //---------------------------------------------------------------------------//
0016 /*!
0017  * Accesss the 2D fields (i.e., {track slot, level}) of OrangeStateData.
0018  */
0019 class LevelStateAccessor
0020 {
0021   public:
0022     //!@{
0023     //! Type aliases
0024     using StateRef = NativeRef<OrangeStateData>;
0025     //!@}
0026 
0027   public:
0028     // Construct from states and indices
0029     inline CELER_FUNCTION LevelStateAccessor(StateRef const* states,
0030                                              TrackSlotId tid,
0031                                              LevelId level_id);
0032 
0033     LevelStateAccessor(LevelStateAccessor const&) = default;
0034     LevelStateAccessor(LevelStateAccessor&&) = default;
0035     // Copy data from another LSA
0036     inline CELER_FUNCTION LevelStateAccessor&
0037     operator=(LevelStateAccessor const& other);
0038     ~LevelStateAccessor() = default;
0039 
0040     //// ACCESSORS ////
0041 
0042     CELER_FUNCTION LocalVolumeId& vol()
0043     {
0044         return states_->vol[OpaqueId<LocalVolumeId>{index_}];
0045     }
0046 
0047     CELER_FUNCTION Real3& pos()
0048     {
0049         return states_->pos[OpaqueId<Real3>{index_}];
0050     }
0051 
0052     CELER_FUNCTION Real3& dir()
0053     {
0054         return states_->dir[OpaqueId<Real3>{index_}];
0055     }
0056 
0057     CELER_FUNCTION UniverseId& universe()
0058     {
0059         return states_->universe[OpaqueId<UniverseId>{index_}];
0060     }
0061 
0062     //// CONST ACCESSORS ////
0063 
0064     CELER_FUNCTION LocalVolumeId const& vol() const
0065     {
0066         return states_->vol[OpaqueId<LocalVolumeId>{index_}];
0067     }
0068 
0069     CELER_FUNCTION Real3 const& pos() const
0070     {
0071         return states_->pos[OpaqueId<Real3>{index_}];
0072     }
0073 
0074     CELER_FUNCTION Real3 const& dir() const
0075     {
0076         return states_->dir[OpaqueId<Real3>{index_}];
0077     }
0078 
0079     CELER_FUNCTION UniverseId const& universe() const
0080     {
0081         return states_->universe[OpaqueId<UniverseId>{index_}];
0082     }
0083 
0084   private:
0085     StateRef const* const states_;
0086     size_type const index_;
0087 };
0088 
0089 //---------------------------------------------------------------------------//
0090 // INLINE DEFINITIONS
0091 //---------------------------------------------------------------------------//
0092 /*!
0093  * Construct from states and indices
0094  */
0095 CELER_FUNCTION
0096 LevelStateAccessor::LevelStateAccessor(StateRef const* states,
0097                                        TrackSlotId tid,
0098                                        LevelId level_id)
0099     : states_(states), index_(tid.get() * states_->max_depth + level_id.get())
0100 {
0101     CELER_EXPECT(level_id < states->max_depth);
0102 }
0103 
0104 //---------------------------------------------------------------------------//
0105 /*!
0106  * Copy data from another LSA
0107  */
0108 CELER_FUNCTION LevelStateAccessor&
0109 LevelStateAccessor::operator=(LevelStateAccessor const& other)
0110 {
0111     if (this == &other)
0112     {
0113         return *this;
0114     }
0115     this->vol() = other.vol();
0116     this->pos() = other.pos();
0117     this->dir() = other.dir();
0118     this->universe() = other.universe();
0119 
0120     return *this;
0121 }
0122 
0123 //---------------------------------------------------------------------------//
0124 }  // namespace celeritas