00001
00002 #ifndef GAUDIKERNEL_ALGORITHM_H
00003 #define GAUDIKERNEL_ALGORITHM_H
00004
00005
00006 #include "GaudiKernel/IProperty.h"
00007 #include "GaudiKernel/IAlgorithm.h"
00008 #include "GaudiKernel/IService.h"
00009 #include "GaudiKernel/PropertyMgr.h"
00010 #include <string>
00011 #include <vector>
00012
00013
00014 class ISvcLocator;
00015 class IMessageSvc;
00016 class IDataProviderSvc;
00017 class IHistogramSvc;
00018 class IConversionSvc;
00019 class INTupleSvc;
00020 class IChronoStatSvc;
00021 class IRndmGenSvc;
00022 class IAuditorSvc;
00023 class Property;
00024
00046 class Algorithm : virtual public IAlgorithm,
00047 virtual public IProperty {
00048 public:
00049
00053 Algorithm( const std::string& name, ISvcLocator *svcloc );
00055 virtual ~Algorithm();
00056
00061 virtual StatusCode sysInitialize();
00062
00068 virtual StatusCode sysExecute();
00069
00070
00073 virtual StatusCode sysFinalize();
00074
00080 virtual const std::string& name() const;
00081
00083 virtual bool isExecuted( ) const;
00084
00086 virtual StatusCode setExecuted( bool state );
00087
00089 virtual StatusCode resetExecuted( );
00090
00092 virtual StatusCode beginRun();
00094 virtual StatusCode endRun();
00095
00097 virtual bool isEnabled( ) const;
00098
00100 virtual bool filterPassed( ) const;
00101
00103 virtual StatusCode setFilterPassed( bool state );
00104
00105
00106
00109 template <class T>
00110 StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const {
00111 IService* theSvc;
00112 StatusCode sc = serviceLocator()->getService( name, theSvc, createIf );
00113 if ( sc.isSuccess() ) {
00114 return theSvc->queryInterface(T::interfaceID(), (void**)&svc);
00115 }
00116 svc = 0;
00117 return sc;
00118 }
00119
00121 void setOutputLevel( int level );
00122
00126 IAuditorSvc* auditorSvc() const;
00127
00129 IChronoStatSvc* chronoSvc() const;
00131 IChronoStatSvc* chronoStatService() const;
00132
00136 IDataProviderSvc* detSvc() const;
00138 IDataProviderSvc* detDataService() const;
00139
00143 IConversionSvc* detCnvSvc() const;
00145 IConversionSvc* detDataCnvService() const;
00146
00150 IDataProviderSvc* eventSvc() const;
00152 IDataProviderSvc* eventDataService() const;
00153
00157 IConversionSvc* eventCnvSvc() const;
00159 IConversionSvc* eventDataCnvService() const;
00160
00164 IHistogramSvc* histoSvc() const;
00166 IHistogramSvc* histogramDataService() const;
00167
00171 IMessageSvc* msgSvc() const;
00173 IMessageSvc* messageService() const;
00174
00178 INTupleSvc* ntupleSvc() const;
00180 INTupleSvc* ntupleService() const;
00181
00183 IRndmGenSvc* randSvc() const;
00184
00189 ISvcLocator* serviceLocator() const;
00190
00201 StatusCode createSubAlgorithm( const std::string& type,
00202 const std::string& name, Algorithm*& pSubAlg );
00203
00205 std::vector<Algorithm*>* subAlgorithms() const;
00206
00208 virtual StatusCode setProperty(const Property& p);
00210 virtual StatusCode setProperty( std::istream& s );
00212 virtual StatusCode setProperty( const std::string& n, const std::string& v);
00214 virtual StatusCode getProperty(Property* p) const;
00216 virtual const Property& getProperty( const std::string& name) const;
00218 virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
00220 virtual const std::vector<Property*>& getProperties( ) const;
00221
00227 StatusCode setProperties();
00228
00230 template <class T>
00231 StatusCode declareProperty( const std::string& name, T& property ) const {
00232 m_propertyMgr->declareProperty(name, property);
00233 return StatusCode::SUCCESS;
00234 }
00236 StatusCode declareRemoteProperty( const std::string& name, IProperty* rsvc,
00237 const std::string& rname = "" ) const {
00238 m_propertyMgr->declareRemoteProperty(name, rsvc, rname);
00239 return StatusCode::SUCCESS;
00240 }
00241
00242
00244 unsigned long addRef();
00246 unsigned long release();
00248 StatusCode queryInterface(const IID& riid, void**);
00249
00250 protected:
00252 bool isInitialized( ) const;
00253
00255 void setInitialized( );
00256
00258 bool isFinalized( ) const;
00259
00261 void setFinalized( );
00262
00263 private:
00264
00265 long m_refCount;
00266 std::string m_name;
00267 std::vector<Algorithm *>* m_subAlgms;
00268
00269 mutable IMessageSvc* m_MS;
00270 mutable IDataProviderSvc* m_EDS;
00271 mutable IConversionSvc* m_ECS;
00272 mutable IDataProviderSvc* m_DDS;
00273 mutable IConversionSvc* m_DCS;
00274 mutable IHistogramSvc* m_HDS;
00275 mutable INTupleSvc* m_NTS;
00276 mutable IChronoStatSvc* m_CSS;
00277 mutable IRndmGenSvc* m_RGS;
00278 mutable IAuditorSvc* m_pAuditorSvc;
00279 ISvcLocator* m_pSvcLocator;
00280 PropertyMgr* m_propertyMgr;
00281 int m_outputLevel;
00282 int m_errorMax;
00283 int m_errorCount;
00284 bool m_auditorInitialize;
00285 bool m_auditorExecute;
00286 bool m_auditorFinalize;
00287 bool m_filterPassed;
00288 bool m_isEnabled;
00289 bool m_isExecuted;
00290 bool m_isInitialized;
00291 bool m_isFinalized;
00292
00294 Algorithm(const Algorithm& a);
00295
00297 Algorithm& operator=(const Algorithm& rhs);
00298 };
00299
00300 #endif //GAUDIKERNEL_ALGORITHM_H