| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# AlgTool.h

Go to the documentation of this file.

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

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines