BOSS 7.0.8
BESIII Offline Software System
Loading...
Searching...
No Matches
BesVisAlg.cxx
Go to the documentation of this file.
12#include "EventModel/Event.h"
14#include <assert.h>
15/////////////////////////////////////////////////////////////////////////////
16int BesVisAlg::counter = 0; // static data member
17
18BesVisAlg::BesVisAlg(const std::string& name, ISvcLocator* pSvcLocator) :
19 Algorithm(name, pSvcLocator)
20{
21 // Part 1: Declare the properties
22 declareProperty("TestVec",testVec);
23 declareProperty("OutputShareFile", f_rootOutputFile);
24 declareProperty("InputGeometryFile", f_geoInputFile);
25 declareProperty("DisplayMode", m_mode=0); // offline mode: 0 online mode:1
26 // Part 2: Define some semaphore operate flag
27 // semaphore start_value
28 start_val[0] = 1; // free-space = 1
29 start_val[1] = 0; // output-shore = 0
30
31 // acquire semaphore, decrease resource supply
32 acquire.sem_num = 0;
33 acquire.sem_op = -1;
34 acquire.sem_flg = SEM_UNDO;
35
36 // release semaphore, increase resource supply
37 release.sem_num = 0;
38 release.sem_op = 1;
39 release.sem_flg = SEM_UNDO;
40
41 recdis = NULL;
42 recTrack1 = NULL;
43 mdchit = NULL;
44 tofTrack = NULL;
45 muctrk = NULL;
46
47}
48
49// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
51 // Part 1: Get the messaging service, print where you are
52 MsgStream log(msgSvc(), name());
53 log << MSG::INFO << " BesVisAlg ~BesVisAlg()" << endreq;
54
55
56 // Part 2: Delete semaphore
57 //if (semctl(semid, 0, IPC_RMID, 0) == -1)
58 // log << MSG::ERROR << "Delete semaphore" << endreq;
59 //else
60 // log << MSG::INFO << "Delete semaphore" << endreq;
61
62 // Part 3: Delete temp file
63 //if (remove(BUFFER) == -1)
64 // log << MSG::ERROR << "delete -- temp file" << endreq;
65 //else
66 // log << MSG::INFO << "Delete temp file" << endreq;
67
68}
69
70//**************************************************************************
72
73 // Part 1: Get the messaging service, print where you are
74 MsgStream log(msgSvc(), name());
75 log << MSG::INFO << " BesVisAlg initialize()" << endreq;
76 StatusCode status = StatusCode::SUCCESS;
77
78 // Part 2: Print out the property values
79//############################################################
80 IService* isvc = 0;
81 status = serviceLocator()->service("RootCnvSvc", isvc, false);
82 if ( !status.isSuccess() )
83 status = serviceLocator()->service("EventCnvSvc", isvc, true);
84 if ( status.isSuccess() )
85 status = isvc->queryInterface(IID_IRootCnvSvc, (void**)&m_cnvSvc);
86 status = hasWrite();
87 if ( status.isSuccess()){
88 log << MSG::INFO << "share file writed -- success"
89 << endreq;
90 }
91 else {
92 log << MSG::ERROR << "share file writed -- ERROR!!!!!"
93 << endreq;
94 }
95//############################################################
96
97 // Part 2: Print out the property values
98 log << MSG::INFO << " OutputFile = " << f_rootOutputFile << endreq;
99
100 for (unsigned int i=0; i<testVec.size(); i++) {
101 log << MSG::INFO << " MyStringVec[" << i << "] = "
102 << testVec[i] << endreq;
103 }
104
105 // Part 3: Initialize semphore
106 m_pid = getpid();
107 log << MSG::ERROR << "BesVisAlg process PID: [" << m_pid << "]"
108 << endreq;
109
110 log << MSG::ERROR << "Create and initialize semaphore" << endreq;
111 if ((semid = semget((int)m_pid, 2, IPC_CREAT | IPC_EXCL | 0666)) != -1){
112 arg.array = start_val;
113 log << MSG::ERROR << "Semaphore ID:" << semid << endreq;
114
115 if (semctl(semid, 0, SETALL, arg) == -1){
116 log << MSG::ERROR << "semctl -- parent -- initialization"
117 << endreq;
118 exit(1);
119 }
120
121 if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
122 log << MSG::ERROR << "semctl -- GETVAL" << endreq;
123 exit(1);
124 }
125
126 if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
127 log << MSG::ERROR << "semctl -- GETVAL" << endreq;
128 exit(1);
129 }
130 }
131 else {
132 log << MSG::INFO << "semget -- parent -- creation" << endreq;
133 exit(2);
134 }
135 //******************************
136 // Debug information
137 //*******************************
138 //log << MSG::INFO << "semaphore ID: " << semid << endreq;
139 //log << MSG::ERROR << "set init sem_value_FREE-SPACE: " << sem_value_F << endreq;
140 //log << MSG::ERROR << "set init sem_value_OUTPUT-STORE: " << sem_value_O << endreq;
141
142 // Part 4: fork consumer process
143 if ((c_pid = fork()) == -1){
144 log << MSG::ERROR << "fork -- consumer" << endreq;
145 exit(5);
146 }
147 else if (c_pid == 0){
148 // enter consumer logic
149 log << MSG::INFO << "Parent fork consumer: ppid = " << getppid()
150 << "; pid = " << getpid() << endreq;
151
152 // convert msg to char[] and transfer them to child process
153 char msg_pid[25];
154 sprintf(msg_pid, "%d", m_pid);
155
156 const char *msg_sleep = testVec[1].c_str();
157
158 log << MSG::INFO << "msg_pid: " << msg_pid << endreq;
159 log << MSG::INFO << "Consumer sleep time: " << msg_sleep
160 << " seconds." << endreq;
161
162 //execute besvis.exe
163 execlp("besvis.exe", "besvis.exe",
164 "-B", msg_pid, "-e", f_rootOutputFile.c_str(),
165 "-g", f_geoInputFile.c_str(), (char *)NULL );
166
167 //execlp("./a.out", "consumer", msg_pid, "5", (char *)NULL);
168 log << MSG::ERROR << "exec -- consumer" << endreq;
169 exit(6);
170 }
171
172
173 return StatusCode::SUCCESS;
174}
175
176// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
177
178StatusCode BesVisAlg::execute() {
179
180 // Part 1: Get the messaging service, print where you are
181 MsgStream log(msgSvc(), name());
182 log << MSG::INFO << "BesVisAlg execute()" << endreq;
183
184 // Part 2: Producer execute
185 const char *msg_sleep = testVec[0].c_str();
186 producer(atoi(msg_sleep));
187
188 return StatusCode::SUCCESS;
189}
190
191// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
192
194
195 // Part 1: Get the messaging service, print where you are
196 MsgStream log(msgSvc(), name());
197 log << MSG::INFO << "BesVisAlg finalize()" << endreq;
198
199 // Part 2: Waiting consumer process accessing the data
200 // and then kill it
201 while (1){
202 if (hasRead()) break;
203 else sleep(5);
204 }
205
206 // Part 3: Delete semaphore
207 if (semctl(semid, 0, IPC_RMID, 0) == -1)
208 log << MSG::ERROR << "Delete semaphore" << endreq;
209 else
210 log << MSG::INFO << "Delete semaphore" << endreq;
211
212 int status;
213 pid_t wait_pid;
214 cout << "wait for besvis terminate" << endl;
215 while ( wait_pid = waitpid(c_pid, &status, 0) ){
216 log << MSG::INFO << "Wait on PID: " << c_pid << " returns status of: "
217 << status << endreq;
218 if (wait_pid == -1) break;
219 sleep(5);
220 }
221 cout << "finalize" << endl;
222 return StatusCode::SUCCESS;
223}
224
225// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
226StatusCode BesVisAlg::producer(int p_sleep){
227 // Part 1: Get the messaging service, print where you are
228 MsgStream log(msgSvc(), name());
229 log << MSG::INFO << "Producer work" << endreq;
230 StatusCode status = StatusCode::SUCCESS;
231
232 // Part 3: operate semaphore -- FREE_SPACE
233 acquire.sem_num = FREE_SPACE;
234 //++++++++++++++++++++++++++++++
235 // Debug information
236 //++++++++++++++++++++++++++++++
237 //log << MSG::ERROR << "A -- No[" << counter << "] event "
238 //<< "will generate by producer." << endreq;
239 //
240 //log << MSG::ERROR << "semid: " << semid << endreq;
241 //
242 //log << MSG::ERROR << "Before change FREE_SPACE" << endreq;
243 //log << MSG::ERROR << "FREE_SPACE will change from 1 to 0" << endreq;
244 //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
245 // log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
246 // << endreq;
247 // exit(5);
248 //}
249 //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 1) " <<
250 //sem_value_F << endreq;
251
252 //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
253 // log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
254 // << endreq;
255 // exit(5);
256 //}
257 //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
258 //sem_value_O << endreq;
259
260 //++++++++++++++++++++++++++++++
261 if (semop(semid, &acquire, 1) == -1){
262 log << MSG::ERROR << "Producer -- decrease -- freeSpace"
263 << endreq;
264 exit(2);
265 }
266
267 //++++++++++++++++++++++++++++++
268 // Debug information
269 //++++++++++++++++++++++++++++++
270 //log << MSG::ERROR << "semid: " << semid << endreq;
271 //
272 //log << MSG::ERROR << "After change FREE_SPACE" << endreq;
273 //log << MSG::ERROR << "FREE_SPACE has changed from 1 to 0" << endreq;
274 //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
275 // log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
276 // << endreq;
277 // exit(5);
278 //}
279 //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
280 //sem_value_F << endreq;
281
282 //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
283 // log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
284 // << endreq;
285 // exit(5);
286 //}
287 //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
288 //sem_value_O << endreq;
289 //++++++++++++++++++++++++++++++
290
291 //Part 4: open file and write
292 // produce rand number, will be replaced by data industry
293 //sleep(p_sleep);
294 //srand((unsigned)m_pid);
295 //int n = rand() % 99 + 1;
296
297 //FILE *fptr;
298 //if ((fptr = fopen("./buffer", "w")) == NULL){
299 // log << MSG::ERROR << "BUFFER" << endreq;
300 // exit(3);
301 //}
302 //fprintf(fptr, "%d \n", n);
303 //fclose(fptr);
304 //++++++++++++++++++++++++++++++
305
306// status = hasWrite();
307// if ( status.isSuccess()){
308// log << MSG::INFO << "share file writed -- success"
309// << endreq;
310// }
311// else {
312// log << MSG::ERROR << "share file writed -- ERROR!!!!!"
313// << endreq;
314// }
315//############################################################
316 /* status = collectObjects();
317 if ( !status.isSuccess()){
318 log <<MSG::ERROR << "collectObjects() error!" << endreq;
319 return status;
320 }
321 */
322
323 DataObject* obj = 0;
324 IOpaqueAddress *pAddress = 0;
325 // StatusCode status;
326 status = m_pDataProvider->retrieveObject("/Event", obj);
327 if ( status.isSuccess() ) {
328 status = m_pConversionSvc->createRep(obj, pAddress);
329 }
330
331 obj = 0;
332 pAddress = 0;
333 status = m_pDataProvider->retrieveObject("/Event/Trig", obj);
334 if ( status.isSuccess() ) {
335 status = m_pConversionSvc->createRep(obj, pAddress);
336 }
337 obj = 0;
338 pAddress = 0;
339 status = m_pDataProvider->retrieveObject("/Event/Trig/TrigData", obj);
340 if ( status.isSuccess() ) {
341 status = m_pConversionSvc->createRep(obj, pAddress);
342 }
343 obj = 0;
344 pAddress = 0;
345 status = m_pDataProvider->retrieveObject("/Event/EventHeader", obj);
346 if ( status.isSuccess() ) {
347 status = m_pConversionSvc->createRep(obj, pAddress);
348 }
349 obj = 0;
350 pAddress = 0;
351 status = m_pDataProvider->retrieveObject("/Event/Digi", obj);
352 if ( status.isSuccess() ) {
353 status = m_pConversionSvc->createRep(obj, pAddress);
354 }
355 obj = 0;
356 pAddress = 0;
357 status = m_pDataProvider->retrieveObject("/Event/Digi/MdcDigiCol", obj);
358 if ( status.isSuccess() ) {
359 status = m_pConversionSvc->createRep(obj, pAddress);
360 }
361 obj = 0;
362 pAddress = 0;
363 status = m_pDataProvider->retrieveObject("/Event/Digi/TofDigiCol", obj);
364 if ( status.isSuccess() ) {
365 status = m_pConversionSvc->createRep(obj, pAddress);
366 }
367 obj = 0;
368 pAddress = 0;
369 status = m_pDataProvider->retrieveObject("/Event/Digi/EmcDigiCol", obj);
370 if ( status.isSuccess() ) {
371 status = m_pConversionSvc->createRep(obj, pAddress);
372 }
373 obj = 0;
374 pAddress = 0;
375 status = m_pDataProvider->retrieveObject("/Event/Digi/MucDigiCol", obj);
376 if ( status.isSuccess() ) {
377 status = m_pConversionSvc->createRep(obj, pAddress);
378 }
379 obj = 0;
380 pAddress = 0;
381 status = m_pDataProvider->retrieveObject("/Event/Recon", obj);
382 if ( status.isSuccess() ) {
383 status = m_pConversionSvc->createRep(obj, pAddress);
384 }
385 obj = 0;
386 pAddress = 0;
387 status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcHitCol", obj);
388 if ( status.isSuccess() ) {
389 status = m_pConversionSvc->createRep(obj, pAddress);
390 }
391 obj = 0;
392 pAddress = 0;
393 status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcTrackCol", obj);
394 if ( status.isSuccess() ) {
395 status = m_pConversionSvc->createRep(obj, pAddress);
396 }
397 obj = 0;
398 pAddress = 0;
399 status = m_pDataProvider->retrieveObject("/Event/Recon/MdcHOTCol", obj);
400 if ( status.isSuccess() ) {
401 status = m_pConversionSvc->createRep(obj, pAddress);
402 }
403 obj = 0;
404 pAddress = 0;
405 status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcDedxCol", obj);
406 if ( status.isSuccess() ) {
407 status = m_pConversionSvc->createRep(obj, pAddress);
408 }
409 obj = 0;
410 pAddress = 0;
411 status = m_pDataProvider->retrieveObject("/Event/Recon/RecTofTrackCol", obj);
412 if ( status.isSuccess() ) {
413 status = m_pConversionSvc->createRep(obj, pAddress);
414 }
415 //
416 obj = 0;
417 pAddress = 0;
418 status = m_pDataProvider->retrieveObject("/Event/Recon/RecEmcShowerCol", obj);
419 if ( status.isSuccess() ) {
420 status = m_pConversionSvc->createRep(obj, pAddress);
421 }
422 obj = 0;
423 pAddress = 0;
424 status = m_pDataProvider->retrieveObject("/Event/Recon/RecMucTrackCol", obj);
425 if ( status.isSuccess() ) {
426 status = m_pConversionSvc->createRep(obj, pAddress);
427 }
428 TRecTrackEvent *recEvt = m_cnvSvc->getRecTrackCnv()->getWriteObject();
429 TTrigEvent *trigEvt = m_cnvSvc->getTrigCnv()->getWriteObject();
430 TEvtHeader *evtHeader = m_cnvSvc->getEvtHeaderCnv()->getWriteObject();
431 TDigiEvent *digiEvt = m_cnvSvc->getDigiCnv()->getWriteObject();
432
433 if (recTrack1){
434 delete [] recTrack1;
435 recTrack1 = NULL;
436 }
437 if (recdis){
438 delete recdis;
439 recdis = NULL;
440 }
441 recdis = new TDisTrack();
442//add mdc tracks
443 recTrack1 = new TRecMdcTrack[20];
444 int no = 0;
445 no=(recEvt->getRecMdcTrackCol())->GetEntries();
446
447 std::cout<<" mdc trk number ="<< no <<std::endl;
448 if (no>20) no=20;
449 for (int i=0;i<no;i++){
450 const TRecMdcTrack* recTrack =recEvt->getRecMdcTrack(i);
451 /* Int_t charge = recTrack->charge();
452 Double_t pt = recTrack->pxy();
453 Double_t pz = recTrack->pz();*/
454 (recTrack1+i)->setTRecMdcTrack(recTrack);
455 recdis->addRecMdcTrack(recTrack1+i);
456 }
457
458//add tof tracks
459 if (tofTrack){
460 delete [] tofTrack;
461 tofTrack = NULL;
462 }
463 tofTrack = new TRecTofTrack[200];
464 no=0;
465 no = (recEvt->getTofTrackCol())->GetEntries();
466 std::cout<<" tof trk number ="<< no <<std::endl;
467 if (no>200) no =200;
468 for (int i=0;i<no;i++){
469 const TRecTofTrack* tofTrack1 =recEvt->getTofTrack(i);
470 (tofTrack+i)->setTRecTofTrack(tofTrack1);
471 recdis->addTofTrack(tofTrack+i);
472 }
473
474//add mdchits
475 if (mdchit){
476 delete [] mdchit;
477 mdchit = NULL;
478 }
479 mdchit = new TRecMdcHit[1000];
480 no=0;
481 no = (recEvt->getRecMdcHitCol())->GetEntries();
482 std::cout<<" mdc hits number ="<< no <<std::endl;
483 if (no>1000) no =1000;
484 for (int i=0;i<no;i++){
485 const TRecMdcHit* mdchit1 =recEvt->getRecMdcHit(i);
486 (mdchit+i)->setTRecMdcHit(mdchit1);
487 recdis->addRecMdcHit(mdchit+i);
488 }
489//add muctrks
490 if (muctrk){
491 delete [] muctrk;
492 muctrk = NULL;
493 }
494 muctrk = new TRecMucTrack[20];
495 no=0;
496 no = (recEvt->getMucTrackCol())->GetEntries();
497
498 std::cout<<" muc trk number ="<< no <<std::endl;
499 if (no>20) no=20;
500 for (int i=0;i<no;i++){
501 const TRecMucTrack* mucTrack1 =recEvt->getMucTrack(i);
502 (muctrk+i)->setTRecMucTrack(mucTrack1);
503 recdis->addMucTrack(muctrk+i);
504 }
505
506//add emcshowers
507 if (emcshower){
508 delete [] emcshower;
509 emcshower=NULL;
510 }
511 emcshower = new TRecEmcShower[20];
512 no=0;
513 no = (recEvt->getEmcShowerCol())->GetEntries();
514 std::cout<<" emc trk number ="<< no <<std::endl;
515 if (no>20) no=20;
516 for (int i=0;i<no;i++){
517 const TRecEmcShower* rec_emc =recEvt->getEmcShower(i);
518 (emcshower+i)->setTRecEmcShower(rec_emc);
519 recdis->addEmcShower(emcshower+i);
520 }
521
522
523 TFile file(f_rootOutputFile.c_str(),"RECREATE");
524 TTree tree("Event","Event");
525 tree.Branch("TDisTrack","TDisTrack",&recdis,64000,1);
526 tree.Branch("TDigiEvent", "TDigiEvent", &digiEvt, 64000, 1);
527 tree.Branch("TEvtHeader","TEvtHeader",&evtHeader,64000,1);
528 tree.Branch("TTrigEvent","TTrigEvent",&trigEvt,64000,1);
529 tree.Fill();
530 file.Write();
531 file.Close();
532 recdis->Clear();
533
534 if (m_mode == 1){
535 commonData tmp;
536 tmp.clear();
537 }
538
539
540
541//############################################################
542 //Part 5: operate semaphore -- OUTPUT_STORE, add event counter
543 release.sem_num = OUTPUT_STORE;
544 //++++++++++++++++++++++++++++++
545 // Debug information
546 //++++++++++++++++++++++++++++++
547 //log << MSG::ERROR << "B -- No[" << counter++ << "] event "
548 //<< "has deposited by producer." << endreq;
549 //
550 //log << MSG::ERROR << "Before change OUTPUT_STORE" << endreq;
551 //log << MSG::ERROR << "OUTPUT_STORE will change from 0 to 1" << endreq;
552 //log << MSG::ERROR << "semid: " << semid << endreq;
553 //
554 //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
555 // log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
556 // << endreq;
557 // exit(5);
558 //}
559 //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
560 //sem_value_F << endreq;
561 //
562 //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
563 // log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
564 // << endreq;
565 // exit(5);
566 //}
567 //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
568 //sem_value_O << endreq;
569 //++++++++++++++++++++++++++++++
570
571 if (semop(semid, &release, 1) == -1){
572 log << MSG::ERROR << "Producer -- increase -- storage"
573 << endreq;
574 exit(4);
575 }
576 //++++++++++++++++++++++++++++++
577 // Debug information
578 //++++++++++++++++++++++++++++++
579 //log << MSG::ERROR << "After change OUTPUT_STORE" << endreq;
580 //log << MSG::ERROR << "OUTPUT_STORE has changed from 0 to 1" << endreq;
581
582 //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
583 // log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
584 // << endreq;
585 // exit(5);
586 //}
587 //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
588 //sem_value_F << endreq;
589 //
590 //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
591 // log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
592 // << endreq;
593 // exit(5);
594 //}
595 //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 1) " <<
596 //sem_value_O << endreq;
597 //++++++++++++++++++++++++++++++
598
599 //TFile* f = new TFile("myShare.root", "read");
600 //TTree* t = (TTree*)f->Get("Event");
601 //std::cout << "BesVisAlg read file for debug" << std::endl;
602 //t->Print();
603 return status;
604}
605
606// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
607bool BesVisAlg::hasRead(){
608 // Part 1: Get the messaging service, print where you are
609 MsgStream log(msgSvc(), name());
610 log << MSG::INFO << "hadRead()" << endreq;
611
612 // Part 2: Testing semaphore value
613 if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
614 log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
615 << endreq;
616 exit(5);
617 }
618 log << MSG::INFO << "Semaphore FREE_SPACE has value of " <<
619 sem_value_F << endreq;
620
621 if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
622 log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
623 << endreq;
624 exit(5);
625 }
626 log << MSG::INFO << "Semaphore OUTPUT_STORE has value of " <<
627 sem_value_O << endreq;
628
629 if ((sem_value_F == 1) && (sem_value_O == 0)) return true;
630 else return false;
631
632}
633
634// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
635StatusCode BesVisAlg::hasWrite(){
636 MsgStream log(msgSvc(), name());
637 log << MSG::INFO << "hasWrite()" << endreq;
638 StatusCode status = StatusCode::SUCCESS;
639
640 int statusCode;
641 //statusCode = remove(f_rootOutputFile.c_str());
642 //log << MSG::ERROR << "remove file(" << f_rootOutputFile << "): " << statusCode << endreq;
643
644 status = getSvc();
645 if ( !status.isSuccess()){
646 log <<MSG::ERROR << "getSvc() error!" << endreq;
647 return StatusCode::SUCCESS;
648 }
649
650
651 status = collectObjects();
652 if ( !status.isSuccess()){
653 log <<MSG::ERROR << "collectObjects() error!" << endreq;
654 return StatusCode::SUCCESS;
655 }
656
657//************************************************************************
658//
659//
660//***********************************************************************
661// status = write2file();
662// if ( !status.isSuccess()){
663// log <<MSG::ERROR << "write2file() error!" << endreq;
664// return status;
665// }
666//
667// status = finishSvc();
668// if ( !status.isSuccess()){
669// log <<MSG::ERROR << "finishSvc() error!" << endreq;
670// return status;
671// }
672
673 return status;
674
675}
676
677// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
678StatusCode BesVisAlg::getSvc(){
679 MsgStream log(msgSvc(), name());
680 log << MSG::INFO << "getSvc()" << endreq;
681 StatusCode status = StatusCode::SUCCESS;
682
683//#################################
684 ItemNames m_itemNames;
685 m_itemNames.push_back("/Event#1");
686 m_itemNames.push_back("/Event/EventHeader#1");
687
688 m_itemNames.push_back("/Event/Digi#1");
689 m_itemNames.push_back("/Event/Digi/MdcDigiCol#1");
690 m_itemNames.push_back("/Event/Digi/TofDigiCol#1");
691 m_itemNames.push_back("/Event/Digi/EmcDigiCol#1");
692 m_itemNames.push_back("/Event/Digi/MucDigiCol#1");
693
694 m_itemNames.push_back("/Event/Recon#1");
695 m_itemNames.push_back("/Event/Recon/RecMdcHitCol#1");
696 m_itemNames.push_back("/Event/Recon/RecMdcTrackCol#1");
697
698 m_itemNames.push_back("/Event/Trig#1");
699 m_itemNames.push_back("/Event/Trig/TrigData#1");
700 //m_itemNames.push_back("/Event/Recon/MdcHOTCol#1");
701 //m_itemNames.push_back("/Event/Recon/RecMdcDedxCol#1");
702 //m_itemNames.push_back("/Event/Recon/RecMdcDedxHitCol#1");
703 //m_itemNames.push_back("/Event/Recon/RecMdcKalTrackCol#1");
704 //m_itemNames.push_back("/Event/Recon/RecEsTimeCol#1");
705 //m_itemNames.push_back("/Event/Recon/RecExtTrackCol#1");
706 //m_itemNames.push_back("/Event/Recon/RecBTofHitCol#1");
707 //m_itemNames.push_back("/Event/Recon/RecETofHitCol#1");
708 //m_itemNames.push_back("/Event/Recon/RecTofTrackCol#1");
709 //m_itemNames.push_back("/Event/Recon/RecBTofCalHitCol#1");
710 //m_itemNames.push_back("/Event/Recon/RecETofCalHitCol#1");
711 //m_itemNames.push_back("/Event/Recon/RecEmcHitCol#1");
712 //m_itemNames.push_back("/Event/Recon/RecEmcClusterCol#1");
713 //m_itemNames.push_back("/Event/Recon/RecEmcShowerCol#1");
714 //m_itemNames.push_back("/Event/Recon/MucRecHitCol#1");
715 //m_itemNames.push_back("/Event/Recon/RecMucTrackCol#1");
716 //m_itemNames.push_back("/Event/Recon/RecMdcKalHelixSegCol#1");
717 //m_itemNames.push_back("/Event/Recon/EvtRecEvent#1");
718 //m_itemNames.push_back("/Event/Recon/EvtRecTrackCol#1");
719 //m_itemNames.push_back("/Event/Recon/EvtRecVertexCol#1");
720//#################################
721 clearItems(m_itemList);
722 ItemNames::iterator i;
723 for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
724 addItem(m_itemList, *i);
725 }
726
727 status = serviceLocator()->service("EventDataSvc", m_pDataManager, true);
728 if ( !status.isSuccess() ) {
729 log << MSG::FATAL << "Unable to locate IDataManagerSvc interface"
730 << endreq;
731 return status;
732 }
733
734 status = serviceLocator()->service("EventDataSvc", m_pDataProvider, true);
735 if ( !status.isSuccess() ) {
736 log << MSG::FATAL << "Unable to locate IDataProviderSvc interface"
737 << endreq;
738 return status;
739 }
740
741 status = serviceLocator()->service("EventCnvSvc", m_pConversionSvc, true);
742 if ( !status.isSuccess() ) {
743 log << MSG::FATAL << "Unable to locate IConversionSvc interface"
744 << endreq;
745 return status;
746 }
747
748 return status;
749}
750
751// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
752StatusCode BesVisAlg::finishSvc(){
753 MsgStream log(msgSvc(), name());
754 log << MSG::INFO << "finishSvc()" << endreq;
755 StatusCode status = StatusCode::SUCCESS;
756
757 status = m_pRootInterface->f_finalize();
758 if ( !status.isSuccess())
759 log << MSG::ERROR << "f_finalize() error" << endreq;
760
761 status = m_pConversionSvc->commitOutput(f_rootOutputFile.c_str(), true);
762 if ( !status.isSuccess())
763 log << MSG::ERROR << "commitOutput() error" << endreq;
764
765 clearItems(m_itemList);
766
767 return StatusCode::SUCCESS;
768}
769
770// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
771// Add item to output streamer list
772void BesVisAlg::addItem(Items& itms, const std::string& descriptor) {
773 MsgStream log(msgSvc(), name());
774 int level = 0;
775 size_t sep = descriptor.rfind("#");
776 std::string obj_path (descriptor,0,sep);
777 std::string slevel (descriptor,sep+1,descriptor.length());
778 if ( slevel == "*" ) {
779 level = 9999999;
780 }
781 else {
782 level = atoi(slevel.c_str());
783 }
784 size_t idx = obj_path.find("/",1);
785 while (idx != std::string::npos) {
786 std::string sub_item = obj_path.substr(0,idx);
787 if ( 0 == findItem(sub_item) ) {
788 addItem(itms, sub_item+"#1");
789 }
790 idx = obj_path.find("/",idx+1);
791 }
792 DataStoreItem* item = new DataStoreItem(obj_path, level);
793 log << MSG::DEBUG << "Adding OutputStream item " << item->path()
794 << " with " << item->depth()
795 << " level(s)." << endreq;
796 itms.push_back( item );
797}
798
799// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
800void BesVisAlg::clearItems(Items& itms) {
801 for ( Items::iterator i = itms.begin(); i != itms.end(); i++ ) {
802 delete (*i);
803 }
804 itms.erase(itms.begin(), itms.end());
805}
806
807// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
808// Find single item identified by its path (exact match)
809DataStoreItem*
810BesVisAlg::findItem(const std::string& path) {
811 for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i) {
812 if ( (*i)->path() == path ) return (*i);
813 }
814 return 0;
815}
816
817// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
818StatusCode BesVisAlg::collectObjects(){
819 MsgStream log(msgSvc(), name());
820 StatusCode status = StatusCode::SUCCESS;
821 Items::iterator i;
822
823 // Traverse the tree and collect the requested objects
824
825 for ( i = m_itemList.begin(); i != m_itemList.end(); i++ ) {
826 DataObject* obj = 0;
827 IOpaqueAddress *pAddress = 0;
828 m_currentItem = (*i);
829
830 status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
831 if ( status.isSuccess() ) {
832 status = m_pConversionSvc->createRep(obj, pAddress);
833 }
834 else {
835 log << MSG::WARNING << "Cannot write mandatory object(s) (Not found): "
836 << m_currentItem->path() << endreq;
837 }
838 }
839
840
841 return StatusCode::SUCCESS;
842}
843
844StatusCode BesVisAlg::write2file(){
845 MsgStream log(msgSvc(), name());
846 StatusCode status = StatusCode::SUCCESS;
847
848 log << MSG::INFO << "write2file()" << endreq;
849
850 const std::string treename("Event");
851// ************************************************************************
852//
853// single event output stream
854//
855// ***********************************************************************
856// TDigiEvent
857// ***********************************************************************
858
859 TDigiEvent *pTRawEvent = commonData::m_recEvt;
860 if ( pTRawEvent == 0) {
861 log << MSG::WARNING << "Can not get point TDigiEvent" << endreq;
862 }
863
864 const std::string rawBranchname("TDigiEvent");
865 int branchnr = -1;
866
867 m_pRootInterface = RootInterface::Instance(log);
868 m_pRootInterface->f_addOutput(treename, f_rootOutputFile.c_str(), 1, 64000, 1);
869
870 if (pTRawEvent != 0) m_pRootInterface->f_createBranch(treename, rawBranchname,
871 pTRawEvent->ClassName(),
872 &pTRawEvent, branchnr);
873
874// ***********************************************************************
875// TEvtHeader
876// ***********************************************************************
877 TEvtHeader *pTEvtHeader = commonData::m_EvtHeader;
878 if ( pTEvtHeader == 0) {
879 log << MSG::WARNING << "Can not get point TEvtHeader" << endreq;
880 }
881
882 const std::string headerBranchname("TEvtHeader");
883 branchnr = -1;
884 if (pTEvtHeader != 0) m_pRootInterface->f_createBranch(treename, headerBranchname,
885 pTEvtHeader->ClassName(),
886 &pTEvtHeader, branchnr);
887
888// ***********************************************************************
889// TTrigEvent
890// ***********************************************************************
891 TTrigEvent *pTTrigEvent = commonData::m_trigEvt;
892 if ( pTTrigEvent == 0) {
893 log << MSG::WARNING << "Can not get point TTrigEvent" << endreq;
894 }
895
896 const std::string trigBranchname("TTrigEvent");
897 branchnr = -1;
898 if (pTTrigEvent != 0) m_pRootInterface->f_createBranch(treename, trigBranchname,
899 pTTrigEvent->ClassName(),
900 &pTTrigEvent, branchnr);
901
902
903// ***********************************************************************
904// TRecEvent
905// ***********************************************************************
907 if ( pTRecEvent == 0) {
908 log << MSG::WARNING << "Can not get point TRecEvent" << endreq;
909 }
910
911 const std::string recBranchname("TRecEvent");
912 branchnr = -1;
913 if (pTRecEvent != 0) m_pRootInterface->f_createBranch(treename, recBranchname,
914 pTRecEvent->ClassName(),
915 &pTRecEvent, branchnr);
916
917
918// ***********************************************************************
919 status = m_pRootInterface->f_fillTrees();
920 if (status.isFailure())
921 log << MSG::ERROR << "No Root tree was filled" << endreq;
922
923
924// ***********************************************************************
925 return status;
926
927}
struct sembuf acquire
Definition: BesClient.cxx:133
@ FREE_SPACE
Definition: BesVisAlg.h:146
@ OUTPUT_STORE
Definition: BesVisAlg.h:146
const int no
sprintf(cut,"kal_costheta0_em>-0.93&&kal_costheta0_em<0.93&&kal_pxy0_em>=0.05+%d*0.1&&kal_pxy0_em<0.15+%d*0.1&&NGch>=2", j, j)
char * file
Definition: DQA_TO_DB.cxx:15
const InterfaceID IID_IRootCnvSvc
IMessageSvc * msgSvc()
#define NULL
StatusCode finalize()
Definition: BesVisAlg.cxx:193
BesVisAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: BesVisAlg.cxx:18
StatusCode execute()
Definition: BesVisAlg.cxx:178
StatusCode initialize()
Definition: BesVisAlg.cxx:71
static TDigiEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: DigiCnv.h:35
static TEvtHeader * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: EvtHeaderCnv.h:37
static TRecTrackEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: RecTrackCnv.h:36
DigiCnv * getDigiCnv()
Definition: RootCnvSvc.h:154
RecTrackCnv * getRecTrackCnv()
Definition: RootCnvSvc.h:173
EvtHeaderCnv * getEvtHeaderCnv()
Definition: RootCnvSvc.h:174
TrigCnv * getTrigCnv()
Definition: RootCnvSvc.h:157
virtual StatusCode f_createBranch(const std::string &treename, const std::string &branchname, const char *classname, void *addr, int &branchnr)
virtual StatusCode f_finalize()
virtual StatusCode f_fillTrees()
virtual StatusCode f_addOutput(const std::string &treename, const std::string &file, int splitx=1, int bufsize=64000, int compression=1)
static RootInterface * Instance(MsgStream log)
singleton behaviour
void addRecMdcTrack(TRecMdcTrack *Track)
Add a TkrTrack into the Mdc data collection.
Definition: TDisTrack.cxx:109
void addTofTrack(TRecTofTrack *Track)
Definition: TDisTrack.cxx:131
void addMucTrack(TRecMucTrack *Track)
Add a MucTrack into the TOF Data collection.
Definition: TDisTrack.cxx:141
void Clear(Option_t *option="")
Definition: TDisTrack.cxx:68
void addRecMdcHit(TRecMdcHit *Hit)
Add a Rec Mdc Hit into the Mdc data collection.
Definition: TDisTrack.cxx:120
void addEmcShower(TRecEmcShower *Track)
Add a TkrTrack into the Emc data collection.
Definition: TDisTrack.cxx:152
const TObjArray * getTofTrackCol() const
retrieve the whole TObjArray of TofTrack Data
const TRecTofTrack * getTofTrack(Int_t i) const
retrieve a TofTrack From the collection, using the index into the array
const TRecMdcTrack * getRecMdcTrack(Int_t i) const
retrieve a MdcTrack from the collection, using the index into the array
const TObjArray * getEmcShowerCol() const
retrieve the whole TObjArray of EmcShower Data
const TObjArray * getRecMdcTrackCol() const
retrieve the whole TObjArray of RecMdcTrack Data
const TRecEmcShower * getEmcShower(Int_t i) const
retrieve a EmcShower from the collection, using the index into the array *‍/
const TObjArray * getMucTrackCol() const
retrieve the whole TObjArray of MucTrack Data
const TRecMucTrack * getMucTrack(Int_t i) const
retrieve a MucTrack From the collection, using the index into the array
const TRecMdcHit * getRecMdcHit(Int_t i) const
retrieve a RecMdcHit from the collection, using the index into the array
const TObjArray * getRecMdcHitCol() const
retrieve the whole TObjArray of RecMdcHit Data
static TTrigEvent * getWriteObject()
returns object to be written (maintained here for all DIGI-converters)
Definition: TrigCnv.h:35
static TEvtHeader * m_EvtHeader
Definition: commonData.h:113
static TDigiEvent * m_recEvt
Provide access to the ROOT event pointers.
Definition: commonData.h:125
static TTrigEvent * m_trigEvt
Provide access to the ROOT event pointers.
Definition: commonData.h:185
static TRecTrackEvent * m_rectrackEvt
Provide access to the ROOT event pointers.
Definition: commonData.h:200
void clear()
Definition: commonData.cxx:150
ushort * array
Definition: BesVisAlg.h:143