Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-07-16 08:07:26

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