| # Gaudi Framework, version v21r6 |

Home |  | Generated: 11 Nov 2009

# 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/Property.h"
    00031
    00032 #ifndef PACKAGE_VERSION
    00033 #define PACKAGE_VERSION "unknown"
    00034 #endif
    00035
    00061 class GAUDI_API Algorithm: public implements3<IAlgorithm, IProperty, IStateful> {
    00062 public:
    00063
    00068   Algorithm( const std::string& name, ISvcLocator *svcloc,
    00069              const std::string& version=PACKAGE_VERSION );
    00071   virtual ~Algorithm();
    00072
    00078   virtual StatusCode sysStart();
    00079
    00085   virtual StatusCode sysInitialize();
    00086
    00087
    00093   virtual StatusCode sysReinitialize();
    00094
    00099   virtual StatusCode sysRestart();
    00100
    00108   virtual StatusCode sysExecute();
    00109
    00113   virtual StatusCode sysStop();
    00114
    00119   virtual StatusCode sysFinalize();
    00120
    00126   virtual StatusCode sysBeginRun( );
    00127
    00133   virtual StatusCode sysEndRun( );
    00134
    00142   virtual const std::string& name() const;
    00143
    00144   virtual const std::string& version() const;
    00145
    00147   virtual StatusCode configure () { return StatusCode::SUCCESS ; }
    00149   virtual StatusCode terminate () { return StatusCode::SUCCESS ; }
    00150
    00152   virtual StatusCode initialize () { return StatusCode::SUCCESS ; }
    00154   virtual StatusCode start () { return StatusCode::SUCCESS ; }
    00156   virtual StatusCode stop () { return StatusCode::SUCCESS ; }
    00158   virtual StatusCode finalize   () { return StatusCode::SUCCESS ; }
    00159
    00161   virtual StatusCode reinitialize ();
    00163   virtual StatusCode restart ();
    00164
    00166   virtual bool isExecuted( ) const;
    00167
    00169   virtual void setExecuted( bool state );
    00170
    00174   virtual void resetExecuted( );
    00175
    00179   virtual StatusCode beginRun();
    00180
    00182   virtual StatusCode endRun();
    00183
    00185   virtual Gaudi::StateMachine::State FSMState() const { return m_state; }
    00186
    00188   virtual Gaudi::StateMachine::State targetFSMState() const { return m_targetState; }
    00189
    00191   virtual bool isEnabled( ) const;
    00192
    00194   virtual bool filterPassed( ) const;
    00195
    00197   virtual void setFilterPassed( bool state );
    00198
    00200   template <class T>
    00201   StatusCode service
    00202   ( const std::string& name, T*& psvc, bool createIf = true ) const {
    00203     return service_i(name, createIf, T::interfaceID(), (void**)&psvc);
    00204   }
    00205
    00207   template <class T>
    00208   StatusCode service( const std::string& svcType, const std::string& svcName,
    00209                       T*& psvc) const {
    00210     return service_i(svcType, svcName, T::interfaceID(), (void**)&psvc);
    00211   }
    00212
    00214   SmartIF<IService> service(const std::string& name, const bool createIf = true, const bool quiet = false) const;
    00215
    00217   void setOutputLevel( int level );
    00218
    00222   SmartIF<IAuditorSvc>& auditorSvc() const;
    00223
    00227   SmartIF<IChronoStatSvc>& chronoSvc() const;
    00229   SmartIF<IChronoStatSvc>& chronoStatService() const;
    00230
    00234   SmartIF<IDataProviderSvc>& detSvc() const;
    00235
    00237   SmartIF<IDataProviderSvc>& detDataService() const;
    00238
    00242   SmartIF<IConversionSvc>& detCnvSvc() const;
    00243
    00245   SmartIF<IConversionSvc>& detDataCnvService() const;
    00246
    00250   SmartIF<IDataProviderSvc>& eventSvc() const;
    00252   SmartIF<IDataProviderSvc>& evtSvc  () const { return eventSvc() ; }
    00254   SmartIF<IDataProviderSvc>& eventDataService() const;
    00255
    00259   SmartIF<IConversionSvc>&   eventCnvSvc() const;
    00261   SmartIF<IConversionSvc>&   eventDataCnvService() const;
    00262
    00266   SmartIF<IHistogramSvc>& histoSvc() const;
    00268   SmartIF<IHistogramSvc>& histogramDataService() const;
    00269
    00274   SmartIF<IMessageSvc>&      msgSvc() const;
    00275
    00277   SmartIF<IMessageSvc>&      messageService() const;
    00278
    00282   SmartIF<INTupleSvc>& ntupleSvc() const;
    00283
    00285   SmartIF<INTupleSvc>& ntupleService() const;
    00286
    00290   // SmartIF<IAIDATupleSvc>& atupleSvc() const;
    00291
    00292
    00296   SmartIF<IRndmGenSvc>& randSvc() const;
    00297
    00299   SmartIF<IToolSvc>& toolSvc() const;
    00300
    00302   SmartIF<IExceptionSvc>& exceptionSvc() const;
    00303
    00309   SmartIF<ISvcLocator>& serviceLocator() const;
    00311   SmartIF<ISvcLocator>& svcLoc        () const { return serviceLocator() ; }
    00312
    00325   StatusCode createSubAlgorithm( const std::string& type,
    00326                                  const std::string& name, Algorithm*& pSubAlg );
    00327
    00329   std::vector<Algorithm*>* subAlgorithms() const;
    00330
    00332   virtual StatusCode setProperty( const Property& p );
    00334   virtual StatusCode setProperty( const std::string& s );
    00336   virtual StatusCode setProperty( const std::string& n, const std::string& v);
    00338   virtual StatusCode getProperty(Property* p) const;
    00340   virtual const Property& getProperty( const std::string& name) const;
    00342   virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
    00344   virtual const std::vector<Property*>& getProperties( ) const;
    00345
    00353   StatusCode setProperties();
    00354   // ==========================================================================
    00384   template <class T>
    00385   Property* declareProperty
    00386   ( const std::string& name              ,
    00387     T&                 property          ,
    00388     const std::string& doc      = "none" ) const
    00389   {
    00390     return m_propertyMgr->declareProperty(name, property, doc);
    00391   }
    00392   // ==========================================================================
    00394   Property* declareRemoteProperty
    00395   ( const std::string& name       ,
    00396     IProperty*         rsvc       ,
    00397     const std::string& rname = "" ) const
    00398   {
    00399     return m_propertyMgr -> declareRemoteProperty ( name , rsvc , rname );
    00400   }
    00401   // ==========================================================================
    00411   inline SmartIF<IMonitorSvc>& monitorSvc() const
    00412   {
    00413     // If not already located try to locate it without forcing a creation
    00414     if ( !m_pMonitorSvc.isValid() ){
    00415       m_pMonitorSvc = service(m_monitorSvcName, false, true); // do not create and be quiet
    00416     }
    00417     return m_pMonitorSvc;
    00418   }
    00419
    00425   template <class T>
    00426   void declareInfo( const std::string& name,
    00427                     const T& var,
    00428                     const std::string& desc ) const
    00429   {
    00430     IMonitorSvc* mS = monitorSvc().get();
    00431     if ( mS ) mS->declareInfo(name, var, desc, this);
    00432   }
    00433
    00441   void declareInfo( const std::string& name,
    00442                     const std::string& format,
    00443                     const void* var,
    00444                     int size,
    00445                     const std::string& desc ) const
    00446   {
    00447     IMonitorSvc* mS = monitorSvc().get();
    00448     if ( mS ) mS->declareInfo(name, format, var, size, desc, this);
    00449   }
    00450
    00451   // ==========================================================================
    00452 public:
    00453   // ==========================================================================
    00495   template <class TYPE>
    00496   StatusCode setProperty
    00497   ( const std::string& name  ,
    00498     const TYPE&        value )
    00499   { return Gaudi::Utils::setProperty ( m_propertyMgr , name , value ) ; }
    00500   // ==========================================================================
    00501 protected:
    00502
    00504   bool isInitialized( ) const { return Gaudi::StateMachine::INITIALIZED == m_state; }
    00505
    00507   bool isFinalized( ) const { return Gaudi::StateMachine::CONFIGURED == m_state; }
    00508
    00510   int  outputLevel() const { return (int)m_outputLevel ; }
    00511
    00513   IntegerProperty & outputLevelProperty() { return m_outputLevel; }
    00514
    00516   void initOutputLevel(Property& prop);
    00517
    00518
    00519 private:
    00520
    00521   std::string m_name;
    00522   std::string m_version;
    00523   std::vector<Algorithm *>* m_subAlgms;
    00524
    00525   mutable SmartIF<IMessageSvc>      m_MS;
    00526   mutable SmartIF<IDataProviderSvc> m_EDS;
    00527   mutable SmartIF<IConversionSvc>   m_ECS;
    00528   mutable SmartIF<IDataProviderSvc> m_DDS;
    00529   mutable SmartIF<IConversionSvc>   m_DCS;
    00530   mutable SmartIF<IHistogramSvc>    m_HDS;
    00531   mutable SmartIF<INTupleSvc>       m_NTS;
    00532   //  mutable SmartIF<IAIDATupleSvc>    m_ATS;      ///< AIDA tuple service
    00533   mutable SmartIF<IChronoStatSvc>   m_CSS;
    00534   mutable SmartIF<IRndmGenSvc>      m_RGS;
    00535   mutable SmartIF<IExceptionSvc>    m_EXS;
    00536   mutable SmartIF<IAuditorSvc>      m_pAuditorSvc;
    00537   mutable SmartIF<IToolSvc>         m_ptoolSvc;
    00538   mutable SmartIF<IMonitorSvc>      m_pMonitorSvc;
    00539   std::string               m_monitorSvcName;
    00540   SmartIF<ISvcLocator>  m_pSvcLocator;
    00541   PropertyMgr* m_propertyMgr;
    00542   IntegerProperty m_outputLevel;
    00543   int          m_errorMax;
    00544   int          m_errorCount;
    00545   BooleanProperty m_auditInit;
    00546   bool         m_auditorInitialize;
    00547   bool         m_auditorReinitialize;
    00548   bool         m_auditorRestart;
    00549   bool         m_auditorExecute;
    00550   bool         m_auditorFinalize;
    00551   bool         m_auditorBeginRun;
    00552   bool         m_auditorEndRun;
    00553   bool         m_auditorStart;
    00554   bool         m_auditorStop;
    00555   bool         m_filterPassed;
    00556   bool         m_isEnabled;
    00557   bool         m_isExecuted;
    00558   Gaudi::StateMachine::State m_state;
    00559   Gaudi::StateMachine::State m_targetState;
    00560   bool         m_isFinalized;
    00561
    00563   StatusCode service_i(const std::string& svcName,
    00564                        bool createIf,
    00565                        const InterfaceID& iid,
    00566                        void** ppSvc) const;
    00567   StatusCode service_i(const std::string& svcType,
    00568                        const std::string& svcName,
    00569                        const InterfaceID& iid,
    00570                        void** ppSvc) const;
    00571
    00573   Algorithm(const Algorithm& a);
    00574
    00576   Algorithm& operator=(const Algorithm& rhs);
    00577 };
    00578
    00579 #endif //GAUDIKERNEL_ALGORITHM_H