File indexing completed on 2025-01-18 09:55:35
0001
0002
0003 #ifndef EDM4HEP_MCRecoCaloAssociationCollection_H
0004 #define EDM4HEP_MCRecoCaloAssociationCollection_H
0005
0006
0007 #include "edm4hep/MCRecoCaloAssociation.h"
0008 #include "edm4hep/MCRecoCaloAssociationCollectionData.h"
0009 #include "edm4hep/MCRecoCaloAssociationObj.h"
0010 #include "edm4hep/MutableMCRecoCaloAssociation.h"
0011
0012
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.h"
0015
0016 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0017 #include "nlohmann/json_fwd.hpp"
0018 #endif
0019
0020 #include <algorithm>
0021 #include <array>
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 MCRecoCaloAssociationCollectionIterator {
0036 public:
0037 MCRecoCaloAssociationCollectionIterator(size_t index, const MCRecoCaloAssociationObjPointerContainer* collection) :
0038 m_index(index),
0039 m_object(podio::utils::MaybeSharedPtr<MCRecoCaloAssociationObj>{nullptr}),
0040 m_collection(collection) {
0041 }
0042
0043 MCRecoCaloAssociationCollectionIterator(const MCRecoCaloAssociationCollectionIterator&) = delete;
0044 MCRecoCaloAssociationCollectionIterator& operator=(const MCRecoCaloAssociationCollectionIterator&) = delete;
0045
0046 bool operator!=(const MCRecoCaloAssociationCollectionIterator& x) const {
0047 return m_index != x.m_index;
0048 }
0049
0050 bool operator==(const MCRecoCaloAssociationCollectionIterator& x) const {
0051 return m_index == x.m_index;
0052 }
0053
0054 MCRecoCaloAssociation operator*();
0055 MCRecoCaloAssociation* operator->();
0056 MCRecoCaloAssociationCollectionIterator& operator++();
0057
0058 private:
0059 size_t m_index;
0060 MCRecoCaloAssociation m_object;
0061 const MCRecoCaloAssociationObjPointerContainer* m_collection;
0062 };
0063
0064 class MCRecoCaloAssociationMutableCollectionIterator {
0065 public:
0066 MCRecoCaloAssociationMutableCollectionIterator(size_t index,
0067 const MCRecoCaloAssociationObjPointerContainer* collection) :
0068 m_index(index),
0069 m_object(podio::utils::MaybeSharedPtr<MCRecoCaloAssociationObj>{nullptr}),
0070 m_collection(collection) {
0071 }
0072
0073 MCRecoCaloAssociationMutableCollectionIterator(const MCRecoCaloAssociationMutableCollectionIterator&) = delete;
0074 MCRecoCaloAssociationMutableCollectionIterator&
0075 operator=(const MCRecoCaloAssociationMutableCollectionIterator&) = delete;
0076
0077 bool operator!=(const MCRecoCaloAssociationMutableCollectionIterator& x) const {
0078 return m_index != x.m_index;
0079 }
0080
0081 bool operator==(const MCRecoCaloAssociationMutableCollectionIterator& x) const {
0082 return m_index == x.m_index;
0083 }
0084
0085 MutableMCRecoCaloAssociation operator*();
0086 MutableMCRecoCaloAssociation* operator->();
0087 MCRecoCaloAssociationMutableCollectionIterator& operator++();
0088
0089 private:
0090 size_t m_index;
0091 MutableMCRecoCaloAssociation m_object;
0092 const MCRecoCaloAssociationObjPointerContainer* m_collection;
0093 };
0094
0095
0096
0097
0098 class MCRecoCaloAssociationCollection : public podio::CollectionBase {
0099 public:
0100 using value_type = MCRecoCaloAssociation;
0101 using const_iterator = MCRecoCaloAssociationCollectionIterator;
0102 using iterator = MCRecoCaloAssociationMutableCollectionIterator;
0103 using difference_type = ptrdiff_t;
0104 using size_type = size_t;
0105
0106 MCRecoCaloAssociationCollection();
0107 MCRecoCaloAssociationCollection(MCRecoCaloAssociationCollectionData&& data, bool isSubsetColl);
0108
0109 MCRecoCaloAssociationCollection(const MCRecoCaloAssociationCollection&) = delete;
0110 MCRecoCaloAssociationCollection& operator=(const MCRecoCaloAssociationCollection&) = delete;
0111 MCRecoCaloAssociationCollection(MCRecoCaloAssociationCollection&&) = default;
0112 MCRecoCaloAssociationCollection& operator=(MCRecoCaloAssociationCollection&&) = default;
0113
0114
0115 ~MCRecoCaloAssociationCollection();
0116
0117 constexpr static auto typeName = "edm4hep::MCRecoCaloAssociationCollection";
0118 constexpr static auto valueTypeName = "edm4hep::MCRecoCaloAssociation";
0119 constexpr static auto dataTypeName = "edm4hep::MCRecoCaloAssociationData";
0120
0121 void clear() final;
0122
0123
0124 void print(std::ostream& os = std::cout, bool flush = true) const final;
0125
0126
0127 MCRecoCaloAssociationCollection* operator->() {
0128 return static_cast<MCRecoCaloAssociationCollection*>(this);
0129 }
0130
0131
0132 MutableMCRecoCaloAssociation create();
0133
0134
0135
0136 template <typename... Args>
0137 MutableMCRecoCaloAssociation create(Args&&... args);
0138
0139
0140 std::size_t size() const final;
0141
0142
0143 std::size_t max_size() const final;
0144
0145
0146 bool empty() const final;
0147
0148
0149 const std::string_view getTypeName() const final {
0150 return typeName;
0151 }
0152
0153 const std::string_view getValueTypeName() const final {
0154 return valueTypeName;
0155 }
0156
0157 const std::string_view getDataTypeName() const final {
0158 return dataTypeName;
0159 }
0160
0161 podio::SchemaVersionT getSchemaVersion() const final;
0162
0163 bool isSubsetCollection() const final {
0164 return m_isSubsetColl;
0165 }
0166
0167 void setSubsetCollection(bool setSubset = true) final;
0168
0169
0170 MCRecoCaloAssociation operator[](std::size_t index) const;
0171
0172 MutableMCRecoCaloAssociation operator[](std::size_t index);
0173
0174 MCRecoCaloAssociation at(std::size_t index) const;
0175
0176 MutableMCRecoCaloAssociation at(std::size_t index);
0177
0178
0179 void push_back(const MutableMCRecoCaloAssociation& object);
0180
0181 void push_back(const MCRecoCaloAssociation& object);
0182
0183 void prepareForWrite() const final;
0184 void prepareAfterRead() final;
0185 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0186
0187
0188 podio::CollectionWriteBuffers getBuffers() final;
0189
0190 void setID(uint32_t ID) final {
0191 m_collectionID = ID;
0192 if (!m_isSubsetColl) {
0193 std::for_each(m_storage.entries.begin(), m_storage.entries.end(), [ID](MCRecoCaloAssociationObj* obj) {
0194 obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0195 });
0196 }
0197 m_isValid = true;
0198 }
0199
0200 uint32_t getID() const final {
0201 return m_collectionID;
0202 }
0203
0204 bool isValid() const final {
0205 return m_isValid;
0206 }
0207
0208 size_t getDatamodelRegistryIndex() const final;
0209
0210
0211 iterator begin() {
0212 return iterator(0, &m_storage.entries);
0213 }
0214 const_iterator begin() const {
0215 return const_iterator(0, &m_storage.entries);
0216 }
0217 const_iterator cbegin() const {
0218 return begin();
0219 }
0220 iterator end() {
0221 return iterator(m_storage.entries.size(), &m_storage.entries);
0222 }
0223 const_iterator end() const {
0224 return const_iterator(m_storage.entries.size(), &m_storage.entries);
0225 }
0226 const_iterator cend() const {
0227 return end();
0228 }
0229
0230 std::vector<float> weight(const size_t nElem = 0) const;
0231
0232 private:
0233
0234
0235
0236 friend class MCRecoCaloAssociationCollectionData;
0237
0238 bool m_isValid{false};
0239 mutable bool m_isPrepared{false};
0240 bool m_isSubsetColl{false};
0241 uint32_t m_collectionID{0};
0242 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0243 mutable MCRecoCaloAssociationCollectionData m_storage{};
0244 };
0245
0246 std::ostream& operator<<(std::ostream& o, const MCRecoCaloAssociationCollection& v);
0247
0248 template <typename... Args>
0249 MutableMCRecoCaloAssociation MCRecoCaloAssociationCollection::create(Args&&... args) {
0250 if (m_isSubsetColl) {
0251 throw std::logic_error("Cannot create new elements on a subset collection");
0252 }
0253 const int size = m_storage.entries.size();
0254 auto obj = new MCRecoCaloAssociationObj({size, m_collectionID}, {std::forward<Args>(args)...});
0255 m_storage.entries.push_back(obj);
0256
0257 return MutableMCRecoCaloAssociation(podio::utils::MaybeSharedPtr(obj));
0258 }
0259
0260 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0261 void to_json(nlohmann::json& j, const MCRecoCaloAssociationCollection& collection);
0262 #endif
0263
0264 }
0265
0266 #endif