ATLAS Offline Software
DbObject.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //====================================================================
6 // DbObject definition
7 //--------------------------------------------------------------------
8 //
9 // Package : (The POOL project)
10 //
11 // Description: Generic persistable object
12 //
13 // @author M.Frank
14 //====================================================================
15 #ifndef POOL_DBOBJECT_H
16 #define POOL_DBOBJECT_H 1
17 
18 // Framework include files
20 #include "StorageSvc/pool.h"
21 #include "StorageSvc/DbType.h"
24 
25 /*
26  * POOL namespace declaration
27  */
28 namespace pool {
29  // forward declarations
30  class DbObjectAccessor;
31  class DbTypeInfo;
32  class DbContainer;
33  typedef const class Shape *ShapeH;
34 }
35 
36 #ifdef POOL_HAVE_BASE
37 
38 namespace pool {
39 
54  class DbObject {
55  protected:
57  virtual ~DbObject();
58  public:
60  void* operator new(size_t size);
62  void operator delete(void* ptr);
64  void* operator new(size_t siz, DbContainer& cntH);
66  void operator delete(void *ptr, DbContainer& cntH);
68  DbObject();
69  };
70 }
71 #else
72 
74 void* operator new(size_t siz, pool::DbContainer& cntH, const pool::DbTypeInfo* typ);
76 void* operator new(size_t siz, pool::DbContainer& cntH, const void *ptr, pool::ShapeH shape);
77 #endif
78 
79 
80 namespace pool {
81 
90  template <class USER> class DbObjectHandle : public DbHandleBase<USER> {
91  private:
94  const USER* makePtr(void* p) { return (const USER*)(p); }
95  protected:
97  template<typename T> void _set(const T* ptr, const DbType& typ) {
98  _setObject(ptr);
99  _setType(typ);
100  }
101  public:
103  void _setType(const DbType& type) { Base::setType(type); }
105  template<class T> void _setObject(T* p) {
106  if ( 0 == Base::ptr() && 0 == p ) return;
107  Base::m_ptr = p;
108  }
109  void _setObject(const int /* null_obj */ ) {
110  if ( 0 == Base::ptr() ) return;
111  Base::m_ptr = 0;
112  }
113  public:
115  virtual ~DbObjectHandle() { _setObject(0); }
119  DbObjectHandle(const DbType& typ) { _setType(typ); }
124  { _set(c.ptr(),c.type()); }
126  operator const USER*() const { return Base::ptr(); }
127  operator USER*() { return Base::ptr(); }
129  DbObjectHandle<USER>& operator=(const int /* nuller */)
130  { _setObject(0); return *this; }
132  {
133  if (&c != this)
134  _set (c.ptr(), c.type());
135  return *this;
136  }
138  template <typename T> bool operator==(const DbHandleBase<T>& objH) const
139  { return Base::type() == objH.type() && Base::ptr() == objH.ptr(); }
141  const DbContainer& containedIn() const;
143  const Token::OID_t& oid() const;
148  };
149 
150 
151  template <class USER> class DbHandle : public DbObjectHandle< USER> {
153  public:
155  virtual ~DbHandle() { }
157  DbHandle() { }
159  DbHandle(const DbType& typ) { Handle::_setType(typ); }
163  template <typename T> DbHandle(const DbObjectHandle<T>& c)
164  : DbObjectHandle<USER>()
165  { Handle::_set(c.ptr(),c.type()); }
168  { Handle::_set(c.ptr(),c.type()); }
171  if ( this != &c ) Handle::_set(c.ptr(),c.type());
172  return *this;
173  }
176  if ( Handle::ptr() != obj ) Handle::_setObject(obj);
177  return *this;
178  }
180  template <typename T>
182  if ( Handle::ptr() != c.ptr() ) Handle::_set(c.ptr(), c.type());
183  return *this;
184  }
185  };
186 
188 #ifndef POOL_HAVE_BASE
189  template <> class DbHandle<DbObject> {};
190 #endif
191 }
192 
193 /*
194  *
195  * Inline object handle implementation
196  *
197  */
199 
200 namespace pool {
201 #ifndef __no_inline
202 
204  template <class T> inline
206  { return DbObjectAccessor::containedIn(Base::ptr()); }
207 
209  template <class T> inline
211  { return DbObjectAccessor::objectOid(Base::ptr()); }
212 
214  template <class T> inline
216  { return DbObjectAccessor::objectOid(Base::ptr()); }
217 
219  template <class T> inline
221  { return DbObjectAccessor::makeObjectLink(Base::ptr(), pToken, linkH); }
222 
223 #endif
224 } // End namespace pool
225 #endif // POOL_DBOBJECT_H
pool::DbHandle::DbHandle
DbHandle()
Default constructor.
Definition: DbObject.h:157
pool::DbObject
void DbObject
Definition: Database/APR/StorageSvc/StorageSvc/pool.h:35
pool::DbStatus
Definition: DbStatus.h:67
pool::DbObjectHandle::oid
Token::OID_t & oid()
Access object oid.
Definition: DbObject.h:210
pool::DbHandle::Handle
DbObjectHandle< USER > Handle
Definition: DbObject.h:152
ViewHelper::makeLink
ElementLink< T > makeLink(const SG::View *view, const SG::ReadHandle< T > &handle, size_t index)
Create EL to a collection in view.
Definition: ViewHelper.h:297
pool::DbHandle::DbHandle
DbHandle(const DbObjectHandle< T > &c)
Copy constructor.
Definition: DbObject.h:163
pool::DbObjectHandle::operator=
DbObjectHandle< USER > & operator=(const int)
Generic assignment operator.
Definition: DbObject.h:129
pool::DbHandle::DbHandle
DbHandle(const DbType &typ)
Constructor with storage type.
Definition: DbObject.h:159
pool
pool namespace
Definition: libname.h:15
pool::DbObjectHandle< USER >
DbType.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
pool::DbHandle
Definition: DbObject.h:151
pool::DbHandle::operator=
DbHandle< USER > & operator=(DbObjectHandle< T > &c)
Generic assignment operator.
Definition: DbObject.h:181
pool::DbObjectHandle::operator=
DbObjectHandle< USER > & operator=(const DbObjectHandle &c)
Definition: DbObject.h:131
pool::DbHandleBase::type
const DbType & type() const
Inquire storage type of the handle.
Definition: DbHandleBase.h:66
pool::DbHandle::DbHandle
DbHandle(USER *obj)
Constructor with object assignment.
Definition: DbObject.h:161
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle()
Standard Constructor.
Definition: DbObject.h:117
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
pool::DbObjectHandle::operator==
bool operator==(const DbHandleBase< T > &objH) const
Equality operator.
Definition: DbObject.h:138
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Token::OID_t
Definition: Token.h:24
pool::DbObjectHandle::makePtr
const USER * makePtr(void *p)
Pointer conversion.
Definition: DbObject.h:94
pool::ShapeH
const class Shape * ShapeH
Definition: DbContainerObj.h:27
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
pool::DbHandle::DbHandle
DbHandle(const DbHandle< USER > &c)
Copy constructor.
Definition: DbObject.h:167
pool::DbType
Definition: DbType.h:31
pool::DbObjectHandle::_setType
void _setType(const DbType &type)
Set handle type.
Definition: DbObject.h:103
pool::DbHandleBase::ptr
const T * ptr() const
Access to underlying object.
Definition: DbHandleBase.h:61
pool::DbObjectHandle::_setObject
void _setObject(const int)
Definition: DbObject.h:109
pool::DbObjectHandle::ATLAS_NOT_THREAD_SAFE
DbStatus makeLink ATLAS_NOT_THREAD_SAFE(const Token *pToken, Token::OID_t &linkH) const
Add persistent association entry.
pool::DbObjectHandle::_setObject
void _setObject(T *p)
Set object value.
Definition: DbObject.h:105
DbObjectAccessor.h
pool::DbHandle::operator=
DbHandle< USER > & operator=(DbHandle< USER > &c)
Generic assignment operator.
Definition: DbObject.h:170
pool.h
pool::DbObjectHandle::containedIn
const DbContainer & containedIn() const
Retrieve hosting container.
Definition: DbObject.h:205
pool::DbObjectHandle::~DbObjectHandle
virtual ~DbObjectHandle()
Standard destructor.
Definition: DbObject.h:115
pool::DbHandleBase::setType
void setType(const DbType &typ)
Set handle type.
Definition: DbHandleBase.h:50
pool::DbObjectHandle::oid
const Token::OID_t & oid() const
Access object oid.
Definition: DbObject.h:215
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(USER *p)
Constructor with object pointer.
Definition: DbObject.h:121
pool::DbContainer
Definition: DbContainer.h:51
pool::DbHandle::operator=
DbHandle< USER > & operator=(USER *obj)
Generic assignment operator.
Definition: DbObject.h:175
pool::DbHandleBase::m_ptr
T * m_ptr
Data member: Object pointer. Sub-classes need access on re-assignment.
Definition: DbHandleBase.h:41
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
pool::ATLAS_NOT_THREAD_SAFE
DbStatus DbObjectHandle< T >::makeLink ATLAS_NOT_THREAD_SAFE(const Token *pToken, Token::OID_t &linkH) const
Add persistent association entry.
Definition: DbObject.h:220
DbHandleBase.h
pool::DbHandleBase
Definition: DbHandleBase.h:24
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(const DbType &typ)
Constructor with storage type.
Definition: DbObject.h:119
pool::DbHandle::~DbHandle
virtual ~DbHandle()
Standard destructor.
Definition: DbObject.h:155
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(const DbObjectHandle< USER > &c)
Copy constructor.
Definition: DbObject.h:123
pool::DbObjectHandle::_set
void _set(const T *ptr, const DbType &typ)
Attach object to handle with type: may be accessed by sub-class only.
Definition: DbObject.h:97
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
Token.h
This file contains the class definition for the Token class (migrated from POOL).
python.compressB64.c
def c
Definition: compressB64.py:93
pool::DbObjectHandle::Base
DbHandleBase< USER > Base
Definition: DbObject.h:92
pool::DbTypeInfo
Definition: DbTypeInfo.h:47