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