File indexing completed on 2025-09-17 08:59:58
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <vector>
0011 #include <VecGeom/base/Config.h>
0012 #include <VecGeom/base/Cuda.h>
0013 #include <VecGeom/navigation/NavStateFwd.h>
0014 #include <VecGeom/navigation/NavStatePool.h>
0015 #include <VecGeom/navigation/NavigationState.h>
0016
0017 #include "corecel/Assert.hh"
0018 #include "corecel/Types.hh"
0019 #include "corecel/cont/Span.hh"
0020 #include "corecel/sys/ThreadId.hh"
0021
0022 namespace celeritas
0023 {
0024 namespace detail
0025 {
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 template<Ownership W, MemSpace M>
0037 struct VecgeomNavCollection;
0038
0039
0040
0041
0042
0043
0044
0045 template<>
0046 struct VecgeomNavCollection<Ownership::value, MemSpace::host>
0047 {
0048 using NavState = vecgeom::cxx::NavigationState;
0049 using UPNavState = std::unique_ptr<NavState>;
0050
0051 std::vector<UPNavState> nav_state;
0052
0053
0054 void resize(int max_depth, size_type size);
0055
0056 explicit operator bool() const { return !nav_state.empty(); }
0057 };
0058
0059
0060
0061
0062
0063 template<>
0064 struct VecgeomNavCollection<Ownership::reference, MemSpace::host>
0065 {
0066 using NavState = vecgeom::cxx::NavigationState;
0067 using UPNavState = std::unique_ptr<NavState>;
0068
0069 Span<UPNavState> nav_state;
0070
0071
0072 VecgeomNavCollection() = default;
0073 VecgeomNavCollection(VecgeomNavCollection const&) = default;
0074
0075
0076 VecgeomNavCollection&
0077 operator=(VecgeomNavCollection<Ownership::value, MemSpace::host>& other);
0078
0079 VecgeomNavCollection& operator=(VecgeomNavCollection const&) = default;
0080
0081
0082 NavState& at(int, TrackSlotId tid) const;
0083
0084 explicit operator bool() const { return !nav_state.empty(); }
0085 };
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 struct NavStatePoolDeleter
0097 {
0098 using arg_type = vecgeom::cxx::NavStatePool*;
0099 void operator()(arg_type) const;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 template<>
0111 struct VecgeomNavCollection<Ownership::value, MemSpace::device>
0112 {
0113 using UPNavStatePool
0114 = std::unique_ptr<vecgeom::cxx::NavStatePool, NavStatePoolDeleter>;
0115
0116 UPNavStatePool pool;
0117 void* ptr = nullptr;
0118 int max_depth = 0;
0119 size_type size = 0;
0120
0121
0122 void resize(int max_depth, size_type size);
0123
0124 explicit CELER_FUNCTION operator bool() const { return ptr; }
0125 };
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 template<>
0136 struct VecgeomNavCollection<Ownership::reference, MemSpace::device>
0137 {
0138 using NavState = vecgeom::NavigationState;
0139
0140 vecgeom::NavStatePoolView pool_view = {nullptr, 0, 0};
0141
0142
0143 VecgeomNavCollection() = default;
0144 VecgeomNavCollection(VecgeomNavCollection const& other) = default;
0145
0146
0147 VecgeomNavCollection&
0148 operator=(VecgeomNavCollection<Ownership::value, MemSpace::device>& other);
0149
0150 VecgeomNavCollection& operator=(VecgeomNavCollection const& other)
0151 = default;
0152
0153
0154 inline CELER_FUNCTION NavState& at(int max_depth, TrackSlotId tid) const;
0155
0156
0157 explicit CELER_FUNCTION operator bool() const
0158 {
0159 return pool_view.IsValid();
0160 }
0161 };
0162
0163
0164
0165
0166
0167
0168
0169
0170 CELER_FUNCTION auto
0171 VecgeomNavCollection<Ownership::reference, MemSpace::device>::at(
0172 int max_depth_param, TrackSlotId tid) const -> NavState&
0173 {
0174 CELER_EXPECT(this->pool_view.IsValid());
0175 CELER_EXPECT(tid < this->pool_view.Capacity());
0176 CELER_EXPECT(max_depth_param == this->pool_view.Depth());
0177
0178 return *const_cast<NavState*>((this->pool_view)[tid.get()]);
0179 }
0180
0181
0182 }
0183 }