Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 10:00:35

0001 /***********************************************************************************\
0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
0003 *                                                                                   *
0004 * This software is distributed under the terms of the Apache version 2 licence,     *
0005 * copied verbatim in the file "LICENSE".                                            *
0006 *                                                                                   *
0007 * In applying this licence, CERN does not waive the privileges and immunities       *
0008 * granted to it by virtue of its status as an Intergovernmental Organization        *
0009 * or submit itself to any jurisdiction.                                             *
0010 \***********************************************************************************/
0011 #ifndef GAUDIKERNEL_SMARTDATAOBJECTPTR_H
0012 #define GAUDIKERNEL_SMARTDATAOBJECTPTR_H 1
0013 
0014 // STL include files
0015 #include <string>
0016 
0017 // Framework include files
0018 #include "GaudiKernel/Kernel.h"
0019 #include "GaudiKernel/StatusCode.h"
0020 
0021 // Forward declarations
0022 class SmartDataObjectPtr;
0023 class IDataProviderSvc;
0024 class IRegistry;
0025 class DataObject;
0026 
0027 /** @class SmartDataObjectPtr SmartDataObjectPtr.h GaudiKernel/SmartDataObjectPtr.h
0028 
0029     A small class used to access easily (and efficiently) data items
0030     residing in data stores.
0031 
0032       The class is meant as configurable base class for real
0033     Smart pointer instances. Here mainly the access of the data store
0034     is handled.
0035       It is important to keep as less functions as possible NON-VIRTUAL
0036     in particular those, which handle the data access - they might be called
0037     very often and hence the compiler must be able to inline them.
0038 
0039     @author  M.Frank
0040     @version 1.0
0041 */
0042 class GAUDI_API SmartDataObjectPtr {
0043 public:
0044   using AccessFunction = DataObject* (*)( SmartDataObjectPtr* ptr );
0045   /// Helper class to configure smart pointer functionality
0046   class ObjectLoader {
0047   public:
0048     static AccessFunction access();
0049   };
0050 
0051   /// Helper class to configure smart pointer functionality
0052   class ObjectFinder {
0053   public:
0054     static AccessFunction access();
0055   };
0056 
0057 public:
0058   /** Standard constructor: Construct an SmartDataObjectPtr instance.
0059       @param  svc          Pointer to the data service
0060                            interface used to interact with the store.
0061       @param  pDir         Pointer to data directory
0062       @param  path         path to object relative to data directory
0063   */
0064   SmartDataObjectPtr( AccessFunction access, IDataProviderSvc* pService, IRegistry* pDir, std::string path )
0065       : m_dataProvider( pService ), m_pRegistry( pDir ), m_path( std::move( path ) ), m_accessFunc( access ) {}
0066   /** Copy constructor: Construct an copy of a SmartDataStorePtr instance.
0067       @param  copy          Copy of Smart Pointer to object.
0068   */
0069   SmartDataObjectPtr( const SmartDataObjectPtr& ) = default;
0070 
0071   /// Standard Destructor
0072   virtual ~SmartDataObjectPtr() = default;
0073 
0074   /// Assignment operator
0075   virtual SmartDataObjectPtr& operator=( const SmartDataObjectPtr& );
0076 
0077   /// Automatic conversion to data directory
0078   operator IRegistry*() { return m_pRegistry; }
0079 
0080   /// Path name
0081   const std::string& path() const { return m_path; }
0082 
0083   /// Access to data directory
0084   IRegistry* directory() { return m_pRegistry; }
0085 
0086   /// Assign data service
0087   void setService( IDataProviderSvc* svc ) { m_dataProvider = svc; }
0088 
0089   /// Retrieve data service
0090   IDataProviderSvc* service() { return m_dataProvider; }
0091 
0092   /// Access to potential errors during data accesses
0093   const StatusCode& getLastError() const { return m_status; }
0094 
0095   /// Static Object retrieval method: must call specific function
0096   DataObject* accessData() { return m_accessFunc( this ); }
0097 
0098   /// Static Object retrieval method.
0099   static DataObject* retrieve( SmartDataObjectPtr* ptr ) { return ptr->retrieveObject(); }
0100 
0101   /// Static Object find method.
0102   static DataObject* find( SmartDataObjectPtr* ptr ) { return ptr->findObject(); }
0103 
0104   /// Static Object update method.
0105   static DataObject* update( SmartDataObjectPtr* ptr ) { return ptr->updateObject(); }
0106 
0107   /** Object retrieve method.
0108      If the object is not known to the local object, it is requested
0109      from the data service either using the full path if there is no
0110      directory information present.
0111   */
0112   DataObject* retrieveObject();
0113 
0114   /** Object find method.
0115      If the object is not known to the local object, it is requested
0116      from the data service either using the full path if there is no
0117      directory information present.
0118   */
0119   DataObject* findObject();
0120 
0121   /** Object update method.
0122       If the object is not known to the local object, it is requested
0123       from the data service either using the full path if there is no
0124       directory information present.
0125       Needs to be virtual to to implicit object access.
0126   */
0127   DataObject* updateObject();
0128 
0129 protected:
0130   /** Find the specified object from the data store.
0131       @param  pDirectory   Pointer to the directory entry holding the object.
0132       @param  refpObject   Reference to the pointer finally holding the object
0133       @return              StatusCode indicating success or failure.
0134   */
0135   StatusCode find( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject );
0136 
0137   /** Find the specified object from the data store.
0138       @param  fullPath     String containing the full path necessary to locate the object.
0139       @param  refpObject   Reference to the pointer finally holding the object
0140       @return              StatusCode indicating success or failure.
0141   */
0142   StatusCode find( std::string_view fullPath, DataObject*& refpObject );
0143 
0144   /** Retrieve the specified object from the data store.
0145       @param  pDirectory   Pointer to the directory entry holding the object.
0146       @param  refpObject   Reference to the pointer finally holding the object
0147       @return              StatusCode indicating success or failure.
0148   */
0149   StatusCode retrieve( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject );
0150   /** Retrieve the specified object from the data store.
0151       @param  fullPath     String containing the full path necessary to locate the object.
0152       @param  refpObject   Reference to the pointer finally holding the object
0153       @return              StatusCode indicating success or failure.
0154   */
0155   StatusCode retrieve( std::string_view fullPath, DataObject*& refpObject );
0156 
0157   /** Update the specified object from the data store.
0158       @param  pDirectory   Pointer to the directory entry holding the object.
0159       @return              StatusCode indicating success or failure.
0160   */
0161   StatusCode update( IRegistry* pDirectory );
0162   /** Update the specified object from the data store.
0163       @param  fullPath     String containing the full path necessary to locate the object.
0164       @return              StatusCode indicating success or failure.
0165   */
0166   StatusCode update( std::string_view fullPath );
0167 
0168 protected:
0169   /// Pointer to contained object
0170   mutable IDataProviderSvc* m_dataProvider = nullptr;
0171   /// Pointer to the data registry containing the object
0172   mutable IRegistry* m_pRegistry = nullptr;
0173   /// Keep track of the last error
0174   mutable StatusCode m_status = StatusCode::SUCCESS;
0175   /// Path to object
0176   std::string m_path;
0177   /// Data access function
0178   AccessFunction m_accessFunc;
0179 };
0180 #endif // GAUDIKERNEL_SMARTDATAOBJECTPTR_H