Warning, file /include/edm4hep/TrackCollection.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003 #ifndef EDM4HEP_TrackCollection_H
0004 #define EDM4HEP_TrackCollection_H
0005
0006
0007 #include "edm4hep/MutableTrack.h"
0008 #include "edm4hep/Track.h"
0009 #include "edm4hep/TrackCollectionData.h"
0010 #include "edm4hep/TrackObj.h"
0011
0012
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015 #include "podio/detail/Pythonizations.h"
0016
0017 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0018 #include "nlohmann/json_fwd.hpp"
0019 #endif
0020
0021 #include <algorithm>
0022 #include <cstddef>
0023 #include <memory>
0024 #include <mutex>
0025 #include <ostream>
0026 #include <string_view>
0027 #include <vector>
0028
0029 namespace podio {
0030 struct RelationNames;
0031 }
0032
0033 namespace edm4hep {
0034
0035 class TrackCollectionIterator {
0036 public:
0037 using value_type = Track;
0038 using difference_type = ptrdiff_t;
0039 using reference = Track;
0040 using pointer = Track*;
0041 using iterator_category = std::input_iterator_tag;
0042
0043
0044 using iterator_concept = std::random_access_iterator_tag;
0045
0046 TrackCollectionIterator(size_t index, const TrackObjPointerContainer* collection)
0047 : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}), m_collection(collection) {}
0048 TrackCollectionIterator() = default;
0049
0050 TrackCollectionIterator(const TrackCollectionIterator&) = default;
0051 TrackCollectionIterator(TrackCollectionIterator&&) = default;
0052 TrackCollectionIterator& operator=(const TrackCollectionIterator&) = default;
0053 TrackCollectionIterator& operator=(TrackCollectionIterator&&) = default;
0054 ~TrackCollectionIterator() = default;
0055
0056 auto operator<=>(const TrackCollectionIterator& other) const { return m_index <=> other.m_index; }
0057
0058 bool operator==(const TrackCollectionIterator& x) const { return m_index == x.m_index; }
0059
0060 reference operator*() const;
0061 pointer operator->();
0062 TrackCollectionIterator& operator++();
0063 TrackCollectionIterator operator++(int);
0064 TrackCollectionIterator& operator--();
0065 TrackCollectionIterator operator--(int);
0066 TrackCollectionIterator& operator+=(difference_type n);
0067 TrackCollectionIterator operator+(difference_type n) const;
0068 friend TrackCollectionIterator operator+(difference_type n, const TrackCollectionIterator& it);
0069 TrackCollectionIterator& operator-=(difference_type n);
0070 TrackCollectionIterator operator-(difference_type n) const;
0071 reference operator[](difference_type n) const;
0072 difference_type operator-(const TrackCollectionIterator& other) const;
0073
0074 private:
0075 size_t m_index{0};
0076 Track m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0077 const TrackObjPointerContainer* m_collection{nullptr};
0078 };
0079
0080 class TrackMutableCollectionIterator {
0081 public:
0082 using value_type = Track;
0083 using difference_type = ptrdiff_t;
0084 using reference = MutableTrack;
0085 using pointer = MutableTrack*;
0086 using iterator_category = std::input_iterator_tag;
0087
0088
0089 using iterator_concept = std::random_access_iterator_tag;
0090
0091 TrackMutableCollectionIterator(size_t index, const TrackObjPointerContainer* collection)
0092 : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}), m_collection(collection) {}
0093 TrackMutableCollectionIterator() = default;
0094
0095 TrackMutableCollectionIterator(const TrackMutableCollectionIterator&) = default;
0096 TrackMutableCollectionIterator(TrackMutableCollectionIterator&&) = default;
0097 TrackMutableCollectionIterator& operator=(const TrackMutableCollectionIterator&) = default;
0098 TrackMutableCollectionIterator& operator=(TrackMutableCollectionIterator&&) = default;
0099 ~TrackMutableCollectionIterator() = default;
0100
0101 auto operator<=>(const TrackMutableCollectionIterator& other) const { return m_index <=> other.m_index; }
0102
0103 bool operator==(const TrackMutableCollectionIterator& x) const { return m_index == x.m_index; }
0104
0105 reference operator*() const;
0106 pointer operator->();
0107 TrackMutableCollectionIterator& operator++();
0108 TrackMutableCollectionIterator operator++(int);
0109 TrackMutableCollectionIterator& operator--();
0110 TrackMutableCollectionIterator operator--(int);
0111 TrackMutableCollectionIterator& operator+=(difference_type n);
0112 TrackMutableCollectionIterator operator+(difference_type n) const;
0113 friend TrackMutableCollectionIterator operator+(difference_type n, const TrackMutableCollectionIterator& it);
0114 TrackMutableCollectionIterator& operator-=(difference_type n);
0115 TrackMutableCollectionIterator operator-(difference_type n) const;
0116 reference operator[](difference_type n) const;
0117 difference_type operator-(const TrackMutableCollectionIterator& other) const;
0118
0119 private:
0120 size_t m_index{0};
0121 MutableTrack m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0122 const TrackObjPointerContainer* m_collection{nullptr};
0123 };
0124
0125
0126
0127
0128 class TrackCollection : public podio::CollectionBase {
0129 public:
0130 using value_type = Track;
0131 using mutable_type = MutableTrack;
0132 using const_iterator = TrackCollectionIterator;
0133 using iterator = TrackMutableCollectionIterator;
0134 using difference_type = ptrdiff_t;
0135 using size_type = size_t;
0136 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0137 using reverse_iterator = std::reverse_iterator<iterator>;
0138
0139 TrackCollection() = default;
0140 TrackCollection(TrackCollectionData&& data, bool isSubsetColl);
0141
0142 TrackCollection(const TrackCollection&) = delete;
0143 TrackCollection& operator=(const TrackCollection&) = delete;
0144 TrackCollection(TrackCollection&&) = default;
0145 TrackCollection& operator=(TrackCollection&&) = default;
0146
0147
0148 ~TrackCollection() override;
0149
0150 constexpr static std::string_view typeName = "edm4hep::TrackCollection";
0151 constexpr static std::string_view valueTypeName = "edm4hep::Track";
0152 constexpr static std::string_view dataTypeName = "edm4hep::TrackData";
0153
0154 void clear() final;
0155
0156
0157 static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0158 podio::detail::pythonizations::pythonize_subscript(klass, name);
0159 }
0160
0161
0162 void print(std::ostream& os = std::cout, bool flush = true) const final;
0163
0164
0165 MutableTrack create();
0166
0167
0168
0169 template <typename... Args>
0170 MutableTrack create(Args&&... args);
0171
0172
0173 std::size_t size() const final;
0174
0175
0176 std::size_t max_size() const final;
0177
0178
0179 bool empty() const final;
0180
0181
0182 const std::string_view getTypeName() const final { return typeName; }
0183
0184 const std::string_view getValueTypeName() const final { return valueTypeName; }
0185
0186 const std::string_view getDataTypeName() const final { return dataTypeName; }
0187
0188 podio::SchemaVersionT getSchemaVersion() const final;
0189
0190 bool isSubsetCollection() const final { return m_isSubsetColl; }
0191
0192 void setSubsetCollection(bool setSubset = true) final;
0193
0194
0195 Track operator[](std::size_t index) const;
0196
0197 MutableTrack operator[](std::size_t index);
0198
0199 Track at(std::size_t index) const;
0200
0201 MutableTrack at(std::size_t index);
0202
0203
0204 void push_back(const MutableTrack& object);
0205
0206 void push_back(const Track& object);
0207
0208 void prepareForWrite() const final;
0209 void prepareAfterRead() final;
0210 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0211
0212
0213 podio::CollectionWriteBuffers getBuffers() final;
0214
0215 void setID(uint32_t ID) final {
0216 m_collectionID = ID;
0217 if (!m_isSubsetColl) {
0218 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0219 [ID](TrackObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; });
0220 }
0221 }
0222
0223 uint32_t getID() const final { return m_collectionID; }
0224
0225
0226 bool hasID() const final {
0227 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0228 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0229 }
0230
0231 [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
0232 "collection is valid")]] bool
0233 isValid() const final {
0234 return hasID();
0235 }
0236
0237 size_t getDatamodelRegistryIndex() const final;
0238
0239
0240 iterator begin() { return iterator(0, &m_storage.entries); }
0241 const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0242 const_iterator cbegin() const { return begin(); }
0243 iterator end() { return iterator(m_storage.entries.size(), &m_storage.entries); }
0244 const_iterator end() const { return const_iterator(m_storage.entries.size(), &m_storage.entries); }
0245 const_iterator cend() const { return end(); }
0246
0247 reverse_iterator rbegin() { return reverse_iterator(end()); }
0248 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
0249 const_reverse_iterator crbegin() const { return rbegin(); }
0250 reverse_iterator rend() { return reverse_iterator(begin()); }
0251 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
0252 const_reverse_iterator crend() const { return rend(); }
0253
0254 std::vector<std::int32_t> type(const size_t nElem = 0) const;
0255 std::vector<float> chi2(const size_t nElem = 0) const;
0256 std::vector<std::int32_t> ndf(const size_t nElem = 0) const;
0257 std::vector<std::int32_t> Nholes(const size_t nElem = 0) const;
0258
0259 private:
0260
0261
0262
0263 friend class TrackCollectionData;
0264
0265 mutable bool m_isPrepared{false};
0266 bool m_isSubsetColl{false};
0267 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0268 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0269 mutable TrackCollectionData m_storage{};
0270 };
0271
0272 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0273
0274 template <typename... Args>
0275 MutableTrack TrackCollection::create(Args&&... args) {
0276 if (m_isSubsetColl) {
0277 throw std::logic_error("Cannot create new elements on a subset collection");
0278 }
0279 auto obj = new TrackObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0280 m_storage.entries.push_back(obj);
0281
0282
0283 obj->m_trackerHits = new std::vector<edm4hep::TrackerHit>();
0284 obj->m_tracks = new std::vector<edm4hep::Track>();
0285 obj->m_subdetectorHitNumbers = new std::vector<std::int32_t>();
0286 obj->m_subdetectorHoleNumbers = new std::vector<std::int32_t>();
0287 obj->m_trackStates = new std::vector<edm4hep::TrackState>();
0288 m_storage.createRelations(obj);
0289 return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0290 }
0291
0292 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0293 void to_json(nlohmann::json& j, const TrackCollection& collection);
0294 #endif
0295
0296 }
0297
0298
0299
0300
0301 #if defined(__clang__)
0302 #pragma clang diagnostic push
0303 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0304 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0305 #pragma clang diagnostic ignored "-Wdeprecated"
0306 constexpr std::string_view edm4hep::TrackCollection::typeName;
0307 constexpr std::string_view edm4hep::TrackCollection::valueTypeName;
0308 constexpr std::string_view edm4hep::TrackCollection::dataTypeName;
0309 #pragma clang diagnostic pop
0310 #elif defined(__GNUC__)
0311 #pragma GCC diagnostic push
0312 #pragma GCC diagnostic ignored "-Wdeprecated"
0313 constexpr std::string_view edm4hep::TrackCollection::typeName;
0314 constexpr std::string_view edm4hep::TrackCollection::valueTypeName;
0315 constexpr std::string_view edm4hep::TrackCollection::dataTypeName;
0316 #pragma GCC diagnostic pop
0317 #endif
0318
0319 #endif