ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hprod.C
Go to the documentation of this file.
1 {
2  // Histogram producer script. This script creates a memory mapped
3  // file and stores three histogram objects in it (a TH1F, a TH2F and a
4  // TProfile). It then fills, in an infinite loop (so use ctrl-c to
5  // stop this script), the three histogram objects with random numbers.
6  // Every 10 fills the objects are updated in shared memory.
7  // Use the hcons.C script to map this file and display the histograms.
8  //Author: Fons Rademakers
9 
10  gROOT->Reset();
11 
12  // Create a new memory mapped file. The memory mapped file can be
13  // opened in an other process on the same machine and the objects
14  // stored in it can be accessed.
15 
16  TMapFile::SetMapAddress(0xb46a5000);
17  mfile = TMapFile::Create("hsimple.map","RECREATE", 1000000,
18  "Demo memory mapped file with histograms");
19 
20  // Create a 1d, a 2d and a profile histogram. These objects will
21  // be automatically added to the current directory, i.e. mfile.
22  hpx = new TH1F("hpx","This is the px distribution",100,-4,4);
23  hpxpy = new TH2F("hpxpy","py vs px",40,-4,4,40,-4,4);
24  hprof = new TProfile("hprof","Profile of pz versus px",100,-4,4,0,20);
25 
26  // Set a fill color for the TH1F
27  hpx->SetFillColor(48);
28 
29  // Print status of mapped file
30  mfile->Print();
31 
32  // Endless loop filling histograms with random numbers
34  int ii = 0;
35  while (1) {
36  gRandom->Rannor(px,py);
37  pz = px*px + py*py;
38  hpx->Fill(px);
39  hpxpy->Fill(px,py);
40  hprof->Fill(px,pz);
41  if (!(ii % 10)) {
42  mfile->Update(); // updates all objects in shared memory
43  if (!ii) mfile->ls(); // print contents of mapped file after
44  } // first update
45  ii++;
46  }
47 }
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
Definition: TRandom.cxx:460
Float_t pz
Definition: hprod.C:33
static TMapFile * Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="")
Create a memory mapped file.
Definition: TMapFile.cxx:1104
float Float_t
Definition: RtypesCore.h:53
#define gROOT
Definition: TROOT.h:344
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
Float_t py
Definition: hprod.C:33
Profile Historam.
Definition: TProfile.h:34
hpxpy
Definition: hprod.C:23
static void SetMapAddress(Long_t addr)
Set preferred map address.
Definition: TMapFile.cxx:1141
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Float_t px
Definition: hprod.C:33
hpx
Definition: hprod.C:22
hprof
Definition: hprod.C:24
mfile
Definition: hprod.C:17