3#ifndef EICD_ClusterCollection_H
4#define EICD_ClusterCollection_H
14#include "podio/ICollectionProvider.h"
15#include "podio/CollectionBase.h"
16#include "podio/CollectionIDTable.h"
18#ifdef PODIO_JSON_OUTPUT
19#include "nlohmann/json.hpp"
43 return m_index != x.m_index;
65 return m_index != x.m_index;
107 template<
typename... Args>
111 size_t size() const final;
114 std::
string getTypeName() const final {
return std::string(
"eicd::ClusterCollection"); }
118 std::string
getDataTypeName() const final {
return std::string(
"eicd::ClusterData"); }
121 return m_isSubsetColl;
127 Cluster operator[](
unsigned int index) const;
141 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
148 if (!m_isSubsetColl) {
150 [ID] (
ClusterObj* obj) { obj->id = {obj->id.index, static_cast<int>(ID)}; }
157 return m_collectionID;
166 return iterator(0, &m_storage.entries);
172 return iterator(m_storage.entries.size(), &m_storage.entries);
175 return const_iterator(m_storage.entries.size(), &m_storage.entries);
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;
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{};
215std::ostream&
operator<<(std::ostream& o,
const ClusterCollection& v);
217template<
typename... Args>
219 if (m_isSubsetColl) {
220 throw std::logic_error(
"Cannot create new elements on a subset collection");
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);
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);
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
348#ifdef PODIO_JSON_OUTPUT
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: 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