Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-06 07:48:50

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/TrackProxy.hpp"
0012 #include "Acts/EventData/TrackStateProxy.hpp"
0013 #include "Acts/Utilities/HashedString.hpp"
0014 
0015 #include <type_traits>
0016 
0017 namespace Acts::detail {
0018 
0019 template <typename T>
0020 concept MutableProxyType = requires(T t, HashedString key) {
0021   requires !T::ReadOnly;
0022 
0023   {
0024     t.template component<int>(key)
0025   } -> std::same_as<std::conditional_t<T::ReadOnly, const int&, int&>>;
0026 };
0027 
0028 template <typename T>
0029 concept ConstProxyType = requires(T t, HashedString key) {
0030   requires T::ReadOnly;
0031   { t.template component<int>(key) } -> std::same_as<const int&>;
0032 };
0033 
0034 template <typename T>
0035 concept ProxyType = (MutableProxyType<T> || ConstProxyType<T>) &&
0036                     requires(T t, HashedString key) {
0037                       typename T::ConstProxyType;
0038 
0039                       requires ConstProxyType<typename T::ConstProxyType>;
0040 
0041                       { t.hasColumn(key) } -> std::same_as<bool>;
0042                     };
0043 
0044 template <typename T>
0045 concept TrackProxyLike =
0046     ProxyType<T> &&
0047     std::is_same_v<typename T::ConstProxyType, typename T::ConstProxyType>;
0048 
0049 }  // namespace Acts::detail
0050 
0051 namespace Acts {
0052 
0053 /// Utility class that eases accessing dynamic columns in track and track state
0054 /// containers
0055 /// @tparam T the type of the value to access
0056 /// @tparam ReadOnly true if this is a const accessor
0057 template <typename T, bool ReadOnly>
0058 struct ProxyAccessorBase {
0059   /// Hashed string key for data access
0060   HashedString key;
0061 
0062   /// Create the accessor from an already-hashed string key
0063   /// @param _key the key
0064   explicit constexpr ProxyAccessorBase(HashedString _key) : key{_key} {}
0065 
0066   /// Create the accessor from a string key
0067   /// @param _key the key
0068   explicit constexpr ProxyAccessorBase(const std::string& _key)
0069       : key{hashStringDynamic(_key)} {}
0070 
0071   /// Access the stored key on the proxy given as an argument. Mutable version
0072   /// @tparam proxy_t the type of the proxy
0073   /// @param proxy the proxy object to access
0074   /// @return mutable reference to the column behind the key
0075   template <detail::MutableProxyType proxy_t>
0076   T& operator()(proxy_t proxy) const
0077     requires(!ReadOnly)
0078   {
0079     static_assert(!proxy_t::ReadOnly,
0080                   "Cannot get mutable ref for const track proxy");
0081     return proxy.template component<T>(key);
0082   }
0083 
0084   /// Access the stored key on the proxy given as an argument. Const version
0085   /// @tparam proxy_t the type of the track proxy
0086   /// @param proxy the proxy to access
0087   /// @return const reference to the column behind the key
0088   template <detail::ProxyType proxy_t>
0089   const T& operator()(proxy_t proxy) const
0090     requires(ReadOnly)
0091   {
0092     if constexpr (proxy_t::ReadOnly) {
0093       return proxy.template component<T>(key);
0094 
0095     } else {
0096       using const_proxy_t = typename proxy_t::ConstProxyType;
0097       const_proxy_t cproxy{proxy};
0098       return cproxy.template component<T>(key);
0099     }
0100   }
0101 
0102   /// Check if the stored key exists on the proxy given as an argument
0103   /// @tparam proxy_t the type of the proxy
0104   /// @param proxy the proxy object to check
0105   /// @return true if the column exists, false otherwise
0106   template <detail::ProxyType proxy_t>
0107   bool hasColumn(proxy_t proxy) const {
0108     return proxy.hasColumn(key);
0109   }
0110 };
0111 
0112 /// @brief Type alias for a mutable proxy accessor
0113 /// @details Provides mutable access to track state components through a proxy pattern
0114 /// @tparam T The type of the component being accessed
0115 template <typename T>
0116 using ProxyAccessor = ProxyAccessorBase<T, false>;
0117 
0118 /// @brief Type alias for a const proxy accessor
0119 /// @details Provides read-only access to proxy data with const-qualified member functions
0120 template <typename T>
0121 using ConstProxyAccessor = ProxyAccessorBase<T, true>;
0122 }  // namespace Acts