File indexing completed on 2025-09-17 08:59:57
0001
0002
0003
0004
0005
0006
0007 #pragma once
0008
0009 #include <memory>
0010 #include <vector>
0011
0012 #include "corecel/Types.hh"
0013 #include "corecel/cont/Span.hh"
0014 #include "corecel/sys/ThreadId.hh"
0015 #include "geocel/GeantGeoUtils.hh"
0016
0017 template<class>
0018 class G4ReferenceCountedHandle;
0019
0020 namespace celeritas
0021 {
0022 namespace detail
0023 {
0024
0025
0026
0027
0028
0029
0030
0031 template<Ownership W, MemSpace M>
0032 struct GeantGeoNavCollection
0033 {
0034 explicit CELER_FUNCTION operator bool() const { return false; }
0035 CELER_FUNCTION TrackSlotId::size_type size() const { return 0; }
0036 template<Ownership W2, MemSpace M2>
0037 CELER_FUNCTION GeantGeoNavCollection&
0038 operator=(GeantGeoNavCollection<W2, M2>&)
0039 {
0040 return *this;
0041 }
0042 CELER_FUNCTION void reset() { CELER_ASSERT_UNREACHABLE(); }
0043 };
0044
0045
0046
0047 template<class T>
0048 struct G4ExternDeleter
0049 {
0050 void operator()(T* ptr) noexcept;
0051 };
0052
0053
0054
0055 using GeantTouchableHandle = G4ReferenceCountedHandle<GeantTouchableBase>;
0056 using UPTouchHandle = std::unique_ptr<GeantTouchableHandle,
0057 G4ExternDeleter<GeantTouchableHandle>>;
0058 using UPNavigator = std::unique_ptr<G4Navigator, G4ExternDeleter<G4Navigator>>;
0059
0060
0061
0062
0063
0064
0065
0066 template<>
0067 struct GeantGeoNavCollection<Ownership::value, MemSpace::host>
0068 {
0069 std::vector<UPTouchHandle> touch_handles;
0070 std::vector<UPNavigator> navigators;
0071
0072
0073 void resize(size_type size, G4VPhysicalVolume* world, StreamId sid);
0074
0075
0076 CELER_FUNCTION TrackSlotId::size_type size() const
0077 {
0078 return touch_handles.size();
0079 }
0080
0081
0082 explicit operator bool() const
0083 {
0084 return !touch_handles.empty()
0085 && navigators.size() == touch_handles.size();
0086 }
0087
0088
0089 void reset() { CELER_ASSERT_UNREACHABLE(); }
0090 };
0091
0092
0093
0094
0095
0096 template<>
0097 struct GeantGeoNavCollection<Ownership::reference, MemSpace::host>
0098 {
0099 Span<UPTouchHandle> touch_handles;
0100 Span<UPNavigator> navigators;
0101
0102
0103 GeantGeoNavCollection() = default;
0104 GeantGeoNavCollection(GeantGeoNavCollection const&) = default;
0105
0106
0107 GeantGeoNavCollection&
0108 operator=(GeantGeoNavCollection<Ownership::value, MemSpace::host>& other);
0109
0110 GeantGeoNavCollection& operator=(GeantGeoNavCollection const&) = default;
0111
0112
0113 GeantTouchableHandle& touch_handle(TrackSlotId tid) const;
0114
0115 G4Navigator& navigator(TrackSlotId tid) const;
0116
0117
0118 CELER_FUNCTION TrackSlotId::size_type size() const
0119 {
0120 return touch_handles.size();
0121 }
0122
0123
0124 explicit operator bool() const
0125 {
0126 return !touch_handles.empty()
0127 && navigators.size() == touch_handles.size()
0128 && touch_handles.front() && navigators.front();
0129 }
0130
0131
0132 void reset();
0133 };
0134
0135
0136 }
0137 }