BOSS 7.1.0
BESIII Offline Software System
Loading...
Searching...
No Matches
SC.cxx
Go to the documentation of this file.
1// Dear emacs, this is -*- c++ -*-
2
3#include "ESController/SC.h"
7
8//#include <Python.h>
9#include <stdint.h>
10#include <cmath>
11#include <cstdio>
12#include <string>
13
14//hxt #include <df_allocator>
15//#include "RawDataFormat/FragmentType.h"
16//#include "RawDataFormat/AbstractFragment.h"
17//#include "RawDataFormat/minimal.h"
18
19// Include files for Gaudi
20#include "GaudiKernel/SmartIF.h"
21#include "GaudiKernel/Bootstrap.h"
22#include "GaudiKernel/IAppMgrUI.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/IProperty.h"
25#include "GaudiKernel/Property.h"
26#include "GaudiKernel/IService.h"
27#include "GaudiKernel/IMessageSvc.h"
28#include "GaudiKernel/IClassManager.h"
29
30//#include "HltConfig/MyFrame.h"
31
32#include <list>
33
35 m_eventLoopMgr(0),
36 m_config(0),
37 m_pesaAppMgr(0),
38 m_isCreated(false),
39 m_outLev(5),
40 m_nameEventLoopMgr("EFEventLoopMgr")
41{
42 ::setenv("SCOutputLevel","3",1);
43 char* ss=::getenv("SCOutputLevel");
44 //if(ss!=NULL)std::cout<<ss<<std::endl;
45 //else std::cout<<"****************"<<std::endl;
46 //char* outlev=::getenv("SCOutputLevel");
47 //std::cout<<outlev<<std::endl;
48 //m_outLev=atoi(outlev);
49 //std::cout<<m_outLev<<std::endl;
50 //Hlt::MyFrame::instance();
51}
52
54{
55 //delete Hlt::MyFrame::instance();
56 m_pesaAppMgr->release() ;
57}
58
59bool efpsc::SC::configure (const std::string& config)
60{
61 static bool first_call_configure = true;
62 if(first_call_configure){
63 first_call_configure = false;
64 }
65 else{
66 return true;
67 }
68 //if(0==Hlt::MyFrame::instance()){
69 // std::cout<<"Error while create MyFrame"<<std::endl;
70 //exit(1);
71 //}
72
73 //EFPSC_DBG1("efpsc::SC::configure",
74 // "SC configuration started.");
75 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"SC configuration started."<<std::endl;
76 m_config = new efpsc::Config(config);
77
78 // Create an instance of the Pesa application manager
79 //EFPSC_DBG1("efpsc::SC::configure",
80// "---> Create Pesa Application Manager");
81 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Create Pesa Application Manager:"
82 <<m_isCreated<<std::endl;
83 if(!m_isCreated){
84 if ((m_config->dllName().size() != 0) && (m_config->factoryName().size() != 0)) {
85 m_pesaAppMgr = Gaudi::createApplicationMgr(m_config->dllName(),m_config->factoryName());
86 if(m_outLev<=3)std::cout<<"Gaudi::createApplicationMgr(m_config->dllName(),m_config->factoryName())"
87 <<std::endl;
88 } else {
89 m_pesaAppMgr = Gaudi::createApplicationMgr();
90 if(m_outLev<=3)std::cout<<"Gaudi::createApplicationMgr()"<<std::endl;
91 }
92 }
93
94 // configure Pesa
95// EFPSC_DBG1("efpsc::SC::configure",
96// "---> Configure Pesa Property Manager");
97 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Configure Pesa Property Manager"<<std::endl;
98 StatusCode sc ;
99 SmartIF<IProperty> propMgr ( m_pesaAppMgr );
100 SmartIF<IAppMgrUI> appMgr ( m_pesaAppMgr );
101 if( !appMgr.isValid() || !propMgr.isValid() ) {
102 //EFPSC_ERROR("efpsc::SC::configure",
103 // "While creating the ApplicationMgr");
104 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"While creating the ApplicationMgr"<<std::endl;
105 return false;
106 }
107
108 // Get the input configuration file from arguments (default "jobOptions.txt")
109 std::string opts = "jobOptions.txt";
110 ::setenv("efJobPath","",1);
111 if (m_config->jobOptionsPath().size() != 0) {
112 opts = m_config->jobOptionsPath() ;
113 if (opts.rfind("/") < opts.size()) {
114 ::setenv("efJobPath",opts.substr(0,opts.rfind("/")).c_str(),1);
115 }
116 }
117 //EFPSC_DBG1("efpsc::SC::configure", "---> Pesa JobOptions file is = " << opts);
118 //EFPSC_DBG1("efpsc::SC::configure", "---> Pesa JobOptions path = " << ::getenv("efJobPath"));
119 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"---> Pesa JobOptions file is = " << opts<<std::endl
120 <<" "<<"---> Pesa JobOptions path = "
121 << ::getenv("efJobPath")<<std::endl;
122 propMgr->setProperty( "JobOptionsPath", opts );
123
124 propMgr->setProperty( "EventLoop",m_nameEventLoopMgr );
125
126
127
128 // Select the MessageSvc Type
129 if (m_config->messageSvcType().size() != 0) {
130 propMgr->setProperty( "MessageSvcType", m_config->messageSvcType());
131 }
132
133 // No EventSelector will be used
134 if (m_config->evtSel().size() != 0) {
135 propMgr->setProperty( "EvtSel", m_config->evtSel());
136 } else {
137 propMgr->setProperty( "EvtSel", "NONE" );
138 }
139 //EFPSC_DBG1("efpsc::SC::configure", "finish property set--->start configure ");
140 //EFPSC_DBG1("efpsc::SC::configure", "Configuring ApplicationMgr: "
141// << appMgr->stateName() << " Status : " << sc.getCode());
142 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"finish property set--->start configure"<<std::endl;
143 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Configuring ApplicationMgr: "
144 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
145 // Configure the application manager
146 if( opts.substr( opts.length() - 3, 3 ) == ".py" ) {
147
148 //EFPSC_ERROR("efpsc::SC::configure",
149// "Error: Don't support python config files");
150 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "
151 <<"Error: Don't support python config files"<<std::endl;
152 return false;
153 // ----------------------------
154 // Configuration with .py files
155 // ----------------------------
156
157 // Try to initialize the Python interpreter
158 /*if ( ! Py_IsInitialized() ) {
159 Py_Initialize();
160
161 // check
162 if ( ! Py_IsInitialized() ) {
163 EFPSC_ERROR("efpsc::SC::configure",
164 "Error: Python could not been intialized.");
165 Py_Finalize();
166 return false;
167 }
168
169 // import basic python modules (used throughout)
170 std::string pyBasicFile = "SC/SCPythonSetup.py" ;
171 if (m_config->pythonSetupFile().size() != 0) {
172 pyBasicFile = m_config->pythonSetupFile() ;
173 }
174
175 pyBasicFile = PathResolver::find_file(pyBasicFile, "PYTHONPATH");
176 FILE* infile = fopen( pyBasicFile.c_str() , "r" );
177 if ( PyRun_SimpleFile(infile,const_cast<char*>(pyBasicFile.c_str())) != 0 ) {
178 EFPSC_ERROR("efpsc::SC::configure",
179 "Error: Basic Python configuration failed.");
180 Py_Finalize();
181 return false;
182 }
183
184 std::string pyExecFile = "include( \""+std::string(opts)+"\" )" ;
185 if ( PyRun_SimpleString(const_cast<char*>(pyExecFile.c_str())) != 0 ) {
186 EFPSC_ERROR("efpsc::SC::configure",
187 "Error: Python job configuration script failed.");
188 Py_Finalize();
189 return false;
190 }
191 }*/
192 } else {
193 // -----------------------------
194 // Configuration with .txt files
195 // -----------------------------
196 sc = appMgr->configure();
197 if( sc.isFailure() ) {
198 //EFPSC_DBG1("efpsc::SC::configure",
199// "While configuring the ApplicationMgr");
200 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"While configuring the ApplicationMgr"<<std::endl;
201 return false;
202 }
203 }
204 // EFPSC_DBG1("efpsc::SC::configure", "Configuring ApplicationMgr: "
205// << appMgr->stateName() << " Status : " << sc.getCode());
206 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Configuring ApplicationMgr: "
207 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
208 // Initialize the application manager
209 sc = appMgr->initialize();
210 //EFPSC_DBG1("efpsc::SC::configure", "Initialize ApplicationMgr : "
211// << appMgr->stateName()
212// << " Status : " << sc.getCode());
213 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Initialize ApplicationMgr : "
214 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
215 if( sc.isFailure() ) {
216 EFPSC_ERROR("efpsc::SC::configure", "While intializing the ApplicationMgr");
217 return false;
218 }
219
220 // Find the basename for the EventLoopMgr
221 std::string value ;
222 //std::cout<<"value = "<<value<<std::endl;
223 sc = propMgr->getProperty( "EventLoop", value );
224 //std::cout<<"value = "<<value<<std::endl;
225 if( sc.isFailure() ) {
226 //EFPSC_DBG1("efpsc::SC::configure", "While retrieving Property EventLoop ");
227 if(m_outLev<=4) std::cout<<"efpsc::SC::configure "<<"While retrieving Property EventLoop "<<std::endl;
228 } else {
229 m_nameEventLoopMgr.assign(value, value.find_first_of("\"")+1,
230 value.find_last_of("\"")-value.find_first_of("\"")-1) ;
231 }
232
233 SmartIF<ISvcLocator> svcLoc( m_pesaAppMgr );
234 if (svcLoc.isValid()) {
235 //EFPSC_DBG1("efpsc::SC::configure","Name for EventLoopManager:"<<m_nameEventLoopMgr);
236 if(m_outLev<=2) std::cout<<"efpsc::SC::configure "<<"Name for EventLoopManager:"
237 <<m_nameEventLoopMgr<<std::endl;
238 StatusCode sc ;
239 IEventProcessor* processingMgr = 0 ;
240
241 sc = svcLoc->service( m_nameEventLoopMgr , processingMgr);
242 m_eventLoopMgr=processingMgr;
243
244 if( !sc.isSuccess() ) {
245 //EFPSC_ERROR("efpsc::SC::configure", " Error Retrieving Processing manager!") ;
246 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"Error Retrieving Processing manager!"<<std::endl;
247 return false;
248 }
249
250 } else {
251 //EFPSC_ERROR("efpsc::SC::configure", " Error Retrieving Service Locator!") ;
252 if(m_outLev<=5) std::cout<<"efpsc::SC::configure "<<"Error Retrieving Service Locator!"<<std::endl;
253 return false;
254 }
255
256 m_isCreated=true;
257 //EFPSC_DBG1("efpsc::SC::configure","SC configuration finished.");
258 if(m_outLev<=3) std::cout<<"efpsc::SC::configure "<<"SC configuration finished."<<std::endl;
259 return true;
260}
261
263{
264 return true;
265 //EFPSC_DBG1("efpsc::SC::unconfigure",
266// "SC UNconfiguration started.");
267 if(m_outLev<=3) std::cout<<"efpsc::SC::unconfigure "<<"SC UNconfiguration started."<<std::endl;
268 StatusCode sc ;
269 SmartIF<IAppMgrUI> appMgr ( m_pesaAppMgr );
270 if( !appMgr.isValid() ) {
271// EFPSC_ERROR("efpsc::SC::unconfigure",
272// "While unconfiguring the ApplicationMgr, no valid interface");
273 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "
274 <<"While unconfiguring the ApplicationMgr, no valid interface"<<std::endl;
275 return false;
276 }
277 SmartIF<ISvcLocator> svcLoc( m_pesaAppMgr );
278
279 //const std::list<IService*>* svclist=svcLoc->getServices();
280 //for(std::list<IService*>::iterator it = svclist->begin(); it != svclist->end(); it++ ) {
281 // std::cout<<(*it)->name()<<std::endl;
282 //}
283
284 // Finalize the application manager
285 sc = appMgr->finalize();
286
287// EFPSC_DBG1("efpsc::SC::unconfigure", "Finalize ApplicationMgr: "
288// << appMgr->stateName() << " Status : " << sc.getCode());
289 if(m_outLev<=2) std::cout<<"efpsc::SC::unconfigure "<<"Finalize ApplicationMgr: "
290 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
291 if( sc.isFailure() ) {
292// EFPSC_ERROR("efpsc::SC::unconfigure",
293// "---> While finalizing the ApplicationMgr ");
294 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "<<"While finalizing the ApplicationMgr"<<std::endl;
295 return false;
296 }
297
298 // Terminate the application manager
299 sc = appMgr->terminate();
300// EFPSC_DBG1("efpsc::SC::unconfigure", "Terminate ApplicationMgr : "
301// << appMgr->stateName() << " Status : " << sc.getCode());
302 if(m_outLev<=2) std::cout<<"efpsc::SC::unconfigure "<<"Terminate ApplicationMgr : "
303 << appMgr->FSMState() << " Status : " << sc.getCode()<<std::endl;
304 if( sc.isFailure() ) {
305 //EFPSC_ERROR("efpsc::SC::unconfigure","While terminating the ApplicationMgr");
306 if(m_outLev<=5) std::cout<<"efpsc::SC::unconfigure "<<"While terminating the ApplicationMgr"<<std::endl;
307 return false;
308 }
309
310 //IService* msgSvc=0;
311 //svclist=svcLoc->getServices();
312 //svclist->erase(svclist.begin(), svclist.end() );
313 //std::cout<<svclist->size()<<std::endl;
314 //if(svcLoc->existsService("MessageSvc")){
315 // svcLoc->getService("MessageSvc",msgSvc);
316 // std::cout<<"111"<<msgSvc->name()<<std::endl;
317 // std::list<IService*> svclist=svcLoc->getServices();
318 // for(std::list<IService*>::iterator it = svclist.begin(); it != svclist.end(); it++ ) {
319 // //std::cout<<(*it)->name()<<std::endl;
320 // }
321 // int a1=svclist.size();
322 // svclist->remove(msgSvc);
323 // int a2=svclist.size();
324 // if(svcLoc->existsService("MessageSvc"))std::cout<<"exist"<<a1<<","<<a2<<std::endl;
325 //}
326 //appMgr->release();
327 //if(msgSvc) msgSvc->release();
328 //svcMgr->removeService("MessageSvc");
329
330 delete m_config;
331 m_config = 0;
332 //EFPSC_DBG2("efpsc::SC::unconfigure", "SC UNconfiguration finished.");
333 if(m_outLev<=3) std::cout<<"efpsc::SC::unconfigure "<<"SC UNconfiguration finished."<<std::endl;
334 return true;
335}
336
337bool efpsc::SC::prepareForRun(int run_number=0)
338{
339 // This is a placeholder method
340 if(m_eventLoopMgr){
341 SmartIF<IEFEventLoopMgr> processor_psc( m_eventLoopMgr);
342 StatusCode sc = processor_psc->prepareForRun(run_number);
343 std::cout << "=================" << m_eventLoopMgr << std::endl;
344 if(sc.isSuccess()) return true;
345 }
346 return false;
347}
348
349bool efpsc::SC::process(const uint32_t *&feStore, const uint32_t *&sdStore,std::string &efDecision_s,std::vector<uint32_t> &efBitPattern)
350{
351 //std::cout<<"jak:"<<__FILE__<<std::endl;
352 //EFPSC_DBG1("efpsc::SC::process", "***********************************************");
353 //EFPSC_DBG1("efpsc::SC::process", "****************** NEW EVENT ******************");
354 //EFPSC_DBG1("efpsc::SC::process", "***********************************************");
355 if(m_outLev<=3)std::cout<<"efpsc::SC::process"<<" **************** NEW EVENT ****************"<<std::endl;
356 //Test if FullEventFragment is valid
357 // if(!fe->is_valid()){
358 // EFPSC_ERROR("efpsc::SC::process","FullEventFragment NOT valid! This event is not going to be processed!");
359 // return false;
360 // } else {
361 // EFPSC_DBG1("efpsc::SC::process", " FullEventFragment is valid." );
362 // }
363
364
365 // ExecuteEvent from the application manager
366 StatusCode sc ;
367 if ( 0 != m_eventLoopMgr ) {
368 SmartIF<IEventProcessor> processor( m_eventLoopMgr);
369
370 if ( processor.isValid() ) {
371 SmartIF<IService> processor_s( m_eventLoopMgr);
372 //EFPSC_DBG1("efpsc::SC::process", " ---> Executing events for processor"<<processor_s->name());
373 //std::cout<<"jak:"<<__FILE__<<std::endl;
374
375 sc = processor->executeEvent((void*)feStore);
376
377 //EFPSC_DBG1("efpsc::SC::Process","after executeEvent(fe)");
378
379 //std::cout<<"jak:"<<__FILE__<<std::endl;
380 if(m_outLev<=2)std::cout<<"efpsc::SC::process "<<"after executeEvent(fe)"<<std::endl;
381 if( sc.isFailure() ) {
382 //EFPSC_DBG1("efpsc::SC::process", "Error for executeEvent in the ApplicationMgr " << processor_s->name());
383 if(m_outLev<=4)std::cout<<"efpsc::SC::process "<<"Error for executeEvent in the ApplicationMgr "
384 << processor_s->name()<<std::endl;
385 }
386 else {
387 SmartIF<IEFEventLoopMgr> processor_psc( m_eventLoopMgr);
388 //
389 //--- ef Decision and Result from Pesa
390 //
391 //std::cout<<"jak:"<<__FILE__<<std::endl;
392 efDecision_s = processor_psc->EF_Decision();
393
394 //std::cout<<"jak:"<<__FILE__<<std::endl;
395 //EFPSC_DBG1("efpsc::SC::Process","after EF_Decision. EFdecision is: "<<efDecision_s);
396 if(m_outLev<=3)std::cout<<"efpsc::SC::process "<<"after EF_Decision. EFdecision is: "
397 <<efDecision_s<<std::endl;
398 sdStore=(uint32_t*)processor_psc->EF_Fragment_Address();
399 //std::cout<<"jak:"<<__FILE__<<std::endl;
400 if(sdStore==NULL){
401 //EFPSC_DBG1("efpsc::SC::process","EF_Fragment_Address() returns NULL pointer");
402 if(m_outLev<=2)std::cout<<"efpsc::SC::process "
403 <<"EF_Fragment_Address() returns NULL pointer"<<std::endl;
404 }
405 //Hard coded (One must change it in the future):
406 //EF_Decision==Accepted--> efDecision=2
407 //EF_Decision==Rejected--> efDecision=1
408 //EF_Decision==Error--> efDecision=0
409 /*
410 if(efDecision_s=="Accepted"){
411 //efDecision=2;
412 //Append EFResult to the Event Fragment
413 EFPSC_DBG1("efpsc::SC::process", "EFResult is going to be appended to the Event Fragment");
414 }else if(efDecision_s=="Rejected"){
415 //efDecision=1;
416 EFPSC_DBG1("efpsc::SC::process", "No EFResult is going to be appended to the Event Fragment");
417
418 }else{
419 //efDecision=0;
420 EFPSC_DBG1("efpsc::SC::process", "an Error was obtained when running algorithms on the Event.");
421 EFPSC_DBG1("efpsc::SC::process", "No EFResult is going to be appended to the Event Fragment");
422 }
423 */
424 efBitPattern.resize(4, 0); //zoujh: Just a place holder
425 if(efDecision_s=="Junk") efBitPattern[0]=1<<0;
426 //else if(efDecision_s=="GJunk") efBitPattern[0]=(1<<0)+(1<<1);
427 else if(efDecision_s=="GJunk") efBitPattern[0]=(1<<1);
428 else if(efDecision_s=="Beamgas") efBitPattern[0]=1<<2;
429 //else if(efDecision_s=="GBeamgas") efBitPattern[0]=(1<<2)+(1<<3);
430 else if(efDecision_s=="GBeamgas") efBitPattern[0]=(1<<3);
431 else if(efDecision_s=="Cosmic") efBitPattern[0]=1<<4;
432 //else if(efDecision_s=="GCosmic") efBitPattern[0]=(1<<4)+(1<<5);
433 else if(efDecision_s=="GCosmic") efBitPattern[0]=(1<<5);
434 else if(efDecision_s=="EBhabha") efBitPattern[0]=1<<6;
435 //else if(efDecision_s=="GEBhabha") efBitPattern[0]=(1<<6)+(1<<7);
436 else if(efDecision_s=="GEBhabha") efBitPattern[0]=(1<<7);
437 else if(efDecision_s=="BBhabha") efBitPattern[0]=1<<8;
438 //else if(efDecision_s=="GBBhabha") efBitPattern[0]=(1<<8)+(1<<9);
439 else if(efDecision_s=="GBBhabha") efBitPattern[0]=(1<<9);
440 else if(efDecision_s=="Dimuon") efBitPattern[0]=1<<10;
441 //else if(efDecision_s=="GDimuon") efBitPattern[0]=(1<<10)+(1<<11);
442 else if(efDecision_s=="GDimuon") efBitPattern[0]=(1<<11);
443 else if(efDecision_s=="Diphoton") efBitPattern[0]=1<<12;
444 //else if(efDecision_s=="GDiphoton") efBitPattern[0]=(1<<12)+(1<<13);
445 else if(efDecision_s=="GDiphoton") efBitPattern[0]=(1<<13);
446 else if(efDecision_s=="Hadron") efBitPattern[0]=1<<14;
447 //else if(efDecision_s=="GHadron") efBitPattern[0]=(1<<14)+(1<<15);
448 else if(efDecision_s=="GHadron") efBitPattern[0]=(1<<15);
449 else if(efDecision_s=="Twophoton") efBitPattern[0]=1<<16;
450 //else if(efDecision_s=="GTwophoton") efBitPattern[0]=(1<<16)+(1<<17);
451 else if(efDecision_s=="GTwophoton") efBitPattern[0]=(17);
452 else if(efDecision_s=="RandomTrg") efBitPattern[0]=1<<31;
453 else if(efDecision_s=="Error") efBitPattern[0]=1<<30;
454 else if(efDecision_s=="Other") efBitPattern[0]=1<<29;
455 else efBitPattern[0]=1<<28;
456 efBitPattern[1]=processor_psc->EF_Algorithm_Tag();
457 efBitPattern[2]=processor_psc->EF_Version();
458 efBitPattern[3]=processor_psc->EF_Total_Energy();
459 //EFPSC_DBG1("efpsc::SC::process", "**************end of psc process!**************"<<std::endl);
460 if(m_outLev<=2)std::cout<<"efpsc::SC::process "
461 <<"**************end of psc process!**************"<<std::endl;
462 }
463 }
464 else {
465 //EFPSC_DBG1("efpsc::SC::process", "executeEvent ApplicationMgr : no valid event processor ");
466 if(m_outLev<=5)std::cout<<"efpsc::SC::process "
467 <<"executeEvent ApplicationMgr : no valid event processor "<<std::endl;
468 return false;
469 }
470
471 }
472 else {
473 return false;
474 }
475 return true;
476}
477
Defines the error and reporting policies.
#define NULL
virtual bool prepareForRun(int run_number)
Definition: SC.cxx:337
virtual ~SC()
Definition: SC.cxx:53
virtual bool unconfigure(void)
Definition: SC.cxx:262
virtual bool configure(const std::string &config)
Definition: SC.cxx:59
SC()
Definition: SC.cxx:34
virtual bool process(const uint32_t *&feStore, const uint32_t *&sdStore, std::string &efDecision_s, std::vector< uint32_t > &efBitPattern)
Definition: SC.cxx:349