ToolSvc.h
Go to the documentation of this file.
1 #ifndef GAUDISVC_TOOLSVC_H
2 #define GAUDISVC_TOOLSVC_H
3 
4 // Include Files
5 #include "GaudiKernel/Service.h"
6 #include "GaudiKernel/IToolSvc.h"
7 #include <vector>
8 #include <mutex>
9 
23 class ToolSvc : public extends<Service,
24  IToolSvc> {
25 
26 public:
27 
29  StatusCode initialize() override;
30 
32  StatusCode finalize() override;
33 
34  // Start transition for tools
35  StatusCode start() override;
36 
37  // Stop transition for tools
38  StatusCode stop() override;
39 
41  StatusCode retrieve(const std::string& type, const InterfaceID& iid,
42  IAlgTool*& tool, const IInterface* parent,
43  bool createIf) override;
44 
46  StatusCode retrieve(const std::string& tooltype, const std::string& toolname,
47  const InterfaceID& iid, IAlgTool*& tool,
48  const IInterface* parent, bool createIf) override;
49 
51  std::vector<std::string> getInstances( const std::string& toolType ) override;
52 
54  std::vector<std::string> getInstances() const override;
55 
57  std::vector<IAlgTool*> getTools() const override;
58 
60  StatusCode releaseTool( IAlgTool* tool ) override;
61 
63  StatusCode create(const std::string& type, const IInterface* parent,
64  IAlgTool*& tool);
65 
67  StatusCode create(const std::string& type, const std::string& name,
68  const IInterface* parent, IAlgTool*& tool);
69 
71  bool existsTool( const std::string& toolname) const;
72 
74  std::string nameTool(const std::string& nameByUser, const IInterface* parent);
75 
80  ToolSvc( const std::string& name, ISvcLocator* svc );
81 
83  ~ToolSvc() override = default;
84 
85  void registerObserver(IToolSvc::Observer *obs) override;
86  void unRegisterObserver(IToolSvc::Observer *obs) override;
87 
88 
89 private: // methods
90  // helper functions
91  //
93  unsigned long totalToolRefCount() const;
95  unsigned long minimumToolRefCount() const;
96 
98  StatusCode finalizeTool( IAlgTool* itool ) const;
99 
100 private: // data
101 
103  std::vector<IAlgTool*> m_instancesTools; // List of all instances of tools
104 
107 
109 
111  mutable CallMutex m_mut;
112 };
113 
114 #endif
115 
116 
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:106
std::vector< std::string > getInstances() const override
Get names of all tool instances.
Definition: ToolSvc.cpp:363
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
StatusCode releaseTool(IAlgTool *tool) override
Release tool.
Definition: ToolSvc.cpp:381
void unRegisterObserver(IToolSvc::Observer *obs) override
Definition: ToolSvc.cpp:730
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:631
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:244
unsigned long minimumToolRefCount() const
The minimum number of refCounts of all tools.
Definition: ToolSvc.cpp:710
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:414
void registerObserver(IToolSvc::Observer *obs) override
Definition: ToolSvc.cpp:721
tuple toolname
Definition: gaudirun.py:327
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:108
bool existsTool(const std::string &toolname) const
Check if the tool instance exists.
Definition: ToolSvc.cpp:653
StatusCode initialize() override
Initialize the service.
Definition: ToolSvc.cpp:52
This service manages tools.
Definition: ToolSvc.h:23
std::recursive_mutex CallMutex
Definition: ToolSvc.h:110
STL class.
StatusCode start() override
Definition: ToolSvc.cpp:738
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
Interface ID class.
Definition: IInterface.h:30
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:704
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:663
string type
Definition: gaudirun.py:151
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
std::vector< IAlgTool * > getTools() const override
Get pointers to all tool instances.
Definition: ToolSvc.cpp:373
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:103
ToolSvc(const std::string &name, ISvcLocator *svc)
Standard Constructor.
Definition: ToolSvc.cpp:47
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
StatusCode finalize() override
Finalize the service.
Definition: ToolSvc.cpp:74
CallMutex m_mut
Definition: ToolSvc.h:111
StatusCode stop() override
Definition: ToolSvc.cpp:764
~ToolSvc() override=default
Destructor.
Definition of the IHistorySvc interface class.
Definition: IHistorySvc.h:32
StatusCode retrieve(const std::string &type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent, bool createIf) override
Retrieve tool, create it by default as common tool if it does not already exist.
Definition: ToolSvc.cpp:247