Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
DataBucket.h
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 #ifndef ATHENAKERNEL_DATABUCKET_H
8 #define ATHENAKERNEL_DATABUCKET_H
9 
11 
12 //FIXME CLID is a tdef and can't be forward declared
13 #include "GaudiKernel/ClassID.h"
14 #include <memory>
15 #include <type_traits>
16 
24 namespace SG {
25  class IRegisterTransient;
26  class CopyConversionBase;
27 
28  template <class T>
29  class DataBucket : public DataBucketBase {
30 
31  public:
32 
33  // CONSTRUCTORS:
34 
35  DataBucket(): m_ptr(0) {} //needed by the generic converters
37  template <class U>
38  DataBucket(std::unique_ptr<U> data);
39 
40  // DESTRUCTOR:
41 
42  virtual ~DataBucket();
43 
44  // DATAOBJECT METHODS
45  virtual const CLID& clID() const override;
46  static const CLID& classID();
47 
48  // return the pointer as a void*
49  virtual void* object() override
50  {
51  typedef typename std::remove_const<T>::type T_nc;
52  return const_cast<T_nc*>(m_ptr);
53  }
54 
58  virtual const std::type_info& tinfo() const override
59  {
60  return typeid(T);
61  }
62 
63  // Serialize the object for reading
64  // StreamBuffer& serialize(StreamBuffer& s);
65  // Serialize the object for writing
66  // StreamBuffer& serialize(StreamBuffer& s) const;
67 
68 
69 
70  // AUTOMATIC CONVERSION OF TYPES
71  operator T*() { return ptr(); } //FIXME can we do without?
72  operator const T*() const { return cptr(); }
73 
82  virtual void* cast (CLID clid,
83  IRegisterTransient* irt = 0,
84  bool isConst = true) override;
85 
86 
95  virtual void* cast (const std::type_info& tinfo,
96  IRegisterTransient* irt = 0,
97  bool isConst = true) override;
98 
111  virtual void* cast (CLID clid,
112  const std::type_info& tinfo,
113  SG::IRegisterTransient* irt = 0,
114  bool isConst = true) override;
115 
116 
121  virtual void relinquish() override{ m_ptr=0;} //LEAKS m_ptr
122 
126  virtual void lock() override;
127 
128 
129  protected:
130  T* ptr() { return m_ptr; }
131  const T* cptr() const { return m_ptr; }
132 
133 
141  void* tryStaticConversion (CLID clid);
142 
143 
151  void* tryStaticConversion (const std::type_info& tinfo);
152 
153 
154 private:
155  T* m_ptr; //we own the thing now!
156 
158  typedef std::pair<const CopyConversionBase*, void*> ent_t;
159  typedef std::vector<ent_t> vec_t;
161 
164  };
165 } //end namespace SG
167 
168 #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:158
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:49
SG::DataBucket::DataBucket
DataBucket(const DataBucket &)
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataBucket::vec_t
std::vector< ent_t > vec_t
Definition: DataBucket.h:159
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:29
SG::DataBucket::relinquish
virtual void relinquish() override
Give up ownership of the DataBucket contents.
Definition: DataBucket.h:121
SG::DataBucket::cptr
const T * cptr() const
Definition: DataBucket.h:131
SG::DataBucket::tryStaticConversion
void * tryStaticConversion(const std::type_info &tinfo)
Try a conversion using static SG_BASES information.
DataBucket.icc
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
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:58
SG::DataBucket::DataBucket
DataBucket()
Definition: DataBucket.h:35
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()
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:160
SG::DataBucket::ptr
T * ptr()
Definition: DataBucket.h:130
SG::DataBucket::classID
static const CLID & classID()
SG::DataBucket::m_ptr
T * m_ptr
Definition: DataBucket.h:155
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.