BOSS 7.0.9
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 24 of file StepHandler.cxx.

24 :
25 Algorithm(name, pSvcLocator)
26{
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}

◆ ~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 160 of file StepHandler.cxx.

160 {
161 MsgStream log( messageService(), name() );
162
163 Algorithm::beginRun();
164
165 Algorithm* p_seqAlg;
166 Algorithm* p_decAlg;
167
168 StatusCode sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg);
169 if( sc.isFailure() ) {
170 log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endreq;
171 return sc;
172 } else {
173 sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
174 log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endreq;
175 }
176
177 sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg);
178 if( sc.isFailure() ) {
179 log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endreq;
180 return sc;
181 } else {
182 decisionAlg = static_cast<StepDecision*>(p_decAlg);
183 log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endreq;
184 }
185
186 const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->retrieve();
187 std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
188
189 for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
190 sequencerAlg->initSequencer(It->second);
191 decisionAlg->initDecision(It->first);
192 m_stepIdList.push_back(It->second->getSeqID());
193 }
194
195 log << MSG::DEBUG << "finish initializing sub-algorithms" << endreq;
196 return StatusCode::SUCCESS;
197}
const std::vector< std::pair< Signature *, Sequence * > > & retrieve()
StatusCode initDecision(HltProcessor::Signature *)
StatusCode initSequencer(HltProcessor::Sequence *)

◆ execute()

StatusCode StepHandler::execute ( )

Definition at line 201 of file StepHandler.cxx.

