| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

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 AlgTool : public virtual IAlgTool,
00036                 public virtual IProperty,
00037                 public virtual IStateful {
00038   friend class ToolSvc;
00039 public:
00040 
00042   virtual StatusCode queryInterface(const InterfaceID& riid, void** ppvUnknown);
00043 
00045   virtual unsigned long addRef();
00046 
00048   virtual unsigned long release();
00049 
00051   virtual const std::string& name() const;
00052 
00054   virtual const std::string& type() const;
00055 
00057   virtual const IInterface*  parent() const;
00058 
00059   // State machine implementation
00060   virtual StatusCode configure() { return StatusCode::SUCCESS; }
00061   virtual StatusCode initialize();
00062   virtual StatusCode start();
00063   virtual StatusCode stop();
00064   virtual StatusCode finalize();
00065   virtual StatusCode terminate() { return StatusCode::SUCCESS; }
00066   virtual StatusCode reinitialize();
00067   virtual StatusCode restart();
00068   virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
00069   virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
00070   
00072   virtual StatusCode sysInitialize();
00073   
00075   virtual StatusCode sysStart();
00076   
00078   virtual StatusCode sysStop();
00079 
00081   virtual StatusCode sysFinalize();
00082   
00084   virtual StatusCode sysReinitialize();
00085   
00087   virtual StatusCode sysRestart();
00088   
00090   virtual StatusCode setProperty( const Property&    p );
00091   virtual StatusCode setProperty( const std::string& s );
00092   virtual StatusCode setProperty( const std::string& n, const std::string& v);
00093   virtual StatusCode getProperty(Property* p) const;
00094   virtual const Property& getProperty( const std::string& name) const;
00095   virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
00096   virtual const std::vector<Property*>& getProperties( ) const;
00097   
00098   inline PropertyMgr * getPropertyMgr() { return m_propertyMgr; }
00099   
00100 public:
00101   
00142   template <class TYPE>
00143   StatusCode setProperty 
00144   ( const std::string& name  , 
00145     const TYPE&        value ) 
00146   { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
00147   
00148 
00154   AlgTool( const std::string& type,
00155            const std::string& name,
00156            const IInterface* parent);
00157 
00159   ISvcLocator* serviceLocator()  const;
00160 
00162   ISvcLocator* svcLoc()  const { return serviceLocator() ; }
00163 
00165   IMessageSvc* msgSvc() const;
00166 
00168   IToolSvc* toolSvc() const;
00169 
00175   StatusCode setProperties();
00176 
00180   template <class T>
00181   StatusCode service
00182   ( const std::string& name, T*& svc, bool createIf = true ) const {
00183     return service_i(name, createIf, T::interfaceID(), (void**)&svc);
00184   }
00185 
00188   template <class T>
00189   StatusCode service( const std::string& type, const std::string& name, T*& svc) const {
00190     return service_i(type, name, T::interfaceID(), (void**)&svc);
00191   }
00192 
00194   void declInterface( const InterfaceID&, void*);
00195 
00196   template <class I> class declareInterface {
00197   public:
00198     template <class T> declareInterface(T* tool) {
00199       tool->declInterface( I::interfaceID(), (I*)tool);
00200     }
00201   };
00202   // ==========================================================================
00232   template <class T>
00233   Property* declareProperty
00234   ( const std::string& name         , 
00235     T&                 property     ,
00236     const std::string& doc = "none" ) const 
00237   {
00238     return m_propertyMgr -> declareProperty ( name , property , doc ) ;
00239   }
00241   Property* declareRemoteProperty
00242   ( const std::string& name       , 
00243     IProperty*         rsvc       ,
00244     const std::string& rname = "" ) const 
00245   {
00246     return m_propertyMgr-> declareRemoteProperty ( name , rsvc , rname ) ;
00247   }
00248   // ==========================================================================
00250   IAuditorSvc* auditorSvc() const;
00251 
00261   inline IMonitorSvc* monitorSvc() const
00262   {
00263     // If not already located try to locate it without forcing a creation
00264     if ( !m_pMonitorSvc ){
00265       service_i( m_monitorSvcName, false,
00266                  IMonitorSvc::interfaceID(), pp_cast<void>(&m_pMonitorSvc) );
00267     }
00268     return m_pMonitorSvc;
00269   }
00270 
00276   template <class T>
00277   void declareInfo( const std::string& name,
00278                     const T& var,
00279                     const std::string& desc ) const
00280   {
00281     IMonitorSvc* mS = monitorSvc();
00282     if ( mS ) mS->declareInfo(name, var, desc, this);
00283   }
00284 
00292   void declareInfo( const std::string& name,
00293                     const std::string& format,
00294                     const void* var,
00295                     int size,
00296                     const std::string& desc ) const
00297   {
00298     IMonitorSvc* mS = monitorSvc();
00299     if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
00300   }
00301 
00302 protected:
00303 
00305   int           outputLevel () const { return (int)m_outputLevel ; }
00306 
00311   virtual unsigned long refCount() const { return m_refCount; }
00312 
00314   IntegerProperty & outputLevelProperty() { return m_outputLevel; }
00315 
00317   void initOutputLevel(Property& prop);
00318  
00319 
00320 
00321 protected:
00322 
00323   // Standard destructor.
00324   virtual ~AlgTool();
00325 
00326 private:
00327   typedef std::list<std::pair<InterfaceID,void*> >  InterfaceList;
00328   IntegerProperty      m_outputLevel;      
00329   std::string          m_type;             
00330   const std::string    m_name;             
00331   const IInterface*    m_parent;           
00332   unsigned long        m_refCount;         
00333   mutable ISvcLocator* m_svcLocator;       
00334   mutable IMessageSvc* m_messageSvc;       
00335   mutable IToolSvc*    m_ptoolSvc;         
00336   mutable IMonitorSvc* m_pMonitorSvc;      
00337   std::string          m_monitorSvcName;   
00338   PropertyMgr*         m_propertyMgr;      
00339   InterfaceList        m_interfaceList;    
00340   std::string          m_threadID;         
00341 
00343   StatusCode service_i(const std::string& algName,
00344                        bool createIf,
00345                        const InterfaceID& iid,
00346                        void** ppSvc) const;
00347   StatusCode service_i(const std::string& svcType,
00348                        const std::string& svcName,
00349                        const InterfaceID& iid,
00350                        void** ppS) const;
00351 
00352   mutable IAuditorSvc*      m_pAuditorSvc; 
00353 
00354   BooleanProperty m_auditInit;
00355   bool         m_auditorInitialize;
00356   bool         m_auditorStart;     
00357   bool         m_auditorStop;      
00358   bool         m_auditorFinalize;  
00359   bool         m_auditorReinitialize;
00360   bool         m_auditorRestart;     
00361   
00362   Gaudi::StateMachine::State m_state;            
00363   Gaudi::StateMachine::State m_targetState;      
00364 };
00365 
00366 #endif // GAUDIKERNEL_ALGTOOL_H
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:56:57 2011 for GaudiKernel by doxygen 1.4.7