File indexing completed on 2024-11-15 09:01:28
0001
0002
0003
0004
0005
0006
0007
0008
0009 #pragma once
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Definitions/TrackParametrization.hpp"
0013 #include "Acts/Definitions/Units.hpp"
0014 #include "Acts/EventData/MultiTrajectory.hpp"
0015 #include "Acts/EventData/TrackContainerBackendConcept.hpp"
0016 #include "Acts/EventData/TrackProxy.hpp"
0017 #include "Acts/EventData/Types.hpp"
0018 #include "Acts/EventData/Utils.hpp"
0019 #include "Acts/Utilities/HashedString.hpp"
0020 #include "Acts/Utilities/Holders.hpp"
0021 #include "Acts/Utilities/UnitVectors.hpp"
0022
0023 #include <any>
0024 #include <cstddef>
0025 #include <iterator>
0026
0027 namespace Acts {
0028
0029 template <typename T>
0030 struct IsReadOnlyTrackContainer;
0031
0032
0033
0034
0035
0036
0037
0038 template <ACTS_CONCEPT(TrackContainerBackend) track_container_t,
0039 typename traj_t,
0040 template <typename> class holder_t = detail::RefHolder>
0041 class TrackContainer {
0042 public:
0043
0044 static constexpr bool ReadOnly =
0045 IsReadOnlyTrackContainer<track_container_t>::value;
0046
0047
0048
0049 static constexpr bool TrackStateReadOnly =
0050 IsReadOnlyMultiTrajectory<traj_t>::value;
0051
0052 static_assert(ReadOnly == TrackStateReadOnly,
0053 "Either both track container and track state container need to "
0054 "be readonly or both have to be readwrite");
0055
0056
0057 using IndexType = TrackIndexType;
0058
0059
0060 static constexpr IndexType kInvalid = kTrackIndexInvalid;
0061
0062
0063
0064 using TrackProxy =
0065 Acts::TrackProxy<track_container_t, traj_t, holder_t, false>;
0066
0067
0068
0069 using ConstTrackProxy =
0070 Acts::TrackProxy<track_container_t, traj_t, holder_t, true>;
0071
0072 #ifndef DOXYGEN
0073 friend TrackProxy;
0074 friend ConstTrackProxy;
0075 #endif
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 TrackContainer(holder_t<track_container_t> container, holder_t<traj_t> traj)
0093 : m_container{std::move(container)}, m_traj{std::move(traj)} {}
0094
0095
0096
0097
0098
0099
0100
0101 template <template <typename> class H = holder_t,
0102 typename = std::enable_if_t<
0103 detail::is_same_template<H, detail::RefHolder>::value>>
0104 TrackContainer(track_container_t& container, traj_t& traj)
0105 : m_container{&container}, m_traj{&traj} {}
0106
0107
0108
0109
0110
0111
0112
0113 template <
0114 template <typename> class H = holder_t,
0115 bool RO = (IsReadOnlyTrackContainer<track_container_t>::value &&
0116 IsReadOnlyMultiTrajectory<traj_t>::value),
0117 typename = std::enable_if_t<
0118 detail::is_same_template<H, detail::ConstRefHolder>::value && RO>>
0119 TrackContainer(const track_container_t& container, const traj_t& traj)
0120 : m_container{&container}, m_traj{&traj} {}
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135 ConstTrackProxy getTrack(IndexType itrack) const {
0136 return {*this, itrack};
0137 }
0138
0139
0140
0141
0142
0143 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0144 TrackProxy getTrack(IndexType itrack) {
0145 return {*this, itrack};
0146 }
0147
0148
0149
0150
0151
0152 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0153 IndexType addTrack() {
0154 auto track = getTrack(m_container->addTrack_impl());
0155 track.tipIndex() = kInvalid;
0156 return track.index();
0157 }
0158
0159
0160
0161
0162
0163 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0164 TrackProxy makeTrack() {
0165 return getTrack(addTrack());
0166 }
0167
0168
0169
0170
0171
0172
0173 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0174 void removeTrack(IndexType itrack) {
0175 m_container->removeTrack_impl(itrack);
0176 }
0177
0178
0179
0180
0181 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0182 auto begin() {
0183 return detail_tc::TrackProxyIterator<std::decay_t<decltype(*this)>,
0184 TrackProxy, false>{*this, 0};
0185 }
0186
0187
0188
0189
0190 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0191 auto end() {
0192 return detail_tc::TrackProxyIterator<std::decay_t<decltype(*this)>,
0193 TrackProxy, false>{*this, size()};
0194 }
0195
0196
0197
0198 auto begin() const {
0199 return detail_tc::TrackProxyIterator<std::decay_t<decltype(*this)>,
0200 ConstTrackProxy, true>{*this, 0};
0201 }
0202
0203
0204
0205 auto end() const {
0206 return detail_tc::TrackProxyIterator<std::decay_t<decltype(*this)>,
0207 ConstTrackProxy, true>{*this, size()};
0208 }
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222 template <typename T, bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0223 constexpr void addColumn(const std::string& key) {
0224 m_container->template addColumn_impl<T>(key);
0225 }
0226
0227
0228
0229 constexpr bool hasColumn(const std::string& key) const {
0230 return m_container->hasColumn_impl(hashString(key));
0231 }
0232
0233
0234
0235 constexpr bool hasColumn(HashedString key) const {
0236 return m_container->hasColumn_impl(key);
0237 }
0238
0239
0240
0241
0242
0243
0244
0245
0246 template <typename other_track_container_t, bool RO = ReadOnly,
0247 typename = std::enable_if_t<!RO>>
0248 void ensureDynamicColumns(const other_track_container_t& other) {
0249 container().ensureDynamicColumns_impl(other.container());
0250 }
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0264 auto& container() {
0265 return *m_container;
0266 }
0267
0268
0269
0270 const auto& container() const {
0271 return *m_container;
0272 }
0273
0274
0275
0276
0277 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0278 auto& trackStateContainer() {
0279 return *m_traj;
0280 }
0281
0282
0283
0284
0285 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0286 auto& trackStateContainerHolder() {
0287 return m_traj;
0288 }
0289
0290
0291
0292 const auto& trackStateContainer() const {
0293 return *m_traj;
0294 }
0295
0296
0297
0298 const auto& trackStateContainerHolder() const {
0299 return m_traj;
0300 }
0301
0302
0303
0304
0305
0306 constexpr IndexType size() const {
0307 return m_container->size_impl();
0308 }
0309
0310
0311
0312 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0313 void clear() {
0314 m_container->clear();
0315 m_traj->clear();
0316 }
0317
0318 protected:
0319 template <typename T, HashedString key, bool RO = ReadOnly,
0320 typename = std::enable_if_t<!RO>>
0321 constexpr T& component(IndexType itrack) {
0322 return *std::any_cast<T*>(container().component_impl(key, itrack));
0323 }
0324
0325 template <typename T, bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0326 constexpr T& component(HashedString key, IndexType itrack) {
0327 return *std::any_cast<T*>(container().component_impl(key, itrack));
0328 }
0329
0330 template <typename T, HashedString key>
0331 constexpr const T& component(IndexType itrack) const {
0332 return *std::any_cast<const T*>(container().component_impl(key, itrack));
0333 }
0334
0335 template <typename T>
0336 constexpr const T& component(HashedString key, IndexType itrack) const {
0337 return *std::any_cast<const T*>(container().component_impl(key, itrack));
0338 }
0339
0340 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0341 constexpr typename TrackProxy::Parameters parameters(IndexType itrack) {
0342 return container().parameters(itrack);
0343 }
0344
0345 constexpr typename ConstTrackProxy::ConstParameters parameters(
0346 IndexType itrack) const {
0347 return container().parameters(itrack);
0348 }
0349
0350 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0351 constexpr typename TrackProxy::Covariance covariance(IndexType itrack) {
0352 return container().covariance(itrack);
0353 }
0354
0355 constexpr typename ConstTrackProxy::ConstCovariance covariance(
0356 IndexType itrack) const {
0357 return container().covariance(itrack);
0358 }
0359
0360 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0361 auto reverseTrackStateRange(IndexType itrack) {
0362 auto tip = component<IndexType, hashString("tipIndex")>(itrack);
0363 return m_traj->reverseTrackStateRange(tip);
0364 }
0365
0366 auto reverseTrackStateRange(IndexType itrack) const {
0367 auto tip = component<IndexType, hashString("tipIndex")>(itrack);
0368 return m_traj->reverseTrackStateRange(tip);
0369 }
0370
0371 template <bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0372 auto forwardTrackStateRange(IndexType itrack) {
0373 auto stem = component<IndexType, hashString("stemIndex")>(itrack);
0374 if (stem == kInvalid) {
0375 throw std::invalid_argument{"Track has no stem index"};
0376 }
0377 return m_traj->forwardTrackStateRange(stem);
0378 }
0379
0380 auto forwardTrackStateRange(IndexType itrack) const {
0381 auto stem = component<IndexType, hashString("stemIndex")>(itrack);
0382 if (stem == kInvalid) {
0383 throw std::invalid_argument{"Track has no stem index"};
0384 }
0385 return m_traj->forwardTrackStateRange(stem);
0386 }
0387
0388 private:
0389 template <typename T, bool RO = ReadOnly, typename = std::enable_if_t<!RO>>
0390 void copyDynamicFrom(IndexType dstIdx, const T& src, IndexType srcIdx) {
0391 const auto& dynamicKeys = src.dynamicKeys_impl();
0392 for (const auto key : dynamicKeys) {
0393 std::any srcPtr = src.component_impl(key, srcIdx);
0394 container().copyDynamicFrom_impl(dstIdx, key, srcPtr);
0395 }
0396 }
0397
0398 detail_tc::ConstIf<holder_t<track_container_t>, ReadOnly> m_container;
0399 detail_tc::ConstIf<holder_t<traj_t>, ReadOnly> m_traj;
0400 };
0401
0402 template <ACTS_CONCEPT(TrackContainerBackend) track_container_t,
0403 typename traj_t>
0404 TrackContainer(track_container_t& container, traj_t& traj)
0405 -> TrackContainer<track_container_t, traj_t, detail::RefHolder>;
0406
0407 template <ACTS_CONCEPT(TrackContainerBackend) track_container_t,
0408 typename traj_t>
0409 TrackContainer(const track_container_t& container, const traj_t& traj)
0410 -> TrackContainer<track_container_t, traj_t, detail::ConstRefHolder>;
0411
0412 template <ACTS_CONCEPT(TrackContainerBackend) track_container_t,
0413 typename traj_t>
0414 TrackContainer(track_container_t&& container, traj_t&& traj)
0415 -> TrackContainer<track_container_t, traj_t, detail::ValueHolder>;
0416
0417 }