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
16#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
17#include "nlohmann/json_fwd.hpp"
18#endif
19
20#include <string_view>
21#include <vector>
22#include <algorithm>
23#include <ostream>
24#include <mutex>
25#include <memory>
26#include <cstddef>
27
28namespace podio {
29 struct RelationNames;
30}
31
32namespace edm4eic {
33
34
35
37public:
39 using difference_type = ptrdiff_t;
42 using iterator_category = std::input_iterator_tag;
43 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
44 // remain valid as long as the iterator is valid, not as long as the range is valid.
45 using iterator_concept = std::random_access_iterator_tag;
46
47 ReconstructedParticleCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}), m_collection(collection) {}
49
55
57 return m_index <=> other.m_index;
58 }
59
61 return m_index == x.m_index;
62 }
63
64 reference operator*() const;
77
78private:
79 size_t m_index{0};
80 ReconstructedParticle m_object { podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr} };
81 const ReconstructedParticleObjPointerContainer* m_collection{nullptr};
82};
83
84
86public:
88 using difference_type = ptrdiff_t;
91 using iterator_category = std::input_iterator_tag;
92 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
93 // remain valid as long as the iterator is valid, not as long as the range is valid.
94 using iterator_concept = std::random_access_iterator_tag;
95
96 ReconstructedParticleMutableCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr}), m_collection(collection) {}
98
104
106 return m_index <=> other.m_index;
107 }
108
110 return m_index == x.m_index;
111 }
112
113 reference operator*() const;
126
127private:
128 size_t m_index{0};
129 MutableReconstructedParticle m_object { podio::utils::MaybeSharedPtr<ReconstructedParticleObj>{nullptr} };
130 const ReconstructedParticleObjPointerContainer* m_collection{nullptr};
131};
132
133
134/**
135A Collection is identified by an ID.
136*/
137class ReconstructedParticleCollection : public podio::CollectionBase {
138public:
143 using difference_type = ptrdiff_t;
144 using size_type = size_t;
145 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
146 using reverse_iterator = std::reverse_iterator<iterator>;
147
150 // This is a move-only type
155
156// ReconstructedParticleCollection(ReconstructedParticleVector* data, uint32_t collectionID);
158
159 constexpr static std::string_view typeName = "edm4eic::ReconstructedParticleCollection";
160 constexpr static std::string_view valueTypeName = "edm4eic::ReconstructedParticle";
161 constexpr static std::string_view dataTypeName = "edm4eic::ReconstructedParticleData";
162
163 void clear() final;
164
165 /// Print this collection to the passed stream
166 void print(std::ostream& os=std::cout, bool flush=true) const final;
167
168 /// operator to allow pointer like calling of members a la LCIO
169 ReconstructedParticleCollection* operator->() { return static_cast<ReconstructedParticleCollection*>(this); }
170
171 /// Append a new object to the collection, and return this object.
173
174 /// Append a new object to the collection, and return this object.
175 /// Initialized with the parameters given
176 template<typename... Args>
177 MutableReconstructedParticle create(Args&&... args);
178
179 /// number of elements in the collection
180 std::size_t size() const final;
181
182 /// maximal number of elements in the collection
183 std::size_t max_size() const final;
184
185 /// Is the collection empty
186 bool empty() const final;
187
188 /// fully qualified type name
189 const std::string_view getTypeName() const final { return typeName; }
190 /// fully qualified type name of elements - with namespace
191 const std::string_view getValueTypeName() const final { return valueTypeName; }
192 /// fully qualified type name of stored POD elements - with namespace
193 const std::string_view getDataTypeName() const final { return dataTypeName; }
194 /// schema version
195 podio::SchemaVersionT getSchemaVersion() const final;
196
197 bool isSubsetCollection() const final {
198 return m_isSubsetColl;
199 }
200
201 void setSubsetCollection(bool setSubset=true) final;
202
203 /// Returns the const object of given index
204 ReconstructedParticle operator[](std::size_t index) const;
205 /// Returns the object of a given index
206 MutableReconstructedParticle operator[](std::size_t index);
207 /// Returns the const object of given index
208 ReconstructedParticle at(std::size_t index) const;
209 /// Returns the object of given index
210 MutableReconstructedParticle at(std::size_t index);
211
212
213 /// Append object to the collection
214 void push_back(const MutableReconstructedParticle& object);
215 /// Append an object to the (subset) collection
216 void push_back(const ReconstructedParticle& object);
217
218 void prepareForWrite() const final;
219 void prepareAfterRead() final;
220 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
221
222 /// Get the collection buffers for this collection
223 podio::CollectionWriteBuffers getBuffers() final;
224
225 void setID(uint32_t ID) final {
226 m_collectionID = ID;
227 if (!m_isSubsetColl) {
228 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
229 [ID] (ReconstructedParticleObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
230 );
231 }
232 m_isValid = true;
233 }
234
235 uint32_t getID() const final {
236 return m_collectionID;
237 }
238
239 bool isValid() const final {
240 return m_isValid;
241 }
242
243 size_t getDatamodelRegistryIndex() const final;
244
245 // support for the iterator protocol
247 return iterator(0, &m_storage.entries);
248 }
250 return const_iterator(0, &m_storage.entries);
251 }
253 return begin();
254 }
256 return iterator(m_storage.entries.size(), &m_storage.entries);
257 }
259 return const_iterator(m_storage.entries.size(), &m_storage.entries);
260 }
262 return end();
263 }
264 // reverse iterators
266 return reverse_iterator(end());
267 }
272 return rbegin();
273 }
275 return reverse_iterator(begin());
276 }
281 return rend();
282 }
283
284
285 std::vector<std::int32_t> type(const size_t nElem = 0) const;
286 std::vector<float> energy(const size_t nElem = 0) const;
287 std::vector<edm4hep::Vector3f> momentum(const size_t nElem = 0) const;
288 std::vector<edm4hep::Vector3f> referencePoint(const size_t nElem = 0) const;
289 std::vector<float> charge(const size_t nElem = 0) const;
290 std::vector<float> mass(const size_t nElem = 0) const;
291 std::vector<float> goodnessOfPID(const size_t nElem = 0) const;
292 std::vector<edm4eic::Cov4f> covMatrix(const size_t nElem = 0) const;
293 std::vector<std::int32_t> PDG(const size_t nElem = 0) const;
294
295private:
296 // For setReferences, we need to give our own CollectionData access to our
297 // private entries. Otherwise we would need to expose a public member function
298 // that gives access to the Obj* which is definitely not what we want
300
301 bool m_isValid{false};
302 mutable bool m_isPrepared{false};
303 bool m_isSubsetColl{false};
304 uint32_t m_collectionID{0};
305 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
306 mutable ReconstructedParticleCollectionData m_storage{};
307};
308
309std::ostream& operator<<(std::ostream& o, const ReconstructedParticleCollection& v);
310
311template<typename... Args>
313 if (m_isSubsetColl) {
314 throw std::logic_error("Cannot create new elements on a subset collection");
315 }
316 const int size = m_storage.entries.size();
317 auto obj = new ReconstructedParticleObj({size, m_collectionID}, {std::forward<Args>(args)...});
318 m_storage.entries.push_back(obj);
319
320 // Need to initialize the relation vectors manually for the {ObjectID, ReconstructedParticleData} constructor
321 obj->m_clusters = new std::vector<edm4eic::Cluster>();
322 obj->m_tracks = new std::vector<edm4eic::Track>();
323 obj->m_particles = new std::vector<edm4eic::ReconstructedParticle>();
324 obj->m_particleIDs = new std::vector<edm4hep::ParticleID>();
325 m_storage.createRelations(obj);
326 return MutableReconstructedParticle(podio::utils::MaybeSharedPtr(obj));
327}
328
329#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
330void to_json(nlohmann::json& j, const ReconstructedParticleCollection& collection);
331#endif
332
333} // namespace edm4eic
334
335
336#endif
Definition MutableReconstructedParticle.h:46
Definition ReconstructedParticleCollectionData.h:34
Definition ReconstructedParticleCollection.h:137
void clear() final
Definition ReconstructedParticleCollection.cc:95
void setSubsetCollection(bool setSubset=true) final
Definition ReconstructedParticleCollection.cc:72
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition ReconstructedParticleCollection.h:193
ReconstructedParticle at(std::size_t index) const
Returns the const object of given index.
Definition ReconstructedParticleCollection.cc:42
friend class ReconstructedParticleCollectionData
Definition ReconstructedParticleCollection.h:299
ReconstructedParticleCollection()
Definition ReconstructedParticleCollection.cc:27
ReconstructedParticleCollectionIterator const_iterator
Definition ReconstructedParticleCollection.h:141
reverse_iterator rend()
Definition ReconstructedParticleCollection.h:274
MutableReconstructedParticle create()
Append a new object to the collection, and return this object.
Definition ReconstructedParticleCollection.cc:83
iterator end()
Definition ReconstructedParticleCollection.h:255
ptrdiff_t difference_type
Definition ReconstructedParticleCollection.h:143
const_iterator begin() const
Definition ReconstructedParticleCollection.h:249
static constexpr std::string_view dataTypeName
Definition ReconstructedParticleCollection.h:161
ReconstructedParticleCollection(ReconstructedParticleCollection &&)=default
void setID(uint32_t ID) final
Definition ReconstructedParticleCollection.h:225
bool empty() const final
Is the collection empty.
Definition ReconstructedParticleCollection.cc:68
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ReconstructedParticleCollection.h:145
std::size_t size() const final
number of elements in the collection
Definition ReconstructedParticleCollection.cc:54
ReconstructedParticle value_type
Definition ReconstructedParticleCollection.h:139
ReconstructedParticleCollection & operator=(ReconstructedParticleCollection &&)=default
const_reverse_iterator rbegin() const
Definition ReconstructedParticleCollection.h:268
size_t size_type
Definition ReconstructedParticleCollection.h:144
void push_back(const MutableReconstructedParticle &object)
Append object to the collection.
Definition ReconstructedParticleCollection.cc:128
ReconstructedParticleCollection & operator=(const ReconstructedParticleCollection &)=delete
std::reverse_iterator< iterator > reverse_iterator
Definition ReconstructedParticleCollection.h:146
void prepareAfterRead() final
Definition ReconstructedParticleCollection.cc:109
const_iterator cend() const
Definition ReconstructedParticleCollection.h:261
bool isSubsetCollection() const final
Definition ReconstructedParticleCollection.h:197
const_iterator cbegin() const
Definition ReconstructedParticleCollection.h:252
void prepareForWrite() const final
Definition ReconstructedParticleCollection.cc:100
uint32_t getID() const final
Definition ReconstructedParticleCollection.h:235
~ReconstructedParticleCollection() override
Definition ReconstructedParticleCollection.cc:33
ReconstructedParticleCollection(const ReconstructedParticleCollection &)=delete
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition ReconstructedParticleCollection.cc:260
const_reverse_iterator crbegin() const
Definition ReconstructedParticleCollection.h:271
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition ReconstructedParticleCollection.cc:124
std::size_t max_size() const final
maximal number of elements in the collection
Definition ReconstructedParticleCollection.cc:58
iterator begin()
Definition ReconstructedParticleCollection.h:246
const_reverse_iterator crend() const
Definition ReconstructedParticleCollection.h:280
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition ReconstructedParticleCollection.cc:161
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition ReconstructedParticleCollection.cc:547
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition ReconstructedParticleCollection.h:191
MutableReconstructedParticle mutable_type
Definition ReconstructedParticleCollection.h:140
static constexpr std::string_view valueTypeName
Definition ReconstructedParticleCollection.h:160
ReconstructedParticleMutableCollectionIterator iterator
Definition ReconstructedParticleCollection.h:142
const_reverse_iterator rend() const
Definition ReconstructedParticleCollection.h:277
static constexpr std::string_view typeName
Definition ReconstructedParticleCollection.h:159
bool isValid() const final
Definition ReconstructedParticleCollection.h:239
const std::string_view getTypeName() const final
fully qualified type name
Definition ReconstructedParticleCollection.h:189
reverse_iterator rbegin()
Definition ReconstructedParticleCollection.h:265
const_iterator end() const
Definition ReconstructedParticleCollection.h:258
Definition ReconstructedParticleCollection.h:36
reference operator*() const
Definition ReconstructedParticleCollection.cc:363
bool operator==(const ReconstructedParticleCollectionIterator &x) const
Definition ReconstructedParticleCollection.h:60
std::input_iterator_tag iterator_category
Definition ReconstructedParticleCollection.h:42
ReconstructedParticleCollectionIterator & operator--()
Definition ReconstructedParticleCollection.cc:383
ReconstructedParticleCollectionIterator & operator=(ReconstructedParticleCollectionIterator &&)=default
ReconstructedParticleCollectionIterator operator+(difference_type n) const
Definition ReconstructedParticleCollection.cc:399
ReconstructedParticleCollectionIterator & operator++()
Definition ReconstructedParticleCollection.cc:372
ReconstructedParticleCollectionIterator operator-(difference_type n) const
Definition ReconstructedParticleCollection.cc:414
ReconstructedParticle * pointer
Definition ReconstructedParticleCollection.h:41
ReconstructedParticle value_type
Definition ReconstructedParticleCollection.h:38
ReconstructedParticleCollectionIterator(const ReconstructedParticleCollectionIterator &)=default
ReconstructedParticleCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer *collection)
Definition ReconstructedParticleCollection.h:47
reference operator[](difference_type n) const
Definition ReconstructedParticleCollection.cc:420
auto operator<=>(const ReconstructedParticleCollectionIterator &other) const
Definition ReconstructedParticleCollection.h:56
ReconstructedParticleCollectionIterator & operator-=(difference_type n)
Definition ReconstructedParticleCollection.cc:409
ptrdiff_t difference_type
Definition ReconstructedParticleCollection.h:39
ReconstructedParticleCollectionIterator & operator=(const ReconstructedParticleCollectionIterator &)=default
pointer operator->()
Definition ReconstructedParticleCollection.cc:367
ReconstructedParticleCollectionIterator & operator+=(difference_type n)
Definition ReconstructedParticleCollection.cc:394
std::random_access_iterator_tag iterator_concept
Definition ReconstructedParticleCollection.h:45
ReconstructedParticle reference
Definition ReconstructedParticleCollection.h:40
ReconstructedParticleCollectionIterator(ReconstructedParticleCollectionIterator &&)=default
Definition ReconstructedParticle.h:54
Definition ReconstructedParticleCollection.h:85
ReconstructedParticleMutableCollectionIterator operator+(difference_type n) const
Definition ReconstructedParticleCollection.cc:466
ReconstructedParticleMutableCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer *collection)
Definition ReconstructedParticleCollection.h:96
ReconstructedParticle value_type
Definition ReconstructedParticleCollection.h:87
ReconstructedParticleMutableCollectionIterator(const ReconstructedParticleMutableCollectionIterator &)=default
std::random_access_iterator_tag iterator_concept
Definition ReconstructedParticleCollection.h:94
MutableReconstructedParticle * pointer
Definition ReconstructedParticleCollection.h:90
ReconstructedParticleMutableCollectionIterator & operator-=(difference_type n)
Definition ReconstructedParticleCollection.cc:476
reference operator[](difference_type n) const
Definition ReconstructedParticleCollection.cc:487
ptrdiff_t difference_type
Definition ReconstructedParticleCollection.h:88
reference operator*() const
Definition ReconstructedParticleCollection.cc:430
ReconstructedParticleMutableCollectionIterator & operator+=(difference_type n)
Definition ReconstructedParticleCollection.cc:461
ReconstructedParticleMutableCollectionIterator & operator++()
Definition ReconstructedParticleCollection.cc:439
auto operator<=>(const ReconstructedParticleMutableCollectionIterator &other) const
Definition ReconstructedParticleCollection.h:105
ReconstructedParticleMutableCollectionIterator & operator=(ReconstructedParticleMutableCollectionIterator &&)=default
ReconstructedParticleMutableCollectionIterator operator-(difference_type n) const
Definition ReconstructedParticleCollection.cc:481
ReconstructedParticleMutableCollectionIterator(ReconstructedParticleMutableCollectionIterator &&)=default
ReconstructedParticleMutableCollectionIterator & operator=(const ReconstructedParticleMutableCollectionIterator &)=default
MutableReconstructedParticle reference
Definition ReconstructedParticleCollection.h:89
bool operator==(const ReconstructedParticleMutableCollectionIterator &x) const
Definition ReconstructedParticleCollection.h:109
ReconstructedParticleMutableCollectionIterator & operator--()
Definition ReconstructedParticleCollection.cc:450
pointer operator->()
Definition ReconstructedParticleCollection.cc:434
std::input_iterator_tag iterator_category
Definition ReconstructedParticleCollection.h:91
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:26
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
Definition CalorimeterHit.h:31