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&,
41  const IInterface*> Factory;
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
57  virtual StatusCode configure() { return StatusCode::SUCCESS; }
58  virtual StatusCode initialize();
59  virtual StatusCode start();
60  virtual StatusCode stop();
61  virtual StatusCode finalize();
62  virtual StatusCode terminate() { return StatusCode::SUCCESS; }
63  virtual StatusCode reinitialize();
64  virtual StatusCode restart();
65  virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
66  virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
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;
323  IntegerProperty m_outputLevel;
324  std::string m_type;
325  const std::string m_name;
326  const IInterface* m_parent;
327  mutable ISvcLocator* m_svcLocator;
328  mutable IMessageSvc* m_messageSvc;
329  mutable IToolSvc* m_ptoolSvc;
330  mutable IMonitorSvc* m_pMonitorSvc;
331  std::string m_monitorSvcName;
332  PropertyMgr* m_propertyMgr;
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 
346  mutable IAuditorSvc* m_pAuditorSvc;
347 
348  BooleanProperty m_auditInit;
349  bool m_auditorInitialize;
350  bool m_auditorStart;
351  bool m_auditorStop;
352  bool m_auditorFinalize;
353  bool m_auditorReinitialize;
354  bool m_auditorRestart;
355 
357  Gaudi::StateMachine::State m_targetState;
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
virtual StatusCode configure()
Configuration (from OFFLINE to CONFIGURED).
Definition: Service.h:50
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
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
virtual StatusCode finalize()
Finalize the service.
Definition: ToolSvc.cpp:67
Gaudi::StateMachine::State m_state
Service state.
Definition: Service.h:246
Base class used to implement the interfaces.
Definition: implements.h:167
#define GAUDI_API
Definition: Kernel.h:108
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
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
Interface ID class.
Definition: IInterface.h:55
Definition of the IMonitorSvc interface, which publishes Gaudi variables to outside monitoring proces...
Definition: IMonitorSvc.h:21
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
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:290
virtual StatusCode sysStop()
Initialize Service.
Definition: Service.cpp:115
virtual StatusCode terminate()
Initialization (from CONFIGURED to OFFLINE).
Definition: Service.h:55
virtual Gaudi::StateMachine::State FSMState() const
Get the current state.
Definition: Service.h:56
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
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
Definition: Service.cpp:292
static S::ReturnType create(Args...args)
Definition: AlgTool.h:367
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
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:289
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
Base class from which all the concrete tool classes should be derived.
Definition: AlgTool.h:34
The interface implemented by the AlgTool base class.
Definition: IAlgTool.h:23
string s
Definition: gaudirun.py:244
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
PropertyMgr * m_propertyMgr
Property Manager.
Definition: Service.h:260
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: Service.h:57
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
Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
Definition: Service.h:38
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
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition: MsgStream.cpp:133
tuple start
Definition: IOTest.py:88
string type
Definition: gaudirun.py:151
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