The Gaudi Framework  v33r0 (d5ea422b)
ToolSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 GAUDISVC_TOOLSVC_H
12 #define GAUDISVC_TOOLSVC_H
13 
14 // Include Files
16 #include "GaudiKernel/IToolSvc.h"
17 #include "GaudiKernel/Service.h"
18 #include <mutex>
19 #include <vector>
20 
34 class ToolSvc : public extends<Service, IToolSvc> {
35 
36 public:
38  using extends::extends;
39 
41  ~ToolSvc() override;
43  StatusCode initialize() override;
44 
46  StatusCode finalize() override;
47 
48  // Start transition for tools
49  StatusCode start() override;
50 
51  // Stop transition for tools
52  StatusCode stop() override;
53 
55  StatusCode retrieve( const std::string& type, const InterfaceID& iid, IAlgTool*& tool, const IInterface* parent,
56  bool createIf ) override;
57 
59  StatusCode retrieve( const std::string& tooltype, const std::string& toolname, const InterfaceID& iid,
60  IAlgTool*& tool, const IInterface* parent, bool createIf ) override;
61 
63  std::vector<std::string> getInstances( const std::string& toolType ) override;
64 
66  std::vector<std::string> getInstances() const override;
67 
69  std::vector<IAlgTool*> getTools() const override;
70 
72  StatusCode releaseTool( IAlgTool* tool ) override;
73 
75  StatusCode create( const std::string& type, const IInterface* parent, IAlgTool*& tool );
76 
78  StatusCode create( const std::string& type, const std::string& name, const IInterface* parent, IAlgTool*& tool );
79 
81  bool existsTool( const std::string& toolname ) const;
82 
84  std::string nameTool( const std::string& nameByUser, const IInterface* parent );
85 
86  void registerObserver( IToolSvc::Observer* obs ) override;
87 
88 private: // methods
89  // helper functions
90  //
92  unsigned long totalToolRefCount() const;
94  unsigned long minimumToolRefCount() const;
95 
97  StatusCode finalizeTool( IAlgTool* itool ) const;
98 
99 private: // data
101  std::vector<IAlgTool*> m_instancesTools; // List of all instances of tools
102 
105 
107 
109  mutable CallMutex m_mut;
110 };
111 
112 #endif
IHistorySvc * m_pHistorySvc
Pointer to HistorySvc.
Definition: ToolSvc.h:104
std::vector< std::string > getInstances() const override
Get names of all tool instances.
Definition: ToolSvc.cpp:337
StatusCode releaseTool(IAlgTool *tool) override
Release tool.
Definition: ToolSvc.cpp:354
std::string nameTool(const std::string &nameByUser, const IInterface *parent)
Get Tool full name by combining nameByUser and "parent" part.
Definition: ToolSvc.cpp:573
allow call-backs when a tool is a created or retrieved
Definition: IToolSvc.h:231
StatusCode create(const std::string &type, const IInterface *parent, IAlgTool *&tool)
Create Tool standard way with automatically assigned name.
Definition: ToolSvc.cpp:384
void registerObserver(IToolSvc::Observer *obs) override
Definition: ToolSvc.cpp:648
unsigned long minimumToolRefCount() const
The minimum number of refCounts of all tools.
Definition: ToolSvc.cpp:638
std::vector< IToolSvc::Observer * > m_observers
Definition: ToolSvc.h:106
StatusCode initialize() override
Initialize the service.
Definition: ToolSvc.cpp:62
This service manages tools.
Definition: ToolSvc.h:34
std::recursive_mutex CallMutex
Definition: ToolSvc.h:108
STL class.
StatusCode start() override
Definition: ToolSvc.cpp:662
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
Interface ID class.
Definition: IInterface.h:39
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
~ToolSvc() override
Destructor.
Definition: ToolSvc.cpp:56
Definition of the basic interface.
Definition: IInterface.h:254
std::vector< IAlgTool * > getTools() const override
Get pointers to all tool instances.
Definition: ToolSvc.cpp:347
bool existsTool(const std::string &toolname) const
Check if the tool instance exists.
Definition: ToolSvc.cpp:592
unsigned long totalToolRefCount() const
The total number of refCounts on all tools in the instancesTools list.
Definition: ToolSvc.cpp:632
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
std::vector< IAlgTool * > m_instancesTools
Common Tools.
Definition: ToolSvc.h:101
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:33
StatusCode finalize() override
Finalize the service.
Definition: ToolSvc.cpp:83
StatusCode finalizeTool(IAlgTool *itool) const
Finalize the given tool, with exception handling.
Definition: ToolSvc.cpp:602
CallMutex m_mut
Definition: ToolSvc.h:109
StatusCode stop() override
Definition: ToolSvc.cpp:686
Definition of the IHistorySvc interface class.
Definition: IHistorySvc.h:43
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:239