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