ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
actor_chain.hpp
1// This file is part of the ACTS project.
2//
3// Copyright (C) 2016 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 https://mozilla.org/MPL/2.0/.
8
9#pragma once
10
11// Project include(s)
12#include "detray/definitions/containers.hpp"
13#include "detray/definitions/detail/qualifiers.hpp"
14#include "detray/propagator/base_actor.hpp"
15#include "detray/propagator/composite_actor.hpp"
16#include "detray/utils/logging.hpp"
17#include "detray/utils/tuple.hpp"
18#include "detray/utils/tuple_helpers.hpp"
19
20// System include(s)
21#include <concepts>
22#include <optional>
23#include <type_traits>
24#include <utility>
25
26namespace detray {
27
34template <concepts::actor... actors_t>
36 public:
38 using actor_tuple = dtuple<actors_t...>;
39
42 detail::unique_t<detail::tuple_cat_t<detail::state_tuple_t<actors_t>...>>;
43
45 using state_ref_tuple = detail::unique_t<
46 detail::tuple_cat_t<detail::state_ref_tuple_t<actors_t>...>>;
47
52 template <typename actor_states_t, typename propagator_state_t>
53 DETRAY_HOST_DEVICE void operator()(actor_states_t &states,
54 propagator_state_t &p_state) const {
55 DETRAY_VERBOSE_HOST_DEVICE("Run actors...");
56 run(states, p_state, std::make_index_sequence<sizeof...(actors_t)>{});
57 }
58
60 DETRAY_HOST_DEVICE constexpr const actor_tuple &actors() const {
61 return m_actors;
62 }
63
65 DETRAY_HOST_DEVICE
66 static constexpr auto make_default_actor_states() {
67 // Only possible if each state is default initializable (including
68 // obsevers to the actors in actors_t)
69 if constexpr (detail::tuple_all_v<std::is_default_constructible,
70 state_tuple>) {
71 return state_tuple();
72 } else {
73 return std::nullopt;
74 }
75 }
76
80 DETRAY_HOST_DEVICE static constexpr state_ref_tuple setup_actor_states(
81 state_tuple &t) {
82 return setup_actor_states(
83 t, std::make_index_sequence<detail::tuple_size_v<state_tuple>>{});
84 }
85
86 private:
92 template <concepts::actor actor_t, typename actor_states_t,
93 typename propagator_state_t>
94 DETRAY_HOST_DEVICE inline void run(const actor_t &actr,
95 actor_states_t &states,
96 propagator_state_t &p_state) const {
97 if constexpr (!typename actor_t::is_comp_actor()) {
98 // No actor state defined (empty)
99 if constexpr (std::same_as<typename actor_t::state,
101 actr(p_state);
102 } else {
103 actr(detail::get<typename actor_t::state &>(states), p_state);
104 }
105 } else {
106 actr(states, p_state);
107 }
108 }
109
114 template <typename actor_states_t, typename propagator_state_t,
115 std::size_t... indices>
116 DETRAY_HOST_DEVICE inline void run(
117 actor_states_t &states, propagator_state_t &p_state,
118 std::index_sequence<indices...> /*ids*/) const {
119 (run(detail::get<indices>(m_actors), states, p_state), ...);
120 }
121
123 template <std::size_t... indices>
124 DETRAY_HOST_DEVICE static constexpr state_ref_tuple setup_actor_states(
125 state_tuple &t, std::index_sequence<indices...> /*ids*/) {
126 return detray::tie(detail::get<indices>(t)...);
127 }
128
130 DETRAY_NO_UNIQUE_ADDRESS actor_tuple m_actors = {};
131};
132
134template <>
135class actor_chain<> {
136 public:
143
146
150 template <typename actor_states_t, typename propagator_state_t>
151 DETRAY_HOST_DEVICE constexpr void operator()(
152 actor_states_t & /*states*/, propagator_state_t & /*p_state*/) const {
153 /*Do nothing*/
154 }
155
157 DETRAY_HOST_DEVICE constexpr const actor_tuple &actors() const {
158 return m_actors;
159 }
160
162 DETRAY_HOST_DEVICE
164 return dtuple<>{};
165 }
166
168 DETRAY_HOST_DEVICE static constexpr state_ref_tuple setup_actor_states(
169 const state_tuple & /*unused*/) {
170 return {};
171 }
172
173 private:
174 DETRAY_NO_UNIQUE_ADDRESS actor_tuple m_actors = {};
175};
176
177} // namespace detray
state_tuple state
Empty states replaces a real actor states container.
Definition actor_chain.hpp:145
dtuple<> actor_tuple
Empty tuple representing the actor list.
Definition actor_chain.hpp:138
static consteval state_tuple make_default_actor_states()
Definition actor_chain.hpp:163
dtuple<> state_tuple
Empty tuple representing actor state storage.
Definition actor_chain.hpp:140
constexpr const actor_tuple & actors() const
Definition actor_chain.hpp:157
constexpr void operator()(actor_states_t &, propagator_state_t &) const
Call to actors does nothing.
Definition actor_chain.hpp:151
static constexpr state_ref_tuple setup_actor_states(const state_tuple &)
Definition actor_chain.hpp:168
dtuple<> state_ref_tuple
Empty tuple representing actor state references.
Definition actor_chain.hpp:142
The interface to the actors and aborters in the propagation.
Definition actor_chain.hpp:35
detail::unique_t< detail::tuple_cat_t< detail::state_tuple_t< actors_t >... > > state_tuple
Tuple of actor states (including states of observing actors, if present).
Definition actor_chain.hpp:41
static constexpr state_ref_tuple setup_actor_states(state_tuple &t)
Create references to each actor state in the tuple.
Definition actor_chain.hpp:80
constexpr const actor_tuple & actors() const
Definition actor_chain.hpp:60
static constexpr auto make_default_actor_states()
Definition actor_chain.hpp:66
void operator()(actor_states_t &states, propagator_state_t &p_state) const
Call all actors in the chain.
Definition actor_chain.hpp:53
dtuple< actors_t... > actor_tuple
Types of the actors that are registered in the chain.
Definition actor_chain.hpp:38
detail::unique_t< detail::tuple_cat_t< detail::state_ref_tuple_t< actors_t >... > > state_ref_tuple
Tuple of state references that is used in the propagator.
Definition actor_chain.hpp:45
Concept for a simple actor.
Definition concepts.hpp:25
Detray include(s).
Definition array_operators.hpp:18
constexpr detray::tuple< Ts &... > tie(Ts &...args)
Create a tuple of references to the supplied objects.
Definition tuple.hpp:211
detray::tuple< types... > dtuple
Tuple type used by detray storage and dispatch.
Definition containers.hpp:46
Defines the actors state. Hidden by actor implementations.
Definition base_actor.hpp:25