ATLAS Offline Software
DataBucket.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENAKERNEL_DATABUCKET_H
8 #define ATHENAKERNEL_DATABUCKET_H
9 
12 
13 //FIXME CLID is a tdef and can't be forward declared
14 #include "GaudiKernel/ClassID.h"
15 #include <memory>
16 #include <type_traits>
17 
25 namespace SG {
26  class IRegisterTransient;
27  class CopyConversionBase;
28 
29  template <class T>
30  class DataBucket : public DataBucketBase {
31 
32  public:
33 
34  // CONSTRUCTORS:
35 
36  DataBucket(): m_ptr(0) {} //needed by the generic converters
38  template <class U>
39  DataBucket(std::unique_ptr<U> data);
41 
42  // DESTRUCTOR:
43 
44  virtual ~DataBucket();
45 
46  // DATAOBJECT METHODS
47  virtual const CLID& clID() const override;
48  static const CLID& classID();
49 
50  // return the pointer as a void*
51  virtual void* object() override
52  {
53  typedef typename std::remove_const<T>::type T_nc;
54  return const_cast<T_nc*>(m_ptr);
55  }
56 
60  virtual const std::type_info& tinfo() const override
61  {
62  return typeid(T);
63  }
64 
65  // Serialize the object for reading
66  // StreamBuffer& serialize(StreamBuffer& s);
67  // Serialize the object for writing
68  // StreamBuffer& serialize(StreamBuffer& s) const;
69 
70 
71 
72  // AUTOMATIC CONVERSION OF TYPES
73  operator T*() { return ptr(); } //FIXME can we do without?
74  operator const T*() const { return cptr(); }
75 
84  virtual void* cast (CLID clid,
85  IRegisterTransient* irt = 0,
86  bool isConst = true) override;
87 
88 
97  virtual void* cast (const std::type_info& tinfo,
98  IRegisterTransient* irt = 0,
99  bool isConst = true) override;
100 
113  virtual void* cast (CLID clid,
114  const std::type_info& tinfo,
115  SG::IRegisterTransient* irt = 0,
116  bool isConst = true) override;
117 
118 
123  virtual void relinquish() override{ m_ptr=0;} //LEAKS m_ptr
124 
128  virtual void lock() override;
129 
130 
131  protected:
132  T* ptr() { return m_ptr; }
133  const T* cptr() const { return m_ptr; }
134 
135 
143  void* tryStaticConversion (CLID clid);
144 
145 
153  void* tryStaticConversion (const std::type_info& tinfo);
154 
155 
156 private:
157  T* m_ptr; //we own the thing now!
158 
160  typedef std::pair<const CopyConversionBase*, void*> ent_t;
161  typedef std::vector<ent_t> vec_t;
163 
166  };
167 } //end namespace SG
169 
170 #endif // ATHENAKERNEL_DATABUCKET_H
SG::IRegisterTransient
Interface for registering a transient object in t2p map.
Definition: IRegisterTransient.h:28
SG::DataBucket::ent_t
std::pair< const CopyConversionBase *, void * > ent_t
Objects made by copy conversion.
Definition: DataBucket.h:160
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
SG::DataBucket::operator=
DataBucket & operator=(const DataBucket &)
SG::DataBucket::cast
virtual void * cast(CLID clid, const std::type_info &tinfo, SG::IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
SG::DataBucket::object
virtual void * object() override
Definition: DataBucket.h:51
SG::DataBucket::DataBucket
DataBucket(const DataBucket &)
SG::DataBucket::DataBucket
DataBucket(SG::DataObjectSharedPtr< T > data)
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataBucket::vec_t
std::vector< ent_t > vec_t
Definition: DataBucket.h:161
SG::DataBucket::cast
virtual void * cast(CLID clid, IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
DataBucketBase
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
Definition: DataBucketBase.h:24
DataBucketBase.h
SG::DataBucket
Definition: DataBucket.h:30
SG::DataBucket::relinquish
virtual void relinquish() override
Give up ownership of the DataBucket contents.
Definition: DataBucket.h:123
SG::DataBucket::cptr
const T * cptr() const
Definition: DataBucket.h:133
SG::DataBucket::tryStaticConversion
void * tryStaticConversion(const std::type_info &tinfo)
Try a conversion using static SG_BASES information.
DataBucket.icc
SG::DataBucket::DataBucket
DataBucket(T *data)
SG::DataBucket::tinfo
virtual const std::type_info & tinfo() const override
Return the type_info for the stored object.
Definition: DataBucket.h:60
SG::DataBucket::DataBucket
DataBucket()
Definition: DataBucket.h:36
SG::DataBucket::tryStaticConversion
void * tryStaticConversion(CLID clid)
Try a conversion using static SG_BASES information.
SG::DataBucket::DataBucket
DataBucket(std::unique_ptr< U > data)
SG::DataBucket::~DataBucket
virtual ~DataBucket()
DataObjectSharedPtr.h
Smart pointer to manage DataObject reference counts.
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::DataBucket::clID
virtual const CLID & clID() const override
SG::DataBucket::m_cnvcopies
vec_t m_cnvcopies
Definition: DataBucket.h:162
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SG::DataObjectSharedPtr
Smart pointer to manage DataObject reference counts.
Definition: DataObjectSharedPtr.h:46
SG::DataBucket::ptr
T * ptr()
Definition: DataBucket.h:132
SG::DataBucket::classID
static const CLID & classID()
SG::DataBucket::m_ptr
T * m_ptr
Definition: DataBucket.h:157
SG::DataBucket::cast
virtual void * cast(const std::type_info &tinfo, IRegisterTransient *irt=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by std::type_info.
SG::DataBucket::lock
virtual void lock() override
If the held object derives from ILockable, call lock() on it.