The Gaudi Framework  v31r0 (aeb156f0)
SmartDataObjectPtr Class Reference

A small class used to access easily (and efficiently) data items residing in data stores. More...

#include <GaudiKernel/SmartDataObjectPtr.h>

Inheritance diagram for SmartDataObjectPtr:
Collaboration diagram for SmartDataObjectPtr:

Classes

class  ObjectFinder
 Helper class to configure smart pointer functionality. More...
 
class  ObjectLoader
 Helper class to configure smart pointer functionality. More...
 

Public Types

using AccessFunction = DataObject *(*)(SmartDataObjectPtr *ptr)
 

Public Member Functions

 SmartDataObjectPtr (AccessFunction access, IDataProviderSvc *pService, IRegistry *pDir, std::string path)
 Standard constructor: Construct an SmartDataObjectPtr instance. More...
 
 SmartDataObjectPtr (const SmartDataObjectPtr &)=default
 Copy constructor: Construct an copy of a SmartDataStorePtr instance. More...
 
virtual ~SmartDataObjectPtr ()=default
 Standard Destructor. More...
 
virtual SmartDataObjectPtroperator= (const SmartDataObjectPtr &)
 Assignment operator. More...
 
 operator IRegistry * ()
 Automatic conversion to data directory. More...
 
const std::stringpath () const
 Path name. More...
 
IRegistrydirectory ()
 Access to data directory. More...
 
void setService (IDataProviderSvc *svc)
 Assign data service. More...
 
IDataProviderSvcservice ()
 Retrieve data service. More...
 
const StatusCodegetLastError () const
 Access to potential errors during data accesses. More...
 
DataObjectaccessData ()
 Static Object retrieval method: must call specific function. More...
 
DataObjectretrieveObject ()
 Object retrieve method. More...
 
DataObjectfindObject ()
 Object find method. More...
 
DataObjectupdateObject ()
 Object update method. More...
 

Static Public Member Functions

static DataObjectretrieve (SmartDataObjectPtr *ptr)
 Static Object retrieval method. More...
 
static DataObjectfind (SmartDataObjectPtr *ptr)
 Static Object find method. More...
 
static DataObjectupdate (SmartDataObjectPtr *ptr)
 Static Object update method. More...
 

Protected Member Functions

StatusCode find (IRegistry *pDirectory, const std::string &path, DataObject *&refpObject)
 Find the specified object from the data store. More...
 
StatusCode find (const std::string &fullPath, DataObject *&refpObject)
 Find the specified object from the data store. More...
 
StatusCode retrieve (IRegistry *pDirectory, const std::string &path, DataObject *&refpObject)
 Retrieve the specified object from the data store. More...
 
StatusCode retrieve (const std::string &fullPath, DataObject *&refpObject)
 Retrieve the specified object from the data store. More...
 
StatusCode update (IRegistry *pDirectory)
 Update the specified object from the data store. More...
 
StatusCode update (const std::string &fullPath)
 Update the specified object from the data store. More...
 

Protected Attributes

IDataProviderSvcm_dataProvider = nullptr
 Pointer to contained object. More...
 
IRegistrym_pRegistry = nullptr
 Pointer to the data registry containing the object. More...
 
StatusCode m_status = {StatusCode::SUCCESS, true}
 Keep track of the last error. More...
 
std::string m_path
 Path to object. More...
 
AccessFunction m_accessFunc
 Data access function. More...
 

Detailed Description

A small class used to access easily (and efficiently) data items residing in data stores.

The class is meant as configurable base class for real Smart pointer instances. Here mainly the access of the data store is handled. It is important to keep as less functions as possible NON-VIRTUAL in particular those, which handle the data access - they might be called very often and hence the compiler must be able to inline them.

Author
M.Frank
Version
1.0

Definition at line 32 of file SmartDataObjectPtr.h.

Member Typedef Documentation

Constructor & Destructor Documentation

SmartDataObjectPtr::SmartDataObjectPtr ( AccessFunction  access,
IDataProviderSvc pService,
IRegistry pDir,
std::string  path 
)
inline

Standard constructor: Construct an SmartDataObjectPtr instance.

Parameters
svcPointer to the data service interface used to interact with the store.
pDirPointer to data directory
pathpath to object relative to data directory

Definition at line 54 of file SmartDataObjectPtr.h.

55  : m_dataProvider( pService ), m_pRegistry( pDir ), m_path( std::move( path ) ), m_accessFunc( access ) {}
std::string m_path
Path to object.
T move(T...args)
AccessFunction m_accessFunc
Data access function.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
SmartDataObjectPtr::SmartDataObjectPtr ( const SmartDataObjectPtr )
default

Copy constructor: Construct an copy of a SmartDataStorePtr instance.

Parameters
copyCopy of Smart Pointer to object.
virtual SmartDataObjectPtr::~SmartDataObjectPtr ( )
virtualdefault

Standard Destructor.

Member Function Documentation

