The Gaudi Framework  master (b6adf5d0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ServiceLocatorHelper.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
12 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
13 
14 #include <GaudiKernel/IService.h>
16 #include <GaudiKernel/SmartIF.h>
17 #include <GaudiKernel/StatusCode.h>
18 #include <string>
19 
20 class InterfaceID;
21 class MsgStream;
22 
28 public:
29  ServiceLocatorHelper( ISvcLocator& svcLoc, const INamedInterface& requester )
30  : m_svcLoc( svcLoc )
31  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requester.name() )
32  , // use requester msg level
33  m_requesterName( requester.name() ) {}
34  ServiceLocatorHelper( ISvcLocator& svcLoc, std::string loggedName, std::string requesterName )
35  : m_svcLoc( svcLoc )
36  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), std::move( loggedName ) )
37  , // use requester msg level
38  m_requesterName( std::move( requesterName ) ) {}
39  ServiceLocatorHelper( ISvcLocator& svcLoc, std::string requesterName )
40  : m_svcLoc( svcLoc )
41  , m_msgLog( SmartIF<IMessageSvc>( &svcLoc ), requesterName )
42  , // use requester msg level
43  m_requesterName( std::move( requesterName ) ) {}
44 
45  StatusCode getService( std::string_view name, bool createIf, const InterfaceID& iid, void** ppSvc ) const {
46  return createIf ? createService( name, iid, ppSvc ) : locateService( name, iid, ppSvc, true );
47  }
48 
49  StatusCode locateService( std::string_view name, const InterfaceID& iid, void** ppSvc, bool quiet = false ) const;
50 
51  StatusCode createService( std::string_view name, const InterfaceID& iid, void** ppSvc ) const;
52 
53  StatusCode createService( std::string_view type, std::string_view name, const InterfaceID& iid, void** ppSvc ) const;
54 
55  SmartIF<IService> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const;
56 
57  template <typename T>
58  SmartIF<T> service( std::string_view name, const bool quiet = false, const bool createIf = true ) const {
59  return service( name, quiet, createIf ).as<T>();
60  }
61 
62 private:
63  ISvcLocator* serviceLocator() const { return &m_svcLoc; }
64  MsgStream& log() const { return m_msgLog; }
65  const std::string& requesterName() const { return m_requesterName; }
68  std::string m_requesterName;
69 };
70 #endif
ServiceLocatorHelper::service
SmartIF< T > service(std::string_view name, const bool quiet=false, const bool createIf=true) const
Definition: ServiceLocatorHelper.h:58
ServiceLocatorHelper::m_svcLoc
ISvcLocator & m_svcLoc
Definition: ServiceLocatorHelper.h:66
IService.h
IMessageSvc
Definition: IMessageSvc.h:47
GaudiPartProp.decorators.std
std
Definition: decorators.py:32
ISvcLocator
Definition: ISvcLocator.h:46
ServiceLocatorHelper::m_requesterName
std::string m_requesterName
Definition: ServiceLocatorHelper.h:68
ServiceLocatorHelper::m_msgLog
MsgStream m_msgLog
Definition: ServiceLocatorHelper.h:67
ServiceLocatorHelper::log
MsgStream & log() const
Definition: ServiceLocatorHelper.h:64
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, const INamedInterface &requester)
Definition: ServiceLocatorHelper.h:29
StatusCode.h
ServiceLocatorHelper::requesterName
const std::string & requesterName() const
Definition: ServiceLocatorHelper.h:65
SmartIF.h
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, std::string requesterName)
Definition: ServiceLocatorHelper.h:39
ServiceLocatorHelper::ServiceLocatorHelper
ServiceLocatorHelper(ISvcLocator &svcLoc, std::string loggedName, std::string requesterName)
Definition: ServiceLocatorHelper.h:34
StatusCode
Definition: StatusCode.h:65
ServiceLocatorHelper
an helper to share the implementation of service() among the various kernel base classes
Definition: ServiceLocatorHelper.h:27
ServiceLocatorHelper::getService
StatusCode getService(std::string_view name, bool createIf, const InterfaceID &iid, void **ppSvc) const
Definition: ServiceLocatorHelper.h:45
SmartIF
Definition: IConverter.h:25
MsgStream
Definition: MsgStream.h:33
gaudirun.type
type
Definition: gaudirun.py:160
INamedInterface
Definition: INamedInterface.h:25
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
InterfaceID
Definition: IInterface.h:39
ServiceLocatorHelper::serviceLocator
ISvcLocator * serviceLocator() const
Definition: ServiceLocatorHelper.h:63
ISvcLocator.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:84