EICd
EIC data model
ProtoClusterCollection.h
Go to the documentation of this file.
1 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2 
3 #ifndef EICD_ProtoClusterCollection_H
4 #define EICD_ProtoClusterCollection_H
5 
6 // datamodel specific includes
8 #include "eicd/ProtoCluster.h"
9 #include "eicd/ProtoClusterObj.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 ProtoClusterDataContainer = std::vector<ProtoClusterData>;
27 using ProtoClusterObjPointerContainer = std::deque<ProtoClusterObj*>;
28 
30 public:
31  ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* collection) : m_index(index), m_object(nullptr), m_collection(collection) {}
32 
35 
37  return m_index != x.m_index; // TODO: may not be complete
38  }
39 
43 
44 private:
45  size_t m_index;
46  ProtoCluster m_object;
47  const ProtoClusterObjPointerContainer* m_collection;
48 };
49 
50 
52 public:
53  ProtoClusterConstCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* 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  ConstProtoCluster m_object;
69  const ProtoClusterObjPointerContainer* m_collection;
70 };
71 
72 
73 /**
74 A Collection is identified by an ID.
75 */
76 class ProtoClusterCollection : public podio::CollectionBase {
77 
78 public:
81 
85 // ProtoClusterCollection(ProtoClusterVector* data, int collectionID);
87 
88  void clear() override final;
89 
90  /// operator to allow pointer like calling of members a la LCIO
91  ProtoClusterCollection* operator->() { return (ProtoClusterCollection*) this; }
92 
93  /// Append a new object to the collection, and return this object.
95 
96  /// Append a new object to the collection, and return this object.
97  /// Initialized with the parameters given
98  template<typename... Args>
99  ProtoCluster 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::ProtoCluster"); }
106 
107  /// Returns the const object of given index
108  ConstProtoCluster operator[](unsigned int index) const;
109  /// Returns the object of a given index
110  ProtoCluster operator[](unsigned int index);
111  /// Returns the const object of given index
112  ConstProtoCluster at(unsigned int index) const;
113  /// Returns the object of given index
114  ProtoCluster at(unsigned int index);
115 
116 
117  /// Append object to the collection
118  void push_back(ConstProtoCluster 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] (ProtoClusterObj* 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<ProtoClusterData>* _getBuffer() { return m_data; }
164 
165  template<size_t arraysize>
166  const std::array<eic::Index, arraysize> hitID() const;
167  template<size_t arraysize>
168  const std::array<eic::Index, arraysize> clusterID() const;
169  template<size_t arraysize>
170  const std::array<eic::Weight, arraysize> weight() const;
171 
172 private:
173  bool m_isValid{false};
174  bool m_isReadFromFile{false};
175  int m_collectionID{0};
177 
178  // members to handle 1-to-N-relations
179 
180  // members to handle vector members
181  // members to handle streaming
182  podio::CollRefCollection m_refCollections{};
183  podio::VectorMembersInfo m_vecmem_info{};
185 };
186 
187 std::ostream& operator<<(std::ostream& o, const ProtoClusterCollection& v);
188 
189 template<typename... Args>
190 ProtoCluster ProtoClusterCollection::create(Args&&... args) {
191  const int size = m_entries.size();
192  auto obj = new ProtoClusterObj({size, m_collectionID}, {args...});
193  m_entries.push_back(obj);
194  return ProtoCluster(obj);
195 }
196 
197 template<size_t arraysize>
198 const std::array<eic::Index, arraysize> ProtoClusterCollection::hitID() const {
199  std::array<eic::Index, arraysize> tmp;
200  const auto valid_size = std::min(arraysize, m_entries.size());
201  for (unsigned i = 0; i < valid_size; ++i) {
202  tmp[i] = m_entries[i]->data.hitID;
203  }
204  return tmp;
205 }
206 
207 template<size_t arraysize>
208 const std::array<eic::Index, arraysize> ProtoClusterCollection::clusterID() const {
209  std::array<eic::Index, arraysize> tmp;
210  const auto valid_size = std::min(arraysize, m_entries.size());
211  for (unsigned i = 0; i < valid_size; ++i) {
212  tmp[i] = m_entries[i]->data.clusterID;
213  }
214  return tmp;
215 }
216 
217 template<size_t arraysize>
218 const std::array<eic::Weight, arraysize> ProtoClusterCollection::weight() const {
219  std::array<eic::Weight, arraysize> tmp;
220  const auto valid_size = std::min(arraysize, m_entries.size());
221  for (unsigned i = 0; i < valid_size; ++i) {
222  tmp[i] = m_entries[i]->data.weight;
223  }
224  return tmp;
225 }
226 
227 
228 } // namespace eic
229 
230 
231 #endif
eic::operator<<
std::ostream & operator<<(std::ostream &o, const ConstBasicParticle &value)
Definition: BasicParticle.cc:102
eic::ProtoClusterCollection::ProtoClusterCollection
ProtoClusterCollection()
Definition: ProtoClusterCollection.cc:13
eic::ProtoClusterCollection::referenceCollections
podio::CollRefCollection * referenceCollections() override final
Definition: ProtoClusterCollection.h:125
eic::ProtoClusterCollection::setBuffer
void setBuffer(void *address) override final
Definition: ProtoClusterCollection.cc:101
eic::ProtoClusterCollection::~ProtoClusterCollection
~ProtoClusterCollection()
Definition: ProtoClusterCollection.cc:18
eic::ProtoClusterCollection::operator=
ProtoClusterCollection & operator=(const ProtoClusterCollection &)=delete
eic::ProtoClusterCollectionIterator::ProtoClusterCollectionIterator
ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition: ProtoClusterCollection.h:31
eic::ProtoClusterConstCollectionIterator
Definition: ProtoClusterCollection.h:51
eic::ProtoClusterConstCollectionIterator::ProtoClusterConstCollectionIterator
ProtoClusterConstCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition: ProtoClusterCollection.h:53
eic::ProtoClusterCollection::getID
unsigned getID() const override final
Definition: ProtoClusterCollection.h:137
eic::ProtoClusterConstCollectionIterator::ProtoClusterConstCollectionIterator
ProtoClusterConstCollectionIterator(const ProtoClusterConstCollectionIterator &)=delete
eic::ProtoClusterCollectionIterator::operator!=
bool operator!=(const ProtoClusterCollectionIterator &x) const
Definition: ProtoClusterCollection.h:36
eic::ProtoClusterCollection::vectorMembers
podio::VectorMembersInfo * vectorMembers() override
Definition: ProtoClusterCollection.h:127
eic::ProtoClusterCollection::setID
void setID(unsigned ID) override final
Definition: ProtoClusterCollection.h:129
eic::ProtoClusterCollection::clear
void clear() override final
Definition: ProtoClusterCollection.cc:50
eic
Definition: BasicParticle.cc:13
eic::ProtoClusterCollection::setReferences
bool setReferences(const podio::ICollectionProvider *collectionProvider) override final
Definition: ProtoClusterCollection.cc:84
eic::ProtoClusterCollection::operator[]
ConstProtoCluster operator[](unsigned int index) const
Returns the const object of given index.
Definition: ProtoClusterCollection.cc:23
eic::ProtoCluster
Definition: ProtoCluster.h:23
eic::ConstProtoCluster
Definition: ProtoClusterConst.h:21
eic::ProtoClusterCollection::ProtoClusterCollection
ProtoClusterCollection(const ProtoClusterCollection &)=delete
eic::ProtoClusterCollection::end
iterator end()
Definition: ProtoClusterCollection.h:152
eic::ProtoClusterObjPointerContainer
std::deque< ProtoClusterObj * > ProtoClusterObjPointerContainer
Definition: ProtoClusterCollection.h:27
eic::ProtoClusterCollection::size
size_t size() const override final
number of elements in the collection
Definition: ProtoClusterCollection.cc:39
eic::ProtoClusterDataContainer
std::vector< ProtoClusterData > ProtoClusterDataContainer
Definition: ProtoClusterCollection.h:26
eic::ProtoClusterCollectionIterator
Definition: ProtoClusterCollection.h:29
eic::ProtoClusterCollection::prepareAfterRead
void prepareAfterRead() override final
Definition: ProtoClusterCollection.cc:69
eic::ProtoClusterCollection
Definition: ProtoClusterCollection.h:76
eic::ProtoClusterConstCollectionIterator::operator->
ConstProtoCluster * operator->()
Definition: ProtoClusterCollection.cc:128
ProtoClusterData.h
eic::ProtoClusterConstCollectionIterator::operator!=
bool operator!=(const ProtoClusterConstCollectionIterator &x) const
Definition: ProtoClusterCollection.h:58
eic::ProtoClusterCollection::begin
iterator begin()
Definition: ProtoClusterCollection.h:146
eic::ProtoClusterCollectionIterator::operator->
ProtoCluster * operator->()
Definition: ProtoClusterCollection.cc:111
eic::ProtoClusterCollection::getBufferAddress
void * getBufferAddress() override final
returns the address of the pointer to the data buffer
Definition: ProtoClusterCollection.h:160
eic::ProtoClusterObj
Definition: ProtoClusterObj.h:18
eic::ProtoClusterConstCollectionIterator::operator*
ConstProtoCluster operator*()
Definition: ProtoClusterCollection.cc:123
eic::ProtoClusterCollection::isValid
bool isValid() const override final
Definition: ProtoClusterCollection.h:141
eic::ProtoClusterCollectionIterator::operator++
ProtoClusterCollectionIterator & operator++()
Definition: ProtoClusterCollection.cc:116
eic::ProtoClusterCollectionIterator::ProtoClusterCollectionIterator
ProtoClusterCollectionIterator(const ProtoClusterCollectionIterator &)=delete
eic::ProtoClusterCollectionIterator::operator*
ProtoCluster operator*()
Definition: ProtoClusterCollection.cc:106
eic::ProtoClusterCollection::begin
const_iterator begin() const
Definition: ProtoClusterCollection.h:149
eic::ProtoClusterCollectionIterator::operator=
ProtoClusterCollectionIterator & operator=(const ProtoClusterCollectionIterator &)=delete
eic::ProtoClusterConstCollectionIterator::operator=
ProtoClusterConstCollectionIterator & operator=(const ProtoClusterConstCollectionIterator &)=delete
eic::ProtoClusterCollection::prepareForWrite
void prepareForWrite() override final
Definition: ProtoClusterCollection.cc:56
eic::ProtoClusterCollection::end
const_iterator end() const
Definition: ProtoClusterCollection.h:155
eic::ProtoClusterCollection::create
ProtoCluster create()
Append a new object to the collection, and return this object.
Definition: ProtoClusterCollection.cc:43
eic::ProtoClusterCollection::push_back
void push_back(ConstProtoCluster object)
Append object to the collection.
Definition: ProtoClusterCollection.cc:89
eic::ProtoClusterCollection::_getBuffer
std::vector< ProtoClusterData > * _getBuffer()
Returns the pointer to the data buffer.
Definition: ProtoClusterCollection.h:163
eic::ProtoClusterConstCollectionIterator::operator++
ProtoClusterConstCollectionIterator & operator++()
Definition: ProtoClusterCollection.cc:133
ProtoClusterObj.h
eic::ProtoClusterCollection::getValueTypeName
std::string getValueTypeName() const override
fully qualified type name of elements - with namespace
Definition: ProtoClusterCollection.h:105
eic::ProtoClusterCollection::at
ConstProtoCluster at(unsigned int index) const
Returns the const object of given index.
Definition: ProtoClusterCollection.cc:27
ProtoCluster.h