DataObject* SmartDataObjectPtr::accessData ( )
inline

Static Object retrieval method: must call specific function.

Definition at line 86 of file SmartDataObjectPtr.h.

86 { return m_accessFunc( this ); }
AccessFunction m_accessFunc
Data access function.
IRegistry* SmartDataObjectPtr::directory ( )
inline

Access to data directory.

Definition at line 74 of file SmartDataObjectPtr.h.

74 { return m_pRegistry; }
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
static DataObject* SmartDataObjectPtr::find ( SmartDataObjectPtr ptr)
inlinestatic

Static Object find method.

Definition at line 92 of file SmartDataObjectPtr.h.

92 { return ptr->findObject(); }
DataObject * findObject()
Object find method.
StatusCode SmartDataObjectPtr::find ( IRegistry pDirectory,
const std::string path,
DataObject *&  refpObject 
)
protected

Find the specified object from the data store.

Retrieve the object from the data store.

Parameters
pDirectoryPointer to the directory entry holding the object.
refpObjectReference to the pointer finally holding the object
Returns
StatusCode indicating success or failure.

Definition at line 41 of file SmartDataObjectPtr.cpp.

41  {
42  return ( m_dataProvider && pDirectory ) ? m_dataProvider->findObject( pDirectory, path, refpObject )
44  ;
45 }
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode SmartDataObjectPtr::find ( const std::string fullPath,
DataObject *&  refpObject 
)
protected

Find the specified object from the data store.

Retrieve the object from the data store.

Parameters
fullPathString containing the full path necessary to locate the object.
refpObjectReference to the pointer finally holding the object
Returns
StatusCode indicating success or failure.

Definition at line 48 of file SmartDataObjectPtr.cpp.

48  {
49  return m_dataProvider ? m_dataProvider->findObject( fullPath, refpObject ) : StatusCode::FAILURE;
50 }
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
DataObject * SmartDataObjectPtr::findObject ( )

Object find method.

If the object is not known to the local object, it is requested from the data service either using the full path if there is no directory information present.

Definition at line 82 of file SmartDataObjectPtr.cpp.

82  {
83  DataObject* pObj = nullptr;
84  m_status = ( m_pRegistry ? find( m_pRegistry, m_path, pObj ) : find( m_path, pObj ) );
85  if ( m_status.isSuccess() ) {
86  m_pRegistry = pObj->registry();
87  m_path.clear();
88  }
89  return pObj;
90 }
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
bool isSuccess() const
Definition: StatusCode.h:267
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
std::string m_path
Path to object.
T clear(T...args)
StatusCode m_status
Keep track of the last error.
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
const StatusCode& SmartDataObjectPtr::getLastError ( ) const
inline

Access to potential errors during data accesses.

Definition at line 83 of file SmartDataObjectPtr.h.

83 { return m_status; }
StatusCode m_status
Keep track of the last error.
SmartDataObjectPtr::operator IRegistry * ( )
inline

Automatic conversion to data directory.

Definition at line 68 of file SmartDataObjectPtr.h.

68 { return m_pRegistry; }
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
SmartDataObjectPtr & SmartDataObjectPtr::operator= ( const SmartDataObjectPtr copy)
virtual

Assignment operator.

Reimplemented in SmartDataStorePtr< TYPE, LOADER >, and SmartDataStorePtr< TYPE, SmartDataObjectPtr::ObjectLoader >.

Definition at line 22 of file SmartDataObjectPtr.cpp.

22  {
23  m_path = copy.m_path;
24  m_pRegistry = copy.m_pRegistry;
26  return *this;
27 }
std::string m_path
Path to object.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
const std::string& SmartDataObjectPtr::path ( ) const
inline

Path name.

Definition at line 71 of file SmartDataObjectPtr.h.

71 { return m_path; }
std::string m_path
Path to object.
static DataObject* SmartDataObjectPtr::retrieve ( SmartDataObjectPtr ptr)
inlinestatic

Static Object retrieval method.

Definition at line 89 of file SmartDataObjectPtr.h.

89 { return ptr->retrieveObject(); }
DataObject * retrieveObject()
Object retrieve method.
StatusCode SmartDataObjectPtr::retrieve ( IRegistry pDirectory,
const std::string path,
DataObject *&  refpObject 
)
protected

Retrieve the specified object from the data store.

Retrieve the object from the data store.

Parameters
pDirectoryPointer to the directory entry holding the object.
refpObjectReference to the pointer finally holding the object
Returns
StatusCode indicating success or failure.

Definition at line 30 of file SmartDataObjectPtr.cpp.

30  {
31  return ( m_dataProvider && pRegistry ) ? m_dataProvider->retrieveObject( pRegistry, path, refpObject )
33 }
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode SmartDataObjectPtr::retrieve ( const std::string fullPath,
DataObject *&  refpObject 
)
protected

Retrieve the specified object from the data store.

Retrieve the object from the data store.

