| # Gaudi Framework, version v21r10p1 |

Home |  | Generated: 29 Jul 2010

# AlgTool.h

Go to the documentation of this file.

    00001 // $Id: AlgTool.h,v 1.23 2008/06/02 14:20:38 marcocle Exp $
    00002 // ============================================================================
    00003 #ifndef GAUDIKERNEL_ALGTOOL_H
    00004 #define GAUDIKERNEL_ALGTOOL_H
    00005 // ============================================================================
    00006 // Include files
    00007 #include "GaudiKernel/IAlgTool.h"
    00008 #include "GaudiKernel/IProperty.h"
    00009 #include "GaudiKernel/IService.h"
    00010 #include "GaudiKernel/ISvcLocator.h"
    00011 #include "GaudiKernel/IMessageSvc.h"
    00012 #include "GaudiKernel/IToolSvc.h"
    00013 #include "GaudiKernel/PropertyMgr.h"
    00014 #include "GaudiKernel/IAuditorSvc.h"
    00015 #include "GaudiKernel/IMonitorSvc.h"
    00016 #include "GaudiKernel/IStateful.h"
    00017
    00018 #include <vector>
    00019 #include <list>
    00020
    00021 // Forward declarations
    00022
    00035 class GAUDI_API AlgTool: public implements3<IAlgTool, IProperty, IStateful> {
    00036   friend class ToolSvc;
    00037 public:
    00038
    00040   virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown);
    00041
    00043   virtual const std::string& name() const;
    00044
    00046   virtual const std::string& type() const;
    00047
    00049   virtual const IInterface*  parent() const;
    00050
    00051   // State machine implementation
    00052   virtual StatusCode configure() { return StatusCode::SUCCESS; }
    00053   virtual StatusCode initialize();
    00054   virtual StatusCode start();
    00055   virtual StatusCode stop();
    00056   virtual StatusCode finalize();
    00057   virtual StatusCode terminate() { return StatusCode::SUCCESS; }
    00058   virtual StatusCode reinitialize();
    00059   virtual StatusCode restart();
    00060   virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
    00061   virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
    00062
    00064   virtual StatusCode sysInitialize();
    00065
    00067   virtual StatusCode sysStart();
    00068
    00070   virtual StatusCode sysStop();
    00071
    00073   virtual StatusCode sysFinalize();
    00074
    00076   virtual StatusCode sysReinitialize();
    00077
    00079   virtual StatusCode sysRestart();
    00080
    00082   virtual StatusCode setProperty( const Property&    p );
    00083   virtual StatusCode setProperty( const std::string& s );
    00084   virtual StatusCode setProperty( const std::string& n, const std::string& v);
    00085   virtual StatusCode getProperty(Property* p) const;
    00086   virtual const Property& getProperty( const std::string& name) const;
    00087   virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
    00088   virtual const std::vector<Property*>& getProperties( ) const;
    00089
    00090   inline PropertyMgr * getPropertyMgr() { return m_propertyMgr; }
    00091
    00092 public:
    00093
    00134   template <class TYPE>
    00135   StatusCode setProperty
    00136   ( const std::string& name  ,
    00137     const TYPE&        value )
    00138   { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
    00139
    00140
    00146   AlgTool( const std::string& type,
    00147            const std::string& name,
    00148            const IInterface* parent);
    00149
    00151   ISvcLocator* serviceLocator()  const;
    00152
    00154   ISvcLocator* svcLoc()  const { return serviceLocator() ; }
    00155
    00157   IMessageSvc* msgSvc() const;
    00158
    00160   IToolSvc* toolSvc() const;
    00161
    00167   StatusCode setProperties();
    00168
    00172   template <class T>
    00173   StatusCode service
    00174   ( const std::string& name, T*& svc, bool createIf = true ) const {
    00175     return service_i(name, createIf, T::interfaceID(), (void**)&svc);
    00176   }
    00177
    00180   template <class T>
    00181   StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
    00182     return service_i(type, name, T::interfaceID(), (void**)&svc);
    00183   }
    00184
    00186   void declInterface( const InterfaceID&, void*);
    00187
    00188   template <class I> class declareInterface {
    00189   public:
    00190     template <class T> declareInterface(T* tool) {
    00191       tool->declInterface( I::interfaceID(), (I*)tool);
    00192     }
    00193   };
    00194   // ==========================================================================
    00224   template <class T>
    00225   Property* declareProperty
    00226   ( const std::string& name         ,
    00227     T&                 property     ,
    00228     const std::string& doc = "none" ) const
    00229   {
    00230     return m_propertyMgr -> declareProperty ( name , property , doc ) ;
    00231   }
    00233   Property* declareRemoteProperty
    00234   ( const std::string& name       ,
    00235     IProperty*         rsvc       ,
    00236     const std::string& rname = "" ) const
    00237   {
    00238     return m_propertyMgr-> declareRemoteProperty ( name , rsvc , rname ) ;
    00239   }
    00240   // ==========================================================================
    00242   IAuditorSvc* auditorSvc() const;
    00243
    00253   inline IMonitorSvc* monitorSvc() const
    00254   {
    00255     // If not already located try to locate it without forcing a creation
    00256     if ( !m_pMonitorSvc ){
    00257       service_i( m_monitorSvcName, false,
    00258                  IMonitorSvc::interfaceID(), pp_cast<void>(&m_pMonitorSvc) ).ignore();
    00259     }
    00260     return m_pMonitorSvc;
    00261   }
    00262
    00268   template <class T>
    00269   void declareInfo( const std::string& name,
    00270                     const T& var,
    00271                     const std::string& desc ) const
    00272   {
    00273     IMonitorSvc* mS = monitorSvc();
    00274     if ( mS ) mS->declareInfo(name, var, desc, this);
    00275   }
    00276
    00284   void declareInfo( const std::string& name,
    00285                     const std::string& format,
    00286                     const void* var,
    00287                     int size,
    00288                     const std::string& desc ) const
    00289   {
    00290     IMonitorSvc* mS = monitorSvc();
    00291     if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
    00292   }
    00293
    00294 protected:
    00295
    00297   int           outputLevel () const { return (int)m_outputLevel ; }
    00298
    00300   IntegerProperty & outputLevelProperty() { return m_outputLevel; }
    00301
    00303   void initOutputLevel(Property& prop);
    00304
    00305
    00306
    00307 protected:
    00308
    00309   // Standard destructor.
    00310   virtual ~AlgTool();
    00311
    00312 private:
    00313   typedef std::list<std::pair<InterfaceID,void*> >  InterfaceList;
    00314   IntegerProperty      m_outputLevel;
    00315   std::string          m_type;
    00316   const std::string    m_name;
    00317   const IInterface*    m_parent;
    00318   mutable ISvcLocator* m_svcLocator;
    00319   mutable IMessageSvc* m_messageSvc;
    00320   mutable IToolSvc*    m_ptoolSvc;
    00321   mutable IMonitorSvc* m_pMonitorSvc;
    00322   std::string          m_monitorSvcName;
    00323   PropertyMgr*         m_propertyMgr;
    00324   InterfaceList        m_interfaceList;
    00325   std::string          m_threadID;
    00326
    00328   StatusCode service_i(const std::string& algName,
    00329                        bool createIf,
    00330                        const InterfaceID& iid,
    00331                        void** ppSvc) const;
    00332   StatusCode service_i(const std::string& svcType,
    00333                        const std::string& svcName,
    00334                        const InterfaceID& iid,
    00335                        void** ppS) const;
    00336
    00337   mutable IAuditorSvc*      m_pAuditorSvc;
    00338
    00339   BooleanProperty m_auditInit;
    00340   bool         m_auditorInitialize;
    00341   bool         m_auditorStart;
    00342   bool         m_auditorStop;
    00343   bool         m_auditorFinalize;
    00344   bool         m_auditorReinitialize;
    00345   bool         m_auditorRestart;
    00346
    00347   Gaudi::StateMachine::State m_state;
    00348   Gaudi::StateMachine::State m_targetState;
    00349 };
    00350
    00351 #endif // GAUDIKERNEL_ALGTOOL_H