3#ifndef EDM4EIC_TensorCollection_H
4#define EDM4EIC_TensorCollection_H
13#include "podio/ICollectionProvider.h"
14#include "podio/CollectionBase.h"
15#include "podio/detail/Pythonizations.h"
16#include "podio/utilities/TypeHelpers.h"
18#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
19#include "nlohmann/json_fwd.hpp"
59 return m_index <=> other.m_index;
63 return m_index == x.m_index;
82 Tensor m_object { podio::utils::MaybeSharedPtr<TensorObj>{
nullptr} };
108 return m_index <=> other.m_index;
112 return m_index == x.m_index;
131 MutableTensor m_object { podio::utils::MaybeSharedPtr<TensorObj>{
nullptr} };
159#if defined(__cpp_lib_containers_ranges)
160 template<podio::detail::RangeConvertibleTo<value_type> R>
166 template<podio::detail::RangeConvertibleTo<value_type> R>
169 constexpr static std::string_view
typeName =
"edm4eic::TensorCollection";
171 constexpr static std::string_view
dataTypeName =
"edm4eic::TensorData";
177 podio::detail::pythonizations::pythonize_subscript(klass, name);
181 void print(std::ostream& os=std::cout,
bool flush=
true) const final;
188 template<typename... Args>
192 std::
size_t size() const final;
198 bool empty() const final;
210 return m_isSubsetColl;
216 Tensor operator[](std::
size_t index) const;
239 if (!m_isSubsetColl) {
240 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
241 [ID] (
TensorObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
247 return m_collectionID;
252 return getID() !=
static_cast<uint32_t
>(podio::ObjectID::untracked) &&
253 getID() !=
static_cast<uint32_t
>(podio::ObjectID::invalid);
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")]]
262 size_t getDatamodelRegistryIndex() const final;
266 return iterator(0, &m_storage.entries);
275 return iterator(m_storage.entries.size(), &m_storage.entries);
278 return const_iterator(m_storage.entries.size(), &m_storage.entries);
304 std::vector<std::int32_t> elementType(
const size_t nElem = 0)
const;
312 mutable bool m_isPrepared{
false};
313 bool m_isSubsetColl{
false};
314 uint32_t m_collectionID{
static_cast<uint32_t
>(podio::ObjectID::untracked)};
315 mutable std::unique_ptr<std::mutex> m_storageMtx{std::make_unique<std::mutex>()};
319std::ostream&
operator<<(std::ostream& o,
const TensorCollection& v);
321template<
typename... Args>
323 if (m_isSubsetColl) {
324 throw std::logic_error(
"Cannot create new elements on a subset collection");
326 auto obj =
new TensorObj({
static_cast<int>(m_storage.entries.size()), m_collectionID}, {std::forward<Args>(args)...});
327 m_storage.entries.push_back(obj);
330 obj->
m_shape =
new std::vector<std::int64_t>();
331 obj->m_floatData =
new std::vector<float>();
332 obj->m_int64Data =
new std::vector<std::int64_t>();
333 m_storage.createRelations(obj);
338#if defined(__cpp_lib_containers_ranges)
339template<podio::detail::RangeConvertibleTo<TensorCollection::value_type> R>
344 for (
auto&& elem : range) {
345 push_back(std::forward<
decltype(elem)>(elem));
350template<podio::detail::RangeConvertibleTo<TensorCollection::value_type> R>
353 if constexpr (podio::detail::RangeOf<R, value_type>) {
357 for (
auto&& elem : range) {
358 coll.
push_back(std::forward<
decltype(elem)>(elem));
365#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
375#if defined(__clang__)
376 #pragma clang diagnostic push
377 #pragma clang diagnostic ignored "-Wunknown-warning-option"
378 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
379 #pragma clang diagnostic ignored "-Wdeprecated"
383 #pragma clang diagnostic pop
384#elif defined(__GNUC__)
385 #pragma GCC diagnostic push
386 #pragma GCC diagnostic ignored "-Wdeprecated"
390 #pragma GCC diagnostic pop
Definition MutableTensor.h:35
Definition TensorCollectionData.h:31
Definition TensorCollection.h:139
TensorCollection & operator=(TensorCollection &&)=default
Tensor value_type
Definition TensorCollection.h:141
reverse_iterator rend()
Definition TensorCollection.h:293
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition TensorCollection.h:147
const_reverse_iterator rend() const
Definition TensorCollection.h:296
~TensorCollection() override
Definition TensorCollection.cc:27
bool isSubsetCollection() const final
Definition TensorCollection.h:209
void prepareAfterRead() final
Definition TensorCollection.cc:103
ptrdiff_t difference_type
Definition TensorCollection.h:145
const_iterator cbegin() const
Definition TensorCollection.h:271
uint32_t getID() const final
Definition TensorCollection.h:246
MutableTensor mutable_type
Definition TensorCollection.h:142
MutableTensor create()
Append a new object to the collection, and return this object.
Definition TensorCollection.cc:77
iterator begin()
Definition TensorCollection.h:265
const std::string_view getTypeName() const final
fully qualified type name
Definition TensorCollection.h:201
const_iterator end() const
Definition TensorCollection.h:277
TensorCollection()=default
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition TensorCollection.h:203
const_reverse_iterator crbegin() const
Definition TensorCollection.h:290
static constexpr std::string_view valueTypeName
Definition TensorCollection.h:170
void setID(uint32_t ID) final
Definition TensorCollection.h:237
static constexpr std::string_view dataTypeName
Definition TensorCollection.h:171
static TensorCollection from(R &&range)
Definition TensorCollection.h:351
void clear() final
Definition TensorCollection.cc:89
iterator end()
Definition TensorCollection.h:274
void push_back(const MutableTensor &object)
Append object to the collection.
Definition TensorCollection.cc:122
TensorCollection(TensorCollection &&)=default
std::size_t size() const final
number of elements in the collection
Definition TensorCollection.cc:48
const_iterator cend() const
Definition TensorCollection.h:280
TensorCollection & operator=(const TensorCollection &)=delete
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition TensorCollection.cc:154
bool isValid() const final
Definition TensorCollection.h:258
static constexpr std::string_view typeName
Definition TensorCollection.h:169
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition TensorCollection.cc:173
bool hasID() const final
check if the collection has a valid ID
Definition TensorCollection.h:251
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 TensorCollection.h:176
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition TensorCollection.cc:118
TensorCollection(const TensorCollection &)=delete
void prepareForWrite() const final
Definition TensorCollection.cc:94
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition TensorCollection.h:205
const_reverse_iterator rbegin() const
Definition TensorCollection.h:287
size_t size_type
Definition TensorCollection.h:146
friend class TensorCollectionData
Definition TensorCollection.h:310
const_iterator begin() const
Definition TensorCollection.h:268
void setSubsetCollection(bool setSubset=true) final
Definition TensorCollection.cc:66
std::reverse_iterator< iterator > reverse_iterator
Definition TensorCollection.h:148
Tensor at(std::size_t index) const
Returns the const object of given index.
Definition TensorCollection.cc:36
reverse_iterator rbegin()
Definition TensorCollection.h:284
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition TensorCollection.cc:444
const_reverse_iterator crend() const
Definition TensorCollection.h:299
TensorCollectionIterator const_iterator
Definition TensorCollection.h:143
bool empty() const final
Is the collection empty.
Definition TensorCollection.cc:62
std::size_t max_size() const final
maximal number of elements in the collection
Definition TensorCollection.cc:52
TensorMutableCollectionIterator iterator
Definition TensorCollection.h:144
Definition TensorCollection.h:38
TensorCollectionIterator(const TensorCollectionIterator &)=default
pointer operator->()
Definition TensorCollection.cc:281
TensorCollectionIterator & operator-=(difference_type n)
Definition TensorCollection.cc:323
ptrdiff_t difference_type
Definition TensorCollection.h:41
TensorCollectionIterator & operator=(const TensorCollectionIterator &)=default
TensorCollectionIterator()=default
TensorCollectionIterator & operator+=(difference_type n)
Definition TensorCollection.cc:308
Tensor reference
Definition TensorCollection.h:42
reference operator[](difference_type n) const
Definition TensorCollection.cc:334
TensorCollectionIterator(size_t index, const TensorObjPointerContainer *collection)
Definition TensorCollection.h:49
std::random_access_iterator_tag iterator_concept
Definition TensorCollection.h:47
TensorCollectionIterator operator+(difference_type n) const
Definition TensorCollection.cc:313
Tensor value_type
Definition TensorCollection.h:40
std::input_iterator_tag iterator_category
Definition TensorCollection.h:44
TensorCollectionIterator & operator++()
Definition TensorCollection.cc:286
constexpr auto operator<=>(const TensorCollectionIterator &other) const
Definition TensorCollection.h:58
reference operator*() const
Definition TensorCollection.cc:277
TensorCollectionIterator operator-(difference_type n) const
Definition TensorCollection.cc:328
TensorCollectionIterator & operator--()
Definition TensorCollection.cc:297
~TensorCollectionIterator()=default
Tensor * pointer
Definition TensorCollection.h:43
constexpr bool operator==(const TensorCollectionIterator &x) const
Definition TensorCollection.h:62
TensorCollectionIterator(TensorCollectionIterator &&)=default
TensorCollectionIterator & operator=(TensorCollectionIterator &&)=default
Definition TensorCollection.h:87
TensorMutableCollectionIterator & operator++()
Definition TensorCollection.cc:353
std::input_iterator_tag iterator_category
Definition TensorCollection.h:93
MutableTensor reference
Definition TensorCollection.h:91
TensorMutableCollectionIterator(size_t index, const TensorObjPointerContainer *collection)
Definition TensorCollection.h:98
reference operator*() const
Definition TensorCollection.cc:344
TensorMutableCollectionIterator(const TensorMutableCollectionIterator &)=default
TensorMutableCollectionIterator & operator=(TensorMutableCollectionIterator &&)=default
MutableTensor * pointer
Definition TensorCollection.h:92
constexpr auto operator<=>(const TensorMutableCollectionIterator &other) const
Definition TensorCollection.h:107
~TensorMutableCollectionIterator()=default
TensorMutableCollectionIterator & operator-=(difference_type n)
Definition TensorCollection.cc:390
Tensor value_type
Definition TensorCollection.h:89
constexpr bool operator==(const TensorMutableCollectionIterator &x) const
Definition TensorCollection.h:111
reference operator[](difference_type n) const
Definition TensorCollection.cc:401
TensorMutableCollectionIterator()=default
TensorMutableCollectionIterator & operator+=(difference_type n)
Definition TensorCollection.cc:375
TensorMutableCollectionIterator(TensorMutableCollectionIterator &&)=default
ptrdiff_t difference_type
Definition TensorCollection.h:90
TensorMutableCollectionIterator operator+(difference_type n) const
Definition TensorCollection.cc:380
std::random_access_iterator_tag iterator_concept
Definition TensorCollection.h:96
TensorMutableCollectionIterator & operator=(const TensorMutableCollectionIterator &)=default
pointer operator->()
Definition TensorCollection.cc:348
TensorMutableCollectionIterator operator-(difference_type n) const
Definition TensorCollection.cc:395
TensorMutableCollectionIterator & operator--()
Definition TensorCollection.cc:364
Definition TensorObj.h:19
std::vector< std::int64_t > * m_shape
Definition TensorObj.h:35
Definition ArrowMapper.cc:61
std::deque< TensorObj * > TensorObjPointerContainer
Definition TensorCollectionData.h:23
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:99
Definition CalorimeterHit.h:31