-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add concepts for Track(State) backends (#2093)
This PR adds concepts for the `MultiTrajectory` and `TrackContainer` backends. It also centralizes the index typedef and `kInvalid` sentinel value definition. Blocked by: - #2091
- Loading branch information
1 parent
f7ccfee
commit 20a45ed
Showing
9 changed files
with
277 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
Core/include/Acts/EventData/MultiTrajectoryBackendConcept.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Definitions/Algebra.hpp" | ||
#include "Acts/Definitions/TrackParametrization.hpp" | ||
#include "Acts/EventData/SourceLink.hpp" | ||
#include "Acts/EventData/TrackStatePropMask.hpp" | ||
#include "Acts/EventData/Types.hpp" | ||
#include "Acts/Surfaces/Surface.hpp" | ||
#include "Acts/Utilities/HashedString.hpp" | ||
|
||
#include <any> | ||
#include <type_traits> | ||
|
||
#if defined(ACTS_CONCEPTS_SUPPORTED) | ||
#include <concepts> | ||
|
||
namespace Acts { | ||
|
||
namespace detail { | ||
using Parameters = Eigen::Map<BoundVector>; | ||
using Covariance = Eigen::Map<BoundMatrix>; | ||
|
||
using ConstParameters = Eigen::Map<const BoundVector>; | ||
using ConstCovariance = Eigen::Map<const BoundMatrix>; | ||
|
||
} // namespace detail | ||
|
||
template <typename T> | ||
concept CommonMultiTrajectoryBackend = requires(const T& cv, HashedString key, | ||
TrackIndexType istate) { | ||
{ cv.calibratedSize_impl(istate) } -> std::same_as<TrackIndexType>; | ||
|
||
{ cv.getUncalibratedSourceLink_impl(istate) } -> std::same_as<SourceLink>; | ||
|
||
{ cv.referenceSurface_impl(istate) } -> std::same_as<const Surface*>; | ||
|
||
{ cv.parameters_impl(istate) } -> std::same_as<detail::ConstParameters>; | ||
|
||
{ cv.covariance_impl(istate) } -> std::same_as<detail::ConstCovariance>; | ||
|
||
{ cv.jacobian_impl(istate) } -> std::same_as<detail::ConstCovariance>; | ||
|
||
{ | ||
cv.template measurement_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<const ActsVector<2>>>; | ||
|
||
{ | ||
cv.template measurementCovariance_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<const ActsSymMatrix<2>>>; | ||
|
||
{ cv.has_impl(key, istate) } -> std::same_as<bool>; | ||
|
||
{ cv.size_impl() } -> std::same_as<TrackIndexType>; | ||
|
||
{ cv.component_impl(key, istate) } -> std::same_as<std::any>; | ||
|
||
{ cv.hasColumn_impl(key) } -> std::same_as<bool>; | ||
}; | ||
|
||
template <typename T> | ||
concept ConstMultiTrajectoryBackend = CommonMultiTrajectoryBackend<T> && | ||
requires(T v, HashedString key, TrackIndexType istate) { | ||
{ v.parameters_impl(istate) } -> std::same_as<detail::ConstParameters>; | ||
|
||
{ v.covariance_impl(istate) } -> std::same_as<detail::ConstCovariance>; | ||
|
||
{ v.jacobian_impl(istate) } -> std::same_as<detail::ConstCovariance>; | ||
|
||
{ | ||
v.template measurement_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<const ActsVector<2>>>; | ||
|
||
{ | ||
v.template measurementCovariance_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<const ActsSymMatrix<2>>>; | ||
}; | ||
|
||
template <typename T> | ||
concept MutableMultiTrajectoryBackend = CommonMultiTrajectoryBackend<T> && | ||
requires(T v, HashedString key, TrackIndexType istate, | ||
TrackStatePropMask mask, std::string col, size_t dim, | ||
SourceLink sl, std::shared_ptr<const Surface> surface) { | ||
{ v.parameters_impl(istate) } -> std::same_as<detail::Parameters>; | ||
|
||
{ v.covariance_impl(istate) } -> std::same_as<detail::Covariance>; | ||
|
||
{ v.jacobian_impl(istate) } -> std::same_as<detail::Covariance>; | ||
|
||
{ | ||
v.template measurement_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<ActsVector<2>>>; | ||
|
||
{ | ||
v.template measurementCovariance_impl<2>(istate) | ||
} -> std::same_as<Eigen::Map<ActsSymMatrix<2>>>; | ||
|
||
{ v.addTrackState_impl() } -> std::same_as<TrackIndexType>; | ||
|
||
{v.shareFrom_impl(istate, istate, mask, mask)}; | ||
|
||
{v.unset_impl(mask, istate)}; | ||
|
||
{v.clear_impl()}; | ||
|
||
// As far as I know there's no good way to assert that there's a generic | ||
// template function | ||
{v.template addColumn_impl<uint32_t>(col)}; | ||
{v.template addColumn_impl<uint64_t>(col)}; | ||
{v.template addColumn_impl<int32_t>(col)}; | ||
{v.template addColumn_impl<int64_t>(col)}; | ||
{v.template addColumn_impl<float>(col)}; | ||
{v.template addColumn_impl<double>(col)}; | ||
|
||
{v.allocateCalibrated_impl(istate, dim)}; | ||
|
||
{v.setUncalibratedSourceLink_impl(istate, sl)}; | ||
|
||
{v.setReferenceSurface_impl(istate, surface)}; | ||
|
||
// @TODO: Add copyDynamicFrom + ensureDynamicColumns for MTJ like in TrackContainer | ||
}; | ||
|
||
} // namespace Acts | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
Core/include/Acts/EventData/TrackContainerBackendConcept.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include "Acts/Definitions/TrackParametrization.hpp" | ||
#include "Acts/EventData/Types.hpp" | ||
#include "Acts/Surfaces/Surface.hpp" | ||
#include "Acts/Utilities/HashedString.hpp" | ||
|
||
#include <any> | ||
#include <type_traits> | ||
|
||
#if defined(ACTS_CONCEPTS_SUPPORTED) | ||
#include <concepts> | ||
|
||
namespace Acts { | ||
|
||
namespace detail { | ||
using Parameters = Eigen::Map<BoundVector>; | ||
using Covariance = Eigen::Map<BoundMatrix>; | ||
|
||
using ConstParameters = Eigen::Map<const BoundVector>; | ||
using ConstCovariance = Eigen::Map<const BoundMatrix>; | ||
} // namespace detail | ||
|
||
template <typename T> | ||
concept ConstTrackContainerBackend = requires(const T& cv, HashedString key, | ||
TrackIndexType itrack) { | ||
{ cv.size_impl() } -> std::same_as<std::size_t>; | ||
|
||
{ cv.component_impl(key, itrack) } -> std::same_as<std::any>; | ||
|
||
{ cv.parameters(itrack) } -> std::same_as<detail::ConstParameters>; | ||
|
||
{ cv.covariance(itrack) } -> std::same_as<detail::ConstCovariance>; | ||
|
||
{ cv.hasColumn_impl(key) } -> std::same_as<bool>; | ||
|
||
{ cv.referenceSurface_impl(itrack) } -> std::same_as<const Surface*>; | ||
}; | ||
|
||
template <typename T> | ||
concept MutableTrackContainerBackend = ConstTrackContainerBackend<T> && | ||
requires(T v, HashedString key, TrackIndexType itrack, std::string col, | ||
const T& other, std::shared_ptr<const Surface> sharedSurface) { | ||
{ v.parameters(itrack) } -> std::same_as<detail::Parameters>; | ||
|
||
{ v.covariance(itrack) } -> std::same_as<detail::Covariance>; | ||
|
||
{ v.addTrack_impl() } -> std::same_as<TrackIndexType>; | ||
|
||
{v.removeTrack_impl(itrack)}; | ||
|
||
// As far as I know there's no good way to assert that there's a generic | ||
// template function | ||
{v.template addColumn_impl<uint32_t>(col)}; | ||
{v.template addColumn_impl<uint64_t>(col)}; | ||
{v.template addColumn_impl<int32_t>(col)}; | ||
{v.template addColumn_impl<int64_t>(col)}; | ||
{v.template addColumn_impl<float>(col)}; | ||
{v.template addColumn_impl<double>(col)}; | ||
|
||
{v.copyDynamicFrom_impl(itrack, other, itrack)}; | ||
|
||
{v.ensureDynamicColumns_impl(other)}; | ||
|
||
{v.reserve(itrack)}; | ||
|
||
{v.setReferenceSurface_impl(itrack, sharedSurface)}; | ||
}; | ||
|
||
template <typename T> | ||
struct IsReadOnlyTrackContainer; | ||
|
||
template <typename T> | ||
concept TrackContainerBackend = ConstTrackContainerBackend<T> && | ||
(IsReadOnlyTrackContainer<T>::value || MutableTrackContainerBackend<T>); | ||
|
||
} // namespace Acts | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// This file is part of the Acts project. | ||
// | ||
// Copyright (C) 2023 CERN for the benefit of the Acts project | ||
// | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <limits> | ||
|
||
namespace Acts { | ||
using TrackIndexType = std::uint32_t; | ||
static constexpr TrackIndexType kTrackIndexInvalid = | ||
std::numeric_limits<TrackIndexType>::max(); | ||
|
||
} // namespace Acts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.