re: Using TMapFiles in compiled code

Peter Steinberg (steinber@nevis1.nevis.columbia.edu)
Fri, 10 Jul 1998 14:05:51 -0400 (EDT)


Hans -

Thanks for the code. It actually compiles and runs on NT. Thus, it
appears to be my problem, not ROOT's!

- Peter

---------------------------------------------------------------------------
Peter Steinberg, Columbia University E-mail: peter.steinberg@cern.ch
Nevis Laboratories URL: http://wwwcn.cern.ch/~steinber
P.O. Box 137 Home Phone: (212)678-5971
Irvington, NY 10533 Nevis: (914) 591-2776 (fax 8120)
---------------------------------------------------------------------------

On Fri, 10 Jul 1998, Hans Wenzel wrote:

> Dear peter
>
>
> I don't know if it helps you i am working under irix and linux. below
> you find the modified version of the tutorial hprod.C which i modified
> to hprod.cxx as a stand alone c++ program. i have attached the modified
> makefile (irix and gcc ) .
> hope this helps
>
>
> cheers hans wenzel
>
>
>
> / This is file hprod.cxx
> // Histogram producer script. This script creates a memory mapped
> // file and stores three histogram objects in it (a TH1F, a TH2F and a
> // TProfile). It then fills, in an infinite loop (so use ctrl-c to
> // stop this script), the three histogram objects with random numbers.
> // Every 10 fills the objects are updated in shared memory.
> // Use the hcons.C script to map this file and display the histograms.
> #include "TROOT.h"
> #include "TH1.h"
> #include "TH2.h"
> #include "TProfile.h"
> //#include "TNtuple.h"
> #include "TBrowser.h"
> #include "TRandom.h"
> #include "TMapFile.h"
> #include "TSystem.h"
> int main()
> {
> // Create a new memory mapped file. The memory mapped file can be
> // opened in an other process on the same machine and the objects
> // stored in it can be accessed.
> TROOT hprod("hprod","Test of simple histogram producer to shared
> memory ");
> TH1F *hpx;
> TH2F *hpxpy;
> TProfile *hprof;
> TMapFile *mfile;
> mfile = TMapFile::Create("hsimple.map","RECREATE", 100000,
> "Demo memory mapped file with histograms");
>
> // Create a 1d, a 2d and a profile histogram. These objects will
> // be automatically added to the current directory, i.e. mfile.
> hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
> hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
> hprof = new TProfile("hprof","Profile of pz versus
> px",100,-4,4,0,20);
>
> // Set a fill color for the TH1F
> hpx->SetFillColor(48);
>
> // Print status of mapped file
> mfile->Print();
> // TBrowser b;
> // Endless loop filling histograms with random numbers
> Float_t px, py, pz;
> int ii = 0;
> while (1) {
> gRandom->Rannor(px,py);
> pz = px*px + py*py;
> hpx->Fill(px);
> hpxpy->Fill(px,py);
> hprof->Fill(px,pz);
> if (!(ii % 10)) {
> gSystem->Sleep(100); // sleep for a while
> mfile->Update(); // updates all objects in shared memory
> if (!ii) mfile->ls(); // print contents of mapped file after
> } // first update
> ii++;
> }
>
> return 0;
> }
>
>
>