EDM4eic
EIC data model
Loading...
Searching...
No Matches
MutableTensor.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_MutableTensor_H
4#define EDM4EIC_MutableTensor_H
5
6#include "edm4eic/TensorObj.h"
7// Make the immutable class available from its mutable version but not vice versa
8#include "edm4eic/Tensor.h"
9
10#include "podio/RelationRange.h"
11#include <cstdint>
12#include <vector>
13
14#include "podio/utilities/MaybeSharedPtr.h"
15
16#include <cstdint>
17
18#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
19#include "nlohmann/json_fwd.hpp"
20#endif
21
22// forward declarations
23namespace edm4eic {
24class TensorCollection;
25}
26
27
28namespace edm4eic {
29
30
31/** @class MutableTensor
32 * Tensor type for use in training in inference of ML models
33 * @author: D. Kalinkin
34 */
36
37 friend class TensorCollection;
39 friend class Tensor;
40
41public:
44
45 /// default constructor
47
48 /// Constructor initializing all members
49 MutableTensor(std::int32_t elementType);
50
51 /// copy constructor
52 MutableTensor(const MutableTensor& other) = default;
53
54 /// copy-assignment operator
56
57 /// create a mutable deep-copy of the object with identical relations
58 /// if cloneRelations=false, the relations are not cloned and will be empty
59 MutableTensor clone(bool cloneRelations=true) const;
60
61 /// destructor
62 ~MutableTensor() = default;
63
64
65public:
66
67 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
68 std::int32_t getElementType() const;
69
70
71
72 /// Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
73 void setElementType(std::int32_t value);
74 /// Get mutable reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
75 std::int32_t& getElementType();
76 /// Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
77 [[deprecated("use getElementType instead")]]
78 std::int32_t& elementType();
79
80
81
82 void addToShape(const std::int64_t&);
83 std::size_t shape_size() const;
84 std::int64_t getShape(std::size_t) const;
85 std::vector<std::int64_t>::const_iterator shape_begin() const;
86 std::vector<std::int64_t>::const_iterator shape_end() const;
87 podio::RelationRange<std::int64_t> getShape() const;
88 void addToFloatData(const float&);
89 std::size_t floatData_size() const;
90 float getFloatData(std::size_t) const;
91 std::vector<float>::const_iterator floatData_begin() const;
92 std::vector<float>::const_iterator floatData_end() const;
93 podio::RelationRange<float> getFloatData() const;
94 void addToInt64Data(const std::int64_t&);
95 std::size_t int64Data_size() const;
96 std::int64_t getInt64Data(std::size_t) const;
97 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
98 std::vector<std::int64_t>::const_iterator int64Data_end() const;
99 podio::RelationRange<std::int64_t> getInt64Data() const;
100
101
102
103 /// check whether the object is actually available
104 bool isAvailable() const;
105 /// disconnect from TensorObj instance
106 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
107
108 bool operator==(const MutableTensor& other) const { return m_obj == other.m_obj; }
109 bool operator==(const Tensor& other) const;
110
111 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
112 bool operator!=(const Tensor& other) const { return !(*this == other); }
113
114 // less comparison operator, so that objects can be e.g. stored in sets.
115 bool operator<(const MutableTensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
116
117 podio::ObjectID id() const { return getObjectID(); }
118
119 const podio::ObjectID getObjectID() const;
120
121 friend void swap(MutableTensor& a, MutableTensor& b) {
122 using std::swap;
123 swap(a.m_obj, b.m_obj); // swap out the internal pointers
124 }
125
126private:
127 /// constructor from existing TensorObj
128 explicit MutableTensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
129
130 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
131};
132
133#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
134void to_json(nlohmann::json& j, const MutableTensor& value);
135#endif
136
137
138} // namespace edm4eic
139
140
141#endif
Definition MutableTensor.h:35
bool isAvailable() const
check whether the object is actually available
Definition MutableTensor.cc:171
friend class Tensor
Definition MutableTensor.h:39
MutableTensor(const MutableTensor &other)=default
copy constructor
bool operator<(const MutableTensor &other) const
Definition MutableTensor.h:115
std::vector< float >::const_iterator floatData_end() const
Definition MutableTensor.cc:105
bool operator!=(const MutableTensor &other) const
Definition MutableTensor.h:111
MutableTensor & operator=(MutableTensor other)
copy-assignment operator
Definition MutableTensor.cc:26
bool operator!=(const Tensor &other) const
Definition MutableTensor.h:112
MutableTensor clone(bool cloneRelations=true) const
Definition MutableTensor.cc:31
void addToInt64Data(const std::int64_t &)
Definition MutableTensor.cc:130
void addToFloatData(const float &)
Definition MutableTensor.cc:94
podio::ObjectID id() const
Definition MutableTensor.h:117
friend class TensorCollection
Definition MutableTensor.h:37
MutableTensor()
default constructor
Definition MutableTensor.cc:18
podio::RelationRange< std::int64_t > getInt64Data() const
Definition MutableTensor.cc:158
friend void swap(MutableTensor &a, MutableTensor &b)
Definition MutableTensor.h:121
podio::RelationRange< float > getFloatData() const
Definition MutableTensor.cc:122
std::size_t floatData_size() const
Definition MutableTensor.cc:111
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition MutableTensor.cc:50
~MutableTensor()=default
destructor
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition MutableTensor.cc:141
podio::RelationRange< std::int64_t > getShape() const
Definition MutableTensor.cc:86
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition MutableTensor.cc:135
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition MutableTensor.cc:63
bool operator==(const MutableTensor &other) const
Definition MutableTensor.h:108
std::size_t int64Data_size() const
Definition MutableTensor.cc:147
std::int32_t & elementType()
Get reference to Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition MutableTensor.cc:55
void setElementType(std::int32_t value)
Set the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64.
Definition MutableTensor.cc:53
std::vector< float >::const_iterator floatData_begin() const
Definition MutableTensor.cc:99
std::size_t shape_size() const
Definition MutableTensor.cc:75
void addToShape(const std::int64_t &)
Definition MutableTensor.cc:58
std::vector< std::int64_t >::const_iterator shape_end() const
Definition MutableTensor.cc:69
void unlink()
disconnect from TensorObj instance
Definition MutableTensor.h:106
const podio::ObjectID getObjectID() const
Definition MutableTensor.cc:175
Definition TensorCollection.h:91
Definition Tensor.h:43
Definition TensorCollection.h:62
Definition CalorimeterHit.cc:17
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:150