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:
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 
95  inline PropertyMgr * getPropertyMgr() { return m_propertyMgr; }
96 
97 public:
98 
139  template <class TYPE>
141  ( const std::string& name ,
142  const TYPE& value )
143  { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
144 
145 
151  AlgTool( const std::string& type,
152  const std::string& name,
153  const IInterface* parent);
154 
156  ISvcLocator* serviceLocator() const;
157 
159  ISvcLocator* svcLoc() const { return serviceLocator() ; }
160 
162  IMessageSvc* msgSvc() const;
163 
165  IToolSvc* toolSvc() const;
166 
173 
177  template <class T>
179  ( const std::string& name, T*& svc, bool createIf = true ) const {
180  return service_i(name, createIf, T::interfaceID(), (void**)&svc);
181  }
182 
185  template <class T>
186  StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
187  return service_i(type, name, T::interfaceID(), (void**)&svc);
188  }
189 
191  SmartIF<IService> service(const std::string& name, const bool createIf = true, const bool quiet = false) const;
192 
194  void declInterface( const InterfaceID&, void*);
195 
196  template <class I> class declareInterface {
197  public:
198  template <class T> declareInterface(T* tool) {
199  tool->declInterface( I::interfaceID(), (I*)tool);
200  }
201  };
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 ){
265  service_i( m_monitorSvcName, false,
266  IMonitorSvc::interfaceID(), pp_cast<void>(&m_pMonitorSvc) ).ignore();
267  }
268  return m_pMonitorSvc;
269  }
270 
276  template <class T>
277  void declareInfo( const std::string& name,
278  const T& var,
279  const std::string& desc ) const
280  {
281  IMonitorSvc* mS = monitorSvc();
282  if ( mS ) mS->declareInfo(name, var, desc, this);
283  }
284 
292  void declareInfo( const std::string& name,
293  const std::string& format,
294  const void* var,
295  int size,
296  const std::string& desc ) const
297  {
298  IMonitorSvc* mS = monitorSvc();
299  if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
300  }
301 
302 protected:
303 
305  int outputLevel () const { return (int)m_outputLevel ; }
306 
308  IntegerProperty & outputLevelProperty() { return m_outputLevel; }
309 
311  void initOutputLevel(Property& prop);
312 
313 
314 
315 protected:
316 
317  // Standard destructor.
318  virtual ~AlgTool();
319 
320 private:
321  typedef std::list<std::pair<InterfaceID,void*> > InterfaceList;
323  std::string m_type;
324  const std::string m_name;
328  mutable IToolSvc* m_ptoolSvc;
330  std::string m_monitorSvcName;
333  std::string m_threadID;
334 
336  StatusCode service_i(const std::string& algName,
337  bool createIf,
338  const InterfaceID& iid,
339  void** ppSvc) const;
340  StatusCode service_i(const std::string& svcType,
341  const std::string& svcName,
342  const InterfaceID& iid,
343  void** ppS) const;
344 
346 
354 
357 };
358 
359 
360 #ifndef GAUDI_NEW_PLUGIN_SERVICE
361 template <class T>
362 class ToolFactory {
363 public:
364 #ifndef __REFLEX__
365  template <typename S, typename... Args>
366  static typename S::ReturnType create(Args... args) {
367  return new T(args...);
368  }
369 #endif
370 };
371 
372 // Macros to declare component factories
373 #define DECLARE_TOOL_FACTORY(x) \
374  DECLARE_FACTORY_WITH_CREATOR(x, ToolFactory< x >, AlgTool::Factory)
375 #define DECLARE_NAMESPACE_TOOL_FACTORY(n, x) \
376  DECLARE_TOOL_FACTORY(n::x)
377 
378 #else
379 
380 // Macros to declare component factories
381 #define DECLARE_TOOL_FACTORY(x) DECLARE_COMPONENT(x)
382 #define DECLARE_NAMESPACE_TOOL_FACTORY(n,x) DECLARE_COMPONENT(n::x)
383 
384 #endif
385 
386 
387 #endif // GAUDIKERNEL_ALGTOOL_H
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
Definition: Service.cpp:315
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:247
PropertyMgr * getPropertyMgr()
Definition: AlgTool.h:95
PropertyMgr * m_propertyMgr
Property Manager.
Definition: AlgTool.h:331
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:308
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:323
virtual StatusCode finalize()
Finalize the service.
Definition: ToolSvc.cpp:67
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:245
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:327
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
const IInterface * m_parent
AlgTool parent.
Definition: AlgTool.h:325
ISvcLocator * m_svcLocator
Pointer to Service Locator service.
Definition: AlgTool.h:326
IntegerProperty m_outputLevel
AlgTool output level.
Definition: AlgTool.h:322
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:330
const std::string m_name
AlgTool full name.
Definition: AlgTool.h:324
Interface ID class.
Definition: IInterface.h:55
IMonitorSvc * monitorSvc() const
Access the monitor service.
Definition: AlgTool.h:261
ISvcLocator * svcLoc() const
shortcut for the method service locator
Definition: AlgTool.h:159
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:292
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
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:333
virtual StatusCode sysStop()
Initialize Service.
Definition: Service.cpp:117
IToolSvc * m_ptoolSvc
Tool service.
Definition: AlgTool.h:328
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:351
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:294
void declareInfo(const std::string &name, const T &var, const std::string &desc) const
Declare monitoring information.
Definition: AlgTool.h:277
static S::ReturnType create(Args...args)
Definition: AlgTool.h:366
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:259
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:355
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:254
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:251
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:186
IAuditorSvc * m_pAuditorSvc
Auditor Service.
Definition: AlgTool.h:345
bool m_auditorReinitialize
flag for auditors in "reinitialize()"
Definition: AlgTool.h:352
IMonitorSvc * m_pMonitorSvc
Online Monitoring Service.
Definition: AlgTool.h:329
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:305
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:353
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:142
virtual StatusCode sysReinitialize()
Re-initialize the Service.
Definition: Service.cpp:206
InterfaceList m_interfaceList
Interface list.
Definition: AlgTool.h:332
BooleanProperty m_auditInit
Definition: AlgTool.h:347
bool m_auditorStart
flag for auditors in "start()"
Definition: AlgTool.h:349
Gaudi::StateMachine::State m_targetState
state of the Tool
Definition: AlgTool.h:356
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:350
#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:348
std::list< std::pair< InterfaceID, void * > > InterfaceList
Definition: AlgTool.h:321
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:366
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Definition: Service.cpp:336