AlgTool.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_ALGTOOL_H
2 #define GAUDIKERNEL_ALGTOOL_H
3 // ============================================================================
4 // Include files
5 #include "GaudiKernel/IAlgTool.h"
6 #include "GaudiKernel/IProperty.h"
7 #include "GaudiKernel/IService.h"
8 #include "GaudiKernel/ISvcLocator.h"
9 #include "GaudiKernel/IMessageSvc.h"
10 #include "GaudiKernel/IToolSvc.h"
11 #include "GaudiKernel/PropertyMgr.h"
12 #include "GaudiKernel/IAuditorSvc.h"
13 #include "GaudiKernel/IMonitorSvc.h"
14 #include "GaudiKernel/IStateful.h"
15 #include <Gaudi/PluginService.h>
16 
17 #include <vector>
18 #include <list>
19 
20 // Forward declarations
21 
34 class GAUDI_API AlgTool: public implements3<IAlgTool, IProperty, IStateful> {
35  friend class ToolSvc;
36 public:
37 #ifndef __REFLEX__
39  const std::string&,
40  const std::string&,
42 #endif
43 
45  StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown) override;
46 
48  const std::string& name() const override;
49 
51  const std::string& type() const override;
52 
54  const IInterface* parent() const override;
55 
56  // State machine implementation
57  StatusCode configure() override { return StatusCode::SUCCESS; }
58  StatusCode initialize() override;
59  StatusCode start() override;
60  StatusCode stop() override;
61  StatusCode finalize() override;
62  StatusCode terminate() override { return StatusCode::SUCCESS; }
63  StatusCode reinitialize() override;
64  StatusCode restart() override;
65  Gaudi::StateMachine::State FSMState() const override { return m_state; }
66  Gaudi::StateMachine::State targetFSMState() const override { return m_targetState; }
67 
69  StatusCode sysInitialize() override;
70 
72  StatusCode sysStart() override;
73 
75  StatusCode sysStop() override;
76 
78  StatusCode sysFinalize() override;
79 
81  StatusCode sysReinitialize() override;
82 
84  StatusCode sysRestart() override;
85 
87  StatusCode setProperty( const Property& p ) override;
88  StatusCode setProperty( const std::string& s ) override;
89  StatusCode setProperty( const std::string& n, const std::string& v) override;
90  StatusCode getProperty(Property* p) const override;
91  const Property& getProperty( const std::string& name) const override;
92  StatusCode getProperty( const std::string& n, std::string& v ) const override;
93  const std::vector<Property*>& getProperties( ) const override;
94  bool hasProperty(const std::string& name) const override;
95 
96  inline PropertyMgr * getPropertyMgr() { return m_propertyMgr.get(); }
97 
98 public:
99 
140  template <class TYPE>
142  ( const std::string& name ,
143  const TYPE& value )
144  { return Gaudi::Utils::setProperty ( m_propertyMgr.get() , name , value ) ; }
145 
146 
152  AlgTool( const std::string& type,
153  const std::string& name,
154  const IInterface* parent);
155 
157  ISvcLocator* serviceLocator() const;
158 
160  ISvcLocator* svcLoc() const { return serviceLocator() ; }
161 
163  IMessageSvc* msgSvc() const;
164 
166  IToolSvc* toolSvc() const;
167 
173  StatusCode setProperties();
174 
178  template <class T>
179  StatusCode service
180  ( const std::string& name, T*& svc, bool createIf = true ) const {
181  return service_i(name, createIf, T::interfaceID(), (void**)&svc);
182  }
183 
186  template <class T>
187  StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
188  return service_i(type, name, T::interfaceID(), (void**)&svc);
189  }
190 
192  SmartIF<IService> service(const std::string& name, const bool createIf = true, const bool quiet = false) const;
193 
194  template <typename T>
195  SmartIF<T> service(const std::string& name, const bool createIf = true, const bool quiet = false) const
196  { return SmartIF<T>( service(name,createIf,quiet) ); }
197 
198 protected:
199  template <typename I>
200  void declareInterface( I* i ) { m_interfaceList.emplace_back( I::interfaceID(), i ); }
201 public:
202  // ==========================================================================
232  template <class T>
233  Property* declareProperty
234  ( const std::string& name ,
235  T& property ,
236  const std::string& doc = "none" ) const
237  {
238  return m_propertyMgr -> declareProperty ( name , property , doc ) ;
239  }
241  Property* declareRemoteProperty
242  ( const std::string& name ,
243  IProperty* rsvc ,
244  const std::string& rname = "" ) const
245  {
246  return m_propertyMgr-> declareRemoteProperty ( name , rsvc , rname ) ;
247  }
248  // ==========================================================================
250  IAuditorSvc* auditorSvc() const;
251 
261  inline IMonitorSvc* monitorSvc() const
262  {
263  // If not already located try to locate it without forcing a creation
264  if ( !m_pMonitorSvc ) m_pMonitorSvc = service(m_monitorSvcName, false, true);
265  return m_pMonitorSvc.get();
266  }
267 
273  template <class T>
274  void declareInfo( const std::string& name,
275  const T& var,
276  const std::string& desc ) const
277  {
278  IMonitorSvc* mS = monitorSvc();
279  if ( mS ) mS->declareInfo(name, var, desc, this);
280  }
281 
289  void declareInfo( const std::string& name,
290  const std::string& format,
291  const void* var,
292  int size,
293  const std::string& desc ) const
294  {
295  IMonitorSvc* mS = monitorSvc();
296  if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
297  }
298 
299 protected:
300 
302  int outputLevel () const { return (int)m_outputLevel ; }
303 
305  IntegerProperty & outputLevelProperty() { return m_outputLevel; }
306 
308  void initOutputLevel(Property& prop);
309 
310 
311 
312 protected:
313 
314  // Standard destructor.
315  ~AlgTool() override;
316 
317 private:
318  typedef std::list<std::pair<InterfaceID,void*> > InterfaceList;
319  IntegerProperty m_outputLevel = MSG::NIL;
320  std::string m_type;
321  const std::string m_name;
322  const IInterface* m_parent = nullptr;
323  mutable ISvcLocator* m_svcLocator = nullptr;
324  mutable IMessageSvc* m_messageSvc = nullptr;
327  std::string m_monitorSvcName;
329  InterfaceList m_interfaceList;
330  std::string m_threadID;
331 
333  StatusCode service_i(const std::string& algName,
334  bool createIf,
335  const InterfaceID& iid,
336  void** ppSvc) const;
337  StatusCode service_i(const std::string& svcType,
338  const std::string& svcName,
339  const InterfaceID& iid,
340  void** ppS) const;
341 
343 
344  BooleanProperty m_auditInit = false;
345  bool m_auditorInitialize = false;
346  bool m_auditorStart = false;
347  bool m_auditorStop = false;
348  bool m_auditorFinalize = false;
349  bool m_auditorReinitialize = false;
350  bool m_auditorRestart = false;
351 
354 };
355 
356 
357 #ifndef GAUDI_NEW_PLUGIN_SERVICE
358 template <class T>
359 class ToolFactory {
360 public:
361 #ifndef __REFLEX__
362  template <typename S, typename... Args>
363  static typename S::ReturnType create(Args&&... args) {
364  return new T(std::forward<Args>(args)...);
365  }
366 #endif
367 };
368 
369 // Macros to declare component factories
370 #define DECLARE_TOOL_FACTORY(x) \
371  DECLARE_FACTORY_WITH_CREATOR(x, ToolFactory< x >, AlgTool::Factory)
372 #define DECLARE_NAMESPACE_TOOL_FACTORY(n, x) \
373  DECLARE_TOOL_FACTORY(n::x)
374 
375 #else
376 
377 // Macros to declare component factories
378 #define DECLARE_TOOL_FACTORY(x) DECLARE_COMPONENT(x)
379 #define DECLARE_NAMESPACE_TOOL_FACTORY(n,x) DECLARE_COMPONENT(n::x)
380 
381 #endif
382 
383 
384 #endif // GAUDIKERNEL_ALGTOOL_H
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1187
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:17
PropertyMgr * getPropertyMgr()
Definition: AlgTool.h:96
Base class used to implement the interfaces.
Definition: implements.h:8
def initialize()
Definition: AnalysisTest.py:12
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
IntegerProperty & outputLevelProperty()
Accessor for the Message level property.
Definition: AlgTool.h:305
std::string m_type
AlgTool type (concrete class name)
Definition: AlgTool.h:320
SmartIF< IAuditorSvc > m_pAuditorSvc
Auditor Service.
Definition: AlgTool.h:342
#define GAUDI_API
Definition: Kernel.h:107
GAUDI_API bool hasProperty(const IProperty *p, const std::string &name)
simple function which check the existence of the property with the given name.
Definition: Property.cpp:157
SmartIF< IMonitorSvc > m_pMonitorSvc
Online Monitoring Service.
Definition: AlgTool.h:326
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm, Service, AlgTool).
Definition: StateMachine.h:12
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:259
Property manager helper class.
Definition: PropertyMgr.h:34
This service manages tools.
Definition: ToolSvc.h:22
Gaudi::StateMachine::State FSMState() const override
Definition: AlgTool.h:65
std::string m_monitorSvcName
Name to use for Monitor Service.
Definition: AlgTool.h:327
const std::string m_name
AlgTool full name.
Definition: AlgTool.h:321
static S::ReturnType create(Args &&...args)
Definition: AlgTool.h:363
Interface ID class.
Definition: IInterface.h:30
IMonitorSvc * monitorSvc() const
Access the monitor service.
Definition: AlgTool.h:261
ISvcLocator * svcLoc() const
shortcut for the method service locator
Definition: AlgTool.h:160
Definition of the IMonitorSvc interface, which publishes Gaudi variables to outside monitoring proces...
Definition: IMonitorSvc.h:21
void declareInfo(const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
Declare monitoring information (special case)
Definition: AlgTool.h:289
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
Gaudi::StateMachine::State targetFSMState() const override
Definition: AlgTool.h:66
StatusCode configure() override
Definition: AlgTool.h:57
SmartIF< PropertyMgr > m_propertyMgr
Property Manager.
Definition: AlgTool.h:328
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
std::string m_threadID
Thread Id for Alg Tool.
Definition: AlgTool.h:330
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:255
void declareInfo(const std::string &name, const T &var, const std::string &desc) const
Declare monitoring information.
Definition: AlgTool.h:274
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
virtual void declareInfo(const std::string &name, const bool &var, const std::string &desc, const IInterface *owner)=0
Declare monitoring information.
list args
Definition: gaudirun.py:291
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
StatusCode service(const std::string &type, const std::string &name, T *&svc) const
Access a service by name, type creating it if it doesn't already exist.
Definition: AlgTool.h:187
void declareInterface(I *i)
Definition: AlgTool.h:200
SmartIF< T > service(const std::string &name, const bool createIf=true, const bool quiet=false) const
Definition: AlgTool.h:195
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
int outputLevel() const
get tool's output level
Definition: AlgTool.h:302
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:22
StatusCode finalize() override
Finalize the service.
Definition: ToolSvc.cpp:74
string s
Definition: gaudirun.py:246
SmartIF< IToolSvc > m_ptoolSvc
Tool service.
Definition: AlgTool.h:325
InterfaceList m_interfaceList
Interface list.
Definition: AlgTool.h:329
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:21
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:21
StatusCode terminate() override
Definition: AlgTool.h:62
The interface implemented by the IAuditorSvc base class.
Definition: IAuditorSvc.h:15
list i
Definition: ana.py:128
StatusCode stop() override
Definition: ToolSvc.cpp:733
std::list< std::pair< InterfaceID, void * > > InterfaceList
Definition: AlgTool.h:318
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:120
tuple start
Definition: IOTest.py:88
string type
Definition: gaudirun.py:151
Gaudi::PluginService::Factory< IAlgTool *, const std::string &, const std::string &, const IInterface * > Factory
Definition: AlgTool.h:41