Geant4ParticleCollection.h
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
3 #ifndef DD4POD_Geant4ParticleCollection_H
4 #define DD4POD_Geant4ParticleCollection_H
5 
6 // datamodel specific includes
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 dd4pod {
24 
25 
26 using Geant4ParticleDataContainer = std::vector<Geant4ParticleData>;
27 using Geant4ParticleObjPointerContainer = std::deque<Geant4ParticleObj*>;
28 
30 public:
31  Geant4ParticleCollectionIterator(int index, const Geant4ParticleObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
32 
34  return m_index != x.m_index; // TODO: may not be complete
35  }
36 
37  const Geant4Particle operator*() const;
38  const Geant4Particle* operator->() const;
40 
41 private:
42  mutable int m_index;
43  mutable Geant4Particle m_object;
44  const Geant4ParticleObjPointerContainer* m_collection;
45 };
46 
50 class Geant4ParticleCollection : public podio::CollectionBase {
51 
52 public:
54 
56 // Geant4ParticleCollection(const Geant4ParticleCollection& ) = delete; // deletion doesn't work w/ ROOT IO ! :-(
57 // Geant4ParticleCollection(Geant4ParticleVector* data, int collectionID);
59 
60  void clear() override final;
61 
63  Geant4ParticleCollection* operator->() { return (Geant4ParticleCollection*) this; }
64 
67 
70  template<typename... Args>
71  Geant4Particle create(Args&&... args);
72 
74  size_t size() const override final;
75 
77  std::string getValueTypeName() const override { return std::string("dd4pod::Geant4Particle"); }
78 
80  const Geant4Particle operator[](unsigned int index) const;
82  Geant4Particle operator[](unsigned int index);
84  const Geant4Particle at(unsigned int index) const;
86  Geant4Particle at(unsigned int index);
87 
88 
90  void push_back(ConstGeant4Particle object);
91 
92  void prepareForWrite() override final;
93  void prepareAfterRead() override final;
94  void setBuffer(void* address) override final;
95  bool setReferences(const podio::ICollectionProvider* collectionProvider) override final;
96 
97  podio::CollRefCollection* referenceCollections() override final { return &m_refCollections; }
98 
99  podio::VectorMembersInfo* vectorMembers() override { return &m_vecmem_info; }
100 
101  void setID(unsigned ID) override final {
102  m_collectionID = ID;
103  std::for_each(m_entries.begin(),m_entries.end(),
104  [ID] (Geant4ParticleObj* obj) { obj->id = {obj->id.index, static_cast<int>(ID)}; }
105  );
106  };
107 
108  unsigned getID() const override final {
109  return m_collectionID;
110  }
111 
112  bool isValid() const override final {
113  return m_isValid;
114  }
115 
116  // support for the iterator protocol
117  const const_iterator begin() const {
118  return const_iterator(0, &m_entries);
119  }
120  const const_iterator end() const {
121  return const_iterator(m_entries.size(), &m_entries);
122  }
123 
125  void* getBufferAddress() override final { return (void*)&m_data; }
126 
128  std::vector<Geant4ParticleData>* _getBuffer() { return m_data; }
129 
130  template<size_t arraysize>
131  const std::array<int, arraysize> ID() const;
132  template<size_t arraysize>
133  const std::array<int, arraysize> g4Parent() const;
134  template<size_t arraysize>
135  const std::array<int, arraysize> reason() const;
136  template<size_t arraysize>
137  const std::array<int, arraysize> mask() const;
138  template<size_t arraysize>
139  const std::array<int, arraysize> steps() const;
140  template<size_t arraysize>
141  const std::array<int, arraysize> secondaries() const;
142  template<size_t arraysize>
143  const std::array<int, arraysize> pdgID() const;
144  template<size_t arraysize>
145  const std::array<int, arraysize> status() const;
146  template<size_t arraysize>
147  const std::array<std::array<int, 2>, arraysize> colorFlow() const;
148  template<size_t arraysize>
149  const std::array<int, arraysize> genStatus() const;
150  template<size_t arraysize>
151  const std::array<int, arraysize> charge() const;
152  template<size_t arraysize>
153  const std::array<std::array<int, 1>, arraysize> spare() const;
154  template<size_t arraysize>
155  const std::array<std::array<float, 3>, arraysize> spin() const;
156  template<size_t arraysize>
157  const std::array<double, arraysize> vsx() const;
158  template<size_t arraysize>
159  const std::array<double, arraysize> vsy() const;
160  template<size_t arraysize>
161  const std::array<double, arraysize> vsz() const;
162  template<size_t arraysize>
163  const std::array<double, arraysize> vex() const;
164  template<size_t arraysize>
165  const std::array<double, arraysize> vey() const;
166  template<size_t arraysize>
167  const std::array<double, arraysize> vez() const;
168  template<size_t arraysize>
169  const std::array<double, arraysize> psx() const;
170  template<size_t arraysize>
171  const std::array<double, arraysize> psy() const;
172  template<size_t arraysize>
173  const std::array<double, arraysize> psz() const;
174  template<size_t arraysize>
175  const std::array<double, arraysize> pex() const;
176  template<size_t arraysize>
177  const std::array<double, arraysize> pey() const;
178  template<size_t arraysize>
179  const std::array<double, arraysize> pez() const;
180  template<size_t arraysize>
181  const std::array<double, arraysize> mass() const;
182  template<size_t arraysize>
183  const std::array<double, arraysize> time() const;
184  template<size_t arraysize>
185  const std::array<double, arraysize> properTime() const;
186 
187 private:
188  bool m_isValid;
189  bool m_isReadFromFile{false};
190  int m_collectionID;
192 
193  // members to handle 1-to-N-relations
194 
195  // members to handle vector members
196  std::vector<int>* m_vec_parents;
197  std::vector<std::vector<int>*> m_vecs_parents;
198  std::vector<int>* m_vec_daughters;
199  std::vector<std::vector<int>*> m_vecs_daughters;
200  // members to handle streaming
201  podio::CollRefCollection m_refCollections;
202  podio::VectorMembersInfo m_vecmem_info;
204 };
205 
206 std::ostream& operator<<(std::ostream& o, const Geant4ParticleCollection& v);
207 
208 template<typename... Args>
209 Geant4Particle Geant4ParticleCollection::create(Args&&... args) {
210  const int size = m_entries.size();
211  auto obj = new Geant4ParticleObj({size, m_collectionID}, {args...});
212  m_entries.push_back(obj);
213  return Geant4Particle(obj);
214 }
215 
216 template<size_t arraysize>
217 const std::array<int, arraysize> Geant4ParticleCollection::ID() const {
218  std::array<int, arraysize> tmp;
219  const auto valid_size = std::min(arraysize, m_entries.size());
220  for (unsigned i = 0; i < valid_size; ++i) {
221  tmp[i] = m_entries[i]->data.ID;
222  }
223  return tmp;
224 }
225 
226 template<size_t arraysize>
227 const std::array<int, arraysize> Geant4ParticleCollection::g4Parent() const {
228  std::array<int, arraysize> tmp;
229  const auto valid_size = std::min(arraysize, m_entries.size());
230  for (unsigned i = 0; i < valid_size; ++i) {
231  tmp[i] = m_entries[i]->data.g4Parent;
232  }
233  return tmp;
234 }
235 
236 template<size_t arraysize>
237 const std::array<int, arraysize> Geant4ParticleCollection::reason() const {
238  std::array<int, arraysize> tmp;
239  const auto valid_size = std::min(arraysize, m_entries.size());
240  for (unsigned i = 0; i < valid_size; ++i) {
241  tmp[i] = m_entries[i]->data.reason;
242  }
243  return tmp;
244 }
245 
246 template<size_t arraysize>
247 const std::array<int, arraysize> Geant4ParticleCollection::mask() const {
248  std::array<int, arraysize> tmp;
249  const auto valid_size = std::min(arraysize, m_entries.size());
250  for (unsigned i = 0; i < valid_size; ++i) {
251  tmp[i] = m_entries[i]->data.mask;
252  }
253  return tmp;
254 }
255 
256 template<size_t arraysize>
257 const std::array<int, arraysize> Geant4ParticleCollection::steps() const {
258  std::array<int, arraysize> tmp;
259  const auto valid_size = std::min(arraysize, m_entries.size());
260  for (unsigned i = 0; i < valid_size; ++i) {
261  tmp[i] = m_entries[i]->data.steps;
262  }
263  return tmp;
264 }
265 
266 template<size_t arraysize>
267 const std::array<int, arraysize> Geant4ParticleCollection::secondaries() const {
268  std::array<int, arraysize> tmp;
269  const auto valid_size = std::min(arraysize, m_entries.size());
270  for (unsigned i = 0; i < valid_size; ++i) {
271  tmp[i] = m_entries[i]->data.secondaries;
272  }
273  return tmp;
274 }
275 
276 template<size_t arraysize>
277 const std::array<int, arraysize> Geant4ParticleCollection::pdgID() const {
278  std::array<int, arraysize> tmp;
279  const auto valid_size = std::min(arraysize, m_entries.size());
280  for (unsigned i = 0; i < valid_size; ++i) {
281  tmp[i] = m_entries[i]->data.pdgID;
282  }
283  return tmp;
284 }
285 
286 template<size_t arraysize>
287 const std::array<int, arraysize> Geant4ParticleCollection::status() const {
288  std::array<int, arraysize> tmp;
289  const auto valid_size = std::min(arraysize, m_entries.size());
290  for (unsigned i = 0; i < valid_size; ++i) {
291  tmp[i] = m_entries[i]->data.status;
292  }
293  return tmp;
294 }
295 
296 template<size_t arraysize>
297 const std::array<std::array<int, 2>, arraysize> Geant4ParticleCollection::colorFlow() const {
298  std::array<std::array<int, 2>, arraysize> tmp;
299  const auto valid_size = std::min(arraysize, m_entries.size());
300  for (unsigned i = 0; i < valid_size; ++i) {
301  tmp[i] = m_entries[i]->data.colorFlow;
302  }
303  return tmp;
304 }
305 
306 template<size_t arraysize>
307 const std::array<int, arraysize> Geant4ParticleCollection::genStatus() const {
308  std::array<int, arraysize> tmp;
309  const auto valid_size = std::min(arraysize, m_entries.size());
310  for (unsigned i = 0; i < valid_size; ++i) {
311  tmp[i] = m_entries[i]->data.genStatus;
312  }
313  return tmp;
314 }
315 
316 template<size_t arraysize>
317 const std::array<int, arraysize> Geant4ParticleCollection::charge() const {
318  std::array<int, arraysize> tmp;
319  const auto valid_size = std::min(arraysize, m_entries.size());
320  for (unsigned i = 0; i < valid_size; ++i) {
321  tmp[i] = m_entries[i]->data.charge;
322  }
323  return tmp;
324 }
325 
326 template<size_t arraysize>
327 const std::array<std::array<int, 1>, arraysize> Geant4ParticleCollection::spare() const {
328  std::array<std::array<int, 1>, arraysize> tmp;
329  const auto valid_size = std::min(arraysize, m_entries.size());
330  for (unsigned i = 0; i < valid_size; ++i) {
331  tmp[i] = m_entries[i]->data.spare;
332  }
333  return tmp;
334 }
335 
336 template<size_t arraysize>
337 const std::array<std::array<float, 3>, arraysize> Geant4ParticleCollection::spin() const {
338  std::array<std::array<float, 3>, arraysize> tmp;
339  const auto valid_size = std::min(arraysize, m_entries.size());
340  for (unsigned i = 0; i < valid_size; ++i) {
341  tmp[i] = m_entries[i]->data.spin;
342  }
343  return tmp;
344 }
345 
346 template<size_t arraysize>
347 const std::array<double, arraysize> Geant4ParticleCollection::vsx() const {
348  std::array<double, arraysize> tmp;
349  const auto valid_size = std::min(arraysize, m_entries.size());
350  for (unsigned i = 0; i < valid_size; ++i) {
351  tmp[i] = m_entries[i]->data.vsx;
352  }
353  return tmp;
354 }
355 
356 template<size_t arraysize>
357 const std::array<double, arraysize> Geant4ParticleCollection::vsy() const {
358  std::array<double, arraysize> tmp;
359  const auto valid_size = std::min(arraysize, m_entries.size());
360  for (unsigned i = 0; i < valid_size; ++i) {
361  tmp[i] = m_entries[i]->data.vsy;
362  }
363  return tmp;
364 }
365 
366 template<size_t arraysize>
367 const std::array<double, arraysize> Geant4ParticleCollection::vsz() const {
368  std::array<double, arraysize> tmp;
369  const auto valid_size = std::min(arraysize, m_entries.size());
370  for (unsigned i = 0; i < valid_size; ++i) {
371  tmp[i] = m_entries[i]->data.vsz;
372  }
373  return tmp;
374 }
375 
376 template<size_t arraysize>
377 const std::array<double, arraysize> Geant4ParticleCollection::vex() const {
378  std::array<double, arraysize> tmp;
379  const auto valid_size = std::min(arraysize, m_entries.size());
380  for (unsigned i = 0; i < valid_size; ++i) {
381  tmp[i] = m_entries[i]->data.vex;
382  }
383  return tmp;
384 }
385 
386 template<size_t arraysize>
387 const std::array<double, arraysize> Geant4ParticleCollection::vey() const {
388  std::array<double, arraysize> tmp;
389  const auto valid_size = std::min(arraysize, m_entries.size());
390  for (unsigned i = 0; i < valid_size; ++i) {
391  tmp[i] = m_entries[i]->data.vey;
392  }
393  return tmp;
394 }
395 
396 template<size_t arraysize>
397 const std::array<double, arraysize> Geant4ParticleCollection::vez() const {
398  std::array<double, arraysize> tmp;
399  const auto valid_size = std::min(arraysize, m_entries.size());
400  for (unsigned i = 0; i < valid_size; ++i) {
401  tmp[i] = m_entries[i]->data.vez;
402  }
403  return tmp;
404 }
405 
406 template<size_t arraysize>
407 const std::array<double, arraysize> Geant4ParticleCollection::psx() const {
408  std::array<double, arraysize> tmp;
409  const auto valid_size = std::min(arraysize, m_entries.size());
410  for (unsigned i = 0; i < valid_size; ++i) {
411  tmp[i] = m_entries[i]->data.psx;
412  }
413  return tmp;
414 }
415 
416 template<size_t arraysize>
417 const std::array<double, arraysize> Geant4ParticleCollection::psy() const {
418  std::array<double, arraysize> tmp;
419  const auto valid_size = std::min(arraysize, m_entries.size());
420  for (unsigned i = 0; i < valid_size; ++i) {
421  tmp[i] = m_entries[i]->data.psy;
422  }
423  return tmp;
424 }
425 
426 template<size_t arraysize>
427 const std::array<double, arraysize> Geant4ParticleCollection::psz() const {
428  std::array<double, arraysize> tmp;
429  const auto valid_size = std::min(arraysize, m_entries.size());
430  for (unsigned i = 0; i < valid_size; ++i) {
431  tmp[i] = m_entries[i]->data.psz;
432  }
433  return tmp;
434 }
435 
436 template<size_t arraysize>
437 const std::array<double, arraysize> Geant4ParticleCollection::pex() const {
438  std::array<double, arraysize> tmp;
439  const auto valid_size = std::min(arraysize, m_entries.size());
440  for (unsigned i = 0; i < valid_size; ++i) {
441  tmp[i] = m_entries[i]->data.pex;
442  }
443  return tmp;
444 }
445 
446 template<size_t arraysize>
447 const std::array<double, arraysize> Geant4ParticleCollection::pey() const {
448  std::array<double, arraysize> tmp;
449  const auto valid_size = std::min(arraysize, m_entries.size());
450  for (unsigned i = 0; i < valid_size; ++i) {
451  tmp[i] = m_entries[i]->data.pey;
452  }
453  return tmp;
454 }
455 
456 template<size_t arraysize>
457 const std::array<double, arraysize> Geant4ParticleCollection::pez() const {
458  std::array<double, arraysize> tmp;
459  const auto valid_size = std::min(arraysize, m_entries.size());
460  for (unsigned i = 0; i < valid_size; ++i) {
461  tmp[i] = m_entries[i]->data.pez;
462  }
463  return tmp;
464 }
465 
466 template<size_t arraysize>
467 const std::array<double, arraysize> Geant4ParticleCollection::mass() const {
468  std::array<double, arraysize> tmp;
469  const auto valid_size = std::min(arraysize, m_entries.size());
470  for (unsigned i = 0; i < valid_size; ++i) {
471  tmp[i] = m_entries[i]->data.mass;
472  }
473  return tmp;
474 }
475 
476 template<size_t arraysize>
477 const std::array<double, arraysize> Geant4ParticleCollection::time() const {
478  std::array<double, arraysize> tmp;
479  const auto valid_size = std::min(arraysize, m_entries.size());
480  for (unsigned i = 0; i < valid_size; ++i) {
481  tmp[i] = m_entries[i]->data.time;
482  }
483  return tmp;
484 }
485 
486 template<size_t arraysize>
487 const std::array<double, arraysize> Geant4ParticleCollection::properTime() const {
488  std::array<double, arraysize> tmp;
489  const auto valid_size = std::min(arraysize, m_entries.size());
490  for (unsigned i = 0; i < valid_size; ++i) {
491  tmp[i] = m_entries[i]->data.properTime;
492  }
493  return tmp;
494 }
495 
496 
497 } // namespace dd4pod
498 
499 
500 #endif
std::string getValueTypeName() const override
fully qualified type name of elements - with namespace
Geant4ParticleCollectionIterator(int index, const Geant4ParticleObjPointerContainer *collection)
unsigned getID() const override final
bool operator!=(const Geant4ParticleCollectionIterator &x) const
size_t size() const override final
number of elements in the collection
Geant4Particle create()
Append a new object to the collection, and return this object.
const std::array< int, arraysize > ID() const
const Geant4ParticleCollectionIterator & operator++() const
std::vector< Geant4ParticleData > Geant4ParticleDataContainer
OStream & operator<<(OStream &os, const man_page &man)
generates man page based on command line parameters
Definition: clipp.h:6105
podio::CollRefCollection * referenceCollections() override final
void setID(unsigned ID) override final
void setBuffer(void *address) override final
std::deque< Geant4ParticleObj * > Geant4ParticleObjPointerContainer
std::vector< Geant4ParticleData > * _getBuffer()
Returns the pointer to the data buffer.
void * getBufferAddress() override final
returns the address of the pointer to the data buffer
const const_iterator begin() const
const Geant4Particle operator[](unsigned int index) const
Returns the const object of given index.
void push_back(ConstGeant4Particle object)
Append object to the collection.
podio::VectorMembersInfo * vectorMembers() override
const Geant4Particle at(unsigned int index) const
Returns the const object of given index.
A Collection is identified by an ID.
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final