201 {
202 // MSGStream object to output messages from your algorithm
203 MsgStream log( messageService(), name() );
204 log << MSG::DEBUG << "*** Executing StepHandler *** " << FSMState() << endreq;
205
206 //if(EFBesTimer::pBesTimer&&EFBesTimer::pType==2)EFBesTimer::pBesTimer->start();
207
208#ifdef TIME_MEASUREMENT //// Timer
209 m_timer[0]->start();
210 m_timer[1]->start();
211 m_timer[2]->start();
212 m_timer[3]->start();
213 m_timer[4]->start();
214#endif
215
216 bool StepSeq = true;
217 int StepDec = -999;
218 log << MSG::DEBUG << "point: " << m_EFResult << " " << m_evtType << " " << sequencerAlg << endreq;
219 m_EFResult->reset();
220 m_evtType->reset();
221 if(!sequencerAlg) return StatusCode::FAILURE;
222 sequencerAlg->reset();
223
224 std::string answer, result;
225 std::string::size_type separator;
226
227 std::vector<std::string>::const_iterator id = m_stepIdList.begin();
228
229 while (id != m_stepIdList.end()) {
230 log << MSG::DEBUG << "In step " << (*id) << endreq;
231
232 StepSeq = sequencerAlg->execSequencer(*id);
233 if (!StepSeq) {
234 log << MSG::DEBUG << " Step Sequencer failed" << endreq;
235 id++;
236 continue;
237 }
238
239 log << MSG::DEBUG << "+++++++++++++++++++++++++++++" << endreq;
240
241 StepDec = decisionAlg->execDecision(*id);
242 std::string midAnswer = decisionAlg->getContinue();
243 if (midAnswer!="") m_evtType->setMidAnswer(midAnswer);
244 //cout <<midAnswer<< endl;
245
246 if (StepDec>0) m_EFResult->push_back(StepDec);
247 else {
248 //log << MSG::DEBUG << " Execute next step" << endreq;
249 m_EFResult->push_back(0);
250 id++;
251 continue;
252 }
253 answer = decisionAlg->getBehaviour();
254 log << MSG::DEBUG << " Matched Criteria, Behaviour = " << answer << endreq;
255
256 separator = answer.find('_');
257 if (separator == std::string::npos) {
258 log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
259 return StatusCode::FAILURE;
260 }
261 std::string perform = answer.substr(0, separator);
262
263 //std::string midAnswer = decisionAlg->getContinue();
264 //if(midAnswer!="") m_evtType->setMidAnswer(midAnswer);
265 //cout <<answer<<" "<<midAnswer<< endl;
266 if (perform == "reject") {
267 result = "Rejected";
268 break;
269 }
270 else if (perform == "accept") {
271 result = "Accepted";
272 break;
273 }
274 else if (perform == "jump") {
275 std::string nextId = answer.substr(separator+1);
276 do {
277 ++id;
278 } while ((id != m_stepIdList.end()) && ((*id) != nextId));
279 if (id == m_stepIdList.end()) {
280 log << MSG::ERROR << " Unknown jump target: "<< nextId << endreq;
281 return StatusCode::FAILURE;
282 }
283 }
284 else {
285 log << MSG::ERROR << " Unknown decision result: "<< answer << endreq;
286 return StatusCode::FAILURE;
287 }
288 //std::string evtMark = tmp.substr(tmp.find('_')+1);
289 //if(evtMark!="") m_evtType->setMidAnswer(evtMark);
290 //cout <<answer<<endl;
291 }
292
293 log << MSG::DEBUG << "==============" <<m_evtType->getAnswerIndex()<< endreq;
294
295 if (result == "Accepted") {
296 std::string evtMark = answer.substr(separator+1);
297 log << MSG::DEBUG << " Event is Accepted as " << evtMark << endreq;
298 m_evtType->setAnswer(evtMark);
299 }
300 else if (result == "Rejected") {
301 // only beam-gas rejected defaultly
302 // other type event not decided in Event Filter
303 // by Fu Chengdong
304 std::string evtMark = "Beamgas";
305 m_evtType->setAnswer(evtMark);
306 log << MSG::DEBUG << " Event is Rejected" << endreq;
307 }
308 else {
309 log << MSG::WARNING << " Unknown Behaviour, force to Reject" << endreq;
310 result = "Rejected";
311 }
312 log << MSG::DEBUG << "==============" <<m_evtType->getAnswerIndex()<< endreq;
313 m_EFResult->setAnswer(result);
314
315#ifdef TIME_MEASUREMENT //// Timer
316 m_timer[0]->stop();
317 g_StepHandlerTime=m_timer[0]->elapsed();
318 if(m_tuple){
319 StatusCode status = m_tuple->write();
320 if (!status.isSuccess()) {
321 log << MSG::ERROR << "Can't fill ntuple!" << endreq;
322 }
323 }
324#endif
325 return StatusCode::SUCCESS;
326}
void setAnswer(std::string &answer)
Definition: EFResult.cxx:115
const int getAnswerIndex() const
Definition: EFResult.cxx:168
void setMidAnswer(std::string &answer)
Definition: EFResult.cxx:133
void reset()
Definition: EFResult.cxx:153
bool push_back(uint32_t val)
Definition: EFResult.cxx:61
int execDecision(const std::string &sigID)
const std::string & getBehaviour() const
Definition: StepDecision.h:26
const std::string & getContinue() const
Definition: StepDecision.h:27
bool execSequencer(const std::string &seqID)

◆ finalize()

StatusCode StepHandler::finalize ( )

Definition at line 155 of file StepHandler.cxx.

155 {
156 if (m_evtType) delete m_evtType;
157 return StatusCode::SUCCESS;
158}

