The Gaudi Framework  master (37c0b60a)
IToolSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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_ITOOLSVC_H
12 #define GAUDIKERNEL_ITOOLSVC_H
13 
14 #include <GaudiKernel/IInterface.h>
15 #include <GaudiKernel/System.h>
16 #include <functional>
17 #include <list>
18 #include <string>
19 
20 // Forward declaration
21 class IAlgTool;
22 
29 class GAUDI_API IToolSvc : virtual public IInterface {
30 public:
33 
34  // Typedefs
36 
48  virtual StatusCode retrieve( std::string_view type, const InterfaceID& iid, IAlgTool*& tool,
49  const IInterface* parent = 0, bool createIf = true ) = 0;
50 
63  virtual StatusCode retrieve( std::string_view type, std::string_view name, const InterfaceID& iid, IAlgTool*& tool,
64  const IInterface* parent = 0, bool createIf = true ) = 0;
65 
69  virtual std::vector<std::string> getInstances( std::string_view toolType ) = 0;
70 
74 
77  virtual std::vector<IAlgTool*> getTools() const = 0;
78 
83 
147  template <class T>
148  StatusCode retrieveTool( std::string_view type, T*& tool, const IInterface* parent = nullptr, bool createIf = true ) {
149  return retrieve( type, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
150  }
151 
195  template <class T>
196  StatusCode retrieveTool( std::string_view type, std::string_view name, T*& tool, const IInterface* parent = nullptr,
197  bool createIf = true ) {
198  return retrieve( type, name, T::interfaceID(), (IAlgTool*&)tool, parent, createIf );
199  }
200 
230  class Observer {
231  public:
232  virtual ~Observer() {
233  if ( m_unregister ) m_unregister();
234  }
235  void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
236 
237  virtual void onCreate( const IAlgTool* ) {}
238  virtual void onRetrieve( const IAlgTool* ) {}
239 
240  private:
242  };
243 
244  virtual void registerObserver( Observer* obs ) = 0;
245 };
246 
247 #endif // GAUDIKERNEL_ITOOLSVC_H
Gaudi::InterfaceId
Class to handle automatically the versioning of the interfaces when they are inheriting from other in...
Definition: IInterface.h:189
IAlgTool
Definition: IAlgTool.h:33
std::list
STL class.
IToolSvc::Observer::setUnregister
void setUnregister(std::function< void()> unregister)
Definition: IToolSvc.h:235
std::move
T move(T... args)
IToolSvc::registerObserver
virtual void registerObserver(Observer *obs)=0
System.h
std::vector< std::string >
IToolSvc::ListTools
std::list< IAlgTool * > ListTools
Definition: IToolSvc.h:35
IToolSvc::Observer::onCreate
virtual void onCreate(const IAlgTool *)
Definition: IToolSvc.h:237
IToolSvc::getInstances
virtual std::vector< std::string > getInstances(std::string_view toolType)=0
Get the names of all instances of tools of a given type.
std::function
IToolSvc::retrieveTool
StatusCode retrieveTool(std::string_view type, std::string_view name, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name tool dependent part of the name...
Definition: IToolSvc.h:196
bug_34121.tool
tool
Definition: bug_34121.py:18
StatusCode
Definition: StatusCode.h:65
IInterface.h
IToolSvc::Observer::m_unregister
std::function< void()> m_unregister
Definition: IToolSvc.h:241
IToolSvc::retrieve
virtual StatusCode retrieve(std::string_view type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name automatically assigned.
IToolSvc::Observer
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:230
IToolSvc::Observer::~Observer
virtual ~Observer()
Definition: IToolSvc.h:232
IToolSvc::retrieveTool
StatusCode retrieveTool(std::string_view type, T *&tool, const IInterface *parent=nullptr, bool createIf=true)
Retrieve specified tool sub-type with tool dependent part of the name automatically assigned.
Definition: IToolSvc.h:148
gaudirun.type
type
Definition: gaudirun.py:160
IToolSvc::Observer::onRetrieve
virtual void onRetrieve(const IAlgTool *)
Definition: IToolSvc.h:238
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
IInterface
Definition: IInterface.h:239
IToolSvc::DeclareInterfaceID
DeclareInterfaceID(IToolSvc, 2, 1)
InterfaceID.
IToolSvc::releaseTool
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
InterfaceID
Definition: IInterface.h:39
IToolSvc::getTools
virtual std::vector< IAlgTool * > getTools() const =0
Get pointers to all tool instances.
IToolSvc
Definition: IToolSvc.h:29
IToolSvc::retrieve
virtual StatusCode retrieve(std::string_view type, std::string_view name, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name specified by the requester.
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
IToolSvc::getInstances
virtual std::vector< std::string > getInstances() const =0
Get the names all tool instances.