BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
StepHandler Class Reference

#include <StepHandler.h>

Inheritance diagram for StepHandler:

Public Member Functions

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

Detailed Description

Definition at line 21 of file StepHandler.h.

Constructor & Destructor Documentation

◆ StepHandler()

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

Definition at line 25 of file StepHandler.cxx.

26 : 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 );
32
33 declareProperty( "EventTypes", m_tmp_evtType );
34 // evtTypes.push_back("Unknown");
35 // evtTypes.push_back("Hadron");
36 // evtTypes.push_back("Dimuon");
37 // evtTypes.push_back("DiElectron");
38 // evtTypes.push_back("DiPhoton");
39 // m_evtType = new EFResult(m_tmp_evtType);
40}

Referenced by StepHandler().

◆ ~StepHandler()

StepHandler::~StepHandler ( )

Definition at line 43 of file StepHandler.cxx.

43 {
44 if ( m_EFResult ) delete m_EFResult;
45 // if (m_evtType) delete m_evtType;
46}

Member Function Documentation

◆ beginRun()

StatusCode StepHandler::beginRun ( )

Definition at line 169 of file StepHandler.cxx.

169 {
170 MsgStream log( msgSvc(), name() );
171
172 Algorithm::beginRun();
173
174 Algorithm* p_seqAlg;
175 Algorithm* p_decAlg;
176
177 StatusCode sc = createSubAlgorithm( "StepSequencer", "StepSequencer", p_seqAlg );
178 if ( sc.isFailure() )
179 {
180 log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endmsg;
181 return sc;
182 }
183 else
184 {
185 sequencerAlg = static_cast<StepSequencer*>( p_seqAlg );
186 log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endmsg;
187 }
188
189 sc = createSubAlgorithm( "StepDecision", "StepDecision", p_decAlg );
190 if ( sc.isFailure() )
191 {
192 log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endmsg;
193 return sc;
194 }
195 else
196 {
197 decisionAlg = static_cast<StepDecision*>( p_decAlg );
198 log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endmsg;
199 }
200
201 const std::vector<std::pair<Signature*, Sequence*>>& m_TableVector =
202 m_HltConfigSvc->retrieve();
203 std::vector<std::pair<Signature*, Sequence*>>::const_iterator It;
204
205 for ( It = m_TableVector.begin(); It != m_TableVector.end(); ++It )
206 {
207 sequencerAlg->initSequencer( It->second );
208 decisionAlg->initDecision( It->first );
209 m_stepIdList.push_back( It->second->getSeqID() );
210 }
211
212 log << MSG::DEBUG << "finish initializing sub-algorithms" << endmsg;
213 return StatusCode::SUCCESS;
214}
IMessageSvc * msgSvc()

◆ execute()

StatusCode StepHandler::execute ( )

Definition at line 218 of file StepHandler.cxx.

