File indexing completed on 2025-01-31 10:13:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef K4FWCORE_DATAWRAPPER_H
0020 #define K4FWCORE_DATAWRAPPER_H
0021
0022 #include <type_traits>
0023
0024
0025 #include "GaudiKernel/DataObject.h"
0026 #include "podio/CollectionBase.h"
0027
0028
0029 template <typename T> class DataHandle;
0030
0031 class GAUDI_API DataWrapperBase : public DataObject {
0032 public:
0033
0034
0035 virtual podio::CollectionBase* collectionBase() = 0;
0036 virtual ~DataWrapperBase(){};
0037 virtual void resetData() = 0;
0038 };
0039
0040 template <class T> class GAUDI_API DataWrapper : public DataWrapperBase {
0041 public:
0042 template <class T2> friend class DataHandle;
0043
0044 public:
0045 DataWrapper() : m_data(nullptr){};
0046 DataWrapper(T&& coll) {
0047 m_data = new T(std::move(coll));
0048 is_owner = true;
0049 }
0050 DataWrapper(std::unique_ptr<T> uptr) : m_data(uptr.get()) {
0051 uptr.release();
0052 is_owner = false;
0053 };
0054 virtual ~DataWrapper();
0055
0056 const T* getData() const { return m_data; }
0057 void setData(const T* data) { m_data = data; }
0058 virtual void resetData() { m_data = nullptr; }
0059
0060 operator const T&() const& { return *m_data; }
0061
0062 private:
0063
0064 virtual podio::CollectionBase* collectionBase();
0065
0066 private:
0067 const T* m_data;
0068 bool is_owner{true};
0069 };
0070
0071 template <class T> DataWrapper<T>::~DataWrapper() {
0072 if (is_owner && !m_data)
0073 delete m_data;
0074 }
0075
0076 template <class T> podio::CollectionBase* DataWrapper<T>::collectionBase() {
0077 if constexpr (std::is_base_of<podio::CollectionBase, T>::value) {
0078 return const_cast<T*>(m_data);
0079 }
0080 return nullptr;
0081 }
0082
0083 #endif