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