00001 #include "FROOT.h"
00002
00003 #include <Riostream.h>
00004 #include "TH1F.h"
00005 #include "TH2F.h"
00006 #include "TProfile.h"
00007 #include "TRandom.h"
00008
00010
00011 #undef _FND_ONL_USE_SHARED_FILES_
00012 #undef _FND_ONL_USE_MAP_FILES_
00013
00014 #define _FND_ONL_USE_MAP_FILES_
00015
00017
00018 #if defined _FND_ONL_USE_MAP_FILES_
00019 #include "TMapFile.h"
00020 #elif defined _FND_ONL_USE_SHARED_FILES_
00021 #include "TFile.h"
00022 #endif
00023
00024
00025 #include "TSystem.h"
00026 #include "TString.h"
00027
00028 void HandleConsumerActions(const Char_t *sh_msg_file, Bool_t allow){
00029
00030
00031
00032
00033 TString com = TString("echo ");
00034 Int_t size1 = com.Sizeof()-1;
00035 if(allow) com+="\"go\" > ";
00036 else com+="\"wait\" > ";
00037 com+=sh_msg_file;
00038 gSystem->Exec(com.Data());
00039
00040 com.Resize(size1);
00041 com+="\"\" >> ";
00042 com+=sh_msg_file;
00043 gSystem->Exec(com.Data());
00044
00045 }
00046
00047 void Producer_Finuda(){
00048
00049 gROOT->Reset();
00050
00051
00052 gSystem->Setenv("FND_SHR","./");
00053 TString mnam = TString(gSystem->Getenv("FND_SHR"));
00054 mnam+="/hsimple.map";
00055 TString msgnam = TString(gSystem->Getenv("FND_SHR"));
00056 msgnam+="/shared_msg.txt";
00057
00058 TString comm1 = TString("touch ");
00059 comm1+=msgnam.Data();
00060 gSystem->Exec(comm1.Data());
00061
00062 HandleConsumerActions(msgnam.Data(),0);
00063 #if defined _FND_ONL_USE_MAP_FILES_
00064 TMapFile::SetMapAddress(0x40028000);
00065 #endif
00066
00067 TString command_rm = TString("rm -f ");
00068 command_rm+=mnam.Data();
00069 gSystem->Exec(command_rm.Data());
00070
00071 gSystem->Sleep(300);
00072 #if defined _FND_ONL_USE_MAP_FILES_
00073 cout << "Creating map file" << endl;
00074 TMapFile *mfile = TMapFile::Create(mnam.Data(),"RECREATE", 10000,"Demo memory mapped file");
00075 cout << "Map file created" << endl;
00076 cout << "mfile is: " << mfile << endl;
00077 mfile->Print();
00078 #elif defined _FND_ONL_USE_SHARED_FILES_
00079 cout << "Creating shared file" << endl;
00080 TFile *mfile = new TFile(mnam.Data(),"RECREATE");
00081 cout << "Shared file created" << endl;
00082 #endif
00083 gSystem->Sleep(300);
00084
00085
00086 TH1F *h1 = new TH1F("h1","Histogram 1",100,-4,4);
00087 h1->SetFillColor(48);
00088 HandleConsumerActions(msgnam.Data(),0);
00089 #if defined _FND_ONL_USE_MAP_FILES_
00090 mfile->Update();
00091 #elif defined _FND_ONL_USE_SHARED_FILES_
00092 mfile->cd();
00093 h1->Write();
00094 mfile->Purge();
00095 mfile->Flush();
00096 #endif
00097
00098 HandleConsumerActions(msgnam.Data(),1);
00099
00100 mfile->ls();
00101
00102
00103 TString command_touch = TString("touch ");
00104 command_touch+=mnam.Data();
00105 int ev = 0;
00106 while (1) {
00107 cout << "Macro message: Filling" << endl;
00108 h1->Fill(3);
00109 #if defined _FND_ONL_USE_MAP_FILES_
00110 cout << "Macro message: Updating mapfile" << endl;
00111 mfile->Update();
00112 cout << "Macro message: mapfile updated: now touching it" << endl;
00113 #elif defined _FND_ONL_USE_SHARED_FILES_
00114 cout << "Macro message: Updating shared file" << endl;
00115 mfile->cd();
00116 h1->Write();
00117 mfile->Purge();
00118 mfile->Flush();
00119 cout << "Macro message: shared file updated: now touching it" << endl;
00120 #endif
00121 gSystem->Exec(command_touch.Data());
00122 #if defined _FND_ONL_USE_MAP_FILES_
00123 cout << "Macro message: mapfile touched" << endl;
00124 #elif defined _FND_ONL_USE_SHARED_FILES_
00125 cout << "Macro message: shared file touched" << endl;
00126 #endif
00127 gSystem->ProcessEvents();
00128 mfile->ls();
00129 Char_t a[10];
00130 cout << "press any key to continue (fill and update)" << endl;
00131 cin >> a;
00132 if(!strcmp(a,"q")) break;
00133 ev++;
00134 }
00135 HandleConsumerActions(msgnam.Data(),0);
00136 mfile->Close();
00137
00138 }
00139