Warning, file /include/edm4hep/EventHeaderCollection.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003 #ifndef EDM4HEP_EventHeaderCollection_H
0004 #define EDM4HEP_EventHeaderCollection_H
0005
0006
0007 #include "edm4hep/EventHeader.h"
0008 #include "edm4hep/EventHeaderCollectionData.h"
0009 #include "edm4hep/EventHeaderObj.h"
0010 #include "edm4hep/MutableEventHeader.h"
0011
0012
0013 #include "podio/CollectionBase.h"
0014 #include "podio/ICollectionProvider.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 <algorithm>
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 EventHeaderCollectionIterator {
0036 public:
0037 using value_type = EventHeader;
0038 using difference_type = ptrdiff_t;
0039 using reference = EventHeader;
0040 using pointer = EventHeader*;
0041 using iterator_category = std::input_iterator_tag;
0042
0043
0044 using iterator_concept = std::random_access_iterator_tag;
0045
0046 EventHeaderCollectionIterator(size_t index, const EventHeaderObjPointerContainer* collection)
0047 : m_index(index), m_object(podio::utils::MaybeSharedPtr<EventHeaderObj>{nullptr}), m_collection(collection) {}
0048 EventHeaderCollectionIterator() = default;
0049
0050 EventHeaderCollectionIterator(const EventHeaderCollectionIterator&) = default;
0051 EventHeaderCollectionIterator(EventHeaderCollectionIterator&&) = default;
0052 EventHeaderCollectionIterator& operator=(const EventHeaderCollectionIterator&) = default;
0053 EventHeaderCollectionIterator& operator=(EventHeaderCollectionIterator&&) = default;
0054 ~EventHeaderCollectionIterator() = default;
0055
0056 auto operator<=>(const EventHeaderCollectionIterator& other) const { return m_index <=> other.m_index; }
0057
0058 bool operator==(const EventHeaderCollectionIterator& x) const { return m_index == x.m_index; }
0059
0060 reference operator*() const;
0061 pointer operator->();
0062 EventHeaderCollectionIterator& operator++();
0063 EventHeaderCollectionIterator operator++(int);
0064 EventHeaderCollectionIterator& operator--();
0065 EventHeaderCollectionIterator operator--(int);
0066 EventHeaderCollectionIterator& operator+=(difference_type n);
0067 EventHeaderCollectionIterator operator+(difference_type n) const;
0068 friend EventHeaderCollectionIterator operator+(difference_type n, const EventHeaderCollectionIterator& it);
0069 EventHeaderCollectionIterator& operator-=(difference_type n);
0070 EventHeaderCollectionIterator operator-(difference_type n) const;
0071 reference operator[](difference_type n) const;
0072 difference_type operator-(const EventHeaderCollectionIterator& other) const;
0073
0074 private:
0075 size_t m_index{0};
0076 EventHeader m_object{podio::utils::MaybeSharedPtr<EventHeaderObj>{nullptr}};
0077 const EventHeaderObjPointerContainer* m_collection{nullptr};
0078 };
0079
0080 class EventHeaderMutableCollectionIterator {
0081 public:
0082 using value_type = EventHeader;
0083 using difference_type = ptrdiff_t;
0084 using reference = MutableEventHeader;
0085 using pointer = MutableEventHeader*;
0086 using iterator_category = std::input_iterator_tag;
0087
0088
0089 using iterator_concept = std::random_access_iterator_tag;
0090
0091 EventHeaderMutableCollectionIterator(size_t index, const EventHeaderObjPointerContainer* collection)
0092 : m_index(index), m_object(podio::utils::MaybeSharedPtr<EventHeaderObj>{nullptr}), m_collection(collection) {}
0093 EventHeaderMutableCollectionIterator() = default;
0094
0095 EventHeaderMutableCollectionIterator(const EventHeaderMutableCollectionIterator&) = default;
0096 EventHeaderMutableCollectionIterator(EventHeaderMutableCollectionIterator&&) = default;
0097 EventHeaderMutableCollectionIterator& operator=(const EventHeaderMutableCollectionIterator&) = default;
0098 EventHeaderMutableCollectionIterator& operator=(EventHeaderMutableCollectionIterator&&) = default;
0099 ~EventHeaderMutableCollectionIterator() = default;
0100
0101 auto operator<=>(const EventHeaderMutableCollectionIterator& other) const { return m_index <=> other.m_index; }
0102
0103 bool operator==(const EventHeaderMutableCollectionIterator& x) const { return m_index == x.m_index; }
0104
0105 reference operator*() const;
0106 pointer operator->();
0107 EventHeaderMutableCollectionIterator& operator++();
0108 EventHeaderMutableCollectionIterator operator++(int);
0109 EventHeaderMutableCollectionIterator& operator--();
0110 EventHeaderMutableCollectionIterator operator--(int);
0111 EventHeaderMutableCollectionIterator& operator+=(difference_type n);
0112 EventHeaderMutableCollectionIterator operator+(difference_type n) const;
0113 friend EventHeaderMutableCollectionIterator operator+(difference_type n,
0114 const EventHeaderMutableCollectionIterator& it);
0115 EventHeaderMutableCollectionIterator& operator-=(difference_type n);
0116 EventHeaderMutableCollectionIterator operator-(difference_type n) const;
0117 reference operator[](difference_type n) const;
0118 difference_type operator-(const EventHeaderMutableCollectionIterator& other) const;
0119
0120 private:
0121 size_t m_index{0};
0122 MutableEventHeader m_object{podio::utils::MaybeSharedPtr<EventHeaderObj>{nullptr}};
0123 const EventHeaderObjPointerContainer* m_collection{nullptr};
0124 };
0125
0126
0127
0128
0129 class EventHeaderCollection : public podio::CollectionBase {
0130 public:
0131 using value_type = EventHeader;
0132 using mutable_type = MutableEventHeader;
0133 using const_iterator = EventHeaderCollectionIterator;
0134 using iterator = EventHeaderMutableCollectionIterator;
0135 using difference_type = ptrdiff_t;
0136 using size_type = size_t;
0137 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0138 using reverse_iterator = std::reverse_iterator<iterator>;
0139
0140 EventHeaderCollection() = default;
0141 EventHeaderCollection(EventHeaderCollectionData&& data, bool isSubsetColl);
0142
0143 EventHeaderCollection(const EventHeaderCollection&) = delete;
0144 EventHeaderCollection& operator=(const EventHeaderCollection&) = delete;
0145 EventHeaderCollection(EventHeaderCollection&&) = default;
0146 EventHeaderCollection& operator=(EventHeaderCollection&&) = default;
0147
0148
0149 ~EventHeaderCollection() override;
0150
0151 constexpr static std::string_view typeName = "edm4hep::EventHeaderCollection";
0152 constexpr static std::string_view valueTypeName = "edm4hep::EventHeader";
0153 constexpr static std::string_view dataTypeName = "edm4hep::EventHeaderData";
0154
0155 void clear() final;
0156
0157
0158 static void __cppyy_pythonize__(PyObject* klass, const std::string& name) {
0159 podio::detail::pythonizations::pythonize_subscript(klass, name);
0160 }
0161
0162
0163 void print(std::ostream& os = std::cout, bool flush = true) const final;
0164
0165
0166 MutableEventHeader create();
0167
0168
0169
0170 template <typename... Args>
0171 MutableEventHeader create(Args&&... args);
0172
0173
0174 std::size_t size() const final;
0175
0176
0177 std::size_t max_size() const final;
0178
0179
0180 bool empty() const final;
0181
0182
0183 const std::string_view getTypeName() const final { return typeName; }
0184
0185 const std::string_view getValueTypeName() const final { return valueTypeName; }
0186
0187 const std::string_view getDataTypeName() const final { return dataTypeName; }
0188
0189 podio::SchemaVersionT getSchemaVersion() const final;
0190
0191 bool isSubsetCollection() const final { return m_isSubsetColl; }
0192
0193 void setSubsetCollection(bool setSubset = true) final;
0194
0195
0196 EventHeader operator[](std::size_t index) const;
0197
0198 MutableEventHeader operator[](std::size_t index);
0199
0200 EventHeader at(std::size_t index) const;
0201
0202 MutableEventHeader at(std::size_t index);
0203
0204
0205 void push_back(const MutableEventHeader& object);
0206
0207 void push_back(const EventHeader& object);
0208
0209 void prepareForWrite() const final;
0210 void prepareAfterRead() final;
0211 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
0212
0213
0214 podio::CollectionWriteBuffers getBuffers() final;
0215
0216 void setID(uint32_t ID) final {
0217 m_collectionID = ID;
0218 if (!m_isSubsetColl) {
0219 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0220 [ID](EventHeaderObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; });
0221 }
0222 }
0223
0224 uint32_t getID() const final { return m_collectionID; }
0225
0226
0227 bool hasID() const final {
0228 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
0229 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
0230 }
0231
0232 [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
0233 "collection is valid")]] bool
0234 isValid() const final {
0235 return hasID();
0236 }
0237
0238 size_t getDatamodelRegistryIndex() const final;
0239
0240
0241 iterator begin() { return iterator(0, &m_storage.entries); }
0242 const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0243 const_iterator cbegin() const { return begin(); }
0244 iterator end() { return iterator(m_storage.entries.size(), &m_storage.entries); }
0245 const_iterator end() const { return const_iterator(m_storage.entries.size(), &m_storage.entries); }
0246 const_iterator cend() const { return end(); }
0247
0248 reverse_iterator rbegin() { return reverse_iterator(end()); }
0249 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
0250 const_reverse_iterator crbegin() const { return rbegin(); }
0251 reverse_iterator rend() { return reverse_iterator(begin()); }
0252 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
0253 const_reverse_iterator crend() const { return rend(); }
0254
0255 std::vector<std::uint64_t> eventNumber(const size_t nElem = 0) const;
0256 std::vector<std::uint32_t> runNumber(const size_t nElem = 0) const;
0257 std::vector<std::uint64_t> timeStamp(const size_t nElem = 0) const;
0258 std::vector<double> weight(const size_t nElem = 0) const;
0259
0260 private:
0261
0262
0263
0264 friend class EventHeaderCollectionData;
0265
0266 mutable bool m_isPrepared{false};
0267 bool m_isSubsetColl{false};
0268 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
0269 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
0270 mutable EventHeaderCollectionData m_storage{};
0271 };
0272
0273 std::ostream& operator<<(std::ostream& o, const EventHeaderCollection& v);
0274
0275 template <typename... Args>
0276 MutableEventHeader EventHeaderCollection::create(Args&&... args) {
0277 if (m_isSubsetColl) {
0278 throw std::logic_error("Cannot create new elements on a subset collection");
0279 }
0280 auto obj =
0281 new EventHeaderObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
0282 m_storage.entries.push_back(obj);
0283
0284
0285 obj->m_weights = new std::vector<double>();
0286 m_storage.createRelations(obj);
0287 return MutableEventHeader(podio::utils::MaybeSharedPtr(obj));
0288 }
0289
0290 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0291 void to_json(nlohmann::json& j, const EventHeaderCollection& collection);
0292 #endif
0293
0294 }
0295
0296
0297
0298
0299 #if defined(__clang__)
0300 #pragma clang diagnostic push
0301 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0302 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0303 #pragma clang diagnostic ignored "-Wdeprecated"
0304 constexpr std::string_view edm4hep::EventHeaderCollection::typeName;
0305 constexpr std::string_view edm4hep::EventHeaderCollection::valueTypeName;
0306 constexpr std::string_view edm4hep::EventHeaderCollection::dataTypeName;
0307 #pragma clang diagnostic pop
0308 #elif defined(__GNUC__)
0309 #pragma GCC diagnostic push
0310 #pragma GCC diagnostic ignored "-Wdeprecated"
0311 constexpr std::string_view edm4hep::EventHeaderCollection::typeName;
0312 constexpr std::string_view edm4hep::EventHeaderCollection::valueTypeName;
0313 constexpr std::string_view edm4hep::EventHeaderCollection::dataTypeName;
0314 #pragma GCC diagnostic pop
0315 #endif
0316
0317 #endif