File indexing completed on 2026-05-15 07:37:39
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 = TrackIndexType;
0041 static constexpr auto kInvalid = kTrackIndexInvalid;
0042
0043 using Parameters =
0044 typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CoefficientsMap;
0045 using Covariance =
0046 typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CovarianceMap;
0047
0048 using ConstParameters =
0049 typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CoefficientsMap;
0050 using ConstCovariance =
0051 typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CovarianceMap;
0052
0053 protected:
0054 VectorTrackContainerBase() = default;
0055
0056 VectorTrackContainerBase(const VectorTrackContainerBase& other);
0057
0058 VectorTrackContainerBase(VectorTrackContainerBase&& other) = default;
0059
0060
0061
0062
0063 template <bool EnsureConst, typename T>
0064 static std::any component_impl(T& instance, HashedString key,
0065 IndexType itrack) {
0066 if constexpr (EnsureConst) {
0067 static_assert(std::is_const_v<std::remove_reference_t<T>>,
0068 "Is not const");
0069 }
0070
0071 using namespace Acts::HashedStringLiteral;
0072 switch (key) {
0073 case "tipIndex"_hash:
0074 return &instance.m_tipIndex[itrack];
0075 case "stemIndex"_hash:
0076 return &instance.m_stemIndex[itrack];
0077 case "params"_hash:
0078 return &instance.m_params[itrack];
0079 case "cov"_hash:
0080 return &instance.m_cov[itrack];
0081 case "nMeasurements"_hash:
0082 return &instance.m_nMeasurements[itrack];
0083 case "nHoles"_hash:
0084 return &instance.m_nHoles[itrack];
0085 case "chi2"_hash:
0086 return &instance.m_chi2[itrack];
0087 case "ndf"_hash:
0088 return &instance.m_ndf[itrack];
0089 case "nOutliers"_hash:
0090 return &instance.m_nOutliers[itrack];
0091 case "nSharedHits"_hash:
0092 return &instance.m_nSharedHits[itrack];
0093 default:
0094 auto it = instance.m_dynamic.find(key);
0095 if (it == instance.m_dynamic.end()) {
0096 throw std::runtime_error("Unable to handle this component");
0097 }
0098
0099 std::conditional_t<EnsureConst, const detail::DynamicColumnBase*,
0100 detail::DynamicColumnBase*>
0101 col = it->second.get();
0102 assert(col && "Dynamic column is null");
0103 return col->get(itrack);
0104 }
0105 }
0106
0107 bool checkConsistency() const {
0108 std::size_t size = m_tipIndex.size();
0109
0110 bool result = true;
0111 result = result && m_tipIndex.size() == size;
0112 assert(result);
0113 result = result && m_stemIndex.size() == size;
0114 assert(result);
0115 result = result && m_particleHypothesis.size() == size;
0116 assert(result);
0117 result = result && m_params.size() == size;
0118 assert(result);
0119 result = result && m_cov.size() == size;
0120 assert(result);
0121 result = result && m_referenceSurfaces.size() == size;
0122 assert(result);
0123 result = result && m_nMeasurements.size() == size;
0124 assert(result);
0125 result = result && m_nHoles.size() == size;
0126 assert(result);
0127 result = result && m_chi2.size() == size;
0128 assert(result);
0129 result = result && m_ndf.size() == size;
0130 assert(result);
0131 result = result && m_nOutliers.size() == size;
0132 assert(result);
0133 result = result && m_nSharedHits.size() == size;
0134
0135 for (const auto& [key, col] : m_dynamic) {
0136 static_cast<void>(key);
0137 result = result && col->size() == size;
0138 }
0139
0140 return result;
0141 }
0142
0143 public:
0144 constexpr bool hasColumn_impl(HashedString key) const {
0145 using namespace Acts::HashedStringLiteral;
0146 switch (key) {
0147 case "tipIndex"_hash:
0148 case "stemIndex"_hash:
0149 case "params"_hash:
0150 case "cov"_hash:
0151 case "nMeasurements"_hash:
0152 case "nHoles"_hash:
0153 case "chi2"_hash:
0154 case "ndf"_hash:
0155 case "nOutliers"_hash:
0156 case "nSharedHits"_hash:
0157 return true;
0158 default:
0159 return m_dynamic.contains(key);
0160 }
0161 }
0162
0163 const Surface* referenceSurface_impl(IndexType itrack) const {
0164 return m_referenceSurfaces[itrack].get();
0165 }
0166
0167 ParticleHypothesis particleHypothesis_impl(IndexType itrack) const {
0168 return m_particleHypothesis[itrack];
0169 }
0170
0171 std::size_t size_impl() const {
0172 assert(checkConsistency());
0173 return m_tipIndex.size();
0174 }
0175
0176 detail::DynamicKeyRange<detail::DynamicColumnBase> dynamicKeys_impl() const {
0177 return {m_dynamic.begin(), m_dynamic.end()};
0178 }
0179
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_tsp::FixedSizeTypes<eBoundSize>::Coefficients>
0188 m_params;
0189 std::vector<typename detail_tsp::FixedSizeTypes<eBoundSize>::Covariance>
0190 m_cov;
0191 std::vector<std::shared_ptr<const Surface>> m_referenceSurfaces;
0192
0193 std::vector<unsigned int> m_nMeasurements;
0194 std::vector<unsigned int> m_nHoles;
0195 std::vector<float> m_chi2;
0196 std::vector<unsigned int> m_ndf;
0197 std::vector<unsigned int> m_nOutliers;
0198 std::vector<unsigned int> m_nSharedHits;
0199
0200 std::unordered_map<HashedString, std::unique_ptr<detail::DynamicColumnBase>>
0201 m_dynamic;
0202 std::vector<HashedString> m_dynamicKeys;
0203 };
0204
0205 }
0206
0207 class VectorTrackContainer;
0208 class ConstVectorTrackContainer;
0209
0210 template <>
0211 struct IsReadOnlyTrackContainer<VectorTrackContainer> : std::false_type {};
0212
0213
0214 class VectorTrackContainer final : public detail_vtc::VectorTrackContainerBase {
0215 public:
0216 VectorTrackContainer() : VectorTrackContainerBase{} {}
0217
0218
0219 VectorTrackContainer(const VectorTrackContainer& other) = default;
0220
0221 VectorTrackContainer(VectorTrackContainer&&) = default;
0222
0223
0224
0225 explicit VectorTrackContainer(const ConstVectorTrackContainer& other);
0226
0227 public:
0228
0229
0230
0231 std::any component_impl(HashedString key, IndexType itrack) {
0232 return detail_vtc::VectorTrackContainerBase::component_impl<false>(
0233 *this, key, itrack);
0234 }
0235
0236 std::any component_impl(HashedString key, IndexType itrack) const {
0237 return detail_vtc::VectorTrackContainerBase::component_impl<true>(
0238 *this, key, itrack);
0239 }
0240
0241 IndexType addTrack_impl();
0242
0243 void removeTrack_impl(IndexType itrack);
0244
0245 template <typename T>
0246 constexpr void addColumn_impl(const std::string_view& key) {
0247 HashedString hashedKey = hashStringDynamic(key);
0248 m_dynamic.insert({hashedKey, std::make_unique<detail::DynamicColumn<T>>()});
0249 }
0250
0251 Parameters parameters(IndexType itrack) {
0252 return Parameters{m_params[itrack].data()};
0253 }
0254
0255 ConstParameters parameters(IndexType itrack) const {
0256 return ConstParameters{m_params[itrack].data()};
0257 }
0258
0259 Covariance covariance(IndexType itrack) {
0260 return Covariance{m_cov[itrack].data()};
0261 }
0262
0263 ConstCovariance covariance(IndexType itrack) const {
0264 return ConstCovariance{m_cov[itrack].data()};
0265 }
0266
0267 void copyDynamicFrom_impl(IndexType dstIdx, HashedString key,
0268 const std::any& srcPtr);
0269
0270 void ensureDynamicColumns_impl(
0271 const detail_vtc::VectorTrackContainerBase& other);
0272
0273
0274
0275
0276 void setReferenceSurface_impl(IndexType itrack,
0277 std::shared_ptr<const Surface> surface) {
0278 m_referenceSurfaces[itrack] = std::move(surface);
0279 }
0280
0281
0282
0283
0284 void setParticleHypothesis_impl(
0285 IndexType itrack, const ParticleHypothesis& particleHypothesis) {
0286 m_particleHypothesis[itrack] = particleHypothesis;
0287 }
0288
0289
0290
0291
0292
0293
0294 void reserve(IndexType size);
0295
0296
0297 void clear();
0298
0299
0300
0301 std::size_t size() const;
0302 };
0303
0304 static_assert(TrackContainerBackend<VectorTrackContainer>,
0305 "VectorTrackContainer does not fulfill TrackContainerBackend");
0306
0307 class ConstVectorTrackContainer;
0308
0309 template <>
0310 struct IsReadOnlyTrackContainer<ConstVectorTrackContainer> : std::true_type {};
0311
0312
0313 class ConstVectorTrackContainer final
0314 : public detail_vtc::VectorTrackContainerBase {
0315 public:
0316 ConstVectorTrackContainer() : VectorTrackContainerBase{} {}
0317
0318
0319
0320 ConstVectorTrackContainer(const ConstVectorTrackContainer& other) = default;
0321
0322
0323 explicit ConstVectorTrackContainer(const VectorTrackContainer& other)
0324 : VectorTrackContainerBase{other} {
0325 assert(checkConsistency());
0326 }
0327
0328
0329 ConstVectorTrackContainer(ConstVectorTrackContainer&&) = default;
0330
0331
0332 explicit ConstVectorTrackContainer(VectorTrackContainer&& other)
0333 : VectorTrackContainerBase{std::move(other)} {
0334 assert(checkConsistency());
0335 }
0336
0337 public:
0338
0339
0340
0341
0342
0343
0344 std::any component_impl(HashedString key, IndexType itrack) const {
0345 return detail_vtc::VectorTrackContainerBase::component_impl<true>(
0346 *this, key, itrack);
0347 }
0348
0349
0350
0351
0352 ConstParameters parameters(IndexType itrack) const {
0353 return ConstParameters{m_params[itrack].data()};
0354 }
0355
0356
0357
0358
0359 ConstCovariance covariance(IndexType itrack) const {
0360 return ConstCovariance{m_cov[itrack].data()};
0361 }
0362
0363
0364 };
0365
0366 static_assert(
0367 TrackContainerBackend<ConstVectorTrackContainer>,
0368 "ConstVectorTrackContainer does not fulfill TrackContainerBackend");
0369
0370 inline VectorTrackContainer::VectorTrackContainer(
0371 const ConstVectorTrackContainer& other)
0372 : VectorTrackContainerBase{other} {
0373 assert(checkConsistency());
0374 }
0375
0376 }