Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

StepHandler Class Reference

#include <StepHandler.h>

List of all members.

Public Member Functions

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

Private Attributes

StepDecisiondecisionAlg
StepDecisiondecisionAlg
EFResultm_EFResult
EFResultm_EFResult
EFResultm_evtType
EFResultm_evtType
HltConfigSvcm_HltConfigSvc
HltConfigSvcm_HltConfigSvc
HltStoreSvcm_HltStoreSvc
HltStoreSvcm_HltStoreSvc
std::vector< std::string > m_stepIdList
std::vector< std::string > m_stepIdList
std::vector< std::string > m_tmp_evtType
std::vector< std::string > m_tmp_evtType
StepSequencersequencerAlg
StepSequencersequencerAlg


Constructor & Destructor Documentation

StepHandler::StepHandler const std::string &  name,
ISvcLocator *  pSvcLocator
 

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  ) 
 

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

StepHandler::StepHandler const std::string &  name,
ISvcLocator *  pSvcLocator
 

StepHandler::~StepHandler  ) 
 


Member Function Documentation

StatusCode StepHandler::beginRun  ) 
 

StatusCode StepHandler::beginRun  ) 
 

00161                                 {
00162   MsgStream log( messageService(), name() );
00163 
00164   Algorithm* p_seqAlg;
00165   Algorithm* p_decAlg;
00166  
00167   StatusCode sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg);
00168   if( sc.isFailure() ) {
00169     log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endreq;
00170     return sc;
00171   } else {
00172     sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
00173     log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endreq;
00174   }
00175  
00176   sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg);
00177   if( sc.isFailure() ) {
00178     log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endreq;
00179     return sc;
00180   } else {
00181     decisionAlg = static_cast<StepDecision*>(p_decAlg);
00182     log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endreq;
00183   }
00184  
00185   const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->retrieve();
00186   std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
00187  
00188   for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
00189     sequencerAlg->initSequencer(It->second);
00190     decisionAlg->initDecision(It->first);
00191     m_stepIdList.push_back(It->second->getSeqID());
00192   }
00193 }

StatusCode StepHandler::execute  ) 
 

StatusCode StepHandler::execute  ) 
 

00197                                 {
00198   // MSGStream object to output messages from your algorithm
00199   MsgStream log( messageService(), name() );
00200   log << MSG::DEBUG << "*** Executing StepHandler" << endreq;
00201 
00202   //if(EFBesTimer::pBesTimer&&EFBesTimer::pType==2)EFBesTimer::pBesTimer->start();
00203 
00204 #ifdef TIME_MEASUREMENT   
00205   m_timer[0]->start();
00206   m_timer[1]->start();
00207   m_timer[2]->start();
00208   m_timer[3]->start();
00209   m_timer[4]->start();
00210 #endif
00211 
00212   bool StepSeq = true;
00213   int  StepDec = -999;
00214   m_EFResult->reset();
00215   m_evtType->reset();
00216   sequencerAlg->reset();
00217 
00218   std::string answer, result;
00219   std::string::size_type separator;
00220 
00221   std::vector<std::string>::const_iterator id = m_stepIdList.begin();
00222 
00223   while (id != m_stepIdList.end()) {
00224     log << MSG::DEBUG << "In step " << (*id) << endreq;
00225 
00226     StepSeq = sequencerAlg->execSequencer(*id);
00227     if (!StepSeq) {
00228       log << MSG::DEBUG << " Step Sequencer failed" << endreq;
00229       id++;
00230       continue;
00231     } 
00232  
00233     log << MSG::DEBUG << "+++++++++++++++++++++++++++++" << endreq;
00234 
00235     StepDec = decisionAlg->execDecision(*id);
00236     std::string midAnswer = decisionAlg->getContinue();
00237     if (midAnswer!="") m_evtType->setMidAnswer(midAnswer);
00238     //cout <<midAnswer<< endl;
00239 
00240     if (StepDec>0)    m_EFResult->push_back(StepDec);
00241     else {
00242       //log << MSG::DEBUG << " Execute next step" << endreq;
00243       m_EFResult->push_back(0);
00244       id++;
00245       continue;
00246     }
00247     answer = decisionAlg->getBehaviour();
00248     log << MSG::DEBUG << " Matched Criteria, Behaviour = " << answer << endreq;
00249     
00250     separator = answer.find('_');
00251     if (separator == std::string::npos) {
00252       log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
00253       return StatusCode::FAILURE;
00254     }
00255     std::string perform = answer.substr(0, separator);
00256 
00257     //std::string midAnswer = decisionAlg->getContinue();
00258     //if(midAnswer!="") m_evtType->setMidAnswer(midAnswer);
00259     //cout <<answer<<"  "<<midAnswer<< endl;
00260     if (perform == "reject") {
00261       result = "Rejected";
00262       break;
00263     }
00264     else if (perform == "accept") {
00265       result = "Accepted";
00266       break;
00267     }
00268     else if (perform == "jump") {
00269       std::string nextId = answer.substr(separator+1);
00270       do {
00271         ++id;
00272       } while ((id != m_stepIdList.end()) && ((*id) != nextId));
00273       if (id == m_stepIdList.end()) {
00274         log << MSG::ERROR << " Unknown jump target: "<< nextId << endreq;
00275         return StatusCode::FAILURE;
00276       }
00277     }
00278     else {
00279       log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
00280       return StatusCode::FAILURE;
00281     }
00282     //std::string evtMark = tmp.substr(tmp.find('_')+1);
00283     //if(evtMark!="") m_evtType->setMidAnswer(evtMark);
00284     //cout <<answer<<endl;
00285   }
00286 
00287   log << MSG::DEBUG << "============================="
00288       <<m_evtType->getAnswerIndex()<< endreq;
00289   
00290   if (result == "Accepted") {
00291     std::string evtMark = answer.substr(separator+1);
00292     log << MSG::DEBUG << " Event is Accepted as " << evtMark << endreq;
00293     m_evtType->setAnswer(evtMark);
00294   }
00295   else if (result == "Rejected") {
00296     // only beam-gas rejected defaultly
00297     // other type event not decided in Event Filter
00298     // by Fu Chengdong
00299     std::string evtMark = "Beamgas";
00300     m_evtType->setAnswer(evtMark);
00301     log << MSG::DEBUG << " Event is Rejected" << endreq;
00302   }
00303   else {
00304     log << MSG::WARNING << " Unknown Behaviour, force to Reject" << endreq;
00305     result = "Rejected";
00306   }
00307   log << MSG::DEBUG << "============================="
00308       <<m_evtType->getAnswerIndex()<< endreq;
00309   m_EFResult->setAnswer(result);
00310 
00311 #ifdef TIME_MEASUREMENT   
00312   m_timer[0]->stop();
00313   g_StepHandlerTime=m_timer[0]->elapsed();
00314   if(m_tuple){
00315     StatusCode status = m_tuple->write();
00316     if (!status.isSuccess()) {
00317       log << MSG::ERROR << "Can't fill ntuple!" << endreq;
00318     }
00319   }
00320 #endif
00321   return StatusCode::SUCCESS;
00322 }

