Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-12 09:51:44

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef EDM4HEP_ReconstructedParticleCollection_H
0004 #define EDM4HEP_ReconstructedParticleCollection_H
0005 
0006 // datamodel specific includes
0007 #include "edm4hep/MutableReconstructedParticle.h"
0008 #include "edm4hep/ReconstructedParticle.h"
0009 #include "edm4hep/ReconstructedParticleCollectionData.h"
0010 #include "edm4hep/ReconstructedParticleObj.h"
0011 
0012 // podio specific includes
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015 #include "podio/detail/Pythonizations.h"
0016 
0017 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0018 #include "nlohmann/json_fwd.hpp"
0019 #endif
0020 
0021 #include <algorithm>
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 ReconstructedParticleCollectionIterator {
0036 public:
0037   using value_type = ReconstructedParticle;
0038   using difference_type = ptrdiff_t;
0039   using reference = ReconstructedParticle;
0040   using pointer = ReconstructedParticle*;
0041   using iterator_category = std::input_iterator_tag;
0042   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0043   // remain valid as long as the iterator is valid, not as long as the range is valid.
0044   using iterator_concept = std::random_access_iterator_tag;
0045 
0046   ReconstructedParticleCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer* collection)
0047       : m_index(index), m_object(podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}),
0048         m_collection(collection) {}
0049   ReconstructedParticleCollectionIterator() = default;
0050 
0051   ReconstructedParticleCollectionIterator(const ReconstructedParticleCollectionIterator&) = default;
0052   ReconstructedParticleCollectionIterator(ReconstructedParticleCollectionIterator&&) = default;
0053   ReconstructedParticleCollectionIterator& operator=(const ReconstructedParticleCollectionIterator&) = default;
0054   ReconstructedParticleCollectionIterator& operator=(ReconstructedParticleCollectionIterator&&) = default;
0055   ~ReconstructedParticleCollectionIterator() = default;
0056 
0057   auto operator<=>(const ReconstructedParticleCollectionIterator& other) const { return m_index <=> other.m_index; }
0058 
0059   bool operator==(const ReconstructedParticleCollectionIterator& x) const { return m_index == x.m_index; }
0060 
0061   reference operator*() const;
0062   pointer operator->();
0063   ReconstructedParticleCollectionIterator& operator++();
0064   ReconstructedParticleCollectionIterator operator++(int);
0065   ReconstructedParticleCollectionIterator& operator--();
0066   ReconstructedParticleCollectionIterator operator--(int);
0067   ReconstructedParticleCollectionIterator& operator+=(difference_type n);
0068   ReconstructedParticleCollectionIterator operator+(difference_type n) const;
0069   friend ReconstructedParticleCollectionIterator operator+(difference_type n,
0070                                                            const ReconstructedParticleCollectionIterator& it);
0071   ReconstructedParticleCollectionIterator& operator-=(difference_type n);
0072   ReconstructedParticleCollectionIterator operator-(difference_type n) const;
0073   reference operator[](difference_type n) const;
0074   difference_type operator-(const ReconstructedParticleCollectionIterator& other) const;
0075 
0076 private:
0077   size_t m_index{0};
0078   ReconstructedParticle m_object{podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}};
0079   const ReconstructedParticleObjPointerContainer* m_collection{nullptr};
0080 };
0081 
0082 class ReconstructedParticleMutableCollectionIterator {
0083 public:
0084   using value_type = ReconstructedParticle;
0085   using difference_type = ptrdiff_t;
0086   using reference = MutableReconstructedParticle;
0087   using pointer = MutableReconstructedParticle*;
0088   using iterator_category = std::input_iterator_tag;
0089   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0090   // remain valid as long as the iterator is valid, not as long as the range is valid.
0091   using iterator_concept = std::random_access_iterator_tag;
0092 
0093   ReconstructedParticleMutableCollectionIterator(size_t index,
0094                                                  const ReconstructedParticleObjPointerContainer* collection)
0095       : m_index(index), m_object(podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}),
0096         m_collection(collection) {}
0097   ReconstructedParticleMutableCollectionIterator() = default;
0098 
0099   ReconstructedParticleMutableCollectionIterator(const ReconstructedParticleMutableCollectionIterator&) = default;
0100   ReconstructedParticleMutableCollectionIterator(ReconstructedParticleMutableCollectionIterator&&) = default;
0101   ReconstructedParticleMutableCollectionIterator&
0102   operator=(const ReconstructedParticleMutableCollectionIterator&) = default;
0103   ReconstructedParticleMutableCollectionIterator& operator=(ReconstructedParticleMutableCollectionIterator&&) = default;
0104   ~ReconstructedParticleMutableCollectionIterator() = default;
0105 
0106   auto operator<=>(const ReconstructedParticleMutableCollectionIterator& other) const {
0107     return m_index <=> other.m_index;
0108   }
0109 
0110   bool operator==(const ReconstructedParticleMutableCollectionIterator& x) const { return m_index == x.m_index; }
0111 
0112   reference operator*() const;
0113   pointer operator->();
0114   ReconstructedParticleMutableCollectionIterator& operator++();
0115   ReconstructedParticleMutableCollectionIterator operator++(int);
0116   ReconstructedParticleMutableCollectionIterator& operator--();
0117   ReconstructedParticleMutableCollectionIterator operator--(int);
0118   ReconstructedParticleMutableCollectionIterator& operator+=(difference_type n);
0119   ReconstructedParticleMutableCollectionIterator operator+(difference_type n) const;
0120   friend ReconstructedParticleMutableCollectionIterator
0121   operator+(difference_type n, const ReconstructedParticleMutableCollectionIterator& it);
0122   ReconstructedParticleMutableCollectionIterator& operator-=(difference_type n);
0123   ReconstructedParticleMutableCollectionIterator operator-(difference_type n) const;
0124   reference operator[](difference_type n) const;
0125   difference_type operator-(const ReconstructedParticleMutableCollectionIterator& other) const;
0126 
0127 private:
0128   size_t m_index{0};
0129   MutableReconstructedParticle m_object{podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}};
0130   const ReconstructedParticleObjPointerContainer* m_collection{nullptr};
0131 };
0132 
0133 /**
0134 A Collection is identified by an ID.
0135 */
0136 class ReconstructedParticleCollection : public podio::CollectionBase {
0137 public:
0138   using value_type = ReconstructedParticle;
0139   using mutable_type = MutableReconstructedParticle;
0140   using const_iterator = ReconstructedParticleCollectionIterator;
0141   using iterator = ReconstructedParticleMutableCollectionIterator;
0142   using difference_type = ptrdiff_t;
0143   using size_type = size_t;
0144   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0145   using reverse_iterator = std::reverse_iterator<iterator>;
0146 
0147   ReconstructedParticleCollection() = default;
0148   ReconstructedParticleCollection(ReconstructedParticleCollectionData&& data, bool isSubsetColl);
0149   // This is a move-only type
0150   ReconstructedParticleCollection(const ReconstructedParticleCollection&) = delete;
0151   ReconstructedParticleCollection& operator=(const ReconstructedParticleCollection&) = delete;
0152   ReconstructedParticleCollection(ReconstructedParticleCollection&&) = default;
0153   ReconstructedParticleCollection& operator=(ReconstructedParticleCollection&&) = default;
0154 
0155   //  ReconstructedParticleCollection(ReconstructedParticleVector* data, uint32_t collectionID);
0156   ~ReconstructedParticleCollection() override;
0157 
0158   constexpr static std::string_view typeName = "edm4hep::ReconstructedParticleCollection";
0159   constexpr static std::string_view valueTypeName = "edm4hep::ReconstructedParticle";
0160   constexpr static std::string_view dataTypeName = "edm4hep::ReconstructedParticleData";
0161 
0162   void clear() final;
0163 
0164   /// Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
0165   static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0166     podio::detail::pythonizations::pythonize_subscript(klass, name);
0167   }
0168 
0169   /// Print this collection to the passed stream
0170   void print(std::ostream& os = std::cout, bool flush = true) const final;
0171 
0172   /// Append a new object to the collection, and return this object.
0173   MutableReconstructedParticle create();
0174 
0175   /// Append a new object to the collection, and return this object.
0176   /// Initialized with the parameters given
0177   template <typename... Args>
0178   MutableReconstructedParticle create(Args&&... args);
0179 
0180   /// number of elements in the collection
0181   std::size_t size() const final;
0182 
0183   /// maximal number of elements in the collection
0184   std::size_t max_size() const final;
0185 
0186   /// Is the collection empty
0187   bool empty() const final;
0188 
0189   /// fully qualified type name
0190   const std::string_view getTypeName() const final { return typeName; }
0191   /// fully qualified type name of elements - with namespace
0192   const std::string_view getValueTypeName() const final { return valueTypeName; }
0193   /// fully qualified type name of stored POD elements - with namespace
0194   const std::string_view getDataTypeName() const final { return dataTypeName; }
0195   /// schema version
0196   podio::SchemaVersionT getSchemaVersion() const final;
0197 
0198   bool isSubsetCollection() const final { return m_isSubsetColl; }
0199 
0200   void setSubsetCollection(bool setSubset = true) final;
0201 
0202   /// Returns the const object of given index
0203   ReconstructedParticle operator[](std::size_t index) const;
0204   /// Returns the object of a given index
0205   MutableReconstructedParticle operator[](std::size_t index);
0206   /// Returns the const object of given index
0207   ReconstructedParticle at(std::size_t index) const;
0208   /// Returns the object of given index
0209   MutableReconstructedParticle at(std::size_t index);
0210 
0211   /// Append object to the collection
0212   void push_back(const MutableReconstructedParticle& object);
0213   /// Append an object to the (subset) collection
0214   void push_back(const ReconstructedParticle& object);
0215 
0216   void prepareForWrite() const final;
0217   void prepareAfterRead() final;
0218   bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0219 
0220   /// Get the collection buffers for this collection
0221   podio::CollectionWriteBuffers getBuffers() final;
0222 
0223   void setID(uint32_t ID) final {
0224     m_collectionID = ID;
0225     if (!m_isSubsetColl) {
0226       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0227                     [ID](ReconstructedParticleObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; });
0228     }
0229   }
0230 
0231   uint32_t getID() const final { return m_collectionID; }
0232 
0233   /// check if the collection has a valid ID
0234   bool hasID() const final {
0235     return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0236            getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0237   }
0238 
0239   [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
0240                "collection is valid")]] bool
0241   isValid() const final {
0242     return hasID();
0243   }
0244 
0245   size_t getDatamodelRegistryIndex() const final;
0246 
0247   // support for the iterator protocol
0248   iterator begin() { return iterator(0, &m_storage.entries); }
0249   const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0250   const_iterator cbegin() const { return begin(); }
0251   iterator end() { return iterator(m_storage.entries.size(), &m_storage.entries); }
0252   const_iterator end() const { return const_iterator(m_storage.entries.size(), &m_storage.entries); }
0253   const_iterator cend() const { return end(); }
0254   // reverse iterators
0255   reverse_iterator rbegin() { return reverse_iterator(end()); }
0256   const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
0257   const_reverse_iterator crbegin() const { return rbegin(); }
0258   reverse_iterator rend() { return reverse_iterator(begin()); }
0259   const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
0260   const_reverse_iterator crend() const { return rend(); }
0261 
0262   std::vector<std::int32_t> PDG(const size_t nElem = 0) const;
0263   std::vector<float> energy(const size_t nElem = 0) const;
0264   std::vector<edm4hep::Vector3f> momentum(const size_t nElem = 0) const;
0265   std::vector<edm4hep::Vector3f> referencePoint(const size_t nElem = 0) const;
0266   std::vector<float> charge(const size_t nElem = 0) const;
0267   std::vector<float> mass(const size_t nElem = 0) const;
0268   std::vector<float> goodnessOfPID(const size_t nElem = 0) const;
0269   std::vector<edm4hep::CovMatrix4f> covMatrix(const size_t nElem = 0) const;
0270 
0271 private:
0272   // For setReferences, we need to give our own CollectionData access to our
0273   // private entries. Otherwise we would need to expose a public member function
0274   // that gives access to the Obj* which is definitely not what we want
0275   friend class ReconstructedParticleCollectionData;
0276 
0277   mutable bool m_isPrepared{false};
0278   bool m_isSubsetColl{false};
0279   uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0280   mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0281   mutable ReconstructedParticleCollectionData m_storage{};
0282 };
0283 
0284 std::ostream& operator<<(std::ostream& o, const ReconstructedParticleCollection& v);
0285 
0286 template <typename... Args>
0287 MutableReconstructedParticle ReconstructedParticleCollection::create(Args&&... args) {
0288   if (m_isSubsetColl) {
0289     throw std::logic_error("Cannot create new elements on a subset collection");
0290   }
0291   auto obj = new ReconstructedParticleObj({static_cast<int>(m_storage.entries.size()), m_collectionID},
0292                                           {std::forward<Args>(args)...});
0293   m_storage.entries.push_back(obj);
0294 
0295   // Need to initialize the relation vectors manually for the {ObjectID, ReconstructedParticleData} constructor
0296   obj->m_clusters = new std::vector<edm4hep::Cluster>();
0297   obj->m_tracks = new std::vector<edm4hep::Track>();
0298   obj->m_particles = new std::vector<edm4hep::ReconstructedParticle>();
0299   m_storage.createRelations(obj);
0300   return MutableReconstructedParticle(podio::utils::MaybeSharedPtr(obj));
0301 }
0302 
0303 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0304 void to_json(nlohmann::json& j, const ReconstructedParticleCollection& collection);
0305 #endif
0306 
0307 } // namespace edm4hep
0308 
0309 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0310 // until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
0311 // and https://github.com/AIDASoft/podio/issues/770
0312 #if defined(__clang__)
0313 #pragma clang diagnostic push
0314 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0315 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0316 #pragma clang diagnostic ignored "-Wdeprecated"
0317 constexpr std::string_view edm4hep::ReconstructedParticleCollection::typeName;
0318 constexpr std::string_view edm4hep::ReconstructedParticleCollection::valueTypeName;
0319 constexpr std::string_view edm4hep::ReconstructedParticleCollection::dataTypeName;
0320 #pragma clang diagnostic pop
0321 #elif defined(__GNUC__)
0322 #pragma GCC diagnostic push
0323 #pragma GCC diagnostic ignored "-Wdeprecated"
0324 constexpr std::string_view edm4hep::ReconstructedParticleCollection::typeName;
0325 constexpr std::string_view edm4hep::ReconstructedParticleCollection::valueTypeName;
0326 constexpr std::string_view edm4hep::ReconstructedParticleCollection::dataTypeName;
0327 #pragma GCC diagnostic pop
0328 #endif
0329 
0330 #endif