File indexing completed on 2025-01-18 09:10:48
0001
0002
0003
0004
0005
0006
0007
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 }
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 }
0062
0063
0064
0065
0066
0067 template <typename T, bool ReadOnly>
0068 struct ProxyAccessorBase {
0069 HashedString key;
0070
0071
0072
0073 constexpr ProxyAccessorBase(HashedString _key) : key{_key} {}
0074
0075
0076
0077 constexpr ProxyAccessorBase(const std::string& _key)
0078 : key{hashStringDynamic(_key)} {}
0079
0080
0081
0082
0083
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
0094
0095
0096
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 }