ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
abort_list_implementation.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file abort_list_implementation.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 
11 #include <algorithm>
13 
14 namespace Acts {
15 
16 namespace detail {
17 
18 namespace {
21 template <bool has_result = true>
22 struct condition_caller {
23  template <typename condition, typename result_t, typename propagator_state_t,
24  typename stepper_t>
25  static bool check(const condition& c, const result_t& r,
26  propagator_state_t& state, const stepper_t& stepper) {
27  using action_type = action_type_t<condition>;
28  using result_type = result_type_t<action_type>;
29 
30  return c(state, stepper, r.template get<result_type>());
31  }
32 };
33 
36 template <>
37 struct condition_caller<false> {
38  template <typename condition, typename result_t, typename propagator_state_t,
39  typename stepper_t>
40  static bool check(const condition& c, const result_t& /*result*/,
41  propagator_state_t& state, const stepper_t& stepper) {
42  return c(state, stepper);
43  }
44 };
45 } // end of anonymous namespace
46 
47 template <typename... conditions>
49 
53 template <typename first, typename... others>
54 struct abort_list_impl<first, others...> {
55  template <typename T, typename result_t, typename propagator_state_t,
56  typename stepper_t>
57  static bool check(const T& conditions_tuple, const result_t& result,
58  propagator_state_t& state, const stepper_t& stepper) {
59  // get the right helper for calling the abort condition
60  constexpr bool has_result = has_action_type_v<first>;
61  using caller_type = condition_caller<has_result>;
62 
63  // get the cache abort condition
64  const auto& this_condition = std::get<first>(conditions_tuple);
65 
66  // - check abort conditions recursively
67  // - make use of short-circuit evaluation
68  // -> skip remaining conditions if this abort condition evaluates to true
69  bool abort = caller_type::check(this_condition, result, state, stepper) ||
70  abort_list_impl<others...>::check(conditions_tuple, result,
71  state, stepper);
72 
73  return abort;
74  }
75 };
76 
78 template <typename last>
79 struct abort_list_impl<last> {
80  template <typename T, typename result_t, typename propagator_state_t,
81  typename stepper_t>
82  static bool check(const T& conditions_tuple, const result_t& result,
83  propagator_state_t& state, const stepper_t& stepper) {
84  // get the right helper for calling the abort condition
85  constexpr bool has_result = has_action_type_v<last>;
86  const auto& this_condition = std::get<last>(conditions_tuple);
87 
88  return condition_caller<has_result>::check(this_condition, result, state,
89  stepper);
90  }
91 };
92 
94 template <>
95 struct abort_list_impl<> {
96  template <typename T, typename result_t, typename propagator_state_t,
97  typename stepper_t>
98  static bool check(const T& /*unused*/, const result_t& /*result*/,
99  propagator_state_t& /*state*/,
100  const stepper_t& /*unused*/) {
101  return false;
102  }
103 };
104 
105 } // namespace detail
106 
107 } // namespace Acts