EDM4eic
EIC data model
Loading...
Searching...
No Matches
VertexCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_VertexCollection_H
4#define EDM4EIC_VertexCollection_H
5
6// datamodel specific includes
7#include "edm4eic/Vertex.h"
9#include "edm4eic/VertexObj.h"
11
12// podio specific includes
13#include "podio/ICollectionProvider.h"
14#include "podio/CollectionBase.h"
15#include "podio/detail/Pythonizations.h"
16#include "podio/utilities/TypeHelpers.h"
17
18#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
19#include "nlohmann/json_fwd.hpp"
20#endif
21
22#include <string_view>
23#include <vector>
24#include <algorithm>
25#include <ostream>
26#include <mutex>
27#include <memory>
28#include <cstddef>
29
30namespace podio {
31 struct RelationNames;
32}
33
34namespace edm4eic {
35
36
37
39public:
41 using difference_type = ptrdiff_t;
43 using pointer = Vertex*;
44 using iterator_category = std::input_iterator_tag;
45 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
46 // remain valid as long as the iterator is valid, not as long as the range is valid.
47 using iterator_concept = std::random_access_iterator_tag;
48
49 VertexCollectionIterator(size_t index, const VertexObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<VertexObj>{nullptr}), m_collection(collection) {}
51
57
58 constexpr auto operator<=>(const VertexCollectionIterator& other) const {
59 return m_index <=> other.m_index;
60 }
61
62 constexpr bool operator==(const VertexCollectionIterator& x) const {
63 return m_index == x.m_index;
64 }
65
66 reference operator*() const;
79
80private:
81 size_t m_index{0};
82 Vertex m_object { podio::utils::MaybeSharedPtr<VertexObj>{nullptr} };
83 const VertexObjPointerContainer* m_collection{nullptr};
84};
85
86
88public:
90 using difference_type = ptrdiff_t;
93 using iterator_category = std::input_iterator_tag;
94 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
95 // remain valid as long as the iterator is valid, not as long as the range is valid.
96 using iterator_concept = std::random_access_iterator_tag;
97
98 VertexMutableCollectionIterator(size_t index, const VertexObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<VertexObj>{nullptr}), m_collection(collection) {}
100
106
107 constexpr auto operator<=>(const VertexMutableCollectionIterator& other) const {
108 return m_index <=> other.m_index;
109 }
110
111 constexpr bool operator==(const VertexMutableCollectionIterator& x) const {
112 return m_index == x.m_index;
113 }
114
115 reference operator*() const;
128
129private:
130 size_t m_index{0};
131 MutableVertex m_object { podio::utils::MaybeSharedPtr<VertexObj>{nullptr} };
132 const VertexObjPointerContainer* m_collection{nullptr};
133};
134
135
136/**
137A Collection is identified by an ID.
138*/
139class VertexCollection : public podio::CollectionBase {
140public:
145 using difference_type = ptrdiff_t;
146 using size_type = size_t;
147 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
148 using reverse_iterator = std::reverse_iterator<iterator>;
149
150 VertexCollection() = default;
151 VertexCollection(VertexCollectionData&& data, bool isSubsetColl);
152 // This is a move-only type
157
158 ~VertexCollection() override;
159#if defined(__cpp_lib_containers_ranges)
160 template<podio::detail::RangeConvertibleTo<value_type> R>
161 VertexCollection(std::from_range_t, R&& range);
162#endif
163
164 /// Construct a Vertex collection from a range of mutable or
165 /// immutable handles
166 template<podio::detail::RangeConvertibleTo<value_type> R>
167 static VertexCollection from(R&& range);
168
169 constexpr static std::string_view typeName = "edm4eic::VertexCollection";
170 constexpr static std::string_view valueTypeName = "edm4eic::Vertex";
171 constexpr static std::string_view dataTypeName = "edm4eic::VertexData";
172
173 void clear() final;
174
175 /// Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
176 static void __cppyy_pythonize__(PyObject* klass, const std::string& name){
177 podio::detail::pythonizations::pythonize_subscript(klass, name);
178 }
179
180 /// Print this collection to the passed stream
181 void print(std::ostream& os=std::cout, bool flush=true) const final;
182
183 /// Append a new object to the collection, and return this object.
185
186 /// Append a new object to the collection, and return this object.
187 /// Initialized with the parameters given
188 template<typename... Args>
189 MutableVertex create(Args&&... args);
190
191 /// number of elements in the collection
192 std::size_t size() const final;
193
194 /// maximal number of elements in the collection
195 std::size_t max_size() const final;
196
197 /// Is the collection empty
198 bool empty() const final;
199
200 /// fully qualified type name
201 const std::string_view getTypeName() const final { return typeName; }
202 /// fully qualified type name of elements - with namespace
203 const std::string_view getValueTypeName() const final { return valueTypeName; }
204 /// fully qualified type name of stored POD elements - with namespace
205 const std::string_view getDataTypeName() const final { return dataTypeName; }
206 /// schema version
207 podio::SchemaVersionT getSchemaVersion() const final;
208
209 bool isSubsetCollection() const final {
210 return m_isSubsetColl;
211 }
212
213 void setSubsetCollection(bool setSubset=true) final;
214
215 /// Returns the const object of given index
216 Vertex operator[](std::size_t index) const;
217 /// Returns the object of a given index
218 MutableVertex operator[](std::size_t index);
219 /// Returns the const object of given index
220 Vertex at(std::size_t index) const;
221 /// Returns the object of given index
222 MutableVertex at(std::size_t index);
223
224
225 /// Append object to the collection
226 void push_back(const MutableVertex& object);
227 /// Append an object to the (subset) collection
228 void push_back(const Vertex& object);
229
230 void prepareForWrite() const final;
231 void prepareAfterRead() final;
232 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
233
234 /// Get the collection buffers for this collection
235 podio::CollectionWriteBuffers getBuffers() final;
236
237 void setID(uint32_t ID) final {
238 m_collectionID = ID;
239 if (!m_isSubsetColl) {
240 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
241 [ID] (VertexObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
242 );
243 }
244 }
245
246 uint32_t getID() const final {
247 return m_collectionID;
248 }
249
250 /// check if the collection has a valid ID
251 bool hasID() const final {
252 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
253 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
254 }
255
256 [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
257 "collection is valid")]]
258 bool isValid() const final {
259 return hasID();
260 }
261
262 size_t getDatamodelRegistryIndex() const final;
263
264 // support for the iterator protocol
266 return iterator(0, &m_storage.entries);
267 }
269 return const_iterator(0, &m_storage.entries);
270 }
272 return begin();
273 }
275 return iterator(m_storage.entries.size(), &m_storage.entries);
276 }
278 return const_iterator(m_storage.entries.size(), &m_storage.entries);
279 }
281 return end();
282 }
283 // reverse iterators
285 return reverse_iterator(end());
286 }
291 return rbegin();
292 }
294 return reverse_iterator(begin());
295 }
300 return rend();
301 }
302
303
304 std::vector<std::int32_t> type(const size_t nElem = 0) const;
305 std::vector<float> chi2(const size_t nElem = 0) const;
306 std::vector<int> ndf(const size_t nElem = 0) const;
307 std::vector<edm4hep::Vector4f> position(const size_t nElem = 0) const;
308 std::vector<edm4eic::Cov4f> positionError(const size_t nElem = 0) const;
309
310private:
311 // For setReferences, we need to give our own CollectionData access to our
312 // private entries. Otherwise we would need to expose a public member function
313 // that gives access to the Obj* which is definitely not what we want
315
316 mutable bool m_isPrepared{false};
317 bool m_isSubsetColl{false};
318 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
319 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
320 mutable VertexCollectionData m_storage{};
321};
322
323std::ostream& operator<<(std::ostream& o, const VertexCollection& v);
324
325template<typename... Args>
327 if (m_isSubsetColl) {
328 throw std::logic_error("Cannot create new elements on a subset collection");
329 }
330 auto obj = new VertexObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
331 m_storage.entries.push_back(obj);
332
333 // Need to initialize the relation vectors manually for the {ObjectID, VertexData} constructor
334 obj->m_associatedParticles = new std::vector<edm4eic::ReconstructedParticle>();
335 m_storage.createRelations(obj);
336 return MutableVertex(podio::utils::MaybeSharedPtr(obj));
337}
338
339
340#if defined(__cpp_lib_containers_ranges)
341template<podio::detail::RangeConvertibleTo<VertexCollection::value_type> R>
342VertexCollection::VertexCollection(std::from_range_t, R&& range)
343 : VertexCollection() {
344 setSubsetCollection(podio::detail::RangeOf<R, value_type>);
345
346 for (auto&& elem : range) {
347 push_back(std::forward<decltype(elem)>(elem));
348 }
349}
350#endif
351
352template<podio::detail::RangeConvertibleTo<VertexCollection::value_type> R>
354 VertexCollection coll;
355 if constexpr (podio::detail::RangeOf<R, value_type>) {
356 coll.setSubsetCollection();
357 }
358
359 for (auto&& elem : range) {
360 coll.push_back(std::forward<decltype(elem)>(elem));
361 }
362
363 return coll;
364}
365
366
367#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
368void to_json(nlohmann::json& j, const VertexCollection& collection);
369#endif
370
371} // namespace edm4eic
372
373
374// This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
375// until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
376// and https://github.com/AIDASoft/podio/issues/770
377#if defined(__clang__)
378 #pragma clang diagnostic push
379 #pragma clang diagnostic ignored "-Wunknown-warning-option"
380 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
381 #pragma clang diagnostic ignored "-Wdeprecated"
382constexpr std::string_view edm4eic::VertexCollection::typeName;
383constexpr std::string_view edm4eic::VertexCollection::valueTypeName;
384constexpr std::string_view edm4eic::VertexCollection::dataTypeName;
385 #pragma clang diagnostic pop
386#elif defined(__GNUC__)
387 #pragma GCC diagnostic push
388 #pragma GCC diagnostic ignored "-Wdeprecated"
389constexpr std::string_view edm4eic::VertexCollection::typeName;
390constexpr std::string_view edm4eic::VertexCollection::valueTypeName;
391constexpr std::string_view edm4eic::VertexCollection::dataTypeName;
392 #pragma GCC diagnostic pop
393#endif
394
395
396#endif
Definition MutableVertex.h:38
Definition VertexCollectionData.h:32
Definition VertexCollection.h:139
static constexpr std::string_view valueTypeName
Definition VertexCollection.h:170
const_iterator cbegin() const
Definition VertexCollection.h:271
MutableVertex create()
Append a new object to the collection, and return this object.
Definition VertexCollection.cc:77
void push_back(const MutableVertex &object)
Append object to the collection.
Definition VertexCollection.cc:122
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition VertexCollection.h:147
VertexCollection(VertexCollection &&)=default
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition VertexCollection.cc:154
size_t size_type
Definition VertexCollection.h:146
Vertex at(std::size_t index) const
Returns the const object of given index.
Definition VertexCollection.cc:36
std::size_t max_size() const final
maximal number of elements in the collection
Definition VertexCollection.cc:52
VertexCollection & operator=(const VertexCollection &)=delete
VertexCollectionIterator const_iterator
Definition VertexCollection.h:143
bool isValid() const final
Definition VertexCollection.h:258
void clear() final
Definition VertexCollection.cc:89
VertexCollection & operator=(VertexCollection &&)=default
bool hasID() const final
check if the collection has a valid ID
Definition VertexCollection.h:251
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition VertexCollection.h:203
const_reverse_iterator crbegin() const
Definition VertexCollection.h:290
~VertexCollection() override
Definition VertexCollection.cc:27
void prepareForWrite() const final
Definition VertexCollection.cc:94
static constexpr std::string_view dataTypeName
Definition VertexCollection.h:171
uint32_t getID() const final
Definition VertexCollection.h:246
reverse_iterator rend()
Definition VertexCollection.h:293
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition VertexCollection.cc:118
const_reverse_iterator rend() const
Definition VertexCollection.h:296
static constexpr std::string_view typeName
Definition VertexCollection.h:169
bool isSubsetCollection() const final
Definition VertexCollection.h:209
VertexCollection(const VertexCollection &)=delete
MutableVertex mutable_type
Definition VertexCollection.h:142
Vertex value_type
Definition VertexCollection.h:141
bool empty() const final
Is the collection empty.
Definition VertexCollection.cc:62
VertexMutableCollectionIterator iterator
Definition VertexCollection.h:144
static void __cppyy_pythonize__(PyObject *klass, const std::string &name)
Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
Definition VertexCollection.h:176
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition VertexCollection.cc:472
const_iterator begin() const
Definition VertexCollection.h:268
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition VertexCollection.h:205
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition VertexCollection.cc:213
static VertexCollection from(R &&range)
Definition VertexCollection.h:353
const std::string_view getTypeName() const final
fully qualified type name
Definition VertexCollection.h:201
void prepareAfterRead() final
Definition VertexCollection.cc:103
iterator end()
Definition VertexCollection.h:274
const_iterator end() const
Definition VertexCollection.h:277
ptrdiff_t difference_type
Definition VertexCollection.h:145
void setID(uint32_t ID) final
Definition VertexCollection.h:237
friend class VertexCollectionData
Definition VertexCollection.h:314
iterator begin()
Definition VertexCollection.h:265
const_iterator cend() const
Definition VertexCollection.h:280
const_reverse_iterator crend() const
Definition VertexCollection.h:299
reverse_iterator rbegin()
Definition VertexCollection.h:284
void setSubsetCollection(bool setSubset=true) final
Definition VertexCollection.cc:66
const_reverse_iterator rbegin() const
Definition VertexCollection.h:287
std::size_t size() const final
number of elements in the collection
Definition VertexCollection.cc:48
std::reverse_iterator< iterator > reverse_iterator
Definition VertexCollection.h:148
Definition VertexCollection.h:38
constexpr auto operator<=>(const VertexCollectionIterator &other) const
Definition VertexCollection.h:58
VertexCollectionIterator & operator--()
Definition VertexCollection.cc:331
std::random_access_iterator_tag iterator_concept
Definition VertexCollection.h:47
VertexCollectionIterator(VertexCollectionIterator &&)=default
VertexCollectionIterator operator-(difference_type n) const
Definition VertexCollection.cc:362
VertexCollectionIterator & operator=(const VertexCollectionIterator &)=default
std::input_iterator_tag iterator_category
Definition VertexCollection.h:44
pointer operator->()
Definition VertexCollection.cc:315
Vertex reference
Definition VertexCollection.h:42
reference operator*() const
Definition VertexCollection.cc:311
VertexCollectionIterator & operator=(VertexCollectionIterator &&)=default
Vertex * pointer
Definition VertexCollection.h:43
VertexCollectionIterator & operator++()
Definition VertexCollection.cc:320
VertexCollectionIterator(const VertexCollectionIterator &)=default
VertexCollectionIterator operator+(difference_type n) const
Definition VertexCollection.cc:347
VertexCollectionIterator & operator+=(difference_type n)
Definition VertexCollection.cc:342
Vertex value_type
Definition VertexCollection.h:40
ptrdiff_t difference_type
Definition VertexCollection.h:41
VertexCollectionIterator & operator-=(difference_type n)
Definition VertexCollection.cc:357
reference operator[](difference_type n) const
Definition VertexCollection.cc:368
VertexCollectionIterator(size_t index, const VertexObjPointerContainer *collection)
Definition VertexCollection.h:49
constexpr bool operator==(const VertexCollectionIterator &x) const
Definition VertexCollection.h:62
Definition Vertex.h:46
Definition VertexCollection.h:87
constexpr auto operator<=>(const VertexMutableCollectionIterator &other) const
Definition VertexCollection.h:107
VertexMutableCollectionIterator & operator++()
Definition VertexCollection.cc:387
reference operator[](difference_type n) const
Definition VertexCollection.cc:435
VertexMutableCollectionIterator(VertexMutableCollectionIterator &&)=default
std::input_iterator_tag iterator_category
Definition VertexCollection.h:93
VertexMutableCollectionIterator operator-(difference_type n) const
Definition VertexCollection.cc:429
VertexMutableCollectionIterator & operator=(const VertexMutableCollectionIterator &)=default
VertexMutableCollectionIterator & operator+=(difference_type n)
Definition VertexCollection.cc:409
MutableVertex * pointer
Definition VertexCollection.h:92
reference operator*() const
Definition VertexCollection.cc:378
VertexMutableCollectionIterator & operator--()
Definition VertexCollection.cc:398
VertexMutableCollectionIterator & operator=(VertexMutableCollectionIterator &&)=default
VertexMutableCollectionIterator operator+(difference_type n) const
Definition VertexCollection.cc:414
std::random_access_iterator_tag iterator_concept
Definition VertexCollection.h:96
VertexMutableCollectionIterator(const VertexMutableCollectionIterator &)=default
constexpr bool operator==(const VertexMutableCollectionIterator &x) const
Definition VertexCollection.h:111
Vertex value_type
Definition VertexCollection.h:89
ptrdiff_t difference_type
Definition VertexCollection.h:90
MutableVertex reference
Definition VertexCollection.h:91
pointer operator->()
Definition VertexCollection.cc:382
VertexMutableCollectionIterator(size_t index, const VertexObjPointerContainer *collection)
Definition VertexCollection.h:98
VertexMutableCollectionIterator & operator-=(difference_type n)
Definition VertexCollection.cc:424
Definition VertexObj.h:20
std::vector< edm4eic::ReconstructedParticle > * m_associatedParticles
Definition VertexObj.h:36
Definition ArrowMapper.cc:61
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:99
std::deque< VertexObj * > VertexObjPointerContainer
Definition VertexCollectionData.h:24
Definition CalorimeterHit.h:31