Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 09:10:46

0001 // AUTOMATICALLY GENERATED FILE - DO NOT EDIT
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 // forward declarations
0023 namespace edm4eic {
0024 class TensorCollection;
0025 }
0026 
0027 
0028 namespace podio::detail {
0029 // Internal function used in less comparison operators of the datatypes and interface types
0030 OrderKey getOrderKey(const edm4eic::Tensor& obj);
0031 };
0032 
0033 namespace edm4eic {
0034 
0035 class MutableTensor;
0036 class TensorCollection;
0037 class TensorCollectionData;
0038 
0039 /** @class Tensor
0040  *  Tensor type for use in training in inference of ML models
0041  *  @author: D. Kalinkin
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   /// default constructor
0056   Tensor();
0057 
0058   /// Constructor initializing all members
0059   Tensor(const std::int32_t elementType);
0060 
0061   /// copy constructor
0062   Tensor(const Tensor& other) = default;
0063 
0064   /// copy-assignment operator
0065   Tensor& operator=(Tensor other) &; // Rebind this to other's internal object
0066   Tensor& operator=(Tensor other) && = delete; // Prevent rebinding temporary as the changes wouldn't persist
0067 
0068   /// create a mutable deep-copy of the object with identical relations
0069   /// if cloneRelations=false, the relations are not cloned and will be empty
0070   MutableTensor clone(bool cloneRelations=true) const;
0071 
0072   /// destructor
0073   ~Tensor() = default;
0074 
0075   /// converting constructor from mutable object
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   /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
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   /// check whether the object is actually available
0107   bool isAvailable() const;
0108   /// disconnect from TensorObj instance
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   // less comparison operator, so that objects can be e.g. stored in sets.
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); // swap out the internal pointers
0129   }
0130 
0131 private:
0132   /// constructor from existing TensorObj
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 } // namespace edm4eic
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 // This is needed to avoid triggering opening every library in LD_LIBRARY_PATH
0159 // until it's fixed in ROOT. See https://github.com/root-project/root/issues/18489
0160 // and https://github.com/AIDASoft/podio/issues/770
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