Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:35

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