Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:10:48

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   HashedString key;
0070 
0071   /// Create the accessor from an already-hashed string key
0072   /// @param _key the key
0073   constexpr ProxyAccessorBase(HashedString _key) : key{_key} {}
0074 
0075   /// Create the accessor from a string key
0076   /// @param _key the key
0077   constexpr ProxyAccessorBase(const std::string& _key)
0078       : key{hashStringDynamic(_key)} {}
0079 
0080   /// Access the stored key on the proxy given as an argument. Mutable version
0081   /// @tparam proxy_t the type of the proxy
0082   /// @param proxy the proxy object to access
0083   /// @return mutable reference to the column behind the key
0084   template <detail::MutableProxyType proxy_t>
0085   T& operator()(proxy_t proxy) const
0086     requires(!ReadOnly)
0087   {
0088     static_assert(!proxy_t::ReadOnly,
0089                   "Cannot get mutable ref for const track proxy");
0090     return proxy.template component<T>(key);
0091   }
0092 
0093   /// Access the stored key on the proxy given as an argument. Const version
0094   /// @tparam proxy_t the type of the track proxy
0095   /// @param proxy the proxy to access
0096   /// @return const reference to the column behind the key
0097   template <detail::ProxyType proxy_t>
0098   const T& operator()(proxy_t proxy) const
0099     requires(ReadOnly)
0100   {
0101     if constexpr (proxy_t::ReadOnly) {
0102       return proxy.template component<T>(key);
0103 
0104     } else {
0105       using const_proxy_t = typename proxy_t::ConstProxyType;
0106       const_proxy_t cproxy{proxy};
0107       return cproxy.template component<T>(key);
0108     }
0109   }
0110 };
0111 
0112 template <typename T>
0113 using ProxyAccessor = ProxyAccessorBase<T, false>;
0114 template <typename T>
0115 using ConstProxyAccessor = ProxyAccessorBase<T, true>;
0116 }  // namespace Acts