Skip to content

Commit

Permalink
refactor: Improved const-correctness for TrackContainer in Examples (#…
Browse files Browse the repository at this point in the history
…1871)

Also includes a fix of a missing method in the ConstVectorTrackContainer class.
  • Loading branch information
paulgessinger committed Feb 17, 2023
1 parent 910ec13 commit eff1a08
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Core/include/Acts/EventData/VectorTrackContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ class ConstVectorTrackContainer final
return ConstParameters{m_params[itrack].data()};
}

ConstCovariance covariance(IndexType itrack) const {
return ConstCovariance{m_cov[itrack].data()};
}

// END INTERFACE
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ std::vector<std::size_t> computeSharedHits(
return sharedHitCountPerTrack;
}

std::size_t computeTrackHits(const Acts::VectorMultiTrajectory& multiTrajectory,
const std::size_t tip) {
std::size_t computeTrackHits(
const Acts::ConstVectorMultiTrajectory& multiTrajectory,
const std::size_t tip) {
std::size_t result = 0;

multiTrajectory.visitBackwards(tip, [&](const auto&) { ++result; });
Expand Down
12 changes: 11 additions & 1 deletion Examples/Algorithms/TrackFinding/src/TrackFindingAlgorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ ActsExamples::ProcessCode ActsExamples::TrackFindingAlgorithm::execute(
m_memoryStatistics.local().hist +=
tracks.trackStateContainer().statistics().hist;

ctx.eventStore.add(m_cfg.outputTracks, std::move(tracks));
auto constTrackStateContainer =
std::make_shared<Acts::ConstVectorMultiTrajectory>(
std::move(*trackStateContainer));

auto constTrackContainer = std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackContainer));

ConstTrackContainer constTracks{constTrackContainer,
constTrackStateContainer};

ctx.eventStore.add(m_cfg.outputTracks, std::move(constTracks));
return ActsExamples::ProcessCode::SUCCESS;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "ActsExamples/TrackFitting/TrackFittingAlgorithm.hpp"

#include "Acts/EventData/VectorMultiTrajectory.hpp"
#include "Acts/EventData/VectorTrackContainer.hpp"
#include "Acts/Surfaces/PerigeeSurface.hpp"
#include "Acts/TrackFitting/GainMatrixSmoother.hpp"
#include "Acts/TrackFitting/GainMatrixUpdater.hpp"
Expand Down Expand Up @@ -148,6 +149,12 @@ ActsExamples::ProcessCode ActsExamples::TrackFittingAlgorithm::execute(
trackStateContainer->statistics().toStream(ss);
ACTS_DEBUG(ss.str());

ctx.eventStore.add(m_cfg.outputTracks, std::move(tracks));
ConstTrackContainer constTracks{
std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackContainer)),
std::make_shared<Acts::ConstVectorMultiTrajectory>(
std::move(*trackStateContainer))};

ctx.eventStore.add(m_cfg.outputTracks, std::move(constTracks));
return ActsExamples::ProcessCode::SUCCESS;
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ ActsExamples::ProcessCode ActsExamples::TrackFittingChi2Algorithm::execute(
}
}

ctx.eventStore.add(m_cfg.outputTracks, std::move(tracks));
ConstTrackContainer constTracks{
std::make_shared<Acts::ConstVectorTrackContainer>(
std::move(*trackContainer)),
std::make_shared<Acts::ConstVectorMultiTrajectory>(
std::move(*trackStateContainer))};

ctx.eventStore.add(m_cfg.outputTracks, std::move(constTracks));
// TODO: add chi2 values as output?
return ActsExamples::ProcessCode::SUCCESS;
}
3 changes: 2 additions & 1 deletion Examples/Algorithms/Utilities/src/TracksToTrajectories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
namespace ActsExamples {

ProcessCode TracksToTrajectories::execute(const AlgorithmContext& ctx) const {
const auto& tracks = ctx.eventStore.get<TrackContainer>(m_cfg.inputTracks);
const auto& tracks =
ctx.eventStore.get<ConstTrackContainer>(m_cfg.inputTracks);

// Prepare the output data with MultiTrajectory
TrajectoriesContainer trajectories;
Expand Down
4 changes: 4 additions & 0 deletions Examples/Framework/include/ActsExamples/EventData/Track.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ using TrackContainer =
Acts::TrackContainer<Acts::VectorTrackContainer,
Acts::VectorMultiTrajectory, std::shared_ptr>;

using ConstTrackContainer =
Acts::TrackContainer<Acts::ConstVectorTrackContainer,
Acts::ConstVectorMultiTrajectory, std::shared_ptr>;

} // namespace ActsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace ActsExamples {
struct Trajectories final {
public:
/// (Reconstructed) trajectory with multiple states.
using MultiTrajectory = Acts::VectorMultiTrajectory;
using MultiTrajectory = Acts::ConstVectorMultiTrajectory;
/// Fitted parameters identified by indices in the multi trajectory.
using IndexedParameters =
std::unordered_map<Acts::MultiTrajectoryTraits::IndexType,
Expand Down

0 comments on commit eff1a08

Please sign in to comment.