00001
00002
00003 #define GAUDIALG_GAUDIALGORITHM_CPP 1
00004
00005
00006
00007
00008
00009 #include "GaudiKernel/IAlgContextSvc.h"
00010 #include "GaudiKernel/DataObject.h"
00011
00012
00013
00014 #include "GaudiAlg/GaudiAlgorithm.h"
00015
00027
00028
00029
00030 #include "GaudiCommon.icpp"
00031
00032 template class GaudiCommon<Algorithm>;
00033
00034
00035
00036 GaudiAlgorithm::GaudiAlgorithm ( const std::string& name ,
00037 ISvcLocator* pSvcLocator )
00038 : GaudiCommon<Algorithm> ( name , pSvcLocator )
00039
00040 , m_evtColSvc ( 0 )
00041 , m_contextSvc ( 0 )
00042 , m_contextSvcName ( "AlgContextSvc" )
00043
00044 , m_registerContext ( true )
00045 {
00046 m_vetoObjs.clear();
00047 m_requireObjs.clear();
00048
00049 declareProperty
00050 ( "ContextService" ,
00051 m_contextSvcName ,
00052 "The name of Algorithm Context Service" ) ;
00053 declareProperty
00054 ( "RegisterForContextService" ,
00055 m_registerContext ,
00056 "The flag to enforce the registration for Algorithm Context Service") ;
00057 declareProperty( "VetoObjects", m_vetoObjs,
00058 "Skip execute if one or more of these TES objects exists" );
00059 declareProperty( "RequireObjects", m_requireObjs,
00060 "Execute only if one or more of these TES objects exists" );
00061 }
00062
00063
00064
00065 GaudiAlgorithm::~GaudiAlgorithm() { }
00066
00067
00068
00069 StatusCode GaudiAlgorithm::initialize()
00070 {
00071
00072 const StatusCode sc = GaudiCommon<Algorithm>::initialize() ;
00073 if ( sc.isFailure() ) { return sc; }
00074
00075
00076
00077
00078 return sc;
00079 }
00080
00081
00082
00083 StatusCode GaudiAlgorithm::finalize()
00084 {
00085 if ( msgLevel(MSG::DEBUG) )
00086 debug() << "Finalize base class GaudiAlgorithm" << endreq;
00087
00088
00089 m_evtColSvc = 0 ;
00090
00091
00092 return GaudiCommon<Algorithm>::finalize() ;
00093 }
00094
00095
00096
00097 StatusCode GaudiAlgorithm::execute()
00098 {
00099 return Error ( "Default GaudiAlgorithm execute method called !!" ) ;
00100 }
00101
00102
00103
00104 INTupleSvc* GaudiAlgorithm::evtColSvc() const
00105 {
00106 if ( 0 == m_evtColSvc )
00107 {
00108 m_evtColSvc = svc< INTupleSvc > ( "EvtTupleSvc" , true ) ;
00109 }
00110 return m_evtColSvc ;
00111 }
00112
00113
00114
00115 IAlgContextSvc* GaudiAlgorithm::contextSvc() const
00116 {
00117 if ( 0 == m_contextSvc )
00118 {
00119 m_contextSvc = svc< IAlgContextSvc > ( m_contextSvcName , true ) ;
00120 }
00121 return m_contextSvc ;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131 StatusCode GaudiAlgorithm::sysExecute ()
00132 {
00133 IAlgContextSvc* ctx = 0 ;
00134 if ( registerContext() ) { ctx = contextSvc() ; }
00135
00136 Gaudi::Utils::AlgContext cnt ( ctx , this ) ;
00137
00138
00139 for( std::vector<std::string>::iterator it = m_vetoObjs.begin();
00140 it != m_vetoObjs.end(); it++ ) {
00141 if( exist<DataObject>(*it) ) {
00142 debug() << *it << " found, skipping event " << endmsg;
00143 return StatusCode::SUCCESS;
00144 }
00145 }
00146
00147
00148 bool doIt = m_requireObjs.empty() ? true : false;
00149
00150
00151 for( std::vector<std::string>::iterator it = m_requireObjs.begin();
00152 it != m_requireObjs.end(); it++ ) {
00153 if( exist<DataObject>(*it) ) {
00154 doIt = true;
00155 break;
00156 }
00157 }
00158
00159 if( doIt )
00160
00161 return Algorithm::sysExecute() ;
00162 else
00163 return StatusCode::SUCCESS;
00164 }
00165
00166
00167
00168
00169
00170
00171
00172
00173