Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:11:59

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     const NavigationArguments& args, AppendOnlyNavigationStream& stream,
0043     const Logger& logger) const {
0044   for (const auto& delegate : m_delegates) {
0045     delegate(args, stream, logger);
0046   }
0047 }
0048 
0049 void MultiNavigationPolicy::visit(
0050     const std::function<void(const INavigationPolicy&)>& visitor) const {
0051   visitor(*this);
0052   for (const auto& policy : m_policyPtrs) {
0053     visitor(*policy);
0054   }
0055 }
0056 
0057 }  // namespace Acts