EICd
EIC data model
TrackParametersCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_TrackParametersCollection_H
4#define EICD_TrackParametersCollection_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 TrackParametersCollectionIterator(size_t index, const TrackParametersObjPointerContainer* 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 TrackParameters m_object;
53 const TrackParametersObjPointerContainer* m_collection;
54};
55
56
58public:
59 TrackParametersMutableCollectionIterator(size_t index, const TrackParametersObjPointerContainer* 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;
75 const TrackParametersObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class TrackParametersCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// TrackParametersCollection(TrackParametersVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 TrackParametersCollection* operator->() { return (TrackParametersCollection*) this; }
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 MutableTrackParameters 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::TrackParametersCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::TrackParameters"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::TrackParametersData"); }
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 TrackParameters operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableTrackParameters operator[](unsigned int index);
130 /// Returns the const object of given index
131 TrackParameters at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableTrackParameters at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(TrackParameters 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] (TrackParametersObj* 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<edm4hep::Vector2f, arraysize> loc() const;
182 template<size_t arraysize>
183 const std::array<eicd::Cov2f, arraysize> locError() const;
184 template<size_t arraysize>
185 const std::array<float, arraysize> theta() const;
186 template<size_t arraysize>
187 const std::array<float, arraysize> phi() const;
188 template<size_t arraysize>
189 const std::array<float, arraysize> qOverP() const;
190 template<size_t arraysize>
191 const std::array<eicd::Cov3f, arraysize> momentumError() const;
192 template<size_t arraysize>
193 const std::array<float, arraysize> time() const;
194 template<size_t arraysize>
195 const std::array<float, arraysize> timeError() const;
196 template<size_t arraysize>
197 const std::array<float, arraysize> charge() const;
198
199private:
200 // For setReferences, we need to give our own CollectionData access to our
201 // private entries. Otherwise we would need to expose a public member function
202 // that gives access to the Obj* which is definitely not what we want
204
205 bool m_isValid{false};
206 mutable bool m_isPrepared{false};
207 bool m_isSubsetColl{false};
208 int m_collectionID{0};
209 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
210 mutable TrackParametersCollectionData m_storage{};
211};
212
213std::ostream& operator<<(std::ostream& o, const TrackParametersCollection& v);
214
215template<typename... Args>
216MutableTrackParameters TrackParametersCollection::create(Args&&... args) {
217 if (m_isSubsetColl) {
218 throw std::logic_error("Cannot create new elements on a subset collection");
219 }
220 const int size = m_storage.entries.size();
221 auto obj = new TrackParametersObj({size, m_collectionID}, {std::forward<Args>(args)...});
222 m_storage.entries.push_back(obj);
223
224 return MutableTrackParameters(obj);
225}
226
227template<size_t arraysize>
228const std::array<std::int32_t, arraysize> TrackParametersCollection::type() const {
229 std::array<std::int32_t, arraysize> tmp{};
230 const auto valid_size = std::min(arraysize, m_storage.entries.size());
231 for (unsigned i = 0; i < valid_size; ++i) {
232 tmp[i] = m_storage.entries[i]->data.type;
233 }
234 return tmp;
235}
236
237template<size_t arraysize>
238const std::array<edm4hep::Vector2f, arraysize> TrackParametersCollection::loc() const {
239 std::array<edm4hep::Vector2f, arraysize> tmp{};
240 const auto valid_size = std::min(arraysize, m_storage.entries.size());
241 for (unsigned i = 0; i < valid_size; ++i) {
242 tmp[i] = m_storage.entries[i]->data.loc;
243 }
244 return tmp;
245}
246
247template<size_t arraysize>
248const std::array<eicd::Cov2f, arraysize> TrackParametersCollection::locError() const {
249 std::array<eicd::Cov2f, arraysize> tmp{};
250 const auto valid_size = std::min(arraysize, m_storage.entries.size());
251 for (unsigned i = 0; i < valid_size; ++i) {
252 tmp[i] = m_storage.entries[i]->data.locError;
253 }
254 return tmp;
255}
256
257template<size_t arraysize>
258const std::array<float, arraysize> TrackParametersCollection::theta() const {
259 std::array<float, arraysize> tmp{};
260 const auto valid_size = std::min(arraysize, m_storage.entries.size());
261 for (unsigned i = 0; i < valid_size; ++i) {
262 tmp[i] = m_storage.entries[i]->data.theta;
263 }
264 return tmp;
265}
266
267template<size_t arraysize>
268const std::array<float, arraysize> TrackParametersCollection::phi() const {
269 std::array<float, arraysize> tmp{};
270 const auto valid_size = std::min(arraysize, m_storage.entries.size());
271 for (unsigned i = 0; i < valid_size; ++i) {
272 tmp[i] = m_storage.entries[i]->data.phi;
273 }
274 return tmp;
275}
276
277template<size_t arraysize>
278const std::array<float, arraysize> TrackParametersCollection::qOverP() const {
279 std::array<float, arraysize> tmp{};
280 const auto valid_size = std::min(arraysize, m_storage.entries.size());
281 for (unsigned i = 0; i < valid_size; ++i) {
282 tmp[i] = m_storage.entries[i]->data.qOverP;
283 }
284 return tmp;
285}
286
287template<size_t arraysize>
288const std::array<eicd::Cov3f, arraysize> TrackParametersCollection::momentumError() const {
289 std::array<eicd::Cov3f, arraysize> tmp{};
290 const auto valid_size = std::min(arraysize, m_storage.entries.size());
291 for (unsigned i = 0; i < valid_size; ++i) {
292 tmp[i] = m_storage.entries[i]->data.momentumError;
293 }
294 return tmp;
295}
296
297template<size_t arraysize>
298const std::array<float, arraysize> TrackParametersCollection::time() const {
299 std::array<float, arraysize> tmp{};
300 const auto valid_size = std::min(arraysize, m_storage.entries.size());
301 for (unsigned i = 0; i < valid_size; ++i) {
302 tmp[i] = m_storage.entries[i]->data.time;
303 }
304 return tmp;
305}
306
307template<size_t arraysize>
308const std::array<float, arraysize> TrackParametersCollection::timeError() const {
309 std::array<float, arraysize> tmp{};
310 const auto valid_size = std::min(arraysize, m_storage.entries.size());
311 for (unsigned i = 0; i < valid_size; ++i) {
312 tmp[i] = m_storage.entries[i]->data.timeError;
313 }
314 return tmp;
315}
316
317template<size_t arraysize>
318const std::array<float, arraysize> TrackParametersCollection::charge() const {
319 std::array<float, arraysize> tmp{};
320 const auto valid_size = std::min(arraysize, m_storage.entries.size());
321 for (unsigned i = 0; i < valid_size; ++i) {
322 tmp[i] = m_storage.entries[i]->data.charge;
323 }
324 return tmp;
325}
326
327
328#ifdef PODIO_JSON_OUTPUT
329void to_json(nlohmann::json& j, const TrackParametersCollection& collection);
330#endif
331
332} // namespace eicd
333
334
335#endif
Definition: MutableTrackParameters.h:35
Definition: TrackParametersCollectionData.h:29
TrackParametersObjPointerContainer entries
Definition: TrackParametersCollectionData.h:34
Definition: TrackParametersCollection.h:82
TrackParametersCollection & operator=(const TrackParametersCollection &)=delete
TrackParametersCollection(const TrackParametersCollection &)=delete
TrackParameters at(unsigned int index) const
Returns the const object of given index.
Definition: TrackParametersCollection.cc:26
void clear() final
Definition: TrackParametersCollection.cc:64
void push_back(TrackParameters object)
Append object to the collection.
Definition: TrackParametersCollection.cc:109
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: TrackParametersCollection.h:118
unsigned getID() const final
Definition: TrackParametersCollection.h:156
void setSubsetCollection(bool setSubset=true) final
Definition: TrackParametersCollection.cc:42
MutableTrackParameters create()
Append a new object to the collection, and return this object.
Definition: TrackParametersCollection.cc:53
std::string getTypeName() const final
fully qualified type name
Definition: TrackParametersCollection.h:114
void prepareForWrite() const final
Definition: TrackParametersCollection.cc:69
TrackParametersCollection(TrackParametersCollection &&)=default
iterator begin()
Definition: TrackParametersCollection.h:165
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: TrackParametersCollection.cc:105
const_iterator end() const
Definition: TrackParametersCollection.h:174
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: TrackParametersCollection.cc:134
iterator end()
Definition: TrackParametersCollection.h:171
void prepareAfterRead() final
Definition: TrackParametersCollection.cc:90
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: TrackParametersCollection.h:116
bool isSubsetCollection() const final
Definition: TrackParametersCollection.h:120
TrackParametersCollection()
Definition: TrackParametersCollection.cc:14
void setID(unsigned ID) final
Definition: TrackParametersCollection.h:146
bool isValid() const final
Definition: TrackParametersCollection.h:160
~TrackParametersCollection()
Definition: TrackParametersCollection.cc:17
size_t size() const final
number of elements in the collection
Definition: TrackParametersCollection.cc:38
TrackParametersCollection & operator=(TrackParametersCollection &&)=default
const_iterator begin() const
Definition: TrackParametersCollection.h:168
Definition: TrackParametersCollection.h:35
TrackParameters * operator->()
Definition: TrackParametersCollection.cc:153
bool operator!=(const TrackParametersCollectionIterator &x) const
Definition: TrackParametersCollection.h:42
TrackParametersCollectionIterator & operator++()
Definition: TrackParametersCollection.cc:158
TrackParametersCollectionIterator(const TrackParametersCollectionIterator &)=delete
TrackParametersCollectionIterator & operator=(const TrackParametersCollectionIterator &)=delete
TrackParametersCollectionIterator(size_t index, const TrackParametersObjPointerContainer *collection)
Definition: TrackParametersCollection.h:37
TrackParameters operator*()
Definition: TrackParametersCollection.cc:148
Definition: TrackParameters.h:34
Definition: TrackParametersCollection.h:57
TrackParametersMutableCollectionIterator(const TrackParametersMutableCollectionIterator &)=delete
MutableTrackParameters * operator->()
Definition: TrackParametersCollection.cc:170
TrackParametersMutableCollectionIterator(size_t index, const TrackParametersObjPointerContainer *collection)
Definition: TrackParametersCollection.h:59
MutableTrackParameters operator*()
Definition: TrackParametersCollection.cc:165
TrackParametersMutableCollectionIterator & operator++()
Definition: TrackParametersCollection.cc:175
bool operator!=(const TrackParametersMutableCollectionIterator &x) const
Definition: TrackParametersCollection.h:64
TrackParametersMutableCollectionIterator & operator=(const TrackParametersMutableCollectionIterator &)=delete
Definition: TrackParametersObj.h:21
Definition: CalorimeterHit.cc:13
std::deque< TrackParametersObj * > TrackParametersObjPointerContainer
Definition: TrackParametersCollectionData.h:21
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93