EDM4eic
EIC data model
Loading...
Searching...
No Matches
Tensor.h
Go to the documentation of this file.
1// AUTOMATICALLY GENERATED FILE - DO NOT EDIT
2
3#ifndef EDM4EIC_Tensor_H
4#define EDM4EIC_Tensor_H
5
6#include "edm4eic/TensorObj.h"
7
8#include "podio/RelationRange.h"
9#include <cstdint>
10#include <vector>
11
12#include "podio/utilities/MaybeSharedPtr.h"
13#include "podio/detail/OrderKey.h"
14
15#include <ostream>
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 {
25}
26
27
28namespace podio::detail {
29// Internal function used in less comparison operators of the datatypes and interface types
30OrderKey getOrderKey(const edm4eic::Tensor& obj);
31};
32
33namespace edm4eic {
34
35class MutableTensor;
38
39/** @class Tensor
40 * Tensor type for use in training in inference of ML models
41 * @author: D. Kalinkin
42 */
43class Tensor {
44
45 friend class MutableTensor;
46 friend class TensorCollection;
49 friend podio::detail::OrderKey podio::detail::getOrderKey(const Tensor & obj);
50
51public:
54
55 /// default constructor
56 Tensor();
57
58 /// Constructor initializing all members
59 Tensor(const std::int32_t elementType);
60
61 /// copy constructor
62 Tensor(const Tensor& other) = default;
63
64 /// copy-assignment operator
65 Tensor& operator=(Tensor other) &; // Rebind this to other's internal object
66 Tensor& operator=(Tensor other) && = delete; // Prevent rebinding temporary as the changes wouldn't persist
67
68 /// create a mutable deep-copy of the object with identical relations
69 /// if cloneRelations=false, the relations are not cloned and will be empty
70 MutableTensor clone(bool cloneRelations=true) const;
71
72 /// destructor
73 ~Tensor() = default;
74
75 /// converting constructor from mutable object
76 Tensor(const MutableTensor& other);
77
78 static Tensor makeEmpty();
79
80public:
81
82 static constexpr std::string_view typeName = "edm4eic::Tensor";
83
84 /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
85 std::int32_t getElementType() const;
86
87
88
89 std::size_t shape_size() const;
90 std::int64_t getShape(std::size_t) const;
91 std::vector<std::int64_t>::const_iterator shape_begin() const;
92 std::vector<std::int64_t>::const_iterator shape_end() const;
93 podio::RelationRange<std::int64_t> getShape() const;
94 std::size_t floatData_size() const;
95 float getFloatData(std::size_t) const;
96 std::vector<float>::const_iterator floatData_begin() const;
97 std::vector<float>::const_iterator floatData_end() const;
98 podio::RelationRange<float> getFloatData() const;
99 std::size_t int64Data_size() const;
100 std::int64_t getInt64Data(std::size_t) const;
101 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
102 std::vector<std::int64_t>::const_iterator int64Data_end() const;
103 podio::RelationRange<std::int64_t> getInt64Data() const;
104
105
106 /// check whether the object is actually available
107 bool isAvailable() const;
108 /// disconnect from TensorObj instance
109 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
110
111 bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
112 bool operator==(const MutableTensor& other) const;
113
114 bool operator!=(const Tensor& other) const { return !(*this == other); }
115 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
116
117 // less comparison operator, so that objects can be e.g. stored in sets.
118 bool operator<(const Tensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
119
120 podio::ObjectID id() const { return getObjectID(); }
121
122 const podio::ObjectID getObjectID() const;
123
124 friend std::hash<Tensor>;
125
126 friend void swap(Tensor& a, Tensor& b) {
127 using std::swap;
128 swap(a.m_obj, b.m_obj); // swap out the internal pointers
129 }
130
131private:
132 /// constructor from existing TensorObj
133 explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
134 Tensor(TensorObj* obj);
135
136 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
137};
138
139std::ostream& operator<<(std::ostream& o, const Tensor& value);
140
141#if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
142void to_json(nlohmann::json& j, const Tensor& value);
143#endif
144
145
146} // namespace edm4eic
147
148
149
150template<>
151struct std::hash<edm4eic::Tensor> {
152 std::size_t operator()(const edm4eic::Tensor& obj) const {
153 return std::hash<edm4eic::TensorObj*>{}(obj.m_obj.get());
154 }
155};
156
157
158// This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
159// until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
160// and https://github.com/AIDASoft/podio/issues/770
161#if defined(__clang__)
162#pragma clang diagnostic push
163#pragma clang diagnostic ignored "-Wunknown-warning-option"
164#pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
165#pragma clang diagnostic ignored "-Wdeprecated"
166constexpr std::string_view edm4eic::Tensor::typeName;
167#pragma clang diagnostic pop
168#elif defined(__GNUC__)
169#pragma GCC diagnostic push
170#pragma GCC diagnostic ignored "-Wdeprecated"
171constexpr std::string_view edm4eic::Tensor::typeName;
172#pragma GCC diagnostic pop
173#endif
174
175#endif
Definition MutableTensor.h:35
Definition TensorCollectionData.h:30
Definition TensorCollection.h:137
Definition Tensor.h:43
std::vector< std::int64_t >::const_iterator int64Data_begin() const
Definition Tensor.cc:153
MutableTensor clone(bool cloneRelations=true) const
Definition Tensor.cc:33
bool isAvailable() const
check whether the object is actually available
Definition Tensor.cc:188
std::vector< float >::const_iterator floatData_begin() const
Definition Tensor.cc:121
podio::RelationRange< std::int64_t > getInt64Data() const
Definition Tensor.cc:176
static constexpr std::string_view typeName
Definition Tensor.h:82
MutableTensor mutable_type
Definition Tensor.h:52
std::vector< std::int64_t >::const_iterator int64Data_end() const
Definition Tensor.cc:159
std::int32_t getElementType() const
Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float,...
Definition Tensor.cc:85
std::size_t floatData_size() const
Definition Tensor.cc:133
Tensor & operator=(Tensor other) &&=delete
podio::RelationRange< float > getFloatData() const
Definition Tensor.cc:144
TensorCollection collection_type
Definition Tensor.h:53
std::vector< std::int64_t >::const_iterator shape_end() const
Definition Tensor.cc:95
podio::ObjectID id() const
Definition Tensor.h:120
bool operator<(const Tensor &other) const
Definition Tensor.h:118
friend class TensorCollectionIterator
Definition Tensor.h:48
friend class TensorCollection
Definition Tensor.h:46
friend void swap(Tensor &a, Tensor &b)
Definition Tensor.h:126
std::vector< float >::const_iterator floatData_end() const
Definition Tensor.cc:127
std::size_t shape_size() const
Definition Tensor.cc:101
Tensor & operator=(Tensor other) &
copy-assignment operator
Definition Tensor.cc:28
Tensor()
default constructor
Definition Tensor.cc:20
bool operator==(const Tensor &other) const
Definition Tensor.h:111
const podio::ObjectID getObjectID() const
Definition Tensor.cc:192
friend class MutableTensor
Definition Tensor.h:45
void unlink()
disconnect from TensorObj instance
Definition Tensor.h:109
podio::RelationRange< std::int64_t > getShape() const
Definition Tensor.cc:112
std::size_t int64Data_size() const
Definition Tensor.cc:165
bool operator!=(const MutableTensor &other) const
Definition Tensor.h:115
Tensor(const Tensor &other)=default
copy constructor
bool operator!=(const Tensor &other) const
Definition Tensor.h:114
static Tensor makeEmpty()
Definition Tensor.cc:81
~Tensor()=default
destructor
std::vector< std::int64_t >::const_iterator shape_begin() const
Definition Tensor.cc:89
Definition TensorObj.h:19
Definition CalorimeterHit.cc:17
std::ostream & operator<<(std::ostream &o, const CalorimeterHit &value)
Definition CalorimeterHit.cc:103
Definition CalorimeterHit.h:31
OrderKey getOrderKey(const edm4eic::CalorimeterHit &obj)
Definition CalorimeterHit.cc:150
std::size_t operator()(const edm4eic::Tensor &obj) const
Definition Tensor.h:152