◆ 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( messageService(), name() );
53
54 Algorithm::initialize();
55
56 StatusCode sc = service("HltConfigSvc", m_HltConfigSvc);
57 if( sc.isFailure()) {
58 log << MSG::FATAL << name() << ": Unable to locate HltConfigSvc" << endreq;
59 return sc;
60 }
61 sc = service("HltStoreSvc", m_HltStoreSvc);
62 if( sc.isFailure()) {
63 log << MSG::FATAL << name() << ": Unable to locate HltStoreSvc" << endreq;
64 return sc;
65 }
66 //CreateSubAlgorithms; StepSequencer and StepDecision
67 /*
68 Algorithm* p_seqAlg;
69 Algorithm* p_decAlg;
70
71 sc = createSubAlgorithm("StepSequencer", "StepSequencer", p_seqAlg);
72 if( sc.isFailure() ) {
73 log << MSG::FATAL << "Unable to create StepSequencer SubAlgorithm " << endreq;
74 return sc;
75 } else {
76 sequencerAlg = static_cast<StepSequencer*>(p_seqAlg);
77 log << MSG::DEBUG << "created SubAlgorithm StepSequencer/StepSequencer" << endreq;
78 }
79
80 sc = createSubAlgorithm("StepDecision", "StepDecision", p_decAlg);
81 if( sc.isFailure() ) {
82 log << MSG::FATAL << "Unable to create StepDecision SubAlgorithm " << endreq;
83 return sc;
84 } else {
85 decisionAlg = static_cast<StepDecision*>(p_decAlg);
86 log << MSG::DEBUG << "created SubAlgorithm StepDecision/StepDecision" << endreq;
87 }
88
89 const std::vector<std::pair<Signature*,Sequence*> >& m_TableVector = m_HltConfigSvc->retrieve();
90 std::vector<std::pair<Signature*,Sequence*> >::const_iterator It;
91
92 for (It = m_TableVector.begin(); It != m_TableVector.end(); ++It) {
93 sequencerAlg->initSequencer(It->second);
94 decisionAlg->initDecision(It->first);
95 m_stepIdList.push_back(It->second->getSeqID());
96 }
97 */
98 if (m_EFResult)
99 m_HltStoreSvc->put("EFResult", m_EFResult);
100 else {
101 log << MSG::ERROR << "Unvalid m_EFResult" << endreq;
102 return StatusCode::FAILURE;
103 }
104
105 m_evtType = new EFResult(m_tmp_evtType);
106 if (m_evtType)
107 m_HltStoreSvc->put("EventType", m_evtType);
108 else {
109 log << MSG::ERROR << "Unvalid m_evtType" << endreq;
110 return StatusCode::FAILURE;
111 }
112#ifdef TIME_MEASUREMENT //// Timer
113 sc = service("BesTimerSvc", m_timersvc);
114 if (sc.isFailure()) {
115 log << MSG::WARNING << name() << ": Unable to locate BesTimer Service" << endreq;
116 return StatusCode::FAILURE;
117 }
118 m_timer[0] = m_timersvc->addItem("Step Handler Time");
119 m_timer[1] = m_timersvc->addItem("1stStep exec Time");
120 m_timer[2] = m_timersvc->addItem("1stStep deci Time");
121 m_timer[3] = m_timersvc->addItem("2ndStep exec Time");
122 m_timer[4] = m_timersvc->addItem("2ndStep deci Time");
123
124 NTuplePtr nt(ntupleSvc(),"FILE444/nt");
125 if ( nt ) {
126 m_tuple = nt;
127 m_tuple->addItem("total", g_StepHandlerTime);
128 m_tuple->addItem("mdc", g_1stStepExecTime);
129 m_tuple->addItem("mdcd", g_1stStepDeciTime);
130 m_tuple->addItem("emc", g_2ndStepExecTime);
131 m_tuple->addItem("emcd", g_2ndStepDeciTime);
132 } else {
133 m_tuple = ntupleSvc()->book("FILE444/nt",CLID_ColumnWiseTuple,"StepCnt");
134 if (m_tuple) {
135 m_tuple->addItem("total", g_StepHandlerTime);
136 m_tuple->addItem("mdc", g_1stStepExecTime);
137 m_tuple->addItem("mdcd", g_1stStepDeciTime);
138 m_tuple->addItem("emc", g_2ndStepExecTime);
139 m_tuple->addItem("emcd", g_2ndStepDeciTime);
140 } else {
141 log << MSG::ERROR <<"Cannot book N-tuple:" << long(m_tuple) << endmsg;
142 return StatusCode::FAILURE;
143 }
144 }
145 round = 0;
146#endif
147
148 log << MSG::INFO << "Initialization " << name() << " completed successfully" << endreq;
149 return StatusCode::SUCCESS;
150}
INTupleSvc * ntupleSvc()
bool put(const std::string &name, const T &value)
Definition: HltStoreSvc.h:60

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