5#include "GaudiKernel/MsgStream.h"
6#include "GaudiKernel/Property.h"
7#include "GaudiKernel/ISvcLocator.h"
25 Algorithm(name, pSvcLocator)
27 std::vector<std::string> resultVec;
28 resultVec.push_back(
"Error");
29 resultVec.push_back(
"Rejected");
30 resultVec.push_back(
"Accepted");
31 m_EFResult =
new EFResult(resultVec);
33 declareProperty(
"EventTypes", m_tmp_evtType);
44 if (m_EFResult)
delete m_EFResult;
52 MsgStream log( messageService(), name() );
54 Algorithm::initialize();
56 StatusCode sc = service(
"HltConfigSvc", m_HltConfigSvc);
58 log << MSG::FATAL << name() <<
": Unable to locate HltConfigSvc" << endreq;
62 sc = service(
"HltStoreSvc", m_HltStoreSvc);
64 log << MSG::FATAL << name() <<
": Unable to locate HltStoreSvc" << endreq;
101 m_HltStoreSvc->
put(
"EFResult", m_EFResult);
103 log << MSG::ERROR <<
"Unvalid m_EFResult" << endreq;
104 return StatusCode::FAILURE;
107 m_evtType =
new EFResult(m_tmp_evtType);
109 m_HltStoreSvc->
put(
"EventType", m_evtType);
111 log << MSG::ERROR <<
"Unvalid m_evtType" << endreq;
112 return StatusCode::FAILURE;
115#ifdef TIME_MEASUREMENT
116 sc = service(
"BesTimerSvc", m_timersvc);
117 if (sc.isFailure()) {
118 log << MSG::WARNING << name() <<
": Unable to locate BesTimer Service" << endreq;
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");
130 m_tuple->addItem(
"total", g_StepHandlerTime);
131 m_tuple->addItem(
"mdc", g_1stStepExecTime);
132 m_tuple->addItem(
"mdcd", g_1stStepDeciTime);
133 m_tuple->addItem(
"emc", g_2ndStepExecTime);
134 m_tuple->addItem(
"emcd", g_2ndStepDeciTime);
136 m_tuple =
ntupleSvc()->book(
"FILE444/nt",CLID_ColumnWiseTuple,
"StepCnt");
138 m_tuple->addItem(
"total", g_StepHandlerTime);
139 m_tuple->addItem(
"mdc", g_1stStepExecTime);
140 m_tuple->addItem(
"mdcd", g_1stStepDeciTime);
141 m_tuple->addItem(
"emc", g_2ndStepExecTime);
142 m_tuple->addItem(
"emcd", g_2ndStepDeciTime);
144 log << MSG::ERROR <<
"Cannot book N-tuple:" << long(m_tuple) << endmsg;
145 return StatusCode::FAILURE;
151 log << MSG::INFO <<
"Initialization " << name() <<
" completed successfully" << endreq;
152 return StatusCode::SUCCESS;
159 if (m_evtType)
delete m_evtType;
160 return StatusCode::SUCCESS;
164 MsgStream log( messageService(), name() );
166 Algorithm::beginRun();
171 StatusCode sc = createSubAlgorithm(
"StepSequencer",
"StepSequencer", p_seqAlg);
172 if( sc.isFailure() ) {
173 log << MSG::FATAL <<
"Unable to create StepSequencer SubAlgorithm " << endreq;
177 log << MSG::DEBUG <<
"created SubAlgorithm StepSequencer/StepSequencer" << endreq;
180 sc = createSubAlgorithm(
"StepDecision",
"StepDecision", p_decAlg);
181 if( sc.isFailure() ) {
182 log << MSG::FATAL <<
"Unable to create StepDecision SubAlgorithm " << endreq;
186 log << MSG::DEBUG <<
"created SubAlgorithm StepDecision/StepDecision" << endreq;
189 const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->
retrieve();
190 std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
192 for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
195 m_stepIdList.push_back(It->second->getSeqID());
198 log << MSG::DEBUG <<
"finish initializing sub-algorithms" << endreq;
199 return StatusCode::SUCCESS;
206 MsgStream log( messageService(), name() );
207 log << MSG::DEBUG <<
"*** Executing StepHandler *** " << FSMState() << endreq;
211#ifdef TIME_MEASUREMENT
223 sequencerAlg->
reset();
225 std::string answer, result;
226 std::string::size_type separator;
228 std::vector<std::string>::const_iterator
id = m_stepIdList.begin();
230 while (
id != m_stepIdList.end()) {
231 log << MSG::DEBUG <<
"In step " << (*id) << endreq;
235 log << MSG::DEBUG <<
" Step Sequencer failed" << endreq;
240 log << MSG::DEBUG <<
"+++++++++++++++++++++++++++++" << endreq;
243 std::string midAnswer = decisionAlg->
getContinue();
247 if (StepDec>0) m_EFResult->
push_back(StepDec);
255 log << MSG::DEBUG <<
" Matched Criteria, Behaviour = " << answer << endreq;
257 separator = answer.find(
'_');
258 if (separator == std::string::npos) {
259 log << MSG::ERROR <<
" Unknown decision result: "<< answer << endreq;
260 return StatusCode::FAILURE;
262 std::string perform = answer.substr(0, separator);
267 if (perform ==
"reject") {
271 else if (perform ==
"accept") {
275 else if (perform ==
"jump") {
276 std::string nextId = answer.substr(separator+1);
279 }
while ((
id != m_stepIdList.end()) && ((*
id) != nextId));
280 if (
id == m_stepIdList.end()) {
281 log << MSG::ERROR <<
" Unknown jump target: "<< nextId << endreq;
282 return StatusCode::FAILURE;
286 log << MSG::ERROR <<
" Unknown decision result: "<< answer << endreq;
287 return StatusCode::FAILURE;
294 log << MSG::DEBUG <<
"============================="
297 if (result ==
"Accepted") {
298 std::string evtMark = answer.substr(separator+1);
299 log << MSG::DEBUG <<
" Event is Accepted as " << evtMark << endreq;
302 else if (result ==
"Rejected") {
306 std::string evtMark =
"Beamgas";
308 log << MSG::DEBUG <<
" Event is Rejected" << endreq;
311 log << MSG::WARNING <<
" Unknown Behaviour, force to Reject" << endreq;
314 log << MSG::DEBUG <<
"============================="
318#ifdef TIME_MEASUREMENT
320 g_StepHandlerTime=m_timer[0]->elapsed();
322 StatusCode status = m_tuple->write();
323 if (!status.isSuccess()) {
324 log << MSG::ERROR <<
"Can't fill ntuple!" << endreq;
328 return StatusCode::SUCCESS;
void setAnswer(std::string &answer)
const int getAnswerIndex() const
void setMidAnswer(std::string &answer)
bool push_back(uint32_t val)
const std::vector< std::pair< Signature *, Sequence * > > & retrieve()
bool put(const std::string &name, const T &value)
int execDecision(const std::string &sigID)
StatusCode initDecision(HltProcessor::Signature *)
const std::string & getBehaviour() const
const std::string & getContinue() const
StepHandler(const std::string &name, ISvcLocator *pSvcLocator)
StatusCode initSequencer(HltProcessor::Sequence *)
bool execSequencer(const std::string &seqID)