Skip to content

Commit

Permalink
Adapt actor chain for empty state and to produce actor state tuple if…
Browse files Browse the repository at this point in the history
… states are default constructible
  • Loading branch information
niermann999 committed Nov 5, 2024
1 parent 309ca41 commit 9cabb32
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 24 deletions.
55 changes: 47 additions & 8 deletions core/include/detray/propagator/actor_chain.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2022 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

#include <type_traits>
#include <utility>

// Project include(s)
#include "detray/definitions/detail/containers.hpp"
#include "detray/definitions/detail/qualifiers.hpp"
#include "detray/propagator/base_actor.hpp"
#include "detray/utils/tuple_helpers.hpp"

// System include(s)
#include <concepts>
#include <optional>
#include <type_traits>
#include <utility>

namespace detray {

/// The interface to the actors and aborters in the propagation.
Expand Down Expand Up @@ -44,7 +49,27 @@ class actor_chain {
}

/// @returns the actor list
DETRAY_HOST_DEVICE const actor_list_type &actors() const { return _actors; }
DETRAY_HOST_DEVICE const actor_list_type &actors() const {
return m_actors;
}

/// @returns a tuple of default constructible actor states and a
/// corresponding tuple of references
DETRAY_HOST_DEVICE
static constexpr auto make_actor_states() {
// Only possible if each state is default initializable
if constexpr ((std::default_initializable<typename actors_t::state> &&
...)) {
tuple_t<typename actors_t::state...> states{};

return std::make_tuple(
states,
make_ref_tuple(
states, std::make_index_sequence<sizeof...(actors_t)>{}));
} else {
return std::nullopt;
}
}

private:
/// Call the actors. Either single actor or composition.
Expand All @@ -58,7 +83,13 @@ class actor_chain {
actor_states_t &states,
propagator_state_t &p_state) const {
if constexpr (!typename actor_t::is_comp_actor()) {
actr(detail::get<typename actor_t::state &>(states), p_state);
// No actor state defined (empty)
if constexpr (std::same_as<typename actor_t::state,
detray::actor::state>) {
actr(p_state);
} else {
actr(detail::get<typename actor_t::state &>(states), p_state);
}
} else {
actr(states, p_state);
}
Expand All @@ -73,11 +104,19 @@ class actor_chain {
DETRAY_HOST_DEVICE inline void run(
actor_states_t &states, propagator_state_t &p_state,
std::index_sequence<indices...> /*ids*/) const {
(run(detail::get<indices>(_actors), states, p_state), ...);
(run(detail::get<indices>(m_actors), states, p_state), ...);
}

/// @returns a tuple of reference for every state in the tuple @param t
template <std::size_t... indices>
DETRAY_HOST_DEVICE static constexpr state make_ref_tuple(
tuple_t<typename actors_t::state...> &t,
std::index_sequence<indices...> /*ids*/) {
return detray::tie(detail::get<indices>(t)...);
}

/// Tuple of actors
actor_list_type _actors = {};
actor_list_type m_actors = {};
};

/// Empty actor chain (placeholder)
Expand Down
5 changes: 1 addition & 4 deletions core/include/detray/propagator/actors/parameter_resetter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ struct parameter_resetter : actor {

using scalar_type = dscalar<algebra_t>;

struct state {};

/// Mask store visitor
struct kernel {

Expand Down Expand Up @@ -56,8 +54,7 @@ struct parameter_resetter : actor {
};

template <typename propagator_state_t>
DETRAY_HOST_DEVICE void operator()(state& /*resetter_state*/,
propagator_state_t& propagation) const {
DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const {

const auto& navigation = propagation._navigation;
auto& stepping = propagation._stepping;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ struct parameter_transporter : actor {
using bound_matrix_t = bound_matrix<algebra_t>;
/// @}

struct state {};

struct get_full_jacobian_kernel {

template <typename mask_group_t, typename index_t,
Expand Down Expand Up @@ -86,8 +84,7 @@ struct parameter_transporter : actor {
};

template <typename propagator_state_t>
DETRAY_HOST_DEVICE void operator()(state& /*actor_state*/,
propagator_state_t& propagation) const {
DETRAY_HOST_DEVICE void operator()(propagator_state_t& propagation) const {
auto& stepping = propagation._stepping;
const auto& navigation = propagation._navigation;

Expand Down
25 changes: 17 additions & 8 deletions core/include/detray/propagator/base_actor.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/** Detray library, part of the ACTS project (R&D line)
*
* (c) 2022 CERN for the benefit of the ACTS project
* (c) 2022-2024 CERN for the benefit of the ACTS project
*
* Mozilla Public License Version 2.0
*/

#pragma once

#include <type_traits>
#include <utility>

// Propagate include(s)
#include "detray/definitions/detail/containers.hpp"
#include "detray/definitions/detail/qualifiers.hpp"
#include "detray/utils/tuple_helpers.hpp"

// System include(s)
#include <concepts>
#include <type_traits>
#include <utility>

namespace detray {

/// Base class actor implementation
Expand Down Expand Up @@ -77,7 +80,7 @@ class composite_actor final : public actor_impl_t {
}

// ... then run the observers on the updated state
notify(_observers, states, actor_state, p_state,
notify(m_observers, states, actor_state, p_state,
std::make_index_sequence<sizeof...(observers)>{});
}

Expand All @@ -97,8 +100,14 @@ class composite_actor final : public actor_impl_t {
propagator_state_t &p_state) const {
// Two cases: observer is a simple actor or a composite actor
if constexpr (!typename observer_t::is_comp_actor()) {
observer(detail::get<typename observer_t::state &>(states),
actor_state, p_state);
// No actor state defined (empty)
if constexpr (std::same_as<typename observer_t::state,
detray::actor::state>) {
observer(actor_state, p_state);
} else {
observer(detail::get<typename observer_t::state &>(states),
actor_state, p_state);
}
} else {
observer(states, actor_state, p_state);
}
Expand Down Expand Up @@ -126,7 +135,7 @@ class composite_actor final : public actor_impl_t {
}

/// Keep the observers (might be composites again)
tuple_t<observers...> _observers = {};
tuple_t<observers...> m_observers = {};
};

} // namespace detray

0 comments on commit 9cabb32

Please sign in to comment.