Analysis Software
Documentation for sPHENIX simulation 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 <utility>
14 
15 namespace Acts {
16 namespace detail {
17 
18 namespace {
19 
22 template <bool has_result = true>
23 struct abort_checker {
24  template <typename aborter_t, typename propagator_state_t, typename stepper_t,
25  typename navigator_t, typename result_t, typename... Args>
26  static bool check(const aborter_t& aborter, propagator_state_t& state,
27  const stepper_t& stepper, const navigator_t& navigator,
28  const result_t& result, Args&&... args) {
29  using action_type = action_type_t<aborter_t>;
30  using result_type = result_type_t<action_type>;
31 
32  return aborter(state, stepper, navigator,
33  result.template get<result_type>(),
34  std::forward<Args>(args)...);
35  }
36 };
37 
40 template <>
41 struct abort_checker<false> {
42  template <typename aborter_t, typename propagator_state_t, typename stepper_t,
43  typename navigator_t, typename result_t, typename... Args>
44  static bool check(const aborter_t& aborter, propagator_state_t& state,
45  const stepper_t& stepper, const navigator_t& navigator,
46  const result_t& /*result*/, Args&&... args) {
47  return aborter(state, stepper, navigator, std::forward<Args>(args)...);
48  }
49 };
50 } // end of anonymous namespace
51 
52 template <typename... conditions>
54 
58 template <typename first, typename... others>
59 struct abort_list_impl<first, others...> {
60  template <typename T, typename propagator_state_t, typename stepper_t,
61  typename navigator_t, typename result_t, typename... Args>
62  static bool check(const T& aborters_tuple, propagator_state_t& state,
63  const stepper_t& stepper, const navigator_t& navigator,
64  const result_t& result, Args&&... args) {
65  // get the right helper for calling the abort condition
66  constexpr bool has_result = has_action_type_v<first>;
67 
68  // get the cache abort condition
69  const auto& this_aborter = std::get<first>(aborters_tuple);
70  // - check abort conditions recursively
71  // - make use of short-circuit evaluation
72  // -> skip remaining conditions if this abort condition evaluates to true
73 
74  bool abort =
75  abort_checker<has_result>::check(this_aborter, state, stepper,
76  navigator, result, args...) ||
77  abort_list_impl<others...>::check(aborters_tuple, state, stepper,
78  navigator, result, args...);
79 
80  return abort;
81  }
82 };
83 
85 template <typename last>
86 struct abort_list_impl<last> {
87  template <typename T, typename propagator_state_t, typename stepper_t,
88  typename navigator_t, typename result_t, typename... Args>
89  static bool check(const T& aborters_tuple, propagator_state_t& state,
90  const stepper_t& stepper, const navigator_t& navigator,
91  const result_t& result, Args&&... args) {
92  // get the right helper for calling the abort condition
93  constexpr bool has_result = has_action_type_v<last>;
94  const auto& this_aborter = std::get<last>(aborters_tuple);
95  return abort_checker<has_result>::check(this_aborter, state, stepper,
96  navigator, result,
97  std::forward<Args>(args)...);
98  }
99 };
100 
102 template <>
103 struct abort_list_impl<> {
104  template <typename T, typename propagator_state_t, typename stepper_t,
105  typename navigator_t, typename result_t, typename... Args>
106  static bool check(const T& /*aborter_tuple*/, propagator_state_t& /*state*/,
107  const stepper_t& /*stepper*/,
108  const navigator_t& /*navigator*/,
109  const result_t& /*result*/, Args&&... /*args*/) {
110  return false;
111  }
112 };
113 
114 } // namespace detail
115 } // namespace Acts