| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

ServiceHandle< T > Class Template Reference

Handle to be used in lieu of naked pointers to services. More...

#include <GaudiKernel/ServiceHandle.h>

Inheritance diagram for ServiceHandle< T >:

[legend]
Collaboration diagram for ServiceHandle< T >:
[legend]
List of all members.

Public Member Functions

 ServiceHandle (const std::string &serviceName, const std::string &theParentName)
 Create a handle ('smart pointer') to a service.
StatusCode retrieve () const
 Retrieve the Service.
StatusCode release () const
 Release the component.
 operator bool () const
 For testing if handle has component.
T & operator * ()
T & operator * () const
T * operator-> ()
T * operator-> () const
std::string getDefaultType ()
 Helper function to get default type string from the class type.
std::string getDefaultName ()
std::string typeAndName () const
 The full type and name: "type/name".
std::string type () const
 The concrete component class name: the part before the '/'.
std::string name () const
 The instance name: the part after the '/'.
bool empty () const
 Check if the handle has been set to empty string (i.e.
void setTypeAndName (const std::string &myTypeAndName)
 The component "type/name" string.
void setName (const std::string &myName)
 Set the instance name (part after the '/') without changing the class type.
const std::string pythonPropertyClassName () const
 Name of the componentType with "Handle" appended.
const std::string messageName () const
 name used for printing messages
virtual const std::string pythonRepr () const
 Python representation of handle, i.e.
const std::string & componentType () const
const std::string & propertyName () const
 name as used in declareProperty(name,gaudiHandle)
void setPropertyName (const std::string &propName)
 set name as used in declareProperty(name,gaudiHandle).
const std::string & parentName () const
 The name of the parent.

Protected Member Functions

StatusCode retrieve (T *&service) const
 Do the real retrieval of the Service.
virtual StatusCode release (T *comp) const
 Release the component.

Private Member Functions

ISvcLocatorserviceLocator () const
 Do the real release of the Service.
IMessageSvcmessageSvc () const

Private Attributes

ISvcLocatorm_pSvcLocator
IMessageSvcm_pMessageSvc

Detailed Description

template<class T>
class ServiceHandle< T >

Handle to be used in lieu of naked pointers to services.

This allows better control through the framework of service loading and usage.

Author:
Martin.Woudstra@cern.ch

Definition at line 30 of file ServiceHandle.h.


Constructor & Destructor Documentation

template<class T>
ServiceHandle< T >::ServiceHandle ( const std::string &  serviceName,
const std::string &  theParentName 
) [inline]

Create a handle ('smart pointer') to a service.

The arguments are passed on to ServiceSvc, and have the same meaning:

Parameters:
serviceName name of the service
parentName name of the parent Algorithm, AlgTool or Service. It is used for log printout at retrieve(), and for retrieving a thread-dependent service (if applicable)

Definition at line 42 of file ServiceHandle.h.

00043     : GaudiHandle<T>(serviceName, "Service", theParentName), 
00044       m_pSvcLocator(0), m_pMessageSvc(0)
00045   {}


Member Function Documentation

template<class T>
StatusCode ServiceHandle< T >::retrieve (  )  const [inline]

Retrieve the Service.

Release existing Service if needed. Function must be repeated here to avoid hiding the function retrieve( T*& )

Reimplemented from GaudiHandle< T >.

Definition at line 49 of file ServiceHandle.h.

00049                               { // not really const, because it updates m_pObject
00050     return GaudiHandle<T>::retrieve();
00051   }

template<class T>
StatusCode ServiceHandle< T >::retrieve ( T *&  service  )  const [inline, protected, virtual]

Do the real retrieval of the Service.

Implements GaudiHandle< T >.

Definition at line 61 of file ServiceHandle.h.

00061                                            {
00062     MsgStream log(messageSvc(), GaudiHandleBase::messageName());
00063     ServiceLocatorHelper helper(*serviceLocator(), log, this->parentName());
00064     return helper.getService(GaudiHandleBase::typeAndName(), true, T::interfaceID(), (void**)&service);
00065   }

template<class T>
ISvcLocator* ServiceHandle< T >::serviceLocator (  )  const [inline, private]

Do the real release of the Service.

Definition at line 76 of file ServiceHandle.h.

00076                                       { // not really const, because it may change m_pSvcLocator
00077     if ( !m_pSvcLocator ) {
00078       m_pSvcLocator = Gaudi::svcLocator();
00079       if ( !m_pSvcLocator ) {
00080         throw GaudiException("SvcLocator not found", "Core component not found", StatusCode::FAILURE);
00081       }
00082     }
00083     return m_pSvcLocator;
00084   }

template<class T>
IMessageSvc* ServiceHandle< T >::messageSvc (  )  const [inline, private]

Definition at line 86 of file ServiceHandle.h.

00086                                   { // not really const, because it may change m_pMessageSvc
00087     if ( !m_pMessageSvc ) {
00088       StatusCode sc = serviceLocator()->service( "MessageSvc", m_pMessageSvc, true );
00089       if( sc.isFailure() ) {
00090         throw GaudiException("Service [MessageSvc] not found", 
00091                              this->parentName(), sc);
00092       }
00093     }
00094     return m_pMessageSvc;
00095   }

template<class T>
StatusCode GaudiHandle< T >::release (  )  const [inline, inherited]

Release the component.

Reimplemented in ToolHandle< T >.

Definition at line 198 of file GaudiHandle.h.

00198                              { // not really const, because it updates m_pObject
00199     if ( m_pObject ) {
00200       StatusCode sc = release( m_pObject );
00201       m_pObject = 0;
00202       return sc;
00203     }
00204     return StatusCode::SUCCESS;
00205   }

template<class T>
virtual StatusCode GaudiHandle< T >::release ( T *  comp  )  const [inline, protected, virtual, inherited]

Release the component.

Default implementation calls release() on the component. Can be overridden by the derived class if something else if needed.

Reimplemented in ToolHandle< T >.

Definition at line 250 of file GaudiHandle.h.

00250                                               { // not really const, because it updates m_pObject
00251     comp->release();
00252     return StatusCode::SUCCESS;
00253   }

template<class T>
GaudiHandle< T >::operator bool (  )  const [inline, inherited]

For testing if handle has component.

Does retrieve() if needed. If this returns false, the component could not be retrieved.

Definition at line 209 of file GaudiHandle.h.

00209                         { // not really const, because it may update m_pObject 
00210     return getObject();
00211   }

template<class T>
T& GaudiHandle< T >::operator * (  )  [inline, inherited]

Definition at line 213 of file GaudiHandle.h.

00213                  { 
00214     assertObject();
00215     return *m_pObject;
00216   }

template<class T>
T& GaudiHandle< T >::operator * (  )  const [inline, inherited]

Definition at line 223 of file GaudiHandle.h.

00223                        { // not really const, because it may update m_pObject 
00224     assertObject();
00225     return *m_pObject; 
00226   }

template<class T>
T* GaudiHandle< T >::operator-> (  )  [inline, inherited]

Definition at line 218 of file GaudiHandle.h.

00218                   { 
00219     assertObject();
00220     return m_pObject; 
00221   }

template<class T>
T* GaudiHandle< T >::operator-> (  )  const [inline, inherited]

Definition at line 228 of file GaudiHandle.h.

00228                         { // not really const, because it may update m_pObject 
00229     assertObject();
00230     return m_pObject;
00231   }

template<class T>
std::string GaudiHandle< T >::getDefaultType (  )  [inline, inherited]

Helper function to get default type string from the class type.

Definition at line 234 of file GaudiHandle.h.

00234                              {  
00235     return System::typeinfoName( typeid(T) );
00236   }

template<class T>
std::string GaudiHandle< T >::getDefaultName (  )  [inline, inherited]

Definition at line 238 of file GaudiHandle.h.

00238                              {
00239     std::string defName = GaudiHandleBase::type();
00240     if ( defName.empty() ) defName = getDefaultType();
00241     return defName;
00242   }

std::string GaudiHandleBase::typeAndName (  )  const [inline, inherited]

The full type and name: "type/name".

Definition at line 107 of file GaudiHandle.h.

00107                                 { 
00108      return m_typeAndName;
00109   }

std::string GaudiHandleBase::type (  )  const [inherited]

The concrete component class name: the part before the '/'.

std::string GaudiHandleBase::name (  )  const [inherited]

The instance name: the part after the '/'.

bool GaudiHandleBase::empty (  )  const [inline, inherited]

Check if the handle has been set to empty string (i.e.

typeAndName string is empty).

Definition at line 118 of file GaudiHandle.h.

00118                      {
00119     return m_typeAndName.empty();
00120   }

void GaudiHandleBase::setTypeAndName ( const std::string &  myTypeAndName  )  [inherited]

The component "type/name" string.

void GaudiHandleBase::setName ( const std::string &  myName  )  [inherited]

Set the instance name (part after the '/') without changing the class type.

const std::string GaudiHandleBase::pythonPropertyClassName (  )  const [virtual, inherited]

Name of the componentType with "Handle" appended.

Used as the python class name for the property in the genconf-generated configurables. The python class is defined in GaudiPython/python/GaudiHandles.py.

Implements GaudiHandleInfo.

const std::string GaudiHandleBase::messageName (  )  const [inherited]

name used for printing messages

virtual const std::string GaudiHandleBase::pythonRepr (  )  const [virtual, inherited]

Python representation of handle, i.e.

python class name and argument. Can be used in the genconf-generated configurables. The corresponding python classes are defined in GaudiPython/GaudiHandles.py

Implements GaudiHandleInfo.

const std::string& GaudiHandleInfo::componentType (  )  const [inline, inherited]

Definition at line 33 of file GaudiHandle.h.

00033                                          {
00034      return m_componentType;
00035   }

const std::string& GaudiHandleInfo::propertyName (  )  const [inline, inherited]

name as used in declareProperty(name,gaudiHandle)

Definition at line 38 of file GaudiHandle.h.

00038                                         {
00039      return m_propertyName;
00040   }

void GaudiHandleInfo::setPropertyName ( const std::string &  propName  )  [inline, inherited]

set name as used in declareProperty(name,gaudiHandle).

Used in printout.

Definition at line 43 of file GaudiHandle.h.

00043                                                     {
00044     m_propertyName = propName;
00045   }

const std::string& GaudiHandleInfo::parentName (  )  const [inline, inherited]

The name of the parent.

Definition at line 48 of file GaudiHandle.h.

00048                                       {
00049     return m_parentName;
00050   }


Member Data Documentation

template<class T>
ISvcLocator* ServiceHandle< T >::m_pSvcLocator [mutable, private]

Definition at line 99 of file ServiceHandle.h.

template<class T>
IMessageSvc* ServiceHandle< T >::m_pMessageSvc [mutable, private]

Definition at line 100 of file ServiceHandle.h.


The documentation for this class was generated from the following file:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:57:13 2011 for GaudiKernel by doxygen 1.4.7