Warning, file /acts/Core/include/Acts/EventData/SpacePointColumnProxy.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 SpacePointContainer;
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 = SpacePointIndex;
0032
0033 using IndexRange = SpacePointIndexRange;
0034
0035 using IndexSubset = SpacePointIndexSubset;
0036
0037 using Value = T;
0038
0039 using Container = const_if_t<ReadOnly, SpacePointContainer>;
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 std::uint32_t size() const noexcept { return column().size(); }
0063
0064
0065
0066 SpacePointColumnProxy<T, true> asConst() const noexcept
0067 requires(!ReadOnly)
0068 {
0069 return {*m_container, *m_column};
0070 }
0071
0072
0073
0074 SpacePointContainer &container() noexcept
0075 requires(!ReadOnly)
0076 {
0077 return *m_container;
0078 }
0079
0080
0081 const SpacePointContainer &container() const noexcept { return *m_container; }
0082
0083
0084
0085 const std::vector<Value> &column() const noexcept { return *m_column; }
0086
0087
0088
0089 std::span<Value> data() noexcept
0090 requires(!ReadOnly)
0091 {
0092 return std::span<Value>(column().data(), column().size());
0093 }
0094
0095
0096 std::span<const Value> data() const noexcept {
0097 return std::span<const Value>(column().data(), column().size());
0098 }
0099
0100
0101
0102
0103
0104
0105 Value &at(Index index)
0106 requires(!ReadOnly)
0107 {
0108 if (index >= column().size()) {
0109 throw std::out_of_range("Index out of range in SpacePointContainer: " +
0110 std::to_string(index) +
0111 " >= " + std::to_string(size()));
0112 }
0113 return data()[index];
0114 }
0115
0116
0117
0118
0119
0120 const Value &at(Index index) const {
0121 if (index >= column().size()) {
0122 throw std::out_of_range("Index out of range in SpacePointContainer: " +
0123 std::to_string(index) +
0124 " >= " + std::to_string(size()));
0125 }
0126 return data()[index];
0127 }
0128
0129
0130
0131
0132 Value &operator[](Index index) noexcept
0133 requires(!ReadOnly)
0134 {
0135 assert(index < column().size() && "Index out of bounds");
0136 return data()[index];
0137 }
0138
0139
0140
0141 const Value &operator[](Index index) const noexcept {
0142 assert(index < column().size() && "Index out of bounds");
0143 return data()[index];
0144 }
0145
0146
0147 class Subset
0148 : public detail::ContainerSubset<Subset, Subset, Column, Value,
0149 std::span<const Index>, ReadOnly> {
0150 public:
0151
0152 using Base = detail::ContainerSubset<Subset, Subset, Column, Value,
0153 std::span<const Index>, ReadOnly>;
0154
0155 using Base::Base;
0156 };
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173 Subset subset(const IndexSubset &subset) const noexcept {
0174 return Subset(*m_column, subset);
0175 }
0176
0177 private:
0178 Container *m_container{};
0179 Column *m_column{};
0180
0181 std::vector<Value> &column() noexcept
0182 requires(!ReadOnly)
0183 {
0184 return *m_column;
0185 }
0186
0187 friend class SpacePointContainer;
0188 };
0189
0190
0191 template <typename T>
0192 using ConstSpacePointColumnProxy = SpacePointColumnProxy<T, true>;
0193
0194 template <typename T>
0195 using MutableSpacePointColumnProxy = SpacePointColumnProxy<T, false>;
0196
0197 }