The Gaudi Framework  master (37c0b60a)
SmartDataObjectPtr.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 // ====================================================================
12 // SmartDataObjectPtr.cpp
13 // --------------------------------------------------------------------
14 //
15 // Package :
16 //
17 // Author : Markus Frank
18 //
19 // ====================================================================
20 #define GAUDIKERNEL_SMARTDATAOBJECTPTR_CPP 1
21 
22 // Framework include files
23 #include <GaudiKernel/DataObject.h>
26 
28 
30 
32 StatusCode SmartDataObjectPtr::retrieve( IRegistry* pRegistry, std::string_view path, DataObject*& refpObject ) {
33  return ( m_dataProvider && pRegistry ) ? m_dataProvider->retrieveObject( pRegistry, path, refpObject )
35 }
36 
38 StatusCode SmartDataObjectPtr::retrieve( std::string_view fullPath, DataObject*& refpObject ) {
39  return m_dataProvider ? m_dataProvider->retrieveObject( fullPath, refpObject ) : StatusCode::FAILURE;
40 }
41 
43 StatusCode SmartDataObjectPtr::find( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject ) {
44  return ( m_dataProvider && pDirectory ) ? m_dataProvider->findObject( pDirectory, path, refpObject )
46  ;
47 }
48 
50 StatusCode SmartDataObjectPtr::find( std::string_view fullPath, DataObject*& refpObject ) {
51  return m_dataProvider ? m_dataProvider->findObject( fullPath, refpObject ) : StatusCode::FAILURE;
52 }
53 
56  return ( m_dataProvider && pRegistry ) ? m_dataProvider->updateObject( pRegistry ) : StatusCode::FAILURE;
57 }
58 
60 StatusCode SmartDataObjectPtr::update( std::string_view fullPath ) {
62 }
63 
70  DataObject* pObj = nullptr;
71  m_status = ( !m_pRegistry ? retrieve( m_path, pObj ) : retrieve( m_pRegistry, m_path, pObj ) );
72  if ( m_status.isSuccess() ) {
73  m_pRegistry = pObj->registry();
74  m_path.clear();
75  }
76  return pObj;
77 }
78 
85  DataObject* pObj = nullptr;
86  m_status = ( m_pRegistry ? find( m_pRegistry, m_path, pObj ) : find( m_path, pObj ) );
87  if ( m_status.isSuccess() ) {
88  m_pRegistry = pObj->registry();
89  m_path.clear();
90  }
91  return pObj;
92 }
93 
100  DataObject* pObj = accessData(); // Have to load AND update if not present.
101  if ( m_status.isSuccess() ) {
103  if ( !m_status.isSuccess() ) pObj = nullptr;
104  }
105  return pObj;
106 }
107 
120 bool operator&&( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
121  return object_1.accessData() && object_2.accessData();
122 }
123 
140 bool operator||( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
141  return object_1.accessData() || object_2.accessData();
142 }
SmartDataObjectPtr::ObjectLoader::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:27
SmartDataObjectPtr::retrieve
static DataObject * retrieve(SmartDataObjectPtr *ptr)
Static Object retrieval method.
Definition: SmartDataObjectPtr.h:99
SmartDataObjectPtr::m_dataProvider
IDataProviderSvc * m_dataProvider
Pointer to contained object.
Definition: SmartDataObjectPtr.h:170
SmartDataObjectPtr::m_status
StatusCode m_status
Keep track of the last error.
Definition: SmartDataObjectPtr.h:174
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
SmartDataObjectPtr::findObject
DataObject * findObject()
Object find method.
Definition: SmartDataObjectPtr.cpp:84
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:140
SmartDataObjectPtr::AccessFunction
DataObject *(*)(SmartDataObjectPtr *ptr) AccessFunction
Definition: SmartDataObjectPtr.h:44
IRegistry
Definition: IRegistry.h:32
IDataProviderSvc.h
std::string::clear
T clear(T... args)
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:102
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:120
SmartDataObjectPtr::m_pRegistry
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
Definition: SmartDataObjectPtr.h:172
SmartDataObjectPtr.h
StatusCode
Definition: StatusCode.h:65
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
SmartDataObjectPtr::updateObject
DataObject * updateObject()
Object update method.
Definition: SmartDataObjectPtr.cpp:99
SmartDataObjectPtr
Definition: SmartDataObjectPtr.h:42
SmartDataObjectPtr::retrieveObject
DataObject * retrieveObject()
Object retrieve method.
Definition: SmartDataObjectPtr.cpp:69
SmartDataObjectPtr::update
static DataObject * update(SmartDataObjectPtr *ptr)
Static Object update method.
Definition: SmartDataObjectPtr.h:105
DataObject.h
DataObject
Definition: DataObject.h:36
SmartDataObjectPtr::ObjectFinder::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:29
SmartDataObjectPtr::m_path
std::string m_path
Path to object.
Definition: SmartDataObjectPtr.h:176
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:81
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:78
IDataProviderSvc::updateObject
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:96