00001 #include <sys/types.h>
00002 #include <sys/stat.h>
00003 #include <sys/file.h>
00004 #include <fcntl.h>
00005
00006
00007 #include <Riostream.h>
00008 #include <stdio.h>
00009 #include "TH1F.h"
00010 #include "TH2F.h"
00011 #include "TProfile.h"
00012 #include "TRandom.h"
00013 #include "TMapFile.h"
00014 #include "TSystem.h"
00015 #include "TString.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 void HandleConsumerActions(const Char_t *sh_msg_file, Bool_t allow){
00043
00044
00045
00046
00047 TString com = TString("echo ");
00048 Int_t size1 = com.Sizeof()-1;
00049 if(allow) com+="\"go\" > ";
00050 else com+="\"wait\" > ";
00051 com+=sh_msg_file;
00052 gSystem->Exec(com.Data());
00053
00054 com.Resize(size1);
00055 com+="\"\" >> ";
00056 com+=sh_msg_file;
00057 gSystem->Exec(com.Data());
00058
00059 }
00060
00061 void Producer_Diego(){
00062
00063 TString mnam = TString(gSystem->Getenv("FND_SHR"));
00064 mnam+="/hsimple.map";
00065 TString msgnam = TString(gSystem->Getenv("FND_SHR"));
00066 msgnam+="/shared_msg.txt";
00067
00068 TString comm1 = TString("touch ");
00069 comm1+=msgnam.Data();
00070 gSystem->Exec(comm1.Data());
00071
00072 HandleConsumerActions(msgnam.Data(),0);
00073
00074
00075 TString command_rm = TString("rm -f ");
00076 command_rm+=mnam.Data();
00077 gSystem->Exec(command_rm.Data());
00078
00079 gSystem->Sleep(300);
00080 TMapFile *mfile = TMapFile::Create(mnam.Data(),"RECREATE", 100000,"Demo memory mapped file");
00081 gSystem->Sleep(300);
00082
00083 cout << "mfile is: " << mfile << endl;
00084 mfile->Print();
00085
00086 TH1F *h1 = new TH1F("h1","Histogram 1",100,-4,4);
00087 h1->SetFillColor(48);
00088 mfile->Update();
00089 HandleConsumerActions(msgnam.Data(),1);
00090
00091 mfile->ls();
00092
00093
00094 TString command_touch = TString("touch ");
00095 command_touch+=mnam.Data();
00096 int ev = 0;
00097 while (1) {
00098 cout << "Filling" << endl;
00099 h1->Fill(3);
00100 mfile->Update();
00101 gSystem->Exec(command_touch.Data());
00102 gSystem->ProcessEvents();
00103 mfile->ls();
00104 Char_t a[10];
00105 cout << "press any key to continue (fill and update)" << endl;
00106 cin >> a;
00107 if(!strcmp(a,"q")) break;
00108 ev++;
00109 }
00110 HandleConsumerActions(msgnam.Data(),0);
00111 cout << "Closing mapfile" << endl;
00112 mfile->Close();
00113 cout << "done: setting pointer to zero" << endl;
00114 mfile = 0;
00115 cout << "done." << endl;
00116
00117 }
00118