CalorimeterHitCollection.h
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
3 #ifndef DD4POD_CalorimeterHitCollection_H
4 #define DD4POD_CalorimeterHitCollection_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 CalorimeterHitDataContainer = std::vector<CalorimeterHitData>;
27 using CalorimeterHitObjPointerContainer = std::deque<CalorimeterHitObj*>;
28 
30 public:
31  CalorimeterHitCollectionIterator(int index, const CalorimeterHitObjPointerContainer* 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 CalorimeterHit operator*() const;
38  const CalorimeterHit* operator->() const;
40 
41 private:
42  mutable int m_index;
43  mutable CalorimeterHit m_object;
44  const CalorimeterHitObjPointerContainer* m_collection;
45 };
46 
50 class CalorimeterHitCollection : public podio::CollectionBase {
51 
52 public:
54 
56 // CalorimeterHitCollection(const CalorimeterHitCollection& ) = delete; // deletion doesn't work w/ ROOT IO ! :-(
57 // CalorimeterHitCollection(CalorimeterHitVector* data, int collectionID);
59 
60  void clear() override final;
61 
63  CalorimeterHitCollection* operator->() { return (CalorimeterHitCollection*) this; }
64 
67 
70  template<typename... Args>
71  CalorimeterHit create(Args&&... args);
72 
74  size_t size() const override final;
75 
77  std::string getValueTypeName() const override { return std::string("dd4pod::CalorimeterHit"); }
78 
80  const CalorimeterHit operator[](unsigned int index) const;
82  CalorimeterHit operator[](unsigned int index);
84  const CalorimeterHit at(unsigned int index) const;
86  CalorimeterHit at(unsigned int index);
87 
88 
90  void push_back(ConstCalorimeterHit 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] (CalorimeterHitObj* 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<CalorimeterHitData>* _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::MonteCarloContrib, arraysize> truth() const;
140  template<size_t arraysize>
141  const std::array<double, arraysize> energyDeposit() const;
142 
143 private:
144  bool m_isValid;
145  bool m_isReadFromFile{false};
146  int m_collectionID;
148 
149  // members to handle 1-to-N-relations
150 
151  // members to handle vector members
152  // members to handle streaming
153  podio::CollRefCollection m_refCollections;
154  podio::VectorMembersInfo m_vecmem_info;
156 };
157 
158 std::ostream& operator<<(std::ostream& o, const CalorimeterHitCollection& v);
159 
160 template<typename... Args>
161 CalorimeterHit CalorimeterHitCollection::create(Args&&... args) {
162  const int size = m_entries.size();
163  auto obj = new CalorimeterHitObj({size, m_collectionID}, {args...});
164  m_entries.push_back(obj);
165  return CalorimeterHit(obj);
166 }
167 
168 template<size_t arraysize>
169 const std::array<long long, arraysize> CalorimeterHitCollection::cellID() const {
170  std::array<long long, arraysize> tmp;
171  const auto valid_size = std::min(arraysize, m_entries.size());
172  for (unsigned i = 0; i < valid_size; ++i) {
173  tmp[i] = m_entries[i]->data.cellID;
174  }
175  return tmp;
176 }
177 
178 template<size_t arraysize>
179 const std::array<long, arraysize> CalorimeterHitCollection::flag() const {
180  std::array<long, arraysize> tmp;
181  const auto valid_size = std::min(arraysize, m_entries.size());
182  for (unsigned i = 0; i < valid_size; ++i) {
183  tmp[i] = m_entries[i]->data.flag;
184  }
185  return tmp;
186 }
187 
188 template<size_t arraysize>
189 const std::array<long, arraysize> CalorimeterHitCollection::g4ID() const {
190  std::array<long, arraysize> tmp;
191  const auto valid_size = std::min(arraysize, m_entries.size());
192  for (unsigned i = 0; i < valid_size; ++i) {
193  tmp[i] = m_entries[i]->data.g4ID;
194  }
195  return tmp;
196 }
197 
198 template<size_t arraysize>
199 const std::array<dd4pod::FourVector, arraysize> CalorimeterHitCollection::position() const {
200  std::array<dd4pod::FourVector, arraysize> tmp;
201  const auto valid_size = std::min(arraysize, m_entries.size());
202  for (unsigned i = 0; i < valid_size; ++i) {
203  tmp[i] = m_entries[i]->data.position;
204  }
205  return tmp;
206 }
207 
208 template<size_t arraysize>
209 const std::array<dd4pod::MonteCarloContrib, arraysize> CalorimeterHitCollection::truth() const {
210  std::array<dd4pod::MonteCarloContrib, arraysize> tmp;
211  const auto valid_size = std::min(arraysize, m_entries.size());
212  for (unsigned i = 0; i < valid_size; ++i) {
213  tmp[i] = m_entries[i]->data.truth;
214  }
215  return tmp;
216 }
217 
218 template<size_t arraysize>
219 const std::array<double, arraysize> CalorimeterHitCollection::energyDeposit() const {
220  std::array<double, arraysize> tmp;
221  const auto valid_size = std::min(arraysize, m_entries.size());
222  for (unsigned i = 0; i < valid_size; ++i) {
223  tmp[i] = m_entries[i]->data.energyDeposit;
224  }
225  return tmp;
226 }
227 
228 
229 } // namespace dd4pod
230 
231 
232 #endif
void setBuffer(void *address) override final
podio::CollRefCollection * referenceCollections() override final
CalorimeterHit create()
Append a new object to the collection, and return this object.
podio::VectorMembersInfo * vectorMembers() override
const CalorimeterHit operator[](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
std::vector< CalorimeterHitData > CalorimeterHitDataContainer
OStream & operator<<(OStream &os, const man_page &man)
generates man page based on command line parameters
Definition: clipp.h:6105
unsigned getID() const override final
void * getBufferAddress() override final
returns the address of the pointer to the data buffer
const CalorimeterHitCollectionIterator & operator++() const
size_t size() const override final
number of elements in the collection
std::deque< CalorimeterHitObj * > CalorimeterHitObjPointerContainer
const const_iterator begin() const
bool operator!=(const CalorimeterHitCollectionIterator &x) const
const CalorimeterHit at(unsigned int index) const
Returns the const object of given index.
CalorimeterHitCollectionIterator(int index, const CalorimeterHitObjPointerContainer *collection)
void setID(unsigned ID) override final
void push_back(ConstCalorimeterHit object)
Append object to the collection.
std::vector< CalorimeterHitData > * _getBuffer()
Returns the pointer to the data buffer.
std::string getValueTypeName() const override
fully qualified type name of elements - with namespace