Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-03-28 07:45:15

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/EventData/MultiTrajectory.hpp"
0012 #include "Acts/EventData/SourceLink.hpp"
0013 #include "Acts/EventData/SubspaceHelpers.hpp"
0014 #include "Acts/EventData/TrackStatePropMask.hpp"
0015 #include "Acts/EventData/TrackStateProxy.hpp"
0016 #include "Acts/EventData/TrackStateProxyCommon.hpp"
0017 #include "Acts/EventData/TrackStateProxyConcept.hpp"
0018 #include "Acts/EventData/TrackStateType.hpp"
0019 #include "Acts/Surfaces/Surface.hpp"
0020 #include "Acts/Utilities/HashedString.hpp"
0021 
0022 #include <algorithm>
0023 #include <any>
0024 #include <cassert>
0025 #include <memory>
0026 #include <ranges>
0027 #include <string_view>
0028 #include <type_traits>
0029 #include <utility>
0030 
0031 namespace Acts {
0032 
0033 /// Type-erased track state proxy for any trajectory backend.
0034 /// @tparam read_only True for const access, false for mutable access.
0035 template <bool read_only>
0036 class AnyTrackStateProxy;
0037 
0038 namespace detail_anytstate {
0039 
0040 class TrackStateHandlerConstBase {
0041  public:
0042   using ParametersMap =
0043       typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CoefficientsMap;
0044   using ConstParametersMap =
0045       typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CoefficientsMap;
0046   using CovarianceMap =
0047       typename detail_tsp::FixedSizeTypes<eBoundSize, false>::CovarianceMap;
0048   using ConstCovarianceMap =
0049       typename detail_tsp::FixedSizeTypes<eBoundSize, true>::CovarianceMap;
0050   using EffectiveCalibratedMap =
0051       typename detail_tsp::DynamicSizeTypes<false>::CoefficientsMap;
0052   using ConstEffectiveCalibratedMap =
0053       typename detail_tsp::DynamicSizeTypes<true>::CoefficientsMap;
0054   using EffectiveCalibratedCovarianceMap =
0055       typename detail_tsp::DynamicSizeTypes<false>::CovarianceMap;
0056   using ConstEffectiveCalibratedCovarianceMap =
0057       typename detail_tsp::DynamicSizeTypes<true>::CovarianceMap;
0058 
0059   virtual ~TrackStateHandlerConstBase() = default;
0060 
0061   virtual TrackIndexType index(TrackIndexType state) const { return state; }
0062 
0063   virtual TrackIndexType calibratedSize(const void* container,
0064                                         TrackIndexType index) const = 0;
0065 
0066   virtual ConstParametersMap parameters(
0067       const void* container, TrackIndexType parametersIndex) const = 0;
0068 
0069   virtual ConstCovarianceMap covariance(
0070       const void* container, TrackIndexType covarianceIndex) const = 0;
0071 
0072   virtual const double* calibratedData(const void* container,
0073                                        TrackIndexType index) const = 0;
0074 
0075   virtual const double* calibratedCovarianceData(
0076       const void* container, TrackIndexType index) const = 0;
0077 
0078   virtual bool has(const void* container, TrackIndexType index,
0079                    HashedString key) const = 0;
0080 
0081   virtual std::any component(const void* container, TrackIndexType index,
0082                              HashedString key) const = 0;
0083 
0084   virtual bool hasColumn(const void* container, HashedString key) const = 0;
0085 
0086   virtual const Surface* referenceSurface(const void* container,
0087                                           TrackIndexType index) const = 0;
0088 
0089   virtual bool hasReferenceSurface(const void* container,
0090                                    TrackIndexType index) const = 0;
0091 
0092   virtual bool hasUncalibratedSourceLink(const void* container,
0093                                          TrackIndexType index) const = 0;
0094 
0095   virtual SourceLink getUncalibratedSourceLink(const void* container,
0096                                                TrackIndexType index) const = 0;
0097 
0098   virtual ConstCovarianceMap jacobian(const void* container,
0099                                       TrackIndexType index) const = 0;
0100 };
0101 
0102 class TrackStateHandlerMutableBase : public TrackStateHandlerConstBase {
0103  public:
0104   using TrackStateHandlerConstBase::component;
0105   using TrackStateHandlerConstBase::covariance;
0106   using TrackStateHandlerConstBase::jacobian;
0107   using TrackStateHandlerConstBase::parameters;
0108 
0109   virtual ParametersMap parameters(void* container,
0110                                    TrackIndexType parametersIndex) const = 0;
0111 
0112   virtual CovarianceMap covariance(void* container,
0113                                    TrackIndexType covarianceIndex) const = 0;
0114 
0115   virtual double* calibratedDataMutable(void* container,
0116                                         TrackIndexType index) const = 0;
0117 
0118   virtual double* calibratedCovarianceDataMutable(
0119       void* container, TrackIndexType index) const = 0;
0120 
0121   virtual std::any component(void* container, TrackIndexType index,
0122                              HashedString key) const = 0;
0123 
0124   virtual CovarianceMap jacobian(void* container,
0125                                  TrackIndexType index) const = 0;
0126 
0127   virtual void unset(void* container, TrackIndexType index,
0128                      TrackStatePropMask target) const = 0;
0129 
0130   virtual void allocateCalibrated(void* container, TrackIndexType index,
0131                                   std::size_t measdim) const = 0;
0132 
0133   virtual void setUncalibratedSourceLink(void* container, TrackIndexType index,
0134                                          SourceLink&& sourceLink) const = 0;
0135 
0136   virtual void setReferenceSurface(
0137       void* container, TrackIndexType index,
0138       std::shared_ptr<const Surface> surface) const = 0;
0139 
0140   virtual void addTrackStateComponents(void* container, TrackIndexType index,
0141                                        TrackStatePropMask mask) const = 0;
0142 };
0143 
0144 template <typename trajectory_t>
0145 struct TrackStateHandlerTraits {
0146   using Trajectory = std::remove_const_t<trajectory_t>;
0147   using MultiTrajectoryType = MultiTrajectory<Trajectory>;
0148   static constexpr bool ReadOnly =
0149       std::is_const_v<trajectory_t> || MultiTrajectoryType::ReadOnly;
0150 };
0151 
0152 template <typename trajectory_t,
0153           bool read_only = TrackStateHandlerTraits<trajectory_t>::ReadOnly>
0154 class TrackStateHandler;
0155 
0156 template <typename trajectory_t>
0157 class TrackStateHandler<trajectory_t, true> final
0158     : public TrackStateHandlerConstBase {
0159   using MultiTrajectoryType =
0160       typename TrackStateHandlerTraits<trajectory_t>::MultiTrajectoryType;
0161 
0162  public:
0163   static const TrackStateHandler& instance() {
0164     static const TrackStateHandler s_instance;
0165     return s_instance;
0166   }
0167 
0168   TrackIndexType calibratedSize(const void* container,
0169                                 TrackIndexType index) const override {
0170     assert(container != nullptr);
0171     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0172     return traj->calibratedSize(index);
0173   }
0174 
0175   ConstParametersMap parameters(const void* container,
0176                                 TrackIndexType index) const override {
0177     assert(container != nullptr);
0178     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0179     return traj->parameters(index);
0180   }
0181 
0182   ConstCovarianceMap covariance(const void* container,
0183                                 TrackIndexType index) const override {
0184     assert(container != nullptr);
0185     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0186     return traj->covariance(index);
0187   }
0188 
0189   const double* calibratedData(const void* container,
0190                                TrackIndexType index) const override {
0191     assert(container != nullptr);
0192     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0193     return traj->template calibrated<eBoundSize>(index).data();
0194   }
0195 
0196   const double* calibratedCovarianceData(const void* container,
0197                                          TrackIndexType index) const override {
0198     assert(container != nullptr);
0199     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0200     return traj->template calibratedCovariance<eBoundSize>(index).data();
0201   }
0202 
0203   const Surface* referenceSurface(const void* container,
0204                                   TrackIndexType index) const override {
0205     assert(container != nullptr);
0206     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0207     return traj->referenceSurface(index);
0208   }
0209 
0210   bool hasReferenceSurface(const void* container,
0211                            TrackIndexType index) const override {
0212     return referenceSurface(container, index) != nullptr;
0213   }
0214 
0215   bool hasUncalibratedSourceLink(const void* container,
0216                                  TrackIndexType index) const override {
0217     assert(container != nullptr);
0218     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0219     return traj->has(hashString("uncalibratedSourceLink"), index);
0220   }
0221 
0222   SourceLink getUncalibratedSourceLink(const void* container,
0223                                        TrackIndexType index) const override {
0224     assert(container != nullptr);
0225     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0226     return traj->getUncalibratedSourceLink(index);
0227   }
0228 
0229   ConstCovarianceMap jacobian(const void* container,
0230                               TrackIndexType index) const override {
0231     assert(container != nullptr);
0232     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0233     return traj->jacobian(index);
0234   }
0235 
0236   bool has(const void* container, TrackIndexType index,
0237            HashedString key) const override {
0238     assert(container != nullptr);
0239     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0240     return traj->has(key, index);
0241   }
0242 
0243   std::any component(const void* container, TrackIndexType index,
0244                      HashedString key) const override {
0245     assert(container != nullptr);
0246     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0247     return traj->self().component_impl(key, index);
0248   }
0249 
0250   bool hasColumn(const void* container, HashedString key) const override {
0251     assert(container != nullptr);
0252     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0253     return traj->hasColumn(key);
0254   }
0255 
0256  private:
0257   TrackStateHandler() = default;
0258 };
0259 
0260 template <typename trajectory_t>
0261 class TrackStateHandler<trajectory_t, false> final
0262     : public TrackStateHandlerMutableBase {
0263   using MultiTrajectoryType =
0264       typename TrackStateHandlerTraits<trajectory_t>::MultiTrajectoryType;
0265 
0266  public:
0267   static const TrackStateHandler& instance() {
0268     static const TrackStateHandler s_instance;
0269     return s_instance;
0270   }
0271 
0272   TrackIndexType calibratedSize(const void* container,
0273                                 TrackIndexType index) const override {
0274     assert(container != nullptr);
0275     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0276     return traj->calibratedSize(index);
0277   }
0278 
0279   ConstParametersMap parameters(const void* container,
0280                                 TrackIndexType index) const override {
0281     assert(container != nullptr);
0282     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0283     return traj->parameters(index);
0284   }
0285 
0286   ParametersMap parameters(void* container,
0287                            TrackIndexType index) const override {
0288     assert(container != nullptr);
0289     auto* traj = static_cast<MultiTrajectoryType*>(container);
0290     return traj->parameters(index);
0291   }
0292 
0293   ConstCovarianceMap covariance(const void* container,
0294                                 TrackIndexType index) const override {
0295     assert(container != nullptr);
0296     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0297     return traj->covariance(index);
0298   }
0299 
0300   CovarianceMap covariance(void* container,
0301                            TrackIndexType index) const override {
0302     assert(container != nullptr);
0303     auto* traj = static_cast<MultiTrajectoryType*>(container);
0304     return traj->covariance(index);
0305   }
0306 
0307   const double* calibratedData(const void* container,
0308                                TrackIndexType index) const override {
0309     assert(container != nullptr);
0310     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0311     return traj->template calibrated<eBoundSize>(index).data();
0312   }
0313 
0314   const double* calibratedCovarianceData(const void* container,
0315                                          TrackIndexType index) const override {
0316     assert(container != nullptr);
0317     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0318     return traj->template calibratedCovariance<eBoundSize>(index).data();
0319   }
0320 
0321   double* calibratedDataMutable(void* container,
0322                                 TrackIndexType index) const override {
0323     assert(container != nullptr);
0324     auto* traj = static_cast<MultiTrajectoryType*>(container);
0325     return traj->template calibrated<eBoundSize>(index).data();
0326   }
0327 
0328   double* calibratedCovarianceDataMutable(void* container,
0329                                           TrackIndexType index) const override {
0330     assert(container != nullptr);
0331     auto* traj = static_cast<MultiTrajectoryType*>(container);
0332     return traj->template calibratedCovariance<eBoundSize>(index).data();
0333   }
0334 
0335   const Surface* referenceSurface(const void* container,
0336                                   TrackIndexType index) const override {
0337     assert(container != nullptr);
0338     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0339     return traj->referenceSurface(index);
0340   }
0341 
0342   bool hasReferenceSurface(const void* container,
0343                            TrackIndexType index) const override {
0344     return referenceSurface(container, index) != nullptr;
0345   }
0346 
0347   bool hasUncalibratedSourceLink(const void* container,
0348                                  TrackIndexType index) const override {
0349     assert(container != nullptr);
0350     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0351     return traj->has(hashString("uncalibratedSourceLink"), index);
0352   }
0353 
0354   SourceLink getUncalibratedSourceLink(const void* container,
0355                                        TrackIndexType index) const override {
0356     assert(container != nullptr);
0357     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0358     return traj->getUncalibratedSourceLink(index);
0359   }
0360 
0361   ConstCovarianceMap jacobian(const void* container,
0362                               TrackIndexType index) const override {
0363     assert(container != nullptr);
0364     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0365     return traj->jacobian(index);
0366   }
0367 
0368   CovarianceMap jacobian(void* container, TrackIndexType index) const override {
0369     assert(container != nullptr);
0370     auto* traj = static_cast<MultiTrajectoryType*>(container);
0371     return traj->jacobian(index);
0372   }
0373 
0374   bool has(const void* container, TrackIndexType index,
0375            HashedString key) const override {
0376     assert(container != nullptr);
0377     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0378     return traj->has(key, index);
0379   }
0380 
0381   std::any component(const void* container, TrackIndexType index,
0382                      HashedString key) const override {
0383     assert(container != nullptr);
0384     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0385     return traj->self().component_impl(key, index);
0386   }
0387 
0388   bool hasColumn(const void* container, HashedString key) const override {
0389     assert(container != nullptr);
0390     const auto* traj = static_cast<const MultiTrajectoryType*>(container);
0391     return traj->hasColumn(key);
0392   }
0393 
0394   std::any component(void* container, TrackIndexType index,
0395                      HashedString key) const override {
0396     assert(container != nullptr);
0397     auto* traj = static_cast<MultiTrajectoryType*>(container);
0398     return traj->self().component_impl(key, index);
0399   }
0400 
0401   void unset(void* container, TrackIndexType index,
0402              TrackStatePropMask target) const override {
0403     assert(container != nullptr);
0404     auto* traj = static_cast<MultiTrajectoryType*>(container);
0405     traj->unset(target, index);
0406   }
0407 
0408   void allocateCalibrated(void* container, TrackIndexType index,
0409                           std::size_t measdim) const override {
0410     assert(container != nullptr);
0411     auto* traj = static_cast<MultiTrajectoryType*>(container);
0412     traj->allocateCalibrated(index, measdim);
0413   }
0414 
0415   void setUncalibratedSourceLink(void* container, TrackIndexType index,
0416                                  SourceLink&& sourceLink) const override {
0417     assert(container != nullptr);
0418     auto* traj = static_cast<MultiTrajectoryType*>(container);
0419     traj->setUncalibratedSourceLink(index, std::move(sourceLink));
0420   }
0421 
0422   void setReferenceSurface(
0423       void* container, TrackIndexType index,
0424       std::shared_ptr<const Surface> surface) const override {
0425     assert(container != nullptr);
0426     auto* traj = static_cast<MultiTrajectoryType*>(container);
0427     traj->setReferenceSurface(index, std::move(surface));
0428   }
0429 
0430   void addTrackStateComponents(void* container, TrackIndexType index,
0431                                TrackStatePropMask mask) const override {
0432     assert(container != nullptr);
0433     auto* traj = static_cast<MultiTrajectoryType*>(container);
0434     traj->addTrackStateComponents(index, mask);
0435   }
0436 
0437  private:
0438   TrackStateHandler() = default;
0439 };
0440 
0441 }  // namespace detail_anytstate
0442 
0443 /// Type-erased track state proxy for any trajectory backend.
0444 ///
0445 /// Provides the TrackStateProxy interface by delegating to a runtime handler.
0446 /// @tparam read_only True for const access, false for mutable access.
0447 template <bool read_only>
0448 class AnyTrackStateProxy
0449     : public TrackStateProxyCommon<AnyTrackStateProxy<read_only>, read_only> {
0450   using Base = TrackStateProxyCommon<AnyTrackStateProxy<read_only>, read_only>;
0451 
0452   friend class TrackStateProxyCommon<AnyTrackStateProxy<read_only>, read_only>;
0453 
0454   using IndexType = Acts::TrackIndexType;
0455 
0456  public:
0457   /// Whether this proxy provides read-only or mutable access
0458   static constexpr bool ReadOnly = read_only;
0459 
0460   /// Mutable track state proxy type
0461   using MutableTrackState = AnyTrackStateProxy<false>;
0462   /// Const track state proxy type
0463   using ConstTrackState = AnyTrackStateProxy<true>;
0464   /// Const proxy type alias
0465   using ConstProxyType = AnyTrackStateProxy<true>;
0466 
0467   /// Mutable parameters map type
0468   using ParametersMap =
0469       detail_anytstate::TrackStateHandlerConstBase::ParametersMap;
0470   /// Const parameters map type
0471   using ConstParametersMap =
0472       detail_anytstate::TrackStateHandlerConstBase::ConstParametersMap;
0473   /// Mutable covariance map type
0474   using CovarianceMap =
0475       detail_anytstate::TrackStateHandlerConstBase::CovarianceMap;
0476   /// Const covariance map type
0477   using ConstCovarianceMap =
0478       detail_anytstate::TrackStateHandlerConstBase::ConstCovarianceMap;
0479   /// Mutable effective calibrated map type
0480   using MutableEffectiveCalibratedMap =
0481       detail_anytstate::TrackStateHandlerConstBase::EffectiveCalibratedMap;
0482   /// Const effective calibrated map type
0483   using ConstEffectiveCalibratedMap =
0484       detail_anytstate::TrackStateHandlerConstBase::ConstEffectiveCalibratedMap;
0485   /// Mutable effective calibrated covariance map type
0486   using MutableEffectiveCalibratedCovarianceMap = detail_anytstate::
0487       TrackStateHandlerConstBase::EffectiveCalibratedCovarianceMap;
0488   /// Const effective calibrated covariance map type
0489   using ConstEffectiveCalibratedCovarianceMap = detail_anytstate::
0490       TrackStateHandlerConstBase::ConstEffectiveCalibratedCovarianceMap;
0491 
0492   /// Container pointer type
0493   using ContainerPointer = std::conditional_t<ReadOnly, const void*, void*>;
0494 
0495   using Base::allocateCalibrated;
0496   using Base::calibrated;
0497   using Base::calibratedCovariance;
0498   using Base::chi2;
0499   using Base::covariance;
0500   using Base::effectiveCalibrated;
0501   using Base::effectiveCalibratedCovariance;
0502   using Base::filtered;
0503   using Base::filteredCovariance;
0504   using Base::getMask;
0505   using Base::hasCalibrated;
0506   using Base::hasFiltered;
0507   using Base::hasJacobian;
0508   using Base::hasPredicted;
0509   using Base::hasPrevious;
0510   using Base::hasProjector;
0511   using Base::hasSmoothed;
0512   using Base::hasUncalibratedSourceLink;
0513   using Base::parameters;
0514   using Base::pathLength;
0515   using Base::predicted;
0516   using Base::predictedCovariance;
0517   using Base::previous;
0518   using Base::projectorSubspaceHelper;
0519   using Base::projectorSubspaceIndices;
0520   using Base::setProjectorSubspaceIndices;
0521   using Base::smoothed;
0522   using Base::smoothedCovariance;
0523   using Base::typeFlags;
0524 
0525   /// Construct an `AnyTrackStateProxy` from a concrete track-state proxy.
0526   /// @tparam track_state_proxy_t Proxy type satisfying the concept.
0527   /// @param ts Proxy that supplies the trajectory backend and index.
0528   template <TrackStateProxyConcept track_state_proxy_t>
0529     requires(ReadOnly || !track_state_proxy_t::ReadOnly)
0530   explicit AnyTrackStateProxy(track_state_proxy_t& ts)
0531       : m_container(nullptr), m_index(ts.m_istate) {
0532     using trajectory_t = typename track_state_proxy_t::Trajectory;
0533     auto* containerPtr = ts.rawTrajectoryPtr();
0534     if constexpr (ReadOnly) {
0535       m_container = static_cast<const void*>(containerPtr);
0536     } else {
0537       m_container = static_cast<void*>(containerPtr);
0538     }
0539     m_handler = &detail_anytstate::TrackStateHandler<trajectory_t>::instance();
0540   }
0541 
0542   /// Get the index of the underlying track state.
0543   /// @return Track state index within its container.
0544   TrackIndexType index() const { return m_index; }
0545 
0546   /// Check if a compile-time keyed component exists on this track state.
0547   /// @tparam key Component key encoded as a hashed string literal.
0548   /// @return True if the component is available.
0549   template <HashedString key>
0550   bool has() const {
0551     return constHandler()->has(containerPtr(), m_index, key);
0552   }
0553 
0554   /// Check if a hashed component exists on this track state.
0555   /// @param key Component identifier.
0556   /// @return True if the component is available.
0557   bool has(HashedString key) const {
0558     return constHandler()->has(containerPtr(), m_index, key);
0559   }
0560 
0561   /// Check if a string-named component exists on this track state.
0562   /// @param key Component identifier as a string.
0563   /// @return True if the component is available.
0564   bool has(std::string_view key) const { return has(hashStringDynamic(key)); }
0565 
0566   /// Check if the trajectory container exposes a column.
0567   /// @param key Column identifier.
0568   /// @return True if the column exists.
0569   bool hasColumn(HashedString key) const {
0570     return constHandler()->hasColumn(containerPtr(), key);
0571   }
0572 
0573   /// Check if the trajectory container exposes a column.
0574   /// @param key Column identifier as a string.
0575   /// @return True if the column exists.
0576   bool hasColumn(std::string_view key) const {
0577     return hasColumn(hashStringDynamic(key));
0578   }
0579 
0580   /// Access a const component through a compile-time key.
0581   /// @tparam T Component type.
0582   /// @tparam key Component key encoded as a hashed string literal.
0583   /// @return Const reference to the requested component.
0584   template <typename T, HashedString key>
0585   const T& component() const {
0586     std::any result = constHandler()->component(containerPtr(), m_index, key);
0587     return *std::any_cast<const T*>(result);
0588   }
0589 
0590   /// Access a const component by hashed key.
0591   /// @tparam T Component type.
0592   /// @param key Component identifier.
0593   /// @return Const reference to the requested component.
0594   template <typename T>
0595   const T& component(HashedString key) const {
0596     std::any result = constHandler()->component(containerPtr(), m_index, key);
0597     return *std::any_cast<const T*>(result);
0598   }
0599 
0600   /// Access a const component by string key.
0601   /// @tparam T Component type.
0602   /// @param key Component identifier as a string.
0603   /// @return Const reference to the requested component.
0604   template <typename T>
0605   const T& component(std::string_view key) const {
0606     return component<T>(hashStringDynamic(key));
0607   }
0608 
0609   /// Access a mutable component through a compile-time key.
0610   /// @tparam T Component type.
0611   /// @tparam key Component key encoded as a hashed string literal.
0612   /// @return Mutable reference to the requested component.
0613   template <typename T, HashedString key>
0614   T& component()
0615     requires(!ReadOnly)
0616   {
0617     std::any result =
0618         mutableHandler()->component(mutableContainerPtr(), m_index, key);
0619     return *std::any_cast<T*>(result);
0620   }
0621 
0622   /// Access a mutable component by hashed key.
0623   /// @tparam T Component type.
0624   /// @param key Component identifier.
0625   /// @return Mutable reference to the requested component.
0626   template <typename T>
0627   T& component(HashedString key)
0628     requires(!ReadOnly)
0629   {
0630     std::any result =
0631         mutableHandler()->component(mutableContainerPtr(), m_index, key);
0632     return *std::any_cast<T*>(result);
0633   }
0634 
0635   /// Access a mutable component by string key.
0636   /// @tparam T Component type.
0637   /// @param key Component identifier as a string.
0638   /// @return Mutable reference to the requested component.
0639   template <typename T>
0640   T& component(std::string_view key)
0641     requires(!ReadOnly)
0642   {
0643     return component<T>(hashStringDynamic(key));
0644   }
0645 
0646   /// Access the surface the state is referenced to.
0647   /// @return Reference surface of the track state.
0648   const Surface& referenceSurface() const {
0649     assert(hasReferenceSurface());
0650     const Surface* surface =
0651         constHandler()->referenceSurface(containerPtr(), m_index);
0652     assert(surface != nullptr);
0653     return *surface;
0654   }
0655 
0656   /// Check whether a reference surface is attached.
0657   /// @return True if a valid reference surface exists.
0658   bool hasReferenceSurface() const {
0659     return constHandler()->hasReferenceSurface(containerPtr(), m_index);
0660   }
0661 
0662   /// Assign a new reference surface to the track state.
0663   /// @param surface Surface that should be referenced.
0664   void setReferenceSurface(std::shared_ptr<const Surface> surface)
0665     requires(!ReadOnly)
0666   {
0667     mutableHandler()->setReferenceSurface(mutableContainerPtr(), m_index,
0668                                           std::move(surface));
0669   }
0670 
0671   /// Retrieve the original, uncalibrated source link.
0672   /// @return Copy of the stored source link.
0673   SourceLink getUncalibratedSourceLink() const {
0674     assert(hasUncalibratedSourceLink());
0675     return constHandler()->getUncalibratedSourceLink(containerPtr(), m_index);
0676   }
0677 
0678   /// Store an uncalibrated source link on this state.
0679   /// @param sourceLink Source link to copy into the track state.
0680   void setUncalibratedSourceLink(SourceLink sourceLink)
0681     requires(!ReadOnly)
0682   {
0683     mutableHandler()->setUncalibratedSourceLink(mutableContainerPtr(), m_index,
0684                                                 std::move(sourceLink));
0685   }
0686 
0687   /// Retrieve the measurement dimension of the calibrated data.
0688   /// @return Number of calibrated measurement entries.
0689   TrackIndexType calibratedSize() const {
0690     return constHandler()->calibratedSize(containerPtr(), m_index);
0691   }
0692 
0693   /// Allocate memory for runtime-dimension calibrated data.
0694   /// @param measdim Number of measurement rows to reserve.
0695   void allocateCalibrated(std::size_t measdim)
0696     requires(!ReadOnly)
0697   {
0698     mutableHandler()->allocateCalibrated(mutableContainerPtr(), m_index,
0699                                          measdim);
0700     component<TrackIndexType, detail_tsp::kMeasDimKey>() =
0701         static_cast<TrackIndexType>(measdim);
0702   }
0703 
0704   /// Access the transport Jacobian.
0705   /// @return Const map referencing the Jacobian matrix.
0706   ConstCovarianceMap jacobian() const {
0707     assert(hasJacobian());
0708     return constHandler()->jacobian(containerPtr(), m_index);
0709   }
0710 
0711   /// Access the transport Jacobian.
0712   /// @return Mutable map referencing the Jacobian matrix.
0713   CovarianceMap jacobian()
0714     requires(!ReadOnly)
0715   {
0716     assert(hasJacobian());
0717     return mutableHandler()->jacobian(mutableContainerPtr(), m_index);
0718   }
0719 
0720   /// Remove dynamic components according to a mask.
0721   /// @param target Property mask describing which components to drop.
0722   void unset(TrackStatePropMask target)
0723     requires(!ReadOnly)
0724   {
0725     mutableHandler()->unset(mutableContainerPtr(), m_index, target);
0726   }
0727 
0728  protected:
0729   /// Access const parameters at specific index
0730   /// @param parIndex Parameter index
0731   /// @return Const parameters map
0732   ConstParametersMap parametersAtIndex(IndexType parIndex) const {
0733     return constHandler()->parameters(containerPtr(), parIndex);
0734   }
0735 
0736   /// Access mutable parameters at specific index
0737   /// @param parIndex Parameter index
0738   /// @return Mutable parameters map
0739   ParametersMap parametersAtIndexMutable(IndexType parIndex) const
0740     requires(!ReadOnly)
0741   {
0742     return mutableHandler()->parameters(mutableContainerPtr(), parIndex);
0743   }
0744 
0745   /// Access const covariance at specific index
0746   /// @param covIndex Covariance index
0747   /// @return Const covariance map
0748   ConstCovarianceMap covarianceAtIndex(IndexType covIndex) const {
0749     return constHandler()->covariance(containerPtr(), covIndex);
0750   }
0751 
0752   /// Access mutable covariance at specific index
0753   /// @param covIndex Covariance index
0754   /// @return Mutable covariance map
0755   CovarianceMap covarianceAtIndexMutable(IndexType covIndex) const
0756     requires(!ReadOnly)
0757   {
0758     return mutableHandler()->covariance(mutableContainerPtr(), covIndex);
0759   }
0760 
0761   /// Access mutable calibrated measurement data
0762   /// @return Pointer to mutable calibrated data
0763   double* calibratedDataMutable()
0764     requires(!ReadOnly)
0765   {
0766     return mutableHandler()->calibratedDataMutable(mutableContainerPtr(),
0767                                                    m_index);
0768   }
0769 
0770   /// Access const calibrated measurement data
0771   /// @return Pointer to const calibrated data
0772   const double* calibratedData() const {
0773     return constHandler()->calibratedData(containerPtr(), m_index);
0774   }
0775 
0776   /// Access mutable calibrated measurement covariance data
0777   /// @return Pointer to mutable calibrated covariance data
0778   double* calibratedCovarianceDataMutable()
0779     requires(!ReadOnly)
0780   {
0781     return mutableHandler()->calibratedCovarianceDataMutable(
0782         mutableContainerPtr(), m_index);
0783   }
0784 
0785   /// Access const calibrated measurement covariance data
0786   /// @return Pointer to const calibrated covariance data
0787   const double* calibratedCovarianceData() const {
0788     return constHandler()->calibratedCovarianceData(containerPtr(), m_index);
0789   }
0790 
0791  private:
0792   template <bool>
0793   friend class AnyTrackStateProxy;
0794 
0795   const detail_anytstate::TrackStateHandlerConstBase* constHandler() const {
0796     return m_handler;
0797   }
0798 
0799   const detail_anytstate::TrackStateHandlerMutableBase* mutableHandler() const
0800     requires(!ReadOnly)
0801   {
0802     return static_cast<const detail_anytstate::TrackStateHandlerMutableBase*>(
0803         m_handler);
0804   }
0805 
0806   const void* containerPtr() const { return m_container; }
0807 
0808   void* mutableContainerPtr() const
0809     requires(!ReadOnly)
0810   {
0811     return m_container;
0812   }
0813 
0814   ContainerPointer m_container{};
0815   TrackIndexType m_index{};
0816   const detail_anytstate::TrackStateHandlerConstBase* m_handler{};
0817 };
0818 
0819 /// Type alias for a const track state proxy
0820 using AnyConstTrackStateProxy = AnyTrackStateProxy<true>;
0821 /// Type alias for a mutable track state proxy
0822 using AnyMutableTrackStateProxy = AnyTrackStateProxy<false>;
0823 
0824 static_assert(ConstTrackStateProxyConcept<AnyConstTrackStateProxy>);
0825 static_assert(MutableTrackStateProxyConcept<AnyMutableTrackStateProxy>);
0826 
0827 }  // namespace Acts