The Gaudi Framework  master (37c0b60a)
SmartDataObjectPtr.h
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 #ifndef GAUDIKERNEL_SMARTDATAOBJECTPTR_H
12 #define GAUDIKERNEL_SMARTDATAOBJECTPTR_H 1
13 
14 // STL include files
15 #include <string>
16 
17 // Framework include files
18 #include <GaudiKernel/Kernel.h>
19 #include <GaudiKernel/StatusCode.h>
20 
21 // Forward declarations
22 class SmartDataObjectPtr;
23 class IDataProviderSvc;
24 class IRegistry;
25 class DataObject;
26 
43 public:
46  class ObjectLoader {
47  public:
48  static AccessFunction access();
49  };
50 
52  class ObjectFinder {
53  public:
54  static AccessFunction access();
55  };
56 
57 public:
65  : m_dataProvider( pService ), m_pRegistry( pDir ), m_path( std::move( path ) ), m_accessFunc( access ) {}
70 
72  virtual ~SmartDataObjectPtr() = default;
73 
75  virtual SmartDataObjectPtr& operator=( const SmartDataObjectPtr& ) = default;
76 
78  operator IRegistry*() { return m_pRegistry; }
79 
81  const std::string& path() const { return m_path; }
82 
84  IRegistry* directory() { return m_pRegistry; }
85 
87  void setService( IDataProviderSvc* svc ) { m_dataProvider = svc; }
88 
90  IDataProviderSvc* service() { return m_dataProvider; }
91 
93  const StatusCode& getLastError() const { return m_status; }
94 
96  DataObject* accessData() { return m_accessFunc( this ); }
97 
99  static DataObject* retrieve( SmartDataObjectPtr* ptr ) { return ptr->retrieveObject(); }
100 
102  static DataObject* find( SmartDataObjectPtr* ptr ) { return ptr->findObject(); }
103 
105  static DataObject* update( SmartDataObjectPtr* ptr ) { return ptr->updateObject(); }
106 
112  DataObject* retrieveObject();
113 
119  DataObject* findObject();
120 
127  DataObject* updateObject();
128 
129 protected:
135  StatusCode find( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject );
136 
142  StatusCode find( std::string_view fullPath, DataObject*& refpObject );
143 
149  StatusCode retrieve( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject );
155  StatusCode retrieve( std::string_view fullPath, DataObject*& refpObject );
156 
161  StatusCode update( IRegistry* pDirectory );
166  StatusCode update( std::string_view fullPath );
167 
168 protected:
170  mutable IDataProviderSvc* m_dataProvider = nullptr;
172  mutable IRegistry* m_pRegistry = nullptr;
174  mutable StatusCode m_status = StatusCode::SUCCESS;
178  AccessFunction m_accessFunc = nullptr;
179 };
180 #endif // GAUDIKERNEL_SMARTDATAOBJECTPTR_H
SmartDataObjectPtr::retrieve
static DataObject * retrieve(SmartDataObjectPtr *ptr)
Static Object retrieval method.
Definition: SmartDataObjectPtr.h:99
std::string
STL class.
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
SmartDataObjectPtr::findObject
DataObject * findObject()
Object find method.
Definition: SmartDataObjectPtr.cpp:84
SmartDataObjectPtr::AccessFunction
DataObject *(*)(SmartDataObjectPtr *ptr) AccessFunction
Definition: SmartDataObjectPtr.h:44
IRegistry
Definition: IRegistry.h:32
StatusCode.h
SmartDataObjectPtr::directory
IRegistry * directory()
Access to data directory.
Definition: SmartDataObjectPtr.h:84
SmartDataObjectPtr::operator=
virtual SmartDataObjectPtr & operator=(const SmartDataObjectPtr &)=default
Assignment operator.
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:102
StatusCode
Definition: StatusCode.h:65
SmartDataObjectPtr::ObjectFinder
Helper class to configure smart pointer functionality.
Definition: SmartDataObjectPtr.h:52
SmartDataObjectPtr::updateObject
DataObject * updateObject()
Object update method.
Definition: SmartDataObjectPtr.cpp:99
SmartDataObjectPtr
Definition: SmartDataObjectPtr.h:42
SmartDataObjectPtr::SmartDataObjectPtr
SmartDataObjectPtr(const SmartDataObjectPtr &)=default
Copy constructor: Construct an copy of a SmartDataStorePtr instance.
SmartDataObjectPtr::ObjectLoader
Helper class to configure smart pointer functionality.
Definition: SmartDataObjectPtr.h:46
SmartDataObjectPtr::setService
void setService(IDataProviderSvc *svc)
Assign data service.
Definition: SmartDataObjectPtr.h:87
SmartDataObjectPtr::retrieveObject
DataObject * retrieveObject()
Object retrieve method.
Definition: SmartDataObjectPtr.cpp:69
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
SmartDataObjectPtr::update
static DataObject * update(SmartDataObjectPtr *ptr)
Static Object update method.
Definition: SmartDataObjectPtr.h:105
GaudiPython.Pythonizations.update
update
Definition: Pythonizations.py:145
std
STL namespace.
Kernel.h
DataObject
Definition: DataObject.h:36
SmartDataObjectPtr::~SmartDataObjectPtr
virtual ~SmartDataObjectPtr()=default
Standard Destructor.
IDataProviderSvc
Definition: IDataProviderSvc.h:53
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
SmartDataObjectPtr::SmartDataObjectPtr
SmartDataObjectPtr(AccessFunction access, IDataProviderSvc *pService, IRegistry *pDir, std::string path)
Standard constructor: Construct an SmartDataObjectPtr instance.
Definition: SmartDataObjectPtr.h:64
SmartDataObjectPtr::service
IDataProviderSvc * service()
Retrieve data service.
Definition: SmartDataObjectPtr.h:90
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
SmartDataObjectPtr::getLastError
const StatusCode & getLastError() const
Access to potential errors during data accesses.
Definition: SmartDataObjectPtr.h:93
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:96