Skip to content

Commit

Permalink
refactor: Move actor state into propagator state (#2552)
Browse files Browse the repository at this point in the history
I propose to move the actor state into the propagator state. This allows us to copy the whole propagator state and to start the propagation from a specific state after it stopped before.

Intention of this change is that algorithms may want to steer the propagation from the outside rather than from within by using an actor.
  • Loading branch information
andiwand authored Jan 19, 2024
1 parent 9f4a569 commit 6f8e9b8
Show file tree
Hide file tree
Showing 11 changed files with 349 additions and 355 deletions.
9 changes: 3 additions & 6 deletions Core/include/Acts/Propagator/AbortList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,17 @@ struct AbortList : public detail::Extendable<aborters_t...> {
/// @tparam propagator_state_t is the state type of the propagator
/// @tparam stepper_t Type of the stepper
/// @tparam navigator_t Type of the navigator
/// @tparam result_t is the result type from a certain action
///
/// @param [in,out] state is the state object from the propagator
/// @param [in] stepper Stepper used for the propagation
/// @param [in] navigator Navigator used for the propagation
/// @param [in] result is the result object from a certain action
/// @param [in] args are the arguments to be passed to the aborters
template <typename propagator_state_t, typename stepper_t,
typename navigator_t, typename result_t, typename... Args>
typename navigator_t, typename... Args>
bool operator()(propagator_state_t& state, const stepper_t& stepper,
const navigator_t& navigator, const result_t& result,
Args&&... args) const {
const navigator_t& navigator, Args&&... args) const {
using impl = detail::abort_list_impl<aborters_t...>;
return impl::check(tuple(), state, stepper, navigator, result,
return impl::check(tuple(), state, stepper, navigator,
std::forward<Args>(args)...);
}
};
Expand Down
9 changes: 3 additions & 6 deletions Core/include/Acts/Propagator/ActionList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,17 @@ struct ActionList : public detail::Extendable<actors_t...> {
/// @tparam propagator_state_t is the state type of the propagator
/// @tparam stepper_t Type of the stepper used for the propagation
/// @tparam navigator_t Type of the navigator used for the propagation
/// @tparam result_t is the result type from actions
///
/// @param [in,out] state This is the propagator state object
/// @param [in] stepper The stepper in use
/// @param [in] navigator The navigator in use
/// @param [in,out] result This is the result object from actions
/// @param [in] args The arguments to be passed to the actions
template <typename propagator_state_t, typename stepper_t,
typename navigator_t, typename result_t, typename... Args>
typename navigator_t, typename... Args>
void operator()(propagator_state_t& state, const stepper_t& stepper,
const navigator_t& navigator, result_t& result,
Args&&... args) const {
const navigator_t& navigator, Args&&... args) const {
using impl = detail::action_list_impl<actors_t...>;
impl::action(tuple(), state, stepper, navigator, result,
impl::action(tuple(), state, stepper, navigator,
std::forward<Args>(args)...);
}
};
Expand Down
1 change: 1 addition & 0 deletions Core/include/Acts/Propagator/DirectNavigator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class DirectNavigator {
struct this_result {
bool initialized = false;
};

using result_type = this_result;

/// Defaulting the constructor
Expand Down
156 changes: 81 additions & 75 deletions Core/include/Acts/Propagator/Propagator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ enum class PropagatorStage {
/// quantities
template <typename parameters_t, typename... result_list>
struct PropagatorResult : private detail::Extendable<result_list...> {
/// Accessor to additional propagation quantities
using detail::Extendable<result_list...>::get;
using detail::Extendable<result_list...>::tuple;

/// Final track parameters
std::optional<parameters_t> endParameters = std::nullopt;
Expand Down Expand Up @@ -258,13 +258,14 @@ class Propagator final {

/// @brief private Propagator state for navigation and debugging
///
/// @tparam parameters_t Type of the track parameters
/// @tparam propagator_options_t Type of the Objections object
///
/// This struct holds the common state information for propagating
/// which is independent of the actual stepper implementation.
template <typename propagator_options_t>
struct State {
template <typename propagator_options_t, typename... extension_state_t>
struct State : private detail::Extendable<extension_state_t...> {
using options_type = propagator_options_t;

/// Create the propagator state from the options
///
/// @tparam propagator_options_t the type of the propagator options
Expand All @@ -279,6 +280,9 @@ class Propagator final {
navigation{std::move(navigationIn)},
geoContext(topts.geoContext) {}

using detail::Extendable<extension_state_t...>::get;
using detail::Extendable<extension_state_t...>::tuple;

/// Propagation stage
PropagatorStage stage = PropagatorStage::invalid;

Expand All @@ -293,13 +297,42 @@ class Propagator final {

/// Context object for the geometry
std::reference_wrapper<const GeometryContext> geoContext;

/// Number of propagation steps that were carried out
unsigned int steps = 0;

/// Signed distance over which the parameters were propagated
double pathLength = 0.;
};

private:
/// @brief Helper struct determining the state's type
///
/// @tparam propagator_options_t Propagator options type
/// @tparam action_list_t List of propagation action types
///
/// This helper struct provides type definitions to extract the correct
/// propagation state type from a given TrackParameter type and an
/// ActionList.
///
template <typename propagator_options_t, typename action_list_t>
struct state_type_helper {
/// @brief Propagation state type for an arbitrary list of additional
/// propagation states
///
/// @tparam args Parameter pack specifying additional propagation states
///
template <typename... args>
using this_state_type = State<propagator_options_t, args...>;

/// @brief Propagation result type derived from a given action list
using type = typename action_list_t::template result_type<this_state_type>;
};

/// @brief Helper struct determining the result's type
///
/// @tparam parameters_t Type of final track parameters
/// @tparam action_list_t List of propagation action types
/// @tparam action_list_t List of propagation action types
///
/// This helper struct provides type definitions to extract the correct
/// propagation result type from a given TrackParameter type and an
Expand All @@ -320,6 +353,15 @@ class Propagator final {
};

public:
/// @brief Short-hand type definition for propagation state derived from
/// an action list
///
/// @tparam action_list_t List of propagation action types
///
template <typename propagator_options_t, typename action_list_t>
using action_list_t_state_t =
typename state_type_helper<propagator_options_t, action_list_t>::type;

/// @brief Short-hand type definition for propagation result derived from
/// an action list
///
Expand All @@ -330,28 +372,6 @@ class Propagator final {
using action_list_t_result_t =
typename result_type_helper<parameters_t, action_list_t>::type;

private:
/// @brief Propagate track parameters
/// Private method with propagator and stepper state
///
/// This function performs the propagation of the track parameters according
/// to the internal implementation object until at least one abort condition
/// is fulfilled, the destination surface is hit or the maximum number of
/// steps/path length as given in the propagation options is reached.
///
/// @note Does not (yet) convert into the return_type of the propagation
///
/// @tparam result_t Type of the result object for this propagation
/// @tparam propagator_state_t Type of the propagator state with options
///
/// @param [in,out] state the propagator state object
/// @param [in,out] result an existing result object to start from
///
/// @return Propagation result
template <typename result_t, typename propagator_state_t>
Result<void> propagate_impl(propagator_state_t& state,
result_t& result) const;

public:
/// @brief Propagate track parameters
///
Expand Down Expand Up @@ -379,37 +399,6 @@ class Propagator final {
propagate(const parameters_t& start, const propagator_options_t& options,
bool makeCurvilinear = true) const;

/// @brief Propagate track parameters
///
/// This function performs the propagation of the track parameters using the
/// internal stepper implementation, until at least one abort condition is
/// fulfilled or the maximum number of steps/path length provided in the
/// propagation options is reached.
///
/// @tparam parameters_t Type of initial track parameters to propagate
/// @tparam propagator_options_t Type of the propagator options
/// @tparam path_aborter_t The path aborter type to be added
///
/// @param [in] start initial track parameters to propagate
/// @param [in] options Propagation options, type Options<,>
/// @param [in] makeCurvilinear Produce curvilinear parameters at the end of the propagation
/// @param [in] inputResult an existing result object to start from
///
/// @return Propagation result containing the propagation status, final
/// track parameters, and output of actions (if they produce any)
///
template <typename parameters_t, typename propagator_options_t,
typename path_aborter_t = PathLimitReached>
Result<
action_list_t_result_t<StepperCurvilinearTrackParameters,
typename propagator_options_t::action_list_type>>
propagate(
const parameters_t& start, const propagator_options_t& options,
bool makeCurvilinear,
action_list_t_result_t<StepperCurvilinearTrackParameters,
typename propagator_options_t::action_list_type>&&
inputResult) const;

/// @brief Propagate track parameters - User method
///
/// This function performs the propagation of the track parameters according
Expand Down Expand Up @@ -437,41 +426,58 @@ class Propagator final {
propagate(const parameters_t& start, const Surface& target,
const propagator_options_t& options) const;

/// @brief Propagate track parameters - User method
/// @brief Propagate track parameters
///
/// This function performs the propagation of the track parameters according
/// to the internal implementation object until at least one abort condition
/// is fulfilled, the destination surface is hit or the maximum number of
/// steps/path length as given in the propagation options is reached.
///
/// @tparam parameters_t Type of initial track parameters to propagate
/// @tparam propagator_options_t Type of the propagator options
/// @tparam target_aborter_t The target aborter type to be added
/// @tparam path_aborter_t The path aborter type to be added
/// @note Does not (yet) convert into the return_type of the propagation
///
/// @param [in] start Initial track parameters to propagate
/// @param [in] target Target surface of to propagate to
/// @param [in] options Propagation options
/// @param [in] inputResult an existing result object to start from
/// @tparam propagator_state_t Type of the propagator state with options
///
/// @return Propagation result containing the propagation status, final
/// track parameters, and output of actions (if they produce any)
/// @param [in,out] state the propagator state object
///
/// @return Propagation result
template <typename propagator_state_t>
Result<void> propagate(propagator_state_t& state) const;

template <typename parameters_t, typename propagator_options_t,
typename path_aborter_t = PathLimitReached>
auto makeState(const parameters_t& start,
const propagator_options_t& options) const;

template <typename parameters_t, typename propagator_options_t,
typename target_aborter_t = SurfaceReached,
typename path_aborter_t = PathLimitReached>
auto makeState(const parameters_t& start, const Surface& target,
const propagator_options_t& options) const;

template <typename propagator_state_t, typename propagator_options_t>
Result<
action_list_t_result_t<StepperBoundTrackParameters,
action_list_t_result_t<StepperCurvilinearTrackParameters,
typename propagator_options_t::action_list_type>>
propagate(
const parameters_t& start, const Surface& target,
const propagator_options_t& options,
makeResult(propagator_state_t state, Result<void> result,
const propagator_options_t& options, bool makeCurvilinear) const;

template <typename propagator_state_t, typename propagator_options_t>
Result<
action_list_t_result_t<StepperBoundTrackParameters,
typename propagator_options_t::action_list_type>
inputResult) const;
typename propagator_options_t::action_list_type>>
makeResult(propagator_state_t state, Result<void> result,
const Surface& target, const propagator_options_t& options) const;

const stepper_t& stepper() const { return m_stepper; }

const navigator_t& navigator() const { return m_navigator; }

private:
const Logger& logger() const { return *m_logger; }

template <typename propagator_state_t, typename result_t>
void moveStateToResult(propagator_state_t& state, result_t& result) const;

/// Implementation of propagation algorithm
stepper_t m_stepper;

Expand Down
Loading

0 comments on commit 6f8e9b8

Please sign in to comment.