/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventFilter/HltProcessor/HltSteering/HltSteering-01-01-05/src/StepHandler.cxx

Go to the documentation of this file.
00001 /********************************************************************
00002 NAME:     StepHandler.cxx
00003 ********************************************************************/
00004 // INCLUDE GAUDI HEADER FILES:      
00005 #include "GaudiKernel/MsgStream.h"
00006 #include "GaudiKernel/Property.h"
00007 #include "GaudiKernel/ISvcLocator.h"
00008 
00009 #include "HltSteering/StepHandler.h"
00010 //#include "HltSteering/StepSequencer.h"
00011 //#include "HltSteering/StepDecision.h"
00012 #include "HltSteerData/Sequence.h"
00013 #include "HltSteerData/Signature.h"
00014 
00015 //#ifdef TIME_MEASUREMENT   //// Timer
00016 //#include "HltDataTypes/EFBesTimer.h"
00017 //#endif
00018 
00019 using HltProcessor::Sequence;
00020 using HltProcessor::Signature;
00021 using namespace HltProcessor;
00023 //  CONSTRUCTOR:
00024 StepHandler::StepHandler(const std::string& name, ISvcLocator* pSvcLocator): 
00025   Algorithm(name, pSvcLocator)
00026 {
00027   std::vector<std::string> resultVec;
00028   resultVec.push_back("Error");
00029   resultVec.push_back("Rejected");
00030   resultVec.push_back("Accepted");
00031   m_EFResult = new EFResult(resultVec);
00032 
00033   declareProperty("EventTypes",  m_tmp_evtType);
00034   //evtTypes.push_back("Unknown");
00035   //evtTypes.push_back("Hadron");
00036   //evtTypes.push_back("Dimuon");
00037   //evtTypes.push_back("DiElectron");
00038   //evtTypes.push_back("DiPhoton");
00039   //m_evtType = new EFResult(m_tmp_evtType);
00040 }
00041 
00042 // DESTRUCTOR:
00043 StepHandler::~StepHandler() {
00044   if (m_EFResult) delete m_EFResult;
00045   //if (m_evtType)  delete m_evtType;
00046 }
00047 
00049 // INITIALIZE METHOD:
00050 StatusCode StepHandler::initialize() {
00051   // MSGStream object to output messages from your algorithm
00052   MsgStream log( messageService(), name() );
00053 
00054   Algorithm::initialize(); 
00055 
00056   StatusCode sc = service("HltConfigSvc", m_HltConfigSvc);
00057   if( sc.isFailure()) {
00058     log << MSG::FATAL << name() << ": Unable to locate HltConfigSvc" << endreq;
00059     return sc;
00060   }
00061   sc = service("HltStoreSvc", m_HltStoreSvc);
00062   if( sc.isFailure()) {
00063     log << MSG::FATAL << name() << ": Unable to locate HltStoreSvc" << endreq;
00064     return sc;
00065   }
00066   //CreateSubAlgorithms; StepSequencer and StepDecision
00067   /*
00068   Algorithm* p_seqAlg;
00069   Algorithm* p_decAlg;
00070 
00071   sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg); 
00072   if( sc.isFailure() ) {
00073     log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endreq;
00074     return sc;
00075   } else {
00076     sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
00077     log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endreq;
00078   }
00079 
00080   sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg); 
00081   if( sc.isFailure() ) {
00082     log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endreq;
00083     return sc;
00084   } else {
00085     decisionAlg = static_cast<StepDecision*>(p_decAlg);
00086     log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endreq;
00087   }
00088 
00089   const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->retrieve();
00090   std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
00091 
00092   for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
00093     sequencerAlg->initSequencer(It->second);
00094     decisionAlg->initDecision(It->first);
00095     m_stepIdList.push_back(It->second->getSeqID());
00096   }
00097   */
00098   if (m_EFResult)
00099     m_HltStoreSvc->put("EFResult", m_EFResult);
00100   else {
00101     log << MSG::ERROR << "Unvalid m_EFResult" << endreq;
00102     return StatusCode::FAILURE;
00103   }
00104 
00105   m_evtType = new EFResult(m_tmp_evtType);
00106   if (m_evtType)
00107     m_HltStoreSvc->put("EventType", m_evtType);
00108   else {
00109     log << MSG::ERROR << "Unvalid m_evtType" << endreq;
00110     return StatusCode::FAILURE;
00111   }
00112 #ifdef TIME_MEASUREMENT   
00113   sc = service("BesTimerSvc", m_timersvc);
00114   if (sc.isFailure()) {
00115     log << MSG::WARNING << name() << ": Unable to locate BesTimer Service" << endreq;
00116     return StatusCode::FAILURE;
00117   }
00118   m_timer[0] = m_timersvc->addItem("Step Handler Time");
00119   m_timer[1] = m_timersvc->addItem("1stStep exec Time");
00120   m_timer[2] = m_timersvc->addItem("1stStep deci Time");
00121   m_timer[3] = m_timersvc->addItem("2ndStep exec Time");
00122   m_timer[4] = m_timersvc->addItem("2ndStep deci Time");
00123 
00124   NTuplePtr nt(ntupleSvc(),"FILE444/nt");
00125   if ( nt ) {
00126     m_tuple = nt;
00127     m_tuple->addItem("total", g_StepHandlerTime);
00128     m_tuple->addItem("mdc", g_1stStepExecTime);
00129     m_tuple->addItem("mdcd", g_1stStepDeciTime);
00130     m_tuple->addItem("emc", g_2ndStepExecTime);
00131     m_tuple->addItem("emcd", g_2ndStepDeciTime);
00132   } else {
00133     m_tuple = ntupleSvc()->book("FILE444/nt",CLID_ColumnWiseTuple,"StepCnt");
00134     if (m_tuple) {
00135       m_tuple->addItem("total", g_StepHandlerTime);
00136       m_tuple->addItem("mdc", g_1stStepExecTime);
00137       m_tuple->addItem("mdcd", g_1stStepDeciTime);
00138       m_tuple->addItem("emc", g_2ndStepExecTime);
00139       m_tuple->addItem("emcd", g_2ndStepDeciTime);
00140     } else {
00141       log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple) << endmsg;
00142       return StatusCode::FAILURE;
00143     }
00144   }
00145   round = 0;
00146 #endif
00147 
00148   log << MSG::INFO << "Initialization " << name() << " completed successfully" << endreq;
00149   return StatusCode::SUCCESS;
00150 }
00151 
00153 // FINALIZE METHOD:
00154   
00155 StatusCode StepHandler::finalize() {
00156   if (m_evtType)  delete m_evtType;
00157   return StatusCode::SUCCESS;
00158 }
00159 
00160 StatusCode StepHandler::beginRun(){
00161   MsgStream log( messageService(), name() );
00162 
00163   Algorithm::beginRun();
00164 
00165   Algorithm* p_seqAlg;
00166   Algorithm* p_decAlg;
00167  
00168   StatusCode sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg);
00169   if( sc.isFailure() ) {
00170     log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endreq;
00171     return sc;
00172   } else {
00173     sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
00174     log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endreq;
00175   }
00176  
00177   sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg);
00178   if( sc.isFailure() ) {
00179     log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endreq;
00180     return sc;
00181   } else {
00182     decisionAlg = static_cast<StepDecision*>(p_decAlg);
00183     log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endreq;
00184   }
00185  
00186   const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->retrieve();
00187   std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
00188  
00189   for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
00190     sequencerAlg->initSequencer(It->second);
00191     decisionAlg->initDecision(It->first);
00192     m_stepIdList.push_back(It->second->getSeqID());
00193   }
00194 
00195   log << MSG::DEBUG << "finish initializing sub-algorithms" << endreq;
00196   return StatusCode::SUCCESS;
00197 }
00198 
00200 // EXECUTE METHOD:
00201 StatusCode StepHandler::execute() {
00202   // MSGStream object to output messages from your algorithm
00203   MsgStream log( messageService(), name() );
00204   log << MSG::DEBUG << "*** Executing StepHandler *** " << FSMState() << endreq;
00205 
00206   //if(EFBesTimer::pBesTimer&&EFBesTimer::pType==2)EFBesTimer::pBesTimer->start();
00207 
00208 #ifdef TIME_MEASUREMENT   
00209   m_timer[0]->start();
00210   m_timer[1]->start();
00211   m_timer[2]->start();
00212   m_timer[3]->start();
00213   m_timer[4]->start();
00214 #endif
00215 
00216   bool StepSeq = true;
00217   int  StepDec = -999;
00218   log << MSG::DEBUG << "point: " << m_EFResult << " " << m_evtType << " " << sequencerAlg << endreq;
00219   m_EFResult->reset();
00220   m_evtType->reset();
00221   if(!sequencerAlg) return StatusCode::FAILURE;
00222   sequencerAlg->reset();
00223 
00224   std::string answer, result;
00225   std::string::size_type separator;
00226 
00227   std::vector<std::string>::const_iterator id = m_stepIdList.begin();
00228 
00229   while (id != m_stepIdList.end()) {
00230     log << MSG::DEBUG << "In step " << (*id) << endreq;
00231 
00232     StepSeq = sequencerAlg->execSequencer(*id);
00233     if (!StepSeq) {
00234       log << MSG::DEBUG << " Step Sequencer failed" << endreq;
00235       id++;
00236       continue;
00237     } 
00238  
00239     log << MSG::DEBUG << "+++++++++++++++++++++++++++++" << endreq;
00240 
00241     StepDec = decisionAlg->execDecision(*id);
00242     std::string midAnswer = decisionAlg->getContinue();
00243     if (midAnswer!="") m_evtType->setMidAnswer(midAnswer);
00244     //cout <<midAnswer<< endl;
00245 
00246     if (StepDec>0)    m_EFResult->push_back(StepDec);
00247     else {
00248       //log << MSG::DEBUG << " Execute next step" << endreq;
00249       m_EFResult->push_back(0);
00250       id++;
00251       continue;
00252     }
00253     answer = decisionAlg->getBehaviour();
00254     log << MSG::DEBUG << " Matched Criteria, Behaviour = " << answer << endreq;
00255     
00256     separator = answer.find('_');
00257     if (separator == std::string::npos) {
00258       log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
00259       return StatusCode::FAILURE;
00260     }
00261     std::string perform = answer.substr(0, separator);
00262 
00263     //std::string midAnswer = decisionAlg->getContinue();
00264     //if(midAnswer!="") m_evtType->setMidAnswer(midAnswer);
00265     //cout <<answer<<"  "<<midAnswer<< endl;
00266     if (perform == "reject") {
00267       result = "Rejected";
00268       break;
00269     }
00270     else if (perform == "accept") {
00271       result = "Accepted";
00272       break;
00273     }
00274     else if (perform == "jump") {
00275       std::string nextId = answer.substr(separator+1);
00276       do {
00277         ++id;
00278       } while ((id != m_stepIdList.end()) && ((*id) != nextId));
00279       if (id == m_stepIdList.end()) {
00280         log << MSG::ERROR << " Unknown jump target: "<< nextId << endreq;
00281         return StatusCode::FAILURE;
00282       }
00283     }
00284     else {
00285       log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
00286       return StatusCode::FAILURE;
00287     }
00288     //std::string evtMark = tmp.substr(tmp.find('_')+1);
00289     //if(evtMark!="") m_evtType->setMidAnswer(evtMark);
00290     //cout <<answer<<endl;
00291   }
00292 
00293   log << MSG::DEBUG << "==============" <<m_evtType->getAnswerIndex()<< endreq;
00294   
00295   if (result == "Accepted") {
00296     std::string evtMark = answer.substr(separator+1);
00297     log << MSG::DEBUG << " Event is Accepted as " << evtMark << endreq;
00298     m_evtType->setAnswer(evtMark);
00299   }
00300   else if (result == "Rejected") {
00301     // only beam-gas rejected defaultly
00302     // other type event not decided in Event Filter
00303     // by Fu Chengdong
00304     std::string evtMark = "Beamgas";
00305     m_evtType->setAnswer(evtMark);
00306     log << MSG::DEBUG << " Event is Rejected" << endreq;
00307   }
00308   else {
00309     log << MSG::WARNING << " Unknown Behaviour, force to Reject" << endreq;
00310     result = "Rejected";
00311   }
00312   log << MSG::DEBUG << "==============" <<m_evtType->getAnswerIndex()<< endreq;
00313   m_EFResult->setAnswer(result);
00314 
00315 #ifdef TIME_MEASUREMENT   
00316   m_timer[0]->stop();
00317   g_StepHandlerTime=m_timer[0]->elapsed();
00318   if(m_tuple){
00319     StatusCode status = m_tuple->write();
00320     if (!status.isSuccess()) {
00321       log << MSG::ERROR << "Can't fill ntuple!" << endreq;
00322     }
00323   }
00324 #endif
00325   return StatusCode::SUCCESS;
00326 }

Generated on Tue Nov 29 23:12:06 2016 for BOSS_7.0.2 by  doxygen 1.4.7