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