Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-11 10:20:47

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