EICd
EIC data model
ReconstructedParticleCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_ReconstructedParticleCollection_H
4#define EICD_ReconstructedParticleCollection_H
5
6// datamodel specific includes
12
13// podio specific includes
14#include "podio/ICollectionProvider.h"
15#include "podio/CollectionBase.h"
16#include "podio/CollectionIDTable.h"
17
18#ifdef PODIO_JSON_OUTPUT
19#include "nlohmann/json.hpp"
20#endif
21
22#include <string>
23#include <vector>
24#include <deque>
25#include <array>
26#include <algorithm>
27#include <ostream>
28#include <mutex>
29#include <memory>
30
31namespace eicd {
32
33
34
36public:
37 ReconstructedParticleCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
38
41
43 return m_index != x.m_index; // TODO: may not be complete
44 }
45
49
50private:
51 size_t m_index;
52 ReconstructedParticle m_object;
54};
55
56
58public:
59 ReconstructedParticleMutableCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
60
63
65 return m_index != x.m_index; // TODO: may not be complete
66 }
67
71
72private:
73 size_t m_index;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class ReconstructedParticleCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// ReconstructedParticleCollection(ReconstructedParticleVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
101
102 /// Append a new object to the collection, and return this object.
104
105 /// Append a new object to the collection, and return this object.
106 /// Initialized with the parameters given
107 template<typename... Args>
108 MutableReconstructedParticle create(Args&&... args);
109
110 /// number of elements in the collection
111 size_t size() const final;
112
113 /// fully qualified type name
114 std::string getTypeName() const final { return std::string("eicd::ReconstructedParticleCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::ReconstructedParticle"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::ReconstructedParticleData"); }
119
120 bool isSubsetCollection() const final {
121 return m_isSubsetColl;
122 }
123
124 void setSubsetCollection(bool setSubset=true) final;
125
126 /// Returns the const object of given index
127 ReconstructedParticle operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableReconstructedParticle operator[](unsigned int index);
130 /// Returns the const object of given index
131 ReconstructedParticle at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableReconstructedParticle at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(ReconstructedParticle object);
138
139 void prepareForWrite() const final;
140 void prepareAfterRead() final;
141 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
142
143 /// Get the collection buffers for this collection
144 podio::CollectionBuffers getBuffers() final;
145
146 void setID(unsigned ID) final {
147 m_collectionID = ID;
148 if (!m_isSubsetColl) {
149 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
150 [ID] (ReconstructedParticleObj* obj) { obj->id = {obj->id.index, static_cast<int>(ID)}; }
151 );
152 }
153 m_isValid = true;
154 };
155
156 unsigned getID() const final {
157 return m_collectionID;
158 }
159
160 bool isValid() const final {
161 return m_isValid;
162 }
163
164 // support for the iterator protocol
166 return iterator(0, &m_storage.entries);
167 }
169 return const_iterator(0, &m_storage.entries);
170 }
172 return iterator(m_storage.entries.size(), &m_storage.entries);
173 }
175 return const_iterator(m_storage.entries.size(), &m_storage.entries);
176 }
177
178 template<size_t arraysize>
179 const std::array<std::int32_t, arraysize> type() const;
180 template<size_t arraysize>
181 const std::array<float, arraysize> energy() const;
182 template<size_t arraysize>
183 const std::array<edm4hep::Vector3f, arraysize> momentum() const;
184 template<size_t arraysize>
185 const std::array<edm4hep::Vector3f, arraysize> referencePoint() const;
186 template<size_t arraysize>
187 const std::array<float, arraysize> charge() const;
188 template<size_t arraysize>
189 const std::array<float, arraysize> mass() const;
190 template<size_t arraysize>
191 const std::array<float, arraysize> goodnessOfPID() const;
192 template<size_t arraysize>
193 const std::array<eicd::Cov4f, arraysize> covMatrix() const;
194 template<size_t arraysize>
195 const std::array<std::int32_t, arraysize> PDG() const;
196
197private:
198 // For setReferences, we need to give our own CollectionData access to our
199 // private entries. Otherwise we would need to expose a public member function
200 // that gives access to the Obj* which is definitely not what we want
202
203 bool m_isValid{false};
204 mutable bool m_isPrepared{false};
205 bool m_isSubsetColl{false};
206 int m_collectionID{0};
207 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
208 mutable ReconstructedParticleCollectionData m_storage{};
209};
210
211std::ostream& operator<<(std::ostream& o, const ReconstructedParticleCollection& v);
212
213template<typename... Args>
214MutableReconstructedParticle ReconstructedParticleCollection::create(Args&&... args) {
215 if (m_isSubsetColl) {
216 throw std::logic_error("Cannot create new elements on a subset collection");
217 }
218 const int size = m_storage.entries.size();
219 auto obj = new ReconstructedParticleObj({size, m_collectionID}, {std::forward<Args>(args)...});
220 m_storage.entries.push_back(obj);
221
222 // Need to initialize the relation vectors manually for the {ObjectID, ReconstructedParticleData} constructor
223 obj->m_clusters = new std::vector<eicd::Cluster>();
224 obj->m_tracks = new std::vector<eicd::Track>();
225 obj->m_particles = new std::vector<eicd::ReconstructedParticle>();
226 obj->m_particleIDs = new std::vector<edm4hep::ParticleID>();
227 m_storage.createRelations(obj);
229}
230
231template<size_t arraysize>
232const std::array<std::int32_t, arraysize> ReconstructedParticleCollection::type() const {
233 std::array<std::int32_t, arraysize> tmp{};
234 const auto valid_size = std::min(arraysize, m_storage.entries.size());
235 for (unsigned i = 0; i < valid_size; ++i) {
236 tmp[i] = m_storage.entries[i]->data.type;
237 }
238 return tmp;
239}
240
241template<size_t arraysize>
242const std::array<float, arraysize> ReconstructedParticleCollection::energy() const {
243 std::array<float, arraysize> tmp{};
244 const auto valid_size = std::min(arraysize, m_storage.entries.size());
245 for (unsigned i = 0; i < valid_size; ++i) {
246 tmp[i] = m_storage.entries[i]->data.energy;
247 }
248 return tmp;
249}
250
251template<size_t arraysize>
252const std::array<edm4hep::Vector3f, arraysize> ReconstructedParticleCollection::momentum() const {
253 std::array<edm4hep::Vector3f, arraysize> tmp{};
254 const auto valid_size = std::min(arraysize, m_storage.entries.size());
255 for (unsigned i = 0; i < valid_size; ++i) {
256 tmp[i] = m_storage.entries[i]->data.momentum;
257 }
258 return tmp;
259}
260
261template<size_t arraysize>
262const std::array<edm4hep::Vector3f, arraysize> ReconstructedParticleCollection::referencePoint() const {
263 std::array<edm4hep::Vector3f, arraysize> tmp{};
264 const auto valid_size = std::min(arraysize, m_storage.entries.size());
265 for (unsigned i = 0; i < valid_size; ++i) {
266 tmp[i] = m_storage.entries[i]->data.referencePoint;
267 }
268 return tmp;
269}
270
271template<size_t arraysize>
272const std::array<float, arraysize> ReconstructedParticleCollection::charge() const {
273 std::array<float, arraysize> tmp{};
274 const auto valid_size = std::min(arraysize, m_storage.entries.size());
275 for (unsigned i = 0; i < valid_size; ++i) {
276 tmp[i] = m_storage.entries[i]->data.charge;
277 }
278 return tmp;
279}
280
281template<size_t arraysize>
282const std::array<float, arraysize> ReconstructedParticleCollection::mass() const {
283 std::array<float, arraysize> tmp{};
284 const auto valid_size = std::min(arraysize, m_storage.entries.size());
285 for (unsigned i = 0; i < valid_size; ++i) {
286 tmp[i] = m_storage.entries[i]->data.mass;
287 }
288 return tmp;
289}
290
291template<size_t arraysize>
292const std::array<float, arraysize> ReconstructedParticleCollection::goodnessOfPID() const {
293 std::array<float, arraysize> tmp{};
294 const auto valid_size = std::min(arraysize, m_storage.entries.size());
295 for (unsigned i = 0; i < valid_size; ++i) {
296 tmp[i] = m_storage.entries[i]->data.goodnessOfPID;
297 }
298 return tmp;
299}
300
301template<size_t arraysize>
302const std::array<eicd::Cov4f, arraysize> ReconstructedParticleCollection::covMatrix() const {
303 std::array<eicd::Cov4f, arraysize> tmp{};
304 const auto valid_size = std::min(arraysize, m_storage.entries.size());
305 for (unsigned i = 0; i < valid_size; ++i) {
306 tmp[i] = m_storage.entries[i]->data.covMatrix;
307 }
308 return tmp;
309}
310
311template<size_t arraysize>
312const std::array<std::int32_t, arraysize> ReconstructedParticleCollection::PDG() const {
313 std::array<std::int32_t, arraysize> tmp{};
314 const auto valid_size = std::min(arraysize, m_storage.entries.size());
315 for (unsigned i = 0; i < valid_size; ++i) {
316 tmp[i] = m_storage.entries[i]->data.PDG;
317 }
318 return tmp;
319}
320
321
322#ifdef PODIO_JSON_OUTPUT
323void to_json(nlohmann::json& j, const ReconstructedParticleCollection& collection);
324#endif
325
326} // namespace eicd
327
328
329#endif
Definition: MutableReconstructedParticle.h:43
Definition: ReconstructedParticleCollectionData.h:32
ReconstructedParticleObjPointerContainer entries
Definition: ReconstructedParticleCollectionData.h:37
Definition: ReconstructedParticleCollection.h:82
void setID(unsigned ID) final
Definition: ReconstructedParticleCollection.h:146
ReconstructedParticle at(unsigned int index) const
Returns the const object of given index.
Definition: ReconstructedParticleCollection.cc:29
void push_back(ReconstructedParticle object)
Append object to the collection.
Definition: ReconstructedParticleCollection.cc:113
const_iterator end() const
Definition: ReconstructedParticleCollection.h:174
bool isValid() const final
Definition: ReconstructedParticleCollection.h:160
bool isSubsetCollection() const final
Definition: ReconstructedParticleCollection.h:120
void setSubsetCollection(bool setSubset=true) final
Definition: ReconstructedParticleCollection.cc:45
iterator begin()
Definition: ReconstructedParticleCollection.h:165
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: ReconstructedParticleCollection.cc:109
ReconstructedParticleCollection(const ReconstructedParticleCollection &)=delete
std::string getTypeName() const final
fully qualified type name
Definition: ReconstructedParticleCollection.h:114
unsigned getID() const final
Definition: ReconstructedParticleCollection.h:156
~ReconstructedParticleCollection()
Definition: ReconstructedParticleCollection.cc:20
ReconstructedParticleCollection & operator=(ReconstructedParticleCollection &&)=default
void prepareAfterRead() final
Definition: ReconstructedParticleCollection.cc:94
size_t size() const final
number of elements in the collection
Definition: ReconstructedParticleCollection.cc:41
void prepareForWrite() const final
Definition: ReconstructedParticleCollection.cc:73
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: ReconstructedParticleCollection.cc:139
iterator end()
Definition: ReconstructedParticleCollection.h:171
void clear() final
Definition: ReconstructedParticleCollection.cc:68
MutableReconstructedParticle create()
Append a new object to the collection, and return this object.
Definition: ReconstructedParticleCollection.cc:56
ReconstructedParticleCollection & operator=(const ReconstructedParticleCollection &)=delete
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: ReconstructedParticleCollection.h:116
ReconstructedParticleCollection()
Definition: ReconstructedParticleCollection.cc:17
const_iterator begin() const
Definition: ReconstructedParticleCollection.h:168
ReconstructedParticleCollection(ReconstructedParticleCollection &&)=default
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: ReconstructedParticleCollection.h:118
Definition: ReconstructedParticleCollection.h:35
ReconstructedParticleCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer *collection)
Definition: ReconstructedParticleCollection.h:37
ReconstructedParticle operator*()
Definition: ReconstructedParticleCollection.cc:153
ReconstructedParticleCollectionIterator & operator++()
Definition: ReconstructedParticleCollection.cc:163
ReconstructedParticle * operator->()
Definition: ReconstructedParticleCollection.cc:158
ReconstructedParticleCollectionIterator(const ReconstructedParticleCollectionIterator &)=delete
ReconstructedParticleCollectionIterator & operator=(const ReconstructedParticleCollectionIterator &)=delete
bool operator!=(const ReconstructedParticleCollectionIterator &x) const
Definition: ReconstructedParticleCollection.h:42
Definition: ReconstructedParticle.h:42
Definition: ReconstructedParticleCollection.h:57
ReconstructedParticleMutableCollectionIterator(size_t index, const ReconstructedParticleObjPointerContainer *collection)
Definition: ReconstructedParticleCollection.h:59
ReconstructedParticleMutableCollectionIterator(const ReconstructedParticleMutableCollectionIterator &)=delete
ReconstructedParticleMutableCollectionIterator & operator=(const ReconstructedParticleMutableCollectionIterator &)=delete
ReconstructedParticleMutableCollectionIterator & operator++()
Definition: ReconstructedParticleCollection.cc:180
bool operator!=(const ReconstructedParticleMutableCollectionIterator &x) const
Definition: ReconstructedParticleCollection.h:64
MutableReconstructedParticle * operator->()
Definition: ReconstructedParticleCollection.cc:175
MutableReconstructedParticle operator*()
Definition: ReconstructedParticleCollection.cc:170
Definition: ReconstructedParticleObj.h:28
std::vector< eicd::Cluster > * m_clusters
Definition: ReconstructedParticleObj.h:45
Definition: CalorimeterHit.cc:13
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93
std::deque< ReconstructedParticleObj * > ReconstructedParticleObjPointerContainer
Definition: ReconstructedParticleCollectionData.h:24