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