File indexing completed on 2026-11-30 09:45:59
0001
0002
0003 #ifndef ACTSPODIOEDM_TrackStateCollection_H
0004 #define ACTSPODIOEDM_TrackStateCollection_H
0005
0006
0007 #include "ActsPodioEdm/MutableTrackState.h"
0008 #include "ActsPodioEdm/TrackState.h"
0009 #include "ActsPodioEdm/TrackStateCollectionData.h"
0010 #include "ActsPodioEdm/TrackStateObj.h"
0011
0012
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015 #include "podio/detail/Pythonizations.h"
0016 #include "podio/utilities/TypeHelpers.h"
0017
0018 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0019 #include "nlohmann/json_fwd.hpp"
0020 #endif
0021
0022 #include <algorithm>
0023 #include <cstddef>
0024 #include <memory>
0025 #include <mutex>
0026 #include <ostream>
0027 #include <string_view>
0028 #include <vector>
0029
0030 namespace podio {
0031 struct RelationNames;
0032 }
0033
0034 namespace ActsPodioEdm {
0035
0036 class TrackStateCollectionIterator {
0037 public:
0038 using value_type = TrackState;
0039 using difference_type = ptrdiff_t;
0040 using reference = TrackState;
0041 using pointer = TrackState*;
0042 using iterator_category = std::input_iterator_tag;
0043
0044
0045
0046 using iterator_concept = std::random_access_iterator_tag;
0047
0048 TrackStateCollectionIterator(size_t index,
0049 const TrackStateObjPointerContainer* collection)
0050 : m_index(index),
0051 m_object(podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}),
0052 m_collection(collection) {}
0053 TrackStateCollectionIterator() = default;
0054
0055 TrackStateCollectionIterator(const TrackStateCollectionIterator&) = default;
0056 TrackStateCollectionIterator(TrackStateCollectionIterator&&) = default;
0057 TrackStateCollectionIterator& operator=(const TrackStateCollectionIterator&) =
0058 default;
0059 TrackStateCollectionIterator& operator=(TrackStateCollectionIterator&&) =
0060 default;
0061 ~TrackStateCollectionIterator() = default;
0062
0063 constexpr auto operator<=>(const TrackStateCollectionIterator& other) const {
0064 return m_index <=> other.m_index;
0065 }
0066
0067 constexpr bool operator==(const TrackStateCollectionIterator& x) const {
0068 return m_index == x.m_index;
0069 }
0070
0071 reference operator*() const;
0072 pointer operator->();
0073 TrackStateCollectionIterator& operator++();
0074 TrackStateCollectionIterator operator++(int);
0075 TrackStateCollectionIterator& operator--();
0076 TrackStateCollectionIterator operator--(int);
0077 TrackStateCollectionIterator& operator+=(difference_type n);
0078 TrackStateCollectionIterator operator+(difference_type n) const;
0079 friend TrackStateCollectionIterator operator+(
0080 difference_type n, const TrackStateCollectionIterator& it);
0081 TrackStateCollectionIterator& operator-=(difference_type n);
0082 TrackStateCollectionIterator operator-(difference_type n) const;
0083 reference operator[](difference_type n) const;
0084 difference_type operator-(const TrackStateCollectionIterator& other) const;
0085
0086 private:
0087 size_t m_index{0};
0088 TrackState m_object{podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}};
0089 const TrackStateObjPointerContainer* m_collection{nullptr};
0090 };
0091
0092 class TrackStateMutableCollectionIterator {
0093 public:
0094 using value_type = TrackState;
0095 using difference_type = ptrdiff_t;
0096 using reference = MutableTrackState;
0097 using pointer = MutableTrackState*;
0098 using iterator_category = std::input_iterator_tag;
0099
0100
0101
0102 using iterator_concept = std::random_access_iterator_tag;
0103
0104 TrackStateMutableCollectionIterator(
0105 size_t index, const TrackStateObjPointerContainer* collection)
0106 : m_index(index),
0107 m_object(podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}),
0108 m_collection(collection) {}
0109 TrackStateMutableCollectionIterator() = default;
0110
0111 TrackStateMutableCollectionIterator(
0112 const TrackStateMutableCollectionIterator&) = default;
0113 TrackStateMutableCollectionIterator(TrackStateMutableCollectionIterator&&) =
0114 default;
0115 TrackStateMutableCollectionIterator& operator=(
0116 const TrackStateMutableCollectionIterator&) = default;
0117 TrackStateMutableCollectionIterator& operator=(
0118 TrackStateMutableCollectionIterator&&) = default;
0119 ~TrackStateMutableCollectionIterator() = default;
0120
0121 constexpr auto operator<=>(
0122 const TrackStateMutableCollectionIterator& other) const {
0123 return m_index <=> other.m_index;
0124 }
0125
0126 constexpr bool operator==(
0127 const TrackStateMutableCollectionIterator& x) const {
0128 return m_index == x.m_index;
0129 }
0130
0131 reference operator*() const;
0132 pointer operator->();
0133 TrackStateMutableCollectionIterator& operator++();
0134 TrackStateMutableCollectionIterator operator++(int);
0135 TrackStateMutableCollectionIterator& operator--();
0136 TrackStateMutableCollectionIterator operator--(int);
0137 TrackStateMutableCollectionIterator& operator+=(difference_type n);
0138 TrackStateMutableCollectionIterator operator+(difference_type n) const;
0139 friend TrackStateMutableCollectionIterator operator+(
0140 difference_type n, const TrackStateMutableCollectionIterator& it);
0141 TrackStateMutableCollectionIterator& operator-=(difference_type n);
0142 TrackStateMutableCollectionIterator operator-(difference_type n) const;
0143 reference operator[](difference_type n) const;
0144 difference_type operator-(
0145 const TrackStateMutableCollectionIterator& other) const;
0146
0147 private:
0148 size_t m_index{0};
0149 MutableTrackState m_object{
0150 podio::utils::MaybeSharedPtr<TrackStateObj>{nullptr}};
0151 const TrackStateObjPointerContainer* m_collection{nullptr};
0152 };
0153
0154
0155
0156
0157 class TrackStateCollection : public podio::CollectionBase {
0158 public:
0159 using value_type = TrackState;
0160 using mutable_type = MutableTrackState;
0161 using const_iterator = TrackStateCollectionIterator;
0162 using iterator = TrackStateMutableCollectionIterator;
0163 using difference_type = ptrdiff_t;
0164 using size_type = size_t;
0165 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0166 using reverse_iterator = std::reverse_iterator<iterator>;
0167
0168 TrackStateCollection() = default;
0169 TrackStateCollection(TrackStateCollectionData&& data, bool isSubsetColl);
0170
0171 TrackStateCollection(const TrackStateCollection&) = delete;
0172 TrackStateCollection& operator=(const TrackStateCollection&) = delete;
0173 TrackStateCollection(TrackStateCollection&&) = default;
0174 TrackStateCollection& operator=(TrackStateCollection&&) = default;
0175
0176 ~TrackStateCollection() override;
0177 #if defined(__cpp_lib_containers_ranges)
0178 template <podio::detail::RangeConvertibleTo<value_type> R>
0179 TrackStateCollection(std::from_range_t, R&& range);
0180 #endif
0181
0182
0183
0184 template <podio::detail::RangeConvertibleTo<value_type> R>
0185 static TrackStateCollection from(R&& range);
0186
0187 constexpr static std::string_view typeName =
0188 "ActsPodioEdm::TrackStateCollection";
0189 constexpr static std::string_view valueTypeName = "ActsPodioEdm::TrackState";
0190 constexpr static std::string_view dataTypeName =
0191 "ActsPodioEdm::TrackStateData";
0192
0193
0194 void clear() final;
0195
0196
0197
0198 static void __cppjit_pythonize__(PyObject* klass, const std::string& name) {
0199 podio::detail::pythonizations::pythonize_subscript(klass, name);
0200 }
0201
0202 static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0203 __cppjit_pythonize__(klass, name);
0204 }
0205
0206
0207 void print(std::ostream& os = std::cout, bool flush = true) const final;
0208
0209
0210
0211 MutableTrackState create();
0212
0213
0214
0215
0216 template <typename... Args>
0217 MutableTrackState create(Args&&... args);
0218
0219
0220 std::size_t size() const final;
0221
0222
0223 std::size_t max_size() const final;
0224
0225
0226 bool empty() const final;
0227
0228
0229 const std::string_view getTypeName() const final { return typeName; }
0230
0231 const std::string_view getValueTypeName() const final {
0232 return valueTypeName;
0233 }
0234
0235 const std::string_view getDataTypeName() const final { return dataTypeName; }
0236
0237 podio::SchemaVersionT getSchemaVersion() const final;
0238
0239 bool isSubsetCollection() const final { return m_isSubsetColl; }
0240
0241 void setSubsetCollection(bool setSubset = true) final;
0242
0243
0244 TrackState operator[](std::size_t index) const;
0245
0246 MutableTrackState operator[](std::size_t index);
0247
0248 TrackState at(std::size_t index) const;
0249
0250 MutableTrackState at(std::size_t index);
0251
0252
0253
0254 void push_back(const MutableTrackState& object);
0255
0256
0257 void push_back(const TrackState& object);
0258
0259 void prepareForWrite() const final;
0260 void prepareAfterRead() final;
0261 bool setReferences(
0262 const podio::ICollectionProvider* collectionProvider) final;
0263
0264
0265 podio::CollectionWriteBuffers getBuffers() final;
0266
0267 void setID(uint32_t ID) final {
0268 m_collectionID = ID;
0269 if (!m_isSubsetColl) {
0270 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0271 [ID](TrackStateObj* obj) {
0272 obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0273 });
0274 }
0275 }
0276
0277 uint32_t getID() const final { return m_collectionID; }
0278
0279
0280 bool hasID() const final {
0281 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0282 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0283 }
0284
0285 size_t getDatamodelRegistryIndex() const final;
0286
0287
0288 iterator begin() { return iterator(0, &m_storage.entries); }
0289 const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0290 const_iterator cbegin() const { return begin(); }
0291 iterator end() {
0292 return iterator(m_storage.entries.size(), &m_storage.entries);
0293 }
0294 const_iterator end() const {
0295 return const_iterator(m_storage.entries.size(), &m_storage.entries);
0296 }
0297 const_iterator cend() const { return end(); }
0298
0299 reverse_iterator rbegin() { return reverse_iterator(end()); }
0300 const_reverse_iterator rbegin() const {
0301 return const_reverse_iterator(end());
0302 }
0303 const_reverse_iterator crbegin() const { return rbegin(); }
0304 reverse_iterator rend() { return reverse_iterator(begin()); }
0305 const_reverse_iterator rend() const {
0306 return const_reverse_iterator(begin());
0307 }
0308 const_reverse_iterator crend() const { return rend(); }
0309
0310 std::vector<ActsPodioEdm::TrackStateInfo> data(const size_t nElem = 0) const;
0311 std::vector<ActsPodioEdm::Surface> referenceSurface(
0312 const size_t nElem = 0) const;
0313
0314 private:
0315
0316
0317
0318 friend class TrackStateCollectionData;
0319
0320 mutable bool m_isPrepared{false};
0321 bool m_isSubsetColl{false};
0322 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0323 mutable std::unique_ptr<std::mutex> m_storageMtx{
0324 std::make_unique<std::mutex>()};
0325 mutable TrackStateCollectionData m_storage{};
0326 };
0327
0328 std::ostream& operator<<(std::ostream& o, const TrackStateCollection& v);
0329
0330 template <typename... Args>
0331 MutableTrackState TrackStateCollection::create(Args&&... args) {
0332 if (m_isSubsetColl) {
0333 throw std::logic_error("Cannot create new elements on a subset collection");
0334 }
0335 auto obj = new TrackStateObj(
0336 {static_cast<int>(m_storage.entries.size()), m_collectionID},
0337 {std::forward<Args>(args)...});
0338 m_storage.entries.push_back(obj);
0339
0340 return MutableTrackState(podio::utils::MaybeSharedPtr(obj));
0341 }
0342
0343 #if defined(__cpp_lib_containers_ranges)
0344 template <podio::detail::RangeConvertibleTo<TrackStateCollection::value_type> R>
0345 TrackStateCollection::TrackStateCollection(std::from_range_t, R&& range)
0346 : TrackStateCollection() {
0347 setSubsetCollection(podio::detail::RangeOf<R, value_type>);
0348
0349 for (auto&& elem : range) {
0350 push_back(std::forward<decltype(elem)>(elem));
0351 }
0352 }
0353 #endif
0354
0355 template <podio::detail::RangeConvertibleTo<TrackStateCollection::value_type> R>
0356 TrackStateCollection TrackStateCollection::from(R&& range) {
0357 TrackStateCollection coll;
0358 if constexpr (podio::detail::RangeOf<R, value_type>) {
0359 coll.setSubsetCollection();
0360 }
0361
0362 for (auto&& elem : range) {
0363 coll.push_back(std::forward<decltype(elem)>(elem));
0364 }
0365
0366 return coll;
0367 }
0368
0369 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0370 void to_json(nlohmann::json& j, const TrackStateCollection& collection);
0371 #endif
0372
0373 }
0374
0375
0376
0377
0378
0379 #if defined(__clang__)
0380 #pragma clang diagnostic push
0381 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0382 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0383 #pragma clang diagnostic ignored "-Wdeprecated"
0384 constexpr std::string_view ActsPodioEdm::TrackStateCollection::typeName;
0385 constexpr std::string_view ActsPodioEdm::TrackStateCollection::valueTypeName;
0386 constexpr std::string_view ActsPodioEdm::TrackStateCollection::dataTypeName;
0387 #pragma clang diagnostic pop
0388 #elif defined(__GNUC__)
0389 #pragma GCC diagnostic push
0390 #pragma GCC diagnostic ignored "-Wdeprecated"
0391 constexpr std::string_view ActsPodioEdm::TrackStateCollection::typeName;
0392 constexpr std::string_view ActsPodioEdm::TrackStateCollection::valueTypeName;
0393 constexpr std::string_view ActsPodioEdm::TrackStateCollection::dataTypeName;
0394 #pragma GCC diagnostic pop
0395 #endif
0396
0397 #endif