File indexing completed on 2025-01-18 09:55:32
0001
0002
0003 #ifndef EDM4EIC_Tensor_H
0004 #define EDM4EIC_Tensor_H
0005
0006 #include "edm4eic/TensorObj.h"
0007
0008 #include "podio/RelationRange.h"
0009 #include <cstdint>
0010 #include <vector>
0011
0012 #include "podio/utilities/MaybeSharedPtr.h"
0013
0014 #include <ostream>
0015 #include <cstdint>
0016
0017 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0018 #include "nlohmann/json_fwd.hpp"
0019 #endif
0020
0021
0022
0023 namespace edm4eic {
0024
0025 class MutableTensor;
0026 class TensorCollection;
0027 class TensorCollectionData;
0028
0029
0030
0031
0032
0033 class Tensor {
0034
0035 friend class MutableTensor;
0036 friend class TensorCollection;
0037 friend class edm4eic::TensorCollectionData;
0038 friend class TensorCollectionIterator;
0039
0040 public:
0041 using mutable_type = MutableTensor;
0042 using collection_type = TensorCollection;
0043
0044
0045 Tensor();
0046
0047
0048 Tensor(std::int32_t elementType);
0049
0050
0051 Tensor(const Tensor& other) = default;
0052
0053
0054 Tensor& operator=(Tensor other);
0055
0056
0057
0058 MutableTensor clone(bool cloneRelations=true) const;
0059
0060
0061 ~Tensor() = default;
0062
0063
0064 Tensor(const MutableTensor& other);
0065
0066 static Tensor makeEmpty();
0067
0068 public:
0069
0070
0071 std::int32_t getElementType() const;
0072
0073
0074
0075 std::size_t shape_size() const;
0076 std::int64_t getShape(std::size_t) const;
0077 std::vector<std::int64_t>::const_iterator shape_begin() const;
0078 std::vector<std::int64_t>::const_iterator shape_end() const;
0079 podio::RelationRange<std::int64_t> getShape() const;
0080 std::size_t floatData_size() const;
0081 float getFloatData(std::size_t) const;
0082 std::vector<float>::const_iterator floatData_begin() const;
0083 std::vector<float>::const_iterator floatData_end() const;
0084 podio::RelationRange<float> getFloatData() const;
0085 std::size_t int64Data_size() const;
0086 std::int64_t getInt64Data(std::size_t) const;
0087 std::vector<std::int64_t>::const_iterator int64Data_begin() const;
0088 std::vector<std::int64_t>::const_iterator int64Data_end() const;
0089 podio::RelationRange<std::int64_t> getInt64Data() const;
0090
0091
0092
0093 bool isAvailable() const;
0094
0095 void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
0096
0097 bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
0098 bool operator==(const MutableTensor& other) const;
0099
0100 bool operator!=(const Tensor& other) const { return !(*this == other); }
0101 bool operator!=(const MutableTensor& other) const { return !(*this == other); }
0102
0103
0104 bool operator<(const Tensor& other) const { return m_obj < other.m_obj; }
0105
0106 podio::ObjectID id() const { return getObjectID(); }
0107
0108 const podio::ObjectID getObjectID() const;
0109
0110 friend void swap(Tensor& a, Tensor& b) {
0111 using std::swap;
0112 swap(a.m_obj, b.m_obj);
0113 }
0114
0115 private:
0116
0117 explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
0118 Tensor(TensorObj* obj);
0119
0120 podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
0121 };
0122
0123 std::ostream& operator<<(std::ostream& o, const Tensor& value);
0124
0125 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0126 void to_json(nlohmann::json& j, const Tensor& value);
0127 #endif
0128
0129
0130 }
0131
0132
0133 #endif