Warning, file /acts/Core/include/Acts/EventData/SeedProxy.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/SeedColumns.hpp"
0012 #include "Acts/EventData/SpacePointContainer.hpp"
0013 #include "Acts/EventData/Types.hpp"
0014 #include "Acts/Utilities/TypeTraits.hpp"
0015
0016 #include <cassert>
0017
0018 namespace Acts {
0019
0020 class SeedContainer;
0021
0022
0023 template <bool read_only>
0024 class SeedProxy {
0025 public:
0026
0027
0028 static constexpr bool ReadOnly = read_only;
0029
0030
0031 using IndexType = SeedIndex;
0032
0033
0034 using ContainerType = const_if_t<ReadOnly, SeedContainer>;
0035
0036
0037
0038
0039 SeedProxy(ContainerType &container, IndexType index) noexcept
0040 : m_container{&container}, m_index{index} {}
0041
0042
0043
0044 SeedProxy(const SeedProxy &other) noexcept = default;
0045
0046
0047
0048 explicit SeedProxy(const SeedProxy<false> &other) noexcept
0049 requires ReadOnly
0050 : m_container(&other.container()), m_index(other.index()) {}
0051
0052
0053
0054
0055 SeedProxy &operator=(const SeedProxy &other) noexcept = default;
0056
0057
0058
0059
0060 SeedProxy &operator=(const SeedProxy<false> &other) noexcept
0061 requires ReadOnly
0062 {
0063 m_container = &other.container();
0064 m_index = other.index();
0065 return *this;
0066 }
0067
0068
0069
0070
0071 SeedProxy &operator=(SeedProxy &&other) noexcept = default;
0072
0073
0074
0075
0076 SeedProxy &operator=(SeedProxy<false> &&other) noexcept
0077 requires ReadOnly
0078 {
0079 m_container = &other.container();
0080 m_index = other.index();
0081 return *this;
0082 }
0083
0084
0085
0086 SeedProxy<true> asConst() const noexcept
0087 requires(!ReadOnly)
0088 {
0089 return {*m_container, m_index};
0090 }
0091
0092
0093
0094 SeedContainer &container() noexcept
0095 requires(!ReadOnly)
0096 {
0097 return *m_container;
0098 }
0099
0100
0101
0102 const SeedContainer &container() const noexcept { return *m_container; }
0103
0104
0105
0106 IndexType index() const noexcept { return m_index; }
0107
0108
0109
0110
0111
0112 void assignSpacePointIndices(
0113 std::span<const SpacePointIndex> spacePointIndices)
0114 requires(!ReadOnly)
0115 {
0116 if (m_index >= m_container->size()) {
0117 throw std::out_of_range("Index out of range in SeedContainer");
0118 }
0119 if (m_container->m_spacePointCounts[m_index] != 0) {
0120 throw std::logic_error("Space points already assigned to the seed");
0121 }
0122
0123 m_container->m_spacePointOffsets[m_index] =
0124 static_cast<std::uint32_t>(m_container->m_spacePoints.size());
0125 m_container->m_spacePointCounts[m_index] =
0126 static_cast<std::uint8_t>(spacePointIndices.size());
0127 m_container->m_spacePoints.insert(m_container->m_spacePoints.end(),
0128 spacePointIndices.begin(),
0129 spacePointIndices.end());
0130 }
0131
0132
0133
0134
0135 [[nodiscard]] std::size_t size() const noexcept {
0136 return spacePointIndices().size();
0137 }
0138
0139
0140
0141 [[nodiscard]]
0142 bool empty() const noexcept {
0143 return size() == 0;
0144 }
0145
0146
0147
0148 std::span<SpacePointIndex> spacePointIndices() noexcept
0149 requires(!ReadOnly)
0150 {
0151 const std::size_t offset = accessImpl(m_container->m_spacePointOffsets);
0152 const std::size_t count = accessImpl(m_container->m_spacePointCounts);
0153 return std::span<SpacePointIndex>(
0154 m_container->m_spacePoints.data() + offset, count);
0155 }
0156
0157
0158
0159 float &quality() noexcept
0160 requires(!ReadOnly)
0161 {
0162 return accessImpl(m_container->m_qualities);
0163 }
0164
0165
0166
0167 float &vertexZ() noexcept
0168 requires(!ReadOnly)
0169 {
0170 return accessImpl(m_container->m_vertexZs);
0171 }
0172
0173
0174
0175
0176 std::span<const SpacePointIndex> spacePointIndices() const noexcept {
0177 const std::size_t offset = accessImpl(m_container->m_spacePointOffsets);
0178 const std::size_t count = accessImpl(m_container->m_spacePointCounts);
0179 return std::span<const SpacePointIndex>(
0180 m_container->m_spacePoints.data() + offset, count);
0181 }
0182
0183
0184
0185 float quality() const noexcept {
0186 return accessImpl(m_container->m_qualities);
0187 }
0188
0189
0190
0191 float vertexZ() const noexcept { return accessImpl(m_container->m_vertexZs); }
0192
0193
0194 class SpacePointIterator {
0195 public:
0196
0197 using value_type = ConstSpacePointProxy;
0198
0199 using difference_type = std::ptrdiff_t;
0200
0201 using pointer = void;
0202
0203 using reference = void;
0204
0205
0206 using iterator_category = std::random_access_iterator_tag;
0207
0208 using iterator_concept = std::random_access_iterator_tag;
0209
0210 SpacePointIterator() = default;
0211
0212
0213
0214 SpacePointIterator(const SpacePointContainer &spacePointContainer,
0215 const SpacePointIndex *indexPointer) noexcept
0216 : m_spacePointContainer{&spacePointContainer},
0217 m_indexPointer{indexPointer} {}
0218
0219
0220
0221 value_type operator*() const noexcept {
0222 return (*m_spacePointContainer)[*m_indexPointer];
0223 }
0224
0225
0226
0227 value_type operator[](difference_type n) const noexcept {
0228 return (*m_spacePointContainer)[m_indexPointer[n]];
0229 }
0230
0231
0232
0233 constexpr SpacePointIterator &operator++() noexcept {
0234 ++m_indexPointer;
0235 return *this;
0236 }
0237
0238
0239 constexpr SpacePointIterator operator++(int) noexcept {
0240 auto tmp = *this;
0241 ++(*this);
0242 return tmp;
0243 }
0244
0245
0246 constexpr SpacePointIterator &operator--() noexcept {
0247 --m_indexPointer;
0248 return *this;
0249 }
0250
0251
0252 constexpr SpacePointIterator operator--(int) noexcept {
0253 auto tmp = *this;
0254 --(*this);
0255 return tmp;
0256 }
0257
0258
0259
0260
0261 constexpr SpacePointIterator &operator+=(difference_type n) noexcept {
0262 m_indexPointer += n;
0263 return *this;
0264 }
0265
0266
0267
0268 constexpr SpacePointIterator &operator-=(difference_type n) noexcept {
0269 m_indexPointer -= n;
0270 return *this;
0271 }
0272
0273 private:
0274 const SpacePointContainer *m_spacePointContainer{nullptr};
0275 const SpacePointIndex *m_indexPointer{nullptr};
0276
0277 friend constexpr SpacePointIterator operator+(SpacePointIterator it,
0278 difference_type n) noexcept {
0279 return it += n;
0280 }
0281
0282 friend constexpr SpacePointIterator operator+(
0283 difference_type n, SpacePointIterator it) noexcept {
0284 return it += n;
0285 }
0286
0287 friend constexpr SpacePointIterator operator-(SpacePointIterator it,
0288 difference_type n) noexcept {
0289 return it -= n;
0290 }
0291
0292 friend constexpr difference_type operator-(
0293 const SpacePointIterator &lhs, const SpacePointIterator &rhs) noexcept {
0294 return lhs.m_indexPointer - rhs.m_indexPointer;
0295 }
0296
0297 friend constexpr auto operator<=>(const SpacePointIterator &a,
0298 const SpacePointIterator &b) noexcept {
0299 return a.m_indexPointer <=> b.m_indexPointer;
0300 }
0301
0302 friend constexpr bool operator==(const SpacePointIterator &a,
0303 const SpacePointIterator &b) noexcept {
0304 return a.m_indexPointer == b.m_indexPointer;
0305 }
0306 };
0307
0308
0309 class SpacePointRange {
0310 public:
0311
0312 using size_type = std::size_t;
0313
0314 using value_type = ConstSpacePointProxy;
0315
0316
0317
0318
0319 SpacePointRange(const SpacePointContainer &spacePointContainer,
0320 std::span<const SpacePointIndex> spacePointIndices) noexcept
0321 : m_spacePointContainer{&spacePointContainer},
0322 m_spacePointIndices{spacePointIndices} {}
0323
0324
0325
0326 std::size_t size() const noexcept { return m_spacePointIndices.size(); }
0327
0328
0329 bool empty() const noexcept { return size() == 0; }
0330
0331
0332
0333
0334 ConstSpacePointProxy operator[](std::size_t index) const noexcept {
0335 return (*m_spacePointContainer)[m_spacePointIndices[index]];
0336 }
0337
0338
0339
0340 SpacePointIterator begin() const noexcept {
0341 return {*m_spacePointContainer, m_spacePointIndices.data()};
0342 }
0343
0344
0345 SpacePointIterator end() const noexcept {
0346 return {*m_spacePointContainer,
0347 m_spacePointIndices.data() + m_spacePointIndices.size()};
0348 }
0349
0350 private:
0351 const SpacePointContainer *m_spacePointContainer{nullptr};
0352 std::span<const SpacePointIndex> m_spacePointIndices;
0353 };
0354
0355
0356
0357
0358 SpacePointRange spacePoints() const {
0359 return {m_container->spacePointContainer(), spacePointIndices()};
0360 }
0361
0362
0363
0364
0365
0366 SpacePointRange spacePoints(
0367 const SpacePointContainer &spacePointContainer) const noexcept {
0368 return {spacePointContainer, spacePointIndices()};
0369 }
0370
0371
0372
0373
0374 template <bool other_read_only>
0375 void copyFrom(const SeedProxy<other_read_only> &other,
0376 SeedColumns columnsToCopy) const
0377 requires(!ReadOnly)
0378 {
0379 m_container->copyFrom(m_index, other.container(), other.index(),
0380 columnsToCopy);
0381 }
0382
0383 private:
0384 ContainerType *m_container{nullptr};
0385 IndexType m_index{0};
0386
0387 template <typename Column>
0388 auto &accessImpl(Column &&column) const {
0389 assert(m_index < column.size() && "Index out of bounds");
0390 return column[m_index];
0391 }
0392 };
0393
0394 }