Parameters
fullPathString containing the full path necessary to locate the object.
refpObjectReference to the pointer finally holding the object
Returns
StatusCode indicating success or failure.

Definition at line 36 of file SmartDataObjectPtr.cpp.

36  {
37  return m_dataProvider ? m_dataProvider->retrieveObject( fullPath, refpObject ) : StatusCode::FAILURE;
38 }
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
DataObject * SmartDataObjectPtr::retrieveObject ( )

Object retrieve method.

Object retrieval method.

If the object is not known to the local object, it is requested from the data service either using the full path if there is no directory information present.

Definition at line 67 of file SmartDataObjectPtr.cpp.

67  {
68  DataObject* pObj = nullptr;
69  m_status = ( !m_pRegistry ? retrieve( m_path, pObj ) : retrieve( m_pRegistry, m_path, pObj ) );
70  if ( m_status.isSuccess() ) {
71  m_pRegistry = pObj->registry();
72  m_path.clear();
73  }
74  return pObj;
75 }
bool isSuccess() const
Definition: StatusCode.h:267
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
static DataObject * retrieve(SmartDataObjectPtr *ptr)
Static Object retrieval method.
std::string m_path
Path to object.
T clear(T...args)
StatusCode m_status
Keep track of the last error.
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
IDataProviderSvc* SmartDataObjectPtr::service ( )
inline

Retrieve data service.

Definition at line 80 of file SmartDataObjectPtr.h.

80 { return m_dataProvider; }
IDataProviderSvc * m_dataProvider
Pointer to contained object.
void SmartDataObjectPtr::setService ( IDataProviderSvc svc)
inline

Assign data service.

Definition at line 77 of file SmartDataObjectPtr.h.

77 { m_dataProvider = svc; }
IDataProviderSvc * m_dataProvider
Pointer to contained object.
static DataObject* SmartDataObjectPtr::update ( SmartDataObjectPtr ptr)
inlinestatic

Static Object update method.

Definition at line 95 of file SmartDataObjectPtr.h.

95 { return ptr->updateObject(); }
DataObject * updateObject()
Object update method.
StatusCode SmartDataObjectPtr::update ( IRegistry pDirectory)
protected

Update the specified object from the data store.

update the object from the data store.

Parameters
pDirectoryPointer to the directory entry holding the object.
Returns
StatusCode indicating success or failure.

Definition at line 53 of file SmartDataObjectPtr.cpp.

53  {
54  return ( m_dataProvider && pRegistry ) ? m_dataProvider->updateObject( pRegistry ) : StatusCode::FAILURE;
55 }
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
StatusCode SmartDataObjectPtr::update ( const std::string fullPath)
protected

Update the specified object from the data store.

update the object from the data store.

Parameters
fullPathString containing the full path necessary to locate the object.
Returns
StatusCode indicating success or failure.

Definition at line 58 of file SmartDataObjectPtr.cpp.

58  {
60 }
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
IDataProviderSvc * m_dataProvider
Pointer to contained object.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
DataObject * SmartDataObjectPtr::updateObject ( )

Object update method.

If the object is not known to the local object, it is requested from the data service either using the full path if there is no directory information present. Needs to be virtual to to implicit object access.

If the object is not known to the local object, it is requested from the data service either using the full path if there is no directory information present.

Definition at line 97 of file SmartDataObjectPtr.cpp.

97  {
98  DataObject* pObj = accessData(); // Have to load AND update if not present.
99  if ( m_status.isSuccess() ) {
100  m_status = ( !m_pRegistry ? update( m_path ) : update( m_pRegistry ) );
101  if ( !m_status.isSuccess() ) pObj = nullptr;
102  }
103  return pObj;
104 }
bool isSuccess() const
Definition: StatusCode.h:267
static DataObject * update(SmartDataObjectPtr *ptr)
Static Object update method.
std::string m_path
Path to object.
DataObject * accessData()
Static Object retrieval method: must call specific function.
StatusCode m_status
Keep track of the last error.
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30

Member Data Documentation

AccessFunction SmartDataObjectPtr::m_accessFunc
protected

Data access function.

Definition at line 168 of file SmartDataObjectPtr.h.

IDataProviderSvc* SmartDataObjectPtr::m_dataProvider = nullptr
mutableprotected

Pointer to contained object.

Definition at line 160 of file SmartDataObjectPtr.h.

std::string SmartDataObjectPtr::m_path
protected

Path to object.

Definition at line 166 of file SmartDataObjectPtr.h.

IRegistry* SmartDataObjectPtr::m_pRegistry = nullptr
mutableprotected

Pointer to the data registry containing the object.

Definition at line 162 of file SmartDataObjectPtr.h.

StatusCode SmartDataObjectPtr::m_status = {StatusCode::SUCCESS, true}
mutableprotected

Keep track of the last error.

Definition at line 164 of file SmartDataObjectPtr.h.


The documentation for this class was generated from the following files: