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