218 {
219 // MSGStream object to output messages from your algorithm
220 MsgStream log( msgSvc(), name() );
221 log << MSG::DEBUG << "*** Executing StepHandler *** " << FSMState() << endmsg;
222
223 // if(EFBesTimer::pBesTimer&&EFBesTimer::pType==2)EFBesTimer::pBesTimer->start();
224
225#ifdef TIME_MEASUREMENT //// Timer
226 m_timer[0]->start();
227 m_timer[1]->start();
228 m_timer[2]->start();
229 m_timer[3]->start();
230 m_timer[4]->start();
231#endif
232
233 bool StepSeq = true;
234 int StepDec = -999;
235 log << MSG::DEBUG << "point: " << m_EFResult << " " << m_evtType << " " << sequencerAlg
236 << endmsg;
237 m_EFResult->reset();
238 m_evtType->reset();
239 if ( !sequencerAlg ) return StatusCode::FAILURE;
240 sequencerAlg->reset();
241
242 std::string answer, result;
243 std::string::size_type separator;
244
245 std::vector<std::string>::const_iterator id = m_stepIdList.begin();
246
247 while ( id != m_stepIdList.end() )
248 {
249 log << MSG::DEBUG << "In step " << ( *id ) << endmsg;
250
251 StepSeq = sequencerAlg->execSequencer( *id );
252 if ( !StepSeq )
253 {
254 log << MSG::DEBUG << " Step Sequencer failed" << endmsg;
255 id++;
256 continue;
257 }
258
259 log << MSG::DEBUG << "+++++++++++++++++++++++++++++" << endmsg;
260
261 StepDec = decisionAlg->execDecision( *id );
262 std::string midAnswer = decisionAlg->getContinue();
263 if ( midAnswer != "" ) m_evtType->setMidAnswer( midAnswer );
264 // cout <<midAnswer<< endl;
265
266 if ( StepDec > 0 ) m_EFResult->push_back( StepDec );
267 else
268 {
269 // log << MSG::DEBUG << " Execute next step" << endmsg;
270 m_EFResult->push_back( 0 );
271 id++;
272 continue;
273 }
274 answer = decisionAlg->getBehaviour();
275 log << MSG::DEBUG << " Matched Criteria, Behaviour = " << answer << endmsg;
276
277 separator = answer.find( '_' );
278 if ( separator == std::string::npos )
279 {
280 log << MSG::ERROR << " Unknown decision result: " << answer << endmsg;
281 return StatusCode::FAILURE;
282 }
283 std::string perform = answer.substr( 0, separator );
284
285 // std::string midAnswer = decisionAlg->getContinue();
286 // if(midAnswer!="") m_evtType->setMidAnswer(midAnswer);
287 // cout <<answer<<" "<<midAnswer<< endl;
288 if ( perform == "reject" )
289 {
290 result = "Rejected";
291 break;
292 }
293 else if ( perform == "accept" )
294 {
295 result = "Accepted";
296 break;
297 }
298 else if ( perform == "jump" )
299 {
300 std::string nextId = answer.substr( separator + 1 );
301 do {
302 ++id;
303 } while ( ( id != m_stepIdList.end() ) && ( ( *id ) != nextId ) );
304 if ( id == m_stepIdList.end() )
305 {
306 log << MSG::ERROR << " Unknown jump target: " << nextId << endmsg;
307 return StatusCode::FAILURE;
308 }
309 }
310 else
311 {
312 log << MSG::ERROR << " Unknown decision result: " << answer << endmsg;
313 return StatusCode::FAILURE;
314 }
315 // std::string evtMark = tmp.substr(tmp.find('_')+1);
316 // if(evtMark!="") m_evtType->setMidAnswer(evtMark);
317 // cout <<answer<<endl;
318 }
319
320 log << MSG::DEBUG << "==============" << m_evtType->getAnswerIndex() << endmsg;
321
322 if ( result == "Accepted" )
323 {
324 std::string evtMark = answer.substr( separator + 1 );
325 log << MSG::DEBUG << " Event is Accepted as " << evtMark << endmsg;
326 m_evtType->setAnswer( evtMark );
327 }
328 else if ( result == "Rejected" )
329 {
330 // only beam-gas rejected defaultly
331 // other type event not decided in Event Filter
332 // by Fu Chengdong
333 std::string evtMark = "Beamgas";
334 m_evtType->setAnswer( evtMark );
335 log << MSG::DEBUG << " Event is Rejected" << endmsg;
336 }
337 else
338 {
339 log << MSG::WARNING << " Unknown Behaviour, force to Reject" << endmsg;
340 result = "Rejected";
341 }
342 log << MSG::DEBUG << "==============" << m_evtType->getAnswerIndex() << endmsg;
343 m_EFResult->setAnswer( result );
344
345#ifdef TIME_MEASUREMENT //// Timer
346 m_timer[0]->stop();
347 g_StepHandlerTime = m_timer[0]->elapsed();
348 if ( m_tuple )
349 {
350 StatusCode status = m_tuple->write();
351 if ( !status.isSuccess() ) { log << MSG::ERROR << "Can't fill ntuple!" << endmsg; }
352 }
353#endif
354 return StatusCode::SUCCESS;
355}

