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