Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:05

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