EDM4eic
EIC data model
Loading...
Searching...
No Matches
ProtoClusterCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_ProtoClusterCollection_H
4#define EDM4EIC_ProtoClusterCollection_H
5
6// datamodel specific includes
11
12// podio specific includes
13#include "podio/ICollectionProvider.h"
14#include "podio/CollectionBase.h"
15
16#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
17#include "nlohmann/json_fwd.hpp"
18#endif
19
20#include <string_view>
21#include <vector>
22#include <algorithm>
23#include <ostream>
24#include <mutex>
25#include <memory>
26#include <cstddef>
27
28namespace podio {
29 struct RelationNames;
30}
31
32namespace edm4eic {
33
34
35
37public:
39 using difference_type = ptrdiff_t;
42 using iterator_category = std::input_iterator_tag;
43 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
44 // remain valid as long as the iterator is valid, not as long as the range is valid.
45 using iterator_concept = std::random_access_iterator_tag;
46
47 ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr}), m_collection(collection) {}
49
55
57 return m_index <=> other.m_index;
58 }
59
61 return m_index == x.m_index;
62 }
63
64 reference operator*() const;
77
78private:
79 size_t m_index{0};
80 ProtoCluster m_object { podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr} };
81 const ProtoClusterObjPointerContainer* m_collection{nullptr};
82};
83
84
86public:
88 using difference_type = ptrdiff_t;
91 using iterator_category = std::input_iterator_tag;
92 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
93 // remain valid as long as the iterator is valid, not as long as the range is valid.
94 using iterator_concept = std::random_access_iterator_tag;
95
96 ProtoClusterMutableCollectionIterator(size_t index, const ProtoClusterObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr}), m_collection(collection) {}
98
104
106 return m_index <=> other.m_index;
107 }
108
110 return m_index == x.m_index;
111 }
112
113 reference operator*() const;
126
127private:
128 size_t m_index{0};
129 MutableProtoCluster m_object { podio::utils::MaybeSharedPtr<ProtoClusterObj>{nullptr} };
130 const ProtoClusterObjPointerContainer* m_collection{nullptr};
131};
132
133
134/**
135A Collection is identified by an ID.
136*/
137class ProtoClusterCollection : public podio::CollectionBase {
138public:
143 using difference_type = ptrdiff_t;
144 using size_type = size_t;
145 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
146 using reverse_iterator = std::reverse_iterator<iterator>;
147
149 ProtoClusterCollection(ProtoClusterCollectionData&& data, bool isSubsetColl);
150 // This is a move-only type
155
156// ProtoClusterCollection(ProtoClusterVector* data, uint32_t collectionID);
157 ~ProtoClusterCollection() override;
158
159 constexpr static std::string_view typeName = "edm4eic::ProtoClusterCollection";
160 constexpr static std::string_view valueTypeName = "edm4eic::ProtoCluster";
161 constexpr static std::string_view dataTypeName = "edm4eic::ProtoClusterData";
162
163 void clear() final;
164
165 /// Print this collection to the passed stream
166 void print(std::ostream& os=std::cout, bool flush=true) const final;
167
168 /// operator to allow pointer like calling of members a la LCIO
169 ProtoClusterCollection* operator->() { return static_cast<ProtoClusterCollection*>(this); }
170
171 /// Append a new object to the collection, and return this object.
173
174 /// Append a new object to the collection, and return this object.
175 /// Initialized with the parameters given
176 template<typename... Args>
177 MutableProtoCluster create(Args&&... args);
178
179 /// number of elements in the collection
180 std::size_t size() const final;
181
182 /// maximal number of elements in the collection
183 std::size_t max_size() const final;
184
185 /// Is the collection empty
186 bool empty() const final;
187
188 /// fully qualified type name
189 const std::string_view getTypeName() const final { return typeName; }
190 /// fully qualified type name of elements - with namespace
191 const std::string_view getValueTypeName() const final { return valueTypeName; }
192 /// fully qualified type name of stored POD elements - with namespace
193 const std::string_view getDataTypeName() const final { return dataTypeName; }
194 /// schema version
195 podio::SchemaVersionT getSchemaVersion() const final;
196
197 bool isSubsetCollection() const final {
198 return m_isSubsetColl;
199 }
200
201 void setSubsetCollection(bool setSubset=true) final;
202
203 /// Returns the const object of given index
204 ProtoCluster operator[](std::size_t index) const;
205 /// Returns the object of a given index
206 MutableProtoCluster operator[](std::size_t index);
207 /// Returns the const object of given index
208 ProtoCluster at(std::size_t index) const;
209 /// Returns the object of given index
210 MutableProtoCluster at(std::size_t index);
211
212
213 /// Append object to the collection
214 void push_back(const MutableProtoCluster& object);
215 /// Append an object to the (subset) collection
216 void push_back(const ProtoCluster& object);
217
218 void prepareForWrite() const final;
219 void prepareAfterRead() final;
220 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
221
222 /// Get the collection buffers for this collection
223 podio::CollectionWriteBuffers getBuffers() final;
224
225 void setID(uint32_t ID) final {
226 m_collectionID = ID;
227 if (!m_isSubsetColl) {
228 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
229 [ID] (ProtoClusterObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
230 );
231 }
232 m_isValid = true;
233 }
234
235 uint32_t getID() const final {
236 return m_collectionID;
237 }
238
239 bool isValid() const final {
240 return m_isValid;
241 }
242
243 size_t getDatamodelRegistryIndex() const final;
244
245 // support for the iterator protocol
247 return iterator(0, &m_storage.entries);
248 }
250 return const_iterator(0, &m_storage.entries);
251 }
253 return begin();
254 }
256 return iterator(m_storage.entries.size(), &m_storage.entries);
257 }
259 return const_iterator(m_storage.entries.size(), &m_storage.entries);
260 }
262 return end();
263 }
264 // reverse iterators
266 return reverse_iterator(end());
267 }
272 return rbegin();
273 }
275 return reverse_iterator(begin());
276 }
281 return rend();
282 }
283
284
285
286private:
287 // For setReferences, we need to give our own CollectionData access to our
288 // private entries. Otherwise we would need to expose a public member function
289 // that gives access to the Obj* which is definitely not what we want
291
292 bool m_isValid{false};
293 mutable bool m_isPrepared{false};
294 bool m_isSubsetColl{false};
295 uint32_t m_collectionID{0};
296 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
297 mutable ProtoClusterCollectionData m_storage{};
298};
299
300std::ostream& operator<<(std::ostream& o, const ProtoClusterCollection& v);
301
302template<typename... Args>
304 if (m_isSubsetColl) {
305 throw std::logic_error("Cannot create new elements on a subset collection");
306 }
307 const int size = m_storage.entries.size();
308 auto obj = new ProtoClusterObj({size, m_collectionID}, {std::forward<Args>(args)...});
309 m_storage.entries.push_back(obj);
310
311 // Need to initialize the relation vectors manually for the {ObjectID, ProtoClusterData} constructor
312 obj->m_hits = new std::vector<edm4eic::CalorimeterHit>();
313 obj->m_weights = new std::vector<float>();
314 m_storage.createRelations(obj);
315 return MutableProtoCluster(podio::utils::MaybeSharedPtr(obj));
316}
317
318#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
319void to_json(nlohmann::json& j, const ProtoClusterCollection& collection);
320#endif
321
322} // namespace edm4eic
323
324
325#endif
Definition MutableProtoCluster.h:35
Definition ProtoClusterCollectionData.h:31
Definition ProtoClusterCollection.h:137
const_reverse_iterator crend() const
Definition ProtoClusterCollection.h:280
ProtoClusterCollection(ProtoClusterCollection &&)=default
std::size_t max_size() const final
maximal number of elements in the collection
Definition ProtoClusterCollection.cc:56
ProtoClusterMutableCollectionIterator iterator
Definition ProtoClusterCollection.h:142
std::reverse_iterator< iterator > reverse_iterator
Definition ProtoClusterCollection.h:146
bool isValid() const final
Definition ProtoClusterCollection.h:239
void push_back(const MutableProtoCluster &object)
Append object to the collection.
Definition ProtoClusterCollection.cc:126
const_iterator end() const
Definition ProtoClusterCollection.h:258
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition ProtoClusterCollection.cc:168
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition ProtoClusterCollection.cc:122
uint32_t getID() const final
Definition ProtoClusterCollection.h:235
friend class ProtoClusterCollectionData
Definition ProtoClusterCollection.h:290
reverse_iterator rend()
Definition ProtoClusterCollection.h:274
bool isSubsetCollection() const final
Definition ProtoClusterCollection.h:197
ProtoClusterCollection()
Definition ProtoClusterCollection.cc:25
static constexpr std::string_view dataTypeName
Definition ProtoClusterCollection.h:161
void prepareAfterRead() final
Definition ProtoClusterCollection.cc:107
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition ProtoClusterCollection.h:191
iterator begin()
Definition ProtoClusterCollection.h:246
void prepareForWrite() const final
Definition ProtoClusterCollection.cc:98
const_reverse_iterator crbegin() const
Definition ProtoClusterCollection.h:271
MutableProtoCluster mutable_type
Definition ProtoClusterCollection.h:140
MutableProtoCluster create()
Append a new object to the collection, and return this object.
Definition ProtoClusterCollection.cc:81
const std::string_view getTypeName() const final
fully qualified type name
Definition ProtoClusterCollection.h:189
~ProtoClusterCollection() override
Definition ProtoClusterCollection.cc:31
const_iterator begin() const
Definition ProtoClusterCollection.h:249
const_reverse_iterator rbegin() const
Definition ProtoClusterCollection.h:268
size_t size_type
Definition ProtoClusterCollection.h:144
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition ProtoClusterCollection.h:145
ProtoClusterCollection(const ProtoClusterCollection &)=delete
std::size_t size() const final
number of elements in the collection
Definition ProtoClusterCollection.cc:52
void setID(uint32_t ID) final
Definition ProtoClusterCollection.h:225
void setSubsetCollection(bool setSubset=true) final
Definition ProtoClusterCollection.cc:70
static constexpr std::string_view typeName
Definition ProtoClusterCollection.h:159
reverse_iterator rbegin()
Definition ProtoClusterCollection.h:265
static constexpr std::string_view valueTypeName
Definition ProtoClusterCollection.h:160
ProtoClusterCollection & operator=(const ProtoClusterCollection &)=delete
ProtoCluster at(std::size_t index) const
Returns the const object of given index.
Definition ProtoClusterCollection.cc:40
ProtoCluster value_type
Definition ProtoClusterCollection.h:139
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition ProtoClusterCollection.h:193
iterator end()
Definition ProtoClusterCollection.h:255
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition ProtoClusterCollection.cc:435
ptrdiff_t difference_type
Definition ProtoClusterCollection.h:143
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition ProtoClusterCollection.cc:159
ProtoClusterCollectionIterator const_iterator
Definition ProtoClusterCollection.h:141
void clear() final
Definition ProtoClusterCollection.cc:93
const_reverse_iterator rend() const
Definition ProtoClusterCollection.h:277
ProtoClusterCollection & operator=(ProtoClusterCollection &&)=default
const_iterator cend() const
Definition ProtoClusterCollection.h:261
const_iterator cbegin() const
Definition ProtoClusterCollection.h:252
bool empty() const final
Is the collection empty.
Definition ProtoClusterCollection.cc:66
Definition ProtoClusterCollection.h:36
auto operator<=>(const ProtoClusterCollectionIterator &other) const
Definition ProtoClusterCollection.h:56
ProtoClusterCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition ProtoClusterCollection.h:47
pointer operator->()
Definition ProtoClusterCollection.cc:278
ProtoClusterCollectionIterator(ProtoClusterCollectionIterator &&)=default
ProtoCluster reference
Definition ProtoClusterCollection.h:40
std::random_access_iterator_tag iterator_concept
Definition ProtoClusterCollection.h:45
ProtoClusterCollectionIterator & operator-=(difference_type n)
Definition ProtoClusterCollection.cc:320
ProtoClusterCollectionIterator & operator++()
Definition ProtoClusterCollection.cc:283
ProtoClusterCollectionIterator & operator=(const ProtoClusterCollectionIterator &)=default
ProtoClusterCollectionIterator & operator=(ProtoClusterCollectionIterator &&)=default
ProtoClusterCollectionIterator & operator--()
Definition ProtoClusterCollection.cc:294
ProtoClusterCollectionIterator operator-(difference_type n) const
Definition ProtoClusterCollection.cc:325
bool operator==(const ProtoClusterCollectionIterator &x) const
Definition ProtoClusterCollection.h:60
ProtoCluster * pointer
Definition ProtoClusterCollection.h:41
ProtoClusterCollectionIterator & operator+=(difference_type n)
Definition ProtoClusterCollection.cc:305
ProtoClusterCollectionIterator operator+(difference_type n) const
Definition ProtoClusterCollection.cc:310
reference operator[](difference_type n) const
Definition ProtoClusterCollection.cc:331
ProtoClusterCollectionIterator(const ProtoClusterCollectionIterator &)=default
std::input_iterator_tag iterator_category
Definition ProtoClusterCollection.h:42
reference operator*() const
Definition ProtoClusterCollection.cc:274
ptrdiff_t difference_type
Definition ProtoClusterCollection.h:39
ProtoCluster value_type
Definition ProtoClusterCollection.h:38
Definition ProtoCluster.h:43
Definition ProtoClusterCollection.h:85
bool operator==(const ProtoClusterMutableCollectionIterator &x) const
Definition ProtoClusterCollection.h:109
MutableProtoCluster * pointer
Definition ProtoClusterCollection.h:90
ProtoClusterMutableCollectionIterator & operator-=(difference_type n)
Definition ProtoClusterCollection.cc:387
MutableProtoCluster reference
Definition ProtoClusterCollection.h:89
ProtoClusterMutableCollectionIterator operator-(difference_type n) const
Definition ProtoClusterCollection.cc:392
ProtoClusterMutableCollectionIterator(const ProtoClusterMutableCollectionIterator &)=default
reference operator*() const
Definition ProtoClusterCollection.cc:341
std::random_access_iterator_tag iterator_concept
Definition ProtoClusterCollection.h:94
ProtoClusterMutableCollectionIterator operator+(difference_type n) const
Definition ProtoClusterCollection.cc:377
ProtoClusterMutableCollectionIterator & operator=(const ProtoClusterMutableCollectionIterator &)=default
ProtoCluster value_type
Definition ProtoClusterCollection.h:87
reference operator[](difference_type n) const
Definition ProtoClusterCollection.cc:398
ProtoClusterMutableCollectionIterator(size_t index, const ProtoClusterObjPointerContainer *collection)
Definition ProtoClusterCollection.h:96
auto operator<=>(const ProtoClusterMutableCollectionIterator &other) const
Definition ProtoClusterCollection.h:105
ProtoClusterMutableCollectionIterator & operator+=(difference_type n)
Definition ProtoClusterCollection.cc:372
std::input_iterator_tag iterator_category
Definition ProtoClusterCollection.h:91
ProtoClusterMutableCollectionIterator & operator++()
Definition ProtoClusterCollection.cc:350
ptrdiff_t difference_type
Definition ProtoClusterCollection.h:88
pointer operator->()
Definition ProtoClusterCollection.cc:345
ProtoClusterMutableCollectionIterator & operator=(ProtoClusterMutableCollectionIterator &&)=default
ProtoClusterMutableCollectionIterator & operator--()
Definition ProtoClusterCollection.cc:361
ProtoClusterMutableCollectionIterator(ProtoClusterMutableCollectionIterator &&)=default
Definition ProtoClusterObj.h:20
std::vector< edm4eic::CalorimeterHit > * m_hits
Definition ProtoClusterObj.h:36
Definition CalorimeterHit.cc:17
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
std::deque< ProtoClusterObj * > ProtoClusterObjPointerContainer
Definition ProtoClusterCollectionData.h:23
Definition CalorimeterHit.h:31