Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:43

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2018 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Utilities/detail/MPL/type_collector.hpp"
0012 
0013 #include <utility>
0014 
0015 namespace Acts::detail {
0016 
0017 namespace {
0018 
0019 /// This is the caller used if the aborter uses the result and that result type
0020 /// exists
0021 template <bool has_result = true>
0022 struct abort_checker {
0023   template <typename aborter_t, typename propagator_state_t, typename stepper_t,
0024             typename navigator_t, typename... Args>
0025   static bool check(const aborter_t& aborter, propagator_state_t& state,
0026                     const stepper_t& stepper, const navigator_t& navigator,
0027                     Args&&... args) {
0028     using action_type = action_type_t<aborter_t>;
0029     using result_type = result_type_t<action_type>;
0030 
0031     return aborter(state, stepper, navigator, state.template get<result_type>(),
0032                    std::forward<Args>(args)...);
0033   }
0034 };
0035 
0036 /// This is the caller used if the aborter only uses the cache it has no access
0037 /// to the result
0038 template <>
0039 struct abort_checker<false> {
0040   template <typename aborter_t, typename propagator_state_t, typename stepper_t,
0041             typename navigator_t, typename... Args>
0042   static bool check(const aborter_t& aborter, propagator_state_t& state,
0043                     const stepper_t& stepper, const navigator_t& navigator,
0044                     Args&&... args) {
0045     return aborter(state, stepper, navigator, std::forward<Args>(args)...);
0046   }
0047 };
0048 }  // end of anonymous namespace
0049 
0050 template <typename... conditions>
0051 struct abort_list_impl;
0052 
0053 /// This is the check call on the a list of conditions it calls the apparent
0054 /// condition and broadcasts the call to the remaining ones
0055 template <typename first, typename... others>
0056 struct abort_list_impl<first, others...> {
0057   template <typename T, typename propagator_state_t, typename stepper_t,
0058             typename navigator_t, typename... Args>
0059   static bool check(const T& aborters_tuple, propagator_state_t& state,
0060                     const stepper_t& stepper, const navigator_t& navigator,
0061                     Args&&... args) {
0062     // get the right helper for calling the abort condition
0063     constexpr bool has_result = has_action_type_v<first>;
0064 
0065     // get the cache abort condition
0066     const auto& this_aborter = std::get<first>(aborters_tuple);
0067     // - check abort conditions recursively
0068     // - make use of short-circuit evaluation
0069     // -> skip remaining conditions if this abort condition evaluates to true
0070 
0071     bool abort = abort_checker<has_result>::check(this_aborter, state, stepper,
0072                                                   navigator, args...) ||
0073                  abort_list_impl<others...>::check(aborters_tuple, state,
0074                                                    stepper, navigator, args...);
0075 
0076     return abort;
0077   }
0078 };
0079 
0080 /// This is the check call on the a last of all conditions
0081 template <typename last>
0082 struct abort_list_impl<last> {
0083   template <typename T, typename propagator_state_t, typename stepper_t,
0084             typename navigator_t, typename... Args>
0085   static bool check(const T& aborters_tuple, propagator_state_t& state,
0086                     const stepper_t& stepper, const navigator_t& navigator,
0087                     Args&&... args) {
0088     // get the right helper for calling the abort condition
0089     constexpr bool has_result = has_action_type_v<last>;
0090     const auto& this_aborter = std::get<last>(aborters_tuple);
0091     return abort_checker<has_result>::check(
0092         this_aborter, state, stepper, navigator, std::forward<Args>(args)...);
0093   }
0094 };
0095 
0096 /// This is the empty call list - never abort
0097 template <>
0098 struct abort_list_impl<> {
0099   template <typename T, typename propagator_state_t, typename stepper_t,
0100             typename navigator_t, typename... Args>
0101   static bool check(const T& /*aborter_tuple*/, propagator_state_t& /*state*/,
0102                     const stepper_t& /*stepper*/,
0103                     const navigator_t& /*navigator*/, Args&&... /*args*/) {
0104     return false;
0105   }
0106 };
0107 
0108 }  // namespace Acts::detail