Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:23:14

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 #include "Acts/Navigation/MultiNavigationPolicy.hpp"
0010 
0011 namespace Acts {
0012 
0013 MultiNavigationPolicy::MultiNavigationPolicy(
0014     std::vector<std::unique_ptr<INavigationPolicy>>&& policies)
0015     : m_policyPtrs(std::move(policies)) {
0016   m_delegates.reserve(m_policyPtrs.size());
0017   for (const auto& policy : m_policyPtrs) {
0018     auto& delegate = m_delegates.emplace_back();
0019     policy->connect(delegate);
0020     if (!delegate.connected()) {
0021       throw std::runtime_error(
0022           "Failed to connect policy in MultiNavigationPolicyDynamic");
0023     }
0024   }
0025 }
0026 
0027 void MultiNavigationPolicy::connect(NavigationDelegate& delegate) const {
0028   if (!std::ranges::all_of(m_delegates,
0029                            [](const auto& d) { return d.connected(); })) {
0030     throw std::runtime_error(
0031         "Not all delegates are connected to MultiNavigationPolicyDynamic");
0032   }
0033   delegate.connect<&MultiNavigationPolicy::initializeCandidates>(this);
0034 }
0035 
0036 std::span<const std::unique_ptr<INavigationPolicy>>
0037 MultiNavigationPolicy::policies() const {
0038   return std::span{m_policyPtrs};
0039 }
0040 
0041 void MultiNavigationPolicy::initializeCandidates(
0042     [[maybe_unused]] const GeometryContext& gctx,
0043     const NavigationArguments& args, AppendOnlyNavigationStream& stream,
0044     const Logger& logger) const {
0045   for (const auto& delegate : m_delegates) {
0046     delegate(gctx, args, stream, logger);
0047   }
0048 }
0049 
0050 void MultiNavigationPolicy::visit(
0051     const std::function<void(const INavigationPolicy&)>& visitor) const {
0052   visitor(*this);
0053   for (const auto& policy : m_policyPtrs) {
0054     visitor(*policy);
0055   }
0056 }
0057 
0058 }  // namespace Acts