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"
7 #include "GaudiKernel/IService.h"
10 #include "GaudiKernel/IToolSvc.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  virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown);
46 
48  virtual const std::string& name() const;
49 
51  virtual const std::string& type() const;
52 
54  virtual const IInterface* parent() const;
55 
56  // State machine implementation
58  virtual StatusCode initialize();
59  virtual StatusCode start();
60  virtual StatusCode stop();
61  virtual StatusCode finalize();
63  virtual StatusCode reinitialize();
64  virtual StatusCode restart();
65  virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
67 
69  virtual StatusCode sysInitialize();
70 
72  virtual StatusCode sysStart();
73 
75  virtual StatusCode sysStop();
76 
78  virtual StatusCode sysFinalize();
79 
81  virtual StatusCode sysReinitialize();
82 
84  virtual StatusCode sysRestart();
85 
87  virtual StatusCode setProperty( const Property& p );
88  virtual StatusCode setProperty( const std::string& s );
89  virtual StatusCode setProperty( const std::string& n, const std::string& v);
90  virtual StatusCode getProperty(Property* p) const;
91  virtual const Property& getProperty( const std::string& name) const;
92  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
93  virtual const std::vector<Property*>& getProperties( ) const;
94  virtual bool hasProperty(const std::string& name) const;
95 
96  inline PropertyMgr * getPropertyMgr() { return m_propertyMgr; }
97 
98 public:
99 
140  template <class TYPE>
142  ( const std::string& name ,
143  const TYPE& value )
144  { return Gaudi::Utils::setProperty ( m_propertyMgr , 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 
174 
178  template <class T>
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 
195  void declInterface( const InterfaceID&, void*);
196 
197  template <class I> class declareInterface {
198  public:
199  template <class T> declareInterface(T* tool) {
200  tool->declInterface( I::interfaceID(), (I*)tool);
201  }
202  };
203  // ==========================================================================
233  template <class T>
234  Property* declareProperty
235  ( const std::string& name ,
236  T& property ,
237  const std::string& doc = "none" ) const
238  {
239  return m_propertyMgr -> declareProperty ( name , property , doc ) ;
240  }
242  Property* declareRemoteProperty
243  ( const std::string& name ,
244  IProperty* rsvc ,
245  const std::string& rname = "" ) const
246  {
247  return m_propertyMgr-> declareRemoteProperty ( name , rsvc , rname ) ;
248  }
249  // ==========================================================================
251  IAuditorSvc* auditorSvc() const;
252 
262  inline IMonitorSvc* monitorSvc() const
263  {
264  // If not already located try to locate it without forcing a creation
265  if ( !m_pMonitorSvc ){
266  service_i( m_monitorSvcName, false,
267  IMonitorSvc::interfaceID(), pp_cast<void>(&m_pMonitorSvc) ).ignore();
268  }
269  return m_pMonitorSvc;
270  }
271 
277  template <class T>
278  void declareInfo( const std::string& name,
279  const T& var,
280  const std::string& desc ) const
281  {
282  IMonitorSvc* mS = monitorSvc();
283  if ( mS ) mS->declareInfo(name, var, desc, this);
284  }
285 
293  void declareInfo( const std::string& name,
294  const std::string& format,
295  const void* var,
296  int size,
297  const std::string& desc ) const
298  {
299  IMonitorSvc* mS = monitorSvc();
300  if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
301  }
302 
303 protected:
304 
306  int outputLevel () const { return (int)m_outputLevel ; }
307 
309  IntegerProperty & outputLevelProperty() { return m_outputLevel; }
310 
312  void initOutputLevel(Property& prop);
313 
314 
315 
316 protected:
317 
318  // Standard destructor.
319  virtual ~AlgTool();
320 
321 private:
322  typedef std::list<std::pair<InterfaceID,void*> > InterfaceList;
324  std::string m_type;
325  const std::string m_name;
329  mutable IToolSvc* m_ptoolSvc;
331  std::string m_monitorSvcName;
333  InterfaceList m_interfaceList;
334  std::string m_threadID;
335 
337  StatusCode service_i(const std::string& algName,
338  bool createIf,
339  const InterfaceID& iid,
340  void** ppSvc) const;
341  StatusCode service_i(const std::string& svcType,
342  const std::string& svcName,
343  const InterfaceID& iid,
344  void** ppS) const;
345 
347 
355 
358 };
359 
360 
361 #ifndef GAUDI_NEW_PLUGIN_SERVICE
362 template <class T>
363 class ToolFactory {
364 public:
365 #ifndef __REFLEX__
366  template <typename S, typename... Args>
367  static typename S::ReturnType create(Args... args) {
368  return new T(args...);
369  }
370 #endif
371 };
372 
373 // Macros to declare component factories
374 #define DECLARE_TOOL_FACTORY(x) \
375  DECLARE_FACTORY_WITH_CREATOR(x, ToolFactory< x >, AlgTool::Factory)
376 #define DECLARE_NAMESPACE_TOOL_FACTORY(n, x) \
377  DECLARE_TOOL_FACTORY(n::x)
378 
379 #else
380 
381 // Macros to declare component factories
382 #define DECLARE_TOOL_FACTORY(x) DECLARE_COMPONENT(x)
383 #define DECLARE_NAMESPACE_TOOL_FACTORY(n,x) DECLARE_COMPONENT(n::x)
384 
385 #endif
386 
387 
388 #endif // GAUDIKERNEL_ALGTOOL_H
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: Service.cpp:313
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:1212
The interface implemented by the IToolSvc base class.
Definition: IToolSvc.h:17
Gaudi::StateMachine::State m_targetState
Service state.
Definition: Service.h:248
PropertyMgr * getPropertyMgr()
Definition: AlgTool.h:96
PropertyMgr * m_propertyMgr
Property Manager.
Definition: AlgTool.h:332
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:26
IntegerProperty & outputLevelProperty()
Accessor for the Message level property.
Definition: AlgTool.h:309
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
std::string m_type
AlgTool type (concrete class name)
Definition: AlgTool.h:324
virtual StatusCode finalize()
Finalize the service.
Definition: ToolSvc.cpp:67
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:246
virtual StatusCode terminate()
Initialization (from CONFIGURED to OFFLINE).
Definition: AlgTool.h:62
virtual Gaudi::StateMachine::State targetFSMState() const
When we are in the middle of a transition, get the state where the transition is leading us...
Definition: AlgTool.h:66
Base class used to implement the interfaces.
Definition: implements.h:167
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: AlgTool.h:65
IMessageSvc * m_messageSvc
Message service.
Definition: AlgTool.h:328
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
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:232
const IInterface * m_parent
AlgTool parent.
Definition: AlgTool.h:326
ISvcLocator * m_svcLocator
Pointer to Service Locator service.
Definition: AlgTool.h:327
IntegerProperty m_outputLevel
AlgTool output level.
Definition: AlgTool.h:323
State
Allowed states for classes implementing the state machine (ApplicationMgr, Algorithm, Service, AlgTool).
Definition: StateMachine.h:12
virtual StatusCode sysFinalize()
Finalize Service.
Definition: Service.cpp:162
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:297
Property manager helper class.
Definition: PropertyMgr.h:34
This service manages tools.
Definition: ToolSvc.h:23
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:164
std::string m_monitorSvcName
Name to use for Monitor Service.
Definition: AlgTool.h:331
const std::string m_name
AlgTool full name.
Definition: AlgTool.h:325
Interface ID class.
Definition: IInterface.h:55
IMonitorSvc * monitorSvc() const
Access the monitor service.
Definition: AlgTool.h:262
ISvcLocator * svcLoc() const
shortcut for the method service locator
Definition: AlgTool.h:160
string type
Definition: gaudirun.py:127
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:293
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
Definition: ToolSvc.cpp:798
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)
Implementation of IInterface::queryInterface.
Definition: extends.h:43
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
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:334
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:290
virtual StatusCode sysStop()
Initialize Service.
Definition: Service.cpp:115
IToolSvc * m_ptoolSvc
Tool service.
Definition: AlgTool.h:329
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
Definition: Service.cpp:373
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:329
virtual StatusCode sysInitialize()
Initialize Service.
Definition: Service.cpp:35
bool m_auditorFinalize
flag for auditors in "finalize()"
Definition: AlgTool.h:352
virtual StatusCode configure()
Configuration (from OFFLINE to CONFIGURED).
Definition: AlgTool.h:57
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Definition: Service.cpp:292
void declareInfo(const std::string &name, const T &var, const std::string &desc) const
Declare monitoring information.
Definition: AlgTool.h:278
static S::ReturnType create(Args...args)
Definition: AlgTool.h:367
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:260
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
Gaudi::StateMachine::State m_state
state of the Tool
Definition: AlgTool.h:356
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:262
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
virtual StatusCode sysRestart()
Re-initialize the Service.
Definition: Service.cpp:249
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
IAuditorSvc * m_pAuditorSvc
Auditor Service.
Definition: AlgTool.h:346
bool m_auditorReinitialize
flag for auditors in "reinitialize()"
Definition: AlgTool.h:353
IMonitorSvc * m_pMonitorSvc
Online Monitoring Service.
Definition: AlgTool.h:330
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:306
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:217
bool m_auditorRestart
flag for auditors in "restart()"
Definition: AlgTool.h:354
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:143
virtual StatusCode sysReinitialize()
Re-initialize the Service.
Definition: Service.cpp:204
InterfaceList m_interfaceList
Interface list.
Definition: AlgTool.h:333
BooleanProperty m_auditInit
Definition: AlgTool.h:348
bool m_auditorStart
flag for auditors in "start()"
Definition: AlgTool.h:350
Gaudi::StateMachine::State m_targetState
state of the Tool
Definition: AlgTool.h:357
The IProperty is the basic interface for all components which have properties that can be set or get...
Definition: IProperty.h:22
The interface implemented by the IAuditorSvc base class.
Definition: IAuditorSvc.h:16
bool m_auditorStop
flag for auditors in "stop()"
Definition: AlgTool.h:351
#define GAUDI_API
Definition: Kernel.h:108
virtual StatusCode sysStart()
Initialize Service.
Definition: Service.cpp:81
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:171
bool m_auditorInitialize
flag for auditors in "initialize()"
Definition: AlgTool.h:349
std::list< std::pair< InterfaceID, void * > > InterfaceList
Definition: AlgTool.h:322
tuple start
Definition: IOTest.py:88
Gaudi::PluginService::Factory< IAlgTool *, const std::string &, const std::string &, const IInterface * > Factory
Definition: AlgTool.h:41
virtual const std::vector< Property * > & getProperties() const
Get list of properties.
Definition: Service.cpp:364
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:334