Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:55:28

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