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