Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-04 10:04:36

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 geocel/vg/detail/VecgeomNavCollection.hh
0006 //---------------------------------------------------------------------------//
0007 #pragma once
0008 
0009 #include <memory>
0010 #include <vector>
0011 #include <VecGeom/base/Config.h>
0012 #include <VecGeom/navigation/NavStatePath.h>
0013 
0014 #include "corecel/Assert.hh"
0015 #include "corecel/Types.hh"
0016 #include "corecel/cont/Span.hh"
0017 #include "corecel/sys/ThreadId.hh"
0018 #include "geocel/vg/VecgeomTypes.hh"
0019 
0020 #if CELER_VGNAV != CELER_VGNAV_PATH
0021 #    error \
0022         "This file can only be included when using VecGeom built with VecGeom_NAV=path"
0023 #endif
0024 
0025 namespace celeritas
0026 {
0027 namespace detail
0028 {
0029 using UPVgPathState = std::unique_ptr<vecgeom::NavStatePath>;
0030 
0031 //---------------------------------------------------------------------------//
0032 /*!
0033  * Collection-like container for managing VecGeom navigation states.
0034  *
0035  * This is now used explicitly for a host-only collection of "path" navigation
0036  * states.
0037  */
0038 template<Ownership W, MemSpace M>
0039 struct VecgeomNavCollection
0040 {
0041     explicit operator bool() const { return false; }
0042     size_type size() const { return 0; }
0043 
0044     template<Ownership W2, MemSpace M2>
0045     VecgeomNavCollection& operator=(VecgeomNavCollection<W2, M2>&)
0046     {
0047         CELER_ASSERT_UNREACHABLE();
0048     }
0049 };
0050 
0051 //---------------------------------------------------------------------------//
0052 // HOST MEMSPACE
0053 //---------------------------------------------------------------------------//
0054 /*!
0055  * Manage navigation states in host memory.
0056  */
0057 template<>
0058 struct VecgeomNavCollection<Ownership::value, MemSpace::host>
0059 {
0060     std::vector<UPVgPathState> nav_state;
0061 
0062     // Whether the collection is assigned
0063     explicit operator bool() const { return !nav_state.empty(); }
0064 
0065     //! Number of elements
0066     size_type size() const { return nav_state.size(); }
0067 };
0068 
0069 //---------------------------------------------------------------------------//
0070 /*!
0071  * Reference a host-owned navigation state.
0072  */
0073 template<>
0074 struct VecgeomNavCollection<Ownership::reference, MemSpace::host>
0075 {
0076     Span<UPVgPathState> nav_state;
0077 
0078     // Default construction and copy construction
0079     VecgeomNavCollection() = default;
0080     VecgeomNavCollection(VecgeomNavCollection const&) = default;
0081 
0082     // Obtain reference from host memory
0083     VecgeomNavCollection& operator=(
0084         VecgeomNavCollection<Ownership::value, MemSpace::host>& other);
0085     // Default copy assignment
0086     VecgeomNavCollection& operator=(VecgeomNavCollection const&) = default;
0087 
0088     //! Get the navigation state for a given track slot
0089     vecgeom::NavStatePath& operator[](TrackSlotId tid) const
0090     {
0091         CELER_EXPECT(*this);
0092         CELER_EXPECT(tid < nav_state.size());
0093         return *nav_state[tid.unchecked_get()];
0094     }
0095 
0096     //! Number of elements
0097     size_type size() const { return nav_state.size(); }
0098 
0099     //! True if the collection is assigned/valid
0100     explicit operator bool() const { return !nav_state.empty(); }
0101 };
0102 
0103 //---------------------------------------------------------------------------//
0104 // Resize with a number of states
0105 void resize(VecgeomNavCollection<Ownership::value, MemSpace::host>* nav,
0106             size_type size);
0107 
0108 inline void resize(VecgeomNavCollection<Ownership::value, MemSpace::device>*,
0109                    size_type)
0110 {
0111     CELER_ASSERT_UNREACHABLE();
0112 }
0113 
0114 //---------------------------------------------------------------------------//
0115 }  // namespace detail
0116 }  // namespace celeritas