File indexing completed on 2025-01-18 09:55:38
0001
0002
0003 #ifndef EDM4HEP_RecIonizationClusterCollection_H
0004 #define EDM4HEP_RecIonizationClusterCollection_H
0005
0006
0007 #include "edm4hep/MutableRecIonizationCluster.h"
0008 #include "edm4hep/RecIonizationCluster.h"
0009 #include "edm4hep/RecIonizationClusterCollectionData.h"
0010 #include "edm4hep/RecIonizationClusterObj.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 RecIonizationClusterCollectionIterator {
0036 public:
0037 RecIonizationClusterCollectionIterator(size_t index, const RecIonizationClusterObjPointerContainer* collection) :
0038 m_index(index),
0039 m_object(podio::utils::MaybeSharedPtr<RecIonizationClusterObj>{nullptr}),
0040 m_collection(collection) {
0041 }
0042
0043 RecIonizationClusterCollectionIterator(const RecIonizationClusterCollectionIterator&) = delete;
0044 RecIonizationClusterCollectionIterator& operator=(const RecIonizationClusterCollectionIterator&) = delete;
0045
0046 bool operator!=(const RecIonizationClusterCollectionIterator& x) const {
0047 return m_index != x.m_index;
0048 }
0049
0050 bool operator==(const RecIonizationClusterCollectionIterator& x) const {
0051 return m_index == x.m_index;
0052 }
0053
0054 RecIonizationCluster operator*();
0055 RecIonizationCluster* operator->();
0056 RecIonizationClusterCollectionIterator& operator++();
0057
0058 private:
0059 size_t m_index;
0060 RecIonizationCluster m_object;
0061 const RecIonizationClusterObjPointerContainer* m_collection;
0062 };
0063
0064 class RecIonizationClusterMutableCollectionIterator {
0065 public:
0066 RecIonizationClusterMutableCollectionIterator(size_t index,
0067 const RecIonizationClusterObjPointerContainer* collection) :
0068 m_index(index),
0069 m_object(podio::utils::MaybeSharedPtr<RecIonizationClusterObj>{nullptr}),
0070 m_collection(collection) {
0071 }
0072
0073 RecIonizationClusterMutableCollectionIterator(const RecIonizationClusterMutableCollectionIterator&) = delete;
0074 RecIonizationClusterMutableCollectionIterator&
0075 operator=(const RecIonizationClusterMutableCollectionIterator&) = delete;
0076
0077 bool operator!=(const RecIonizationClusterMutableCollectionIterator& x) const {
0078 return m_index != x.m_index;
0079 }
0080
0081 bool operator==(const RecIonizationClusterMutableCollectionIterator& x) const {
0082 return m_index == x.m_index;
0083 }
0084
0085 MutableRecIonizationCluster operator*();
0086 MutableRecIonizationCluster* operator->();
0087 RecIonizationClusterMutableCollectionIterator& operator++();
0088
0089 private:
0090 size_t m_index;
0091 MutableRecIonizationCluster m_object;
0092 const RecIonizationClusterObjPointerContainer* m_collection;
0093 };
0094
0095
0096
0097
0098 class RecIonizationClusterCollection : public podio::CollectionBase {
0099 public:
0100 using value_type = RecIonizationCluster;
0101 using const_iterator = RecIonizationClusterCollectionIterator;
0102 using iterator = RecIonizationClusterMutableCollectionIterator;
0103 using difference_type = ptrdiff_t;
0104 using size_type = size_t;
0105
0106 RecIonizationClusterCollection();
0107 RecIonizationClusterCollection(RecIonizationClusterCollectionData&& data, bool isSubsetColl);
0108
0109 RecIonizationClusterCollection(const RecIonizationClusterCollection&) = delete;
0110 RecIonizationClusterCollection& operator=(const RecIonizationClusterCollection&) = delete;
0111 RecIonizationClusterCollection(RecIonizationClusterCollection&&) = default;
0112 RecIonizationClusterCollection& operator=(RecIonizationClusterCollection&&) = default;
0113
0114
0115 ~RecIonizationClusterCollection();
0116
0117 constexpr static auto typeName = "edm4hep::RecIonizationClusterCollection";
0118 constexpr static auto valueTypeName = "edm4hep::RecIonizationCluster";
0119 constexpr static auto dataTypeName = "edm4hep::RecIonizationClusterData";
0120
0121 void clear() final;
0122
0123
0124 void print(std::ostream& os = std::cout, bool flush = true) const final;
0125
0126
0127 RecIonizationClusterCollection* operator->() {
0128 return static_cast<RecIonizationClusterCollection*>(this);
0129 }
0130
0131
0132 MutableRecIonizationCluster create();
0133
0134
0135
0136 template <typename... Args>
0137 MutableRecIonizationCluster 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 RecIonizationCluster operator[](std::size_t index) const;
0171
0172 MutableRecIonizationCluster operator[](std::size_t index);
0173
0174 RecIonizationCluster at(std::size_t index) const;
0175
0176 MutableRecIonizationCluster at(std::size_t index);
0177
0178
0179 void push_back(const MutableRecIonizationCluster& object);
0180
0181 void push_back(const RecIonizationCluster& 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](RecIonizationClusterObj* 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<std::uint64_t> cellID(const size_t nElem = 0) const;
0231 std::vector<float> significance(const size_t nElem = 0) const;
0232 std::vector<std::int16_t> type(const size_t nElem = 0) const;
0233
0234 private:
0235
0236
0237
0238 friend class RecIonizationClusterCollectionData;
0239
0240 bool m_isValid{false};
0241 mutable bool m_isPrepared{false};
0242 bool m_isSubsetColl{false};
0243 uint32_t m_collectionID{0};
0244 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0245 mutable RecIonizationClusterCollectionData m_storage{};
0246 };
0247
0248 std::ostream& operator<<(std::ostream& o, const RecIonizationClusterCollection& v);
0249
0250 template <typename... Args>
0251 MutableRecIonizationCluster RecIonizationClusterCollection::create(Args&&... args) {
0252 if (m_isSubsetColl) {
0253 throw std::logic_error("Cannot create new elements on a subset collection");
0254 }
0255 const int size = m_storage.entries.size();
0256 auto obj = new RecIonizationClusterObj({size, m_collectionID}, {std::forward<Args>(args)...});
0257 m_storage.entries.push_back(obj);
0258
0259
0260 obj->m_trackerPulse = new std::vector<edm4hep::TrackerPulse>();
0261 m_storage.createRelations(obj);
0262 return MutableRecIonizationCluster(podio::utils::MaybeSharedPtr(obj));
0263 }
0264
0265 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0266 void to_json(nlohmann::json& j, const RecIonizationClusterCollection& collection);
0267 #endif
0268
0269 }
0270
0271 #endif