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 
12 
13 #include <algorithm>
14 
15 namespace Acts {
16 
17 namespace detail {
18 
19 namespace {
22 template <bool has_result = true>
23 struct condition_caller {
24  template <typename condition, typename result_t, typename propagator_state_t,
25  typename stepper_t>
26  static bool check(const condition& c, const result_t& r,
27  propagator_state_t& state, const stepper_t& stepper) {
28  using action_type = action_type_t<condition>;
29  using result_type = result_type_t<action_type>;
30 
31  return c(state, stepper, r.template get<result_type>());
32  }
33 };
34 
37 template <>
38 struct condition_caller<false> {
39  template <typename condition, typename result_t, typename propagator_state_t,
40  typename stepper_t>
41  static bool check(const condition& c, const result_t& /*result*/,
42  propagator_state_t& state, const stepper_t& stepper) {
43  return c(state, stepper);
44  }
45 };
46 } // end of anonymous namespace
47 
48 template <typename... conditions>
50 
54 template <typename first, typename... others>
55 struct abort_list_impl<first, others...> {
56  template <typename T, typename result_t, typename propagator_state_t,
57  typename stepper_t>
58  static bool check(const T& conditions_tuple, const result_t& result,
59  propagator_state_t& state, const stepper_t& stepper) {
60  // get the right helper for calling the abort condition
61  constexpr bool has_result = has_action_type_v<first>;
62  using caller_type = condition_caller<has_result>;
63 
64  // get the cache abort condition
65  const auto& this_condition = std::get<first>(conditions_tuple);
66 
67  // - check abort conditions recursively
68  // - make use of short-circuit evaluation
69  // -> skip remaining conditions if this abort condition evaluates to true
70  bool abort = caller_type::check(this_condition, result, state, stepper) ||
71  abort_list_impl<others...>::check(conditions_tuple, result,
72  state, stepper);
73 
74  return abort;
75  }
76 };
77 
79 template <typename last>
80 struct abort_list_impl<last> {
81  template <typename T, typename result_t, typename propagator_state_t,
82  typename stepper_t>
83  static bool check(const T& conditions_tuple, const result_t& result,
84  propagator_state_t& state, const stepper_t& stepper) {
85  // get the right helper for calling the abort condition
86  constexpr bool has_result = has_action_type_v<last>;
87  const auto& this_condition = std::get<last>(conditions_tuple);
88 
89  return condition_caller<has_result>::check(this_condition, result, state,
90  stepper);
91  }
92 };
93 
95 template <>
96 struct abort_list_impl<> {
97  template <typename T, typename result_t, typename propagator_state_t,
98  typename stepper_t>
99  static bool check(const T& /*unused*/, const result_t& /*result*/,
100  propagator_state_t& /*state*/,
101  const stepper_t& /*unused*/) {
102  return false;
103  }
104 };
105 
106 } // namespace detail
107 
108 } // namespace Acts