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