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