EICd
EIC data model
ClusterCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_ClusterCollection_H
4#define EICD_ClusterCollection_H
5
6// datamodel specific includes
7#include "eicd/ClusterData.h"
8#include "eicd/Cluster.h"
10#include "eicd/ClusterObj.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 ClusterCollectionIterator(size_t index, const ClusterObjPointerContainer* 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 Cluster m_object;
53 const ClusterObjPointerContainer* m_collection;
54};
55
56
58public:
59 ClusterMutableCollectionIterator(size_t index, const ClusterObjPointerContainer* 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 MutableCluster m_object;
75 const ClusterObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class ClusterCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// ClusterCollection(ClusterVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 ClusterCollection* operator->() { return (ClusterCollection*) 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 MutableCluster 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::ClusterCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::Cluster"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::ClusterData"); }
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 Cluster operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableCluster operator[](unsigned int index);
130 /// Returns the const object of given index
131 Cluster at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableCluster at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(Cluster 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] (ClusterObj* 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<float, arraysize> energyError() const;
184 template<size_t arraysize>
185 const std::array<float, arraysize> time() const;
186 template<size_t arraysize>
187 const std::array<float, arraysize> timeError() const;
188 template<size_t arraysize>
189 const std::array<std::uint32_t, arraysize> nhits() const;
190 template<size_t arraysize>
191 const std::array<edm4hep::Vector3f, arraysize> position() const;
192 template<size_t arraysize>
193 const std::array<eicd::Cov3f, arraysize> positionError() const;
194 template<size_t arraysize>
195 const std::array<float, arraysize> intrinsicTheta() const;
196 template<size_t arraysize>
197 const std::array<float, arraysize> intrinsicPhi() const;
198 template<size_t arraysize>
199 const std::array<eicd::Cov2f, arraysize> intrinsicDirectionError() const;
200
201private:
202 // For setReferences, we need to give our own CollectionData access to our
203 // private entries. Otherwise we would need to expose a public member function
204 // that gives access to the Obj* which is definitely not what we want
206
207 bool m_isValid{false};
208 mutable bool m_isPrepared{false};
209 bool m_isSubsetColl{false};
210 int m_collectionID{0};
211 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
212 mutable ClusterCollectionData m_storage{};
213};
214
215std::ostream& operator<<(std::ostream& o, const ClusterCollection& v);
216
217template<typename... Args>
218MutableCluster ClusterCollection::create(Args&&... args) {
219 if (m_isSubsetColl) {
220 throw std::logic_error("Cannot create new elements on a subset collection");
221 }
222 const int size = m_storage.entries.size();
223 auto obj = new ClusterObj({size, m_collectionID}, {std::forward<Args>(args)...});
224 m_storage.entries.push_back(obj);
225
226 // Need to initialize the relation vectors manually for the {ObjectID, ClusterData} constructor
227 obj->m_clusters = new std::vector<eicd::Cluster>();
228 obj->m_hits = new std::vector<eicd::CalorimeterHit>();
229 obj->m_particleIDs = new std::vector<edm4hep::ParticleID>();
230 obj->m_shapeParameters = new std::vector<float>();
231 obj->m_hitContributions = new std::vector<float>();
232 obj->m_subdetectorEnergies = new std::vector<float>();
233 m_storage.createRelations(obj);
234 return MutableCluster(obj);
235}
236
237template<size_t arraysize>
238const std::array<std::int32_t, arraysize> ClusterCollection::type() const {
239 std::array<std::int32_t, 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.type;
243 }
244 return tmp;
245}
246
247template<size_t arraysize>
248const std::array<float, arraysize> ClusterCollection::energy() const {
249 std::array<float, 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.energy;
253 }
254 return tmp;
255}
256
257template<size_t arraysize>
258const std::array<float, arraysize> ClusterCollection::energyError() 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.energyError;
263 }
264 return tmp;
265}
266
267template<size_t arraysize>
268const std::array<float, arraysize> ClusterCollection::time() 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.time;
273 }
274 return tmp;
275}
276
277template<size_t arraysize>
278const std::array<float, arraysize> ClusterCollection::timeError() 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.timeError;
283 }
284 return tmp;
285}
286
287template<size_t arraysize>
288const std::array<std::uint32_t, arraysize> ClusterCollection::nhits() const {
289 std::array<std::uint32_t, 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.nhits;
293 }
294 return tmp;
295}
296
297template<size_t arraysize>
298const std::array<edm4hep::Vector3f, arraysize> ClusterCollection::position() const {
299 std::array<edm4hep::Vector3f, 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.position;
303 }
304 return tmp;
305}
306
307template<size_t arraysize>
308const std::array<eicd::Cov3f, arraysize> ClusterCollection::positionError() const {
309 std::array<eicd::Cov3f, 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.positionError;
313 }
314 return tmp;
315}
316
317template<size_t arraysize>
318const std::array<float, arraysize> ClusterCollection::intrinsicTheta() 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.intrinsicTheta;
323 }
324 return tmp;
325}
326
327template<size_t arraysize>
328const std::array<float, arraysize> ClusterCollection::intrinsicPhi() const {
329 std::array<float, arraysize> tmp{};
330 const auto valid_size = std::min(arraysize, m_storage.entries.size());
331 for (unsigned i = 0; i < valid_size; ++i) {
332 tmp[i] = m_storage.entries[i]->data.intrinsicPhi;
333 }
334 return tmp;
335}
336
337template<size_t arraysize>
338const std::array<eicd::Cov2f, arraysize> ClusterCollection::intrinsicDirectionError() const {
339 std::array<eicd::Cov2f, arraysize> tmp{};
340 const auto valid_size = std::min(arraysize, m_storage.entries.size());
341 for (unsigned i = 0; i < valid_size; ++i) {
342 tmp[i] = m_storage.entries[i]->data.intrinsicDirectionError;
343 }
344 return tmp;
345}
346
347
348#ifdef PODIO_JSON_OUTPUT
349void to_json(nlohmann::json& j, const ClusterCollection& collection);
350#endif
351
352} // namespace eicd
353
354
355#endif
Definition: ClusterCollectionData.h:30
ClusterObjPointerContainer entries
Definition: ClusterCollectionData.h:35
Definition: ClusterCollection.h:82
const_iterator begin() const
Definition: ClusterCollection.h:168
void prepareForWrite() const final
Definition: ClusterCollection.cc:72
ClusterCollection(ClusterCollection &&)=default
bool isValid() const final
Definition: ClusterCollection.h:160
void setID(unsigned ID) final
Definition: ClusterCollection.h:146
unsigned getID() const final
Definition: ClusterCollection.h:156
iterator begin()
Definition: ClusterCollection.h:165
void push_back(Cluster object)
Append object to the collection.
Definition: ClusterCollection.cc:112
ClusterCollection & operator=(ClusterCollection &&)=default
~ClusterCollection()
Definition: ClusterCollection.cc:19
iterator end()
Definition: ClusterCollection.h:171
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: ClusterCollection.h:118
std::string getTypeName() const final
fully qualified type name
Definition: ClusterCollection.h:114
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: ClusterCollection.cc:138
MutableCluster create()
Append a new object to the collection, and return this object.
Definition: ClusterCollection.cc:55
ClusterCollection(const ClusterCollection &)=delete
void setSubsetCollection(bool setSubset=true) final
Definition: ClusterCollection.cc:44
ClusterCollection & operator=(const ClusterCollection &)=delete
ClusterCollection()
Definition: ClusterCollection.cc:16
Cluster at(unsigned int index) const
Returns the const object of given index.
Definition: ClusterCollection.cc:28
void prepareAfterRead() final
Definition: ClusterCollection.cc:93
size_t size() const final
number of elements in the collection
Definition: ClusterCollection.cc:40
void clear() final
Definition: ClusterCollection.cc:67
const_iterator end() const
Definition: ClusterCollection.h:174
bool isSubsetCollection() const final
Definition: ClusterCollection.h:120
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: ClusterCollection.h:116
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: ClusterCollection.cc:108
Definition: ClusterCollection.h:35
bool operator!=(const ClusterCollectionIterator &x) const
Definition: ClusterCollection.h:42
ClusterCollectionIterator(size_t index, const ClusterObjPointerContainer *collection)
Definition: ClusterCollection.h:37
ClusterCollectionIterator & operator=(const ClusterCollectionIterator &)=delete
ClusterCollectionIterator(const ClusterCollectionIterator &)=delete
Cluster * operator->()
Definition: ClusterCollection.cc:157
ClusterCollectionIterator & operator++()
Definition: ClusterCollection.cc:162
Cluster operator*()
Definition: ClusterCollection.cc:152
Definition: Cluster.h:33
Definition: ClusterCollection.h:57
bool operator!=(const ClusterMutableCollectionIterator &x) const
Definition: ClusterCollection.h:64
ClusterMutableCollectionIterator(const ClusterMutableCollectionIterator &)=delete
MutableCluster * operator->()
Definition: ClusterCollection.cc:174
ClusterMutableCollectionIterator(size_t index, const ClusterObjPointerContainer *collection)
Definition: ClusterCollection.h:59
ClusterMutableCollectionIterator & operator=(const ClusterMutableCollectionIterator &)=delete
MutableCluster operator*()
Definition: ClusterCollection.cc:169
ClusterMutableCollectionIterator & operator++()
Definition: ClusterCollection.cc:179
Definition: ClusterObj.h:20
std::vector< eicd::Cluster > * m_clusters
Definition: ClusterObj.h:35
Definition: MutableCluster.h:34
Definition: CalorimeterHit.cc:13
std::deque< ClusterObj * > ClusterObjPointerContainer
Definition: ClusterCollectionData.h:22
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93