ATLAS Offline Software
DbObjectHandle.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 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 handle to persistable objects
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"
23 #include "StorageSvc/DbHeap.h"
24 #include "StorageSvc/DbDatabase.h"
26 
27 namespace pool {
28 
29  class DbContainer;
30 
39  template <class USER> class DbObjectHandle : public DbHandleBase<USER> {
40  private:
43  const USER* makePtr(void* p) { return (const USER*)(p); }
44  protected:
46  template<typename T> void _set(const T* ptr, const DbType& typ) {
47  _setObject(ptr);
48  _setType(typ);
49  }
50  public:
51  using Base::ptr;
52  using Base::type;
53 
55  void _setType(const DbType& type) { Base::setType(type); }
57  template<class T> void _setObject(T* p) {
58  if ( 0 == ptr() && 0 == p ) return;
59  Base::m_ptr = p;
60  }
61  void _setObject(const int /* null_obj */ ) {
62  if ( 0 == ptr() ) return;
63  Base::m_ptr = 0;
64  }
65  public:
67  virtual ~DbObjectHandle() { _setObject(0); }
71  DbObjectHandle(const DbType& typ) { _setType(typ); }
74 
77  { _set(c.ptr(),c.type()); }
78 
80  operator const USER*() const { return ptr(); }
81  operator USER*() { return ptr(); }
82 
84  DbObjectHandle<USER>& operator=(const int /* nuller */)
85  { _setObject(0); return *this; }
86 
88  if (&c != this) _set (c.ptr(), c.type());
89  return *this;
90  }
91 
94  if( ptr() != obj ) _setObject(obj);
95  return *this;
96  }
97 
99  template <typename T> bool operator==(const DbHandleBase<T>& objH) const
100  { return type() == objH.type() && ptr() == objH.ptr(); }
101 
103  const DbContainer& containedIn() const
104  { return DbHeap::container(ptr()); }
105 
107  const Token::OID_t& oid() const
108  { return DbHeap::oid(ptr()); }
109 
112  { return DbHeap::oid(ptr()); }
113 
116  if( pToken ) {
118  return dbH.makeLink(pToken, linkH);
119  }
120  return Error;
121  }
122  };
123 
124 
125  template <class USER> using DbHandle = DbObjectHandle< USER>;
126 
127 } // End namespace pool
128 
129 #endif // POOL_DBOBJECT_H
pool::DbObjectHandle::containedIn
const DbContainer & containedIn() const
Retrieve hosting container.
Definition: DbObjectHandle.h:103
pool::DbStatus
Definition: DbStatus.h:67
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:309
pool::DbObjectHandle::operator=
DbObjectHandle< USER > & operator=(const int)
Generic assignment operator.
Definition: DbObjectHandle.h:84
pool::DbObjectHandle::operator=
DbObjectHandle< USER > & operator=(USER *obj)
Generic assignment operator.
Definition: DbObjectHandle.h:93
pool
pool namespace
Definition: libname.h:15
pool::DbObjectHandle
Definition: DbContainer.h:37
DbType.h
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
pool::DbObjectHandle::ATLAS_NOT_THREAD_SAFE
DbStatus makeLink ATLAS_NOT_THREAD_SAFE(Token *pToken, Token::OID_t &linkH) const
Add persistent association entry.
Definition: DbObjectHandle.h:115
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle()
Standard Constructor.
Definition: DbObjectHandle.h:69
DbDatabase.h
Token
This class provides a token that identifies in a unique way objects on the persistent storage.
Definition: Token.h:21
pool::DbHandleBase::m_ptr
T * m_ptr
Data member: Object pointer. Sub-classes need access on re-assignment.
Definition: DbHandleBase.h:38
pool::DbObjectHandle::operator==
bool operator==(const DbHandleBase< T > &objH) const
Equality operator.
Definition: DbObjectHandle.h:99
Token::OID_t
Definition: Token.h:24
pool::DbObjectHandle::makePtr
const USER * makePtr(void *p)
Pointer conversion.
Definition: DbObjectHandle.h:43
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
pool::DbHandleBase::ptr
const T * ptr() const
Access to underlying object.
Definition: DbHandleBase.h:65
pool::DbType
Definition: DbType.h:31
pool::DbObjectHandle::oid
Token::OID_t & oid()
Access object oid.
Definition: DbObjectHandle.h:111
pool::DbObjectHandle::_setType
void _setType(const DbType &type)
Set handle type.
Definition: DbObjectHandle.h:55
pool::DbObjectHandle::_setObject
void _setObject(const int)
Definition: DbObjectHandle.h:61
pool::DbContainer::containedIn
DbDatabase & containedIn()
Access to the Database the container resides in.
pool::DbObjectHandle::_setObject
void _setObject(T *p)
Set object value.
Definition: DbObjectHandle.h:57
pool::DbObjectHandle::operator=
DbObjectHandle< USER > & operator=(DbObjectHandle &c)
Definition: DbObjectHandle.h:87
pool::DbHandleBase::setType
void setType(const DbType &typ)
Set handle type.
Definition: DbHandleBase.h:54
pool.h
pool::DbObjectHandle::~DbObjectHandle
virtual ~DbObjectHandle()
Standard destructor.
Definition: DbObjectHandle.h:67
pool::DbHeap::oid
static Token::OID_t & oid(DbObject *pObj)
Access the offset of an object.
pool::DbDatabase::makeLink
DbStatus makeLink(Token *pToken, Token::OID_t &linkH)
Add association link to link container.
pool::DbHeap::container
static DbContainer & container(DbObject *pObj)
Access the container of an object.
pool::DbObjectHandle::oid
const Token::OID_t & oid() const
Access object oid.
Definition: DbObjectHandle.h:107
pool::DbHandleBase::type
const DbType & type() const
Inquire storage type of the handle.
Definition: DbHandleBase.h:70
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(USER *p)
Constructor with object pointer.
Definition: DbObjectHandle.h:73
pool::DbContainer
Definition: DbContainer.h:51
DbHandleBase.h
pool::DbHandleBase
Definition: DbHandleBase.h:31
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(const DbType &typ)
Constructor with storage type.
Definition: DbObjectHandle.h:71
pool::DbObjectHandle::DbObjectHandle
DbObjectHandle(const DbObjectHandle< USER > &c)
Copy constructor.
Definition: DbObjectHandle.h:76
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: DbObjectHandle.h:46
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
pool::DbDatabase
Definition: DbDatabase.h:53
Token.h
This file contains the class definition for the Token class (migrated from POOL).
python.compressB64.c
def c
Definition: compressB64.py:93
DbHeap.h