3#ifndef EDM4EIC_TensorCollection_H
4#define EDM4EIC_TensorCollection_H
13#include "podio/ICollectionProvider.h"
14#include "podio/CollectionBase.h"
16#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
17#include "nlohmann/json_fwd.hpp"
57 return m_index <=> other.m_index;
61 return m_index == x.m_index;
80 Tensor m_object { podio::utils::MaybeSharedPtr<TensorObj>{
nullptr} };
106 return m_index <=> other.m_index;
110 return m_index == x.m_index;
129 MutableTensor m_object { podio::utils::MaybeSharedPtr<TensorObj>{
nullptr} };
159 constexpr static std::string_view
typeName =
"edm4eic::TensorCollection";
161 constexpr static std::string_view
dataTypeName =
"edm4eic::TensorData";
166 void print(std::ostream& os=std::cout,
bool flush=true) const final;
176 template<
typename... Args>
180 std::size_t
size() const final;
186 bool empty() const final;
198 return m_isSubsetColl;
204 Tensor operator[](std::
size_t index) const;
227 if (!m_isSubsetColl) {
228 std::for_each(m_storage.entries.begin(), m_storage.entries.end(),
229 [ID] (
TensorObj* obj) { obj->id = {obj->id.index, static_cast<uint32_t>(ID)}; }
236 return m_collectionID;
243 size_t getDatamodelRegistryIndex() const final;
247 return iterator(0, &m_storage.entries);
256 return iterator(m_storage.entries.size(), &m_storage.entries);
259 return const_iterator(m_storage.entries.size(), &m_storage.entries);
285 std::vector<std::int32_t> elementType(
const size_t nElem = 0)
const;
293 bool m_isValid{
false};
294 mutable bool m_isPrepared{
false};
295 bool m_isSubsetColl{
false};
296 uint32_t m_collectionID{0};
297 mutable std::unique_ptr<std::mutex> m_storageMtx{
nullptr};
301std::ostream&
operator<<(std::ostream& o,
const TensorCollection& v);
303template<
typename... Args>
305 if (m_isSubsetColl) {
306 throw std::logic_error(
"Cannot create new elements on a subset collection");
308 const int size = m_storage.entries.size();
309 auto obj =
new TensorObj({
size, m_collectionID}, {std::forward<Args>(args)...});
310 m_storage.entries.push_back(obj);
313 obj->
m_shape =
new std::vector<std::int64_t>();
314 obj->m_floatData =
new std::vector<float>();
315 obj->m_int64Data =
new std::vector<std::int64_t>();
316 m_storage.createRelations(obj);
320#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
Definition MutableTensor.h:35
Definition TensorCollectionData.h:30
Definition TensorCollection.h:137
TensorCollection & operator=(TensorCollection &&)=default
Tensor value_type
Definition TensorCollection.h:139
reverse_iterator rend()
Definition TensorCollection.h:274
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition TensorCollection.h:145
const_reverse_iterator rend() const
Definition TensorCollection.h:277
~TensorCollection() override
Definition TensorCollection.cc:30
TensorCollection()
Definition TensorCollection.cc:24
bool isSubsetCollection() const final
Definition TensorCollection.h:197
void prepareAfterRead() final
Definition TensorCollection.cc:106
ptrdiff_t difference_type
Definition TensorCollection.h:143
const_iterator cbegin() const
Definition TensorCollection.h:252
uint32_t getID() const final
Definition TensorCollection.h:235
MutableTensor mutable_type
Definition TensorCollection.h:140
MutableTensor create()
Append a new object to the collection, and return this object.
Definition TensorCollection.cc:80
iterator begin()
Definition TensorCollection.h:246
const std::string_view getTypeName() const final
fully qualified type name
Definition TensorCollection.h:189
const_iterator end() const
Definition TensorCollection.h:258
const std::string_view getValueTypeName() const final
fully qualified type name of elements - with namespace
Definition TensorCollection.h:191
const_reverse_iterator crbegin() const
Definition TensorCollection.h:271
static constexpr std::string_view valueTypeName
Definition TensorCollection.h:160
void setID(uint32_t ID) final
Definition TensorCollection.h:225
static constexpr std::string_view dataTypeName
Definition TensorCollection.h:161
void clear() final
Definition TensorCollection.cc:92
iterator end()
Definition TensorCollection.h:255
void push_back(const MutableTensor &object)
Append object to the collection.
Definition TensorCollection.cc:125
TensorCollection(TensorCollection &&)=default
std::size_t size() const final
number of elements in the collection
Definition TensorCollection.cc:51
const_iterator cend() const
Definition TensorCollection.h:261
TensorCollection & operator=(const TensorCollection &)=delete
podio::CollectionWriteBuffers getBuffers() final
Get the collection buffers for this collection.
Definition TensorCollection.cc:158
bool isValid() const final
Definition TensorCollection.h:239
static constexpr std::string_view typeName
Definition TensorCollection.h:159
podio::SchemaVersionT getSchemaVersion() const final
schema version
Definition TensorCollection.cc:177
bool setReferences(const podio::ICollectionProvider *collectionProvider) final
Definition TensorCollection.cc:121
TensorCollection(const TensorCollection &)=delete
void prepareForWrite() const final
Definition TensorCollection.cc:97
const std::string_view getDataTypeName() const final
fully qualified type name of stored POD elements - with namespace
Definition TensorCollection.h:193
const_reverse_iterator rbegin() const
Definition TensorCollection.h:268
size_t size_type
Definition TensorCollection.h:144
friend class TensorCollectionData
Definition TensorCollection.h:291
const_iterator begin() const
Definition TensorCollection.h:249
void setSubsetCollection(bool setSubset=true) final
Definition TensorCollection.cc:69
std::reverse_iterator< iterator > reverse_iterator
Definition TensorCollection.h:146
Tensor at(std::size_t index) const
Returns the const object of given index.
Definition TensorCollection.cc:39
reverse_iterator rbegin()
Definition TensorCollection.h:265
void print(std::ostream &os=std::cout, bool flush=true) const final
Print this collection to the passed stream.
Definition TensorCollection.cc:456
const_reverse_iterator crend() const
Definition TensorCollection.h:280
TensorCollectionIterator const_iterator
Definition TensorCollection.h:141
bool empty() const final
Is the collection empty.
Definition TensorCollection.cc:65
std::size_t max_size() const final
maximal number of elements in the collection
Definition TensorCollection.cc:55
TensorMutableCollectionIterator iterator
Definition TensorCollection.h:142
Definition TensorCollection.h:36
TensorCollectionIterator(const TensorCollectionIterator &)=default
pointer operator->()
Definition TensorCollection.cc:293
TensorCollectionIterator & operator-=(difference_type n)
Definition TensorCollection.cc:335
ptrdiff_t difference_type
Definition TensorCollection.h:39
TensorCollectionIterator & operator=(const TensorCollectionIterator &)=default
TensorCollectionIterator()=default
TensorCollectionIterator & operator+=(difference_type n)
Definition TensorCollection.cc:320
Tensor reference
Definition TensorCollection.h:40
reference operator[](difference_type n) const
Definition TensorCollection.cc:346
TensorCollectionIterator(size_t index, const TensorObjPointerContainer *collection)
Definition TensorCollection.h:47
auto operator<=>(const TensorCollectionIterator &other) const
Definition TensorCollection.h:56
std::random_access_iterator_tag iterator_concept
Definition TensorCollection.h:45
TensorCollectionIterator operator+(difference_type n) const
Definition TensorCollection.cc:325
Tensor value_type
Definition TensorCollection.h:38
std::input_iterator_tag iterator_category
Definition TensorCollection.h:42
TensorCollectionIterator & operator++()
Definition TensorCollection.cc:298
reference operator*() const
Definition TensorCollection.cc:289
TensorCollectionIterator operator-(difference_type n) const
Definition TensorCollection.cc:340
TensorCollectionIterator & operator--()
Definition TensorCollection.cc:309
~TensorCollectionIterator()=default
Tensor * pointer
Definition TensorCollection.h:41
bool operator==(const TensorCollectionIterator &x) const
Definition TensorCollection.h:60
TensorCollectionIterator(TensorCollectionIterator &&)=default
TensorCollectionIterator & operator=(TensorCollectionIterator &&)=default
Definition TensorCollection.h:85
TensorMutableCollectionIterator & operator++()
Definition TensorCollection.cc:365
std::input_iterator_tag iterator_category
Definition TensorCollection.h:91
MutableTensor reference
Definition TensorCollection.h:89
TensorMutableCollectionIterator(size_t index, const TensorObjPointerContainer *collection)
Definition TensorCollection.h:96
reference operator*() const
Definition TensorCollection.cc:356
TensorMutableCollectionIterator(const TensorMutableCollectionIterator &)=default
TensorMutableCollectionIterator & operator=(TensorMutableCollectionIterator &&)=default
MutableTensor * pointer
Definition TensorCollection.h:90
auto operator<=>(const TensorMutableCollectionIterator &other) const
Definition TensorCollection.h:105
~TensorMutableCollectionIterator()=default
TensorMutableCollectionIterator & operator-=(difference_type n)
Definition TensorCollection.cc:402
Tensor value_type
Definition TensorCollection.h:87
reference operator[](difference_type n) const
Definition TensorCollection.cc:413
TensorMutableCollectionIterator()=default
TensorMutableCollectionIterator & operator+=(difference_type n)
Definition TensorCollection.cc:387
TensorMutableCollectionIterator(TensorMutableCollectionIterator &&)=default
ptrdiff_t difference_type
Definition TensorCollection.h:88
TensorMutableCollectionIterator operator+(difference_type n) const
Definition TensorCollection.cc:392
std::random_access_iterator_tag iterator_concept
Definition TensorCollection.h:94
TensorMutableCollectionIterator & operator=(const TensorMutableCollectionIterator &)=default
pointer operator->()
Definition TensorCollection.cc:360
bool operator==(const TensorMutableCollectionIterator &x) const
Definition TensorCollection.h:109
TensorMutableCollectionIterator operator-(difference_type n) const
Definition TensorCollection.cc:407
TensorMutableCollectionIterator & operator--()
Definition TensorCollection.cc:376
Definition TensorObj.h:19
std::vector< std::int64_t > * m_shape
Definition TensorObj.h:35
Definition CalorimeterHit.cc:17
std::deque< TensorObj * > TensorObjPointerContainer
Definition TensorCollectionData.h:22
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
Definition CalorimeterHit.h:31