EICd
EIC data model
VertexCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_VertexCollection_H
4#define EICD_VertexCollection_H
5
6// datamodel specific includes
7#include "eicd/VertexData.h"
8#include "eicd/Vertex.h"
10#include "eicd/VertexObj.h"
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 VertexCollectionIterator(size_t index, const VertexObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
38
41
42 bool operator!=(const VertexCollectionIterator& x) const {
43 return m_index != x.m_index; // TODO: may not be complete
44 }
45
49
50private:
51 size_t m_index;
52 Vertex m_object;
53 const VertexObjPointerContainer* m_collection;
54};
55
56
58public:
59 VertexMutableCollectionIterator(size_t index, const VertexObjPointerContainer* 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;
74 MutableVertex m_object;
75 const VertexObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class VertexCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// VertexCollection(VertexVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 VertexCollection* operator->() { return (VertexCollection*) 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 MutableVertex 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::VertexCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::Vertex"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::VertexData"); }
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 Vertex operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableVertex operator[](unsigned int index);
130 /// Returns the const object of given index
131 Vertex at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableVertex at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(Vertex 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] (VertexObj* 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> primary() const;
180 template<size_t arraysize>
181 const std::array<float, arraysize> chi2() const;
182 template<size_t arraysize>
183 const std::array<float, arraysize> probability() const;
184 template<size_t arraysize>
185 const std::array<edm4hep::Vector3f, arraysize> position() const;
186 template<size_t arraysize>
187 const std::array<eicd::Cov3f, arraysize> positionError() const;
188 template<size_t arraysize>
189 const std::array<std::int32_t, arraysize> algorithmType() const;
190 template<size_t arraysize>
191 const std::array<float, arraysize> time() const;
192
193private:
194 // For setReferences, we need to give our own CollectionData access to our
195 // private entries. Otherwise we would need to expose a public member function
196 // that gives access to the Obj* which is definitely not what we want
198
199 bool m_isValid{false};
200 mutable bool m_isPrepared{false};
201 bool m_isSubsetColl{false};
202 int m_collectionID{0};
203 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
204 mutable VertexCollectionData m_storage{};
205};
206
207std::ostream& operator<<(std::ostream& o, const VertexCollection& v);
208
209template<typename... Args>
210MutableVertex VertexCollection::create(Args&&... args) {
211 if (m_isSubsetColl) {
212 throw std::logic_error("Cannot create new elements on a subset collection");
213 }
214 const int size = m_storage.entries.size();
215 auto obj = new VertexObj({size, m_collectionID}, {std::forward<Args>(args)...});
216 m_storage.entries.push_back(obj);
217
218 // Need to initialize the relation vectors manually for the {ObjectID, VertexData} constructor
219 obj->m_parameters = new std::vector<float>();
220 m_storage.createRelations(obj);
221 return MutableVertex(obj);
222}
223
224template<size_t arraysize>
225const std::array<std::int32_t, arraysize> VertexCollection::primary() const {
226 std::array<std::int32_t, arraysize> tmp{};
227 const auto valid_size = std::min(arraysize, m_storage.entries.size());
228 for (unsigned i = 0; i < valid_size; ++i) {
229 tmp[i] = m_storage.entries[i]->data.primary;
230 }
231 return tmp;
232}
233
234template<size_t arraysize>
235const std::array<float, arraysize> VertexCollection::chi2() const {
236 std::array<float, arraysize> tmp{};
237 const auto valid_size = std::min(arraysize, m_storage.entries.size());
238 for (unsigned i = 0; i < valid_size; ++i) {
239 tmp[i] = m_storage.entries[i]->data.chi2;
240 }
241 return tmp;
242}
243
244template<size_t arraysize>
245const std::array<float, arraysize> VertexCollection::probability() const {
246 std::array<float, arraysize> tmp{};
247 const auto valid_size = std::min(arraysize, m_storage.entries.size());
248 for (unsigned i = 0; i < valid_size; ++i) {
249 tmp[i] = m_storage.entries[i]->data.probability;
250 }
251 return tmp;
252}
253
254template<size_t arraysize>
255const std::array<edm4hep::Vector3f, arraysize> VertexCollection::position() const {
256 std::array<edm4hep::Vector3f, arraysize> tmp{};
257 const auto valid_size = std::min(arraysize, m_storage.entries.size());
258 for (unsigned i = 0; i < valid_size; ++i) {
259 tmp[i] = m_storage.entries[i]->data.position;
260 }
261 return tmp;
262}
263
264template<size_t arraysize>
265const std::array<eicd::Cov3f, arraysize> VertexCollection::positionError() const {
266 std::array<eicd::Cov3f, arraysize> tmp{};
267 const auto valid_size = std::min(arraysize, m_storage.entries.size());
268 for (unsigned i = 0; i < valid_size; ++i) {
269 tmp[i] = m_storage.entries[i]->data.positionError;
270 }
271 return tmp;
272}
273
274template<size_t arraysize>
275const std::array<std::int32_t, arraysize> VertexCollection::algorithmType() const {
276 std::array<std::int32_t, arraysize> tmp{};
277 const auto valid_size = std::min(arraysize, m_storage.entries.size());
278 for (unsigned i = 0; i < valid_size; ++i) {
279 tmp[i] = m_storage.entries[i]->data.algorithmType;
280 }
281 return tmp;
282}
283
284template<size_t arraysize>
285const std::array<float, arraysize> VertexCollection::time() const {
286 std::array<float, arraysize> tmp{};
287 const auto valid_size = std::min(arraysize, m_storage.entries.size());
288 for (unsigned i = 0; i < valid_size; ++i) {
289 tmp[i] = m_storage.entries[i]->data.time;
290 }
291 return tmp;
292}
293
294
295#ifdef PODIO_JSON_OUTPUT
296void to_json(nlohmann::json& j, const VertexCollection& collection);
297#endif
298
299} // namespace eicd
300
301
302#endif
Definition: MutableVertex.h:36
Definition: VertexCollectionData.h:29
VertexObjPointerContainer entries
Definition: VertexCollectionData.h:34
Definition: VertexCollection.h:82
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: VertexCollection.h:118
void push_back(Vertex object)
Append object to the collection.
Definition: VertexCollection.cc:111
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: VertexCollection.cc:137
VertexCollection()
Definition: VertexCollection.cc:15
~VertexCollection()
Definition: VertexCollection.cc:18
VertexCollection(VertexCollection &&)=default
void setID(unsigned ID) final
Definition: VertexCollection.h:146
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: VertexCollection.cc:107
iterator begin()
Definition: VertexCollection.h:165
void clear() final
Definition: VertexCollection.cc:66
VertexCollection(const VertexCollection &)=delete
const_iterator end() const
Definition: VertexCollection.h:174
bool isSubsetCollection() const final
Definition: VertexCollection.h:120
Vertex at(unsigned int index) const
Returns the const object of given index.
Definition: VertexCollection.cc:27
VertexCollection & operator=(VertexCollection &&)=default
unsigned getID() const final
Definition: VertexCollection.h:156
iterator end()
Definition: VertexCollection.h:171
bool isValid() const final
Definition: VertexCollection.h:160
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: VertexCollection.h:116
size_t size() const final
number of elements in the collection
Definition: VertexCollection.cc:39
void prepareForWrite() const final
Definition: VertexCollection.cc:71
void setSubsetCollection(bool setSubset=true) final
Definition: VertexCollection.cc:43
void prepareAfterRead() final
Definition: VertexCollection.cc:92
const_iterator begin() const
Definition: VertexCollection.h:168
std::string getTypeName() const final
fully qualified type name
Definition: VertexCollection.h:114
MutableVertex create()
Append a new object to the collection, and return this object.
Definition: VertexCollection.cc:54
VertexCollection & operator=(const VertexCollection &)=delete
Definition: VertexCollection.h:35
VertexCollectionIterator(size_t index, const VertexObjPointerContainer *collection)
Definition: VertexCollection.h:37
VertexCollectionIterator & operator++()
Definition: VertexCollection.cc:161
Vertex operator*()
Definition: VertexCollection.cc:151
bool operator!=(const VertexCollectionIterator &x) const
Definition: VertexCollection.h:42
VertexCollectionIterator & operator=(const VertexCollectionIterator &)=delete
VertexCollectionIterator(const VertexCollectionIterator &)=delete
Vertex * operator->()
Definition: VertexCollection.cc:156
Definition: Vertex.h:35
Definition: VertexCollection.h:57
VertexMutableCollectionIterator(const VertexMutableCollectionIterator &)=delete
VertexMutableCollectionIterator(size_t index, const VertexObjPointerContainer *collection)
Definition: VertexCollection.h:59
VertexMutableCollectionIterator & operator=(const VertexMutableCollectionIterator &)=delete
VertexMutableCollectionIterator & operator++()
Definition: VertexCollection.cc:178
MutableVertex * operator->()
Definition: VertexCollection.cc:173
MutableVertex operator*()
Definition: VertexCollection.cc:168
bool operator!=(const VertexMutableCollectionIterator &x) const
Definition: VertexCollection.h:64
Definition: VertexObj.h:22
std::vector< float > * m_parameters
Definition: VertexObj.h:38
Definition: CalorimeterHit.cc:13
std::deque< VertexObj * > VertexObjPointerContainer
Definition: VertexCollectionData.h:21
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93