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 //  ====================================================================
0012 //  SmartDataLocator.h
0013 //  --------------------------------------------------------------------
0014 //
0015 //  Package    : GaudiKernel ( The LHCb Offline System)
0016 //
0017 //  Description: Implementation of a smart pointer class to access
0018 //               easily (and efficiently) data stores.
0019 //
0020 //  Author     : M.Frank
0021 //  ====================================================================
0022 #ifndef GAUDIKERNEL_SMARTDATALOCATOR_H
0023 #define GAUDIKERNEL_SMARTDATALOCATOR_H 1
0024 
0025 // Framework include files
0026 #include "GaudiKernel/SmartDataPtr.h"
0027 
0028 /** A small class used to access easily (and efficiently) data items
0029     residing in data stores.
0030 
0031       The class constructors take several arguments neccessary to be passed
0032     tyo the data services in order to automatically load objects in case
0033     they are not yet loaded. This is achieved through a smart pointer
0034     mechanism i.e. by overloading the operator->() at dereferencing time
0035     the the object will be requested from the store.
0036 
0037       The SmartDataLocator is meant to be "short living". It only makes
0038     sense to keep an object instance within e.g. the scope of one method.
0039     "long living" instances do not make sense and in the contrary
0040     would be harmful, because the information passed during construction
0041     to would be invalid and returned object pointers would actually
0042     point to hyperspace.
0043 
0044     The intrinsic functionality, wether the object will be retrieved or
0045     loaded from the data store is defined by the LOADER::.
0046 
0047 
0048     Base Class:
0049     SmartDataStorePtr
0050 
0051     @author  M.Frank
0052     @version 1.0
0053 */
0054 
0055 template <class TYPE>
0056 class SmartDataLocator : public SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader> {
0057 public:
0058   /** Standard constructor: Construct an SmartDataLocator instance which is
0059                             able to connect to a DataObject instance
0060                             which is identified by its parent object and
0061                             the path relative to the parent.
0062       @param  pService      Pointer to the data service interface which
0063                             should be used to load the object.
0064       @param  fullPath      Full path leading to the data object.
0065   */
0066   SmartDataLocator( IDataProviderSvc* pService, const std::string& fullPath )
0067       : SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader>( pService, 0, fullPath ) {}
0068 
0069   /** Standard constructor: Construct an SmartDataLocator instance which is
0070                             able to connect to a DataObject instance
0071                             which is identified by its directory entry.
0072                             *** FASTEST ACCESS TO THE DATA STORE ***
0073       @param  pService      Pointer to the data service interface which
0074                             should be used to load the object.
0075       @param  pDirectory    Pointer to the data directory entry.
0076   */
0077   SmartDataLocator( IDataProviderSvc* pService, IRegistry* pDirectory )
0078       : SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader>( pService, pDirectory, "" ) {}
0079 
0080   /** Standard constructor: Construct an SmartDataLocator instance which is
0081                             able to connect to a DataObject instance
0082                             which is identified by its parent object and
0083                             the path relative to the parent.
0084                             The path is meant to address only ONE level,
0085                             multiple path layers are invalid.
0086       @param  pService      Pointer to the data service interface which
0087                             should be used to load the object.
0088       @param  pObject       Pointer to the parent object.
0089       @param  path          Path to the data object relative to the parent object.
0090   */
0091   SmartDataLocator( IDataProviderSvc* pService, DataObject* pObject, const std::string& path )
0092       : SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader>( pService, 0, path ) {
0093     if ( 0 != pObject ) { this->m_pDirectory = pObject->registry(); }
0094   }
0095 
0096   /** Standard constructor: Construct an SmartDataLocator instance which is
0097                             able to connect to a DataObject instance
0098                             which is identified by its parent object and
0099                             the path relative to the parent.
0100                             The path is meant to address only ONE level,
0101                             multiple path layers are invalid.
0102       @param  refObject     Smart Pointer to the parent object.
0103       @param  pDirectory    Pointer to the data directory entry.
0104   */
0105   SmartDataLocator( SmartDataObjectPtr& refObject, IRegistry* pDirectory )
0106       : SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader>( refObject.service(), pDirectory, "" ) {}
0107 
0108   /** Standard constructor: Construct an SmartDataLocator instance which is
0109                             able to connect to a DataObject instance
0110                             which is identified by its parent object and
0111                             the path relative to the parent.
0112                             The path is meant to address only ONE level,
0113                             multiple path layers are invalid.
0114       @param  refObject     Smart Pointer to the parent object.
0115       @param  path          Path to the data object relative to the parent object.
0116   */
0117   SmartDataLocator( SmartDataObjectPtr& refObject, const std::string& path )
0118       : SmartDataStorePtr<TYPE, SmartDataObjectPtr::ObjectLoader>( refObject.service(), refObject.directory(), path ) {}
0119 
0120   /** Standard destructor
0121    */
0122   virtual ~SmartDataLocator() {}
0123 
0124   /// Automatic conversion to data type
0125   template <class OTHER>
0126   SmartDataPtr<OTHER>& operator=( OTHER* pObj ) {
0127     this->m_pObject = dynamic_cast<TYPE*>( pObj );
0128     return *this;
0129   }
0130 
0131   /// Automatic conversion to data type
0132   template <class OTHER>
0133   SmartDataPtr<OTHER>& operator=( const OTHER* pObj ) {
0134     this->m_pObject = dynamic_cast<TYPE*>( const_cast<OTHER*>( pObj ) );
0135     return *this;
0136   }
0137 };
0138 
0139 #endif // GAUDIKERNEL_SMARTDATALOCATOR_H