File indexing completed on 2025-12-13 09:38:48
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/EventData/Types.hpp"
0012 #include "Acts/Utilities/TypeTraits.hpp"
0013 #include "Acts/Utilities/detail/ContainerSubset.hpp"
0014
0015 #include <cassert>
0016 #include <span>
0017 #include <vector>
0018
0019 namespace Acts {
0020
0021 class SpacePointContainer2;
0022
0023
0024
0025 template <typename T, bool read_only>
0026 class SpacePointColumnProxy {
0027 public:
0028
0029 constexpr static bool ReadOnly = read_only;
0030
0031 using Index = SpacePointIndex2;
0032
0033 using IndexRange = SpacePointIndexRange2;
0034
0035 using IndexSubset = SpacePointIndexSubset2;
0036
0037 using Value = T;
0038
0039 using Container = const_if_t<ReadOnly, SpacePointContainer2>;
0040
0041 using Column = const_if_t<ReadOnly, std::vector<Value>>;
0042
0043
0044
0045
0046 SpacePointColumnProxy(Container &container, Column &column)
0047 : m_container{&container}, m_column(&column) {}
0048
0049
0050
0051 SpacePointColumnProxy(const SpacePointColumnProxy &other) noexcept = default;
0052
0053
0054
0055 explicit SpacePointColumnProxy(
0056 const SpacePointColumnProxy<T, false> &other) noexcept
0057 requires ReadOnly
0058 : m_container(&other.container()), m_column(&other.column()) {}
0059
0060
0061
0062 SpacePointColumnProxy<T, true> asConst() const noexcept
0063 requires(!ReadOnly)
0064 {
0065 return {*m_container, *m_column};
0066 }
0067
0068
0069
0070 SpacePointContainer2 &container() noexcept
0071 requires(!ReadOnly)
0072 {
0073 return *m_container;
0074 }
0075
0076
0077 const SpacePointContainer2 &container() const noexcept {
0078 return *m_container;
0079 }
0080
0081
0082
0083 const std::vector<Value> &column() const noexcept { return *m_column; }
0084
0085
0086
0087 std::span<Value> data() noexcept
0088 requires(!ReadOnly)
0089 {
0090 return std::span<Value>(column().data(), column().size());
0091 }
0092
0093
0094 std::span<const Value> data() const noexcept {
0095 return std::span<const Value>(column().data(), column().size());
0096 }
0097
0098
0099
0100
0101
0102
0103 Value &at(Index index)
0104 requires(!ReadOnly)
0105 {
0106 if (index >= column().size()) {
0107 throw std::out_of_range("Index out of range in SpacePointContainer2: " +
0108 std::to_string(index) +
0109 " >= " + std::to_string(size()));
0110 }
0111 return data()[index];
0112 }
0113
0114
0115
0116
0117
0118 const Value &at(Index index) const {
0119 if (index >= column().size()) {
0120 throw std::out_of_range("Index out of range in SpacePointContainer2: " +
0121 std::to_string(index) +
0122 " >= " + std::to_string(size()));
0123 }
0124 return data()[index];
0125 }
0126
0127
0128
0129
0130 Value &operator[](Index index) noexcept
0131 requires(!ReadOnly)
0132 {
0133 assert(index < column().size() && "Index out of bounds");
0134 return data()[index];
0135 }
0136
0137
0138
0139 const Value &operator[](Index index) const noexcept {
0140 assert(index < column().size() && "Index out of bounds");
0141 return data()[index];
0142 }
0143
0144 class Subset : public detail::ContainerSubset<Subset, Subset, Column, Value,
0145 Index, ReadOnly> {
0146 public:
0147 using Base =
0148 detail::ContainerSubset<Subset, Subset, Column, Value, Index, ReadOnly>;
0149
0150 using Base::Base;
0151 };
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 Subset subset(const IndexSubset &subset) const noexcept {
0169 return Subset(*m_column, subset);
0170 }
0171
0172 private:
0173 Container *m_container{};
0174 Column *m_column{};
0175
0176 std::uint32_t size() const noexcept { return column().size(); }
0177
0178 std::vector<Value> &column() noexcept
0179 requires(!ReadOnly)
0180 {
0181 return *m_column;
0182 }
0183
0184 friend class SpacePointContainer2;
0185 };
0186
0187 template <typename T>
0188 using ConstSpacePointColumnProxy = SpacePointColumnProxy<T, true>;
0189 template <typename T>
0190 using MutableSpacePointColumnProxy = SpacePointColumnProxy<T, false>;
0191
0192 }