StatusCode StepHandler::finalize  ) 
 

StatusCode StepHandler::finalize  ) 
 

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

StatusCode StepHandler::initialize  ) 
 

StatusCode StepHandler::initialize  ) 
 

00050                                    {
00051   // MSGStream object to output messages from your algorithm
00052   MsgStream log( messageService(), name() );
00053 
00054   StatusCode sc = service("HltConfigSvc", m_HltConfigSvc);
00055   if( sc.isFailure()) {
00056     log << MSG::FATAL << name() << ": Unable to locate HltConfigSvc" << endreq;
00057     return sc;
00058   }
00059  
00060   sc = service("HltStoreSvc", m_HltStoreSvc);
00061   if( sc.isFailure()) {
00062     log << MSG::FATAL << name() << ": Unable to locate HltStoreSvc" << endreq;
00063     return sc;
00064   }
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 
00113 #ifdef TIME_MEASUREMENT   
00114   sc = service("BesTimerSvc", m_timersvc);
00115   if (sc.isFailure()) {
00116     log << MSG::WARNING << name() << ": Unable to locate BesTimer Service" << endreq;
00117     return StatusCode::FAILURE;
00118   }
00119   m_timer[0] = m_timersvc->addItem("Step Handler Time");
00120   m_timer[1] = m_timersvc->addItem("1stStep exec Time");
00121   m_timer[2] = m_timersvc->addItem("1stStep deci Time");
00122   m_timer[3] = m_timersvc->addItem("2ndStep exec Time");
00123   m_timer[4] = m_timersvc->addItem("2ndStep deci Time");
00124 
00125   NTuplePtr nt(ntupleSvc(),"FILE444/nt");
00126   if ( nt ) {
00127     m_tuple = nt;
00128     m_tuple->addItem("total", g_StepHandlerTime);
00129     m_tuple->addItem("mdc", g_1stStepExecTime);
00130     m_tuple->addItem("mdcd", g_1stStepDeciTime);
00131     m_tuple->addItem("emc", g_2ndStepExecTime);
00132     m_tuple->addItem("emcd", g_2ndStepDeciTime);
00133   } else {
00134     m_tuple = ntupleSvc()->book("FILE444/nt",CLID_ColumnWiseTuple,"StepCnt");
00135     if (m_tuple) {
00136       m_tuple->addItem("total", g_StepHandlerTime);
00137       m_tuple->addItem("mdc", g_1stStepExecTime);
00138       m_tuple->addItem("mdcd", g_1stStepDeciTime);
00139       m_tuple->addItem("emc", g_2ndStepExecTime);
00140       m_tuple->addItem("emcd", g_2ndStepDeciTime);
00141     } else {
00142       log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple) << endmsg;
00143       return StatusCode::FAILURE;
00144     }
00145   }
00146   round = 0;
00147 #endif
00148 
00149   log << MSG::INFO << "Initialization " << name() << " completed successfully" << endreq;
00150   return StatusCode::SUCCESS;
00151 }


Member Data Documentation

StepDecision* StepHandler::decisionAlg [private]
 

StepDecision* StepHandler::decisionAlg [private]
 

EFResult* StepHandler::m_EFResult [private]
 

EFResult* StepHandler::m_EFResult [private]
 

EFResult* StepHandler::m_evtType [private]
 

EFResult* StepHandler::m_evtType [private]
 

HltConfigSvc* StepHandler::m_HltConfigSvc [private]
 

HltConfigSvc* StepHandler::m_HltConfigSvc [private]
 

HltStoreSvc* StepHandler::m_HltStoreSvc [private]
 

HltStoreSvc* StepHandler::m_HltStoreSvc [private]
 

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

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

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

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

StepSequencer* StepHandler::sequencerAlg [private]
 

StepSequencer* StepHandler::sequencerAlg [private]
 


The documentation for this class was generated from the following files:
Generated on Wed Feb 2 18:49:58 2011 for BOSS6.5.5 by  doxygen 1.3.9.1