Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:01: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 "Acts/Navigation/NavigationDelegate.hpp"
0012 #include "Acts/Navigation/NavigationStream.hpp"
0013 
0014 #include <type_traits>
0015 
0016 namespace Acts {
0017 
0018 class TrackingVolume;
0019 class INavigationPolicy;
0020 
0021 /// Concept for a navigation policy
0022 /// This exists so `updateState` can be a non-virtual method and we still have a
0023 /// way to enforce it exists.
0024 template <typename T>
0025 concept NavigationPolicyConcept = requires {
0026   requires std::is_base_of_v<INavigationPolicy, T>;
0027   // Has a conforming update method
0028   requires requires(T policy, const NavigationArguments& args) {
0029     policy.initializeCandidates(args,
0030                                 std::declval<AppendOnlyNavigationStream&>(),
0031                                 std::declval<const Logger&>());
0032   };
0033 };
0034 
0035 /// Base class for all navigation policies. The policy needs to be *connected*
0036 /// to a delegate via a virtual method for it to become active. The update
0037 /// method is not part of the class interface. The conventional `updateState`
0038 /// method is only required for use with the navigation policy factory,
0039 /// otherwise `connect` is free to connect any function.
0040 class INavigationPolicy {
0041  public:
0042   /// Noop update function that is suitable as a default for default navigation
0043   /// delegates.
0044   static void noopInitializeCandidates(
0045       const NavigationArguments& /*unused*/,
0046       const AppendOnlyNavigationStream& /*unused*/, const Logger& /*unused*/) {
0047     // This is a noop
0048   }
0049 
0050   /// Virtual destructor so policies can be held through this base class.
0051   virtual ~INavigationPolicy() = default;
0052 
0053   /// Connect a policy with a delegate (usually a member of a volume).
0054   /// This method exists to allow a policy to ensure a non-virtual function is
0055   /// registered with the delegate.
0056   /// @param delegate The delegate to connect to
0057   virtual void connect(NavigationDelegate& delegate) const = 0;
0058 
0059   /// Convenience function to walk over all navigation policies. The default
0060   /// implementation just calls this on itself, while the @ref
0061   /// MultiNavigationPolicy will call it on all it's children.
0062   /// @param visitor The visitor function to call for each policy
0063   virtual void visit(
0064       const std::function<void(const INavigationPolicy&)>& visitor) const {
0065     visitor(*this);
0066   }
0067 
0068  protected:
0069   /// Internal helper function for derived classes that conform to the concept
0070   /// and have a conventional `updateState` method. Mainly used to save some
0071   /// boilerplate.
0072   /// @tparam T The type of the navigation policy
0073   /// @param delegate The delegate to connect to
0074   template <NavigationPolicyConcept T>
0075   void connectDefault(NavigationDelegate& delegate) const {
0076     // This cannot be a concept because we use it in CRTP below
0077     const auto* self = static_cast<const T*>(this);
0078     delegate.template connect<&T::initializeCandidates>(self);
0079   }
0080 };
0081 
0082 }  // namespace Acts