File indexing completed on 2025-10-31 08:59:55
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 #include "podio/detail/OrderKey.h"
0014 
0015 #include <ostream>
0016 #include <cstdint>
0017 
0018 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0019 #include "nlohmann/json_fwd.hpp"
0020 #endif
0021 
0022 
0023 namespace edm4eic {
0024 class TensorCollection;
0025 }
0026 
0027 
0028 namespace podio::detail {
0029 
0030 OrderKey getOrderKey(const edm4eic::Tensor& obj);
0031 };
0032 
0033 namespace edm4eic {
0034 
0035 class MutableTensor;
0036 class TensorCollection;
0037 class TensorCollectionData;
0038 
0039 
0040 
0041 
0042 
0043 class Tensor {
0044 
0045   friend class MutableTensor;
0046   friend class TensorCollection;
0047   friend class edm4eic::TensorCollectionData;
0048   friend class TensorCollectionIterator;
0049   friend podio::detail::OrderKey podio::detail::getOrderKey(const Tensor & obj);
0050 
0051 public:
0052   using mutable_type = MutableTensor;
0053   using collection_type = TensorCollection;
0054 
0055   
0056   Tensor();
0057 
0058   
0059   Tensor(const std::int32_t elementType);
0060 
0061   
0062   Tensor(const Tensor& other) = default;
0063 
0064   
0065   Tensor& operator=(Tensor other) &; 
0066   Tensor& operator=(Tensor other) && = delete; 
0067 
0068   
0069   
0070   MutableTensor clone(bool cloneRelations=true) const;
0071 
0072   
0073   ~Tensor() = default;
0074 
0075   
0076   Tensor(const MutableTensor& other);
0077 
0078   static Tensor makeEmpty();
0079 
0080 public:
0081 
0082   static constexpr std::string_view typeName = "edm4eic::Tensor";
0083 
0084   
0085   std::int32_t getElementType() const;
0086 
0087 
0088 
0089   std::size_t shape_size() const;
0090   std::int64_t getShape(std::size_t) const;
0091   std::vector<std::int64_t>::const_iterator shape_begin() const;
0092   std::vector<std::int64_t>::const_iterator shape_end() const;
0093   podio::RelationRange<std::int64_t> getShape() const;
0094   std::size_t floatData_size() const;
0095   float getFloatData(std::size_t) const;
0096   std::vector<float>::const_iterator floatData_begin() const;
0097   std::vector<float>::const_iterator floatData_end() const;
0098   podio::RelationRange<float> getFloatData() const;
0099   std::size_t int64Data_size() const;
0100   std::int64_t getInt64Data(std::size_t) const;
0101   std::vector<std::int64_t>::const_iterator int64Data_begin() const;
0102   std::vector<std::int64_t>::const_iterator int64Data_end() const;
0103   podio::RelationRange<std::int64_t> getInt64Data() const;
0104 
0105 
0106   
0107   bool isAvailable() const;
0108   
0109   void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
0110 
0111   bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
0112   bool operator==(const MutableTensor& other) const;
0113 
0114   bool operator!=(const Tensor& other) const { return !(*this == other); }
0115   bool operator!=(const MutableTensor& other) const { return !(*this == other); }
0116 
0117   
0118   bool operator<(const Tensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
0119 
0120   podio::ObjectID id() const { return getObjectID(); }
0121 
0122   const podio::ObjectID getObjectID() const;
0123 
0124   friend std::hash<Tensor>;
0125 
0126   friend void swap(Tensor& a, Tensor& b) {
0127     using std::swap;
0128     swap(a.m_obj, b.m_obj); 
0129   }
0130 
0131 private:
0132   
0133   explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
0134   Tensor(TensorObj* obj);
0135 
0136   podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
0137 };
0138 
0139 std::ostream& operator<<(std::ostream& o, const Tensor& value);
0140 
0141 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0142 void to_json(nlohmann::json& j, const Tensor& value);
0143 #endif
0144 
0145 
0146 } 
0147 
0148 
0149 
0150 template<>
0151 struct std::hash<edm4eic::Tensor> {
0152   std::size_t operator()(const edm4eic::Tensor& obj) const {
0153     return std::hash<edm4eic::TensorObj*>{}(obj.m_obj.get());
0154   }
0155 };
0156 
0157 
0158 
0159 
0160 
0161 #if defined(__clang__)
0162 #pragma clang diagnostic push
0163 #pragma clang diagnostic ignored "-Wunknown-warning-option"
0164 #pragma clang diagnostic ignored "-Wdeprecated-redundant-constexpr-static-def"
0165 #pragma clang diagnostic ignored "-Wdeprecated"
0166 constexpr std::string_view edm4eic::Tensor::typeName;
0167 #pragma clang diagnostic pop
0168 #elif defined(__GNUC__)
0169 #pragma GCC diagnostic push
0170 #pragma GCC diagnostic ignored "-Wdeprecated"
0171 constexpr std::string_view edm4eic::Tensor::typeName;
0172 #pragma GCC diagnostic pop
0173 #endif
0174 
0175 #endif