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