All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
38  const std::string&,
39  const std::string&,
41 
43  virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown);
44 
46  virtual const std::string& name() const;
47 
49  virtual const std::string& type() const;
50 
52  virtual const IInterface* parent() const;
53 
54  // State machine implementation
56  virtual StatusCode initialize();
57  virtual StatusCode start();
58  virtual StatusCode stop();
59  virtual StatusCode finalize();
61  virtual StatusCode reinitialize();
62  virtual StatusCode restart();
63  virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
65 
67  virtual StatusCode sysInitialize();
68 
70  virtual StatusCode sysStart();
71 
73  virtual StatusCode sysStop();
74 
76  virtual StatusCode sysFinalize();
77 
79  virtual StatusCode sysReinitialize();
80 
82  virtual StatusCode sysRestart();
83 
85  virtual StatusCode setProperty( const Property& p );
86  virtual StatusCode setProperty( const std::string& s );
87  virtual StatusCode setProperty( const std::string& n, const std::string& v);
88  virtual StatusCode getProperty(Property* p) const;
89  virtual const Property& getProperty( const std::string& name) const;
90  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
91  virtual const std::vector<Property*>& getProperties( ) const;
92 
93  inline PropertyMgr * getPropertyMgr() { return m_propertyMgr; }
94 
95 public:
96 
137  template <class TYPE>
139  ( const std::string& name ,
140  const TYPE& value )
141  { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
142 
143 
149  AlgTool( const std::string& type,
150  const std::string& name,
151  const IInterface* parent);
152 
154  ISvcLocator* serviceLocator() const;
155 
157  ISvcLocator* svcLoc() const { return serviceLocator() ; }
158 
160  IMessageSvc* msgSvc() const;
161 
163  IToolSvc* toolSvc() const;
164 
171 
175  template <class T>
177  ( const std::string& name, T*& svc, bool createIf = true ) const {
178  return service_i(name, createIf, T::interfaceID(), (void**)&svc);
179  }
180 
183  template <class T>
184  StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
185  return service_i(type, name, T::interfaceID(), (void**)&svc);
186  }
187 
189  SmartIF<IService> service(const std::string& name, const bool createIf = true, const bool quiet = false) const;
190 
192  void declInterface( const InterfaceID&, void*);
193 
194  template <class I> class declareInterface {
195  public:
196  template <class T> declareInterface(T* tool) {
197  tool->declInterface( I::interfaceID(), (I*)tool);
198  }
199  };
200  // ==========================================================================
230  template <class T>
231  Property* declareProperty
232  ( const std::string& name ,
233  T& property ,
234  const std::string& doc = "none" ) const
235  {
236  return m_propertyMgr -> declareProperty ( name , property , doc ) ;
237  }
239  Property* declareRemoteProperty
240  ( const std::string& name ,
241  IProperty* rsvc ,
242  const std::string& rname = "" ) const
243  {
244  return m_propertyMgr-> declareRemoteProperty ( name , rsvc , rname ) ;
245  }
246  // ==========================================================================
248  IAuditorSvc* auditorSvc() const;
249 
259  inline IMonitorSvc* monitorSvc() const
260  {
261  // If not already located try to locate it without forcing a creation
262  if ( !m_pMonitorSvc ){
263  service_i( m_monitorSvcName, false,
264  IMonitorSvc::interfaceID(), pp_cast<void>(&m_pMonitorSvc) ).ignore();
265  }
266  return m_pMonitorSvc;
267  }
268 
274  template <class T>
275  void declareInfo( const std::string& name,
276  const T& var,
277  const std::string& desc ) const
278  {
279  IMonitorSvc* mS = monitorSvc();
280  if ( mS ) mS->declareInfo(name, var, desc, this);
281  }
282 
290  void declareInfo( const std::string& name,
291  const std::string& format,
292  const void* var,
293  int size,
294  const std::string& desc ) const
295  {
296  IMonitorSvc* mS = monitorSvc();
297  if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
298  }
299 
300 protected:
301 
303  int outputLevel () const { return (int)m_outputLevel ; }
304 
306  IntegerProperty & outputLevelProperty() { return m_outputLevel; }
307 
309  void initOutputLevel(Property& prop);
310 
311 
312 
313 protected:
314 
315  // Standard destructor.
316  virtual ~AlgTool();
317 
318 private:
319  typedef std::list<std::pair<InterfaceID,void*> > InterfaceList;
321  std::string m_type;
322  const std::string m_name;
326  mutable IToolSvc* m_ptoolSvc;
328  std::string m_monitorSvcName;
331  std::string m_threadID;
332 
334  StatusCode service_i(const std::string& algName,
335  bool createIf,
336  const InterfaceID& iid,
337  void** ppSvc) const;
338  StatusCode service_i(const std::string& svcType,
339  const std::string& svcName,
340  const InterfaceID& iid,
341  void** ppS) const;
342 
344 
352 
355 };
356 
357 
358 #ifndef GAUDI_NEW_PLUGIN_SERVICE
359 template <class T>
360 class ToolFactory {
361 public:
362  template <typename S>
363  static typename S::ReturnType create(typename S::Arg1Type a1,
364  typename S::Arg2Type a2,
365  typename S::Arg3Type a3) {
366  return new T(a1, a2, a3);
367  }
368 };
369 
370 // Macros to declare component factories
371 #define DECLARE_TOOL_FACTORY(x) \
372  DECLARE_FACTORY_WITH_CREATOR(x, ToolFactory< x >, AlgTool::Factory)
373 #define DECLARE_NAMESPACE_TOOL_FACTORY(n, x) \
374  DECLARE_TOOL_FACTORY(n::x)
375 
376 #else
377 
378 // Macros to declare component factories
379 #define DECLARE_TOOL_FACTORY(x) DECLARE_COMPONENT(x)
380 #define DECLARE_NAMESPACE_TOOL_FACTORY(n,x) DECLARE_COMPONENT(n::x)
381 
382 #endif
383 
384 
385 #endif // GAUDIKERNEL_ALGTOOL_H
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: Service.cpp:315
static S::ReturnType create(typename S::Arg1Type a1, typename S::Arg2Type a2, typename S::Arg3Type a3)
Definition: AlgTool.h:363
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:245
PropertyMgr * getPropertyMgr()
Definition: AlgTool.h:93
PropertyMgr * m_propertyMgr
Property Manager.
Definition: AlgTool.h:329
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:306
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:321
virtual StatusCode finalize()
Finalize the service.
Definition: ToolSvc.cpp:67
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:243
virtual StatusCode terminate()
Initialization (from CONFIGURED to OFFLINE).
Definition: AlgTool.h:60
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:64
Base class used to implement the interfaces.
Definition: implements.h:167
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: AlgTool.h:63
IMessageSvc * m_messageSvc
Message service.
Definition: AlgTool.h:325
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
const IInterface * m_parent
AlgTool parent.
Definition: AlgTool.h:323
ISvcLocator * m_svcLocator
Pointer to Service Locator service.
Definition: AlgTool.h:324
IntegerProperty m_outputLevel
AlgTool output level.
Definition: AlgTool.h:320
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:164
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:349
Property manager helper class.
Definition: PropertyMgr.h:38
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:328
const std::string m_name
AlgTool full name.
Definition: AlgTool.h:322
Interface ID class.
Definition: IInterface.h:55
IMonitorSvc * monitorSvc() const
Access the monitor service.
Definition: AlgTool.h:259
ISvcLocator * svcLoc() const
shortcut for the method service locator
Definition: AlgTool.h:157
string type
Definition: gaudirun.py:126
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:290
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
Definition: ToolSvc.cpp:782
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)
Implementation of IInterface::queryInterface.
Definition: extends.h:43
Class wrapping the signature for a factory with 3 arguments.
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:331
virtual StatusCode sysStop()
Initialize Service.
Definition: Service.cpp:117
IToolSvc * m_ptoolSvc
Tool service.
Definition: AlgTool.h:326
StatusCode setProperties()
Method for setting declared properties to the values specified for the job.
Definition: Service.cpp:371
virtual const std::string & name() const
Retrieve name of the service.
Definition: Service.cpp:331
virtual StatusCode sysInitialize()
Initialize Service.
Definition: Service.cpp:37
bool m_auditorFinalize
flag for auditors in "finalize()"
Definition: AlgTool.h:349
virtual StatusCode configure()
Configuration (from OFFLINE to CONFIGURED).
Definition: AlgTool.h:55
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Definition: Service.cpp:294
void declareInfo(const std::string &name, const T &var, const std::string &desc) const
Declare monitoring information.
Definition: AlgTool.h:275
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:257
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:353
virtual void declareInfo(const std::string &name, const bool &var, const std::string &desc, const IInterface *owner)=0
Declare monitoring information.
virtual StatusCode sysRestart()
Re-initialize the Service.
Definition: Service.cpp:251
Gaudi::PluginService::Factory3< IAlgTool *, const std::string &, const std::string &, const IInterface * > Factory
Definition: AlgTool.h:40
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:184
IAuditorSvc * m_pAuditorSvc
Auditor Service.
Definition: AlgTool.h:343
bool m_auditorReinitialize
flag for auditors in "reinitialize()"
Definition: AlgTool.h:350
IMonitorSvc * m_pMonitorSvc
Online Monitoring Service.
Definition: AlgTool.h:327
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:303
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:210
bool m_auditorRestart
flag for auditors in "restart()"
Definition: AlgTool.h:351
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:140
virtual StatusCode sysReinitialize()
Re-initialize the Service.
Definition: Service.cpp:206
InterfaceList m_interfaceList
Interface list.
Definition: AlgTool.h:330
BooleanProperty m_auditInit
Definition: AlgTool.h:345
bool m_auditorStart
flag for auditors in "start()"
Definition: AlgTool.h:347
Gaudi::StateMachine::State m_targetState
state of the Tool
Definition: AlgTool.h:354
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:348
#define GAUDI_API
Definition: Kernel.h:108
virtual StatusCode sysStart()
Initialize Service.
Definition: Service.cpp:83
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:346
std::list< std::pair< InterfaceID, void * > > InterfaceList
Definition: AlgTool.h:319
tuple start
Definition: IOTest.py:88
virtual const std::vector< Property * > & getProperties() const
Get list of properties.
Definition: Service.cpp:366
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336