Warning, file /acts/Core/include/Acts/EventData/TrackContainer.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/DynamicColumnInfo.hpp"
0012 #include "Acts/EventData/MultiTrajectory.hpp"
0013 #include "Acts/EventData/MultiTrajectoryBackendConcept.hpp"
0014 #include "Acts/EventData/TrackContainerBackendConcept.hpp"
0015 #include "Acts/EventData/TrackProxy.hpp"
0016 #include "Acts/EventData/Types.hpp"
0017 #include "Acts/EventData/Utils.hpp"
0018 #include "Acts/Utilities/HashedString.hpp"
0019 #include "Acts/Utilities/Holders.hpp"
0020 #include "Acts/Utilities/TypeTraits.hpp"
0021 #include "Acts/Utilities/detail/ContainerIterator.hpp"
0022
0023 #include <any>
0024 #include <string>
0025 #include <string_view>
0026
0027 namespace Acts {
0028
0029 template <typename T>
0030 struct IsReadOnlyTrackContainer;
0031
0032
0033
0034
0035
0036
0037
0038 template <TrackContainerBackend track_container_t,
0039 CommonMultiTrajectoryBackend traj_t,
0040 template <typename> class holder_t = RefHolder>
0041 requires HolderFor<holder_t, track_container_t> && HolderFor<holder_t, traj_t>
0042 class TrackContainer {
0043 public:
0044
0045 static constexpr bool ReadOnly =
0046 IsReadOnlyTrackContainer<track_container_t>::value;
0047
0048
0049
0050 static constexpr bool TrackStateReadOnly =
0051 IsReadOnlyMultiTrajectory<traj_t>::value;
0052
0053 static_assert(ReadOnly == TrackStateReadOnly,
0054 "Either both track container and track state container need to "
0055 "be readonly or both have to be readwrite");
0056
0057
0058 using IndexType = TrackIndexType;
0059
0060
0061 static constexpr IndexType kInvalid = kTrackIndexInvalid;
0062
0063
0064
0065 using TrackProxy =
0066 Acts::TrackProxy<track_container_t, traj_t, holder_t, false>;
0067
0068
0069
0070 using ConstTrackProxy =
0071 Acts::TrackProxy<track_container_t, traj_t, holder_t, true>;
0072
0073 static_assert(ConstTrackProxyConcept<ConstTrackProxy>,
0074 "ConstTrackProxy must fulfill the TrackProxyConcept");
0075 static_assert(ReadOnly || MutableTrackProxyConcept<TrackProxy>,
0076 "TrackProxy must fulfill the TrackProxyConcept");
0077
0078
0079 using TrackContainerBackend = track_container_t;
0080
0081 using TrackStateContainerBackend = traj_t;
0082
0083
0084 using TrackStateProxy = typename MultiTrajectory<traj_t>::TrackStateProxy;
0085
0086 using ConstTrackStateProxy =
0087 typename MultiTrajectory<traj_t>::ConstTrackStateProxy;
0088
0089
0090 using size_type = IndexType;
0091
0092 using iterator =
0093 detail::ContainerIterator<TrackContainer, TrackProxy, IndexType, false>;
0094
0095 using const_iterator =
0096 detail::ContainerIterator<TrackContainer, ConstTrackProxy, IndexType,
0097 true>;
0098
0099 #ifndef DOXYGEN
0100 friend TrackProxy;
0101 friend ConstTrackProxy;
0102 #endif
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 TrackContainer(holder_t<track_container_t> container, holder_t<traj_t> traj)
0120 : m_container{std::move(container)}, m_traj{std::move(traj)} {}
0121
0122
0123
0124
0125
0126
0127
0128 TrackContainer(auto& container, auto& traj)
0129 requires(std::same_as<holder_t<track_container_t>,
0130 RefHolder<track_container_t>> &&
0131 std::same_as<holder_t<traj_t>, RefHolder<traj_t>>)
0132 : m_container{&container}, m_traj{&traj} {}
0133
0134
0135
0136
0137
0138
0139
0140 TrackContainer(const auto& container, const auto& traj)
0141 requires(std::same_as<holder_t<track_container_t>,
0142 ConstRefHolder<track_container_t>> &&
0143 std::same_as<holder_t<traj_t>, ConstRefHolder<traj_t>> &&
0144 ReadOnly && TrackStateReadOnly)
0145 : m_container{&container}, m_traj{&traj} {}
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 ConstTrackProxy getTrack(IndexType itrack) const { return {*this, itrack}; }
0161
0162
0163
0164
0165
0166 TrackProxy getTrack(IndexType itrack)
0167 requires(!ReadOnly)
0168 {
0169 return {*this, itrack};
0170 }
0171
0172
0173
0174
0175 ConstTrackProxy at(IndexType itrack) const { return getTrack(itrack); }
0176
0177
0178
0179
0180
0181 TrackProxy at(IndexType itrack)
0182 requires(!ReadOnly)
0183 {
0184 return {*this, itrack};
0185 }
0186
0187
0188
0189
0190
0191 IndexType addTrack()
0192 requires(!ReadOnly)
0193 {
0194 auto track = getTrack(m_container->addTrack_impl());
0195 track.tipIndex() = kInvalid;
0196 return track.index();
0197 }
0198
0199
0200
0201
0202
0203 TrackProxy makeTrack()
0204 requires(!ReadOnly)
0205 {
0206 return getTrack(addTrack());
0207 }
0208
0209
0210
0211
0212
0213
0214 void removeTrack(IndexType itrack)
0215 requires(!ReadOnly)
0216 {
0217 m_container->removeTrack_impl(itrack);
0218 }
0219
0220
0221
0222
0223 iterator begin()
0224 requires(!ReadOnly)
0225 {
0226 return iterator{*this, 0};
0227 }
0228
0229
0230
0231
0232 iterator end()
0233 requires(!ReadOnly)
0234 {
0235 return iterator{*this, size()};
0236 }
0237
0238
0239
0240 const_iterator begin() const { return const_iterator{*this, 0}; }
0241
0242
0243
0244 const_iterator end() const { return const_iterator{*this, size()}; }
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258 template <typename T>
0259 constexpr void addColumn(std::string_view key)
0260 requires(!ReadOnly)
0261 {
0262 m_container->template addColumn_impl<T>(key);
0263 }
0264
0265
0266
0267
0268 constexpr bool hasColumn(const std::string& key) const {
0269 return m_container->hasColumn_impl(hashStringDynamic(key));
0270 }
0271
0272
0273
0274
0275 constexpr bool hasColumn(HashedString key) const {
0276 return m_container->hasColumn_impl(key);
0277 }
0278
0279
0280
0281
0282 detail::DynamicColumnInfoRange auto dynamicColumns() const
0283 requires requires(const track_container_t& backend) {
0284 { backend.dynamicColumns_impl() } -> detail::DynamicColumnInfoRange;
0285 }
0286 {
0287 return container().dynamicColumns_impl();
0288 }
0289
0290
0291
0292
0293
0294
0295
0296
0297 template <typename other_track_container_t>
0298 void ensureDynamicColumns(const other_track_container_t& other)
0299 requires(!ReadOnly)
0300 {
0301 container().ensureDynamicColumns_impl(other.container());
0302 trackStateContainer().ensureDynamicColumns_impl(
0303 other.trackStateContainer());
0304 }
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315
0316
0317 auto& container()
0318 requires(!ReadOnly)
0319 {
0320 return *m_container;
0321 }
0322
0323
0324
0325 const auto& container() const { return *m_container; }
0326
0327
0328
0329
0330 auto& trackStateContainer()
0331 requires(!ReadOnly)
0332 {
0333 return *m_traj;
0334 }
0335
0336
0337
0338
0339 auto& trackStateContainerHolder()
0340 requires(!ReadOnly)
0341 {
0342 return m_traj;
0343 }
0344
0345
0346
0347 const auto& trackStateContainer() const { return *m_traj; }
0348
0349
0350
0351 const auto& trackStateContainerHolder() const { return m_traj; }
0352
0353
0354
0355
0356
0357 constexpr IndexType size() const { return m_container->size_impl(); }
0358
0359
0360
0361 void clear()
0362 requires(!ReadOnly)
0363 {
0364 m_container->clear();
0365 m_traj->clear();
0366 }
0367
0368 protected:
0369
0370
0371
0372
0373
0374 template <typename T, HashedString key>
0375 constexpr T& component(IndexType itrack)
0376 requires(!ReadOnly)
0377 {
0378 return *std::any_cast<T*>(container().component_impl(key, itrack));
0379 }
0380
0381
0382
0383
0384
0385
0386 template <typename T>
0387 constexpr T& component(HashedString key, IndexType itrack)
0388 requires(!ReadOnly)
0389 {
0390 return *std::any_cast<T*>(container().component_impl(key, itrack));
0391 }
0392
0393
0394
0395
0396
0397
0398 template <typename T, HashedString key>
0399 constexpr const T& component(IndexType itrack) const {
0400 return *std::any_cast<const T*>(container().component_impl(key, itrack));
0401 }
0402
0403
0404
0405
0406
0407
0408 template <typename T>
0409 constexpr const T& component(HashedString key, IndexType itrack) const {
0410 return *std::any_cast<const T*>(container().component_impl(key, itrack));
0411 }
0412
0413
0414
0415
0416 constexpr typename TrackProxy::Parameters parameters(IndexType itrack)
0417 requires(!ReadOnly)
0418 {
0419 return container().parameters(itrack);
0420 }
0421
0422
0423
0424
0425 constexpr typename ConstTrackProxy::ConstParameters parameters(
0426 IndexType itrack) const {
0427 return container().parameters(itrack);
0428 }
0429
0430
0431
0432
0433 constexpr typename TrackProxy::Covariance covariance(IndexType itrack)
0434 requires(!ReadOnly)
0435 {
0436 return container().covariance(itrack);
0437 }
0438
0439
0440
0441
0442 constexpr typename ConstTrackProxy::ConstCovariance covariance(
0443 IndexType itrack) const {
0444 return container().covariance(itrack);
0445 }
0446
0447
0448
0449
0450 auto reverseTrackStateRange(IndexType itrack)
0451 requires(!ReadOnly)
0452 {
0453 auto tip = component<IndexType, hashString("tipIndex")>(itrack);
0454 return m_traj->reverseTrackStateRange(tip);
0455 }
0456
0457
0458
0459
0460 auto reverseTrackStateRange(IndexType itrack) const {
0461 auto tip = component<IndexType, hashString("tipIndex")>(itrack);
0462 return m_traj->reverseTrackStateRange(tip);
0463 }
0464
0465
0466
0467
0468
0469 auto forwardTrackStateRange(IndexType itrack)
0470 requires(!ReadOnly)
0471 {
0472 auto stem = component<IndexType, hashString("stemIndex")>(itrack);
0473 if (stem == kInvalid) {
0474 throw std::invalid_argument{"Track has no stem index"};
0475 }
0476 return m_traj->forwardTrackStateRange(stem);
0477 }
0478
0479
0480
0481
0482
0483 auto forwardTrackStateRange(IndexType itrack) const {
0484 auto stem = component<IndexType, hashString("stemIndex")>(itrack);
0485 if (stem == kInvalid) {
0486 throw std::invalid_argument{"Track has no stem index"};
0487 }
0488 return m_traj->forwardTrackStateRange(stem);
0489 }
0490
0491 private:
0492 template <typename T>
0493 void copyDynamicFrom(IndexType dstIdx, const T& src, IndexType srcIdx)
0494 requires(!ReadOnly)
0495 {
0496 const auto& dynamicKeys = src.dynamicKeys_impl();
0497 for (const auto key : dynamicKeys) {
0498 std::any srcPtr = src.component_impl(key, srcIdx);
0499 container().copyDynamicFrom_impl(dstIdx, key, srcPtr);
0500 }
0501 }
0502
0503 const_if_t<ReadOnly, holder_t<track_container_t>> m_container;
0504 const_if_t<ReadOnly, holder_t<traj_t>> m_traj;
0505 };
0506
0507
0508
0509
0510 template <TrackContainerBackend track_container_t, typename traj_t>
0511 TrackContainer(track_container_t& container, traj_t& traj)
0512 -> TrackContainer<track_container_t, traj_t, RefHolder>;
0513
0514
0515
0516
0517 template <TrackContainerBackend track_container_t, typename traj_t>
0518 TrackContainer(const track_container_t& container, const traj_t& traj)
0519 -> TrackContainer<track_container_t, traj_t, ConstRefHolder>;
0520
0521
0522
0523
0524 template <TrackContainerBackend track_container_t, typename traj_t>
0525 TrackContainer(track_container_t&& container, traj_t&& traj)
0526 -> TrackContainer<track_container_t, traj_t, ValueHolder>;
0527
0528 }