Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-12-01 10:06:26

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef EDM4HEP_TrackCollection_H
0004 #define EDM4HEP_TrackCollection_H
0005 
0006 // datamodel specific includes
0007 #include "edm4hep/MutableTrack.h"
0008 #include "edm4hep/Track.h"
0009 #include "edm4hep/TrackCollectionData.h"
0010 #include "edm4hep/TrackObj.h"
0011 
0012 // podio specific includes
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 edm4hep {
0035 
0036 class TrackCollectionIterator {
0037 public:
0038   using value_type = Track;
0039   using difference_type = ptrdiff_t;
0040   using reference = Track;
0041   using pointer = Track*;
0042   using iterator_category = std::input_iterator_tag;
0043   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0044   // remain valid as long as the iterator is valid, not as long as the range is valid.
0045   using iterator_concept = std::random_access_iterator_tag;
0046 
0047   TrackCollectionIterator(size_t index, const TrackObjPointerContainer* collection)
0048       : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}), m_collection(collection) {}
0049   TrackCollectionIterator() = default;
0050 
0051   TrackCollectionIterator(const TrackCollectionIterator&) = default;
0052   TrackCollectionIterator(TrackCollectionIterator&&) = default;
0053   TrackCollectionIterator& operator=(const TrackCollectionIterator&) = default;
0054   TrackCollectionIterator& operator=(TrackCollectionIterator&&) = default;
0055   ~TrackCollectionIterator() = default;
0056 
0057   constexpr auto operator<=>(const TrackCollectionIterator& other) const { return m_index <=> other.m_index; }
0058 
0059   constexpr bool operator==(const TrackCollectionIterator& x) const { return m_index == x.m_index; }
0060 
0061   reference operator*() const;
0062   pointer operator->();
0063   TrackCollectionIterator& operator++();
0064   TrackCollectionIterator operator++(int);
0065   TrackCollectionIterator& operator--();
0066   TrackCollectionIterator operator--(int);
0067   TrackCollectionIterator& operator+=(difference_type n);
0068   TrackCollectionIterator operator+(difference_type n) const;
0069   friend TrackCollectionIterator operator+(difference_type n, const TrackCollectionIterator& it);
0070   TrackCollectionIterator& operator-=(difference_type n);
0071   TrackCollectionIterator operator-(difference_type n) const;
0072   reference operator[](difference_type n) const;
0073   difference_type operator-(const TrackCollectionIterator& other) const;
0074 
0075 private:
0076   size_t m_index{0};
0077   Track m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0078   const TrackObjPointerContainer* m_collection{nullptr};
0079 };
0080 
0081 class TrackMutableCollectionIterator {
0082 public:
0083   using value_type = Track;
0084   using difference_type = ptrdiff_t;
0085   using reference = MutableTrack;
0086   using pointer = MutableTrack*;
0087   using iterator_category = std::input_iterator_tag;
0088   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0089   // remain valid as long as the iterator is valid, not as long as the range is valid.
0090   using iterator_concept = std::random_access_iterator_tag;
0091 
0092   TrackMutableCollectionIterator(size_t index, const TrackObjPointerContainer* collection)
0093       : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}), m_collection(collection) {}
0094   TrackMutableCollectionIterator() = default;
0095 
0096   TrackMutableCollectionIterator(const TrackMutableCollectionIterator&) = default;
0097   TrackMutableCollectionIterator(TrackMutableCollectionIterator&&) = default;
0098   TrackMutableCollectionIterator& operator=(const TrackMutableCollectionIterator&) = default;
0099   TrackMutableCollectionIterator& operator=(TrackMutableCollectionIterator&&) = default;
0100   ~TrackMutableCollectionIterator() = default;
0101 
0102   constexpr auto operator<=>(const TrackMutableCollectionIterator& other) const { return m_index <=> other.m_index; }
0103 
0104   constexpr bool operator==(const TrackMutableCollectionIterator& x) const { return m_index == x.m_index; }
0105 
0106   reference operator*() const;
0107   pointer operator->();
0108   TrackMutableCollectionIterator& operator++();
0109   TrackMutableCollectionIterator operator++(int);
0110   TrackMutableCollectionIterator& operator--();
0111   TrackMutableCollectionIterator operator--(int);
0112   TrackMutableCollectionIterator& operator+=(difference_type n);
0113   TrackMutableCollectionIterator operator+(difference_type n) const;
0114   friend TrackMutableCollectionIterator operator+(difference_type n, const TrackMutableCollectionIterator& it);
0115   TrackMutableCollectionIterator& operator-=(difference_type n);
0116   TrackMutableCollectionIterator operator-(difference_type n) const;
0117   reference operator[](difference_type n) const;
0118   difference_type operator-(const TrackMutableCollectionIterator& other) const;
0119 
0120 private:
0121   size_t m_index{0};
0122   MutableTrack m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0123   const TrackObjPointerContainer* m_collection{nullptr};
0124 };
0125 
0126 /**
0127 A Collection is identified by an ID.
0128 */
0129 class TrackCollection : public podio::CollectionBase {
0130 public:
0131   using value_type = Track;
0132   using mutable_type = MutableTrack;
0133   using const_iterator = TrackCollectionIterator;
0134   using iterator = TrackMutableCollectionIterator;
0135   using difference_type = ptrdiff_t;
0136   using size_type = size_t;
0137   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0138   using reverse_iterator = std::reverse_iterator<iterator>;
0139 
0140   TrackCollection() = default;
0141   TrackCollection(TrackCollectionData&& data, bool isSubsetColl);
0142   // This is a move-only type
0143   TrackCollection(const TrackCollection&) = delete;
0144   TrackCollection& operator=(const TrackCollection&) = delete;
0145   TrackCollection(TrackCollection&&) = default;
0146   TrackCollection& operator=(TrackCollection&&) = default;
0147 
0148   ~TrackCollection() override;
0149 #if defined(__cpp_lib_containers_ranges)
0150   template <podio::detail::RangeConvertibleTo<value_type> R>
0151   TrackCollection(std::from_range_t, R&& range);
0152 #endif
0153 
0154   /// Construct a Track collection from a range of mutable or
0155   /// immutable handles
0156   template <podio::detail::RangeConvertibleTo<value_type> R>
0157   static TrackCollection from(R&& range);
0158 
0159   constexpr static std::string_view typeName = "edm4hep::TrackCollection";
0160   constexpr static std::string_view valueTypeName = "edm4hep::Track";
0161   constexpr static std::string_view dataTypeName = "edm4hep::TrackData";
0162 
0163   /// Invalidates all iterators.
0164   void clear() final;
0165 
0166   /// Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
0167   static void __cppjit_pythonize__(PyObject* klass, const std::string& name) {
0168     podio::detail::pythonizations::pythonize_subscript(klass, name);
0169   }
0170   /// Pythonizations for ROOT <= 6.40 before the switch to cppjit
0171   static void __cppyy_pythonize__(PyObject* klass, const std::string& name) { __cppjit_pythonize__(klass, name); }
0172 
0173   /// Print this collection to the passed stream
0174   void print(std::ostream& os = std::cout, bool flush = true) const final;
0175 
0176   /// Append a new object to the collection, and return this object.
0177   /// Does not invalidate iterators.
0178   MutableTrack create();
0179 
0180   /// Append a new object to the collection, and return this object.
0181   /// Initialized with the parameters given.
0182   /// Does not invalidate iterators.
0183   template <typename... Args>
0184   MutableTrack create(Args&&... args);
0185 
0186   /// number of elements in the collection
0187   std::size_t size() const final;
0188 
0189   /// maximal number of elements in the collection
0190   std::size_t max_size() const final;
0191 
0192   /// Is the collection empty
0193   bool empty() const final;
0194 
0195   /// fully qualified type name
0196   const std::string_view getTypeName() const final { return typeName; }
0197   /// fully qualified type name of elements - with namespace
0198   const std::string_view getValueTypeName() const final { return valueTypeName; }
0199   /// fully qualified type name of stored POD elements - with namespace
0200   const std::string_view getDataTypeName() const final { return dataTypeName; }
0201   /// schema version
0202   podio::SchemaVersionT getSchemaVersion() const final;
0203 
0204   bool isSubsetCollection() const final { return m_isSubsetColl; }
0205 
0206   void setSubsetCollection(bool setSubset = true) final;
0207 
0208   /// Returns the const object of given index
0209   Track operator[](std::size_t index) const;
0210   /// Returns the object of a given index
0211   MutableTrack operator[](std::size_t index);
0212   /// Returns the const object of given index
0213   Track at(std::size_t index) const;
0214   /// Returns the object of given index
0215   MutableTrack at(std::size_t index);
0216 
0217   /// Append object to the collection.
0218   /// Does not invalidate iterators.
0219   void push_back(const MutableTrack& object);
0220   /// Append an object to the (subset) collection.
0221   /// Does not invalidate iterators.
0222   void push_back(const Track& object);
0223 
0224   void prepareForWrite() const final;
0225   void prepareAfterRead() final;
0226   bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0227 
0228   /// Get the collection buffers for this collection
0229   podio::CollectionWriteBuffers getBuffers() final;
0230 
0231   void setID(uint32_t ID) final {
0232     m_collectionID = ID;
0233     if (!m_isSubsetColl) {
0234       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0235                     [ID](TrackObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; });
0236     }
0237   }
0238 
0239   uint32_t getID() const final { return m_collectionID; }
0240 
0241   /// check if the collection has a valid ID
0242   bool hasID() const final {
0243     return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0244            getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0245   }
0246 
0247   size_t getDatamodelRegistryIndex() const final;
0248 
0249   // support for the iterator protocol
0250   iterator begin() { return iterator(0, &m_storage.entries); }
0251   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0252   const_iterator cbegin() const { return begin(); }
0253   iterator end() { return iterator(m_storage.entries.size(), &m_storage.entries); }
0254   const_iterator end() const { return const_iterator(m_storage.entries.size(), &m_storage.entries); }
0255   const_iterator cend() const { return end(); }
0256   // reverse iterators
0257   reverse_iterator rbegin() { return reverse_iterator(end()); }
0258   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
0259   const_reverse_iterator crbegin() const { return rbegin(); }
0260   reverse_iterator rend() { return reverse_iterator(begin()); }
0261   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
0262   const_reverse_iterator crend() const { return rend(); }
0263 
0264   std::vector<std::int32_t> type(const size_t nElem = 0) const;
0265   std::vector<float> chi2(const size_t nElem = 0) const;
0266   std::vector<std::int32_t> ndf(const size_t nElem = 0) const;
0267   std::vector<std::int32_t> Nholes(const size_t nElem = 0) const;
0268 
0269 private:
0270   // For setReferences, we need to give our own CollectionData access to our
0271   // private entries. Otherwise we would need to expose a public member function
0272   // that gives access to the Obj* which is definitely not what we want
0273   friend class TrackCollectionData;
0274 
0275   mutable bool m_isPrepared{false};
0276   bool m_isSubsetColl{false};
0277   uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0278   mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0279   mutable TrackCollectionData m_storage{};
0280 };
0281 
0282 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0283 
0284 template <typename... Args>
0285 MutableTrack TrackCollection::create(Args&&... args) {
0286   if (m_isSubsetColl) {
0287     throw std::logic_error("Cannot create new elements on a subset collection");
0288   }
0289   auto obj = new TrackObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0290   m_storage.entries.push_back(obj);
0291 
0292   // Need to initialize the relation vectors manually for the {ObjectID, TrackData} constructor
0293   obj->m_trackerHits = new std::vector<edm4hep::TrackerHit>();
0294   obj->m_tracks = new std::vector<edm4hep::Track>();
0295   obj->m_subdetectorHitNumbers = new std::vector<std::int32_t>();
0296   obj->m_subdetectorHoleNumbers = new std::vector<std::int32_t>();
0297   obj->m_trackStates = new std::vector<edm4hep::TrackState>();
0298   m_storage.createRelations(obj);
0299   return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0300 }
0301 
0302 #if defined(__cpp_lib_containers_ranges)
0303 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0304 TrackCollection::TrackCollection(std::from_range_t, R&& range) : TrackCollection() {
0305   setSubsetCollection(podio::detail::RangeOf<R, value_type>);
0306 
0307   for (auto&& elem : range) {
0308     push_back(std::forward<decltype(elem)>(elem));
0309   }
0310 }
0311 #endif
0312 
0313 template <podio::detail::RangeConvertibleTo<TrackCollection::value_type> R>
0314 TrackCollection TrackCollection::from(R&& range) {
0315   TrackCollection coll;
0316   if constexpr (podio::detail::RangeOf<R, value_type>) {
0317     coll.setSubsetCollection();
0318   }
0319 
0320   for (auto&& elem : range) {
0321     coll.push_back(std::forward<decltype(elem)>(elem));
0322   }
0323 
0324   return coll;
0325 }
0326 
0327 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0328 void to_json(nlohmann::json& j, const TrackCollection& collection);
0329 #endif
0330 
0331 } // namespace edm4hep
0332 
0333 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0334 // until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
0335 // and https://github.com/AIDASoft/podio/issues/770
0336 #if defined(__clang__)
0337 #pragma clang diagnostic push
0338 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0339 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0340 #pragma clang diagnostic ignored "-Wdeprecated"
0341 constexpr std::string_view edm4hep::TrackCollection::typeName;
0342 constexpr std::string_view edm4hep::TrackCollection::valueTypeName;
0343 constexpr std::string_view edm4hep::TrackCollection::dataTypeName;
0344 #pragma clang diagnostic pop
0345 #elif defined(__GNUC__)
0346 #pragma GCC diagnostic push
0347 #pragma GCC diagnostic ignored "-Wdeprecated"
0348 constexpr std::string_view edm4hep::TrackCollection::typeName;
0349 constexpr std::string_view edm4hep::TrackCollection::valueTypeName;
0350 constexpr std::string_view edm4hep::TrackCollection::dataTypeName;
0351 #pragma GCC diagnostic pop
0352 #endif
0353 
0354 #endif