EICd
EIC data model
CalorimeterHitCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_CalorimeterHitCollection_H
4#define EICD_CalorimeterHitCollection_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 CalorimeterHitCollectionIterator(size_t index, const CalorimeterHitObjPointerContainer* 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 CalorimeterHit m_object;
53 const CalorimeterHitObjPointerContainer* m_collection;
54};
55
56
58public:
59 CalorimeterHitMutableCollectionIterator(size_t index, const CalorimeterHitObjPointerContainer* 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 MutableCalorimeterHit m_object;
75 const CalorimeterHitObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class CalorimeterHitCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// CalorimeterHitCollection(CalorimeterHitVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 CalorimeterHitCollection* operator->() { return (CalorimeterHitCollection*) 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 MutableCalorimeterHit 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::CalorimeterHitCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::CalorimeterHit"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::CalorimeterHitData"); }
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 CalorimeterHit operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableCalorimeterHit operator[](unsigned int index);
130 /// Returns the const object of given index
131 CalorimeterHit at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableCalorimeterHit at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(CalorimeterHit 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] (CalorimeterHitObj* 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::uint64_t, arraysize> cellID() 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<edm4hep::Vector3f, arraysize> position() const;
190 template<size_t arraysize>
191 const std::array<edm4hep::Vector3f, arraysize> dimension() const;
192 template<size_t arraysize>
193 const std::array<std::int32_t, arraysize> sector() const;
194 template<size_t arraysize>
195 const std::array<std::int32_t, arraysize> layer() const;
196 template<size_t arraysize>
197 const std::array<edm4hep::Vector3f, arraysize> local() 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 CalorimeterHitCollectionData m_storage{};
211};
212
213std::ostream& operator<<(std::ostream& o, const CalorimeterHitCollection& v);
214
215template<typename... Args>
216MutableCalorimeterHit CalorimeterHitCollection::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 CalorimeterHitObj({size, m_collectionID}, {std::forward<Args>(args)...});
222 m_storage.entries.push_back(obj);
223
224 return MutableCalorimeterHit(obj);
225}
226
227template<size_t arraysize>
228const std::array<std::uint64_t, arraysize> CalorimeterHitCollection::cellID() const {
229 std::array<std::uint64_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.cellID;
233 }
234 return tmp;
235}
236
237template<size_t arraysize>
238const std::array<float, arraysize> CalorimeterHitCollection::energy() const {
239 std::array<float, 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.energy;
243 }
244 return tmp;
245}
246
247template<size_t arraysize>
248const std::array<float, arraysize> CalorimeterHitCollection::energyError() 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.energyError;
253 }
254 return tmp;
255}
256
257template<size_t arraysize>
258const std::array<float, arraysize> CalorimeterHitCollection::time() 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.time;
263 }
264 return tmp;
265}
266
267template<size_t arraysize>
268const std::array<float, arraysize> CalorimeterHitCollection::timeError() 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.timeError;
273 }
274 return tmp;
275}
276
277template<size_t arraysize>
278const std::array<edm4hep::Vector3f, arraysize> CalorimeterHitCollection::position() const {
279 std::array<edm4hep::Vector3f, 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.position;
283 }
284 return tmp;
285}
286
287template<size_t arraysize>
288const std::array<edm4hep::Vector3f, arraysize> CalorimeterHitCollection::dimension() const {
289 std::array<edm4hep::Vector3f, 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.dimension;
293 }
294 return tmp;
295}
296
297template<size_t arraysize>
298const std::array<std::int32_t, arraysize> CalorimeterHitCollection::sector() const {
299 std::array<std::int32_t, 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.sector;
303 }
304 return tmp;
305}
306
307template<size_t arraysize>
308const std::array<std::int32_t, arraysize> CalorimeterHitCollection::layer() const {
309 std::array<std::int32_t, 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.layer;
313 }
314 return tmp;
315}
316
317template<size_t arraysize>
318const std::array<edm4hep::Vector3f, arraysize> CalorimeterHitCollection::local() const {
319 std::array<edm4hep::Vector3f, 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.local;
323 }
324 return tmp;
325}
326
327
328#ifdef PODIO_JSON_OUTPUT
329void to_json(nlohmann::json& j, const CalorimeterHitCollection& collection);
330#endif
331
332} // namespace eicd
333
334
335#endif
Definition: CalorimeterHitCollectionData.h:28
CalorimeterHitObjPointerContainer entries
Definition: CalorimeterHitCollectionData.h:33
Definition: CalorimeterHitCollection.h:82
std::string getTypeName() const final
fully qualified type name
Definition: CalorimeterHitCollection.h:114
iterator begin()
Definition: CalorimeterHitCollection.h:165
CalorimeterHitCollection(CalorimeterHitCollection &&)=default
CalorimeterHit at(unsigned int index) const
Returns the const object of given index.
Definition: CalorimeterHitCollection.cc:25
unsigned getID() const final
Definition: CalorimeterHitCollection.h:156
void push_back(CalorimeterHit object)
Append object to the collection.
Definition: CalorimeterHitCollection.cc:108
const_iterator end() const
Definition: CalorimeterHitCollection.h:174
void prepareAfterRead() final
Definition: CalorimeterHitCollection.cc:89
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: CalorimeterHitCollection.h:116
iterator end()
Definition: CalorimeterHitCollection.h:171
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: CalorimeterHitCollection.h:118
bool isValid() const final
Definition: CalorimeterHitCollection.h:160
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: CalorimeterHitCollection.cc:104
const_iterator begin() const
Definition: CalorimeterHitCollection.h:168
~CalorimeterHitCollection()
Definition: CalorimeterHitCollection.cc:16
CalorimeterHitCollection(const CalorimeterHitCollection &)=delete
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: CalorimeterHitCollection.cc:133
void setID(unsigned ID) final
Definition: CalorimeterHitCollection.h:146
size_t size() const final
number of elements in the collection
Definition: CalorimeterHitCollection.cc:37
void prepareForWrite() const final
Definition: CalorimeterHitCollection.cc:68
CalorimeterHitCollection & operator=(const CalorimeterHitCollection &)=delete
bool isSubsetCollection() const final
Definition: CalorimeterHitCollection.h:120
void clear() final
Definition: CalorimeterHitCollection.cc:63
CalorimeterHitCollection & operator=(CalorimeterHitCollection &&)=default
CalorimeterHitCollection()
Definition: CalorimeterHitCollection.cc:13
MutableCalorimeterHit create()
Append a new object to the collection, and return this object.
Definition: CalorimeterHitCollection.cc:52
void setSubsetCollection(bool setSubset=true) final
Definition: CalorimeterHitCollection.cc:41
Definition: CalorimeterHitCollection.h:35
bool operator!=(const CalorimeterHitCollectionIterator &x) const
Definition: CalorimeterHitCollection.h:42
CalorimeterHitCollectionIterator(const CalorimeterHitCollectionIterator &)=delete
CalorimeterHitCollectionIterator & operator=(const CalorimeterHitCollectionIterator &)=delete
CalorimeterHit * operator->()
Definition: CalorimeterHitCollection.cc:152
CalorimeterHit operator*()
Definition: CalorimeterHitCollection.cc:147
CalorimeterHitCollectionIterator(size_t index, const CalorimeterHitObjPointerContainer *collection)
Definition: CalorimeterHitCollection.h:37
CalorimeterHitCollectionIterator & operator++()
Definition: CalorimeterHitCollection.cc:157
Definition: CalorimeterHit.h:27
Definition: CalorimeterHitCollection.h:57
CalorimeterHitMutableCollectionIterator(size_t index, const CalorimeterHitObjPointerContainer *collection)
Definition: CalorimeterHitCollection.h:59
bool operator!=(const CalorimeterHitMutableCollectionIterator &x) const
Definition: CalorimeterHitCollection.h:64
CalorimeterHitMutableCollectionIterator & operator=(const CalorimeterHitMutableCollectionIterator &)=delete
CalorimeterHitMutableCollectionIterator(const CalorimeterHitMutableCollectionIterator &)=delete
MutableCalorimeterHit * operator->()
Definition: CalorimeterHitCollection.cc:169
MutableCalorimeterHit operator*()
Definition: CalorimeterHitCollection.cc:164
CalorimeterHitMutableCollectionIterator & operator++()
Definition: CalorimeterHitCollection.cc:174
Definition: CalorimeterHitObj.h:17
Definition: MutableCalorimeterHit.h:28
Definition: CalorimeterHit.cc:13
std::deque< CalorimeterHitObj * > CalorimeterHitObjPointerContainer
Definition: CalorimeterHitCollectionData.h:20
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93