/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/EventDisplay/BesVisAlg/BesVisAlg-00-01-07/src/BesVisAlg.cxx

Go to the documentation of this file.
00001 #include "BesVisAlg/BesVisAlg.h"
00002 #include "RootEventData/TRecTrackEvent.h"
00003 #include "RootEventData/TDigiEvent.h"
00004 #include "RootEventData/TEvtHeader.h"
00005 #include "RootEventData/TTrigEvent.h"
00006 #include "RootCnvSvc/Rec/RecTrackCnv.h"
00007 #include "RootCnvSvc/Digi/DigiCnv.h"
00008 #include "RootCnvSvc/EvtHeaderCnv.h"
00009 #include "RootCnvSvc/Trig/TrigCnv.h"
00010 #include "RootCnvSvc/Trig/TrigDataCnv.h"
00011 #include "EventModel/EventHeader.h"
00012 #include "EventModel/Event.h"
00013 #include "EventModel/EventModel.h"
00014 #include <assert.h>
00016 int BesVisAlg::counter = 0;     // static data member
00017 
00018 BesVisAlg::BesVisAlg(const std::string& name, ISvcLocator* pSvcLocator) :
00019         Algorithm(name, pSvcLocator)
00020 {
00021     // Part 1: Declare the properties
00022     declareProperty("TestVec",testVec);
00023     declareProperty("OutputShareFile", f_rootOutputFile);
00024     declareProperty("InputGeometryFile", f_geoInputFile);
00025     declareProperty("DisplayMode", m_mode=0); // offline mode: 0 online mode:1
00026     // Part 2: Define some semaphore operate flag
00027     // semaphore start_value
00028     start_val[0] = 1;   // free-space = 1
00029     start_val[1] = 0;   // output-shore = 0
00030 
00031     // acquire semaphore, decrease resource supply
00032     acquire.sem_num = 0;
00033     acquire.sem_op = -1;
00034     acquire.sem_flg = SEM_UNDO;
00035 
00036     // release semaphore, increase resource supply
00037     release.sem_num = 0;
00038     release.sem_op = 1;
00039     release.sem_flg = SEM_UNDO;
00040 
00041     recdis = NULL;
00042     recTrack1 = NULL;
00043     mdchit = NULL;
00044     tofTrack = NULL;
00045     muctrk = NULL;
00046 
00047 }
00048 
00049 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00050 BesVisAlg::~BesVisAlg(){
00051     // Part 1: Get the messaging service, print where you are
00052     MsgStream log(msgSvc(), name());
00053     log << MSG::INFO << " BesVisAlg ~BesVisAlg()" << endreq;
00054 
00055 
00056     // Part 2: Delete semaphore
00057     //if (semctl(semid, 0, IPC_RMID, 0) == -1)
00058     //    log << MSG::ERROR << "Delete semaphore" << endreq;
00059     //else
00060     //    log << MSG::INFO <<  "Delete semaphore" << endreq;
00061 
00062     // Part 3: Delete temp file
00063     //if (remove(BUFFER) == -1)
00064     //    log << MSG::ERROR << "delete -- temp file" << endreq;
00065     //else
00066     //    log << MSG::INFO << "Delete temp file" << endreq;
00067 
00068 }
00069 
00070 //**************************************************************************
00071 StatusCode BesVisAlg::initialize(){
00072 
00073     // Part 1: Get the messaging service, print where you are
00074     MsgStream log(msgSvc(), name());
00075     log << MSG::INFO << " BesVisAlg initialize()" << endreq;
00076     StatusCode status = StatusCode::SUCCESS;
00077 
00078     // Part 2: Print out the property values
00079 //############################################################
00080     IService* isvc = 0;
00081     status = serviceLocator()->service("RootCnvSvc", isvc, false);
00082     if ( !status.isSuccess() )
00083         status = serviceLocator()->service("EventCnvSvc", isvc, true);
00084     if ( status.isSuccess() )
00085         status = isvc->queryInterface(IID_IRootCnvSvc, (void**)&m_cnvSvc);
00086     status = hasWrite();
00087     if ( status.isSuccess()){
00088         log << MSG::INFO << "share file writed -- success"
00089         << endreq;
00090     }
00091     else {
00092         log << MSG::ERROR << "share file writed -- ERROR!!!!!"
00093         << endreq;
00094     }
00095 //############################################################
00096 
00097     // Part 2: Print out the property values
00098     log << MSG::INFO << "  OutputFile = " << f_rootOutputFile << endreq;
00099 
00100     for (unsigned int i=0; i<testVec.size(); i++) {
00101         log << MSG::INFO << "  MyStringVec[" << i << "] = "
00102         << testVec[i] << endreq;
00103     }
00104 
00105     // Part 3: Initialize semphore
00106     m_pid = getpid();
00107     log << MSG::ERROR << "BesVisAlg process PID: [" << m_pid << "]"
00108     << endreq;
00109 
00110     log << MSG::ERROR << "Create and initialize semaphore" << endreq;
00111     if ((semid = semget((int)m_pid, 2, IPC_CREAT | IPC_EXCL | 0666)) != -1){
00112         arg.array = start_val;
00113         log << MSG::ERROR << "Semaphore ID:" << semid << endreq;
00114 
00115         if (semctl(semid, 0, SETALL, arg) == -1){
00116             log << MSG::ERROR << "semctl -- parent -- initialization"
00117             << endreq;
00118             exit(1);
00119         }
00120 
00121         if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00122             log << MSG::ERROR << "semctl -- GETVAL" << endreq;
00123             exit(1);
00124         }
00125 
00126         if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00127             log << MSG::ERROR << "semctl -- GETVAL" << endreq;
00128             exit(1);
00129         }
00130     }
00131     else {
00132         log << MSG::INFO << "semget -- parent -- creation" << endreq;
00133         exit(2);
00134     }
00135     //******************************
00136     // Debug information
00137     //*******************************
00138     //log << MSG::INFO << "semaphore ID: " << semid << endreq;
00139     //log << MSG::ERROR << "set init sem_value_FREE-SPACE: " << sem_value_F << endreq;
00140     //log << MSG::ERROR << "set init sem_value_OUTPUT-STORE: " << sem_value_O << endreq;
00141 
00142     // Part 4: fork consumer process
00143     if ((c_pid = fork()) == -1){
00144         log << MSG::ERROR << "fork -- consumer" << endreq;
00145         exit(5);
00146     }
00147     else if (c_pid == 0){
00148         // enter consumer logic
00149         log << MSG::INFO << "Parent fork consumer: ppid = " << getppid()
00150         << "; pid = " << getpid() << endreq;
00151 
00152         // convert msg to char[] and transfer them to child process
00153         char    msg_pid[25];
00154         sprintf(msg_pid, "%d", m_pid);
00155 
00156         const char      *msg_sleep = testVec[1].c_str();
00157 
00158         log << MSG::INFO << "msg_pid: " << msg_pid << endreq;
00159         log << MSG::INFO << "Consumer sleep time: " << msg_sleep
00160         << " seconds." << endreq;
00161 
00162         //execute besvis.exe
00163         execlp("besvis.exe", "besvis.exe",
00164                "-B", msg_pid, "-e", f_rootOutputFile.c_str(),
00165                "-g", f_geoInputFile.c_str(), (char *)NULL );
00166 
00167         //execlp("./a.out", "consumer", msg_pid, "5", (char *)NULL);
00168         log << MSG::ERROR << "exec -- consumer" << endreq;
00169         exit(6);
00170     }
00171 
00172 
00173     return StatusCode::SUCCESS;
00174 }
00175 
00176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00177 
00178 StatusCode BesVisAlg::execute() {
00179 
00180     // Part 1: Get the messaging service, print where you are
00181     MsgStream log(msgSvc(), name());
00182     log << MSG::INFO << "BesVisAlg execute()" << endreq;
00183 
00184     // Part 2: Producer execute
00185     const char  *msg_sleep = testVec[0].c_str();
00186     producer(atoi(msg_sleep));
00187 
00188     return StatusCode::SUCCESS;
00189 }
00190 
00191 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00192 
00193 StatusCode BesVisAlg::finalize() {
00194 
00195     // Part 1: Get the messaging service, print where you are
00196     MsgStream log(msgSvc(), name());
00197     log << MSG::INFO << "BesVisAlg finalize()" << endreq;
00198 
00199     // Part 2: Waiting consumer process accessing the data
00200     // and then kill it
00201     while (1){
00202         if (hasRead()) break;
00203         else    sleep(5);
00204     }
00205 
00206     // Part 3: Delete semaphore
00207     if (semctl(semid, 0, IPC_RMID, 0) == -1)
00208         log << MSG::ERROR << "Delete semaphore" << endreq;
00209     else
00210         log << MSG::INFO <<  "Delete semaphore" << endreq;
00211 
00212     int   status;
00213     pid_t wait_pid;
00214     cout << "wait for besvis terminate" << endl;
00215     while ( wait_pid = waitpid(c_pid, &status, 0) ){
00216         log << MSG::INFO << "Wait on PID: " << c_pid << " returns status of: "
00217         << status << endreq;
00218         if (wait_pid == -1) break;
00219         sleep(5);
00220     }
00221     cout << "finalize" << endl;
00222     return StatusCode::SUCCESS;
00223 }
00224 
00225 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00226 StatusCode BesVisAlg::producer(int p_sleep){
00227     // Part 1: Get the messaging service, print where you are
00228     MsgStream log(msgSvc(), name());
00229     log << MSG::INFO << "Producer work" << endreq;
00230     StatusCode status = StatusCode::SUCCESS;
00231 
00232     // Part 3: operate semaphore -- FREE_SPACE
00233     acquire.sem_num = FREE_SPACE;
00234     //++++++++++++++++++++++++++++++
00235     // Debug information
00236     //++++++++++++++++++++++++++++++
00237     //log << MSG::ERROR << "A -- No[" << counter << "] event "
00238     //<< "will generate by producer." << endreq;
00239     //
00240     //log << MSG::ERROR << "semid: " << semid << endreq;
00241     //
00242     //log << MSG::ERROR << "Before change FREE_SPACE" << endreq;
00243     //log << MSG::ERROR << "FREE_SPACE will change from 1 to 0" << endreq;
00244     //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00245     //    log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
00246     //    << endreq;
00247     //    exit(5);
00248     //}
00249     //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 1) " <<
00250     //sem_value_F << endreq;
00251 
00252     //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00253     //    log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
00254     //    << endreq;
00255     //    exit(5);
00256     //}
00257     //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
00258     //sem_value_O << endreq;
00259 
00260     //++++++++++++++++++++++++++++++
00261     if (semop(semid, &acquire, 1) == -1){
00262         log << MSG::ERROR << "Producer -- decrease -- freeSpace"
00263         << endreq;
00264         exit(2);
00265     }
00266 
00267     //++++++++++++++++++++++++++++++
00268     // Debug information
00269     //++++++++++++++++++++++++++++++
00270     //log << MSG::ERROR << "semid: " << semid << endreq;
00271     //
00272     //log << MSG::ERROR << "After change FREE_SPACE" << endreq;
00273     //log << MSG::ERROR << "FREE_SPACE has changed from 1 to 0" << endreq;
00274     //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00275     //    log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
00276     //    << endreq;
00277     //    exit(5);
00278     //}
00279     //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
00280     //sem_value_F << endreq;
00281 
00282     //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00283     //    log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
00284     //    << endreq;
00285     //    exit(5);
00286     //}
00287     //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
00288     //sem_value_O << endreq;
00289     //++++++++++++++++++++++++++++++
00290 
00291     //Part 4: open file and write
00292     // produce rand number, will be replaced by data industry
00293     //sleep(p_sleep);
00294     //srand((unsigned)m_pid);
00295     //int n = rand() % 99 + 1;
00296 
00297     //FILE              *fptr;
00298     //if ((fptr = fopen("./buffer", "w")) == NULL){
00299     //    log << MSG::ERROR << "BUFFER" << endreq;
00300     //    exit(3);
00301     //}
00302     //fprintf(fptr, "%d \n", n);
00303     //fclose(fptr);
00304     //++++++++++++++++++++++++++++++
00305 
00306 //    status = hasWrite();
00307 //    if ( status.isSuccess()){
00308 //        log << MSG::INFO << "share file writed -- success"
00309 //        << endreq;
00310 //    }
00311 //    else {
00312 //        log << MSG::ERROR << "share file writed -- ERROR!!!!!"
00313 //        << endreq;
00314 //    }
00315 //############################################################
00316     /*   status = collectObjects();
00317        if ( !status.isSuccess()){
00318            log <<MSG::ERROR << "collectObjects() error!" << endreq;
00319            return status;
00320        }
00321        */
00322 
00323     DataObject* obj = 0;
00324     IOpaqueAddress *pAddress = 0;
00325     //    StatusCode status;
00326     status = m_pDataProvider->retrieveObject("/Event", obj);
00327     if ( status.isSuccess() )  {
00328         status = m_pConversionSvc->createRep(obj, pAddress);
00329     }
00330 
00331     obj = 0;
00332     pAddress = 0;
00333     status = m_pDataProvider->retrieveObject("/Event/Trig", obj);
00334     if ( status.isSuccess() )  {
00335         status = m_pConversionSvc->createRep(obj, pAddress);
00336     }
00337     obj = 0;
00338     pAddress = 0;
00339     status = m_pDataProvider->retrieveObject("/Event/Trig/TrigData", obj);
00340     if ( status.isSuccess() )  {
00341         status = m_pConversionSvc->createRep(obj, pAddress);
00342     }
00343     obj = 0;
00344     pAddress = 0;
00345     status = m_pDataProvider->retrieveObject("/Event/EventHeader", obj);
00346     if ( status.isSuccess() )  {
00347         status = m_pConversionSvc->createRep(obj, pAddress);
00348     }
00349     obj = 0;
00350     pAddress = 0;
00351     status = m_pDataProvider->retrieveObject("/Event/Digi", obj);
00352     if ( status.isSuccess() )  {
00353         status = m_pConversionSvc->createRep(obj, pAddress);
00354     }
00355     obj = 0;
00356     pAddress = 0;
00357     status = m_pDataProvider->retrieveObject("/Event/Digi/MdcDigiCol", obj);
00358     if ( status.isSuccess() )  {
00359         status = m_pConversionSvc->createRep(obj, pAddress);
00360     }
00361     obj = 0;
00362     pAddress = 0;
00363     status = m_pDataProvider->retrieveObject("/Event/Digi/TofDigiCol", obj);
00364     if ( status.isSuccess() )  {
00365         status = m_pConversionSvc->createRep(obj, pAddress);
00366     }
00367     obj = 0;
00368     pAddress = 0;
00369     status = m_pDataProvider->retrieveObject("/Event/Digi/EmcDigiCol", obj);
00370     if ( status.isSuccess() )  {
00371         status = m_pConversionSvc->createRep(obj, pAddress);
00372     }
00373     obj = 0;
00374     pAddress = 0;
00375     status = m_pDataProvider->retrieveObject("/Event/Digi/MucDigiCol", obj);
00376     if ( status.isSuccess() )  {
00377         status = m_pConversionSvc->createRep(obj, pAddress);
00378     }
00379     obj = 0;
00380     pAddress = 0;
00381     status = m_pDataProvider->retrieveObject("/Event/Recon", obj);
00382     if ( status.isSuccess() )  {
00383         status = m_pConversionSvc->createRep(obj, pAddress);
00384     }
00385     obj = 0;
00386     pAddress = 0;
00387     status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcHitCol", obj);
00388     if ( status.isSuccess() )  {
00389         status = m_pConversionSvc->createRep(obj, pAddress);
00390     }
00391     obj = 0;
00392     pAddress = 0;
00393     status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcTrackCol", obj);
00394     if ( status.isSuccess() )  {
00395         status = m_pConversionSvc->createRep(obj, pAddress);
00396     }
00397     obj = 0;
00398     pAddress = 0;
00399     status = m_pDataProvider->retrieveObject("/Event/Recon/MdcHOTCol", obj);
00400     if ( status.isSuccess() )  {
00401         status = m_pConversionSvc->createRep(obj, pAddress);
00402     }
00403     obj = 0;
00404     pAddress = 0;
00405     status = m_pDataProvider->retrieveObject("/Event/Recon/RecMdcDedxCol", obj);
00406     if ( status.isSuccess() )  {
00407         status = m_pConversionSvc->createRep(obj, pAddress);
00408     }
00409     obj = 0;
00410     pAddress = 0;
00411     status = m_pDataProvider->retrieveObject("/Event/Recon/RecTofTrackCol", obj);
00412     if ( status.isSuccess() )  {
00413         status = m_pConversionSvc->createRep(obj, pAddress);
00414     }
00415     //
00416     obj = 0;
00417     pAddress = 0;
00418     status = m_pDataProvider->retrieveObject("/Event/Recon/RecEmcShowerCol", obj);
00419     if ( status.isSuccess() )  {
00420         status = m_pConversionSvc->createRep(obj, pAddress);
00421     }
00422     obj = 0;
00423     pAddress = 0;
00424     status = m_pDataProvider->retrieveObject("/Event/Recon/RecMucTrackCol", obj);
00425     if ( status.isSuccess() )  {
00426         status = m_pConversionSvc->createRep(obj, pAddress);
00427     }
00428     TRecTrackEvent *recEvt     = m_cnvSvc->getRecTrackCnv()->getWriteObject();
00429     TTrigEvent     *trigEvt    = m_cnvSvc->getTrigCnv()->getWriteObject();
00430     TEvtHeader     *evtHeader  = m_cnvSvc->getEvtHeaderCnv()->getWriteObject();
00431     TDigiEvent     *digiEvt    = m_cnvSvc->getDigiCnv()->getWriteObject();
00432 
00433     if (recTrack1){
00434         delete [] recTrack1;
00435         recTrack1 = NULL;
00436     }
00437     if (recdis){
00438         delete recdis;
00439         recdis = NULL;
00440     }
00441     recdis = new TDisTrack();
00442 //add mdc tracks
00443     recTrack1 = new TRecMdcTrack[20];
00444     int no = 0;
00445     no=(recEvt->getRecMdcTrackCol())->GetEntries();
00446 
00447     std::cout<<" mdc trk number ="<< no <<std::endl;
00448     if (no>20) no=20;
00449     for (int i=0;i<no;i++){
00450         const TRecMdcTrack* recTrack =recEvt->getRecMdcTrack(i);
00451         /*  Int_t    charge = recTrack->charge();
00452           Double_t pt     = recTrack->pxy();
00453           Double_t pz     = recTrack->pz();*/
00454         (recTrack1+i)->setTRecMdcTrack(recTrack);
00455         recdis->addRecMdcTrack(recTrack1+i);
00456     }
00457 
00458 //add tof tracks
00459     if (tofTrack){
00460         delete [] tofTrack;
00461         tofTrack = NULL;
00462     }
00463     tofTrack = new TRecTofTrack[200];
00464     no=0;
00465     no = (recEvt->getTofTrackCol())->GetEntries();
00466     std::cout<<" tof trk number ="<< no <<std::endl;
00467     if (no>200) no =200;
00468     for (int i=0;i<no;i++){
00469         const TRecTofTrack* tofTrack1 =recEvt->getTofTrack(i);
00470         (tofTrack+i)->setTRecTofTrack(tofTrack1);
00471         recdis->addTofTrack(tofTrack+i);
00472     }
00473 
00474 //add mdchits
00475     if (mdchit){
00476         delete [] mdchit;
00477         mdchit = NULL;
00478     }
00479     mdchit = new TRecMdcHit[1000];
00480     no=0;
00481     no = (recEvt->getRecMdcHitCol())->GetEntries();
00482     std::cout<<" mdc hits number ="<< no <<std::endl;
00483     if (no>1000) no =1000;
00484     for (int i=0;i<no;i++){
00485         const TRecMdcHit* mdchit1 =recEvt->getRecMdcHit(i);
00486         (mdchit+i)->setTRecMdcHit(mdchit1);
00487         recdis->addRecMdcHit(mdchit+i);
00488     }
00489 //add muctrks
00490     if (muctrk){
00491         delete []  muctrk;
00492         muctrk = NULL;
00493     }
00494     muctrk = new TRecMucTrack[20];
00495     no=0;
00496     no = (recEvt->getMucTrackCol())->GetEntries();
00497 
00498     std::cout<<" muc trk number ="<< no <<std::endl;
00499     if (no>20) no=20;
00500     for (int i=0;i<no;i++){
00501         const TRecMucTrack* mucTrack1 =recEvt->getMucTrack(i);
00502         (muctrk+i)->setTRecMucTrack(mucTrack1);
00503         recdis->addMucTrack(muctrk+i);
00504     }
00505 
00506 //add emcshowers
00507     if (emcshower){
00508         delete [] emcshower;
00509         emcshower=NULL;
00510     }
00511     emcshower = new TRecEmcShower[20];
00512     no=0;
00513     no = (recEvt->getEmcShowerCol())->GetEntries();
00514     std::cout<<" emc trk number ="<< no <<std::endl;
00515     if (no>20) no=20;
00516     for (int i=0;i<no;i++){
00517         const TRecEmcShower* rec_emc =recEvt->getEmcShower(i);
00518         (emcshower+i)->setTRecEmcShower(rec_emc);
00519         recdis->addEmcShower(emcshower+i);
00520     }
00521 
00522 
00523     TFile file(f_rootOutputFile.c_str(),"RECREATE");
00524     TTree tree("Event","Event");
00525     tree.Branch("TDisTrack","TDisTrack",&recdis,64000,1);
00526     tree.Branch("TDigiEvent", "TDigiEvent", &digiEvt, 64000, 1);
00527     tree.Branch("TEvtHeader","TEvtHeader",&evtHeader,64000,1);
00528     tree.Branch("TTrigEvent","TTrigEvent",&trigEvt,64000,1);
00529     tree.Fill();
00530     file.Write();
00531     file.Close();
00532     recdis->Clear();
00533 
00534     if (m_mode == 1){
00535         commonData tmp;
00536         tmp.clear();
00537     }
00538 
00539 
00540 
00541 //############################################################
00542     //Part 5: operate semaphore -- OUTPUT_STORE, add event counter
00543     release.sem_num = OUTPUT_STORE;
00544     //++++++++++++++++++++++++++++++
00545     // Debug information
00546     //++++++++++++++++++++++++++++++
00547     //log << MSG::ERROR << "B -- No[" << counter++ << "] event "
00548     //<< "has deposited by producer." << endreq;
00549     //
00550     //log << MSG::ERROR << "Before change OUTPUT_STORE" << endreq;
00551     //log << MSG::ERROR << "OUTPUT_STORE will change from 0 to 1" << endreq;
00552     //log << MSG::ERROR << "semid: " << semid << endreq;
00553     //
00554     //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00555     //    log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
00556     //    << endreq;
00557     //    exit(5);
00558     //}
00559     //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
00560     //sem_value_F << endreq;
00561     //
00562     //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00563     //    log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
00564     //    << endreq;
00565     //    exit(5);
00566     //}
00567     //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 0) " <<
00568     //sem_value_O << endreq;
00569     //++++++++++++++++++++++++++++++
00570 
00571     if (semop(semid, &release, 1) == -1){
00572         log << MSG::ERROR << "Producer -- increase -- storage"
00573         << endreq;
00574         exit(4);
00575     }
00576     //++++++++++++++++++++++++++++++
00577     // Debug information
00578     //++++++++++++++++++++++++++++++
00579     //log << MSG::ERROR << "After change OUTPUT_STORE" << endreq;
00580     //log << MSG::ERROR << "OUTPUT_STORE has changed from 0 to 1" << endreq;
00581 
00582     //if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00583     //    log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
00584     //    << endreq;
00585     //    exit(5);
00586     //}
00587     //log << MSG::ERROR << "Semaphore FREE_SPACE has value of(refer 0) " <<
00588     //sem_value_F << endreq;
00589     //
00590     //if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00591     //    log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
00592     //    << endreq;
00593     //    exit(5);
00594     //}
00595     //log << MSG::ERROR << "Semaphore OUTPUT_STORE has value of(refer 1) " <<
00596     //sem_value_O << endreq;
00597     //++++++++++++++++++++++++++++++
00598 
00599     //TFile* f = new TFile("myShare.root", "read");
00600     //TTree* t = (TTree*)f->Get("Event");
00601     //std::cout << "BesVisAlg read file for debug" << std::endl;
00602     //t->Print();
00603     return status;
00604 }
00605 
00606 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00607 bool BesVisAlg::hasRead(){
00608     // Part 1: Get the messaging service, print where you are
00609     MsgStream log(msgSvc(), name());
00610     log << MSG::INFO << "hadRead()" << endreq;
00611 
00612     // Part 2: Testing semaphore value
00613     if ((sem_value_F = semctl(semid, FREE_SPACE, GETVAL, 0)) == -1){
00614         log << MSG::ERROR << "semctl: GETVAL -- FREE_SPACE"
00615         << endreq;
00616         exit(5);
00617     }
00618     log << MSG::INFO << "Semaphore FREE_SPACE has value of " <<
00619     sem_value_F << endreq;
00620 
00621     if ((sem_value_O = semctl(semid, OUTPUT_STORE, GETVAL, 0)) == -1){
00622         log << MSG::ERROR << "semctl: GETVAL -- OUTPUT_STORE"
00623         << endreq;
00624         exit(5);
00625     }
00626     log << MSG::INFO << "Semaphore OUTPUT_STORE has value of " <<
00627     sem_value_O << endreq;
00628 
00629     if  ((sem_value_F == 1) && (sem_value_O == 0))      return true;
00630     else return false;
00631 
00632 }
00633 
00634 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00635 StatusCode BesVisAlg::hasWrite(){
00636     MsgStream log(msgSvc(), name());
00637     log << MSG::INFO << "hasWrite()" << endreq;
00638     StatusCode status = StatusCode::SUCCESS;
00639 
00640     int statusCode;
00641     //statusCode = remove(f_rootOutputFile.c_str());
00642     //log << MSG::ERROR << "remove file(" << f_rootOutputFile << "): " << statusCode << endreq;
00643 
00644     status = getSvc();
00645     if ( !status.isSuccess()){
00646         log <<MSG::ERROR << "getSvc() error!" << endreq;
00647         return StatusCode::SUCCESS;
00648     }
00649 
00650 
00651     status = collectObjects();
00652     if ( !status.isSuccess()){
00653         log <<MSG::ERROR << "collectObjects() error!" << endreq;
00654         return StatusCode::SUCCESS;
00655     }
00656 
00657 //************************************************************************
00658 //
00659 //
00660 //***********************************************************************
00661 //   status = write2file();
00662 //   if ( !status.isSuccess()){
00663 //       log <<MSG::ERROR << "write2file() error!" << endreq;
00664 //       return status;
00665 //   }
00666 //
00667 //   status = finishSvc();
00668 //   if ( !status.isSuccess()){
00669 //       log <<MSG::ERROR << "finishSvc() error!" << endreq;
00670 //       return status;
00671 //   }
00672 
00673     return status;
00674 
00675 }
00676 
00677 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00678 StatusCode BesVisAlg::getSvc(){
00679     MsgStream log(msgSvc(), name());
00680     log << MSG::INFO << "getSvc()" << endreq;
00681     StatusCode status = StatusCode::SUCCESS;
00682 
00683 //#################################
00684     ItemNames   m_itemNames;
00685     m_itemNames.push_back("/Event#1");
00686     m_itemNames.push_back("/Event/EventHeader#1");
00687 
00688     m_itemNames.push_back("/Event/Digi#1");
00689     m_itemNames.push_back("/Event/Digi/MdcDigiCol#1");
00690     m_itemNames.push_back("/Event/Digi/TofDigiCol#1");
00691     m_itemNames.push_back("/Event/Digi/EmcDigiCol#1");
00692     m_itemNames.push_back("/Event/Digi/MucDigiCol#1");
00693 
00694     m_itemNames.push_back("/Event/Recon#1");
00695     m_itemNames.push_back("/Event/Recon/RecMdcHitCol#1");
00696     m_itemNames.push_back("/Event/Recon/RecMdcTrackCol#1");
00697 
00698     m_itemNames.push_back("/Event/Trig#1");
00699     m_itemNames.push_back("/Event/Trig/TrigData#1");
00700     //m_itemNames.push_back("/Event/Recon/MdcHOTCol#1");
00701     //m_itemNames.push_back("/Event/Recon/RecMdcDedxCol#1");
00702     //m_itemNames.push_back("/Event/Recon/RecMdcDedxHitCol#1");
00703     //m_itemNames.push_back("/Event/Recon/RecMdcKalTrackCol#1");
00704     //m_itemNames.push_back("/Event/Recon/RecEsTimeCol#1");
00705     //m_itemNames.push_back("/Event/Recon/RecExtTrackCol#1");
00706     //m_itemNames.push_back("/Event/Recon/RecBTofHitCol#1");
00707     //m_itemNames.push_back("/Event/Recon/RecETofHitCol#1");
00708     //m_itemNames.push_back("/Event/Recon/RecTofTrackCol#1");
00709     //m_itemNames.push_back("/Event/Recon/RecBTofCalHitCol#1");
00710     //m_itemNames.push_back("/Event/Recon/RecETofCalHitCol#1");
00711     //m_itemNames.push_back("/Event/Recon/RecEmcHitCol#1");
00712     //m_itemNames.push_back("/Event/Recon/RecEmcClusterCol#1");
00713     //m_itemNames.push_back("/Event/Recon/RecEmcShowerCol#1");
00714     //m_itemNames.push_back("/Event/Recon/MucRecHitCol#1");
00715     //m_itemNames.push_back("/Event/Recon/RecMucTrackCol#1");
00716     //m_itemNames.push_back("/Event/Recon/RecMdcKalHelixSegCol#1");
00717     //m_itemNames.push_back("/Event/Recon/EvtRecEvent#1");
00718     //m_itemNames.push_back("/Event/Recon/EvtRecTrackCol#1");
00719     //m_itemNames.push_back("/Event/Recon/EvtRecVertexCol#1");
00720 //#################################
00721     clearItems(m_itemList);
00722     ItemNames::iterator i;
00723     for (i = m_itemNames.begin(); i != m_itemNames.end(); i++){
00724         addItem(m_itemList, *i);
00725     }
00726 
00727     status = serviceLocator()->service("EventDataSvc", m_pDataManager, true);
00728     if ( !status.isSuccess() ) {
00729         log << MSG::FATAL << "Unable to locate IDataManagerSvc interface"
00730         << endreq;
00731         return status;
00732     }
00733 
00734     status = serviceLocator()->service("EventDataSvc", m_pDataProvider, true);
00735     if ( !status.isSuccess() ) {
00736         log << MSG::FATAL << "Unable to locate IDataProviderSvc interface"
00737         << endreq;
00738         return status;
00739     }
00740 
00741     status = serviceLocator()->service("EventCnvSvc", m_pConversionSvc, true);
00742     if ( !status.isSuccess() ) {
00743         log << MSG::FATAL << "Unable to locate IConversionSvc interface"
00744         << endreq;
00745         return status;
00746     }
00747 
00748     return status;
00749 }
00750 
00751 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00752 StatusCode BesVisAlg::finishSvc(){
00753     MsgStream log(msgSvc(), name());
00754     log << MSG::INFO << "finishSvc()" << endreq;
00755     StatusCode status = StatusCode::SUCCESS;
00756 
00757     status = m_pRootInterface->f_finalize();
00758     if ( !status.isSuccess())
00759         log << MSG::ERROR << "f_finalize() error" << endreq;
00760 
00761     status = m_pConversionSvc->commitOutput(f_rootOutputFile.c_str(), true);
00762     if ( !status.isSuccess())
00763         log << MSG::ERROR << "commitOutput() error" << endreq;
00764 
00765     clearItems(m_itemList);
00766 
00767     return StatusCode::SUCCESS;
00768 }
00769 
00770 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00771 // Add item to output streamer list
00772 void BesVisAlg::addItem(Items& itms, const std::string& descriptor)   {
00773     MsgStream log(msgSvc(), name());
00774     int level = 0;
00775     size_t sep = descriptor.rfind("#");
00776     std::string obj_path (descriptor,0,sep);
00777     std::string slevel   (descriptor,sep+1,descriptor.length());
00778     if ( slevel == "*" )  {
00779         level = 9999999;
00780     }
00781     else   {
00782         level = atoi(slevel.c_str());
00783     }
00784     size_t idx = obj_path.find("/",1);
00785     while (idx != std::string::npos)  {
00786         std::string sub_item = obj_path.substr(0,idx);
00787         if ( 0 == findItem(sub_item) )   {
00788             addItem(itms, sub_item+"#1");
00789         }
00790         idx = obj_path.find("/",idx+1);
00791     }
00792     DataStoreItem* item = new DataStoreItem(obj_path, level);
00793     log << MSG::DEBUG << "Adding OutputStream item " << item->path()
00794     << " with " << item->depth()
00795     << " level(s)." << endreq;
00796     itms.push_back( item );
00797 }
00798 
00799 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00800 void BesVisAlg::clearItems(Items& itms)     {
00801     for ( Items::iterator i = itms.begin(); i != itms.end(); i++ )    {
00802         delete (*i);
00803     }
00804     itms.erase(itms.begin(), itms.end());
00805 }
00806 
00807 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00808 // Find single item identified by its path (exact match)
00809 DataStoreItem*
00810 BesVisAlg::findItem(const std::string& path)  {
00811     for (Items::const_iterator i=m_itemList.begin(); i != m_itemList.end(); ++i)  {
00812         if ( (*i)->path() == path )  return (*i);
00813     }
00814     return 0;
00815 }
00816 
00817 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00818 StatusCode BesVisAlg::collectObjects(){
00819     MsgStream log(msgSvc(), name());
00820     StatusCode status = StatusCode::SUCCESS;
00821     Items::iterator i;
00822 
00823     // Traverse the tree and collect the requested objects
00824 
00825     for ( i = m_itemList.begin(); i != m_itemList.end(); i++ )    {
00826         DataObject* obj = 0;
00827         IOpaqueAddress *pAddress = 0;
00828         m_currentItem = (*i);
00829 
00830         status = m_pDataProvider->retrieveObject(m_currentItem->path(), obj);
00831         if ( status.isSuccess() )  {
00832             status = m_pConversionSvc->createRep(obj, pAddress);
00833         }
00834         else  {
00835             log << MSG::WARNING << "Cannot write mandatory object(s) (Not found): "
00836             << m_currentItem->path() << endreq;
00837         }
00838     }
00839 
00840 
00841     return StatusCode::SUCCESS;
00842 }
00843 
00844 StatusCode BesVisAlg::write2file(){
00845     MsgStream log(msgSvc(), name());
00846     StatusCode status = StatusCode::SUCCESS;
00847 
00848     log << MSG::INFO << "write2file()" << endreq;
00849 
00850     const std::string treename("Event");
00851 // ************************************************************************
00852 //
00853 // single event output stream
00854 //
00855 // ***********************************************************************
00856 // TDigiEvent
00857 // ***********************************************************************
00858 
00859     TDigiEvent *pTRawEvent = commonData::m_recEvt;
00860     if ( pTRawEvent == 0) {
00861         log << MSG::WARNING << "Can not get point TDigiEvent" << endreq;
00862     }
00863 
00864     const std::string rawBranchname("TDigiEvent");
00865     int branchnr = -1;
00866 
00867     m_pRootInterface = RootInterface::Instance(log);
00868     m_pRootInterface->f_addOutput(treename, f_rootOutputFile.c_str(), 1, 64000, 1);
00869 
00870     if (pTRawEvent != 0) m_pRootInterface->f_createBranch(treename, rawBranchname,
00871                 pTRawEvent->ClassName(),
00872                 &pTRawEvent, branchnr);
00873 
00874 // ***********************************************************************
00875 // TEvtHeader
00876 // ***********************************************************************
00877     TEvtHeader *pTEvtHeader = commonData::m_EvtHeader;
00878     if ( pTEvtHeader == 0) {
00879         log << MSG::WARNING << "Can not get point TEvtHeader" << endreq;
00880     }
00881 
00882     const std::string headerBranchname("TEvtHeader");
00883     branchnr = -1;
00884     if (pTEvtHeader != 0) m_pRootInterface->f_createBranch(treename, headerBranchname,
00885                 pTEvtHeader->ClassName(),
00886                 &pTEvtHeader, branchnr);
00887 
00888 // ***********************************************************************
00889 // TTrigEvent
00890 // ***********************************************************************
00891     TTrigEvent *pTTrigEvent = commonData::m_trigEvt;
00892     if ( pTTrigEvent == 0) {
00893         log << MSG::WARNING << "Can not get point TTrigEvent" << endreq;
00894     }
00895 
00896     const std::string trigBranchname("TTrigEvent");
00897     branchnr = -1;
00898     if (pTTrigEvent != 0) m_pRootInterface->f_createBranch(treename, trigBranchname,
00899                 pTTrigEvent->ClassName(),
00900                 &pTTrigEvent, branchnr);
00901 
00902 
00903 // ***********************************************************************
00904 // TRecEvent
00905 // ***********************************************************************
00906     TRecTrackEvent *pTRecEvent = commonData::m_rectrackEvt;
00907     if ( pTRecEvent == 0) {
00908         log << MSG::WARNING << "Can not get point TRecEvent" << endreq;
00909     }
00910 
00911     const std::string recBranchname("TRecEvent");
00912     branchnr = -1;
00913     if (pTRecEvent != 0) m_pRootInterface->f_createBranch(treename, recBranchname,
00914                 pTRecEvent->ClassName(),
00915                 &pTRecEvent, branchnr);
00916 
00917 
00918 // ***********************************************************************
00919     status = m_pRootInterface->f_fillTrees();
00920     if (status.isFailure())
00921         log << MSG::ERROR << "No Root tree was filled" << endreq;
00922 
00923 
00924 // ***********************************************************************
00925     return status;
00926 
00927 }

Generated on Tue Nov 29 23:12:00 2016 for BOSS_7.0.2 by  doxygen 1.4.7