Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-13 08:15:40

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 /// @brief Base class for tracking geometry visitors
0024 ///
0025 /// This class provides a common interface for both const and mutable visitors
0026 /// to the tracking geometry hierarchy. It allows decide on the visiting order
0027 /// based on the visitInDepth flag. If true, the visiting happens from the
0028 /// outermost volume and goes deeper to the volumes into the hierarchy.
0029 class ITrackingGeometryVisitor {
0030  public:
0031   virtual ~ITrackingGeometryVisitor() = 0;
0032 
0033   /// @param visitDepthFirst Flag to control visit order (depth-first vs breadth-first)
0034   explicit ITrackingGeometryVisitor(bool visitDepthFirst = false)
0035       : m_visitDepthFirst(visitDepthFirst) {}
0036 
0037   /// @brief indicate the order of visiting
0038   /// @note default is outermost --> innermost volume visiting
0039   /// @return True if depth-first traversal is enabled, false for breadth-first
0040   bool visitDepthFirst() const { return m_visitDepthFirst; }
0041 
0042  private:
0043   /// Flag to indicate if the visitor should follow from the outermost to the
0044   /// innermost volume depth
0045   bool m_visitDepthFirst{false};
0046 };
0047 
0048 /// @brief Visitor interface for traversing the tracking geometry hierarchy
0049 ///
0050 /// This visitor allows for const access to traverse and inspect the tracking
0051 /// geometry components without modifying them. It's used for operations like
0052 /// visualization, validation, or collecting information about the geometry
0053 /// structure.
0054 class TrackingGeometryVisitor : public ITrackingGeometryVisitor {
0055  public:
0056   /// @brief Constructor from base class
0057   /// @param visitDepthFirst Flag to control visit order (depth-first vs breadth-first)
0058   using ITrackingGeometryVisitor::ITrackingGeometryVisitor;
0059 
0060   ~TrackingGeometryVisitor() override;
0061 
0062   /// @brief Visit a tracking volume in the geometry
0063   /// @param volume The tracking volume being visited
0064   /// @note Called for each volume in the geometry hierarchy during traversal
0065   virtual void visitVolume(const TrackingVolume& volume);
0066 
0067   /// @brief Visit a portal (boundary between volumes)
0068   /// @param portal The portal being visited
0069   /// @note Called for each portal encountered during geometry traversal
0070   virtual void visitPortal(const Portal& portal);
0071 
0072   /// @brief Visit a surface in the geometry
0073   /// @param surface The surface being visited
0074   /// @note Called for each surface encountered during geometry traversal
0075   virtual void visitSurface(const Surface& surface);
0076 
0077   // Gen 1
0078   /// @brief Visit a detector layer
0079   /// @param layer The layer being visited
0080   /// @note Called for each layer encountered during geometry traversal
0081   virtual void visitLayer(const Layer& layer);
0082 
0083   /// @brief Visit a boundary surface between tracking volumes
0084   /// @param boundary The boundary surface being visited
0085   /// @note Called for each boundary surface encountered during geometry traversal
0086   virtual void visitBoundarySurface(
0087       const BoundarySurfaceT<TrackingVolume>& boundary);
0088 };
0089 
0090 /// @brief Mutable visitor interface for modifying the tracking geometry hierarchy
0091 ///
0092 /// This visitor allows for non-const access to traverse and modify the
0093 /// tracking geometry components. It's used for operations like geometry
0094 /// construction, material decoration, or geometry ID assignment.
0095 class TrackingGeometryMutableVisitor : public ITrackingGeometryVisitor {
0096  public:
0097   /// @brief Constructor
0098   /// @param visitDepthFirst Flag to control visit order (depth-first vs breadth-first)
0099   using ITrackingGeometryVisitor::ITrackingGeometryVisitor;
0100 
0101   ~TrackingGeometryMutableVisitor() override;
0102 
0103   /// @brief Visit and potentially modify a tracking volume
0104   /// @param volume The tracking volume being visited
0105   /// @note Called for each volume in the geometry hierarchy during traversal
0106   virtual void visitVolume(TrackingVolume& volume);
0107 
0108   /// @brief Visit and potentially modify a portal
0109   /// @param portal The portal being visited
0110   /// @note Called for each portal encountered during geometry traversal
0111   virtual void visitPortal(Portal& portal);
0112 
0113   /// @brief Visit and potentially modify a surface
0114   /// @param surface The surface being visited
0115   /// @note Called for each surface encountered during geometry traversal
0116   virtual void visitSurface(Surface& surface);
0117 
0118   // Gen 1
0119   /// @brief Visit and potentially modify a detector layer
0120   /// @param layer The layer being visited
0121   /// @note Called for each layer encountered during geometry traversal
0122   virtual void visitLayer(Layer& layer);
0123 
0124   /// @brief Visit and potentially modify a boundary surface
0125   /// @param boundary The boundary surface being visited
0126   /// @note Called for each boundary surface encountered during geometry traversal
0127   virtual void visitBoundarySurface(BoundarySurfaceT<TrackingVolume>& boundary);
0128 };
0129 
0130 namespace detail {
0131 
0132 template <typename Callable>
0133 consteval bool callableWithAnyMutable() {
0134   return std::is_invocable_v<Callable, Surface&> ||
0135          std::is_invocable_v<Callable, TrackingVolume&> ||
0136          std::is_invocable_v<Callable, BoundarySurfaceT<TrackingVolume>&> ||
0137          std::is_invocable_v<Callable, Layer&> ||
0138          std::is_invocable_v<Callable, Portal&>;
0139 }
0140 
0141 template <typename Callable>
0142 consteval bool callableWithAnyConst() {
0143   return std::is_invocable_v<Callable, const Surface&> ||
0144          std::is_invocable_v<Callable, const TrackingVolume&> ||
0145          std::is_invocable_v<Callable,
0146                              const BoundarySurfaceT<TrackingVolume>&> ||
0147          std::is_invocable_v<Callable, const Layer&> ||
0148          std::is_invocable_v<Callable, const Portal&>;
0149 }
0150 
0151 template <typename Callable>
0152 consteval bool callableWithAny() {
0153   return callableWithAnyMutable<Callable>() || callableWithAnyConst<Callable>();
0154 }
0155 
0156 template <typename Callable>
0157   requires(callableWithAnyConst<Callable>())
0158 class TrackingGeometryLambdaVisitor : public TrackingGeometryVisitor {
0159  public:
0160   explicit TrackingGeometryLambdaVisitor(Callable callable)
0161       : m_callable(std::move(callable)) {}
0162 
0163   void visitSurface(const Surface& surface) override {
0164     if constexpr (std::is_invocable_v<Callable, const Surface&>) {
0165       m_callable(surface);
0166     }
0167   }
0168 
0169   void visitVolume(const TrackingVolume& volume) override {
0170     if constexpr (std::is_invocable_v<Callable, const TrackingVolume&>) {
0171       m_callable(volume);
0172     }
0173   }
0174 
0175   void visitBoundarySurface(
0176       const BoundarySurfaceT<TrackingVolume>& boundary) override {
0177     if constexpr (std::is_invocable_v<
0178                       Callable, const BoundarySurfaceT<TrackingVolume>&>) {
0179       m_callable(boundary);
0180     }
0181   }
0182 
0183   void visitLayer(const Layer& layer) override {
0184     if constexpr (std::is_invocable_v<Callable, const Layer&>) {
0185       m_callable(layer);
0186     }
0187   }
0188 
0189   void visitPortal(const Portal& portal) override {
0190     if constexpr (std::is_invocable_v<Callable, const Portal&>) {
0191       m_callable(portal);
0192     }
0193   }
0194 
0195  private:
0196   Callable m_callable;
0197 };
0198 
0199 template <typename Callable>
0200   requires(callableWithAnyMutable<Callable>())
0201 class TrackingGeometryLambdaMutableVisitor
0202     : public TrackingGeometryMutableVisitor {
0203  public:
0204   explicit TrackingGeometryLambdaMutableVisitor(Callable callable)
0205       : m_callable(std::move(callable)) {}
0206 
0207   void visitSurface(Surface& surface) override {
0208     if constexpr (std::is_invocable_v<Callable, Surface&>) {
0209       m_callable(surface);
0210     }
0211   }
0212 
0213   void visitVolume(TrackingVolume& volume) override {
0214     if constexpr (std::is_invocable_v<Callable, TrackingVolume&>) {
0215       m_callable(volume);
0216     }
0217   }
0218 
0219   void visitBoundarySurface(
0220       BoundarySurfaceT<TrackingVolume>& boundary) override {
0221     if constexpr (std::is_invocable_v<Callable,
0222                                       BoundarySurfaceT<TrackingVolume>&>) {
0223       m_callable(boundary);
0224     }
0225   }
0226 
0227   void visitLayer(Layer& layer) override {
0228     if constexpr (std::is_invocable_v<Callable, Layer&>) {
0229       m_callable(layer);
0230     }
0231   }
0232 
0233   void visitPortal(Portal& portal) override {
0234     if constexpr (std::is_invocable_v<Callable, Portal&>) {
0235       m_callable(portal);
0236     }
0237   }
0238 
0239  private:
0240   Callable m_callable;
0241 };
0242 
0243 }  // namespace detail
0244 
0245 }  // namespace Acts