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