ROOT logo
{
   // 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.
   //Author: Fons Rademakers
   
   gROOT->Reset();

   // 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.

   TMapFile::SetMapAddress(0xb46a5000);
   mfile = TMapFile::Create("hsimple.map","RECREATE", 1000000,
                            "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();

   // 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)) {
         mfile->Update();       // updates all objects in shared memory
         if (!ii) mfile->ls();  // print contents of mapped file after
      }                         // first update
      ii++;
   }
}
 hprod.C:1
 hprod.C:2
 hprod.C:3
 hprod.C:4
 hprod.C:5
 hprod.C:6
 hprod.C:7
 hprod.C:8
 hprod.C:9
 hprod.C:10
 hprod.C:11
 hprod.C:12
 hprod.C:13
 hprod.C:14
 hprod.C:15
 hprod.C:16
 hprod.C:17
 hprod.C:18
 hprod.C:19
 hprod.C:20
 hprod.C:21
 hprod.C:22
 hprod.C:23
 hprod.C:24
 hprod.C:25
 hprod.C:26
 hprod.C:27
 hprod.C:28
 hprod.C:29
 hprod.C:30
 hprod.C:31
 hprod.C:32
 hprod.C:33
 hprod.C:34
 hprod.C:35
 hprod.C:36
 hprod.C:37
 hprod.C:38
 hprod.C:39
 hprod.C:40
 hprod.C:41
 hprod.C:42
 hprod.C:43
 hprod.C:44
 hprod.C:45
 hprod.C:46
 hprod.C:47
 hprod.C:48