EICd
EIC data model
RingImageCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_RingImageCollection_H
4#define EICD_RingImageCollection_H
5
6// datamodel specific includes
8#include "eicd/RingImage.h"
10#include "eicd/RingImageObj.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 RingImageCollectionIterator(size_t index, const RingImageObjPointerContainer* 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 RingImage m_object;
53 const RingImageObjPointerContainer* m_collection;
54};
55
56
58public:
59 RingImageMutableCollectionIterator(size_t index, const RingImageObjPointerContainer* 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 MutableRingImage m_object;
75 const RingImageObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class RingImageCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// RingImageCollection(RingImageVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
100 RingImageCollection* operator->() { return (RingImageCollection*) 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 MutableRingImage 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::RingImageCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::RingImage"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::RingImageData"); }
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 RingImage operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableRingImage operator[](unsigned int index);
130 /// Returns the const object of given index
131 RingImage at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableRingImage at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(RingImage 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] (RingImageObj* 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<float, arraysize> npe() const;
180 template<size_t arraysize>
181 const std::array<edm4hep::Vector3f, arraysize> position() const;
182 template<size_t arraysize>
183 const std::array<edm4hep::Vector3f, arraysize> positionError() 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> thetaError() const;
188 template<size_t arraysize>
189 const std::array<float, arraysize> radius() const;
190 template<size_t arraysize>
191 const std::array<float, arraysize> radiusError() 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 RingImageCollectionData m_storage{};
205};
206
207std::ostream& operator<<(std::ostream& o, const RingImageCollection& v);
208
209template<typename... Args>
210MutableRingImage RingImageCollection::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 RingImageObj({size, m_collectionID}, {std::forward<Args>(args)...});
216 m_storage.entries.push_back(obj);
217
218 return MutableRingImage(obj);
219}
220
221template<size_t arraysize>
222const std::array<float, arraysize> RingImageCollection::npe() const {
223 std::array<float, arraysize> tmp{};
224 const auto valid_size = std::min(arraysize, m_storage.entries.size());
225 for (unsigned i = 0; i < valid_size; ++i) {
226 tmp[i] = m_storage.entries[i]->data.npe;
227 }
228 return tmp;
229}
230
231template<size_t arraysize>
232const std::array<edm4hep::Vector3f, arraysize> RingImageCollection::position() const {
233 std::array<edm4hep::Vector3f, 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.position;
237 }
238 return tmp;
239}
240
241template<size_t arraysize>
242const std::array<edm4hep::Vector3f, arraysize> RingImageCollection::positionError() const {
243 std::array<edm4hep::Vector3f, 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.positionError;
247 }
248 return tmp;
249}
250
251template<size_t arraysize>
252const std::array<float, arraysize> RingImageCollection::theta() const {
253 std::array<float, 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.theta;
257 }
258 return tmp;
259}
260
261template<size_t arraysize>
262const std::array<float, arraysize> RingImageCollection::thetaError() const {
263 std::array<float, 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.thetaError;
267 }
268 return tmp;
269}
270
271template<size_t arraysize>
272const std::array<float, arraysize> RingImageCollection::radius() 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.radius;
277 }
278 return tmp;
279}
280
281template<size_t arraysize>
282const std::array<float, arraysize> RingImageCollection::radiusError() 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.radiusError;
287 }
288 return tmp;
289}
290
291
292#ifdef PODIO_JSON_OUTPUT
293void to_json(nlohmann::json& j, const RingImageCollection& collection);
294#endif
295
296} // namespace eicd
297
298
299#endif
Definition: MutableRingImage.h:27
Definition: RingImageCollectionData.h:28
RingImageObjPointerContainer entries
Definition: RingImageCollectionData.h:33
Definition: RingImageCollection.h:82
RingImage at(unsigned int index) const
Returns the const object of given index.
Definition: RingImageCollection.cc:25
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: RingImageCollection.h:116
void prepareForWrite() const final
Definition: RingImageCollection.cc:68
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: RingImageCollection.cc:104
bool isValid() const final
Definition: RingImageCollection.h:160
size_t size() const final
number of elements in the collection
Definition: RingImageCollection.cc:37
RingImageCollection(RingImageCollection &&)=default
std::string getTypeName() const final
fully qualified type name
Definition: RingImageCollection.h:114
RingImageCollection(const RingImageCollection &)=delete
const_iterator end() const
Definition: RingImageCollection.h:174
void push_back(RingImage object)
Append object to the collection.
Definition: RingImageCollection.cc:108
iterator begin()
Definition: RingImageCollection.h:165
void clear() final
Definition: RingImageCollection.cc:63
void setID(unsigned ID) final
Definition: RingImageCollection.h:146
MutableRingImage create()
Append a new object to the collection, and return this object.
Definition: RingImageCollection.cc:52
RingImageCollection & operator=(const RingImageCollection &)=delete
unsigned getID() const final
Definition: RingImageCollection.h:156
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: RingImageCollection.h:118
~RingImageCollection()
Definition: RingImageCollection.cc:16
void prepareAfterRead() final
Definition: RingImageCollection.cc:89
const_iterator begin() const
Definition: RingImageCollection.h:168
RingImageCollection()
Definition: RingImageCollection.cc:13
bool isSubsetCollection() const final
Definition: RingImageCollection.h:120
void setSubsetCollection(bool setSubset=true) final
Definition: RingImageCollection.cc:41
RingImageCollection & operator=(RingImageCollection &&)=default
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: RingImageCollection.cc:133
iterator end()
Definition: RingImageCollection.h:171
Definition: RingImageCollection.h:35
bool operator!=(const RingImageCollectionIterator &x) const
Definition: RingImageCollection.h:42
RingImageCollectionIterator & operator=(const RingImageCollectionIterator &)=delete
RingImage operator*()
Definition: RingImageCollection.cc:147
RingImageCollectionIterator(const RingImageCollectionIterator &)=delete
RingImage * operator->()
Definition: RingImageCollection.cc:152
RingImageCollectionIterator & operator++()
Definition: RingImageCollection.cc:157
RingImageCollectionIterator(size_t index, const RingImageObjPointerContainer *collection)
Definition: RingImageCollection.h:37
Definition: RingImage.h:26
Definition: RingImageCollection.h:57
bool operator!=(const RingImageMutableCollectionIterator &x) const
Definition: RingImageCollection.h:64
MutableRingImage * operator->()
Definition: RingImageCollection.cc:169
RingImageMutableCollectionIterator(const RingImageMutableCollectionIterator &)=delete
MutableRingImage operator*()
Definition: RingImageCollection.cc:164
RingImageMutableCollectionIterator & operator=(const RingImageMutableCollectionIterator &)=delete
RingImageMutableCollectionIterator(size_t index, const RingImageObjPointerContainer *collection)
Definition: RingImageCollection.h:59
RingImageMutableCollectionIterator & operator++()
Definition: RingImageCollection.cc:174
Definition: RingImageObj.h:17
Definition: CalorimeterHit.cc:13
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93
std::deque< RingImageObj * > RingImageObjPointerContainer
Definition: RingImageCollectionData.h:20