EICd
EIC data model
RawCalorimeterHitCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EICD_RawCalorimeterHitCollection_H
4#define EICD_RawCalorimeterHitCollection_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 RawCalorimeterHitCollectionIterator(size_t index, const RawCalorimeterHitObjPointerContainer* 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 RawCalorimeterHit m_object;
53 const RawCalorimeterHitObjPointerContainer* m_collection;
54};
55
56
58public:
59 RawCalorimeterHitMutableCollectionIterator(size_t index, const RawCalorimeterHitObjPointerContainer* 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 RawCalorimeterHitObjPointerContainer* m_collection;
76};
77
78
79/**
80A Collection is identified by an ID.
81*/
82class RawCalorimeterHitCollection : public podio::CollectionBase {
83public:
86
88 // This is a move-only type
93
94// RawCalorimeterHitCollection(RawCalorimeterHitVector* data, int collectionID);
96
97 void clear() final;
98
99 /// operator to allow pointer like calling of members a la LCIO
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 MutableRawCalorimeterHit 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::RawCalorimeterHitCollection"); }
115 /// fully qualified type name of elements - with namespace
116 std::string getValueTypeName() const final { return std::string("eicd::RawCalorimeterHit"); }
117 /// fully qualified type name of stored POD elements - with namespace
118 std::string getDataTypeName() const final { return std::string("eicd::RawCalorimeterHitData"); }
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 RawCalorimeterHit operator[](unsigned int index) const;
128 /// Returns the object of a given index
129 MutableRawCalorimeterHit operator[](unsigned int index);
130 /// Returns the const object of given index
131 RawCalorimeterHit at(unsigned int index) const;
132 /// Returns the object of given index
133 MutableRawCalorimeterHit at(unsigned int index);
134
135
136 /// Append object to the collection
137 void push_back(RawCalorimeterHit 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] (RawCalorimeterHitObj* 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<std::uint64_t, arraysize> amplitude() const;
182 template<size_t arraysize>
183 const std::array<std::uint64_t, arraysize> timeStamp() const;
184
185private:
186 // For setReferences, we need to give our own CollectionData access to our
187 // private entries. Otherwise we would need to expose a public member function
188 // that gives access to the Obj* which is definitely not what we want
190
191 bool m_isValid{false};
192 mutable bool m_isPrepared{false};
193 bool m_isSubsetColl{false};
194 int m_collectionID{0};
195 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
196 mutable RawCalorimeterHitCollectionData m_storage{};
197};
198
199std::ostream& operator<<(std::ostream& o, const RawCalorimeterHitCollection& v);
200
201template<typename... Args>
202MutableRawCalorimeterHit RawCalorimeterHitCollection::create(Args&&... args) {
203 if (m_isSubsetColl) {
204 throw std::logic_error("Cannot create new elements on a subset collection");
205 }
206 const int size = m_storage.entries.size();
207 auto obj = new RawCalorimeterHitObj({size, m_collectionID}, {std::forward<Args>(args)...});
208 m_storage.entries.push_back(obj);
209
210 return MutableRawCalorimeterHit(obj);
211}
212
213template<size_t arraysize>
214const std::array<std::uint64_t, arraysize> RawCalorimeterHitCollection::cellID() const {
215 std::array<std::uint64_t, arraysize> tmp{};
216 const auto valid_size = std::min(arraysize, m_storage.entries.size());
217 for (unsigned i = 0; i < valid_size; ++i) {
218 tmp[i] = m_storage.entries[i]->data.cellID;
219 }
220 return tmp;
221}
222
223template<size_t arraysize>
224const std::array<std::uint64_t, arraysize> RawCalorimeterHitCollection::amplitude() const {
225 std::array<std::uint64_t, arraysize> tmp{};
226 const auto valid_size = std::min(arraysize, m_storage.entries.size());
227 for (unsigned i = 0; i < valid_size; ++i) {
228 tmp[i] = m_storage.entries[i]->data.amplitude;
229 }
230 return tmp;
231}
232
233template<size_t arraysize>
234const std::array<std::uint64_t, arraysize> RawCalorimeterHitCollection::timeStamp() const {
235 std::array<std::uint64_t, arraysize> tmp{};
236 const auto valid_size = std::min(arraysize, m_storage.entries.size());
237 for (unsigned i = 0; i < valid_size; ++i) {
238 tmp[i] = m_storage.entries[i]->data.timeStamp;
239 }
240 return tmp;
241}
242
243
244#ifdef PODIO_JSON_OUTPUT
245void to_json(nlohmann::json& j, const RawCalorimeterHitCollection& collection);
246#endif
247
248} // namespace eicd
249
250
251#endif
Definition: MutableRawCalorimeterHit.h:27
Definition: RawCalorimeterHitCollectionData.h:28
RawCalorimeterHitObjPointerContainer entries
Definition: RawCalorimeterHitCollectionData.h:33
Definition: RawCalorimeterHitCollection.h:82
RawCalorimeterHitCollection(const RawCalorimeterHitCollection &)=delete
RawCalorimeterHitCollection(RawCalorimeterHitCollection &&)=default
const_iterator begin() const
Definition: RawCalorimeterHitCollection.h:168
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition: RawCalorimeterHitCollection.cc:104
RawCalorimeterHit at(unsigned int index) const
Returns the const object of given index.
Definition: RawCalorimeterHitCollection.cc:25
void setID(unsigned ID) final
Definition: RawCalorimeterHitCollection.h:146
iterator end()
Definition: RawCalorimeterHitCollection.h:171
bool isSubsetCollection() const final
Definition: RawCalorimeterHitCollection.h:120
iterator begin()
Definition: RawCalorimeterHitCollection.h:165
podio::CollectionBuffers getBuffers() final
Get the collection buffers for this collection.
Definition: RawCalorimeterHitCollection.cc:133
void prepareForWrite() const final
Definition: RawCalorimeterHitCollection.cc:68
bool isValid() const final
Definition: RawCalorimeterHitCollection.h:160
unsigned getID() const final
Definition: RawCalorimeterHitCollection.h:156
~RawCalorimeterHitCollection()
Definition: RawCalorimeterHitCollection.cc:16
std::string getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition: RawCalorimeterHitCollection.h:118
std::string getTypeName() const final
fully qualified type name
Definition: RawCalorimeterHitCollection.h:114
RawCalorimeterHitCollection & operator=(const RawCalorimeterHitCollection &)=delete
void clear() final
Definition: RawCalorimeterHitCollection.cc:63
MutableRawCalorimeterHit create()
Append a new object to the collection, and return this object.
Definition: RawCalorimeterHitCollection.cc:52
RawCalorimeterHitCollection & operator=(RawCalorimeterHitCollection &&)=default
RawCalorimeterHitCollection()
Definition: RawCalorimeterHitCollection.cc:13
void push_back(RawCalorimeterHit object)
Append object to the collection.
Definition: RawCalorimeterHitCollection.cc:108
std::string getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition: RawCalorimeterHitCollection.h:116
void setSubsetCollection(bool setSubset=true) final
Definition: RawCalorimeterHitCollection.cc:41
void prepareAfterRead() final
Definition: RawCalorimeterHitCollection.cc:89
const_iterator end() const
Definition: RawCalorimeterHitCollection.h:174
size_t size() const final
number of elements in the collection
Definition: RawCalorimeterHitCollection.cc:37
Definition: RawCalorimeterHitCollection.h:35
RawCalorimeterHitCollectionIterator & operator=(const RawCalorimeterHitCollectionIterator &)=delete
RawCalorimeterHit operator*()
Definition: RawCalorimeterHitCollection.cc:147
bool operator!=(const RawCalorimeterHitCollectionIterator &x) const
Definition: RawCalorimeterHitCollection.h:42
RawCalorimeterHit * operator->()
Definition: RawCalorimeterHitCollection.cc:152
RawCalorimeterHitCollectionIterator & operator++()
Definition: RawCalorimeterHitCollection.cc:157
RawCalorimeterHitCollectionIterator(const RawCalorimeterHitCollectionIterator &)=delete
RawCalorimeterHitCollectionIterator(size_t index, const RawCalorimeterHitObjPointerContainer *collection)
Definition: RawCalorimeterHitCollection.h:37
Definition: RawCalorimeterHit.h:26
Definition: RawCalorimeterHitCollection.h:57
MutableRawCalorimeterHit * operator->()
Definition: RawCalorimeterHitCollection.cc:169
MutableRawCalorimeterHit operator*()
Definition: RawCalorimeterHitCollection.cc:164
bool operator!=(const RawCalorimeterHitMutableCollectionIterator &x) const
Definition: RawCalorimeterHitCollection.h:64
RawCalorimeterHitMutableCollectionIterator & operator=(const RawCalorimeterHitMutableCollectionIterator &)=delete
RawCalorimeterHitMutableCollectionIterator & operator++()
Definition: RawCalorimeterHitCollection.cc:174
RawCalorimeterHitMutableCollectionIterator(const RawCalorimeterHitMutableCollectionIterator &)=delete
RawCalorimeterHitMutableCollectionIterator(size_t index, const RawCalorimeterHitObjPointerContainer *collection)
Definition: RawCalorimeterHitCollection.h:59
Definition: RawCalorimeterHitObj.h:17
Definition: CalorimeterHit.cc:13
std::deque< RawCalorimeterHitObj * > RawCalorimeterHitObjPointerContainer
Definition: RawCalorimeterHitCollectionData.h:20
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition: CalorimeterHit.cc:93