Skip to content

Commit

Permalink
some reshuffling in MTJ
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgessinger committed Dec 12, 2023
1 parent b2d2b4e commit c89e7ce
Showing 1 changed file with 45 additions and 39 deletions.
84 changes: 45 additions & 39 deletions Core/include/Acts/EventData/MultiTrajectory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,58 @@ class MultiTrajectory {
return getTrackState(addTrackState(istate));
}

/// @}

/// @anchor track_state_container_iteration
/// @name MultiTrajectory track state iteraion
/// @{

/// Visit all previous states starting at a given endpoint.
///
/// @param iendpoint index of the last state
/// @param callable non-modifying functor to be called with each point
template <typename F>
void visitBackwards(IndexType iendpoint, F&& callable) const;

/// Apply a function to all previous states starting at a given endpoint.
///
/// @param iendpoint index of the last state
/// @param callable modifying functor to be called with each point
///
/// @warning If the trajectory contains multiple components with common
/// points, this can have an impact on the other components.
/// @note Only available if the MultiTrajectory is not read-only
template <typename F, bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
void applyBackwards(IndexType iendpoint, F&& callable) {
static_assert(detail_lt::VisitorConcept<F, TrackStateProxy>,
"Callable needs to satisfy VisitorConcept");

if (iendpoint == MultiTrajectoryTraits::kInvalid) {
throw std::runtime_error(
"Cannot apply backwards with kInvalid as endpoint");
}

while (true) {
auto ts = getTrackState(iendpoint);
if constexpr (std::is_same_v<std::invoke_result_t<F, TrackStateProxy>,
bool>) {
bool proceed = callable(ts);
// this point has no parent and ends the trajectory, or a break was
// requested
if (!proceed || !ts.hasPrevious()) {
break;
}
} else {
callable(ts);
// this point has no parent and ends the trajectory
if (!ts.hasPrevious()) {
break;
}
}
iendpoint = ts.previous();
}
}

/// Range for the track states from @p iendpoint to the trajectory start
/// @param iendpoint Trajectory entry point to start from
/// @return Iterator pair to iterate over
Expand Down Expand Up @@ -326,45 +371,6 @@ class MultiTrajectory {
return range_t{getTrackState(istartpoint)};
}

/// Apply a function to all previous states starting at a given endpoint.
///
/// @param iendpoint index of the last state
/// @param callable modifying functor to be called with each point
///
/// @warning If the trajectory contains multiple components with common
/// points, this can have an impact on the other components.
/// @note Only available if the MultiTrajectory is not read-only
template <typename F, bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
void applyBackwards(IndexType iendpoint, F&& callable) {
static_assert(detail_lt::VisitorConcept<F, TrackStateProxy>,
"Callable needs to satisfy VisitorConcept");

if (iendpoint == MultiTrajectoryTraits::kInvalid) {
throw std::runtime_error(
"Cannot apply backwards with kInvalid as endpoint");
}

while (true) {
auto ts = getTrackState(iendpoint);
if constexpr (std::is_same_v<std::invoke_result_t<F, TrackStateProxy>,
bool>) {
bool proceed = callable(ts);
// this point has no parent and ends the trajectory, or a break was
// requested
if (!proceed || !ts.hasPrevious()) {
break;
}
} else {
callable(ts);
// this point has no parent and ends the trajectory
if (!ts.hasPrevious()) {
break;
}
}
iendpoint = ts.previous();
}
}

/// @}

/// @anchor track_state_container_columns
Expand Down

0 comments on commit c89e7ce

Please sign in to comment.