| The Gaudi Framework v32r1 (f65d50dc)

ServiceLocatorHelper.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/ServiceLocatorHelper.h"
2
3 #include "GaudiKernel/IService.h"
4 #include "GaudiKernel/ISvcLocator.h"
5 #include "GaudiKernel/MsgStream.h"
6
7 StatusCode ServiceLocatorHelper::locateService( const std::string& name, const InterfaceID& iid, void** ppSvc,
8 bool quiet ) const {
9 auto theSvc = service( name, quiet, false );
10 if ( !theSvc ) return StatusCode::FAILURE;
11 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
12 if ( !sc.isSuccess() ) {
13 *ppSvc = nullptr;
14 if ( !quiet )
15 log() << MSG::ERROR << "ServiceLocatorHelper::locateService: wrong interface id " << iid << " for service "
16 << name << endmsg;
17 }
18 return sc;
19 }
20
21 StatusCode ServiceLocatorHelper::createService( const std::string& name, const InterfaceID& iid, void** ppSvc ) const {
22 auto theSvc = service( name, false, true );
23 if ( !theSvc ) return StatusCode::FAILURE;
24 StatusCode sc = theSvc->queryInterface( iid, ppSvc );
25 if ( !sc.isSuccess() ) {
26 *ppSvc = nullptr;
27 log() << MSG::ERROR << "ServiceLocatorHelper::createService: wrong interface id " << iid << " for service " << name
28 << endmsg;
29 }
30 return sc;
31 }
32
33 StatusCode ServiceLocatorHelper::createService( const std::string& type, const std::string& name,
34 const InterfaceID& iid, void** ppSvc ) const {
35 return createService( type + "/" + name, iid, ppSvc );
36 }
37
38 SmartIF<IService> ServiceLocatorHelper::service( const std::string& name, const bool quiet,
39 const bool createIf ) const {
40 SmartIF<IService> theSvc = serviceLocator()->service( name, createIf );
41
42 if ( theSvc ) {
43 if ( !quiet ) {
44 if ( UNLIKELY( log().level() <= MSG::VERBOSE ) )
45 log() << MSG::VERBOSE << "ServiceLocatorHelper::service: found service " << name << endmsg;
46 }
47 } else {
48 // if not return an error
49 if ( !quiet ) { log() << MSG::ERROR << "ServiceLocatorHelper::service: can not locate service " << name << endmsg; }
50 }
51 return theSvc;
52 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
SmartIF< IService >
ServiceLocatorHelper::createService
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.cpp:21
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
MsgStream.h
MSG::VERBOSE
Definition: IMessageSvc.h:15
std::string
STL class.
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
InterfaceID
Interface ID class.
Definition: IInterface.h:29
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:61
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
gaudirun.type
type
Definition: gaudirun.py:142
ServiceLocatorHelper::service
SmartIF< IService > service(const std::string &name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.cpp:38
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
IService.h
ServiceLocatorHelper::locateService
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
Definition: ServiceLocatorHelper.cpp:7
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:60
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
ServiceLocatorHelper.h
MSG::ERROR
Definition: IMessageSvc.h:15
gaudirun.level
level
Definition: gaudirun.py:334
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192