Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-16 08:27:50

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef ACTSPODIOEDM_TrackCollection_H
0004 #define ACTSPODIOEDM_TrackCollection_H
0005 
0006 // datamodel specific includes
0007 #include "ActsPodioEdm/MutableTrack.h"
0008 #include "ActsPodioEdm/Track.h"
0009 #include "ActsPodioEdm/TrackCollectionData.h"
0010 #include "ActsPodioEdm/TrackObj.h"
0011 
0012 // podio specific includes
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015 
0016 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0017 #include "nlohmann/json_fwd.hpp"
0018 #endif
0019 
0020 #include <algorithm>
0021 #include <cstddef>
0022 #include <memory>
0023 #include <mutex>
0024 #include <ostream>
0025 #include <string_view>
0026 #include <vector>
0027 
0028 namespace podio {
0029 struct RelationNames;
0030 }
0031 
0032 namespace ActsPodioEdm {
0033 
0034 class TrackCollectionIterator {
0035  public:
0036   using value_type = Track;
0037   using difference_type = ptrdiff_t;
0038   using reference = Track;
0039   using pointer = Track*;
0040   using iterator_category = std::input_iterator_tag;
0041   // `std::forward_iterator` is supported except that the pointers obtained with
0042   // `operator->()` remain valid as long as the iterator is valid, not as long
0043   // as the range is valid.
0044   using iterator_concept = std::random_access_iterator_tag;
0045 
0046   TrackCollectionIterator(size_t index,
0047                           const TrackObjPointerContainer* collection)
0048       : m_index(index),
0049         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0050         m_collection(collection) {}
0051   TrackCollectionIterator() = default;
0052 
0053   TrackCollectionIterator(const TrackCollectionIterator&) = default;
0054   TrackCollectionIterator(TrackCollectionIterator&&) = default;
0055   TrackCollectionIterator& operator=(const TrackCollectionIterator&) = default;
0056   TrackCollectionIterator& operator=(TrackCollectionIterator&&) = default;
0057   ~TrackCollectionIterator() = default;
0058 
0059   auto operator<=>(const TrackCollectionIterator& other) const {
0060     return m_index <=> other.m_index;
0061   }
0062 
0063   bool operator==(const TrackCollectionIterator& x) const {
0064     return m_index == x.m_index;
0065   }
0066 
0067   reference operator*() const;
0068   pointer operator->();
0069   TrackCollectionIterator& operator++();
0070   TrackCollectionIterator operator++(int);
0071   TrackCollectionIterator& operator--();
0072   TrackCollectionIterator operator--(int);
0073   TrackCollectionIterator& operator+=(difference_type n);
0074   TrackCollectionIterator operator+(difference_type n) const;
0075   friend TrackCollectionIterator operator+(difference_type n,
0076                                            const TrackCollectionIterator& it);
0077   TrackCollectionIterator& operator-=(difference_type n);
0078   TrackCollectionIterator operator-(difference_type n) const;
0079   reference operator[](difference_type n) const;
0080   difference_type operator-(const TrackCollectionIterator& other) const;
0081 
0082  private:
0083   size_t m_index{0};
0084   Track m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0085   const TrackObjPointerContainer* m_collection{nullptr};
0086 };
0087 
0088 class TrackMutableCollectionIterator {
0089  public:
0090   using value_type = Track;
0091   using difference_type = ptrdiff_t;
0092   using reference = MutableTrack;
0093   using pointer = MutableTrack*;
0094   using iterator_category = std::input_iterator_tag;
0095   // `std::forward_iterator` is supported except that the pointers obtained with
0096   // `operator->()` remain valid as long as the iterator is valid, not as long
0097   // as the range is valid.
0098   using iterator_concept = std::random_access_iterator_tag;
0099 
0100   TrackMutableCollectionIterator(size_t index,
0101                                  const TrackObjPointerContainer* collection)
0102       : m_index(index),
0103         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0104         m_collection(collection) {}
0105   TrackMutableCollectionIterator() = default;
0106 
0107   TrackMutableCollectionIterator(const TrackMutableCollectionIterator&) =
0108       default;
0109   TrackMutableCollectionIterator(TrackMutableCollectionIterator&&) = default;
0110   TrackMutableCollectionIterator& operator=(
0111       const TrackMutableCollectionIterator&) = default;
0112   TrackMutableCollectionIterator& operator=(TrackMutableCollectionIterator&&) =
0113       default;
0114   ~TrackMutableCollectionIterator() = default;
0115 
0116   auto operator<=>(const TrackMutableCollectionIterator& other) const {
0117     return m_index <=> other.m_index;
0118   }
0119 
0120   bool operator==(const TrackMutableCollectionIterator& x) const {
0121     return m_index == x.m_index;
0122   }
0123 
0124   reference operator*() const;
0125   pointer operator->();
0126   TrackMutableCollectionIterator& operator++();
0127   TrackMutableCollectionIterator operator++(int);
0128   TrackMutableCollectionIterator& operator--();
0129   TrackMutableCollectionIterator operator--(int);
0130   TrackMutableCollectionIterator& operator+=(difference_type n);
0131   TrackMutableCollectionIterator operator+(difference_type n) const;
0132   friend TrackMutableCollectionIterator operator+(
0133       difference_type n, const TrackMutableCollectionIterator& it);
0134   TrackMutableCollectionIterator& operator-=(difference_type n);
0135   TrackMutableCollectionIterator operator-(difference_type n) const;
0136   reference operator[](difference_type n) const;
0137   difference_type operator-(const TrackMutableCollectionIterator& other) const;
0138 
0139  private:
0140   size_t m_index{0};
0141   MutableTrack m_object{podio::utils::MaybeSharedPtr<TrackObj>{nullptr}};
0142   const TrackObjPointerContainer* m_collection{nullptr};
0143 };
0144 
0145 /**
0146 A Collection is identified by an ID.
0147 */
0148 class TrackCollection : public podio::CollectionBase {
0149  public:
0150   using value_type = Track;
0151   using mutable_type = MutableTrack;
0152   using const_iterator = TrackCollectionIterator;
0153   using iterator = TrackMutableCollectionIterator;
0154   using difference_type = ptrdiff_t;
0155   using size_type = size_t;
0156   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0157   using reverse_iterator = std::reverse_iterator<iterator>;
0158 
0159   TrackCollection();
0160   TrackCollection(TrackCollectionData&& data, bool isSubsetColl);
0161   // This is a move-only type
0162   TrackCollection(const TrackCollection&) = delete;
0163   TrackCollection& operator=(const TrackCollection&) = delete;
0164   TrackCollection(TrackCollection&&) = default;
0165   TrackCollection& operator=(TrackCollection&&) = default;
0166 
0167   //  TrackCollection(TrackVector* data, uint32_t collectionID);
0168   ~TrackCollection() override;
0169 
0170   constexpr static std::string_view typeName = "ActsPodioEdm::TrackCollection";
0171   constexpr static std::string_view valueTypeName = "ActsPodioEdm::Track";
0172   constexpr static std::string_view dataTypeName = "ActsPodioEdm::TrackData";
0173 
0174   void clear() final;
0175 
0176   /// Print this collection to the passed stream
0177   void print(std::ostream& os = std::cout, bool flush = true) const final;
0178 
0179   /// operator to allow pointer like calling of members a la LCIO
0180   TrackCollection* operator->() { return static_cast<TrackCollection*>(this); }
0181 
0182   /// Append a new object to the collection, and return this object.
0183   MutableTrack create();
0184 
0185   /// Append a new object to the collection, and return this object.
0186   /// Initialized with the parameters given
0187   template <typename... Args>
0188   MutableTrack create(Args&&... args);
0189 
0190   /// number of elements in the collection
0191   std::size_t size() const final;
0192 
0193   /// maximal number of elements in the collection
0194   std::size_t max_size() const final;
0195 
0196   /// Is the collection empty
0197   bool empty() const final;
0198 
0199   /// fully qualified type name
0200   const std::string_view getTypeName() const final { return typeName; }
0201   /// fully qualified type name of elements - with namespace
0202   const std::string_view getValueTypeName() const final {
0203     return valueTypeName;
0204   }
0205   /// fully qualified type name of stored POD elements - with namespace
0206   const std::string_view getDataTypeName() const final { return dataTypeName; }
0207   /// schema version
0208   podio::SchemaVersionT getSchemaVersion() const final;
0209 
0210   bool isSubsetCollection() const final { return m_isSubsetColl; }
0211 
0212   void setSubsetCollection(bool setSubset = true) final;
0213 
0214   /// Returns the const object of given index
0215   Track operator[](std::size_t index) const;
0216   /// Returns the object of a given index
0217   MutableTrack operator[](std::size_t index);
0218   /// Returns the const object of given index
0219   Track at(std::size_t index) const;
0220   /// Returns the object of given index
0221   MutableTrack at(std::size_t index);
0222 
0223   /// Append object to the collection
0224   void push_back(const MutableTrack& object);
0225   /// Append an object to the (subset) collection
0226   void push_back(const Track& object);
0227 
0228   void prepareForWrite() const final;
0229   void prepareAfterRead() final;
0230   bool setReferences(
0231       const podio::ICollectionProvider* collectionProvider) final;
0232 
0233   /// Get the collection buffers for this collection
0234   podio::CollectionWriteBuffers getBuffers() final;
0235 
0236   void setID(uint32_t ID) final {
0237     m_collectionID = ID;
0238     if (!m_isSubsetColl) {
0239       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0240                     [ID](TrackObj* obj) {
0241                       obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0242                     });
0243     }
0244     m_isValid = true;
0245   }
0246 
0247   uint32_t getID() const final { return m_collectionID; }
0248 
0249   bool isValid() const final { return m_isValid; }
0250 
0251   size_t getDatamodelRegistryIndex() const final;
0252 
0253   // support for the iterator protocol
0254   iterator begin() { return iterator(0, &m_storage.entries); }
0255   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0256   const_iterator cbegin() const { return begin(); }
0257   iterator end() {
0258     return iterator(m_storage.entries.size(), &m_storage.entries);
0259   }
0260   const_iterator end() const {
0261     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0262   }
0263   const_iterator cend() const { return end(); }
0264   // reverse iterators
0265   reverse_iterator rbegin() { return reverse_iterator(end()); }
0266   const_reverse_iterator rbegin() const {
0267     return const_reverse_iterator(end());
0268   }
0269   const_reverse_iterator crbegin() const { return rbegin(); }
0270   reverse_iterator rend() { return reverse_iterator(begin()); }
0271   const_reverse_iterator rend() const {
0272     return const_reverse_iterator(begin());
0273   }
0274   const_reverse_iterator crend() const { return rend(); }
0275 
0276   std::vector<ActsPodioEdm::TrackInfo> data(const size_t nElem = 0) const;
0277   std::vector<ActsPodioEdm::Surface> referenceSurface(
0278       const size_t nElem = 0) const;
0279   std::vector<ActsPodioEdm::ParticleHypothesis> particleHypothesis(
0280       const size_t nElem = 0) const;
0281 
0282  private:
0283   // For setReferences, we need to give our own CollectionData access to our
0284   // private entries. Otherwise we would need to expose a public member function
0285   // that gives access to the Obj* which is definitely not what we want
0286   friend class TrackCollectionData;
0287 
0288   bool m_isValid{false};
0289   mutable bool m_isPrepared{false};
0290   bool m_isSubsetColl{false};
0291   uint32_t m_collectionID{0};
0292   mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0293   mutable TrackCollectionData m_storage{};
0294 };
0295 
0296 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0297 
0298 template <typename... Args>
0299 MutableTrack TrackCollection::create(Args&&... args) {
0300   if (m_isSubsetColl) {
0301     throw std::logic_error("Cannot create new elements on a subset collection");
0302   }
0303   const int size = m_storage.entries.size();
0304   auto obj =
0305       new TrackObj({size, m_collectionID}, {std::forward<Args>(args)...});
0306   m_storage.entries.push_back(obj);
0307 
0308   return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0309 }
0310 
0311 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0312 void to_json(nlohmann::json& j, const TrackCollection& collection);
0313 #endif
0314 
0315 }  // namespace ActsPodioEdm
0316 
0317 #endif