EDM4eic
EIC data model
Loading...
Searching...
No Matches
TrackSegmentCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_TrackSegmentCollection_H
4#define EDM4EIC_TrackSegmentCollection_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 TrackSegmentCollectionIterator(size_t index, const TrackSegmentObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackSegmentObj>{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 TrackSegment m_object { podio::utils::MaybeSharedPtr<TrackSegmentObj>{nullptr} };
81 const TrackSegmentObjPointerContainer* 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 TrackSegmentMutableCollectionIterator(size_t index, const TrackSegmentObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<TrackSegmentObj>{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 MutableTrackSegment m_object { podio::utils::MaybeSharedPtr<TrackSegmentObj>{nullptr} };
130 const TrackSegmentObjPointerContainer* m_collection{nullptr};
131};
132
133
134/**
135A Collection is identified by an ID.
136*/
137class TrackSegmentCollection : 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 TrackSegmentCollection(TrackSegmentCollectionData&& data, bool isSubsetColl);
150 // This is a move-only type
155
156// TrackSegmentCollection(TrackSegmentVector* data, uint32_t collectionID);
157 ~TrackSegmentCollection() override;
158
159 constexpr static std::string_view typeName = "edm4eic::TrackSegmentCollection";
160 constexpr static std::string_view valueTypeName = "edm4eic::TrackSegment";
161 constexpr static std::string_view dataTypeName = "edm4eic::TrackSegmentData";
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 TrackSegmentCollection* operator->() { return static_cast<TrackSegmentCollection*>(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 MutableTrackSegment 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 TrackSegment operator[](std::size_t index) const;
205 /// Returns the object of a given index
206 MutableTrackSegment operator[](std::size_t index);
207 /// Returns the const object of given index
208 TrackSegment at(std::size_t index) const;
209 /// Returns the object of given index
210 MutableTrackSegment at(std::size_t index);
211
212
213 /// Append object to the collection
214 void push_back(const MutableTrackSegment& object);
215 /// Append an object to the (subset) collection
216 void push_back(const TrackSegment& 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] (TrackSegmentObj* 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 std::vector<float> length(const size_t nElem = 0) const;
286 std::vector<float> lengthError(const size_t nElem = 0) const;
287
288private:
289 // For setReferences, we need to give our own CollectionData access to our
290 // private entries. Otherwise we would need to expose a public member function
291 // that gives access to the Obj* which is definitely not what we want
293
294 bool m_isValid{false};
295 mutable bool m_isPrepared{false};
296 bool m_isSubsetColl{false};
297 uint32_t m_collectionID{0};
298 mutable std::unique_ptr<std::mutex> m_storageMtx{nullptr};
299 mutable TrackSegmentCollectionData m_storage{};
300};
301
302std::ostream& operator<<(std::ostream& o, const TrackSegmentCollection& v);
303
304template<typename... Args>
306 if (m_isSubsetColl) {
307 throw std::logic_error("Cannot create new elements on a subset collection");
308 }
309 const int size = m_storage.entries.size();
310 auto obj = new TrackSegmentObj({size, m_collectionID}, {std::forward<Args>(args)...});
311 m_storage.entries.push_back(obj);
312
313 // Need to initialize the relation vectors manually for the {ObjectID, TrackSegmentData} constructor
314 obj->m_points = new std::vector<edm4eic::TrackPoint>();
315 m_storage.createRelations(obj);
316 return MutableTrackSegment(podio::utils::MaybeSharedPtr(obj));
317}
318
319#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
320void to_json(nlohmann::json& j, const TrackSegmentCollection& collection);
321#endif
322
323} // namespace edm4eic
324
325
326#endif
Definition MutableTrackSegment.h:37
Definition TrackSegmentCollectionData.h:31
Definition TrackSegmentCollection.h:137
void push_back(const MutableTrackSegment &object)
Append object to the collection.
Definition TrackSegmentCollection.cc:126
reverse_iterator rend()
Definition TrackSegmentCollection.h:274
std::size_t size() const final
number of elements in the collection
Definition TrackSegmentCollection.cc:52
const_iterator begin() const
Definition TrackSegmentCollection.h:249
TrackSegmentCollection & operator=(TrackSegmentCollection &&)=default
reverse_iterator rbegin()
Definition TrackSegmentCollection.h:265
const std::string_view getTypeName() const final
fully qualified type name
Definition TrackSegmentCollection.h:189
const_iterator cbegin() const
Definition TrackSegmentCollection.h:252
const_reverse_iterator crbegin() const
Definition TrackSegmentCollection.h:271
const_reverse_iterator crend() const
Definition TrackSegmentCollection.h:280
void clear() final
Definition TrackSegmentCollection.cc:93
iterator end()
Definition TrackSegmentCollection.h:255
static constexpr std::string_view valueTypeName
Definition TrackSegmentCollection.h:160
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition TrackSegmentCollection.h:145
~TrackSegmentCollection() override
Definition TrackSegmentCollection.cc:31
void setID(uint32_t ID) final
Definition TrackSegmentCollection.h:225
TrackSegment at(std::size_t index) const
Returns the const object of given index.
Definition TrackSegmentCollection.cc:40
TrackSegmentMutableCollectionIterator iterator
Definition TrackSegmentCollection.h:142
const_iterator cend() const
Definition TrackSegmentCollection.h:261
static constexpr std::string_view typeName
Definition TrackSegmentCollection.h:159
TrackSegmentCollection(const TrackSegmentCollection &)=delete
TrackSegmentCollection(TrackSegmentCollection &&)=default
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition TrackSegmentCollection.cc:454
bool isValid() const final
Definition TrackSegmentCollection.h:239
void setSubsetCollection(bool setSubset=true) final
Definition TrackSegmentCollection.cc:70
MutableTrackSegment mutable_type
Definition TrackSegmentCollection.h:140
void prepareForWrite() const final
Definition TrackSegmentCollection.cc:98
const_iterator end() const
Definition TrackSegmentCollection.h:258
const_reverse_iterator rend() const
Definition TrackSegmentCollection.h:277
TrackSegmentCollection()
Definition TrackSegmentCollection.cc:25
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition TrackSegmentCollection.cc:159
iterator begin()
Definition TrackSegmentCollection.h:246
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition TrackSegmentCollection.h:193
bool empty() const final
Is the collection empty.
Definition TrackSegmentCollection.cc:66
bool isSubsetCollection() const final
Definition TrackSegmentCollection.h:197
std::size_t max_size() const final
maximal number of elements in the collection
Definition TrackSegmentCollection.cc:56
MutableTrackSegment create()
Append a new object to the collection, and return this object.
Definition TrackSegmentCollection.cc:81
TrackSegment value_type
Definition TrackSegmentCollection.h:139
TrackSegmentCollection & operator=(const TrackSegmentCollection &)=delete
size_t size_type
Definition TrackSegmentCollection.h:144
friend class TrackSegmentCollectionData
Definition TrackSegmentCollection.h:292
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition TrackSegmentCollection.cc:122
void prepareAfterRead() final
Definition TrackSegmentCollection.cc:107
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition TrackSegmentCollection.h:191
std::reverse_iterator< iterator > reverse_iterator
Definition TrackSegmentCollection.h:146
static constexpr std::string_view dataTypeName
Definition TrackSegmentCollection.h:161
const_reverse_iterator rbegin() const
Definition TrackSegmentCollection.h:268
ptrdiff_t difference_type
Definition TrackSegmentCollection.h:143
TrackSegmentCollectionIterator const_iterator
Definition TrackSegmentCollection.h:141
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition TrackSegmentCollection.cc:188
uint32_t getID() const final
Definition TrackSegmentCollection.h:235
Definition TrackSegmentCollection.h:36
ptrdiff_t difference_type
Definition TrackSegmentCollection.h:39
TrackSegment * pointer
Definition TrackSegmentCollection.h:41
TrackSegmentCollectionIterator operator+(difference_type n) const
Definition TrackSegmentCollection.cc:330
TrackSegmentCollectionIterator & operator--()
Definition TrackSegmentCollection.cc:314
TrackSegmentCollectionIterator operator-(difference_type n) const
Definition TrackSegmentCollection.cc:345
TrackSegmentCollectionIterator & operator=(TrackSegmentCollectionIterator &&)=default
TrackSegmentCollectionIterator(const TrackSegmentCollectionIterator &)=default
TrackSegmentCollectionIterator(size_t index, const TrackSegmentObjPointerContainer *collection)
Definition TrackSegmentCollection.h:47
std::input_iterator_tag iterator_category
Definition TrackSegmentCollection.h:42
TrackSegmentCollectionIterator & operator-=(difference_type n)
Definition TrackSegmentCollection.cc:340
TrackSegment reference
Definition TrackSegmentCollection.h:40
reference operator[](difference_type n) const
Definition TrackSegmentCollection.cc:351
TrackSegmentCollectionIterator & operator++()
Definition TrackSegmentCollection.cc:303
pointer operator->()
Definition TrackSegmentCollection.cc:298
TrackSegmentCollectionIterator & operator+=(difference_type n)
Definition TrackSegmentCollection.cc:325
TrackSegmentCollectionIterator & operator=(const TrackSegmentCollectionIterator &)=default
std::random_access_iterator_tag iterator_concept
Definition TrackSegmentCollection.h:45
auto operator<=>(const TrackSegmentCollectionIterator &other) const
Definition TrackSegmentCollection.h:56
TrackSegmentCollectionIterator(TrackSegmentCollectionIterator &&)=default
bool operator==(const TrackSegmentCollectionIterator &x) const
Definition TrackSegmentCollection.h:60
reference operator*() const
Definition TrackSegmentCollection.cc:294
TrackSegment value_type
Definition TrackSegmentCollection.h:38
Definition TrackSegment.h:45
Definition TrackSegmentCollection.h:85
bool operator==(const TrackSegmentMutableCollectionIterator &x) const
Definition TrackSegmentCollection.h:109
std::input_iterator_tag iterator_category
Definition TrackSegmentCollection.h:91
TrackSegmentMutableCollectionIterator operator-(difference_type n) const
Definition TrackSegmentCollection.cc:412
TrackSegmentMutableCollectionIterator(TrackSegmentMutableCollectionIterator &&)=default
MutableTrackSegment reference
Definition TrackSegmentCollection.h:89
TrackSegmentMutableCollectionIterator(size_t index, const TrackSegmentObjPointerContainer *collection)
Definition TrackSegmentCollection.h:96
pointer operator->()
Definition TrackSegmentCollection.cc:365
TrackSegment value_type
Definition TrackSegmentCollection.h:87
TrackSegmentMutableCollectionIterator(const TrackSegmentMutableCollectionIterator &)=default
ptrdiff_t difference_type
Definition TrackSegmentCollection.h:88
MutableTrackSegment * pointer
Definition TrackSegmentCollection.h:90
reference operator*() const
Definition TrackSegmentCollection.cc:361
TrackSegmentMutableCollectionIterator & operator++()
Definition TrackSegmentCollection.cc:370
auto operator<=>(const TrackSegmentMutableCollectionIterator &other) const
Definition TrackSegmentCollection.h:105
TrackSegmentMutableCollectionIterator & operator=(const TrackSegmentMutableCollectionIterator &)=default
std::random_access_iterator_tag iterator_concept
Definition TrackSegmentCollection.h:94
TrackSegmentMutableCollectionIterator operator+(difference_type n) const
Definition TrackSegmentCollection.cc:397
TrackSegmentMutableCollectionIterator & operator=(TrackSegmentMutableCollectionIterator &&)=default
TrackSegmentMutableCollectionIterator & operator--()
Definition TrackSegmentCollection.cc:381
TrackSegmentMutableCollectionIterator & operator-=(difference_type n)
Definition TrackSegmentCollection.cc:407
TrackSegmentMutableCollectionIterator & operator+=(difference_type n)
Definition TrackSegmentCollection.cc:392
reference operator[](difference_type n) const
Definition TrackSegmentCollection.cc:418
Definition TrackSegmentObj.h:24
std::vector< edm4eic::TrackPoint > * m_points
Definition TrackSegmentObj.h:41
Definition CalorimeterHit.cc:17
std::deque< TrackSegmentObj * > TrackSegmentObjPointerContainer
Definition TrackSegmentCollectionData.h:23
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
Definition CalorimeterHit.h:31