| The Gaudi Framework v32r1 (f65d50dc)

SmartDataObjectPtr.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // SmartDataObjectPtr.cpp
3 // --------------------------------------------------------------------
4 //
5 // Package :
6 //
7 // Author : Markus Frank
8 //
9 // ====================================================================
10 #define GAUDIKERNEL_SMARTDATAOBJECTPTR_CPP 1
11
12 // Framework include files
13 #include "GaudiKernel/SmartDataObjectPtr.h"
14 #include "GaudiKernel/DataObject.h"
15 #include "GaudiKernel/IDataProviderSvc.h"
16
17 SmartDataObjectPtr::AccessFunction SmartDataObjectPtr::ObjectLoader::access() { return &SmartDataObjectPtr::retrieve; }
18
19 SmartDataObjectPtr::AccessFunction SmartDataObjectPtr::ObjectFinder::access() { return &SmartDataObjectPtr::find; }
20
22 SmartDataObjectPtr& SmartDataObjectPtr::operator=( const SmartDataObjectPtr& copy ) {
23 m_path = copy.m_path;
24 m_pRegistry = copy.m_pRegistry;
25 m_dataProvider = copy.m_dataProvider;
26 return *this;
27 }
28
30 StatusCode SmartDataObjectPtr::retrieve( IRegistry* pRegistry, const std::string& path, DataObject*& refpObject ) {
31 return ( m_dataProvider && pRegistry ) ? m_dataProvider->retrieveObject( pRegistry, path, refpObject )
32 : StatusCode::FAILURE;
33 }
34
36 StatusCode SmartDataObjectPtr::retrieve( const std::string& fullPath, DataObject*& refpObject ) {
37 return m_dataProvider ? m_dataProvider->retrieveObject( fullPath, refpObject ) : StatusCode::FAILURE;
38 }
39
41 StatusCode SmartDataObjectPtr::find( IRegistry* pDirectory, const std::string& path, DataObject*& refpObject ) {
42 return ( m_dataProvider && pDirectory ) ? m_dataProvider->findObject( pDirectory, path, refpObject )
43 : StatusCode::FAILURE;
44 ;
45 }
46
48 StatusCode SmartDataObjectPtr::find( const std::string& fullPath, DataObject*& refpObject ) {
49 return m_dataProvider ? m_dataProvider->findObject( fullPath, refpObject ) : StatusCode::FAILURE;
50 }
51
53 StatusCode SmartDataObjectPtr::update( IRegistry* pRegistry ) {
54 return ( m_dataProvider && pRegistry ) ? m_dataProvider->updateObject( pRegistry ) : StatusCode::FAILURE;
55 }
56
58 StatusCode SmartDataObjectPtr::update( const std::string& fullPath ) {
59 return ( m_dataProvider ) ? m_dataProvider->updateObject( fullPath ) : StatusCode::FAILURE;
60 }
61
67 DataObject* SmartDataObjectPtr::retrieveObject() {
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 }
76
82 DataObject* SmartDataObjectPtr::findObject() {
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 }
91
97 DataObject* SmartDataObjectPtr::updateObject() {
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 }
105
118 bool operator&&( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
119 return object_1.accessData() && object_2.accessData();
120 }
121
138 bool operator||( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
139 return object_1.accessData() || object_2.accessData();
140 }
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:92
operator||
bool operator||(SmartDataObjectPtr &object_1, SmartDataObjectPtr &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartEvtDataPtr<...
Definition: SmartDataObjectPtr.cpp:138
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
operator &&
bool operator &&(SmartDataObjectPtr &object_1, SmartDataObjectPtr &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartEvtDataPtr<...
Definition: SmartDataObjectPtr.cpp:118
SmartDataObjectPtr::retrieveObject
DataObject * retrieveObject()
Object retrieve method.
Definition: SmartDataObjectPtr.cpp:67
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.
SmartDataObjectPtr::update
static DataObject * update(SmartDataObjectPtr *ptr)
Static Object update method.
Definition: SmartDataObjectPtr.h:95
SmartDataObjectPtr::retrieve
static DataObject * retrieve(SmartDataObjectPtr *ptr)
Static Object retrieval method.
Definition: SmartDataObjectPtr.h:89
std::string
STL class.
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:71
IDataProviderSvc.h
SmartDataObjectPtr::ObjectFinder::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:19
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IDataProviderSvc::updateObject
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
SmartDataObjectPtr::m_path
std::string m_path
Path to object.
Definition: SmartDataObjectPtr.h:166
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:86
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
std::string::clear
T clear(T... args)
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
SmartDataObjectPtr::operator=
virtual SmartDataObjectPtr & operator=(const SmartDataObjectPtr &)
Assignment operator.
Definition: SmartDataObjectPtr.cpp:22
SmartDataObjectPtr::m_status
StatusCode m_status
Keep track of the last error.
Definition: SmartDataObjectPtr.h:164
SmartDataObjectPtr
A small class used to access easily (and efficiently) data items residing in data stores.
Definition: SmartDataObjectPtr.h:32
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
SmartDataObjectPtr::findObject
DataObject * findObject()
Object find method.
Definition: SmartDataObjectPtr.cpp:82
SmartDataObjectPtr::m_dataProvider
IDataProviderSvc * m_dataProvider
Pointer to contained object.
Definition: SmartDataObjectPtr.h:160
SmartDataObjectPtr::ObjectLoader::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:17
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
SmartDataObjectPtr::AccessFunction
DataObject *(*)(SmartDataObjectPtr *ptr) AccessFunction
Definition: SmartDataObjectPtr.h:34
SmartDataObjectPtr::m_pRegistry
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
Definition: SmartDataObjectPtr.h:162
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
SmartDataObjectPtr::updateObject
DataObject * updateObject()
Object update method.
Definition: SmartDataObjectPtr.cpp:97
DataObject.h
SmartDataObjectPtr.h