| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# Algorithm.h

Go to the documentation of this file.

    00001 // $Id: Algorithm.h,v 1.34 2008/06/02 14:20:38 marcocle Exp $
    00002 // ============================================================================
    00003 #ifndef GAUDIKERNEL_ALGORITHM_H
    00004 #define GAUDIKERNEL_ALGORITHM_H
    00005 // ============================================================================
    00006 // Include files
    00007 // ============================================================================
    00008 #include "GaudiKernel/IProperty.h"
    00009 #include "GaudiKernel/IAlgorithm.h"
    00010 #include "GaudiKernel/IService.h"
    00011 #include "GaudiKernel/PropertyMgr.h"
    00012 #include "GaudiKernel/ISvcLocator.h"
    00013 #include "GaudiKernel/IMessageSvc.h"
    00014 #include "GaudiKernel/IStateful.h"
    00015
    00016 #include <string>
    00017 #include <vector>
    00018
    00019 // Extra include files (forward declarations should be sufficient)
    00020 #include "GaudiKernel/IDataProviderSvc.h"
    00021 #include "GaudiKernel/IHistogramSvc.h"
    00022 #include "GaudiKernel/IConversionSvc.h"
    00023 #include "GaudiKernel/INTupleSvc.h"
    00024 #include "GaudiKernel/IChronoStatSvc.h"
    00025 #include "GaudiKernel/IRndmGenSvc.h"
    00026 #include "GaudiKernel/IAuditorSvc.h"
    00027 #include "GaudiKernel/IToolSvc.h"
    00028 #include "GaudiKernel/IMonitorSvc.h"
    00029 #include "GaudiKernel/IExceptionSvc.h"
    00030 #include "GaudiKernel/IAlgContextSvc.h"
    00031 #include "GaudiKernel/Property.h"
    00032
    00033 #ifndef PACKAGE_VERSION
    00034 #define PACKAGE_VERSION "unknown"
    00035 #endif
    00036
    00062 class GAUDI_API Algorithm: public implements3<IAlgorithm, IProperty, IStateful> {
    00063 public:
    00064
    00069   Algorithm( const std::string& name, ISvcLocator *svcloc,
    00070              const std::string& version=PACKAGE_VERSION );
    00072   virtual ~Algorithm();
    00073
    00079   virtual StatusCode sysStart();
    00080
    00086   virtual StatusCode sysInitialize();
    00087
    00088
    00094   virtual StatusCode sysReinitialize();
    00095
    00100   virtual StatusCode sysRestart();
    00101
    00109   virtual StatusCode sysExecute();
    00110
    00114   virtual StatusCode sysStop();
    00115
    00120   virtual StatusCode sysFinalize();
    00121
    00127   virtual StatusCode sysBeginRun( );
    00128
    00134   virtual StatusCode sysEndRun( );
    00135
    00143   virtual const std::string& name() const;
    00144
    00145   virtual const std::string& version() const;
    00146
    00148   virtual StatusCode configure () { return StatusCode::SUCCESS ; }
    00150   virtual StatusCode terminate () { return StatusCode::SUCCESS ; }
    00151
    00153   virtual StatusCode initialize () { return StatusCode::SUCCESS ; }
    00155   virtual StatusCode start () { return StatusCode::SUCCESS ; }
    00157   virtual StatusCode stop () { return StatusCode::SUCCESS ; }
    00159   virtual StatusCode finalize   () { return StatusCode::SUCCESS ; }
    00160
    00162   virtual StatusCode reinitialize ();
    00164   virtual StatusCode restart ();
    00165
    00167   virtual bool isExecuted( ) const;
    00168
    00170   virtual void setExecuted( bool state );
    00171
    00175   virtual void resetExecuted( );
    00176
    00180   virtual StatusCode beginRun();
    00181
    00183   virtual StatusCode endRun();
    00184
    00186   virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
    00187
    00189   virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
    00190
    00192   virtual bool isEnabled( ) const;
    00193
    00195   virtual bool filterPassed( ) const;
    00196
    00198   virtual void setFilterPassed( bool state );
    00199
    00201   template <class T>
    00202   StatusCode service
    00203   ( const std::string& name, T*& psvc, bool createIf = true ) const {
    00204     return service_i(name, createIf, T::interfaceID(), (void**)&psvc);
    00205   }
    00206
    00208   template <class T>
    00209   StatusCode service( const std::string& svcType, const std::string& svcName,
    00210                       T*& psvc) const {
    00211     return service_i(svcType, svcName, T::interfaceID(), (void**)&psvc);
    00212   }
    00213
    00215   SmartIF<IService> service(const std::string& name, const bool createIf = true, const bool quiet = false) const;
    00216
    00218   void setOutputLevel( int level );
    00219
    00223   SmartIF<IAuditorSvc>& auditorSvc() const;
    00224
    00228   SmartIF<IChronoStatSvc>& chronoSvc() const;
    00230   SmartIF<IChronoStatSvc>& chronoStatService() const;
    00231
    00235   SmartIF<IDataProviderSvc>& detSvc() const;
    00236
    00238   SmartIF<IDataProviderSvc>& detDataService() const;
    00239
    00243   SmartIF<IConversionSvc>& detCnvSvc() const;
    00244
    00246   SmartIF<IConversionSvc>& detDataCnvService() const;
    00247
    00251   SmartIF<IDataProviderSvc>& eventSvc() const;
    00253   SmartIF<IDataProviderSvc>& evtSvc  () const { return eventSvc() ; }
    00255   SmartIF<IDataProviderSvc>& eventDataService() const;
    00256
    00260   SmartIF<IConversionSvc>&   eventCnvSvc() const;
    00262   SmartIF<IConversionSvc>&   eventDataCnvService() const;
    00263
    00267   SmartIF<IHistogramSvc>& histoSvc() const;
    00269   SmartIF<IHistogramSvc>& histogramDataService() const;
    00270
    00275   SmartIF<IMessageSvc>&      msgSvc() const;
    00276
    00278   SmartIF<IMessageSvc>&      messageService() const;
    00279
    00283   SmartIF<INTupleSvc>& ntupleSvc() const;
    00284
    00286   SmartIF<INTupleSvc>& ntupleService() const;
    00287
    00291   // SmartIF<IAIDATupleSvc>& atupleSvc() const;
    00292
    00293
    00297   SmartIF<IRndmGenSvc>& randSvc() const;
    00298
    00300   SmartIF<IToolSvc>& toolSvc() const;
    00301
    00303   SmartIF<IExceptionSvc>& exceptionSvc() const;
    00304
    00306   SmartIF<IAlgContextSvc>& contextSvc() const ;
    00307
    00313   SmartIF<ISvcLocator>& serviceLocator() const;
    00315   SmartIF<ISvcLocator>& svcLoc        () const { return serviceLocator() ; }
    00316
    00318   bool registerContext() const { return m_registerContext ; }
    00319
    00332   StatusCode createSubAlgorithm( const std::string& type,
    00333                                  const std::string& name, Algorithm*& pSubAlg );
    00334
    00336   std::vector<Algorithm*>* subAlgorithms() const;
    00337
    00339   virtual StatusCode setProperty( const Property& p );
    00341   virtual StatusCode setProperty( const std::string& s );
    00343   virtual StatusCode setProperty( const std::string& n, const std::string& v);
    00345   virtual StatusCode getProperty(Property* p) const;
    00347   virtual const Property& getProperty( const std::string& name) const;
    00349   virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
    00351   virtual const std::vector<Property*>& getProperties( ) const;
    00352
    00360   StatusCode setProperties();
    00361   // ==========================================================================
    00391   template <class T>
    00392   Property* declareProperty
    00393   ( const std::string& name              ,
    00394     T&                 property          ,
    00395     const std::string& doc      = "none" ) const
    00396   {
    00397     return m_propertyMgr->declareProperty(name, property, doc);
    00398   }
    00399   // ==========================================================================
    00401   Property* declareRemoteProperty
    00402   ( const std::string& name       ,
    00403     IProperty*         rsvc       ,
    00404     const std::string& rname = "" ) const
    00405   {
    00406     return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname );
    00407   }
    00408   // ==========================================================================
    00418   inline SmartIF<IMonitorSvc>& monitorSvc() const
    00419   {
    00420     // If not already located try to locate it without forcing a creation
    00421     if ( !m_pMonitorSvc.isValid() ){
    00422       m_pMonitorSvc = service(m_monitorSvcName, false, true); // do not create and be quiet
    00423     }
    00424     return m_pMonitorSvc;
    00425   }
    00426
    00432   template <class T>
    00433   void declareInfo( const std::string& name,
    00434                     const T& var,
    00435                     const std::string& desc ) const
    00436   {
    00437     IMonitorSvc* mS = monitorSvc().get();
    00438     if ( mS ) mS->declareInfo(name, var, desc, this);
    00439   }
    00440
    00448   void declareInfo( const std::string& name,
    00449                     const std::string& format,
    00450                     const void* var,
    00451                     int size,
    00452                     const std::string& desc ) const
    00453   {
    00454     IMonitorSvc* mS = monitorSvc().get();
    00455     if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
    00456   }
    00457
    00458   // ==========================================================================
    00459 public:
    00460   // ==========================================================================
    00502   template <class TYPE>
    00503   StatusCode setProperty
    00504   ( const std::string& name  ,
    00505     const TYPE&        value )
    00506   { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
    00507   // ==========================================================================
    00508 protected:
    00509
    00511   bool isInitialized( ) const { return Gaudi::StateMachine::INITIALIZED == m_state; }
    00512
    00514   bool isFinalized( ) const { return Gaudi::StateMachine::CONFIGURED == m_state; }
    00515
    00517   int  outputLevel() const { return (int)m_outputLevel ; }
    00518
    00520   IntegerProperty & outputLevelProperty() { return m_outputLevel; }
    00521
    00523   void initOutputLevel(Property& prop);
    00524
    00525
    00526 private:
    00527
    00528   std::string m_name;
    00529   std::string m_version;
    00530   std::vector<Algorithm *>* m_subAlgms;
    00531
    00532   mutable SmartIF<IMessageSvc>      m_MS;
    00533   mutable SmartIF<IDataProviderSvc> m_EDS;
    00534   mutable SmartIF<IConversionSvc>   m_ECS;
    00535   mutable SmartIF<IDataProviderSvc> m_DDS;
    00536   mutable SmartIF<IConversionSvc>   m_DCS;
    00537   mutable SmartIF<IHistogramSvc>    m_HDS;
    00538   mutable SmartIF<INTupleSvc>       m_NTS;
    00539   //  mutable SmartIF<IAIDATupleSvc>    m_ATS;      ///< AIDA tuple service
    00540   mutable SmartIF<IChronoStatSvc>   m_CSS;
    00541   mutable SmartIF<IRndmGenSvc>      m_RGS;
    00542   mutable SmartIF<IExceptionSvc>    m_EXS;
    00543   mutable SmartIF<IAuditorSvc>      m_pAuditorSvc;
    00544   mutable SmartIF<IToolSvc>         m_ptoolSvc;
    00545   mutable SmartIF<IMonitorSvc>      m_pMonitorSvc;
    00546   mutable SmartIF<IAlgContextSvc>   m_contextSvc ;
    00547   bool  m_registerContext ;
    00548   std::string               m_monitorSvcName;
    00549   SmartIF<ISvcLocator>  m_pSvcLocator;
    00550   PropertyMgr* m_propertyMgr;
    00551   IntegerProperty m_outputLevel;
    00552   int          m_errorMax;
    00553   int          m_errorCount;
    00554   BooleanProperty m_auditInit;
    00555   bool         m_auditorInitialize;
    00556   bool         m_auditorReinitialize;
    00557   bool         m_auditorRestart;
    00558   bool         m_auditorExecute;
    00559   bool         m_auditorFinalize;
    00560   bool         m_auditorBeginRun;
    00561   bool         m_auditorEndRun;
    00562   bool         m_auditorStart;
    00563   bool         m_auditorStop;
    00564   bool         m_filterPassed;
    00565   bool         m_isEnabled;
    00566   bool         m_isExecuted;
    00567   Gaudi::StateMachine::State m_state;
    00568   Gaudi::StateMachine::State m_targetState;
    00569   bool         m_isFinalized;
    00570
    00572   StatusCode service_i(const std::string& svcName,
    00573                        bool createIf,
    00574                        const InterfaceID& iid,
    00575                        void** ppSvc) const;
    00576   StatusCode service_i(const std::string& svcType,
    00577                        const std::string& svcName,
    00578                        const InterfaceID& iid,
    00579                        void** ppSvc) const;
    00580
    00582   Algorithm(const Algorithm& a);
    00583
    00585   Algorithm& operator=(const Algorithm& rhs);
    00586 };
    00587
    00588 #endif //GAUDIKERNEL_ALGORITHM_H