52 MsgStream log(
msgSvc(), name() );
54 Algorithm::initialize();
56 StatusCode sc = service(
"HltConfigSvc", m_HltConfigSvc );
59 log << MSG::FATAL << name() <<
": Unable to locate HltConfigSvc" << endmsg;
62 sc = service(
"HltStoreSvc", m_HltStoreSvc );
65 log << MSG::FATAL << name() <<
": Unable to locate HltStoreSvc" << endmsg;
100 if ( m_EFResult ) m_HltStoreSvc->put(
"EFResult", m_EFResult );
103 log << MSG::ERROR <<
"Unvalid m_EFResult" << endmsg;
104 return StatusCode::FAILURE;
107 m_evtType =
new EFResult( m_tmp_evtType );
108 if ( m_evtType ) m_HltStoreSvc->put(
"EventType", m_evtType );
111 log << MSG::ERROR <<
"Unvalid m_evtType" << endmsg;
112 return StatusCode::FAILURE;
114#ifdef TIME_MEASUREMENT
115 sc = service(
"BesTimerSvc", m_timersvc );
116 if ( sc.isFailure() )
118 log << MSG::WARNING << name() <<
": Unable to locate BesTimer Service" << endmsg;
119 return StatusCode::FAILURE;
121 m_timer[0] = m_timersvc->addItem(
"Step Handler Time" );
122 m_timer[1] = m_timersvc->addItem(
"1stStep exec Time" );
123 m_timer[2] = m_timersvc->addItem(
"1stStep deci Time" );
124 m_timer[3] = m_timersvc->addItem(
"2ndStep exec Time" );
125 m_timer[4] = m_timersvc->addItem(
"2ndStep deci Time" );
127 NTuplePtr nt(
ntupleSvc(),
"FILE444/nt" );
131 m_tuple->addItem(
"total", g_StepHandlerTime );
132 m_tuple->addItem(
"mdc", g_1stStepExecTime );
133 m_tuple->addItem(
"mdcd", g_1stStepDeciTime );
134 m_tuple->addItem(
"emc", g_2ndStepExecTime );
135 m_tuple->addItem(
"emcd", g_2ndStepDeciTime );
139 m_tuple =
ntupleSvc()->book(
"FILE444/nt", CLID_ColumnWiseTuple,
"StepCnt" );
142 m_tuple->addItem(
"total", g_StepHandlerTime );
143 m_tuple->addItem(
"mdc", g_1stStepExecTime );
144 m_tuple->addItem(
"mdcd", g_1stStepDeciTime );
145 m_tuple->addItem(
"emc", g_2ndStepExecTime );
146 m_tuple->addItem(
"emcd", g_2ndStepDeciTime );
150 log << MSG::ERROR <<
"Cannot book N-tuple:" << long( m_tuple ) << endmsg;
151 return StatusCode::FAILURE;
157 log << MSG::INFO <<
"Initialization " << name() <<
" completed successfully" << endmsg;
158 return StatusCode::SUCCESS;
170 MsgStream log(
msgSvc(), name() );
172 Algorithm::beginRun();
177 StatusCode sc = createSubAlgorithm(
"StepSequencer",
"StepSequencer", p_seqAlg );
178 if ( sc.isFailure() )
180 log << MSG::FATAL <<
"Unable to create StepSequencer SubAlgorithm " << endmsg;
186 log << MSG::DEBUG <<
"created SubAlgorithm StepSequencer/StepSequencer" << endmsg;
189 sc = createSubAlgorithm(
"StepDecision",
"StepDecision", p_decAlg );
190 if ( sc.isFailure() )
192 log << MSG::FATAL <<
"Unable to create StepDecision SubAlgorithm " << endmsg;
198 log << MSG::DEBUG <<
"created SubAlgorithm StepDecision/StepDecision" << endmsg;
201 const std::vector<std::pair<Signature*, Sequence*>>& m_TableVector =
202 m_HltConfigSvc->retrieve();
203 std::vector<std::pair<Signature*, Sequence*>>::const_iterator It;
205 for ( It = m_TableVector.begin(); It != m_TableVector.end(); ++It )
207 sequencerAlg->initSequencer( It->second );
208 decisionAlg->initDecision( It->first );
209 m_stepIdList.push_back( It->second->getSeqID() );
212 log << MSG::DEBUG <<
"finish initializing sub-algorithms" << endmsg;
213 return StatusCode::SUCCESS;
220 MsgStream log(
msgSvc(), name() );
221 log << MSG::DEBUG <<
"*** Executing StepHandler *** " << FSMState() << endmsg;
225#ifdef TIME_MEASUREMENT
235 log << MSG::DEBUG <<
"point: " << m_EFResult <<
" " << m_evtType <<
" " << sequencerAlg
239 if ( !sequencerAlg )
return StatusCode::FAILURE;
240 sequencerAlg->reset();
242 std::string answer, result;
243 std::string::size_type separator;
245 std::vector<std::string>::const_iterator
id = m_stepIdList.begin();
247 while (
id != m_stepIdList.end() )
249 log << MSG::DEBUG <<
"In step " << ( *id ) << endmsg;
251 StepSeq = sequencerAlg->execSequencer( *
id );
254 log << MSG::DEBUG <<
" Step Sequencer failed" << endmsg;
259 log << MSG::DEBUG <<
"+++++++++++++++++++++++++++++" << endmsg;
261 StepDec = decisionAlg->execDecision( *
id );
262 std::string midAnswer = decisionAlg->getContinue();
263 if ( midAnswer !=
"" ) m_evtType->setMidAnswer( midAnswer );
266 if ( StepDec > 0 ) m_EFResult->push_back( StepDec );
270 m_EFResult->push_back( 0 );
274 answer = decisionAlg->getBehaviour();
275 log << MSG::DEBUG <<
" Matched Criteria, Behaviour = " << answer << endmsg;
277 separator = answer.find(
'_' );
278 if ( separator == std::string::npos )
280 log << MSG::ERROR <<
" Unknown decision result: " << answer << endmsg;
281 return StatusCode::FAILURE;
283 std::string perform = answer.substr( 0, separator );
288 if ( perform ==
"reject" )
293 else if ( perform ==
"accept" )
298 else if ( perform ==
"jump" )
300 std::string nextId = answer.substr( separator + 1 );
303 }
while ( (
id != m_stepIdList.end() ) && ( ( *
id ) != nextId ) );
304 if (
id == m_stepIdList.end() )
306 log << MSG::ERROR <<
" Unknown jump target: " << nextId << endmsg;
307 return StatusCode::FAILURE;
312 log << MSG::ERROR <<
" Unknown decision result: " << answer << endmsg;
313 return StatusCode::FAILURE;
320 log << MSG::DEBUG <<
"==============" << m_evtType->getAnswerIndex() << endmsg;
322 if ( result ==
"Accepted" )
324 std::string evtMark = answer.substr( separator + 1 );
325 log << MSG::DEBUG <<
" Event is Accepted as " << evtMark << endmsg;
326 m_evtType->setAnswer( evtMark );
328 else if ( result ==
"Rejected" )
333 std::string evtMark =
"Beamgas";
334 m_evtType->setAnswer( evtMark );
335 log << MSG::DEBUG <<
" Event is Rejected" << endmsg;
339 log << MSG::WARNING <<
" Unknown Behaviour, force to Reject" << endmsg;
342 log << MSG::DEBUG <<
"==============" << m_evtType->getAnswerIndex() << endmsg;
343 m_EFResult->setAnswer( result );
345#ifdef TIME_MEASUREMENT
347 g_StepHandlerTime = m_timer[0]->elapsed();
350 StatusCode status = m_tuple->write();
351 if ( !status.isSuccess() ) { log << MSG::ERROR <<
"Can't fill ntuple!" << endmsg; }
354 return StatusCode::SUCCESS;