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"
9 #include "eicd/ClusterObj.h"
10 
11 // podio specific includes
12 #include "podio/ICollectionProvider.h"
13 #include "podio/CollectionBase.h"
14 #include "podio/CollectionIDTable.h"
15 
16 #include <string>
17 #include <vector>
18 #include <deque>
19 #include <array>
20 #include <algorithm>
21 #include <ostream>
22 
23 namespace eic {
24 
25 
26 using ClusterDataContainer = std::vector<ClusterData>;
27 using ClusterObjPointerContainer = std::deque<ClusterObj*>;
28 
30 public:
31  ClusterCollectionIterator(size_t index, const ClusterObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
32 
35 
36  bool operator!=(const ClusterCollectionIterator& x) const {
37  return m_index != x.m_index; // TODO: may not be complete
38  }
39 
43 
44 private:
45  size_t m_index;
46  Cluster m_object;
47  const ClusterObjPointerContainer* m_collection;
48 };
49 
50 
52 public:
53  ClusterConstCollectionIterator(size_t index, const ClusterObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
54 
57 
59  return m_index != x.m_index; // TODO: may not be complete
60  }
61 
65 
66 private:
67  size_t m_index;
68  ConstCluster m_object;
69  const ClusterObjPointerContainer* m_collection;
70 };
71 
72 
73 /**
74 A Collection is identified by an ID.
75 */
76 class ClusterCollection : public podio::CollectionBase {
77 
78 public:
81 
85 // ClusterCollection(ClusterVector* data, int collectionID);
87 
88  void clear() override final;
89 
90  /// operator to allow pointer like calling of members a la LCIO
91  ClusterCollection* operator->() { return (ClusterCollection*) this; }
92 
93  /// Append a new object to the collection, and return this object.
94  Cluster create();
95 
96  /// Append a new object to the collection, and return this object.
97  /// Initialized with the parameters given
98  template<typename... Args>
99  Cluster create(Args&&... args);
100 
101  /// number of elements in the collection
102  size_t size() const override final;
103 
104  /// fully qualified type name of elements - with namespace
105  std::string getValueTypeName() const override { return std::string("eic::Cluster"); }
106 
107  /// Returns the const object of given index
108  ConstCluster operator[](unsigned int index) const;
109  /// Returns the object of a given index
110  Cluster operator[](unsigned int index);
111  /// Returns the const object of given index
112  ConstCluster at(unsigned int index) const;
113  /// Returns the object of given index
114  Cluster at(unsigned int index);
115 
116 
117  /// Append object to the collection
118  void push_back(ConstCluster object);
119 
120  void prepareForWrite() override final;
121  void prepareAfterRead() override final;
122  void setBuffer(void* address) override final;
123  bool setReferences(const podio::ICollectionProvider* collectionProvider) override final;
124 
125  podio::CollRefCollection* referenceCollections() override final { return &m_refCollections; }
126 
127  podio::VectorMembersInfo* vectorMembers() override { return &m_vecmem_info; }
128 
129  void setID(unsigned ID) override final {
130  m_collectionID = ID;
131  std::for_each(m_entries.begin(),m_entries.end(),
132  [ID] (ClusterObj* obj) { obj->id = {obj->id.index, static_cast<int>(ID)}; }
133  );
134  m_isValid = true;
135  };
136 
137  unsigned getID() const override final {
138  return m_collectionID;
139  }
140 
141  bool isValid() const override final {
142  return m_isValid;
143  }
144 
145  // support for the iterator protocol
147  return iterator(0, &m_entries);
148  }
150  return const_iterator(0, &m_entries);
151  }
153  return iterator(m_entries.size(), &m_entries);
154  }
155  const_iterator end() const {
156  return const_iterator(m_entries.size(), &m_entries);
157  }
158 
159  /// returns the address of the pointer to the data buffer
160  void* getBufferAddress() override final { return (void*)&m_data; }
161 
162  /// Returns the pointer to the data buffer
163  std::vector<ClusterData>* _getBuffer() { return m_data; }
164 
165  template<size_t arraysize>
166  const std::array<eic::Index, arraysize> ID() const;
167  template<size_t arraysize>
168  const std::array<float, arraysize> energy() const;
169  template<size_t arraysize>
170  const std::array<float, arraysize> energyError() const;
171  template<size_t arraysize>
172  const std::array<float, arraysize> time() const;
173  template<size_t arraysize>
174  const std::array<std::uint32_t, arraysize> nhits() const;
175  template<size_t arraysize>
176  const std::array<eic::VectorXYZ, arraysize> position() const;
177  template<size_t arraysize>
178  const std::array<eic::CovXYZ, arraysize> positionError() const;
179  template<size_t arraysize>
180  const std::array<float, arraysize> radius() const;
181  template<size_t arraysize>
182  const std::array<float, arraysize> skewness() const;
183 
184 private:
185  bool m_isValid{false};
186  bool m_isReadFromFile{false};
187  int m_collectionID{0};
188  ClusterObjPointerContainer m_entries;
189 
190  // members to handle 1-to-N-relations
191 
192  // members to handle vector members
193  // members to handle streaming
194  podio::CollRefCollection m_refCollections{};
195  podio::VectorMembersInfo m_vecmem_info{};
196  ClusterDataContainer* m_data;
197 };
198 
199 std::ostream& operator<<(std::ostream& o, const ClusterCollection& v);
200 
201 template<typename... Args>
202 Cluster ClusterCollection::create(Args&&... args) {
203  const int size = m_entries.size();
204  auto obj = new ClusterObj({size, m_collectionID}, {args...});
205  m_entries.push_back(obj);
206  return Cluster(obj);
207 }
208 
209 template<size_t arraysize>
210 const std::array<eic::Index, arraysize> ClusterCollection::ID() const {
211  std::array<eic::Index, arraysize> tmp;
212  const auto valid_size = std::min(arraysize, m_entries.size());
213  for (unsigned i = 0; i < valid_size; ++i) {
214  tmp[i] = m_entries[i]->data.ID;
215  }
216  return tmp;
217 }
218 
219 template<size_t arraysize>
220 const std::array<float, arraysize> ClusterCollection::energy() const {
221  std::array<float, arraysize> tmp;
222  const auto valid_size = std::min(arraysize, m_entries.size());
223  for (unsigned i = 0; i < valid_size; ++i) {
224  tmp[i] = m_entries[i]->data.energy;
225  }
226  return tmp;
227 }
228 
229 template<size_t arraysize>
230 const std::array<float, arraysize> ClusterCollection::energyError() const {
231  std::array<float, arraysize> tmp;
232  const auto valid_size = std::min(arraysize, m_entries.size());
233  for (unsigned i = 0; i < valid_size; ++i) {
234  tmp[i] = m_entries[i]->data.energyError;
235  }
236  return tmp;
237 }
238 
239 template<size_t arraysize>
240 const std::array<float, arraysize> ClusterCollection::time() const {
241  std::array<float, arraysize> tmp;
242  const auto valid_size = std::min(arraysize, m_entries.size());
243  for (unsigned i = 0; i < valid_size; ++i) {
244  tmp[i] = m_entries[i]->data.time;
245  }
246  return tmp;
247 }
248 
249 template<size_t arraysize>
250 const std::array<std::uint32_t, arraysize> ClusterCollection::nhits() const {
251  std::array<std::uint32_t, arraysize> tmp;
252  const auto valid_size = std::min(arraysize, m_entries.size());
253  for (unsigned i = 0; i < valid_size; ++i) {
254  tmp[i] = m_entries[i]->data.nhits;
255  }
256  return tmp;
257 }
258 
259 template<size_t arraysize>
260 const std::array<eic::VectorXYZ, arraysize> ClusterCollection::position() const {
261  std::array<eic::VectorXYZ, arraysize> tmp;
262  const auto valid_size = std::min(arraysize, m_entries.size());
263  for (unsigned i = 0; i < valid_size; ++i) {
264  tmp[i] = m_entries[i]->data.position;
265  }
266  return tmp;
267 }
268 
269 template<size_t arraysize>
270 const std::array<eic::CovXYZ, arraysize> ClusterCollection::positionError() const {
271  std::array<eic::CovXYZ, arraysize> tmp;
272  const auto valid_size = std::min(arraysize, m_entries.size());
273  for (unsigned i = 0; i < valid_size; ++i) {
274  tmp[i] = m_entries[i]->data.positionError;
275  }
276  return tmp;
277 }
278 
279 template<size_t arraysize>
280 const std::array<float, arraysize> ClusterCollection::radius() const {
281  std::array<float, arraysize> tmp;
282  const auto valid_size = std::min(arraysize, m_entries.size());
283  for (unsigned i = 0; i < valid_size; ++i) {
284  tmp[i] = m_entries[i]->data.radius;
285  }
286  return tmp;
287 }
288 
289 template<size_t arraysize>
290 const std::array<float, arraysize> ClusterCollection::skewness() const {
291  std::array<float, arraysize> tmp;
292  const auto valid_size = std::min(arraysize, m_entries.size());
293  for (unsigned i = 0; i < valid_size; ++i) {
294  tmp[i] = m_entries[i]->data.skewness;
295  }
296  return tmp;
297 }
298 
299 
300 } // namespace eic
301 
302 
303 #endif
eic::operator<<
std::ostream & operator<<(std::ostream &o, const ConstBasicParticle &value)
Definition: BasicParticle.cc:102
eic::ClusterCollectionIterator::operator++
ClusterCollectionIterator & operator++()
Definition: ClusterCollection.cc:116
eic::ClusterCollection::getID
unsigned getID() const override final
Definition: ClusterCollection.h:137
eic::ClusterCollectionIterator::ClusterCollectionIterator
ClusterCollectionIterator(size_t index, const ClusterObjPointerContainer *collection)
Definition: ClusterCollection.h:31
eic::ClusterCollection::begin
iterator begin()
Definition: ClusterCollection.h:146
eic::ClusterCollection
Definition: ClusterCollection.h:76
eic::ClusterCollectionIterator::operator!=
bool operator!=(const ClusterCollectionIterator &x) const
Definition: ClusterCollection.h:36
eic::ClusterCollection::setReferences
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final
Definition: ClusterCollection.cc:84
eic::ClusterConstCollectionIterator
Definition: ClusterCollection.h:51
eic::ClusterCollection::push_back
void push_back(ConstCluster object)
Append object to the collection.
Definition: ClusterCollection.cc:89
eic::Cluster
Definition: Cluster.h:24
eic::ClusterCollection::ClusterCollection
ClusterCollection(const ClusterCollection &)=delete
eic::ClusterConstCollectionIterator::operator=
ClusterConstCollectionIterator & operator=(const ClusterConstCollectionIterator &)=delete
eic::ClusterConstCollectionIterator::operator->
ConstCluster * operator->()
Definition: ClusterCollection.cc:128
eic::ClusterCollectionIterator::operator*
Cluster operator*()
Definition: ClusterCollection.cc:106
eic::ClusterCollection::prepareAfterRead
void prepareAfterRead() override final
Definition: ClusterCollection.cc:69
eic::ClusterCollection::prepareForWrite
void prepareForWrite() override final
Definition: ClusterCollection.cc:56
eic::ClusterObj
Definition: ClusterObj.h:18
eic::ClusterConstCollectionIterator::operator++
ClusterConstCollectionIterator & operator++()
Definition: ClusterCollection.cc:133
eic
Definition: BasicParticle.cc:13
eic::ClusterConstCollectionIterator::ClusterConstCollectionIterator
ClusterConstCollectionIterator(size_t index, const ClusterObjPointerContainer *collection)
Definition: ClusterCollection.h:53
eic::ClusterConstCollectionIterator::operator*
ConstCluster operator*()
Definition: ClusterCollection.cc:123
eic::ClusterCollectionIterator::operator->
Cluster * operator->()
Definition: ClusterCollection.cc:111
eic::ClusterCollection::ID
const std::array< eic::Index, arraysize > ID() const
Definition: ClusterCollection.h:210
eic::ClusterConstCollectionIterator::operator!=
bool operator!=(const ClusterConstCollectionIterator &x) const
Definition: ClusterCollection.h:58
eic::ClusterCollectionIterator
Definition: ClusterCollection.h:29
eic::ClusterObjPointerContainer
std::deque< ClusterObj * > ClusterObjPointerContainer
Definition: ClusterCollection.h:27
eic::ClusterCollection::~ClusterCollection
~ClusterCollection()
Definition: ClusterCollection.cc:18
eic::ClusterCollection::end
const_iterator end() const
Definition: ClusterCollection.h:155
eic::ClusterDataContainer
std::vector< ClusterData > ClusterDataContainer
Definition: ClusterCollection.h:26
ClusterData.h
eic::ClusterCollection::clear
void clear() override final
Definition: ClusterCollection.cc:50
eic::ClusterCollection::isValid
bool isValid() const override final
Definition: ClusterCollection.h:141
eic::ClusterCollection::at
ConstCluster at(unsigned int index) const
Returns the const object of given index.
Definition: ClusterCollection.cc:27
eic::ClusterCollection::setID
void setID(unsigned ID) override final
Definition: ClusterCollection.h:129
Cluster.h
eic::ClusterCollection::ClusterCollection
ClusterCollection()
Definition: ClusterCollection.cc:13
eic::ClusterCollection::create
Cluster create()
Append a new object to the collection, and return this object.
Definition: ClusterCollection.cc:43
eic::ClusterCollection::referenceCollections
podio::CollRefCollection * referenceCollections() override final
Definition: ClusterCollection.h:125
eic::ClusterCollection::getValueTypeName
std::string getValueTypeName() const override
fully qualified type name of elements - with namespace
Definition: ClusterCollection.h:105
eic::ClusterCollectionIterator::operator=
ClusterCollectionIterator & operator=(const ClusterCollectionIterator &)=delete
eic::ClusterCollectionIterator::ClusterCollectionIterator
ClusterCollectionIterator(const ClusterCollectionIterator &)=delete
eic::ClusterConstCollectionIterator::ClusterConstCollectionIterator
ClusterConstCollectionIterator(const ClusterConstCollectionIterator &)=delete
eic::ConstCluster
Definition: ClusterConst.h:22
eic::ClusterCollection::operator[]
ConstCluster operator[](unsigned int index) const
Returns the const object of given index.
Definition: ClusterCollection.cc:23
eic::ClusterCollection::vectorMembers
podio::VectorMembersInfo * vectorMembers() override
Definition: ClusterCollection.h:127
eic::ClusterCollection::setBuffer
void setBuffer(void *address) override final
Definition: ClusterCollection.cc:101
eic::ClusterCollection::end
iterator end()
Definition: ClusterCollection.h:152
eic::ClusterCollection::begin
const_iterator begin() const
Definition: ClusterCollection.h:149
eic::ClusterCollection::operator=
ClusterCollection & operator=(const ClusterCollection &)=delete
eic::ClusterCollection::getBufferAddress
void * getBufferAddress() override final
returns the address of the pointer to the data buffer
Definition: ClusterCollection.h:160
eic::ClusterCollection::size
size_t size() const override final
number of elements in the collection
Definition: ClusterCollection.cc:39
eic::ClusterCollection::_getBuffer
std::vector< ClusterData > * _getBuffer()
Returns the pointer to the data buffer.
Definition: ClusterCollection.h:163
ClusterObj.h