Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Core/include/Acts/Navigation/INavigationPolicy.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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