Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:52:29

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