StepHandler Class Reference

#include <StepHandler.h>

List of all members.

Public Member Functions

 StepHandler (const std::string &name, ISvcLocator *pSvcLocator)
 ~StepHandler ()
StatusCode initialize ()
StatusCode finalize ()
StatusCode execute ()
StatusCode beginRun ()

Private Attributes

HltStoreSvcm_HltStoreSvc
HltConfigSvcm_HltConfigSvc
StepSequencersequencerAlg
StepDecisiondecisionAlg
EFResultm_EFResult
EFResultm_evtType
std::vector< std::stringm_stepIdList
std::vector< std::stringm_tmp_evtType


Detailed Description

Definition at line 21 of file StepHandler.h.


Constructor & Destructor Documentation

StepHandler::StepHandler ( const std::string name,
ISvcLocator *  pSvcLocator 
)

Definition at line 24 of file StepHandler.cxx.

References m_EFResult, and m_tmp_evtType.

00024                                                                        : 
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 }

StepHandler::~StepHandler (  ) 

Definition at line 43 of file StepHandler.cxx.

References m_EFResult.

00043                           {
00044   if (m_EFResult) delete m_EFResult;
00045   //if (m_evtType)  delete m_evtType;
00046 }


Member Function Documentation

StatusCode StepHandler::beginRun (  ) 

Definition at line 160 of file StepHandler.cxx.

References boss::Algorithm, Bes_Common::DEBUG, decisionAlg, Bes_Common::FATAL, StepDecision::initDecision(), StepSequencer::initSequencer(), m_HltConfigSvc, m_stepIdList, HltConfigSvc::retrieve(), and sequencerAlg.

00160                                 {
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 }

StatusCode StepHandler::execute (  ) 

Definition at line 201 of file StepHandler.cxx.

References Bes_Common::DEBUG, decisionAlg, calibUtil::ERROR, StepDecision::execDecision(), StepSequencer::execSequencer(), EFResult::getAnswerIndex(), StepDecision::getBehaviour(), StepDecision::getContinue(), m_EFResult, m_evtType, m_stepIdList, RealDBUtil::npos, EFResult::push_back(), StepSequencer::reset(), EFResult::reset(), sequencerAlg, EFResult::setAnswer(), EFResult::setMidAnswer(), deljobs::string, and Bes_Common::WARNING.

00201                                 {
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 }

StatusCode StepHandler::finalize (  ) 

Definition at line 155 of file StepHandler.cxx.

References m_evtType.

00155                                  {
00156   if (m_evtType)  delete m_evtType;
00157   return StatusCode::SUCCESS;
00158 }

StatusCode StepHandler::initialize (  ) 

Definition at line 50 of file StepHandler.cxx.

References calibUtil::ERROR, Bes_Common::FATAL, Bes_Common::INFO, m_EFResult, m_evtType, m_HltConfigSvc, m_HltStoreSvc, m_tmp_evtType, ntupleSvc(), HltStoreSvc::put(), and Bes_Common::WARNING.

00050                                    {
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 }


Member Data Documentation

StepDecision* StepHandler::decisionAlg [private]

Definition at line 38 of file StepHandler.h.

Referenced by beginRun(), and execute().

EFResult* StepHandler::m_EFResult [private]

Definition at line 40 of file StepHandler.h.

Referenced by execute(), initialize(), StepHandler(), and ~StepHandler().

EFResult* StepHandler::m_evtType [private]

Definition at line 41 of file StepHandler.h.

Referenced by execute(), finalize(), and initialize().

HltConfigSvc* StepHandler::m_HltConfigSvc [private]

Definition at line 36 of file StepHandler.h.

Referenced by beginRun(), and initialize().

HltStoreSvc* StepHandler::m_HltStoreSvc [private]

Definition at line 35 of file StepHandler.h.

Referenced by initialize().

std::vector<std::string> StepHandler::m_stepIdList [private]

Definition at line 42 of file StepHandler.h.

Referenced by beginRun(), and execute().

std::vector<std::string> StepHandler::m_tmp_evtType [private]

Definition at line 44 of file StepHandler.h.

Referenced by initialize(), and StepHandler().

StepSequencer* StepHandler::sequencerAlg [private]

Definition at line 37 of file StepHandler.h.

Referenced by beginRun(), and execute().


Generated on Tue Nov 29 23:35:55 2016 for BOSS_7.0.2 by  doxygen 1.4.7