Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:55

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