The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
IToolSvc.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#pragma once
12
14#include <GaudiKernel/System.h>
15#include <functional>
16#include <list>
17#include <string>
18
19// Forward declaration
20class IAlgTool;
21
28class GAUDI_API IToolSvc : virtual public IInterface {
29public:
32
33 // Typedefs
34 typedef std::list<IAlgTool*> ListTools;
35
47 virtual StatusCode retrieve( std::string_view type, const InterfaceID& iid, IAlgTool*& tool,
48 const IInterface* parent = 0, bool createIf = true ) = 0;
49
62 virtual StatusCode retrieve( std::string_view type, std::string_view name, const InterfaceID& iid, IAlgTool*& tool,
63 const IInterface* parent = 0, bool createIf = true ) = 0;
64
68 virtual std::vector<std::string> getInstances( std::string_view toolType ) = 0;
69
72 virtual std::vector<std::string> getInstances() const = 0;
73
76 virtual std::vector<IAlgTool*> getTools() const = 0;
77
81 virtual StatusCode releaseTool( IAlgTool* tool ) = 0;
82
146 template <class T>
147 StatusCode retrieveTool( std::string_view type, T*& tool, const IInterface* parent = nullptr, bool createIf = true ) {
148 IAlgTool* ialgtool{ nullptr };
149 StatusCode sc = retrieve( type, T::interfaceID(), ialgtool, parent, createIf );
150 tool = Gaudi::Cast<T>( ialgtool );
151 return sc;
152 }
153
197 template <class T>
198 StatusCode retrieveTool( std::string_view type, std::string_view name, T*& tool, const IInterface* parent = nullptr,
199 bool createIf = true ) {
200 IAlgTool* ialgtool{ nullptr };
201 StatusCode sc = retrieve( type, name, T::interfaceID(), ialgtool, parent, createIf );
202 tool = Gaudi::Cast<T>( ialgtool );
203 return sc;
204 }
205
235 class Observer {
236 public:
237 virtual ~Observer() {
238 if ( m_unregister ) m_unregister();
239 }
240 void setUnregister( std::function<void()> unregister ) { m_unregister = std::move( unregister ); }
241
242 virtual void onCreate( const IAlgTool* ) {}
243 virtual void onRetrieve( const IAlgTool* ) {}
244
245 private:
246 std::function<void()> m_unregister;
247 };
248
249 virtual void registerObserver( Observer* obs ) = 0;
250};
#define GAUDI_API
Definition Kernel.h:49
The interface implemented by the AlgTool base class.
Definition IAlgTool.h:29
Definition of the basic interface.
Definition IInterface.h:225
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition IInterface.h:228
allow call-backs when a tool is a created or retrieved
Definition IToolSvc.h:235
void setUnregister(std::function< void()> unregister)
Definition IToolSvc.h:240
virtual ~Observer()
Definition IToolSvc.h:237
virtual void onRetrieve(const IAlgTool *)
Definition IToolSvc.h:243
std::function< void()> m_unregister
Definition IToolSvc.h:246
virtual void onCreate(const IAlgTool *)
Definition IToolSvc.h:242
The interface implemented by the IToolSvc base class.
Definition IToolSvc.h:28
virtual void registerObserver(Observer *obs)=0
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.
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:198
std::list< IAlgTool * > ListTools
Definition IToolSvc.h:34
virtual StatusCode releaseTool(IAlgTool *tool)=0
Release the tool.
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:147
virtual std::vector< std::string > getInstances(std::string_view toolType)=0
Get the names of all instances of tools of a given type.
virtual std::vector< std::string > getInstances() const =0
Get the names all tool instances.
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.
DeclareInterfaceID(IToolSvc, 2, 1)
InterfaceID.
virtual std::vector< IAlgTool * > getTools() const =0
Get pointers to all tool instances.
Interface ID class.
Definition IInterface.h:38
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
TARGET * Cast(IInterface *i)
Definition IInterface.h:340