File indexing completed on 2025-09-17 08:21:54
0001
0002
0003 #ifndef ACTSPODIOEDM_BoundParametersCollection_H
0004 #define ACTSPODIOEDM_BoundParametersCollection_H
0005
0006
0007 #include "ActsPodioEdm/BoundParameters.h"
0008 #include "ActsPodioEdm/BoundParametersCollectionData.h"
0009 #include "ActsPodioEdm/BoundParametersObj.h"
0010 #include "ActsPodioEdm/MutableBoundParameters.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 <cstddef>
0022 #include <memory>
0023 #include <mutex>
0024 #include <ostream>
0025 #include <string_view>
0026 #include <vector>
0027
0028 namespace podio {
0029 struct RelationNames;
0030 }
0031
0032 namespace ActsPodioEdm {
0033
0034 class BoundParametersCollectionIterator {
0035 public:
0036 using value_type = BoundParameters;
0037 using difference_type = ptrdiff_t;
0038 using reference = BoundParameters;
0039 using pointer = BoundParameters*;
0040 using iterator_category = std::input_iterator_tag;
0041
0042
0043
0044 using iterator_concept = std::random_access_iterator_tag;
0045
0046 BoundParametersCollectionIterator(
0047 size_t index, const BoundParametersObjPointerContainer* collection)
0048 : m_index(index),
0049 m_object(podio::utils::MaybeSharedPtr<BoundParametersObj>{nullptr}),
0050 m_collection(collection) {}
0051 BoundParametersCollectionIterator() = default;
0052
0053 BoundParametersCollectionIterator(const BoundParametersCollectionIterator&) =
0054 default;
0055 BoundParametersCollectionIterator(BoundParametersCollectionIterator&&) =
0056 default;
0057 BoundParametersCollectionIterator& operator=(
0058 const BoundParametersCollectionIterator&) = default;
0059 BoundParametersCollectionIterator& operator=(
0060 BoundParametersCollectionIterator&&) = default;
0061 ~BoundParametersCollectionIterator() = default;
0062
0063 auto operator<=>(const BoundParametersCollectionIterator& other) const {
0064 return m_index <=> other.m_index;
0065 }
0066
0067 bool operator==(const BoundParametersCollectionIterator& x) const {
0068 return m_index == x.m_index;
0069 }
0070
0071 reference operator*() const;
0072 pointer operator->();
0073 BoundParametersCollectionIterator& operator++();
0074 BoundParametersCollectionIterator operator++(int);
0075 BoundParametersCollectionIterator& operator--();
0076 BoundParametersCollectionIterator operator--(int);
0077 BoundParametersCollectionIterator& operator+=(difference_type n);
0078 BoundParametersCollectionIterator operator+(difference_type n) const;
0079 friend BoundParametersCollectionIterator operator+(
0080 difference_type n, const BoundParametersCollectionIterator& it);
0081 BoundParametersCollectionIterator& operator-=(difference_type n);
0082 BoundParametersCollectionIterator operator-(difference_type n) const;
0083 reference operator[](difference_type n) const;
0084 difference_type operator-(
0085 const BoundParametersCollectionIterator& other) const;
0086
0087 private:
0088 size_t m_index{0};
0089 BoundParameters m_object{
0090 podio::utils::MaybeSharedPtr<BoundParametersObj>{nullptr}};
0091 const BoundParametersObjPointerContainer* m_collection{nullptr};
0092 };
0093
0094 class BoundParametersMutableCollectionIterator {
0095 public:
0096 using value_type = BoundParameters;
0097 using difference_type = ptrdiff_t;
0098 using reference = MutableBoundParameters;
0099 using pointer = MutableBoundParameters*;
0100 using iterator_category = std::input_iterator_tag;
0101
0102
0103
0104 using iterator_concept = std::random_access_iterator_tag;
0105
0106 BoundParametersMutableCollectionIterator(
0107 size_t index, const BoundParametersObjPointerContainer* collection)
0108 : m_index(index),
0109 m_object(podio::utils::MaybeSharedPtr<BoundParametersObj>{nullptr}),
0110 m_collection(collection) {}
0111 BoundParametersMutableCollectionIterator() = default;
0112
0113 BoundParametersMutableCollectionIterator(
0114 const BoundParametersMutableCollectionIterator&) = default;
0115 BoundParametersMutableCollectionIterator(
0116 BoundParametersMutableCollectionIterator&&) = default;
0117 BoundParametersMutableCollectionIterator& operator=(
0118 const BoundParametersMutableCollectionIterator&) = default;
0119 BoundParametersMutableCollectionIterator& operator=(
0120 BoundParametersMutableCollectionIterator&&) = default;
0121 ~BoundParametersMutableCollectionIterator() = default;
0122
0123 auto operator<=>(
0124 const BoundParametersMutableCollectionIterator& other) const {
0125 return m_index <=> other.m_index;
0126 }
0127
0128 bool operator==(const BoundParametersMutableCollectionIterator& x) const {
0129 return m_index == x.m_index;
0130 }
0131
0132 reference operator*() const;
0133 pointer operator->();
0134 BoundParametersMutableCollectionIterator& operator++();
0135 BoundParametersMutableCollectionIterator operator++(int);
0136 BoundParametersMutableCollectionIterator& operator--();
0137 BoundParametersMutableCollectionIterator operator--(int);
0138 BoundParametersMutableCollectionIterator& operator+=(difference_type n);
0139 BoundParametersMutableCollectionIterator operator+(difference_type n) const;
0140 friend BoundParametersMutableCollectionIterator operator+(
0141 difference_type n, const BoundParametersMutableCollectionIterator& it);
0142 BoundParametersMutableCollectionIterator& operator-=(difference_type n);
0143 BoundParametersMutableCollectionIterator operator-(difference_type n) const;
0144 reference operator[](difference_type n) const;
0145 difference_type operator-(
0146 const BoundParametersMutableCollectionIterator& other) const;
0147
0148 private:
0149 size_t m_index{0};
0150 MutableBoundParameters m_object{
0151 podio::utils::MaybeSharedPtr<BoundParametersObj>{nullptr}};
0152 const BoundParametersObjPointerContainer* m_collection{nullptr};
0153 };
0154
0155
0156
0157
0158 class BoundParametersCollection : public podio::CollectionBase {
0159 public:
0160 using value_type = BoundParameters;
0161 using mutable_type = MutableBoundParameters;
0162 using const_iterator = BoundParametersCollectionIterator;
0163 using iterator = BoundParametersMutableCollectionIterator;
0164 using difference_type = ptrdiff_t;
0165 using size_type = size_t;
0166 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0167 using reverse_iterator = std::reverse_iterator<iterator>;
0168
0169 BoundParametersCollection();
0170 BoundParametersCollection(BoundParametersCollectionData&& data,
0171 bool isSubsetColl);
0172
0173 BoundParametersCollection(const BoundParametersCollection&) = delete;
0174 BoundParametersCollection& operator=(const BoundParametersCollection&) =
0175 delete;
0176 BoundParametersCollection(BoundParametersCollection&&) = default;
0177 BoundParametersCollection& operator=(BoundParametersCollection&&) = default;
0178
0179
0180
0181 ~BoundParametersCollection() override;
0182
0183 constexpr static std::string_view typeName =
0184 "ActsPodioEdm::BoundParametersCollection";
0185 constexpr static std::string_view valueTypeName =
0186 "ActsPodioEdm::BoundParameters";
0187 constexpr static std::string_view dataTypeName =
0188 "ActsPodioEdm::BoundParametersData";
0189
0190 void clear() final;
0191
0192
0193 void print(std::ostream& os = std::cout, bool flush = true) const final;
0194
0195
0196 BoundParametersCollection* operator->() {
0197 return static_cast<BoundParametersCollection*>(this);
0198 }
0199
0200
0201 MutableBoundParameters create();
0202
0203
0204
0205 template <typename... Args>
0206 MutableBoundParameters create(Args&&... args);
0207
0208
0209 std::size_t size() const final;
0210
0211
0212 std::size_t max_size() const final;
0213
0214
0215 bool empty() const final;
0216
0217
0218 const std::string_view getTypeName() const final { return typeName; }
0219
0220 const std::string_view getValueTypeName() const final {
0221 return valueTypeName;
0222 }
0223
0224 const std::string_view getDataTypeName() const final { return dataTypeName; }
0225
0226 podio::SchemaVersionT getSchemaVersion() const final;
0227
0228 bool isSubsetCollection() const final { return m_isSubsetColl; }
0229
0230 void setSubsetCollection(bool setSubset = true) final;
0231
0232
0233 BoundParameters operator[](std::size_t index) const;
0234
0235 MutableBoundParameters operator[](std::size_t index);
0236
0237 BoundParameters at(std::size_t index) const;
0238
0239 MutableBoundParameters at(std::size_t index);
0240
0241
0242 void push_back(const MutableBoundParameters& object);
0243
0244 void push_back(const BoundParameters& object);
0245
0246 void prepareForWrite() const final;
0247 void prepareAfterRead() final;
0248 bool setReferences(
0249 const podio::ICollectionProvider* collectionProvider) final;
0250
0251
0252 podio::CollectionWriteBuffers getBuffers() final;
0253
0254 void setID(uint32_t ID) final {
0255 m_collectionID = ID;
0256 if (!m_isSubsetColl) {
0257 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
0258 [ID](BoundParametersObj* obj) {
0259 obj->id = {obj->id.index, static_cast<uint32_t>(ID)};
0260 });
0261 }
0262 m_isValid = true;
0263 }
0264
0265 uint32_t getID() const final { return m_collectionID; }
0266
0267 bool isValid() const final { return m_isValid; }
0268
0269 size_t getDatamodelRegistryIndex() const final;
0270
0271
0272 iterator begin() { return iterator(0, &m_storage.entries); }
0273 const_iterator begin() const { return const_iterator(0, &m_storage.entries); }
0274 const_iterator cbegin() const { return begin(); }
0275 iterator end() {
0276 return iterator(m_storage.entries.size(), &m_storage.entries);
0277 }
0278 const_iterator end() const {
0279 return const_iterator(m_storage.entries.size(), &m_storage.entries);
0280 }
0281 const_iterator cend() const { return end(); }
0282
0283 reverse_iterator rbegin() { return reverse_iterator(end()); }
0284 const_reverse_iterator rbegin() const {
0285 return const_reverse_iterator(end());
0286 }
0287 const_reverse_iterator crbegin() const { return rbegin(); }
0288 reverse_iterator rend() { return reverse_iterator(begin()); }
0289 const_reverse_iterator rend() const {
0290 return const_reverse_iterator(begin());
0291 }
0292 const_reverse_iterator crend() const { return rend(); }
0293
0294 std::vector<ActsPodioEdm::BoundParametersInfo> data(
0295 const size_t nElem = 0) const;
0296
0297 private:
0298
0299
0300
0301 friend class BoundParametersCollectionData;
0302
0303 bool m_isValid{false};
0304 mutable bool m_isPrepared{false};
0305 bool m_isSubsetColl{false};
0306 uint32_t m_collectionID{0};
0307 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
0308 mutable BoundParametersCollectionData m_storage{};
0309 };
0310
0311 std::ostream& operator<<(std::ostream& o, const BoundParametersCollection& v);
0312
0313 template <typename... Args>
0314 MutableBoundParameters BoundParametersCollection::create(Args&&... args) {
0315 if (m_isSubsetColl) {
0316 throw std::logic_error("Cannot create new elements on a subset collection");
0317 }
0318 const int size = m_storage.entries.size();
0319 auto obj = new BoundParametersObj({size, m_collectionID},
0320 {std::forward<Args>(args)...});
0321 m_storage.entries.push_back(obj);
0322
0323 return MutableBoundParameters(podio::utils::MaybeSharedPtr(obj));
0324 }
0325
0326 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0327 void to_json(nlohmann::json& j, const BoundParametersCollection& collection);
0328 #endif
0329
0330 }
0331
0332 #endif