00001 { 00002 // Histogram producer script. This script creates a memory mapped 00003 // file and stores three histogram objects in it (a TH1F, a TH2F and a 00004 // TProfile). It then fills, in an infinite loop (so use ctrl-c to 00005 // stop this script), the three histogram objects with random numbers. 00006 // Every 10 fills the objects are updated in shared memory. 00007 // Use the hcons.C script to map this file and display the histograms. 00008 //Author: Fons Rademakers 00009 00010 gROOT->Reset(); 00011 00012 // Create a new memory mapped file. The memory mapped file can be 00013 // opened in an other process on the same machine and the objects 00014 // stored in it can be accessed. 00015 00016 TMapFile::SetMapAddress(0xb46a5000); 00017 mfile = TMapFile::Create("hsimple.map","RECREATE", 1000000, 00018 "Demo memory mapped file with histograms"); 00019 00020 // Create a 1d, a 2d and a profile histogram. These objects will 00021 // be automatically added to the current directory, i.e. mfile. 00022 hpx = new TH1F("hpx","This is the px distribution",100,-4,4); 00023 hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4); 00024 hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20); 00025 00026 // Set a fill color for the TH1F 00027 hpx->SetFillColor(48); 00028 00029 // Print status of mapped file 00030 mfile->Print(); 00031 00032 // Endless loop filling histograms with random numbers 00033 Float_t px, py, pz; 00034 int ii = 0; 00035 while (1) { 00036 gRandom->Rannor(px,py); 00037 pz = px*px + py*py; 00038 hpx->Fill(px); 00039 hpxpy->Fill(px,py); 00040 hprof->Fill(px,pz); 00041 if (!(ii % 10)) { 00042 mfile->Update(); // updates all objects in shared memory 00043 if (!ii) mfile->ls(); // print contents of mapped file after 00044 } // first update 00045 ii++; 00046 } 00047 }