EDM4eic
EIC data model
Loading...
Searching...
No Matches
TruthinessCollection.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_TruthinessCollection_H
4#define EDM4EIC_TruthinessCollection_H
5
6// datamodel specific includes
11
12// podio specific includes
13#include "podio/ICollectionProvider.h"
14#include "podio/CollectionBase.h"
15#include "podio/detail/Pythonizations.h"
16#include "podio/utilities/TypeHelpers.h"
17
18#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
19#include "nlohmann/json_fwd.hpp"
20#endif
21
22#include <string_view>
23#include <vector>
24#include <algorithm>
25#include <ostream>
26#include <mutex>
27#include <memory>
28#include <cstddef>
29
30namespace podio {
31 struct RelationNames;
32}
33
34namespace edm4eic {
35
36
37
39public:
41 using difference_type = ptrdiff_t;
44 using iterator_category = std::input_iterator_tag;
45 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
46 // remain valid as long as the iterator is valid, not as long as the range is valid.
47 using iterator_concept = std::random_access_iterator_tag;
48
49 TruthinessCollectionIterator(size_t index, const TruthinessObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<TruthinessObj>{nullptr}), m_collection(collection) {}
51
57
58 constexpr auto operator<=>(const TruthinessCollectionIterator& other) const {
59 return m_index <=> other.m_index;
60 }
61
62 constexpr bool operator==(const TruthinessCollectionIterator& x) const {
63 return m_index == x.m_index;
64 }
65
66 reference operator*() const;
79
80private:
81 size_t m_index{0};
82 Truthiness m_object { podio::utils::MaybeSharedPtr<TruthinessObj>{nullptr} };
83 const TruthinessObjPointerContainer* m_collection{nullptr};
84};
85
86
88public:
90 using difference_type = ptrdiff_t;
93 using iterator_category = std::input_iterator_tag;
94 // `std::forward_iterator` is supported except that the pointers obtained with `operator->()`
95 // remain valid as long as the iterator is valid, not as long as the range is valid.
96 using iterator_concept = std::random_access_iterator_tag;
97
98 TruthinessMutableCollectionIterator(size_t index, const TruthinessObjPointerContainer* collection) : m_index(index), m_object(podio::utils::MaybeSharedPtr<TruthinessObj>{nullptr}), m_collection(collection) {}
100
106
107 constexpr auto operator<=>(const TruthinessMutableCollectionIterator& other) const {
108 return m_index <=> other.m_index;
109 }
110
111 constexpr bool operator==(const TruthinessMutableCollectionIterator& x) const {
112 return m_index == x.m_index;
113 }
114
115 reference operator*() const;
128
129private:
130 size_t m_index{0};
131 MutableTruthiness m_object { podio::utils::MaybeSharedPtr<TruthinessObj>{nullptr} };
132 const TruthinessObjPointerContainer* m_collection{nullptr};
133};
134
135
136/**
137A Collection is identified by an ID.
138*/
139class TruthinessCollection : public podio::CollectionBase {
140public:
145 using difference_type = ptrdiff_t;
146 using size_type = size_t;
147 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
148 using reverse_iterator = std::reverse_iterator<iterator>;
149
151 TruthinessCollection(TruthinessCollectionData&& data, bool isSubsetColl);
152 // This is a move-only type
157
158 ~TruthinessCollection() override;
159#if defined(__cpp_lib_containers_ranges)
160 template<podio::detail::RangeConvertibleTo<value_type> R>
161 TruthinessCollection(std::from_range_t, R&& range);
162#endif
163
164 /// Construct a Truthiness collection from a range of mutable or
165 /// immutable handles
166 template<podio::detail::RangeConvertibleTo<value_type> R>
167 static TruthinessCollection from(R&& range);
168
169 constexpr static std::string_view typeName = "edm4eic::TruthinessCollection";
170 constexpr static std::string_view valueTypeName = "edm4eic::Truthiness";
171 constexpr static std::string_view dataTypeName = "edm4eic::TruthinessData";
172
173 void clear() final;
174
175 /// Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
176 static void __cppyy_pythonize__(PyObject* klass, const std::string& name){
177 podio::detail::pythonizations::pythonize_subscript(klass, name);
178 }
179
180 /// Print this collection to the passed stream
181 void print(std::ostream& os=std::cout, bool flush=true) const final;
182
183 /// Append a new object to the collection, and return this object.
185
186 /// Append a new object to the collection, and return this object.
187 /// Initialized with the parameters given
188 template<typename... Args>
189 MutableTruthiness create(Args&&... args);
190
191 /// number of elements in the collection
192 std::size_t size() const final;
193
194 /// maximal number of elements in the collection
195 std::size_t max_size() const final;
196
197 /// Is the collection empty
198 bool empty() const final;
199
200 /// fully qualified type name
201 const std::string_view getTypeName() const final { return typeName; }
202 /// fully qualified type name of elements - with namespace
203 const std::string_view getValueTypeName() const final { return valueTypeName; }
204 /// fully qualified type name of stored POD elements - with namespace
205 const std::string_view getDataTypeName() const final { return dataTypeName; }
206 /// schema version
207 podio::SchemaVersionT getSchemaVersion() const final;
208
209 bool isSubsetCollection() const final {
210 return m_isSubsetColl;
211 }
212
213 void setSubsetCollection(bool setSubset=true) final;
214
215 /// Returns the const object of given index
216 Truthiness operator[](std::size_t index) const;
217 /// Returns the object of a given index
218 MutableTruthiness operator[](std::size_t index);
219 /// Returns the const object of given index
220 Truthiness at(std::size_t index) const;
221 /// Returns the object of given index
222 MutableTruthiness at(std::size_t index);
223
224
225 /// Append object to the collection
226 void push_back(const MutableTruthiness& object);
227 /// Append an object to the (subset) collection
228 void push_back(const Truthiness& object);
229
230 void prepareForWrite() const final;
231 void prepareAfterRead() final;
232 bool setReferences(const podio::ICollectionProvider* collectionProvider) final;
233
234 /// Get the collection buffers for this collection
235 podio::CollectionWriteBuffers getBuffers() final;
236
237 void setID(uint32_t ID) final {
238 m_collectionID = ID;
239 if (!m_isSubsetColl) {
240 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
241 [ID] (TruthinessObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
242 );
243 }
244 }
245
246 uint32_t getID() const final {
247 return m_collectionID;
248 }
249
250 /// check if the collection has a valid ID
251 bool hasID() const final {
252 return getID() != static_cast<uint32_t>(podio::ObjectID::untracked) &&
253 getID() != static_cast<uint32_t>(podio::ObjectID::invalid);
254 }
255
256 [[deprecated("isValid will be removed, use hasID() if you want to check if it has an ID, otherwise assume the "
257 "collection is valid")]]
258 bool isValid() const final {
259 return hasID();
260 }
261
262 size_t getDatamodelRegistryIndex() const final;
263
264 // support for the iterator protocol
266 return iterator(0, &m_storage.entries);
267 }
269 return const_iterator(0, &m_storage.entries);
270 }
272 return begin();
273 }
275 return iterator(m_storage.entries.size(), &m_storage.entries);
276 }
278 return const_iterator(m_storage.entries.size(), &m_storage.entries);
279 }
281 return end();
282 }
283 // reverse iterators
285 return reverse_iterator(end());
286 }
291 return rbegin();
292 }
294 return reverse_iterator(begin());
295 }
300 return rend();
301 }
302
303
304 std::vector<float> truthiness(const size_t nElem = 0) const;
305 std::vector<edm4eic::TruthinessContribution> associationContribution(const size_t nElem = 0) const;
306 std::vector<float> unassociatedMCParticlesContribution(const size_t nElem = 0) const;
307 std::vector<float> unassociatedRecoParticlesContribution(const size_t nElem = 0) const;
308
309private:
310 // For setReferences, we need to give our own CollectionData access to our
311 // private entries. Otherwise we would need to expose a public member function
312 // that gives access to the Obj* which is definitely not what we want
314
315 mutable bool m_isPrepared{false};
316 bool m_isSubsetColl{false};
317 uint32_t m_collectionID{static_cast<uint32_t>(podio::ObjectID::untracked)};
318 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
319 mutable TruthinessCollectionData m_storage{};
320};
321
322std::ostream& operator<<(std::ostream& o, const TruthinessCollection& v);
323
324template<typename... Args>
326 if (m_isSubsetColl) {
327 throw std::logic_error("Cannot create new elements on a subset collection");
328 }
329 auto obj = new TruthinessObj({static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
330 m_storage.entries.push_back(obj);
331
332 // Need to initialize the relation vectors manually for the {ObjectID, TruthinessData} constructor
333 obj->m_associations = new std::vector<edm4eic::MCRecoParticleAssociation>();
334 obj->m_unassociatedMCParticles = new std::vector<edm4hep::MCParticle>();
335 obj->m_unassociatedRecoParticles = new std::vector<edm4eic::ReconstructedParticle>();
336 obj->m_associationContributions = new std::vector<edm4eic::TruthinessContribution>();
337 m_storage.createRelations(obj);
338 return MutableTruthiness(podio::utils::MaybeSharedPtr(obj));
339}
340
341
342#if defined(__cpp_lib_containers_ranges)
343template<podio::detail::RangeConvertibleTo<TruthinessCollection::value_type> R>
344TruthinessCollection::TruthinessCollection(std::from_range_t, R&& range)
346 setSubsetCollection(podio::detail::RangeOf<R, value_type>);
347
348 for (auto&& elem : range) {
349 push_back(std::forward<decltype(elem)>(elem));
350 }
351}
352#endif
353
354template<podio::detail::RangeConvertibleTo<TruthinessCollection::value_type> R>
357 if constexpr (podio::detail::RangeOf<R, value_type>) {
358 coll.setSubsetCollection();
359 }
360
361 for (auto&& elem : range) {
362 coll.push_back(std::forward<decltype(elem)>(elem));
363 }
364
365 return coll;
366}
367
368
369#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
370void to_json(nlohmann::json& j, const TruthinessCollection& collection);
371#endif
372
373} // namespace edm4eic
374
375
376// This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
377// until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
378// and https://github.com/AIDASoft/podio/issues/770
379#if defined(__clang__)
380 #pragma clang diagnostic push
381 #pragma clang diagnostic ignored "-Wunknown-warning-option"
382 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
383 #pragma clang diagnostic ignored "-Wdeprecated"
384constexpr std::string_view edm4eic::TruthinessCollection::typeName;
385constexpr std::string_view edm4eic::TruthinessCollection::valueTypeName;
386constexpr std::string_view edm4eic::TruthinessCollection::dataTypeName;
387 #pragma clang diagnostic pop
388#elif defined(__GNUC__)
389 #pragma GCC diagnostic push
390 #pragma GCC diagnostic ignored "-Wdeprecated"
391constexpr std::string_view edm4eic::TruthinessCollection::typeName;
392constexpr std::string_view edm4eic::TruthinessCollection::valueTypeName;
393constexpr std::string_view edm4eic::TruthinessCollection::dataTypeName;
394 #pragma GCC diagnostic pop
395#endif
396
397
398#endif
Definition MutableTruthiness.h:38
Definition TruthinessCollectionData.h:34
Definition TruthinessCollection.h:139
bool isValid() const final
Definition TruthinessCollection.h:258
const_reverse_iterator rbegin() const
Definition TruthinessCollection.h:287
Truthiness at(std::size_t index) const
Returns the const object of given index.
Definition TruthinessCollection.cc:39
void setID(uint32_t ID) final
Definition TruthinessCollection.h:237
const_iterator cend() const
Definition TruthinessCollection.h:280
size_t size_type
Definition TruthinessCollection.h:146
const_iterator end() const
Definition TruthinessCollection.h:277
static void __cppyy_pythonize__(PyObject *klass, const std::string &name)
Cppyy protocol to setup the pythonizations for this class. Not to be called directly.
Definition TruthinessCollection.h:176
const_iterator begin() const
Definition TruthinessCollection.h:268
void prepareAfterRead() final
Definition TruthinessCollection.cc:106
bool hasID() const final
check if the collection has a valid ID
Definition TruthinessCollection.h:251
TruthinessMutableCollectionIterator iterator
Definition TruthinessCollection.h:144
reverse_iterator rbegin()
Definition TruthinessCollection.h:284
iterator begin()
Definition TruthinessCollection.h:265
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition TruthinessCollection.cc:206
bool isSubsetCollection() const final
Definition TruthinessCollection.h:209
static constexpr std::string_view valueTypeName
Definition TruthinessCollection.h:170
uint32_t getID() const final
Definition TruthinessCollection.h:246
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition TruthinessCollection.cc:481
~TruthinessCollection() override
Definition TruthinessCollection.cc:30
const_reverse_iterator crbegin() const
Definition TruthinessCollection.h:290
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition TruthinessCollection.h:203
void clear() final
Definition TruthinessCollection.cc:92
const_reverse_iterator rend() const
Definition TruthinessCollection.h:296
MutableTruthiness create()
Append a new object to the collection, and return this object.
Definition TruthinessCollection.cc:80
void prepareForWrite() const final
Definition TruthinessCollection.cc:97
friend class TruthinessCollectionData
Definition TruthinessCollection.h:313
std::size_t size() const final
number of elements in the collection
Definition TruthinessCollection.cc:51
iterator end()
Definition TruthinessCollection.h:274
const std::string_view getTypeName() const final
fully qualified type name
Definition TruthinessCollection.h:201
static constexpr std::string_view typeName
Definition TruthinessCollection.h:169
void push_back(const MutableTruthiness &object)
Append object to the collection.
Definition TruthinessCollection.cc:125
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition TruthinessCollection.cc:157
const_reverse_iterator crend() const
Definition TruthinessCollection.h:299
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition TruthinessCollection.cc:121
void setSubsetCollection(bool setSubset=true) final
Definition TruthinessCollection.cc:69
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition TruthinessCollection.h:147
reverse_iterator rend()
Definition TruthinessCollection.h:293
Truthiness value_type
Definition TruthinessCollection.h:141
TruthinessCollectionIterator const_iterator
Definition TruthinessCollection.h:143
std::reverse_iterator< iterator > reverse_iterator
Definition TruthinessCollection.h:148
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition TruthinessCollection.h:205
TruthinessCollection(const TruthinessCollection &)=delete
std::size_t max_size() const final
maximal number of elements in the collection
Definition TruthinessCollection.cc:55
bool empty() const final
Is the collection empty.
Definition TruthinessCollection.cc:65
TruthinessCollection & operator=(const TruthinessCollection &)=delete
ptrdiff_t difference_type
Definition TruthinessCollection.h:145
MutableTruthiness mutable_type
Definition TruthinessCollection.h:142
static TruthinessCollection from(R &&range)
Definition TruthinessCollection.h:355
static constexpr std::string_view dataTypeName
Definition TruthinessCollection.h:171
const_iterator cbegin() const
Definition TruthinessCollection.h:271
TruthinessCollection(TruthinessCollection &&)=default
TruthinessCollection & operator=(TruthinessCollection &&)=default
Definition TruthinessCollection.h:38
TruthinessCollectionIterator(size_t index, const TruthinessObjPointerContainer *collection)
Definition TruthinessCollection.h:49
TruthinessCollectionIterator(TruthinessCollectionIterator &&)=default
ptrdiff_t difference_type
Definition TruthinessCollection.h:41
TruthinessCollectionIterator & operator++()
Definition TruthinessCollection.cc:315
Truthiness reference
Definition TruthinessCollection.h:42
TruthinessCollectionIterator & operator=(const TruthinessCollectionIterator &)=default
reference operator[](difference_type n) const
Definition TruthinessCollection.cc:363
std::random_access_iterator_tag iterator_concept
Definition TruthinessCollection.h:47
reference operator*() const
Definition TruthinessCollection.cc:306
TruthinessCollectionIterator operator+(difference_type n) const
Definition TruthinessCollection.cc:342
constexpr bool operator==(const TruthinessCollectionIterator &x) const
Definition TruthinessCollection.h:62
std::input_iterator_tag iterator_category
Definition TruthinessCollection.h:44
pointer operator->()
Definition TruthinessCollection.cc:310
TruthinessCollectionIterator operator-(difference_type n) const
Definition TruthinessCollection.cc:357
TruthinessCollectionIterator & operator-=(difference_type n)
Definition TruthinessCollection.cc:352
TruthinessCollectionIterator(const TruthinessCollectionIterator &)=default
Truthiness * pointer
Definition TruthinessCollection.h:43
TruthinessCollectionIterator & operator+=(difference_type n)
Definition TruthinessCollection.cc:337
constexpr auto operator<=>(const TruthinessCollectionIterator &other) const
Definition TruthinessCollection.h:58
TruthinessCollectionIterator & operator--()
Definition TruthinessCollection.cc:326
Truthiness value_type
Definition TruthinessCollection.h:40
TruthinessCollectionIterator & operator=(TruthinessCollectionIterator &&)=default
Definition Truthiness.h:46
Definition TruthinessCollection.h:87
std::random_access_iterator_tag iterator_concept
Definition TruthinessCollection.h:96
TruthinessMutableCollectionIterator & operator=(TruthinessMutableCollectionIterator &&)=default
constexpr bool operator==(const TruthinessMutableCollectionIterator &x) const
Definition TruthinessCollection.h:111
TruthinessMutableCollectionIterator(const TruthinessMutableCollectionIterator &)=default
TruthinessMutableCollectionIterator & operator=(const TruthinessMutableCollectionIterator &)=default
TruthinessMutableCollectionIterator & operator+=(difference_type n)
Definition TruthinessCollection.cc:404
MutableTruthiness reference
Definition TruthinessCollection.h:91
TruthinessMutableCollectionIterator operator-(difference_type n) const
Definition TruthinessCollection.cc:424
MutableTruthiness * pointer
Definition TruthinessCollection.h:92
TruthinessMutableCollectionIterator operator+(difference_type n) const
Definition TruthinessCollection.cc:409
constexpr auto operator<=>(const TruthinessMutableCollectionIterator &other) const
Definition TruthinessCollection.h:107
TruthinessMutableCollectionIterator & operator--()
Definition TruthinessCollection.cc:393
reference operator[](difference_type n) const
Definition TruthinessCollection.cc:430
ptrdiff_t difference_type
Definition TruthinessCollection.h:90
TruthinessMutableCollectionIterator(size_t index, const TruthinessObjPointerContainer *collection)
Definition TruthinessCollection.h:98
Truthiness value_type
Definition TruthinessCollection.h:89
reference operator*() const
Definition TruthinessCollection.cc:373
pointer operator->()
Definition TruthinessCollection.cc:377
std::input_iterator_tag iterator_category
Definition TruthinessCollection.h:93
TruthinessMutableCollectionIterator & operator-=(difference_type n)
Definition TruthinessCollection.cc:419
TruthinessMutableCollectionIterator(TruthinessMutableCollectionIterator &&)=default
TruthinessMutableCollectionIterator & operator++()
Definition TruthinessCollection.cc:382
Definition TruthinessObj.h:23
std::vector< edm4eic::MCRecoParticleAssociation > * m_associations
Definition TruthinessObj.h:39
Definition ArrowMapper.cc:61
std::deque< TruthinessObj * > TruthinessObjPointerContainer
Definition TruthinessCollectionData.h:26
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:99
Definition CalorimeterHit.h:31