@@ -53,7 +53,11 @@ class surface {
5353 // / @param desc from that detector.
5454 DETRAY_HOST_DEVICE
5555 constexpr surface (const detector_t &det, const descr_t &desc)
56- : m_detector{det}, m_desc{desc} {}
56+ : m_detector{det}, m_desc{desc} {
57+ assert (!m_desc.barcode ().is_invalid ());
58+ assert (m_desc.index () < det.surfaces ().size ());
59+ assert (m_desc.transform () < det.transform_store ().size ());
60+ }
5761
5862 // / Constructor from detector @param det and barcode @param bcd in
5963 // / that detector.
@@ -84,20 +88,30 @@ class surface {
8488 // / @returns the surface barcode
8589 DETRAY_HOST_DEVICE
8690 constexpr auto barcode () const -> geometry::barcode {
91+ assert (!m_desc.barcode ().is_invalid ());
8792 return m_desc.barcode ();
8893 }
8994
9095 // / @returns the index of the mother volume
9196 DETRAY_HOST_DEVICE
92- constexpr auto volume () const -> dindex { return barcode ().volume (); }
97+ constexpr auto volume () const -> dindex {
98+ assert (barcode ().volume () < m_detector.volumes ().size ());
99+ return barcode ().volume ();
100+ }
93101
94102 // / @returns the index of the surface in the detector surface lookup
95103 DETRAY_HOST_DEVICE
96- constexpr auto index () const -> dindex { return barcode ().index (); }
104+ constexpr auto index () const -> dindex {
105+ assert (barcode ().index () < m_detector.surfaces ().size ());
106+ return barcode ().index ();
107+ }
97108
98109 // / @returns the surface id (sensitive, passive or portal)
99110 DETRAY_HOST_DEVICE
100- constexpr auto id () const -> surface_id { return barcode ().id (); }
111+ constexpr auto id () const -> surface_id {
112+ assert (barcode ().id () != surface_id::e_unknown);
113+ return barcode ().id ();
114+ }
101115
102116 // / @returns the extra bits in the barcode
103117 DETRAY_HOST_DEVICE
@@ -110,7 +124,7 @@ class surface {
110124 // / @returns the surface source link
111125 DETRAY_HOST_DEVICE
112126 constexpr auto source () const {
113- return m_detector.surface (m_desc. barcode ()).source ;
127+ return m_detector.surface (barcode ()).source ;
114128 }
115129
116130 // / @returns true if the surface is a senstive detector module.
@@ -156,6 +170,7 @@ class surface {
156170 DETRAY_HOST_DEVICE
157171 constexpr auto transform (const context &ctx) const
158172 -> const transform3_type & {
173+ assert (m_desc.transform () < m_detector.transform_store ().size ());
159174 return m_detector.transform_store ().at (m_desc.transform (), ctx);
160175 }
161176
@@ -239,8 +254,8 @@ class surface {
239254 // / @tparam Args types of additional arguments to the functor
240255 template <typename functor_t , typename ... Args>
241256 DETRAY_HOST_DEVICE constexpr auto visit_mask (Args &&... args) const {
257+ assert (!m_desc.mask ().is_invalid ());
242258 const auto &masks = m_detector.mask_store ();
243-
244259 return masks.template visit <functor_t >(m_desc.mask (),
245260 std::forward<Args>(args)...);
246261 }
@@ -251,8 +266,8 @@ class surface {
251266 // / @tparam Args types of additional arguments to the functor
252267 template <typename functor_t , typename ... Args>
253268 DETRAY_HOST_DEVICE constexpr auto visit_material (Args &&... args) const {
269+ assert (has_material ());
254270 const auto &materials = m_detector.material_store ();
255-
256271 return materials.template visit <functor_t >(m_desc.material (),
257272 std::forward<Args>(args)...);
258273 }
0 commit comments