| # Gaudi Framework, version v25r0 |

Home |  | Generated: Mon Feb 17 2014

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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"
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 typedef Gaudi::PluginService::Factory3<IAlgTool*,
38 const std::string&,
39 const std::string&,
40 const IInterface*> Factory;
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
55 virtual StatusCode configure() { return StatusCode::SUCCESS; }
56 virtual StatusCode initialize();
57 virtual StatusCode start();
58 virtual StatusCode stop();
59 virtual StatusCode finalize();
60 virtual StatusCode terminate() { return StatusCode::SUCCESS; }
61 virtual StatusCode reinitialize();
62 virtual StatusCode restart();
63 virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
64 virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
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>
138 StatusCode setProperty
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
170 StatusCode setProperties();
171
175 template <class T>
176 StatusCode service
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;
320 IntegerProperty m_outputLevel;
321 std::string m_type;
322 const std::string m_name;
323 const IInterface* m_parent;
324 mutable ISvcLocator* m_svcLocator;
325 mutable IMessageSvc* m_messageSvc;
326 mutable IToolSvc* m_ptoolSvc;
327 mutable IMonitorSvc* m_pMonitorSvc;
328 std::string m_monitorSvcName;
329 PropertyMgr* m_propertyMgr;
330 InterfaceList m_interfaceList;
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
343 mutable IAuditorSvc* m_pAuditorSvc;
344
345 BooleanProperty m_auditInit;
346 bool m_auditorInitialize;
347 bool m_auditorStart;
348 bool m_auditorStop;
349 bool m_auditorFinalize;
350 bool m_auditorReinitialize;
351 bool m_auditorRestart;
352
353 Gaudi::StateMachine::State m_state;
354 Gaudi::StateMachine::State m_targetState;
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