File indexing completed on 2025-08-06 08:10:00
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/Concepts.hpp"
0014 #include "Acts/Utilities/HashedString.hpp"
0015
0016 #include <type_traits>
0017
0018 #if defined(__cpp_concepts)
0019 #include <concepts>
0020 namespace Acts::detail {
0021
0022 template <typename T>
0023 concept MutableProxyType = requires(T t, HashedString key) {
0024 requires !T::ReadOnly;
0025
0026 {
0027 t.template component<int>(key)
0028 } -> std::same_as<std::conditional_t<T::ReadOnly, const int&, int&>>;
0029 };
0030
0031 template <typename T>
0032 concept ConstProxyType = requires(T t, HashedString key) {
0033 requires T::ReadOnly;
0034 { t.template component<int>(key) } -> std::same_as<const int&>;
0035 };
0036
0037 template <typename T>
0038 concept ProxyType = (MutableProxyType<T> || ConstProxyType<T>)&&requires {
0039 typename T::ConstProxyType;
0040
0041 requires ConstProxyType<typename T::ConstProxyType>;
0042 };
0043
0044 }
0045 #endif
0046
0047 namespace Acts {
0048
0049 namespace detail {
0050 template <typename... Args>
0051 struct associatedConstProxy;
0052
0053 template <typename trajectory_t, std::size_t M, bool read_only>
0054 struct associatedConstProxy<TrackStateProxy<trajectory_t, M, read_only>> {
0055 using type = TrackStateProxy<trajectory_t, M, true>;
0056 };
0057
0058 template <typename track_container_t, typename trajectory_t,
0059 template <typename> class holder_t, bool read_only>
0060 struct associatedConstProxy<
0061 TrackProxy<track_container_t, trajectory_t, holder_t, read_only>> {
0062 using type = TrackProxy<track_container_t, trajectory_t, holder_t, true>;
0063 };
0064
0065 }
0066
0067
0068
0069
0070
0071 template <typename T, bool ReadOnly>
0072 struct ProxyAccessorBase {
0073 HashedString key;
0074
0075
0076
0077 constexpr ProxyAccessorBase(HashedString _key) : key{_key} {}
0078
0079
0080
0081 ProxyAccessorBase(const std::string& _key) : key{hashString(_key)} {}
0082
0083
0084
0085
0086
0087 template <ACTS_CONCEPT(detail::MutableProxyType) proxy_t, bool RO = ReadOnly,
0088 typename = std::enable_if_t<!RO>>
0089 T& operator()(proxy_t proxy) const {
0090 static_assert(!proxy_t::ReadOnly,
0091 "Cannot get mutable ref for const track proxy");
0092 return proxy.template component<T>(key);
0093 }
0094
0095
0096
0097
0098
0099 template <ACTS_CONCEPT(detail::ProxyType) proxy_t, bool RO = ReadOnly,
0100 typename = std::enable_if_t<RO>>
0101 const T& operator()(proxy_t proxy) const {
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
0113 template <typename T>
0114 using ProxyAccessor = ProxyAccessorBase<T, false>;
0115 template <typename T>
0116 using ConstProxyAccessor = ProxyAccessorBase<T, true>;
0117 }