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/INavigationPolicy.hpp"
0012 
0013 namespace Acts {
0014 
0015 /// Base class for multi navigation policies
0016 class MultiNavigationPolicyBase : public INavigationPolicy {};
0017 
0018 /// Combined navigation policy that calls all contained other navigation
0019 /// policies. This class only works with policies complying with
0020 /// `NavigationPolicyConcept`, which means that they have a conventional
0021 /// `updateState` method.
0022 ///
0023 /// Internally, this uses a delegate chain factory to produce an unrolled
0024 /// delegate chain.
0025 ///
0026 /// @tparam Policies The navigation policies to be combined
0027 template <NavigationPolicyConcept... Policies>
0028   requires(sizeof...(Policies) > 0)
0029 class MultiNavigationPolicy final : public MultiNavigationPolicyBase {
0030  public:
0031   /// Constructor from a set of child policies.
0032   /// @param policies The child policies
0033   explicit MultiNavigationPolicy(Policies&&... policies)
0034       : m_policies{std::move(policies)...} {}
0035 
0036   /// Implementation of the connection to a navigation delegate.
0037   /// It uses the delegate chain factory to produce a delegate chain and stores
0038   /// that chain in the owning navigation delegate.
0039   /// @param delegate The navigation delegate to connect to
0040   void connect(NavigationDelegate& delegate) const override {
0041     auto factory = add(DelegateChainBuilder{delegate},
0042                        std::index_sequence_for<Policies...>{});
0043 
0044     factory.store(delegate);
0045   }
0046 
0047   /// Access the contained policies
0048   /// @return The contained policies
0049   const std::tuple<Policies...>& policies() const { return m_policies; }
0050 
0051  private:
0052   /// Internal helper to build the delegate chain
0053   template <std::size_t... Is>
0054   constexpr auto add(
0055       auto factory,
0056       std::integer_sequence<std::size_t, Is...> /*unused*/) const {
0057     return add<Is...>(factory);
0058   }
0059 
0060   /// Internal helper to build the delegate chain
0061   template <std::size_t I, std::size_t... Is>
0062   constexpr auto add(auto factory) const {
0063     using policy_type = std::tuple_element_t<I, decltype(m_policies)>;
0064     auto* policy = &std::get<I>(m_policies);
0065 
0066     auto added =
0067         factory.template add<&policy_type::initializeCandidates>(policy);
0068 
0069     if constexpr (sizeof...(Is) > 0) {
0070       return add<Is...>(added);
0071     } else {
0072       return added;
0073     }
0074   }
0075 
0076   std::tuple<Policies...> m_policies;
0077 };
0078 }  // namespace Acts