00001
00002
00003 #include "ESController/SC.h"
00004 #include "ESController/error.h"
00005 #include "EFServices/IEFEventLoopMgr.h"
00006 #include "HltTools/PathResolver.h"
00007
00008
00009 #include <stdint.h>
00010 #include <cmath>
00011 #include <cstdio>
00012 #include <string>
00013
00014
00015
00016
00017
00018
00019
00020 #include "GaudiKernel/SmartIF.h"
00021 #include "GaudiKernel/Bootstrap.h"
00022 #include "GaudiKernel/IAppMgrUI.h"
00023 #include "GaudiKernel/ISvcLocator.h"
00024 #include "GaudiKernel/IProperty.h"
00025 #include "GaudiKernel/Property.h"
00026 #include "GaudiKernel/IService.h"
00027 #include "GaudiKernel/IMessageSvc.h"
00028 #include "GaudiKernel/IClassManager.h"
00029
00030
00031
00032 #include <list>
00033
00034 efpsc::SC::SC () :
00035 m_eventLoopMgr(0),
00036 m_config(0),
00037 m_pesaAppMgr(0),
00038 m_isCreated(false),
00039 m_outLev(5),
00040 m_nameEventLoopMgr("EFEventLoopMgr")
00041 {
00042 ::setenv("SCOutputLevel","3",1);
00043 char* ss=::getenv("SCOutputLevel");
00044
00045
00046
00047
00048
00049
00050
00051 }
00052
00053 efpsc::SC::~SC ()
00054 {
00055
00056 m_pesaAppMgr->release() ;
00057 }
00058
00059 bool efpsc::SC::configure (const std::string& config)
00060 {
00061 static bool first_call_configure = true;
00062 if(first_call_configure){
00063 first_call_configure = false;
00064 }
00065 else{
00066 return true;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"SC configuration started."<<std::endl;
00076 m_config = new efpsc::Config(config);
00077
00078
00079
00080
00081 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Create Pesa Application Manager:"
00082 <<m_isCreated<<std::endl;
00083 if(!m_isCreated){
00084 if ((m_config->dllName().size() != 0) && (m_config->factoryName().size() != 0)) {
00085 m_pesaAppMgr = Gaudi::createApplicationMgr(m_config->dllName(),m_config->factoryName());
00086 if(m_outLev<=3)std::cout<<"Gaudi::createApplicationMgr(m_config->dllName(),m_config->factoryName())"
00087 <<std::endl;
00088 } else {
00089 m_pesaAppMgr = Gaudi::createApplicationMgr();
00090 if(m_outLev<=3)std::cout<<"Gaudi::createApplicationMgr()"<<std::endl;
00091 }
00092 }
00093
00094
00095
00096
00097 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Configure Pesa Property Manager"<<std::endl;
00098 StatusCode sc ;
00099 SmartIF<IProperty> propMgr ( m_pesaAppMgr );
00100 SmartIF<IAppMgrUI> appMgr ( m_pesaAppMgr );
00101 if( !appMgr.isValid() || !propMgr.isValid() ) {
00102
00103
00104 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"While creating the ApplicationMgr"<<std::endl;
00105 return false;
00106 }
00107
00108
00109 std::string opts = "jobOptions.txt";
00110 ::setenv("efJobPath","",1);
00111 if (m_config->jobOptionsPath().size() != 0) {
00112 opts = m_config->jobOptionsPath() ;
00113 if (opts.rfind("/") < opts.size()) {
00114 ::setenv("efJobPath",opts.substr(0,opts.rfind("/")).c_str(),1);
00115 }
00116 }
00117
00118
00119 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Pesa JobOptions file is = " << opts<<std::endl
00120 <<" "<<"---> Pesa JobOptions path = "
00121 << ::getenv("efJobPath")<<std::endl;
00122 propMgr->setProperty( "JobOptionsPath", opts );
00123
00124 propMgr->setProperty( "EventLoop",m_nameEventLoopMgr );
00125
00126
00127
00128
00129 if (m_config->messageSvcType().size() != 0) {
00130 propMgr->setProperty( "MessageSvcType", m_config->messageSvcType());
00131 }
00132
00133
00134 if (m_config->evtSel().size() != 0) {
00135 propMgr->setProperty( "EvtSel", m_config->evtSel());
00136 } else {
00137 propMgr->setProperty( "EvtSel", "NONE" );
00138 }
00139
00140
00141
00142 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"finish property set--->start configure"<<std::endl;
00143 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Configuring ApplicationMgr: "
00144 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
00145
00146 if( opts.substr( opts.length() - 3, 3 ) == ".py" ) {
00147
00148
00149
00150 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "
00151 <<"Error: Don't support python config files"<<std::endl;
00152 return false;
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192 } else {
00193
00194
00195
00196 sc = appMgr->configure();
00197 if( sc.isFailure() ) {
00198
00199
00200 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"While configuring the ApplicationMgr"<<std::endl;
00201 return false;
00202 }
00203 }
00204
00205
00206 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Configuring ApplicationMgr: "
00207 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
00208
00209 sc = appMgr->initialize();
00210
00211
00212
00213 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Initialize ApplicationMgr : "
00214 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
00215 if( sc.isFailure() ) {
00216 EFPSC_ERROR("efpsc::SC::configure", "While intializing the ApplicationMgr");
00217 return false;
00218 }
00219
00220
00221 std::string value ;
00222
00223 sc = propMgr->getProperty( "EventLoop", value );
00224
00225 if( sc.isFailure() ) {
00226
00227 if(m_outLev<=4) std::cout<<"efpsc::SC::configure "<<"While retrieving Property EventLoop "<<std::endl;
00228 } else {
00229 m_nameEventLoopMgr.assign(value, value.find_first_of("\"")+1,
00230 value.find_last_of("\"")-value.find_first_of("\"")-1) ;
00231 }
00232
00233 SmartIF<ISvcLocator> svcLoc( m_pesaAppMgr );
00234 if (svcLoc.isValid()) {
00235
00236 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Name for EventLoopManager:"
00237 <<m_nameEventLoopMgr<<std::endl;
00238 StatusCode sc ;
00239 IEventProcessor* processingMgr = 0 ;
00240
00241 sc = svcLoc->service( m_nameEventLoopMgr , processingMgr);
00242 m_eventLoopMgr=processingMgr;
00243
00244 if( !sc.isSuccess() ) {
00245
00246 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"Error Retrieving Processing manager!"<<std::endl;
00247 return false;
00248 }
00249
00250 } else {
00251
00252 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"Error Retrieving Service Locator!"<<std::endl;
00253 return false;
00254 }
00255
00256 m_isCreated=true;
00257
00258 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"SC configuration finished."<<std::endl;
00259 return true;
00260 }
00261
00262 bool efpsc::SC::unconfigure (void)
00263 {
00264 return true;
00265
00266
00267 if(m_outLev<=3) std::cout<<"efpsc::SC::unconfigure "<<"SC UNconfiguration started."<<std::endl;
00268 StatusCode sc ;
00269 SmartIF<IAppMgrUI> appMgr ( m_pesaAppMgr );
00270 if( !appMgr.isValid() ) {
00271
00272
00273 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "
00274 <<"While unconfiguring the ApplicationMgr, no valid interface"<<std::endl;
00275 return false;
00276 }
00277 SmartIF<ISvcLocator> svcLoc( m_pesaAppMgr );
00278
00279
00280
00281
00282
00283
00284
00285 sc = appMgr->finalize();
00286
00287
00288
00289 if(m_outLev<=2) std::cout<<"efpsc::SC::unconfigure "<<"Finalize ApplicationMgr: "
00290 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
00291 if( sc.isFailure() ) {
00292
00293
00294 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "<<"While finalizing the ApplicationMgr"<<std::endl;
00295 return false;
00296 }
00297
00298
00299 sc = appMgr->terminate();
00300
00301
00302 if(m_outLev<=2) std::cout<<"efpsc::SC::unconfigure "<<"Terminate ApplicationMgr : "
00303 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
00304 if( sc.isFailure() ) {
00305
00306 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "<<"While terminating the ApplicationMgr"<<std::endl;
00307 return false;
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 delete m_config;
00331 m_config = 0;
00332
00333 if(m_outLev<=3) std::cout<<"efpsc::SC::unconfigure "<<"SC UNconfiguration finished."<<std::endl;
00334 return true;
00335 }
00336
00337 bool efpsc::SC::prepareForRun(int run_number=0)
00338 {
00339
00340 if(m_eventLoopMgr){
00341 SmartIF<IEFEventLoopMgr> processor_psc( m_eventLoopMgr);
00342 StatusCode sc = processor_psc->prepareForRun(run_number);
00343 std::cout << "=================" << m_eventLoopMgr << std::endl;
00344 if(sc.isSuccess()) return true;
00345 }
00346 return false;
00347 }
00348
00349 bool efpsc::SC::process(const uint32_t *&feStore, const uint32_t *&sdStore,std::string &efDecision_s,std::vector<uint32_t> &efBitPattern)
00350 {
00351
00352
00353
00354
00355 if(m_outLev<=3)std::cout<<"efpsc::SC::process"<<" **************** NEW EVENT ****************"<<std::endl;
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 StatusCode sc ;
00367 if ( 0 != m_eventLoopMgr ) {
00368 SmartIF<IEventProcessor> processor( m_eventLoopMgr);
00369
00370 if ( processor.isValid() ) {
00371 SmartIF<IService> processor_s( m_eventLoopMgr);
00372
00373
00374
00375 sc = processor->executeEvent((void*)feStore);
00376
00377
00378
00379
00380 if(m_outLev<=2)std::cout<<"efpsc::SC::process "<<"after executeEvent(fe)"<<std::endl;
00381 if( sc.isFailure() ) {
00382
00383 if(m_outLev<=4)std::cout<<"efpsc::SC::process "<<"Error for executeEvent in the ApplicationMgr "
00384 << processor_s->name()<<std::endl;
00385 }
00386 else {
00387 SmartIF<IEFEventLoopMgr> processor_psc( m_eventLoopMgr);
00388
00389
00390
00391
00392 efDecision_s = processor_psc->EF_Decision();
00393
00394
00395
00396 if(m_outLev<=3)std::cout<<"efpsc::SC::process "<<"after EF_Decision. EFdecision is: "
00397 <<efDecision_s<<std::endl;
00398 sdStore=(uint32_t*)processor_psc->EF_Fragment_Address();
00399
00400 if(sdStore==NULL){
00401
00402 if(m_outLev<=2)std::cout<<"efpsc::SC::process "
00403 <<"EF_Fragment_Address() returns NULL pointer"<<std::endl;
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424 efBitPattern.resize(4, 0);
00425 if(efDecision_s=="Junk") efBitPattern[0]=1<<0;
00426
00427 else if(efDecision_s=="GJunk") efBitPattern[0]=(1<<1);
00428 else if(efDecision_s=="Beamgas") efBitPattern[0]=1<<2;
00429
00430 else if(efDecision_s=="GBeamgas") efBitPattern[0]=(1<<3);
00431 else if(efDecision_s=="Cosmic") efBitPattern[0]=1<<4;
00432
00433 else if(efDecision_s=="GCosmic") efBitPattern[0]=(1<<5);
00434 else if(efDecision_s=="EBhabha") efBitPattern[0]=1<<6;
00435
00436 else if(efDecision_s=="GEBhabha") efBitPattern[0]=(1<<7);
00437 else if(efDecision_s=="BBhabha") efBitPattern[0]=1<<8;
00438
00439 else if(efDecision_s=="GBBhabha") efBitPattern[0]=(1<<9);
00440 else if(efDecision_s=="Dimuon") efBitPattern[0]=1<<10;
00441
00442 else if(efDecision_s=="GDimuon") efBitPattern[0]=(1<<11);
00443 else if(efDecision_s=="Diphoton") efBitPattern[0]=1<<12;
00444
00445 else if(efDecision_s=="GDiphoton") efBitPattern[0]=(1<<13);
00446 else if(efDecision_s=="Hadron") efBitPattern[0]=1<<14;
00447
00448 else if(efDecision_s=="GHadron") efBitPattern[0]=(1<<15);
00449 else if(efDecision_s=="Twophoton") efBitPattern[0]=1<<16;
00450
00451 else if(efDecision_s=="GTwophoton") efBitPattern[0]=(17);
00452 else if(efDecision_s=="RandomTrg") efBitPattern[0]=1<<31;
00453 else if(efDecision_s=="Error") efBitPattern[0]=1<<30;
00454 else if(efDecision_s=="Other") efBitPattern[0]=1<<29;
00455 else efBitPattern[0]=1<<28;
00456 efBitPattern[1]=processor_psc->EF_Algorithm_Tag();
00457 efBitPattern[2]=processor_psc->EF_Version();
00458 efBitPattern[3]=processor_psc->EF_Total_Energy();
00459
00460 if(m_outLev<=2)std::cout<<"efpsc::SC::process "
00461 <<"**************end of psc process!**************"<<std::endl;
00462 }
00463 }
00464 else {
00465
00466 if(m_outLev<=5)std::cout<<"efpsc::SC::process "
00467 <<"executeEvent ApplicationMgr : no valid event processor "<<std::endl;
00468 return false;
00469 }
00470
00471 }
00472 else {
00473 return false;
00474 }
00475 return true;
00476 }
00477