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