Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:35:19

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(std::int32_t elementType);
0060 
0061   /// copy constructor
0062   Tensor(const Tensor& other) = default;
0063 
0064   /// copy-assignment operator
0065   Tensor& operator=(Tensor other);
0066 
0067   /// create a mutable deep-copy of the object with identical relations
0068   /// if cloneRelations=false, the relations are not cloned and will be empty
0069   MutableTensor clone(bool cloneRelations=true) const;
0070 
0071   /// destructor
0072   ~Tensor() = default;
0073 
0074   /// converting constructor from mutable object
0075   Tensor(const MutableTensor& other);
0076 
0077   static Tensor makeEmpty();
0078 
0079 public:
0080 
0081   static constexpr auto typeName = "edm4eic::Tensor";
0082 
0083   /// Access the Data type in the same encoding as "ONNXTensorElementDataType", 1 - float, 7 - int64
0084   std::int32_t getElementType() const;
0085 
0086 
0087 
0088   std::size_t shape_size() const;
0089   std::int64_t getShape(std::size_t) const;
0090   std::vector<std::int64_t>::const_iterator shape_begin() const;
0091   std::vector<std::int64_t>::const_iterator shape_end() const;
0092   podio::RelationRange<std::int64_t> getShape() const;
0093   std::size_t floatData_size() const;
0094   float getFloatData(std::size_t) const;
0095   std::vector<float>::const_iterator floatData_begin() const;
0096   std::vector<float>::const_iterator floatData_end() const;
0097   podio::RelationRange<float> getFloatData() const;
0098   std::size_t int64Data_size() const;
0099   std::int64_t getInt64Data(std::size_t) const;
0100   std::vector<std::int64_t>::const_iterator int64Data_begin() const;
0101   std::vector<std::int64_t>::const_iterator int64Data_end() const;
0102   podio::RelationRange<std::int64_t> getInt64Data() const;
0103 
0104 
0105   /// check whether the object is actually available
0106   bool isAvailable() const;
0107   /// disconnect from TensorObj instance
0108   void unlink() { m_obj = podio::utils::MaybeSharedPtr<TensorObj>{nullptr}; }
0109 
0110   bool operator==(const Tensor& other) const { return m_obj == other.m_obj; }
0111   bool operator==(const MutableTensor& other) const;
0112 
0113   bool operator!=(const Tensor& other) const { return !(*this == other); }
0114   bool operator!=(const MutableTensor& other) const { return !(*this == other); }
0115 
0116   // less comparison operator, so that objects can be e.g. stored in sets.
0117   bool operator<(const Tensor& other) const { return podio::detail::getOrderKey(*this) < podio::detail::getOrderKey(other); }
0118 
0119   podio::ObjectID id() const { return getObjectID(); }
0120 
0121   const podio::ObjectID getObjectID() const;
0122 
0123   friend void swap(Tensor& a, Tensor& b) {
0124     using std::swap;
0125     swap(a.m_obj, b.m_obj); // swap out the internal pointers
0126   }
0127 
0128 private:
0129   /// constructor from existing TensorObj
0130   explicit Tensor(podio::utils::MaybeSharedPtr<TensorObj> obj);
0131   Tensor(TensorObj* obj);
0132 
0133   podio::utils::MaybeSharedPtr<TensorObj> m_obj{nullptr};
0134 };
0135 
0136 std::ostream& operator<<(std::ostream& o, const Tensor& value);
0137 
0138 #if defined(PODIO_JSON_OUTPUT) && !defined(__CLING__)
0139 void to_json(nlohmann::json& j, const Tensor& value);
0140 #endif
0141 
0142 
0143 } // namespace edm4eic
0144 
0145 
0146 #endif