Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ServiceLocatorHelper.cpp
Go to the documentation of this file.
2 
3 #include "GaudiKernel/IService.h"
6 
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 
34  const InterfaceID& iid, void** ppSvc ) const {
35  return createService( type + "/" + name, iid, ppSvc );
36 }
37 
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 }
ISvcLocator * serviceLocator() const
#define UNLIKELY(x)
Definition: Kernel.h:89
bool isSuccess() const
Definition: StatusCode.h:267
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:76
Interface ID class.
Definition: IInterface.h:29
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
StatusCode locateService(const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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:192
StatusCode createService(const std::string &name, const InterfaceID &iid, void **ppSvc) const