File indexing completed on 2025-12-06 09:50:21
0001
0002
0003 #ifndef PODIODATAMODEL_ExampleClusterCollection_H
0004 #define PODIODATAMODEL_ExampleClusterCollection_H
0005
0006
0007 #include "PodioDatamodel/ExampleCluster.h"
0008 #include "PodioDatamodel/MutableExampleCluster.h"
0009 #include "PodioDatamodel/ExampleClusterObj.h"
0010 #include "PodioDatamodel/ExampleClusterCollectionData.h"
0011
0012
0013 #include "podio/ICollectionProvider.h"
0014 #include "podio/CollectionBase.h"
0015 #include "podio/detail/Pythonizations.h"
0016
0017 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0018 #include "nlohmann/json_fwd.hpp"
0019 #endif
0020
0021 #include <string_view>
0022 #include <vector>
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
0034
0035
0036 class ExampleClusterCollectionIterator {
0037 public:
0038 using value_type = ExampleCluster;
0039 using difference_type = ptrdiff_t;
0040 using reference = ExampleCluster;
0041 using pointer = ExampleCluster*;
0042 using iterator_category = std::input_iterator_tag;
0043
0044
0045 using iterator_concept = std::random_access_iterator_tag;
0046
0047 ExampleClusterCollectionIterator(size_t index, const ExampleClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ExampleClusterObj>{nullptr}), m_collection(collection) {}
0048 ExampleClusterCollectionIterator() = default;
0049
0050 ExampleClusterCollectionIterator(const ExampleClusterCollectionIterator&) = default;
0051 ExampleClusterCollectionIterator(ExampleClusterCollectionIterator&&) = default;
0052 ExampleClusterCollectionIterator& operator=(const ExampleClusterCollectionIterator&) = default;
0053 ExampleClusterCollectionIterator& operator=(ExampleClusterCollectionIterator&&) = default;
0054 ~ExampleClusterCollectionIterator() = default;
0055
0056 auto operator<=>(const ExampleClusterCollectionIterator& other) const {
0057 return m_index <=> other.m_index;
0058 }
0059
0060 bool operator==(const ExampleClusterCollectionIterator& x) const {
0061 return m_index == x.m_index;
0062 }
0063
0064 reference operator*() const;
0065 pointer operator->();
0066 ExampleClusterCollectionIterator& operator++();
0067 ExampleClusterCollectionIterator operator++(int);
0068 ExampleClusterCollectionIterator& operator--();
0069 ExampleClusterCollectionIterator operator--(int);
0070 ExampleClusterCollectionIterator& operator+=(difference_type n);
0071 ExampleClusterCollectionIterator operator+(difference_type n) const;
0072 friend ExampleClusterCollectionIterator operator+(difference_type n, const ExampleClusterCollectionIterator& it);
0073 ExampleClusterCollectionIterator& operator-=(difference_type n);
0074 ExampleClusterCollectionIterator operator-(difference_type n) const;
0075 reference operator[](difference_type n) const;
0076 difference_type operator-(const ExampleClusterCollectionIterator& other) const;
0077
0078 private:
0079 size_t m_index{0};
0080 ExampleCluster m_object { podio::utils::MaybeSharedPtr<ExampleClusterObj>{nullptr} };
0081 const ExampleClusterObjPointerContainer* m_collection{nullptr};
0082 };
0083
0084
0085 class ExampleClusterMutableCollectionIterator {
0086 public:
0087 using value_type = ExampleCluster;
0088 using difference_type = ptrdiff_t;
0089 using reference = MutableExampleCluster;
0090 using pointer = MutableExampleCluster*;
0091 using iterator_category = std::input_iterator_tag;
0092
0093
0094 using iterator_concept = std::random_access_iterator_tag;
0095
0096 ExampleClusterMutableCollectionIterator(size_t index, const ExampleClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ExampleClusterObj>{nullptr}), m_collection(collection) {}
0097 ExampleClusterMutableCollectionIterator() = default;
0098
0099 ExampleClusterMutableCollectionIterator(const ExampleClusterMutableCollectionIterator&) = default;
0100 ExampleClusterMutableCollectionIterator(ExampleClusterMutableCollectionIterator&&) = default;
0101 ExampleClusterMutableCollectionIterator& operator=(const ExampleClusterMutableCollectionIterator&) = default;
0102 ExampleClusterMutableCollectionIterator& operator=(ExampleClusterMutableCollectionIterator&&) = default;
0103 ~ExampleClusterMutableCollectionIterator() = default;
0104
0105 auto operator<=>(const ExampleClusterMutableCollectionIterator& other) const {
0106 return m_index <=> other.m_index;
0107 }
0108
0109 bool operator==(const ExampleClusterMutableCollectionIterator& x) const {
0110 return m_index == x.m_index;
0111 }
0112
0113 reference operator*() const;
0114 pointer operator->();
0115 ExampleClusterMutableCollectionIterator& operator++();
0116 ExampleClusterMutableCollectionIterator operator++(int);
0117 ExampleClusterMutableCollectionIterator& operator--();
0118 ExampleClusterMutableCollectionIterator operator--(int);
0119 ExampleClusterMutableCollectionIterator& operator+=(difference_type n);
0120 ExampleClusterMutableCollectionIterator operator+(difference_type n) const;
0121 friend ExampleClusterMutableCollectionIterator operator+(difference_type n, const ExampleClusterMutableCollectionIterator& it);
0122 ExampleClusterMutableCollectionIterator& operator-=(difference_type n);
0123 ExampleClusterMutableCollectionIterator operator-(difference_type n) const;
0124 reference operator[](difference_type n) const;
0125 difference_type operator-(const ExampleClusterMutableCollectionIterator& other) const;
0126
0127 private:
0128 size_t m_index{0};
0129 MutableExampleCluster m_object { podio::utils::MaybeSharedPtr<ExampleClusterObj>{nullptr} };
0130 const ExampleClusterObjPointerContainer* m_collection{nullptr};
0131 };
0132
0133
0134
0135
0136
0137 class ExampleClusterCollection : public podio::CollectionBase {
0138 public:
0139 using value_type = ExampleCluster;
0140 using mutable_type = MutableExampleCluster;
0141 using const_iterator = ExampleClusterCollectionIterator;
0142 using iterator = ExampleClusterMutableCollectionIterator;
0143 using difference_type = ptrdiff_t;
0144 using size_type = size_t;
0145 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0146 using reverse_iterator = std::reverse_iterator<iterator>;
0147
0148 ExampleClusterCollection() = default;
0149 ExampleClusterCollection(ExampleClusterCollectionData&& data, bool isSubsetColl);
0150
0151 ExampleClusterCollection(const ExampleClusterCollection& ) = delete;
0152 ExampleClusterCollection& operator=(const ExampleClusterCollection& ) = delete;
0153 ExampleClusterCollection(ExampleClusterCollection&&) = default;
0154 ExampleClusterCollection& operator=(ExampleClusterCollection&&) = default;
0155
0156
0157 ~ExampleClusterCollection() override;
0158
0159 constexpr static std::string_view typeName = "ExampleClusterCollection";
0160 constexpr static std::string_view valueTypeName = "ExampleCluster";
0161 constexpr static std::string_view dataTypeName = "ExampleClusterData";
0162
0163 void clear() final;
0164
0165
0166 static void __cppyy_pythonize__(PyObject* klass, const std::string& name){
0167 podio::detail::pythonizations::pythonize_subscript(klass, name);
0168 }
0169
0170
0171 void print(std::ostream& os=std::cout, bool flush=true) const final;
0172
0173
0174 MutableExampleCluster create();
0175
0176
0177
0178 template<typename... Args>
0179 MutableExampleCluster create(Args&&... args);
0180
0181
0182 std::size_t size() const final;
0183
0184
0185 std::size_t max_size() const final;
0186
0187
0188 bool empty() const final;
0189
0190
0191 const std::string_view getTypeName() const final { return typeName; }
0192
0193 const std::string_view getValueTypeName() const final { return valueTypeName; }
0194
0195 const std::string_view getDataTypeName() const final { return dataTypeName; }
0196
0197 podio::SchemaVersionT getSchemaVersion() const final;
0198
0199 bool isSubsetCollection() const final {
0200 return m_isSubsetColl;
0201 }
0202
0203 void setSubsetCollection(bool setSubset=true) final;
0204
0205
0206 ExampleCluster operator[](std::size_t index) const;
0207
0208 MutableExampleCluster operator[](std::size_t index);
0209
0210 ExampleCluster at(std::size_t index) const;
0211
0212 MutableExampleCluster at(std::size_t index);
0213
0214
0215
0216 void push_back(const MutableExampleCluster& object);
0217
0218 void push_back(const ExampleCluster& object);
0219
0220 void prepareForWrite() const final;
0221 void prepareAfterRead() final;
0222 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0223
0224
0225 podio::CollectionWriteBuffers getBuffers() final;
0226
0227 void setID(uint32_t ID) final {
0228 m_collectionID = ID;
0229 if (!m_isSubsetColl) {
0230 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0231 [ID] (ExampleClusterObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
0232 );
0233 }
0234 }
0235
0236 uint32_t getID() const final {
0237 return m_collectionID;
0238 }
0239
0240
0241 bool hasID() const final {
0242 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0243 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0244 }
0245
0246 [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
0247 "collection is valid")]]
0248 bool isValid() const final {
0249 return hasID();
0250 }
0251
0252 size_t getDatamodelRegistryIndex() const final;
0253
0254
0255 iterator begin() {
0256 return iterator(0, &m_storage.entries);
0257 }
0258 const_iterator begin() const {
0259 return const_iterator(0, &m_storage.entries);
0260 }
0261 const_iterator cbegin() const {
0262 return begin();
0263 }
0264 iterator end() {
0265 return iterator(m_storage.entries.size(), &m_storage.entries);
0266 }
0267 const_iterator end() const {
0268 return const_iterator(m_storage.entries.size(), &m_storage.entries);
0269 }
0270 const_iterator cend() const {
0271 return end();
0272 }
0273
0274 reverse_iterator rbegin() {
0275 return reverse_iterator(end());
0276 }
0277 const_reverse_iterator rbegin() const {
0278 return const_reverse_iterator(end());
0279 }
0280 const_reverse_iterator crbegin() const {
0281 return rbegin();
0282 }
0283 reverse_iterator rend() {
0284 return reverse_iterator(begin());
0285 }
0286 const_reverse_iterator rend() const {
0287 return const_reverse_iterator(begin());
0288 }
0289 const_reverse_iterator crend() const {
0290 return rend();
0291 }
0292
0293
0294 std::vector<double> energy(const size_t nElem = 0) const;
0295
0296 private:
0297
0298
0299
0300 friend class ExampleClusterCollectionData;
0301
0302 mutable bool m_isPrepared{false};
0303 bool m_isSubsetColl{false};
0304 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0305 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0306 mutable ExampleClusterCollectionData m_storage{};
0307 };
0308
0309 std::ostream& operator<<(std::ostream& o, const ExampleClusterCollection& v);
0310
0311 template<typename... Args>
0312 MutableExampleCluster ExampleClusterCollection::create(Args&&... args) {
0313 if (m_isSubsetColl) {
0314 throw std::logic_error("Cannot create new elements on a subset collection");
0315 }
0316 auto obj = new ExampleClusterObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0317 m_storage.entries.push_back(obj);
0318
0319
0320 obj->m_Hits = new std::vector<ExampleHit>();
0321 obj->m_Clusters = new std::vector<ExampleCluster>();
0322 m_storage.createRelations(obj);
0323 return MutableExampleCluster(podio::utils::MaybeSharedPtr(obj));
0324 }
0325
0326 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0327 void to_json(nlohmann::json& j, const ExampleClusterCollection& collection);
0328 #endif
0329
0330
0331
0332
0333
0334
0335 #if defined(__clang__)
0336 #pragma clang diagnostic push
0337 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0338 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0339 #pragma clang diagnostic ignored "-Wdeprecated"
0340 constexpr std::string_view ExampleClusterCollection::typeName;
0341 constexpr std::string_view ExampleClusterCollection::valueTypeName;
0342 constexpr std::string_view ExampleClusterCollection::dataTypeName;
0343 #pragma clang diagnostic pop
0344 #elif defined(__GNUC__)
0345 #pragma GCC diagnostic push
0346 #pragma GCC diagnostic ignored "-Wdeprecated"
0347 constexpr std::string_view ExampleClusterCollection::typeName;
0348 constexpr std::string_view ExampleClusterCollection::valueTypeName;
0349 constexpr std::string_view ExampleClusterCollection::dataTypeName;
0350 #pragma GCC diagnostic pop
0351 #endif
0352
0353
0354 #endif