TrackerHitCollection.h
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
3 #ifndef DD4POD_TrackerHitCollection_H
4 #define DD4POD_TrackerHitCollection_H
5 
6 // datamodel specific includes
8 #include "dd4pod/TrackerHit.h"
9 #include "dd4pod/TrackerHitObj.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 dd4pod {
24 
25 
26 using TrackerHitDataContainer = std::vector<TrackerHitData>;
27 using TrackerHitObjPointerContainer = std::deque<TrackerHitObj*>;
28 
30 public:
31  TrackerHitCollectionIterator(int index, const TrackerHitObjPointerContainer* 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 TrackerHit operator*() const;
38  const TrackerHit* operator->() const;
40 
41 private:
42  mutable int m_index;
43  mutable TrackerHit m_object;
44  const TrackerHitObjPointerContainer* m_collection;
45 };
46 
50 class TrackerHitCollection : public podio::CollectionBase {
51 
52 public:
54 
56 // TrackerHitCollection(const TrackerHitCollection& ) = delete; // deletion doesn't work w/ ROOT IO ! :-(
57 // TrackerHitCollection(TrackerHitVector* data, int collectionID);
59 
60  void clear() override final;
61 
63  TrackerHitCollection* operator->() { return (TrackerHitCollection*) this; }
64 
67 
70  template<typename... Args>
71  TrackerHit create(Args&&... args);
72 
74  size_t size() const override final;
75 
77  std::string getValueTypeName() const override { return std::string("dd4pod::TrackerHit"); }
78 
80  const TrackerHit operator[](unsigned int index) const;
82  TrackerHit operator[](unsigned int index);
84  const TrackerHit at(unsigned int index) const;
86  TrackerHit at(unsigned int index);
87 
88 
90  void push_back(ConstTrackerHit 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] (TrackerHitObj* 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<TrackerHitData>* _getBuffer() { return m_data; }
129 
130  template<size_t arraysize>
131  const std::array<long long, arraysize> cellID() const;
132  template<size_t arraysize>
133  const std::array<long, arraysize> flag() const;
134  template<size_t arraysize>
135  const std::array<long, arraysize> g4ID() const;
136  template<size_t arraysize>
137  const std::array<dd4pod::FourVector, arraysize> position() const;
138  template<size_t arraysize>
139  const std::array<dd4pod::FourVector, arraysize> momentum() const;
140  template<size_t arraysize>
141  const std::array<double, arraysize> length() const;
142  template<size_t arraysize>
143  const std::array<dd4pod::MonteCarloContrib, arraysize> truth() const;
144  template<size_t arraysize>
145  const std::array<double, arraysize> energyDeposit() const;
146 
147 private:
148  bool m_isValid;
149  bool m_isReadFromFile{false};
150  int m_collectionID;
152 
153  // members to handle 1-to-N-relations
154 
155  // members to handle vector members
156  // members to handle streaming
157  podio::CollRefCollection m_refCollections;
158  podio::VectorMembersInfo m_vecmem_info;
159  TrackerHitDataContainer* m_data;
160 };
161 
162 std::ostream& operator<<(std::ostream& o, const TrackerHitCollection& v);
163 
164 template<typename... Args>
165 TrackerHit TrackerHitCollection::create(Args&&... args) {
166  const int size = m_entries.size();
167  auto obj = new TrackerHitObj({size, m_collectionID}, {args...});
168  m_entries.push_back(obj);
169  return TrackerHit(obj);
170 }
171 
172 template<size_t arraysize>
173 const std::array<long long, arraysize> TrackerHitCollection::cellID() const {
174  std::array<long long, arraysize> tmp;
175  const auto valid_size = std::min(arraysize, m_entries.size());
176  for (unsigned i = 0; i < valid_size; ++i) {
177  tmp[i] = m_entries[i]->data.cellID;
178  }
179  return tmp;
180 }
181 
182 template<size_t arraysize>
183 const std::array<long, arraysize> TrackerHitCollection::flag() const {
184  std::array<long, arraysize> tmp;
185  const auto valid_size = std::min(arraysize, m_entries.size());
186  for (unsigned i = 0; i < valid_size; ++i) {
187  tmp[i] = m_entries[i]->data.flag;
188  }
189  return tmp;
190 }
191 
192 template<size_t arraysize>
193 const std::array<long, arraysize> TrackerHitCollection::g4ID() const {
194  std::array<long, arraysize> tmp;
195  const auto valid_size = std::min(arraysize, m_entries.size());
196  for (unsigned i = 0; i < valid_size; ++i) {
197  tmp[i] = m_entries[i]->data.g4ID;
198  }
199  return tmp;
200 }
201 
202 template<size_t arraysize>
203 const std::array<dd4pod::FourVector, arraysize> TrackerHitCollection::position() const {
204  std::array<dd4pod::FourVector, arraysize> tmp;
205  const auto valid_size = std::min(arraysize, m_entries.size());
206  for (unsigned i = 0; i < valid_size; ++i) {
207  tmp[i] = m_entries[i]->data.position;
208  }
209  return tmp;
210 }
211 
212 template<size_t arraysize>
213 const std::array<dd4pod::FourVector, arraysize> TrackerHitCollection::momentum() const {
214  std::array<dd4pod::FourVector, arraysize> tmp;
215  const auto valid_size = std::min(arraysize, m_entries.size());
216  for (unsigned i = 0; i < valid_size; ++i) {
217  tmp[i] = m_entries[i]->data.momentum;
218  }
219  return tmp;
220 }
221 
222 template<size_t arraysize>
223 const std::array<double, arraysize> TrackerHitCollection::length() const {
224  std::array<double, arraysize> tmp;
225  const auto valid_size = std::min(arraysize, m_entries.size());
226  for (unsigned i = 0; i < valid_size; ++i) {
227  tmp[i] = m_entries[i]->data.length;
228  }
229  return tmp;
230 }
231 
232 template<size_t arraysize>
233 const std::array<dd4pod::MonteCarloContrib, arraysize> TrackerHitCollection::truth() const {
234  std::array<dd4pod::MonteCarloContrib, arraysize> tmp;
235  const auto valid_size = std::min(arraysize, m_entries.size());
236  for (unsigned i = 0; i < valid_size; ++i) {
237  tmp[i] = m_entries[i]->data.truth;
238  }
239  return tmp;
240 }
241 
242 template<size_t arraysize>
243 const std::array<double, arraysize> TrackerHitCollection::energyDeposit() const {
244  std::array<double, arraysize> tmp;
245  const auto valid_size = std::min(arraysize, m_entries.size());
246  for (unsigned i = 0; i < valid_size; ++i) {
247  tmp[i] = m_entries[i]->data.energyDeposit;
248  }
249  return tmp;
250 }
251 
252 
253 } // namespace dd4pod
254 
255 
256 #endif
const const_iterator end() const
podio::CollRefCollection * referenceCollections() override final
void push_back(ConstTrackerHit object)
Append object to the collection.
podio::VectorMembersInfo * vectorMembers() override
const TrackerHitCollectionIterator & operator++() const
A Collection is identified by an ID.
std::vector< TrackerHitData > * _getBuffer()
Returns the pointer to the data buffer.
void setID(unsigned ID) override final
const TrackerHit at(unsigned int index) const
Returns the const object of given index.
std::deque< TrackerHitObj * > TrackerHitObjPointerContainer
OStream & operator<<(OStream &os, const man_page &man)
generates man page based on command line parameters
Definition: clipp.h:6105
const const_iterator begin() const
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final
void prepareForWrite() override final
size_t size() const override final
number of elements in the collection
TrackerHitCollectionIterator(int index, const TrackerHitObjPointerContainer *collection)
TrackerHit create()
Append a new object to the collection, and return this object.
void setBuffer(void *address) override final
bool isValid() const override final
std::vector< TrackerHitData > TrackerHitDataContainer
const TrackerHit operator[](unsigned int index) const
Returns the const object of given index.
unsigned getID() const override final
bool operator!=(const TrackerHitCollectionIterator &x) const
void prepareAfterRead() override final
std::string getValueTypeName() const override
fully qualified type name of elements - with namespace
void * getBufferAddress() override final
returns the address of the pointer to the data buffer