File indexing completed on 2025-09-17 08:01:33
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/TrackParametrization.hpp"
0012 #include "Acts/EventData/MultiTrajectory.hpp"
0013 #include "Acts/EventData/ParticleHypothesis.hpp"
0014 #include "Acts/EventData/TrackContainer.hpp"
0015 #include "Acts/EventData/TrackContainerBackendConcept.hpp"
0016 #include "Acts/EventData/detail/DynamicColumn.hpp"
0017 #include "Acts/EventData/detail/DynamicKeyIterator.hpp"
0018 #include "Acts/Utilities/HashedString.hpp"
0019
0020 #include <any>
0021 #include <cassert>
0022 #include <cstddef>
0023 #include <memory>
0024 #include <stdexcept>
0025 #include <string>
0026 #include <type_traits>
0027 #include <unordered_map>
0028 #include <utility>
0029 #include <vector>
0030
0031 namespace Acts {
0032 class Surface;
0033 template <typename T>
0034 struct IsReadOnlyTrackContainer;
0035
0036 namespace detail_vtc {
0037
0038 class VectorTrackContainerBase {
0039 public:
0040 using IndexType = MultiTrajectoryTraits::IndexType;
0041 static constexpr auto kInvalid = MultiTrajectoryTraits::kInvalid;
0042 static constexpr auto MeasurementSizeMax =
0043 MultiTrajectoryTraits::MeasurementSizeMax;
0044
0045 using Parameters =
0046 typename detail_lt::FixedSizeTypes<eBoundSize, false>::CoefficientsMap;
0047 using Covariance =
0048 typename detail_lt::FixedSizeTypes<eBoundSize, false>::CovarianceMap;
0049
0050 using ConstParameters =
0051 typename detail_lt::FixedSizeTypes<eBoundSize, true>::CoefficientsMap;
0052 using ConstCovariance =
0053 typename detail_lt::FixedSizeTypes<eBoundSize, true>::CovarianceMap;
0054
0055 protected:
0056 VectorTrackContainerBase() = default;
0057
0058 VectorTrackContainerBase(const VectorTrackContainerBase& other);
0059
0060 VectorTrackContainerBase(VectorTrackContainerBase&& other) = default;
0061
0062
0063
0064 template <bool EnsureConst, typename T>
0065 static std::any component_impl(T& instance, HashedString key,
0066 IndexType itrack) {
0067 using namespace Acts::HashedStringLiteral;
0068 if constexpr (EnsureConst) {
0069 static_assert(std::is_const_v<std::remove_reference_t<T>>,
0070 "Is not const");
0071 }
0072
0073 using namespace Acts::HashedStringLiteral;
0074 switch (key) {
0075 case "tipIndex"_hash:
0076 return &instance.m_tipIndex[itrack];
0077 case "stemIndex"_hash:
0078 return &instance.m_stemIndex[itrack];
0079 case "params"_hash:
0080 return &instance.m_params[itrack];
0081 case "cov"_hash:
0082 return &instance.m_cov[itrack];
0083 case "nMeasurements"_hash:
0084 return &instance.m_nMeasurements[itrack];
0085 case "nHoles"_hash:
0086 return &instance.m_nHoles[itrack];
0087 case "chi2"_hash:
0088 return &instance.m_chi2[itrack];
0089 case "ndf"_hash:
0090 return &instance.m_ndf[itrack];
0091 case "nOutliers"_hash:
0092 return &instance.m_nOutliers[itrack];
0093 case "nSharedHits"_hash:
0094 return &instance.m_nSharedHits[itrack];
0095 default:
0096 auto it = instance.m_dynamic.find(key);
0097 if (it == instance.m_dynamic.end()) {
0098 throw std::runtime_error("Unable to handle this component");
0099 }
0100
0101 std::conditional_t<EnsureConst, const detail::DynamicColumnBase*,
0102 detail::DynamicColumnBase*>
0103 col = it->second.get();
0104 assert(col && "Dynamic column is null");
0105 return col->get(itrack);
0106 }
0107 }
0108
0109 bool checkConsistency() const {
0110 std::size_t size = m_tipIndex.size();
0111
0112 bool result = true;
0113 result = result && m_tipIndex.size() == size;
0114 assert(result);
0115 result = result && m_stemIndex.size() == size;
0116 assert(result);
0117 result = result && m_particleHypothesis.size() == size;
0118 assert(result);
0119 result = result && m_params.size() == size;
0120 assert(result);
0121 result = result && m_cov.size() == size;
0122 assert(result);
0123 result = result && m_referenceSurfaces.size() == size;
0124 assert(result);
0125 result = result && m_nMeasurements.size() == size;
0126 assert(result);
0127 result = result && m_nHoles.size() == size;
0128 assert(result);
0129 result = result && m_chi2.size() == size;
0130 assert(result);
0131 result = result && m_ndf.size() == size;
0132 assert(result);
0133 result = result && m_nOutliers.size() == size;
0134 assert(result);
0135 result = result && m_nSharedHits.size() == size;
0136
0137 for (const auto& [key, col] : m_dynamic) {
0138 (void)key;
0139 result = result && col->size() == size;
0140 }
0141
0142 return result;
0143 }
0144
0145 public:
0146 constexpr bool hasColumn_impl(HashedString key) const {
0147 using namespace Acts::HashedStringLiteral;
0148 switch (key) {
0149 case "tipIndex"_hash:
0150 case "stemIndex"_hash:
0151 case "params"_hash:
0152 case "cov"_hash:
0153 case "nMeasurements"_hash:
0154 case "nHoles"_hash:
0155 case "chi2"_hash:
0156 case "ndf"_hash:
0157 case "nOutliers"_hash:
0158 case "nSharedHits"_hash:
0159 return true;
0160 default:
0161 return m_dynamic.contains(key);
0162 }
0163 }
0164
0165 const Surface* referenceSurface_impl(IndexType itrack) const {
0166 return m_referenceSurfaces[itrack].get();
0167 }
0168
0169 ParticleHypothesis particleHypothesis_impl(IndexType itrack) const {
0170 return m_particleHypothesis[itrack];
0171 }
0172
0173 std::size_t size_impl() const {
0174 assert(checkConsistency());
0175 return m_tipIndex.size();
0176 }
0177
0178 detail::DynamicKeyRange<detail::DynamicColumnBase> dynamicKeys_impl() const {
0179 return {m_dynamic.begin(), m_dynamic.end()};
0180 }
0181
0182
0183
0184 std::vector<IndexType> m_tipIndex;
0185 std::vector<IndexType> m_stemIndex;
0186 std::vector<ParticleHypothesis> m_particleHypothesis;
0187 std::vector<typename detail_lt::FixedSizeTypes<eBoundSize>::Coefficients>
0188 m_params;
0189 std::vector<typename detail_lt::FixedSizeTypes<eBoundSize>::Covariance> m_cov;
0190 std::vector<std::shared_ptr<const Surface>> m_referenceSurfaces;
0191
0192 std::vector<unsigned int> m_nMeasurements;
0193 std::vector<unsigned int> m_nHoles;
0194 std::vector<float> m_chi2;
0195 std::vector<unsigned int> m_ndf;
0196 std::vector<unsigned int> m_nOutliers;
0197 std::vector<unsigned int> m_nSharedHits;
0198
0199 std::unordered_map<HashedString, std::unique_ptr<detail::DynamicColumnBase>>
0200 m_dynamic;
0201 std::vector<HashedString> m_dynamicKeys;
0202 };
0203
0204 }
0205
0206 class VectorTrackContainer;
0207 class ConstVectorTrackContainer;
0208
0209 template <>
0210 struct IsReadOnlyTrackContainer<VectorTrackContainer> : std::false_type {};
0211
0212 class VectorTrackContainer final : public detail_vtc::VectorTrackContainerBase {
0213 public:
0214 VectorTrackContainer() : VectorTrackContainerBase{} {}
0215 VectorTrackContainer(const VectorTrackContainer& other) = default;
0216 VectorTrackContainer(VectorTrackContainer&&) = default;
0217
0218 explicit VectorTrackContainer(const ConstVectorTrackContainer& other);
0219
0220 public:
0221
0222
0223 std::any component_impl(HashedString key, IndexType itrack) {
0224 return detail_vtc::VectorTrackContainerBase::component_impl<false>(
0225 *this, key, itrack);
0226 }
0227
0228 std::any component_impl(HashedString key, IndexType itrack) const {
0229 return detail_vtc::VectorTrackContainerBase::component_impl<true>(
0230 *this, key, itrack);
0231 }
0232
0233 IndexType addTrack_impl();
0234
0235 void removeTrack_impl(IndexType itrack);
0236
0237 template <typename T>
0238 constexpr void addColumn_impl(const std::string_view& key) {
0239 HashedString hashedKey = hashStringDynamic(key);
0240 m_dynamic.insert({hashedKey, std::make_unique<detail::DynamicColumn<T>>()});
0241 }
0242
0243 Parameters parameters(IndexType itrack) {
0244 return Parameters{m_params[itrack].data()};
0245 }
0246
0247 ConstParameters parameters(IndexType itrack) const {
0248 return ConstParameters{m_params[itrack].data()};
0249 }
0250
0251 Covariance covariance(IndexType itrack) {
0252 return Covariance{m_cov[itrack].data()};
0253 }
0254
0255 ConstCovariance covariance(IndexType itrack) const {
0256 return ConstCovariance{m_cov[itrack].data()};
0257 }
0258
0259 void copyDynamicFrom_impl(IndexType dstIdx, HashedString key,
0260 const std::any& srcPtr);
0261
0262 void ensureDynamicColumns_impl(
0263 const detail_vtc::VectorTrackContainerBase& other);
0264
0265 void reserve(IndexType size);
0266 void clear();
0267 std::size_t size() const;
0268
0269 void setReferenceSurface_impl(IndexType itrack,
0270 std::shared_ptr<const Surface> surface) {
0271 m_referenceSurfaces[itrack] = std::move(surface);
0272 }
0273
0274 void setParticleHypothesis_impl(
0275 IndexType itrack, const ParticleHypothesis& particleHypothesis) {
0276 m_particleHypothesis[itrack] = particleHypothesis;
0277 }
0278
0279
0280 };
0281
0282 static_assert(TrackContainerBackend<VectorTrackContainer>,
0283 "VectorTrackContainer does not fulfill TrackContainerBackend");
0284
0285 class ConstVectorTrackContainer;
0286
0287 template <>
0288 struct IsReadOnlyTrackContainer<ConstVectorTrackContainer> : std::true_type {};
0289
0290 class ConstVectorTrackContainer final
0291 : public detail_vtc::VectorTrackContainerBase {
0292 public:
0293 ConstVectorTrackContainer() : VectorTrackContainerBase{} {}
0294
0295 ConstVectorTrackContainer(const ConstVectorTrackContainer& other) = default;
0296 explicit ConstVectorTrackContainer(const VectorTrackContainer& other)
0297 : VectorTrackContainerBase{other} {
0298 assert(checkConsistency());
0299 }
0300
0301 ConstVectorTrackContainer(ConstVectorTrackContainer&&) = default;
0302 explicit ConstVectorTrackContainer(VectorTrackContainer&& other)
0303 : VectorTrackContainerBase{std::move(other)} {
0304 assert(checkConsistency());
0305 }
0306
0307 public:
0308
0309
0310 std::any component_impl(HashedString key, IndexType itrack) const {
0311 return detail_vtc::VectorTrackContainerBase::component_impl<true>(
0312 *this, key, itrack);
0313 }
0314
0315 ConstParameters parameters(IndexType itrack) const {
0316 return ConstParameters{m_params[itrack].data()};
0317 }
0318
0319 ConstCovariance covariance(IndexType itrack) const {
0320 return ConstCovariance{m_cov[itrack].data()};
0321 }
0322
0323
0324 };
0325
0326 static_assert(
0327 TrackContainerBackend<ConstVectorTrackContainer>,
0328 "ConstVectorTrackContainer does not fulfill TrackContainerBackend");
0329
0330 inline VectorTrackContainer::VectorTrackContainer(
0331 const ConstVectorTrackContainer& other)
0332 : VectorTrackContainerBase{other} {
0333 assert(checkConsistency());
0334 }
0335
0336 }