Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-22 07:51:39

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>) && requires {
0036   typename T::ConstProxyType;
0037 
0038   requires ConstProxyType<typename T::ConstProxyType>;
0039 };
0040 
0041 }  // namespace Acts::detail
0042 
0043 namespace Acts {
0044 
0045 namespace detail {
0046 template <typename... Args>
0047 struct associatedConstProxy;
0048 
0049 template <typename trajectory_t, std::size_t M, bool read_only>
0050 struct associatedConstProxy<TrackStateProxy<trajectory_t, M, read_only>> {
0051   using type = TrackStateProxy<trajectory_t, M, true>;
0052 };
0053 
0054 template <typename track_container_t, typename trajectory_t,
0055           template <typename> class holder_t, bool read_only>
0056 struct associatedConstProxy<
0057     TrackProxy<track_container_t, trajectory_t, holder_t, read_only>> {
0058   using type = TrackProxy<track_container_t, trajectory_t, holder_t, true>;
0059 };
0060 
0061 }  // namespace detail
0062 
0063 /// Utility class that eases accessing dynamic columns in track and track state
0064 /// containers
0065 /// @tparam T the type of the value to access
0066 /// @tparam ReadOnly true if this is a const accessor
0067 template <typename T, bool ReadOnly>
0068 struct ProxyAccessorBase {
0069   /// Hashed string key for data access
0070   HashedString key;
0071 
0072   /// Create the accessor from an already-hashed string key
0073   /// @param _key the key
0074   explicit constexpr ProxyAccessorBase(HashedString _key) : key{_key} {}
0075 
0076   /// Create the accessor from a string key
0077   /// @param _key the key
0078   explicit constexpr ProxyAccessorBase(const std::string& _key)
0079       : key{hashStringDynamic(_key)} {}
0080 
0081   /// Access the stored key on the proxy given as an argument. Mutable version
0082   /// @tparam proxy_t the type of the proxy
0083   /// @param proxy the proxy object to access
0084   /// @return mutable reference to the column behind the key
0085   template <detail::MutableProxyType proxy_t>
0086   T& operator()(proxy_t proxy) const
0087     requires(!ReadOnly)
0088   {
0089     static_assert(!proxy_t::ReadOnly,
0090                   "Cannot get mutable ref for const track proxy");
0091     return proxy.template component<T>(key);
0092   }
0093 
0094   /// Access the stored key on the proxy given as an argument. Const version
0095   /// @tparam proxy_t the type of the track proxy
0096   /// @param proxy the proxy to access
0097   /// @return const reference to the column behind the key
0098   template <detail::ProxyType proxy_t>
0099   const T& operator()(proxy_t proxy) const
0100     requires(ReadOnly)
0101   {
0102     if constexpr (proxy_t::ReadOnly) {
0103       return proxy.template component<T>(key);
0104 
0105     } else {
0106       using const_proxy_t = typename proxy_t::ConstProxyType;
0107       const_proxy_t cproxy{proxy};
0108       return cproxy.template component<T>(key);
0109     }
0110   }
0111 
0112   /// Check if the stored key exists on the proxy given as an argument
0113   /// @tparam proxy_t the type of the proxy
0114   /// @param proxy the proxy object to check
0115   /// @return true if the column exists, false otherwise
0116   template <detail::ProxyType proxy_t>
0117   bool hasColumn(proxy_t proxy) const {
0118     return proxy.container().hasColumn(key);
0119   }
0120 };
0121 
0122 /// @brief Type alias for a mutable proxy accessor
0123 /// @details Provides mutable access to track state components through a proxy pattern
0124 /// @tparam T The type of the component being accessed
0125 template <typename T>
0126 using ProxyAccessor = ProxyAccessorBase<T, false>;
0127 
0128 /// @brief Type alias for a const proxy accessor
0129 /// @details Provides read-only access to proxy data with const-qualified member functions
0130 template <typename T>
0131 using ConstProxyAccessor = ProxyAccessorBase<T, true>;
0132 }  // namespace Acts