◆ finalize()

StatusCode StepHandler::finalize ( )

Definition at line 164 of file StepHandler.cxx.

164 {
165 if ( m_evtType ) delete m_evtType;
166 return StatusCode::SUCCESS;
167}

◆ initialize()

StatusCode StepHandler::initialize ( )

Definition at line 50 of file StepHandler.cxx.

50 {
51 // MSGStream object to output messages from your algorithm
52 MsgStream log( msgSvc(), name() );
53
54 Algorithm::initialize();
55
56 StatusCode sc = service( "HltConfigSvc", m_HltConfigSvc );
57 if ( sc.isFailure() )
58 {
59 log << MSG::FATAL << name() << ": Unable to locate HltConfigSvc" << endmsg;
60 return sc;
61 }
62 sc = service( "HltStoreSvc", m_HltStoreSvc );
63 if ( sc.isFailure() )
64 {
65 log << MSG::FATAL << name() << ": Unable to locate HltStoreSvc" << endmsg;
66 return sc;
67 }
68 // CreateSubAlgorithms; StepSequencer and StepDecision
69 /*
70 Algorithm* p_seqAlg;
71 Algorithm* p_decAlg;
72
73 sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg);
74 if( sc.isFailure() ) {
75 log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endmsg;
76 return sc;
77 } else {
78 sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
79 log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endmsg;
80 }
81
82 sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg);
83 if( sc.isFailure() ) {
84 log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endmsg;
85 return sc;
86 } else {
87 decisionAlg = static_cast<StepDecision*>(p_decAlg);
88 log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endmsg;
89 }
90
91 const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector =
92 m_HltConfigSvc->retrieve(); std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
93
94 for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
95 sequencerAlg->initSequencer(It->second);
96 decisionAlg->initDecision(It->first);
97 m_stepIdList.push_back(It->second->getSeqID());
98 }
99 */
100 if ( m_EFResult ) m_HltStoreSvc->put( "EFResult", m_EFResult );
101 else
102 {
103 log << MSG::ERROR << "Unvalid m_EFResult" << endmsg;
104 return StatusCode::FAILURE;
105 }
106
107 m_evtType = new EFResult( m_tmp_evtType );
108 if ( m_evtType ) m_HltStoreSvc->put( "EventType", m_evtType );
109 else
110 {
111 log << MSG::ERROR << "Unvalid m_evtType" << endmsg;
112 return StatusCode::FAILURE;
113 }
114#ifdef TIME_MEASUREMENT //// Timer
115 sc = service( "BesTimerSvc", m_timersvc );
116 if ( sc.isFailure() )
117 {
118 log << MSG::WARNING << name() << ": Unable to locate BesTimer Service" << endmsg;
119 return StatusCode::FAILURE;
120 }
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" );
126
127 NTuplePtr nt( ntupleSvc(), "FILE444/nt" );
128 if ( nt )
129 {
130 m_tuple = 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 );
136 }
137 else
138 {
139 m_tuple = ntupleSvc()->book( "FILE444/nt", CLID_ColumnWiseTuple, "StepCnt" );
140 if ( m_tuple )
141 {
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 );
147 }
148 else
149 {
150 log << MSG::ERROR << "Cannot book N-tuple:" << long( m_tuple ) << endmsg;
151 return StatusCode::FAILURE;
152 }
153 }
154 round = 0;
155#endif
156
157 log << MSG::INFO << "Initialization " << name() << " completed successfully" << endmsg;
158 return StatusCode::SUCCESS;
159}
INTupleSvc * ntupleSvc()

The documentation for this class was generated from the following files: