Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/JANA/examples/PodioDatamodel/ExampleHitCollection.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
0002 
0003 #ifndef PODIODATAMODEL_ExampleHitCollection_H
0004 #define PODIODATAMODEL_ExampleHitCollection_H
0005 
0006 // datamodel specific includes
0007 #include "PodioDatamodel/ExampleHit.h"
0008 #include "PodioDatamodel/MutableExampleHit.h"
0009 #include "PodioDatamodel/ExampleHitObj.h"
0010 #include "PodioDatamodel/ExampleHitCollectionData.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 
0033 
0034 
0035 class ExampleHitCollectionIterator {
0036 public:
0037   using value_type = ExampleHit;
0038   using difference_type = ptrdiff_t;
0039   using reference = ExampleHit;
0040   using pointer = ExampleHit*;
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   ExampleHitCollectionIterator(size_t index, const ExampleHitObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ExampleHitObj>{nullptr}), m_collection(collection) {}
0047   ExampleHitCollectionIterator() = default;
0048 
0049   ExampleHitCollectionIterator(const ExampleHitCollectionIterator&) = default;
0050   ExampleHitCollectionIterator(ExampleHitCollectionIterator&&) = default;
0051   ExampleHitCollectionIterator& operator=(const ExampleHitCollectionIterator&) = default;
0052   ExampleHitCollectionIterator& operator=(ExampleHitCollectionIterator&&) = default;
0053   ~ExampleHitCollectionIterator() = default;
0054 
0055   auto operator<=>(const ExampleHitCollectionIterator& other) const {
0056     return m_index <=> other.m_index;
0057   }
0058 
0059   bool operator==(const ExampleHitCollectionIterator& x) const {
0060     return m_index ==  x.m_index;
0061   }
0062 
0063   reference operator*() const;
0064   pointer operator->();
0065   ExampleHitCollectionIterator& operator++();
0066   ExampleHitCollectionIterator operator++(int);
0067   ExampleHitCollectionIterator& operator--();
0068   ExampleHitCollectionIterator operator--(int);
0069   ExampleHitCollectionIterator& operator+=(difference_type n);
0070   ExampleHitCollectionIterator operator+(difference_type n) const;
0071   friend ExampleHitCollectionIterator operator+(difference_type n, const ExampleHitCollectionIterator& it);
0072   ExampleHitCollectionIterator& operator-=(difference_type n);
0073   ExampleHitCollectionIterator operator-(difference_type n) const;
0074   reference operator[](difference_type n) const;
0075   difference_type operator-(const ExampleHitCollectionIterator& other) const;
0076 
0077 private:
0078   size_t m_index{0};
0079   ExampleHit m_object { podio::utils::MaybeSharedPtr<ExampleHitObj>{nullptr} };
0080   const ExampleHitObjPointerContainer* m_collection{nullptr};
0081 };
0082 
0083 
0084 class ExampleHitMutableCollectionIterator {
0085 public:
0086   using value_type = ExampleHit;
0087   using difference_type = ptrdiff_t;
0088   using reference = MutableExampleHit;
0089   using pointer = MutableExampleHit*;
0090   using iterator_category = std::input_iterator_tag;
0091   // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
0092   // remain valid as long as the iterator is valid, not as long as the range is valid.
0093   using iterator_concept = std::random_access_iterator_tag;
0094 
0095   ExampleHitMutableCollectionIterator(size_t index, const ExampleHitObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ExampleHitObj>{nullptr}), m_collection(collection) {}
0096   ExampleHitMutableCollectionIterator() = default;
0097 
0098   ExampleHitMutableCollectionIterator(const ExampleHitMutableCollectionIterator&) = default;
0099   ExampleHitMutableCollectionIterator(ExampleHitMutableCollectionIterator&&) = default;
0100   ExampleHitMutableCollectionIterator& operator=(const ExampleHitMutableCollectionIterator&) = default;
0101   ExampleHitMutableCollectionIterator& operator=(ExampleHitMutableCollectionIterator&&) = default;
0102   ~ExampleHitMutableCollectionIterator() = default;
0103 
0104   auto operator<=>(const ExampleHitMutableCollectionIterator& other) const {
0105     return m_index <=> other.m_index;
0106   }
0107 
0108   bool operator==(const ExampleHitMutableCollectionIterator& x) const {
0109     return m_index ==  x.m_index;
0110   }
0111 
0112   reference operator*() const;
0113   pointer operator->();
0114   ExampleHitMutableCollectionIterator& operator++();
0115   ExampleHitMutableCollectionIterator operator++(int);
0116   ExampleHitMutableCollectionIterator& operator--();
0117   ExampleHitMutableCollectionIterator operator--(int);
0118   ExampleHitMutableCollectionIterator& operator+=(difference_type n);
0119   ExampleHitMutableCollectionIterator operator+(difference_type n) const;
0120   friend ExampleHitMutableCollectionIterator operator+(difference_type n, const ExampleHitMutableCollectionIterator& it);
0121   ExampleHitMutableCollectionIterator& operator-=(difference_type n);
0122   ExampleHitMutableCollectionIterator operator-(difference_type n) const;
0123   reference operator[](difference_type n) const;
0124   difference_type operator-(const ExampleHitMutableCollectionIterator& other) const;
0125 
0126 private:
0127   size_t m_index{0};
0128   MutableExampleHit m_object { podio::utils::MaybeSharedPtr<ExampleHitObj>{nullptr} };
0129   const ExampleHitObjPointerContainer* m_collection{nullptr};
0130 };
0131 
0132 
0133 /**
0134 A Collection is identified by an ID.
0135 */
0136 class ExampleHitCollection : public podio::CollectionBase {
0137 public:
0138   using value_type = ExampleHit;
0139   using mutable_type = MutableExampleHit;
0140   using const_iterator = ExampleHitCollectionIterator;
0141   using iterator = ExampleHitMutableCollectionIterator;
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   ExampleHitCollection();
0148   ExampleHitCollection(ExampleHitCollectionData&& data, bool isSubsetColl);
0149   // This is a move-only type
0150   ExampleHitCollection(const ExampleHitCollection& ) = delete;
0151   ExampleHitCollection& operator=(const ExampleHitCollection& ) = delete;
0152   ExampleHitCollection(ExampleHitCollection&&) = default;
0153   ExampleHitCollection& operator=(ExampleHitCollection&&) = default;
0154 
0155 //  ExampleHitCollection(ExampleHitVector* data, uint32_t collectionID);
0156   ~ExampleHitCollection() override;
0157 
0158   constexpr static std::string_view typeName = "ExampleHitCollection";
0159   constexpr static std::string_view valueTypeName = "ExampleHit";
0160   constexpr static std::string_view dataTypeName = "ExampleHitData";
0161 
0162   void clear() final;
0163 
0164   /// Print this collection to the passed stream
0165   void print(std::ostream& os=std::cout, bool flush=true) const final;
0166 
0167   /// operator to allow pointer like calling of members a la LCIO
0168   ExampleHitCollection* operator->() { return static_cast<ExampleHitCollection*>(this); }
0169 
0170   /// Append a new object to the collection, and return this object.
0171   MutableExampleHit create();
0172 
0173   /// Append a new object to the collection, and return this object.
0174   /// Initialized with the parameters given
0175   template<typename... Args>
0176   MutableExampleHit create(Args&&... args);
0177 
0178   /// number of elements in the collection
0179   std::size_t size() const final;
0180 
0181   /// maximal number of elements in the collection
0182   std::size_t max_size() const final;
0183 
0184   /// Is the collection empty
0185   bool empty() const final;
0186 
0187   /// fully qualified type name
0188   const std::string_view getTypeName() const final { return typeName; }
0189   /// fully qualified type name of elements - with namespace
0190   const std::string_view getValueTypeName() const final { return valueTypeName; }
0191   /// fully qualified type name of stored POD elements - with namespace
0192   const std::string_view getDataTypeName() const final { return dataTypeName; }
0193   /// schema version
0194   podio::SchemaVersionT getSchemaVersion() const final;
0195 
0196   bool isSubsetCollection() const final {
0197     return m_isSubsetColl;
0198   }
0199 
0200   void setSubsetCollection(bool setSubset=true) final;
0201 
0202   /// Returns the const object of given index
0203   ExampleHit operator[](std::size_t index) const;
0204   /// Returns the object of a given index
0205   MutableExampleHit operator[](std::size_t index);
0206   /// Returns the const object of given index
0207   ExampleHit at(std::size_t index) const;
0208   /// Returns the object of given index
0209   MutableExampleHit at(std::size_t index);
0210 
0211 
0212   /// Append object to the collection
0213   void push_back(const MutableExampleHit& object);
0214   /// Append an object to the (subset) collection
0215   void push_back(const ExampleHit& object);
0216 
0217   void prepareForWrite() const final;
0218   void prepareAfterRead() final;
0219   bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0220 
0221   /// Get the collection buffers for this collection
0222   podio::CollectionWriteBuffers getBuffers() final;
0223 
0224   void setID(uint32_t ID) final {
0225     m_collectionID = ID;
0226     if (!m_isSubsetColl) {
0227       std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0228                   [ID] (ExampleHitObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
0229       );
0230     }
0231     m_isValid = true;
0232   }
0233 
0234   uint32_t getID() const final {
0235     return m_collectionID;
0236   }
0237 
0238   bool isValid() const final {
0239     return m_isValid;
0240   }
0241 
0242   size_t getDatamodelRegistryIndex() const final;
0243 
0244   // support for the iterator protocol
0245   iterator begin() {
0246     return iterator(0, &m_storage.entries);
0247   }
0248   const_iterator begin() const {
0249     return const_iterator(0, &m_storage.entries);
0250   }
0251   const_iterator cbegin() const {
0252     return begin();
0253   }
0254   iterator end() {
0255     return iterator(m_storage.entries.size(), &m_storage.entries);
0256   }
0257   const_iterator end() const {
0258     return const_iterator(m_storage.entries.size(), &m_storage.entries);
0259   }
0260   const_iterator cend() const {
0261     return end();
0262   }
0263   // reverse iterators
0264   reverse_iterator rbegin() {
0265     return reverse_iterator(end());
0266   }
0267   const_reverse_iterator rbegin() const {
0268     return const_reverse_iterator(end());
0269   }
0270   const_reverse_iterator crbegin() const {
0271     return rbegin();
0272   }
0273   reverse_iterator rend() {
0274     return reverse_iterator(begin());
0275   }
0276   const_reverse_iterator rend() const {
0277     return const_reverse_iterator(begin());
0278   }
0279   const_reverse_iterator crend() const {
0280     return rend();
0281   }
0282 
0283 
0284   std::vector<std::uint64_t> cellID(const size_t nElem = 0) const;
0285   std::vector<double> x(const size_t nElem = 0) const;
0286   std::vector<double> y(const size_t nElem = 0) const;
0287   std::vector<double> z(const size_t nElem = 0) const;
0288   std::vector<double> energy(const size_t nElem = 0) const;
0289   std::vector<std::uint64_t> time(const size_t nElem = 0) const;
0290 
0291 private:
0292   // For setReferences, we need to give our own CollectionData access to our
0293   // private entries. Otherwise we would need to expose a public member function
0294   // that gives access to the Obj* which is definitely not what we want
0295   friend class ExampleHitCollectionData;
0296 
0297   bool m_isValid{false};
0298   mutable bool m_isPrepared{false};
0299   bool m_isSubsetColl{false};
0300   uint32_t m_collectionID{0};
0301   mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0302   mutable ExampleHitCollectionData m_storage{};
0303 };
0304 
0305 std::ostream& operator<<(std::ostream& o, const ExampleHitCollection& v);
0306 
0307 template<typename... Args>
0308 MutableExampleHit ExampleHitCollection::create(Args&&... args) {
0309   if (m_isSubsetColl) {
0310     throw std::logic_error("Cannot create new elements on a subset collection");
0311   }
0312   const int size = m_storage.entries.size();
0313   auto obj = new ExampleHitObj({size, m_collectionID}, {std::forward<Args>(args)...});
0314   m_storage.entries.push_back(obj);
0315 
0316   return MutableExampleHit(podio::utils::MaybeSharedPtr(obj));
0317 }
0318 
0319 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0320 void to_json(nlohmann::json& j, const ExampleHitCollection& collection);
0321 #endif
0322 
0323 
0324 
0325 #endif