Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-03 08:07:28

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   TrackCollectionIterator(size_t index,
0037                           const TrackObjPointerContainer* collection)
0038       : m_index(index),
0039         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0040         m_collection(collection) {}
0041 
0042   TrackCollectionIterator(const TrackCollectionIterator&) = delete;
0043   TrackCollectionIterator& operator=(const TrackCollectionIterator&) = delete;
0044 
0045   bool operator!=(const TrackCollectionIterator& x) const {
0046     return m_index != x.m_index;  // TODO: may not be complete
0047   }
0048 
0049   bool operator==(const TrackCollectionIterator& x) const {
0050     return m_index == x.m_index;  // TODO: may not be complete
0051   }
0052 
0053   Track operator*();
0054   Track* operator->();
0055   TrackCollectionIterator& operator++();
0056 
0057  private:
0058   size_t m_index;
0059   Track m_object;
0060   const TrackObjPointerContainer* m_collection;
0061 };
0062 
0063 class TrackMutableCollectionIterator {
0064  public:
0065   TrackMutableCollectionIterator(size_t index,
0066                                  const TrackObjPointerContainer* collection)
0067       : m_index(index),
0068         m_object(podio::utils::MaybeSharedPtr<TrackObj>{nullptr}),
0069         m_collection(collection) {}
0070 
0071   TrackMutableCollectionIterator(const TrackMutableCollectionIterator&) =
0072       delete;
0073   TrackMutableCollectionIterator& operator=(
0074       const TrackMutableCollectionIterator&) = delete;
0075 
0076   bool operator!=(const TrackMutableCollectionIterator& x) const {
0077     return m_index != x.m_index;  // TODO: may not be complete
0078   }
0079 
0080   bool operator==(const TrackMutableCollectionIterator& x) const {
0081     return m_index == x.m_index;  // TODO: may not be complete
0082   }
0083 
0084   MutableTrack operator*();
0085   MutableTrack* operator->();
0086   TrackMutableCollectionIterator& operator++();
0087 
0088  private:
0089   size_t m_index;
0090   MutableTrack m_object;
0091   const TrackObjPointerContainer* m_collection;
0092 };
0093 
0094 /**
0095 A Collection is identified by an ID.
0096 */
0097 class TrackCollection : public podio::CollectionBase {
0098  public:
0099   using value_type = Track;
0100   using const_iterator = TrackCollectionIterator;
0101   using iterator = TrackMutableCollectionIterator;
0102   using difference_type = ptrdiff_t;
0103   using size_type = size_t;
0104 
0105   TrackCollection();
0106   TrackCollection(TrackCollectionData&& data, bool isSubsetColl);
0107   // This is a move-only type
0108   TrackCollection(const TrackCollection&) = delete;
0109   TrackCollection& operator=(const TrackCollection&) = delete;
0110   TrackCollection(TrackCollection&&) = default;
0111   TrackCollection& operator=(TrackCollection&&) = default;
0112 
0113   //  TrackCollection(TrackVector* data, uint32_t collectionID);
0114   ~TrackCollection() override;
0115 
0116   constexpr static auto typeName = "ActsPodioEdm::TrackCollection";
0117   constexpr static auto valueTypeName = "ActsPodioEdm::Track";
0118   constexpr static auto dataTypeName = "ActsPodioEdm::TrackData";
0119 
0120   void clear() final;
0121 
0122   /// Print this collection to the passed stream
0123   void print(std::ostream& os = std::cout, bool flush = true) const final;
0124 
0125   /// operator to allow pointer like calling of members a la LCIO
0126   TrackCollection* operator->() { return static_cast<TrackCollection*>(this); }
0127 
0128   /// Append a new object to the collection, and return this object.
0129   MutableTrack create();
0130 
0131   /// Append a new object to the collection, and return this object.
0132   /// Initialized with the parameters given
0133   template <typename... Args>
0134   MutableTrack create(Args&&... args);
0135 
0136   /// number of elements in the collection
0137   std::size_t size() const final;
0138 
0139   /// maximal number of elements in the collection
0140   std::size_t max_size() const final;
0141 
0142   /// Is the collection empty
0143   bool empty() const final;
0144 
0145   /// fully qualified type name
0146   const std::string_view getTypeName() const final { return typeName; }
0147   /// fully qualified type name of elements - with namespace
0148   const std::string_view getValueTypeName() const final {
0149     return valueTypeName;
0150   }
0151   /// fully qualified type name of stored POD elements - with namespace
0152   const std::string_view getDataTypeName() const final { return dataTypeName; }
0153   /// schema version
0154   podio::SchemaVersionT getSchemaVersion() const final;
0155 
0156   bool isSubsetCollection() const final { return m_isSubsetColl; }
0157 
0158   void setSubsetCollection(bool setSubset = true) final;
0159 
0160   /// Returns the const object of given index
0161   Track operator[](std::size_t index) const;
0162   /// Returns the object of a given index
0163   MutableTrack operator[](std::size_t index);
0164   /// Returns the const object of given index
0165   Track at(std::size_t index) const;
0166   /// Returns the object of given index
0167   MutableTrack at(std::size_t index);
0168 
0169   /// Append object to the collection
0170   void push_back(const MutableTrack& object);
0171   /// Append an object to the (subset) collection
0172   void push_back(const Track& object);
0173 
0174   void prepareForWrite() const final;
0175   void prepareAfterRead() final;
0176   bool setReferences(
0177       const podio::ICollectionProvider* collectionProvider) final;
0178 
0179   /// Get the collection buffers for this collection
0180   podio::CollectionWriteBuffers getBuffers() final;
0181 
0182   void setID(uint32_t ID) final {
0183     m_collectionID = ID;
0184     if (!m_isSubsetColl) {
0185       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0186                     [ID](TrackObj* obj) {
0187                       obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0188                     });
0189     }
0190     m_isValid = true;
0191   }
0192 
0193   uint32_t getID() const final { return m_collectionID; }
0194 
0195   bool isValid() const final { return m_isValid; }
0196 
0197   size_t getDatamodelRegistryIndex() const final;
0198 
0199   // support for the iterator protocol
0200   iterator begin() { return iterator(0, &m_storage.entries); }
0201   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0202   const_iterator cbegin() const { return begin(); }
0203   iterator end() {
0204     return iterator(m_storage.entries.size(), &m_storage.entries);
0205   }
0206   const_iterator end() const {
0207     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0208   }
0209   const_iterator cend() const { return end(); }
0210 
0211   std::vector<ActsPodioEdm::TrackInfo> data(const size_t nElem = 0) const;
0212   std::vector<ActsPodioEdm::Surface> referenceSurface(
0213       const size_t nElem = 0) const;
0214   std::vector<ActsPodioEdm::ParticleHypothesis> particleHypothesis(
0215       const size_t nElem = 0) const;
0216 
0217  private:
0218   // For setReferences, we need to give our own CollectionData access to our
0219   // private entries. Otherwise we would need to expose a public member function
0220   // that gives access to the Obj* which is definitely not what we want
0221   friend class TrackCollectionData;
0222 
0223   bool m_isValid{false};
0224   mutable bool m_isPrepared{false};
0225   bool m_isSubsetColl{false};
0226   uint32_t m_collectionID{0};
0227   mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0228   mutable TrackCollectionData m_storage{};
0229 };
0230 
0231 std::ostream& operator<<(std::ostream& o, const TrackCollection& v);
0232 
0233 template <typename... Args>
0234 MutableTrack TrackCollection::create(Args&&... args) {
0235   if (m_isSubsetColl) {
0236     throw std::logic_error("Cannot create new elements on a subset collection");
0237   }
0238   const int size = m_storage.entries.size();
0239   auto obj =
0240       new TrackObj({size, m_collectionID}, {std::forward<Args>(args)...});
0241   m_storage.entries.push_back(obj);
0242 
0243   return MutableTrack(podio::utils::MaybeSharedPtr(obj));
0244 }
0245 
0246 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0247 void to_json(nlohmann::json& j, const TrackCollection& collection);
0248 #endif
0249 
0250 }  // namespace ActsPodioEdm
0251 
0252 #endif