Hi, You must define a TApplication object in your producer. You also had an error in a format in hcons. See modified files in attachement Rene Brun Jianglai Liu wrote: > > Dear ROOTers, > > I am experiencing some odd problems with TMapFile. I took the simple > example hprod.C and hcons.C from tutorial and modified both into compiled > programs. Then somehow the consumer did not work correctly. (The > program didn't crashes. But it looked like the consumer histogram was > always be empty ...) BTW the same consumer code worked perfectly OK in > CINT. I am using RH9.0 with gcc3.2 compiler, and a home-compiled ROOT > 3.04/02. I have tried to use SetMapAddress() to get the prefered the share > memory address and linked both of the code with libNew. Below are my codes > and a Makefile. Could someone let me know what might be the cause? > > Many thanks! > > #################################### Producer: hprod.C > #include <TROOT.h> > #include <TPad.h> > #include <TMapFile.h> > #include <TH1.h> > #include <TH2.h> > #include <TProfile.h> > #include <TSystem.h> > #include <TCanvas.h> > #include <iostream> > #include <TRandom.h> > > using namespace std; > int main() > { > > TMapFile::SetMapAddress(0x4125c000); > TMapFile* mfile = TMapFile::Create("hsimple.map","RECREATE", 100000, > "Demo memory mapped file with histograms"); > > TH1F* hpx = new TH1F("hpx","This is the px distribution",100,-4,4); > > hpx->SetFillColor(48); > > mfile->Print(); > > Float_t px, py, pz; > int ii = 0; > while (1) { > gRandom->Rannor(px,py); > hpx->Fill(px); > if (!(ii % 10)) { > mfile->Update(); // updates all objects in shared memory > if (!ii) mfile->ls(); // print contents of mapped file after > } // first update > ii++; > gSystem->Sleep(100); > } > } > > ######################## Consumer hcons_test.C > #include <TROOT.h> > #include <TPad.h> > #include <TMapFile.h> > #include <TH1.h> > #include <TH2.h> > #include <TProfile.h> > #include <TSystem.h> > #include <TCanvas.h> > #include <iostream> > > using namespace std; > int main() > { > TMapFile* mfile = 0; > mfile = TMapFile::Create("hsimple.map"); > > mfile->Print(); > mfile->ls(); > > TH1F *hpx = 0; > > // Loop displaying the histograms. Once the producer stops this > // script will break out of the loop. > Double_t oldentries = 0; > while (1) { > hpx = (TH1F *) mfile->Get("hpx", hpx); > if (hpx->GetEntries() == oldentries) { > gSystem->Sleep(1000); > continue; > } > oldentries = hpx->GetEntries(); > printf("Entries, hpx=%d, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS()); > gSystem->Sleep(1000); > if (gSystem->ProcessEvents()) > break; > } > } > > ############################# Makefile > ROOTCFLAGS = $(shell root-config --cflags) > ROOTLIBS = $(shell root-config --libs) -lNew > ROOTGLIBS = $(shell root-config --glibs) > > CXXFLAGS = -O2 -fPIC -I$(ROOTSYS)/include -DCOMPILED_ROOT > CC = gcc > OPTIM= -O2 -fexpensive-optimizations -funroll-loops > CXXFLAGS +=$(ROOTCFLAGS) > LIBS = $(LIBM) $(ROOTLIBS) $(ROOTGLIBS) > hprod: hprod.o > $(CC) $(CXXFLAGS) -o hprod hprod.o $(LIBS) > hcons_test: hcons_test.o > $(CC) $(CXXFLAGS) -o hcons_test hcons_test.o $(LIBS) #include <TROOT.h> #include <TPad.h> #include <TMapFile.h> #include <TH1.h> #include <TH2.h> #include <TProfile.h> #include <TSystem.h> #include <TCanvas.h> #include <iostream> #include <TRandom.h> #include <TApplication.h> using namespace std; int main() { TApplication app("app",0,0); TMapFile::SetMapAddress(0x4125c000); TMapFile* mfile = TMapFile::Create("hsimple.map","RECREATE", 100000, "Demo memory mapped file with histograms"); TH1F* hpx = new TH1F("hpx","This is the px distribution",100,-4,4); hpx->SetFillColor(48); mfile->Print(); Float_t px, py, pz; int ii = 0; while (1) { gRandom->Rannor(px,py); hpx->Fill(px); if (!(ii % 10)) { mfile->Update(); // updates all objects in shared memory if (!ii) mfile->ls(); // print contents of mapped file after } // first update ii++; gSystem->Sleep(100); } } #include <TROOT.h> #include <TPad.h> #include <TMapFile.h> #include <TH1.h> #include <TH2.h> #include <TProfile.h> #include <TSystem.h> #include <TCanvas.h> #include <iostream> #include <TApplication.h> using namespace std; int main() { //TApplication app("app",0,0); TMapFile* mfile = 0; mfile = TMapFile::Create("hsimple.map"); mfile->Print(); mfile->ls(); TH1F *hpx = 0; // Loop displaying the histograms. Once the producer stops this // script will break out of the loop. Double_t oldentries = 0; while (1) { hpx = (TH1F *) mfile->Get("hpx", hpx); if (hpx->GetEntries() == oldentries) { gSystem->Sleep(1000); continue; } oldentries = hpx->GetEntries(); printf("Entries, hpx=%g, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS()); //hpx->Dump(); gSystem->Sleep(1000); if (gSystem->ProcessEvents()) break; } }
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:15 MET