Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:13:58

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <type_traits>
0012 #include <utility>
0013 
0014 namespace Acts {
0015 
0016 class TrackingVolume;
0017 class Portal;
0018 class Surface;
0019 class Layer;
0020 
0021 template <typename T>
0022 class BoundarySurfaceT;
0023 
0024 /// @brief Visitor interface for traversing the tracking geometry hierarchy
0025 ///
0026 /// This visitor allows for const access to traverse and inspect the tracking
0027 /// geometry components without modifying them. It's used for operations like
0028 /// visualization, validation, or collecting information about the geometry
0029 /// structure.
0030 class TrackingGeometryVisitor {
0031  public:
0032   virtual ~TrackingGeometryVisitor() = 0;
0033 
0034   /// @brief Visit a tracking volume in the geometry
0035   /// @param volume The tracking volume being visited
0036   /// @note Called for each volume in the geometry hierarchy during traversal
0037   virtual void visitVolume(const TrackingVolume& volume);
0038 
0039   /// @brief Visit a portal (boundary between volumes)
0040   /// @param portal The portal being visited
0041   /// @note Called for each portal encountered during geometry traversal
0042   virtual void visitPortal(const Portal& portal);
0043 
0044   /// @brief Visit a surface in the geometry
0045   /// @param surface The surface being visited
0046   /// @note Called for each surface encountered during geometry traversal
0047   virtual void visitSurface(const Surface& surface);
0048 
0049   // Gen 1
0050   /// @brief Visit a detector layer
0051   /// @param layer The layer being visited
0052   /// @note Called for each layer encountered during geometry traversal
0053   virtual void visitLayer(const Layer& layer);
0054 
0055   /// @brief Visit a boundary surface between tracking volumes
0056   /// @param boundary The boundary surface being visited
0057   /// @note Called for each boundary surface encountered during geometry traversal
0058   virtual void visitBoundarySurface(
0059       const BoundarySurfaceT<TrackingVolume>& boundary);
0060 };
0061 
0062 /// @brief Mutable visitor interface for modifying the tracking geometry hierarchy
0063 ///
0064 /// This visitor allows for non-const access to traverse and modify the
0065 /// tracking geometry components. It's used for operations like geometry
0066 /// construction, material decoration, or geometry ID assignment.
0067 class TrackingGeometryMutableVisitor {
0068  public:
0069   virtual ~TrackingGeometryMutableVisitor();
0070 
0071   /// @brief Visit and potentially modify a tracking volume
0072   /// @param volume The tracking volume being visited
0073   /// @note Called for each volume in the geometry hierarchy during traversal
0074   virtual void visitVolume(TrackingVolume& volume);
0075 
0076   /// @brief Visit and potentially modify a portal
0077   /// @param portal The portal being visited
0078   /// @note Called for each portal encountered during geometry traversal
0079   virtual void visitPortal(Portal& portal);
0080 
0081   /// @brief Visit and potentially modify a surface
0082   /// @param surface The surface being visited
0083   /// @note Called for each surface encountered during geometry traversal
0084   virtual void visitSurface(Surface& surface);
0085 
0086   // Gen 1
0087   /// @brief Visit and potentially modify a detector layer
0088   /// @param layer The layer being visited
0089   /// @note Called for each layer encountered during geometry traversal
0090   virtual void visitLayer(Layer& layer);
0091 
0092   /// @brief Visit and potentially modify a boundary surface
0093   /// @param boundary The boundary surface being visited
0094   /// @note Called for each boundary surface encountered during geometry traversal
0095   virtual void visitBoundarySurface(BoundarySurfaceT<TrackingVolume>& boundary);
0096 };
0097 
0098 namespace detail {
0099 
0100 template <typename Callable>
0101 consteval bool callableWithAnyMutable() {
0102   return std::is_invocable_v<Callable, Surface&> ||
0103          std::is_invocable_v<Callable, TrackingVolume&> ||
0104          std::is_invocable_v<Callable, BoundarySurfaceT<TrackingVolume>&> ||
0105          std::is_invocable_v<Callable, Layer&> ||
0106          std::is_invocable_v<Callable, Portal&>;
0107 }
0108 
0109 template <typename Callable>
0110 consteval bool callableWithAnyConst() {
0111   return std::is_invocable_v<Callable, const Surface&> ||
0112          std::is_invocable_v<Callable, const TrackingVolume&> ||
0113          std::is_invocable_v<Callable,
0114                              const BoundarySurfaceT<TrackingVolume>&> ||
0115          std::is_invocable_v<Callable, const Layer&> ||
0116          std::is_invocable_v<Callable, const Portal&>;
0117 }
0118 
0119 template <typename Callable>
0120 consteval bool callableWithAny() {
0121   return callableWithAnyMutable<Callable>() || callableWithAnyConst<Callable>();
0122 }
0123 
0124 template <typename Callable>
0125   requires(callableWithAnyConst<Callable>())
0126 class TrackingGeometryLambdaVisitor : public TrackingGeometryVisitor {
0127  public:
0128   explicit TrackingGeometryLambdaVisitor(Callable callable)
0129       : m_callable(std::move(callable)) {}
0130 
0131   void visitSurface(const Surface& surface) override {
0132     if constexpr (std::is_invocable_v<Callable, const Surface&>) {
0133       m_callable(surface);
0134     }
0135   }
0136 
0137   void visitVolume(const TrackingVolume& volume) override {
0138     if constexpr (std::is_invocable_v<Callable, const TrackingVolume&>) {
0139       m_callable(volume);
0140     }
0141   }
0142 
0143   void visitBoundarySurface(
0144       const BoundarySurfaceT<TrackingVolume>& boundary) override {
0145     if constexpr (std::is_invocable_v<
0146                       Callable, const BoundarySurfaceT<TrackingVolume>&>) {
0147       m_callable(boundary);
0148     }
0149   }
0150 
0151   void visitLayer(const Layer& layer) override {
0152     if constexpr (std::is_invocable_v<Callable, const Layer&>) {
0153       m_callable(layer);
0154     }
0155   }
0156 
0157   void visitPortal(const Portal& portal) override {
0158     if constexpr (std::is_invocable_v<Callable, const Portal&>) {
0159       m_callable(portal);
0160     }
0161   }
0162 
0163  private:
0164   Callable m_callable;
0165 };
0166 
0167 template <typename Callable>
0168   requires(callableWithAnyMutable<Callable>())
0169 class TrackingGeometryLambdaMutableVisitor
0170     : public TrackingGeometryMutableVisitor {
0171  public:
0172   explicit TrackingGeometryLambdaMutableVisitor(Callable callable)
0173       : m_callable(std::move(callable)) {}
0174 
0175   void visitSurface(Surface& surface) override {
0176     if constexpr (std::is_invocable_v<Callable, Surface&>) {
0177       m_callable(surface);
0178     }
0179   }
0180 
0181   void visitVolume(TrackingVolume& volume) override {
0182     if constexpr (std::is_invocable_v<Callable, TrackingVolume&>) {
0183       m_callable(volume);
0184     }
0185   }
0186 
0187   void visitBoundarySurface(
0188       BoundarySurfaceT<TrackingVolume>& boundary) override {
0189     if constexpr (std::is_invocable_v<Callable,
0190                                       BoundarySurfaceT<TrackingVolume>&>) {
0191       m_callable(boundary);
0192     }
0193   }
0194 
0195   void visitLayer(Layer& layer) override {
0196     if constexpr (std::is_invocable_v<Callable, Layer&>) {
0197       m_callable(layer);
0198     }
0199   }
0200 
0201   void visitPortal(Portal& portal) override {
0202     if constexpr (std::is_invocable_v<Callable, Portal&>) {
0203       m_callable(portal);
0204     }
0205   }
0206 
0207  private:
0208   Callable m_callable;
0209 };
0210 
0211 }  // namespace detail
0212 
0213 }  // namespace Acts