Accessing Gaudi Services
Making a Service Available
To set up jobOptions to make a service available for a particular run:
- The shared library containing the service must be loaded ** required **
and, in addition:
- The service may be listed in the list of services available **optional**
For example, to use a service called myNewSvc, which is defined in a shared library called, glastServices, you would add the following lines to your jobOptions file:
ApplicationMgr.Dlls += { "glastServices"}; ** required **
ApplicationMgr.ExtSvc += { "myNewSvc" }; **optional**
Accessing a default Gaudi Service from a Gaudi Algorithm
By default, all Gaudi algorithms include methods to access the standard Gaudi services, so that no special calls are required to gain access to these services.
The following methods are available to all Gaudi algorithms:
|
IAuditorSvc* |
auditorSvc( ) const; |
|
|
IChronoStatSvc* |
chronoSvc( ) const; |
|
|
IDataProviderSvc* |
detSvc( ) const; |
|
|
IConversionSvc* |
detCnvSvc( ) const; |
|
|
IDataProviderSvc* |
eventSvc( ) const; |
|
|
IConversionSvc* |
eventCnvSvc( ) const; |
|
|
IHistogramSvc* |
histoSvc( ) const; |
|
|
IMessageSvc* |
msgSvc( ) const; |
|
|
INTupleSvc* |
ntupleSvc( ) const; |
|
|
IRndmGenSvc* |
randSvc( ) const; |
|
|
IToolSvc* |
toolSvc( ) const; |
|
|
|
|
|
|
Note: Each method returns an interface, and each service implements one or more interfaces. When interacting with a service, you are actually using a specific interface. |
Accessing a Service from a Gaudi Algorithm or Service that is not a default
Gaudi has set up a way for Algorithms and Services to access a service interface that is not one of the defaults provided, assuming a service is available for a particular run.
For example:
|
IIncidentSvc* incsvc = 0;
StatusCode sc = service("IncidentSvc", incSvc, true);
if (sc.isFailure()) {
log << MSG::ERROR << "Could not find the Gaudi Incident Service!" << endreq;
return sc;
} |
How this code works:
|
IIncidentSvc *incsvc = 0; |
|
|
declares a new variable which is of type IIncidentSvc - the interface we want to gain access to. |
|
|
|
|
StatusCode sc = service("IncidentSvc", incSvc, true); |
|
|
|
|
|
Does the work of accessing the interface.
The first parameter is the name of the service,
the second is a variable which is a pointer to the interface you are interested in,
and the third parameter is optional;
true means that the service will be loaded if it is not already.
Note: If this call returns StatusCode::FAILURE, the service could not be accessed. |
Accessing a service from code that is NOT a Gaudi Algorithm or Service
To access services from code that is not a Gaudi algorithm or service, use a call to serviceLocator( ):
|
IService *isvc = 0;
StatusCode sc = serviceLocator( )->getService("GlastDetSvc", isvc, true);
if (sc.isSuccess() ) {
sc = isvc->queryInterface(IID_IGlastDetSvc, (void**)&m_detSvc);
}else {
log << MSG::WARNING << "Failed to access the GlastDetSvc!" << endreq;
} |
How this code works:
|
IService *isvc = 0; |
|
|
Sets up a generic variable isvc that is a pointer to any service. |
|
|
|
|
StatusCode sc = serviceLocator( )->getService("GlastDetSvc", isvc, true); |
|
|
Retrieves a pointer to the service named, GlastDetSvc
isvc points to the service.
The third parameter, if true, means that if the service not already loaded, Gaudi should attempt to load it. |
|
|
|
|
if (sc.isSuccess() ) { |
|
|
Checks whether or not a pointer was successfully retrieved to our service;
if so, one more check is performed:
|
|
|
|
|
sc = isvc->queryInterface(IID_IGlastDetSvc, (void**)&m_detSvc); |
|
|
Makes sure that our GlastDetSvc actually implements the IGlastDetSvc interface. |
Once your code has accessed the service, you may use the methods defined in the
interface(s) that the service implements. (See Gaudi Developer Guide, Section 11.2 Requesting and accessing services.)
Owned by: Heather Kelly
Last updated by: Chuck Patterson
07/27/2005 |
|
|