Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-20 10:16:11

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef EDM4EIC_ProtoClusterCollection_H
0004 #define EDM4EIC_ProtoClusterCollection_H
0005 
0006 // datamodel specific includes
0007 #include "edm4eic/ProtoCluster.h"
0008 #include "edm4eic/MutableProtoCluster.h"
0009 #include "edm4eic/ProtoClusterObj.h"
0010 #include "edm4eic/ProtoClusterCollectionData.h"
0011 
0012 // podio specific includes
0013 #include "podio/ICollectionProvider.h"
0014 #include "podio/CollectionBase.h"
0015 #include "podio/detail/Pythonizations.h"
0016 #include "podio/utilities/TypeHelpers.h"
0017 
0018 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0019 #include "nlohmann/json_fwd.hpp"
0020 #endif
0021 
0022 #include <string_view>
0023 #include <vector>
0024 #include <algorithm>
0025 #include <ostream>
0026 #include <mutex>
0027 #include <memory>
0028 #include <cstddef>
0029 
0030 namespace podio {
0031   struct RelationNames;
0032 }
0033 
0034 namespace edm4eic {
0035 
0036 
0037 
0038 class ProtoClusterCollectionIterator {
0039 public:
0040   using value_type = ProtoCluster;
0041   using difference_type = ptrdiff_t;
0042   using reference = ProtoCluster;
0043   using pointer = ProtoCluster*;
0044   using iterator_category = std::input_iterator_tag;
0045   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0046   // remain valid as long as the iterator is valid, not as long as the range is valid.
0047   using iterator_concept = std::random_access_iterator_tag;
0048 
0049   ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr}), m_collection(collection) {}
0050   ProtoClusterCollectionIterator() = default;
0051 
0052   ProtoClusterCollectionIterator(const ProtoClusterCollectionIterator&) = default;
0053   ProtoClusterCollectionIterator(ProtoClusterCollectionIterator&&) = default;
0054   ProtoClusterCollectionIterator& operator=(const ProtoClusterCollectionIterator&) = default;
0055   ProtoClusterCollectionIterator& operator=(ProtoClusterCollectionIterator&&) = default;
0056   ~ProtoClusterCollectionIterator() = default;
0057 
0058   constexpr auto operator<=>(const ProtoClusterCollectionIterator& other) const {
0059     return m_index <=> other.m_index;
0060   }
0061 
0062   constexpr bool operator==(const ProtoClusterCollectionIterator& x) const {
0063     return m_index ==  x.m_index;
0064   }
0065 
0066   reference operator*() const;
0067   pointer operator->();
0068   ProtoClusterCollectionIterator& operator++();
0069   ProtoClusterCollectionIterator operator++(int);
0070   ProtoClusterCollectionIterator& operator--();
0071   ProtoClusterCollectionIterator operator--(int);
0072   ProtoClusterCollectionIterator& operator+=(difference_type n);
0073   ProtoClusterCollectionIterator operator+(difference_type n) const;
0074   friend ProtoClusterCollectionIterator operator+(difference_type n, const ProtoClusterCollectionIterator& it);
0075   ProtoClusterCollectionIterator& operator-=(difference_type n);
0076   ProtoClusterCollectionIterator operator-(difference_type n) const;
0077   reference operator[](difference_type n) const;
0078   difference_type operator-(const ProtoClusterCollectionIterator& other) const;
0079 
0080 private:
0081   size_t m_index{0};
0082   ProtoCluster m_object { podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr} };
0083   const ProtoClusterObjPointerContainer* m_collection{nullptr};
0084 };
0085 
0086 
0087 class ProtoClusterMutableCollectionIterator {
0088 public:
0089   using value_type = ProtoCluster;
0090   using difference_type = ptrdiff_t;
0091   using reference = MutableProtoCluster;
0092   using pointer = MutableProtoCluster*;
0093   using iterator_category = std::input_iterator_tag;
0094   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0095   // remain valid as long as the iterator is valid, not as long as the range is valid.
0096   using iterator_concept = std::random_access_iterator_tag;
0097 
0098   ProtoClusterMutableCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr}), m_collection(collection) {}
0099   ProtoClusterMutableCollectionIterator() = default;
0100 
0101   ProtoClusterMutableCollectionIterator(const ProtoClusterMutableCollectionIterator&) = default;
0102   ProtoClusterMutableCollectionIterator(ProtoClusterMutableCollectionIterator&&) = default;
0103   ProtoClusterMutableCollectionIterator& operator=(const ProtoClusterMutableCollectionIterator&) = default;
0104   ProtoClusterMutableCollectionIterator& operator=(ProtoClusterMutableCollectionIterator&&) = default;
0105   ~ProtoClusterMutableCollectionIterator() = default;
0106 
0107   constexpr auto operator<=>(const ProtoClusterMutableCollectionIterator& other) const {
0108     return m_index <=> other.m_index;
0109   }
0110 
0111   constexpr bool operator==(const ProtoClusterMutableCollectionIterator& x) const {
0112     return m_index ==  x.m_index;
0113   }
0114 
0115   reference operator*() const;
0116   pointer operator->();
0117   ProtoClusterMutableCollectionIterator& operator++();
0118   ProtoClusterMutableCollectionIterator operator++(int);
0119   ProtoClusterMutableCollectionIterator& operator--();
0120   ProtoClusterMutableCollectionIterator operator--(int);
0121   ProtoClusterMutableCollectionIterator& operator+=(difference_type n);
0122   ProtoClusterMutableCollectionIterator operator+(difference_type n) const;
0123   friend ProtoClusterMutableCollectionIterator operator+(difference_type n, const ProtoClusterMutableCollectionIterator& it);
0124   ProtoClusterMutableCollectionIterator& operator-=(difference_type n);
0125   ProtoClusterMutableCollectionIterator operator-(difference_type n) const;
0126   reference operator[](difference_type n) const;
0127   difference_type operator-(const ProtoClusterMutableCollectionIterator& other) const;
0128 
0129 private:
0130   size_t m_index{0};
0131   MutableProtoCluster m_object { podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr} };
0132   const ProtoClusterObjPointerContainer* m_collection{nullptr};
0133 };
0134 
0135 
0136 /**
0137 A Collection is identified by an ID.
0138 */
0139 class ProtoClusterCollection : public podio::CollectionBase {
0140 public:
0141   using value_type = ProtoCluster;
0142   using mutable_type = MutableProtoCluster;
0143   using const_iterator = ProtoClusterCollectionIterator;
0144   using iterator = ProtoClusterMutableCollectionIterator;
0145   using difference_type = ptrdiff_t;
0146   using size_type = size_t;
0147   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0148   using reverse_iterator = std::reverse_iterator<iterator>;
0149 
0150   ProtoClusterCollection() = default;
0151   ProtoClusterCollection(ProtoClusterCollectionData&& data, bool isSubsetColl);
0152   // This is a move-only type
0153   ProtoClusterCollection(const ProtoClusterCollection& ) = delete;
0154   ProtoClusterCollection& operator=(const ProtoClusterCollection& ) = delete;
0155   ProtoClusterCollection(ProtoClusterCollection&&) = default;
0156   ProtoClusterCollection& operator=(ProtoClusterCollection&&) = default;
0157 
0158   ~ProtoClusterCollection() override;
0159 #if defined(__cpp_lib_containers_ranges)
0160   template<podio::detail::RangeConvertibleTo<value_type> R>
0161   ProtoClusterCollection(std::from_range_t, R&& range);
0162 #endif
0163 
0164   /// Construct a ProtoCluster collection from a range of mutable or
0165   /// immutable handles
0166   template<podio::detail::RangeConvertibleTo<value_type> R>
0167   static ProtoClusterCollection from(R&& range);
0168 
0169   constexpr static std::string_view typeName = "edm4eic::ProtoClusterCollection";
0170   constexpr static std::string_view valueTypeName = "edm4eic::ProtoCluster";
0171   constexpr static std::string_view dataTypeName = "edm4eic::ProtoClusterData";
0172 
0173   /// Invalidates all iterators.
0174   void clear() final;
0175 
0176   /// Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
0177   static void __cppjit_pythonize__(PyObject* klass, const std::string& name) {
0178           podio::detail::pythonizations::pythonize_subscript(klass, name);
0179   }
0180   /// Pythonizations for ROOT <= 6.40 before the switch to cppjit
0181   static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0182         __cppjit_pythonize__(klass, name);
0183   }
0184 
0185   /// Print this collection to the passed stream
0186   void print(std::ostream& os=std::cout, bool flush=true) const final;
0187 
0188   /// Append a new object to the collection, and return this object.
0189   /// Does not invalidate iterators.
0190   MutableProtoCluster create();
0191 
0192   /// Append a new object to the collection, and return this object.
0193   /// Initialized with the parameters given.
0194   /// Does not invalidate iterators.
0195   template<typename... Args>
0196   MutableProtoCluster create(Args&&... args);
0197 
0198   /// number of elements in the collection
0199   std::size_t size() const final;
0200 
0201   /// maximal number of elements in the collection
0202   std::size_t max_size() const final;
0203 
0204   /// Is the collection empty
0205   bool empty() const final;
0206 
0207   /// fully qualified type name
0208   const std::string_view getTypeName() const final { return typeName; }
0209   /// fully qualified type name of elements - with namespace
0210   const std::string_view getValueTypeName() const final { return valueTypeName; }
0211   /// fully qualified type name of stored POD elements - with namespace
0212   const std::string_view getDataTypeName() const final { return dataTypeName; }
0213   /// schema version
0214   podio::SchemaVersionT getSchemaVersion() const final;
0215 
0216   bool isSubsetCollection() const final {
0217     return m_isSubsetColl;
0218   }
0219 
0220   void setSubsetCollection(bool setSubset=true) final;
0221 
0222   /// Returns the const object of given index
0223   ProtoCluster operator[](std::size_t index) const;
0224   /// Returns the object of a given index
0225   MutableProtoCluster operator[](std::size_t index);
0226   /// Returns the const object of given index
0227   ProtoCluster at(std::size_t index) const;
0228   /// Returns the object of given index
0229   MutableProtoCluster at(std::size_t index);
0230 
0231 
0232   /// Append object to the collection.
0233   /// Does not invalidate iterators.
0234   void push_back(const MutableProtoCluster& object);
0235   /// Append an object to the (subset) collection.
0236   /// Does not invalidate iterators.
0237   void push_back(const ProtoCluster& object);
0238 
0239   void prepareForWrite() const final;
0240   void prepareAfterRead() final;
0241   bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0242 
0243   /// Get the collection buffers for this collection
0244   podio::CollectionWriteBuffers getBuffers() final;
0245 
0246   void setID(uint32_t ID) final {
0247     m_collectionID = ID;
0248     if (!m_isSubsetColl) {
0249       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0250                   [ID] (ProtoClusterObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
0251       );
0252     }
0253   }
0254 
0255   uint32_t getID() const final {
0256     return m_collectionID;
0257   }
0258 
0259   /// check if the collection has a valid ID
0260   bool hasID() const final {
0261     return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0262         getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0263   }
0264 
0265   size_t getDatamodelRegistryIndex() const final;
0266 
0267   // support for the iterator protocol
0268   iterator begin() {
0269     return iterator(0, &m_storage.entries);
0270   }
0271   const_iterator begin() const {
0272     return const_iterator(0, &m_storage.entries);
0273   }
0274   const_iterator cbegin() const {
0275     return begin();
0276   }
0277   iterator end() {
0278     return iterator(m_storage.entries.size(), &m_storage.entries);
0279   }
0280   const_iterator end() const {
0281     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0282   }
0283   const_iterator cend() const {
0284     return end();
0285   }
0286   // reverse iterators
0287   reverse_iterator rbegin() {
0288     return reverse_iterator(end());
0289   }
0290   const_reverse_iterator rbegin() const {
0291     return const_reverse_iterator(end());
0292   }
0293   const_reverse_iterator crbegin() const {
0294     return rbegin();
0295   }
0296   reverse_iterator rend() {
0297     return reverse_iterator(begin());
0298   }
0299   const_reverse_iterator rend() const {
0300     return const_reverse_iterator(begin());
0301   }
0302   const_reverse_iterator crend() const {
0303     return rend();
0304   }
0305 
0306 
0307 
0308 private:
0309   // For setReferences, we need to give our own CollectionData access to our
0310   // private entries. Otherwise we would need to expose a public member function
0311   // that gives access to the Obj* which is definitely not what we want
0312   friend class ProtoClusterCollectionData;
0313 
0314   mutable bool m_isPrepared{false};
0315   bool m_isSubsetColl{false};
0316   uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0317   mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0318   mutable ProtoClusterCollectionData m_storage{};
0319 };
0320 
0321 std::ostream& operator<<(std::ostream& o, const ProtoClusterCollection& v);
0322 
0323 template<typename... Args>
0324 MutableProtoCluster ProtoClusterCollection::create(Args&&... args) {
0325   if (m_isSubsetColl) {
0326     throw std::logic_error("Cannot create new elements on a subset collection");
0327   }
0328   auto obj = new ProtoClusterObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0329   m_storage.entries.push_back(obj);
0330 
0331   // Need to initialize the relation vectors manually for the {ObjectID, ProtoClusterData} constructor
0332   obj->m_hits = new std::vector<edm4eic::CalorimeterHit>();
0333   obj->m_weights = new std::vector<float>();
0334   m_storage.createRelations(obj);
0335   return MutableProtoCluster(podio::utils::MaybeSharedPtr(obj));
0336 }
0337 
0338 
0339 #if defined(__cpp_lib_containers_ranges)
0340 template<podio::detail::RangeConvertibleTo<ProtoClusterCollection::value_type> R>
0341 ProtoClusterCollection::ProtoClusterCollection(std::from_range_t, R&& range)
0342   : ProtoClusterCollection() {
0343   setSubsetCollection(podio::detail::RangeOf<R, value_type>);
0344 
0345   for (auto&& elem : range) {
0346     push_back(std::forward<decltype(elem)>(elem));
0347   }
0348 }
0349 #endif
0350 
0351 template<podio::detail::RangeConvertibleTo<ProtoClusterCollection::value_type> R>
0352 ProtoClusterCollection ProtoClusterCollection::from(R&& range) {
0353   ProtoClusterCollection coll;
0354   if constexpr (podio::detail::RangeOf<R, value_type>) {
0355     coll.setSubsetCollection();
0356   }
0357 
0358   for (auto&& elem : range) {
0359     coll.push_back(std::forward<decltype(elem)>(elem));
0360   }
0361 
0362   return coll;
0363 }
0364 
0365 
0366 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0367 void to_json(nlohmann::json& j, const ProtoClusterCollection& collection);
0368 #endif
0369 
0370 } // namespace edm4eic
0371 
0372 
0373 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0374 // until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
0375 // and https://github.com/AIDASoft/podio/issues/770
0376 #if defined(__clang__)
0377   #pragma clang diagnostic push
0378   #pragma clang diagnostic ignored "-Wunknown-warning-option"
0379   #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0380   #pragma clang diagnostic ignored "-Wdeprecated"
0381 constexpr std::string_view edm4eic::ProtoClusterCollection::typeName;
0382 constexpr std::string_view edm4eic::ProtoClusterCollection::valueTypeName;
0383 constexpr std::string_view edm4eic::ProtoClusterCollection::dataTypeName;
0384   #pragma clang diagnostic pop
0385 #elif defined(__GNUC__)
0386   #pragma GCC diagnostic push
0387   #pragma GCC diagnostic ignored "-Wdeprecated"
0388 constexpr std::string_view edm4eic::ProtoClusterCollection::typeName;
0389 constexpr std::string_view edm4eic::ProtoClusterCollection::valueTypeName;
0390 constexpr std::string_view edm4eic::ProtoClusterCollection::dataTypeName;
0391   #pragma GCC diagnostic pop
0392 #endif
0393 
0394 
0395 #endif