00001 #include "FROOT.h"
00002
00003 #include <Riostream.h>
00004 #include "TROOT.h"
00005 #include "TSystem.h"
00006 #include "TCanvas.h"
00007 #include "TH1F.h"
00008 #include "TH2F.h"
00009 #include "TProfile.h"
00010 #include "TRandom.h"
00011
00013
00014 #undef _FND_ONL_USE_SHARED_FILES_
00015 #undef _FND_ONL_USE_MAP_FILES_
00016
00017 #define _FND_ONL_USE_MAP_FILES_
00018
00020
00021 #if defined _FND_ONL_USE_MAP_FILES_
00022 #include "TMapFile.h"
00023 #elif defined _FND_ONL_USE_SHARED_FILES_
00024 #include "TFile.h"
00025 #endif
00026
00027 #include "TSystem.h"
00028 #include "TString.h"
00029
00030
00031
00032 #if defined _FND_ONL_USE_SHARED_FILES_
00033 TFile *mfile = 0;
00034 #elif defined _FND_ONL_USE_MAP_FILES_
00035 TMapFile *mfile = 0;
00036 #endif
00037
00038 Bool_t CheckProducerMessages(const Char_t *sh_msg_file){
00039
00040 Bool_t can_act = kFALSE;
00041
00042
00043 FILE *f_sh = fopen(sh_msg_file,"r");
00044 if(!f_sh){
00045 cout << "Messages shared file not found...waiting" << endl;
00046 return kFALSE;
00047 }
00048
00049 Char_t msg[10];
00050 Int_t scan = fscanf(f_sh,"%s",msg);
00051 cout << "scan: " << scan << " ---> msg: \"" << msg << "\"" << endl;
00052
00053
00054 if(!strcmp(msg,"go")) can_act = kTRUE;
00055 else if(!strcmp(msg,"wait")) can_act = kFALSE;
00056 fclose(f_sh);
00057
00058 return can_act;
00059 }
00060
00061 void Consumer_Finuda(){
00062 gSystem->Setenv("FND_SHR","./");
00063 TString mnam = TString(gSystem->Getenv("FND_SHR"));
00064 mnam+="/hsimple.map";
00065
00066 TString msgnam = TString(gSystem->Getenv("FND_SHR"));
00067 msgnam+="/shared_msg.txt";
00068
00069 TH1F *h1 = 0;
00070
00071 Int_t i = 0;
00072 while (1) {
00073 while(gSystem->AccessPathName(mnam.Data())){
00074 cout << "Shared memory not found! retrying..." << endl;
00075 gSystem->Sleep(500);
00076 }
00077 while(!CheckProducerMessages(msgnam.Data())){
00078 cout << "shared files busy...producer message" << endl;
00079 gSystem->Sleep(500);
00080 }
00081 #if defined _FND_ONL_USE_SHARED_FILES_
00082 if(mfile !=0 && mfile->IsOpen()) { mfile->Close(); delete mfile; mfile = 0; }
00083 mfile = TFile::Open(mnam.Data(),"READ");
00084 #elif defined _FND_ONL_USE_MAP_FILES_
00085 if(mfile) mfile->Close();
00086 mfile = TMapFile::Create(mnam.Data(),"READ");
00087 #endif
00088 if(!mfile){
00089 cout << "mfile \"" << mnam.Data() << "\" not found." << endl;
00090 gSystem->Sleep(300);
00091 continue;
00092 }
00093
00094
00095 if(i==0){
00096 cout << "mfile is: " << mfile << endl;
00097 mfile->Print();
00098 mfile->ls();
00099 }
00100 if(!h1) h1 = (TH1F *) mfile->Get("h1");
00101 #if defined _FND_ONL_USE_MAP_FILES_
00102 else{
00103 h1->Reset();
00104 h1->Add((TH1F *) mfile->Get("h1"));
00105 }
00106 #endif
00107 cout << h1 << " ====> entries: " << h1->GetEntries() << endl;
00108 #if defined _FND_ONL_USE_SHARED_FILES_
00109 delete h1; h1 = 0;
00110 #endif
00111 gSystem->Sleep(300);
00112 i++;
00113 mfile->Close();
00114 }
00115 }
00116
00117