ACTS
Experiment-independent tracking
Loading...
Searching...
No Matches
composite_actor.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/actor.hpp"
13#include "detray/definitions/containers.hpp"
14#include "detray/definitions/detail/qualifiers.hpp"
15#include "detray/propagator/base_actor.hpp"
16#include "detray/propagator/concepts.hpp"
17#include "detray/propagator/detail/type_traits.hpp"
18#include "detray/utils/tuple_helpers.hpp"
19
20// System include(s)
21#include <concepts>
22#include <type_traits>
23#include <utility>
24
25namespace detray {
26
35template <concepts::actor principal_actor_t = base_actor,
36 concepts::actor... observers>
37class composite_actor final : public principal_actor_t {
38 public:
40 struct is_comp_actor : public std::true_type {};
41
44 using actor_type = principal_actor_t;
46 using state = typename actor_type::state;
48 using result = typename actor_type::result;
49
50 // Make sure the result type contains a status code
51 static_assert(std::is_base_of_v<detray::actor::result, result>);
52
55 detail::tuple_cat_t<detail::state_tuple_t<observers>...>;
58 detail::tuple_cat_t<detail::state_ref_tuple_t<observers>...>;
59
70 template <typename actor_states_t, typename propagator_state_t,
71 typename subj_result_t = typename actor::empty_result>
72 DETRAY_HOST_DEVICE void operator()(actor_states_t &states,
73 propagator_state_t &p_state,
74 subj_result_t &&subject_res = {}) const {
75 // State of the primary actor that is implement by this composite actor
76 auto &actor_state = detail::get<typename actor_type::state &>(states);
77
78 // Do your own work ...
79 // Two cases: This is a simple actor or observing actor (pass on its
80 // subject's state)
81 result res{};
82 if constexpr (std::same_as<subj_result_t, actor::empty_result>) {
83 res = actor_type::operator()(actor_state, p_state);
84 } else {
85 res = actor_type::operator()(actor_state, p_state,
86 std::forward<subj_result_t>(subject_res));
87 }
88
89 // ... then run the observers on the new result
90 if (res.status == actor::status::e_notify) {
91 notify(states, p_state, res,
92 std::make_index_sequence<sizeof...(observers)>{});
93 }
94 }
95
96 private:
103 template <concepts::actor observer_t, typename actor_states_t,
104 typename propagator_state_t>
105 DETRAY_HOST_DEVICE inline void notify(const observer_t &observer,
106 actor_states_t &states,
107 propagator_state_t &p_state,
108 result &res) const {
109 // Two cases: observer is a simple actor or a composite actor
110 if constexpr (!concepts::composite_actor<observer_t>) {
111 // No actor state defined (empty)
112 if constexpr (std::same_as<typename observer_t::state,
113 detray::base_actor::state>) {
114 observer(p_state, res);
115 } else {
116 observer(detail::get<typename observer_t::state &>(states), p_state,
117 res);
118 }
119 } else {
120 observer(states, p_state, res);
121 }
122 }
123
132 template <std::size_t... indices, typename actor_states_t,
133 typename propagator_state_t>
134 DETRAY_HOST_DEVICE inline void notify(
135 actor_states_t &states, propagator_state_t &p_state, result &res,
136 std::index_sequence<indices...> /*ids*/) const {
137 (notify(detail::get<indices>(m_observers), states, p_state, res), ...);
138 }
139
141 DETRAY_NO_UNIQUE_ADDRESS dtuple<observers...> m_observers = {};
142};
143
144} // namespace detray
Composition of actors.
Definition composite_actor.hpp:37
detail::tuple_cat_t< detail::state_ref_tuple_t< observers >... > observer_state_refs
Definition composite_actor.hpp:57
void operator()(actor_states_t &states, propagator_state_t &p_state, subj_result_t &&subject_res={}) const
Call to the implementation of the actor (the actor possibly being an observer itself).
Definition composite_actor.hpp:72
detail::tuple_cat_t< detail::state_tuple_t< observers >... > observer_states
Definition composite_actor.hpp:54
Concept for a simple actor.
Definition concepts.hpp:25
Detray include(s).
Definition array_operators.hpp:18
detray::tuple< types... > dtuple
Tuple type used by detray storage and dispatch.
Definition containers.hpp:46
Dummy result type that signals that no result is present.
Definition base_actor.hpp:31
Base class actor implementation.
Definition base_actor.hpp:20
Tag whether this is a composite type (hides the def in the actor).
Definition composite_actor.hpp:40