00001 #include <Riostream.h>
00002 #include "TROOT.h"
00003 #include "TSystem.h"
00004 #include "TCanvas.h"
00005 #include "TH1F.h"
00006 #include "TH2F.h"
00007 #include "TProfile.h"
00008 #include "TRandom.h"
00009 #include "TMapFile.h"
00010 #include "TSystem.h"
00011 #include "TString.h"
00012
00013 #include <sys/types.h>
00014 #include <sys/file.h>
00015 #include <stdio.h>
00016
00017
00018
00019 #include <fcntl.h>
00020
00021 Bool_t CheckProducerMessages(const Char_t *sh_msg_file){
00022
00023 Bool_t can_act = kFALSE;
00024
00025
00026 FILE *f_sh = fopen(sh_msg_file,"r");
00027 if(!f_sh){
00028 cout << "Messages shared file not found...waiting" << endl;
00029 return kFALSE;
00030 }
00031
00032 Char_t msg[10];
00033 Int_t scan = fscanf(f_sh,"%s",msg);
00034 cout << "scan: " << scan << " ---> msg: \"" << msg << "\"" << endl;
00035
00036
00037 if(!strcmp(msg,"go")) can_act = kTRUE;
00038 else if(!strcmp(msg,"wait")) can_act = kFALSE;
00039 fclose(f_sh);
00040
00041 return can_act;
00042 }
00043
00044 void Consumer_Diego(){
00045
00046 TString mnam = TString(gSystem->Getenv("FND_SHR"));
00047 mnam+="/hsimple.map";
00048
00049 TString msgnam = TString(gSystem->Getenv("FND_SHR"));
00050 msgnam+="/shared_msg.txt";
00051
00052
00053
00054
00055
00056 TH1F *h1 = 0;
00057
00058 TMapFile *mfile = 0;
00059 Int_t i = 0;
00060 while (1) {
00061 while(gSystem->AccessPathName(mnam.Data())){
00062 cout << "Shared memory not found! retrying..." << endl;
00063 gSystem->Sleep(100);
00064 }
00065 while(!CheckProducerMessages(msgnam.Data())){
00066 cout << "shared files busy...producer message" << endl;
00067 gSystem->Sleep(100);
00068 }
00069 mfile = TMapFile::Create(mnam.Data());
00070
00071
00072 if(i==0){
00073 cout << "mfile is: " << mfile << endl;
00074 mfile->Print();
00075 mfile->ls();
00076 }
00077 h1 = (TH1F *) mfile->Get("h1", h1);
00078 cout << "entries: " << h1->GetEntries() << endl;
00079
00080 gSystem->Sleep(10);
00081 i++;
00082
00083 mfile->Close();
00084
00085 mfile = 0;
00086
00087 }
00088 }
00089
00090