File indexing completed on 2025-12-11 10:20:46
0001
0002
0003 #ifndef JANA2_TUTORIAL_PODIO_DATAMODEL_CalorimeterClusterCollection_H
0004 #define JANA2_TUTORIAL_PODIO_DATAMODEL_CalorimeterClusterCollection_H
0005
0006
0007 #include "jana2_tutorial_podio_datamodel/CalorimeterCluster.h"
0008 #include "jana2_tutorial_podio_datamodel/MutableCalorimeterCluster.h"
0009 #include "jana2_tutorial_podio_datamodel/CalorimeterClusterObj.h"
0010 #include "jana2_tutorial_podio_datamodel/CalorimeterClusterCollectionData.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 CalorimeterClusterCollectionIterator {
0037 public:
0038 using value_type = CalorimeterCluster;
0039 using difference_type = ptrdiff_t;
0040 using reference = CalorimeterCluster;
0041 using pointer = CalorimeterCluster*;
0042 using iterator_category = std::input_iterator_tag;
0043
0044
0045 using iterator_concept = std::random_access_iterator_tag;
0046
0047 CalorimeterClusterCollectionIterator(size_t index, const CalorimeterClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<CalorimeterClusterObj>{nullptr}), m_collection(collection) {}
0048 CalorimeterClusterCollectionIterator() = default;
0049
0050 CalorimeterClusterCollectionIterator(const CalorimeterClusterCollectionIterator&) = default;
0051 CalorimeterClusterCollectionIterator(CalorimeterClusterCollectionIterator&&) = default;
0052 CalorimeterClusterCollectionIterator& operator=(const CalorimeterClusterCollectionIterator&) = default;
0053 CalorimeterClusterCollectionIterator& operator=(CalorimeterClusterCollectionIterator&&) = default;
0054 ~CalorimeterClusterCollectionIterator() = default;
0055
0056 auto operator<=>(const CalorimeterClusterCollectionIterator& other) const {
0057 return m_index <=> other.m_index;
0058 }
0059
0060 bool operator==(const CalorimeterClusterCollectionIterator& x) const {
0061 return m_index == x.m_index;
0062 }
0063
0064 reference operator*() const;
0065 pointer operator->();
0066 CalorimeterClusterCollectionIterator& operator++();
0067 CalorimeterClusterCollectionIterator operator++(int);
0068 CalorimeterClusterCollectionIterator& operator--();
0069 CalorimeterClusterCollectionIterator operator--(int);
0070 CalorimeterClusterCollectionIterator& operator+=(difference_type n);
0071 CalorimeterClusterCollectionIterator operator+(difference_type n) const;
0072 friend CalorimeterClusterCollectionIterator operator+(difference_type n, const CalorimeterClusterCollectionIterator& it);
0073 CalorimeterClusterCollectionIterator& operator-=(difference_type n);
0074 CalorimeterClusterCollectionIterator operator-(difference_type n) const;
0075 reference operator[](difference_type n) const;
0076 difference_type operator-(const CalorimeterClusterCollectionIterator& other) const;
0077
0078 private:
0079 size_t m_index{0};
0080 CalorimeterCluster m_object { podio::utils::MaybeSharedPtr<CalorimeterClusterObj>{nullptr} };
0081 const CalorimeterClusterObjPointerContainer* m_collection{nullptr};
0082 };
0083
0084
0085 class CalorimeterClusterMutableCollectionIterator {
0086 public:
0087 using value_type = CalorimeterCluster;
0088 using difference_type = ptrdiff_t;
0089 using reference = MutableCalorimeterCluster;
0090 using pointer = MutableCalorimeterCluster*;
0091 using iterator_category = std::input_iterator_tag;
0092
0093
0094 using iterator_concept = std::random_access_iterator_tag;
0095
0096 CalorimeterClusterMutableCollectionIterator(size_t index, const CalorimeterClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<CalorimeterClusterObj>{nullptr}), m_collection(collection) {}
0097 CalorimeterClusterMutableCollectionIterator() = default;
0098
0099 CalorimeterClusterMutableCollectionIterator(const CalorimeterClusterMutableCollectionIterator&) = default;
0100 CalorimeterClusterMutableCollectionIterator(CalorimeterClusterMutableCollectionIterator&&) = default;
0101 CalorimeterClusterMutableCollectionIterator& operator=(const CalorimeterClusterMutableCollectionIterator&) = default;
0102 CalorimeterClusterMutableCollectionIterator& operator=(CalorimeterClusterMutableCollectionIterator&&) = default;
0103 ~CalorimeterClusterMutableCollectionIterator() = default;
0104
0105 auto operator<=>(const CalorimeterClusterMutableCollectionIterator& other) const {
0106 return m_index <=> other.m_index;
0107 }
0108
0109 bool operator==(const CalorimeterClusterMutableCollectionIterator& x) const {
0110 return m_index == x.m_index;
0111 }
0112
0113 reference operator*() const;
0114 pointer operator->();
0115 CalorimeterClusterMutableCollectionIterator& operator++();
0116 CalorimeterClusterMutableCollectionIterator operator++(int);
0117 CalorimeterClusterMutableCollectionIterator& operator--();
0118 CalorimeterClusterMutableCollectionIterator operator--(int);
0119 CalorimeterClusterMutableCollectionIterator& operator+=(difference_type n);
0120 CalorimeterClusterMutableCollectionIterator operator+(difference_type n) const;
0121 friend CalorimeterClusterMutableCollectionIterator operator+(difference_type n, const CalorimeterClusterMutableCollectionIterator& it);
0122 CalorimeterClusterMutableCollectionIterator& operator-=(difference_type n);
0123 CalorimeterClusterMutableCollectionIterator operator-(difference_type n) const;
0124 reference operator[](difference_type n) const;
0125 difference_type operator-(const CalorimeterClusterMutableCollectionIterator& other) const;
0126
0127 private:
0128 size_t m_index{0};
0129 MutableCalorimeterCluster m_object { podio::utils::MaybeSharedPtr<CalorimeterClusterObj>{nullptr} };
0130 const CalorimeterClusterObjPointerContainer* m_collection{nullptr};
0131 };
0132
0133
0134
0135
0136
0137 class CalorimeterClusterCollection : public podio::CollectionBase {
0138 public:
0139 using value_type = CalorimeterCluster;
0140 using mutable_type = MutableCalorimeterCluster;
0141 using const_iterator = CalorimeterClusterCollectionIterator;
0142 using iterator = CalorimeterClusterMutableCollectionIterator;
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 CalorimeterClusterCollection() = default;
0149 CalorimeterClusterCollection(CalorimeterClusterCollectionData&& data, bool isSubsetColl);
0150
0151 CalorimeterClusterCollection(const CalorimeterClusterCollection& ) = delete;
0152 CalorimeterClusterCollection& operator=(const CalorimeterClusterCollection& ) = delete;
0153 CalorimeterClusterCollection(CalorimeterClusterCollection&&) = default;
0154 CalorimeterClusterCollection& operator=(CalorimeterClusterCollection&&) = default;
0155
0156
0157 ~CalorimeterClusterCollection() override;
0158
0159 constexpr static std::string_view typeName = "CalorimeterClusterCollection";
0160 constexpr static std::string_view valueTypeName = "CalorimeterCluster";
0161 constexpr static std::string_view dataTypeName = "CalorimeterClusterData";
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 MutableCalorimeterCluster create();
0175
0176
0177
0178 template<typename... Args>
0179 MutableCalorimeterCluster 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 CalorimeterCluster operator[](std::size_t index) const;
0207
0208 MutableCalorimeterCluster operator[](std::size_t index);
0209
0210 CalorimeterCluster at(std::size_t index) const;
0211
0212 MutableCalorimeterCluster at(std::size_t index);
0213
0214
0215
0216 void push_back(const MutableCalorimeterCluster& object);
0217
0218 void push_back(const CalorimeterCluster& 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] (CalorimeterClusterObj* 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> x_center(const size_t nElem = 0) const;
0295 std::vector<double> y_center(const size_t nElem = 0) const;
0296 std::vector<double> z_center(const size_t nElem = 0) const;
0297 std::vector<double> energy(const size_t nElem = 0) const;
0298 std::vector<std::uint64_t> time_begin(const size_t nElem = 0) const;
0299 std::vector<std::uint64_t> time_end(const size_t nElem = 0) const;
0300
0301 private:
0302
0303
0304
0305 friend class CalorimeterClusterCollectionData;
0306
0307 mutable bool m_isPrepared{false};
0308 bool m_isSubsetColl{false};
0309 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0310 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0311 mutable CalorimeterClusterCollectionData m_storage{};
0312 };
0313
0314 std::ostream& operator<<(std::ostream& o, const CalorimeterClusterCollection& v);
0315
0316 template<typename... Args>
0317 MutableCalorimeterCluster CalorimeterClusterCollection::create(Args&&... args) {
0318 if (m_isSubsetColl) {
0319 throw std::logic_error("Cannot create new elements on a subset collection");
0320 }
0321 auto obj = new CalorimeterClusterObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0322 m_storage.entries.push_back(obj);
0323
0324
0325 obj->m_hits = new std::vector<CalorimeterHit>();
0326 obj->m_clusters = new std::vector<CalorimeterCluster>();
0327 m_storage.createRelations(obj);
0328 return MutableCalorimeterCluster(podio::utils::MaybeSharedPtr(obj));
0329 }
0330
0331 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0332 void to_json(nlohmann::json& j, const CalorimeterClusterCollection& collection);
0333 #endif
0334
0335
0336
0337
0338
0339
0340 #if defined(__clang__)
0341 #pragma clang diagnostic push
0342 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0343 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0344 #pragma clang diagnostic ignored "-Wdeprecated"
0345 constexpr std::string_view CalorimeterClusterCollection::typeName;
0346 constexpr std::string_view CalorimeterClusterCollection::valueTypeName;
0347 constexpr std::string_view CalorimeterClusterCollection::dataTypeName;
0348 #pragma clang diagnostic pop
0349 #elif defined(__GNUC__)
0350 #pragma GCC diagnostic push
0351 #pragma GCC diagnostic ignored "-Wdeprecated"
0352 constexpr std::string_view CalorimeterClusterCollection::typeName;
0353 constexpr std::string_view CalorimeterClusterCollection::valueTypeName;
0354 constexpr std::string_view CalorimeterClusterCollection::dataTypeName;
0355 #pragma GCC diagnostic pop
0356 #endif
0357
0358
0359 #endif