ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
hcons.C
Go to the documentation of this file.
1 {
2  // Histogram consumer script. Create a canvas and 3 pads. Connect
3  // to memory mapped file "hsimple.map", that was created by hprod.C.
4  // It reads the histograms from shared memory and displays them
5  // in the pads (sleeping for 0.1 seconds before starting a new read-out
6  // cycle). This script runs in an infinite loop, so use ctrl-c to stop it.
7  //Author: Fons Rademakers
8 
9  gROOT->Reset();
10 
11  // Create a new canvas and 3 pads
12  TCanvas *c1;
14  if (!gROOT->IsBatch()) {
15  c1 = new TCanvas("c1","Shared Memory Consumer Example",200,10,700,780);
16  pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
17  pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21);
18  pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21);
19  pad1->Draw();
20  pad2->Draw();
21  pad3->Draw();
22  }
23 
24  // Open the memory mapped file "hsimple.map" in "READ" (default) mode.
25  mfile = TMapFile::Create("hsimple.map");
26 
27  // Print status of mapped file and list its contents
28  mfile->Print();
29  mfile->ls();
30 
31  // Create pointers to the objects in shared memory.
32  TH1F *hpx = 0;
33  TH2F *hpxpy = 0;
34  TProfile *hprof = 0;
35 
36  // Loop displaying the histograms. Once the producer stops this
37  // script will break out of the loop.
38  Double_t oldentries = 0;
39  while (1) {
40  hpx = (TH1F *) mfile->Get("hpx", hpx);
41  hpxpy = (TH2F *) mfile->Get("hpxpy", hpxpy);
42  hprof = (TProfile *) mfile->Get("hprof", hprof);
43  if (hpx->GetEntries() == oldentries) break;
44  oldentries = hpx->GetEntries();
45  if (!gROOT->IsBatch()) {
46  pad1->cd();
47  hpx->Draw();
48  pad2->cd();
49  hprof->Draw();
50  pad3->cd();
51  hpxpy->Draw("cont");
52  c1->Modified();
53  c1->Update();
54  } else {
55  printf("Entries, hpx=%d, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
56  }
57  gSystem->Sleep(100); // sleep for 0.1 seconds
58  if (gSystem->ProcessEvents())
59  break;
60  }
61 }
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:420
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
TPad * pad1
Definition: hcons.C:13
#define gROOT
Definition: TROOT.h:344
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:570
TPad * pad3
Definition: hcons.C:13
Profile Historam.
Definition: TProfile.h:34
virtual Double_t GetEntries() const
return the current number of entries
Definition: TH1.cxx:4051
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:514
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:441
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1192
mfile
Definition: hcons.C:25
Double_t oldentries
Definition: hcons.C:38
virtual Double_t GetMean(Int_t axis=1) const
For axis = 1,2 or 3 returns the mean value of the histogram along X,Y or Z axis.
Definition: TH1.cxx:7014
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2878
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:256
TCanvas * c1
Definition: hcons.C:1
The most important graphics class in the ROOT system.
Definition: TPad.h:46
Double_t GetRMS(Int_t axis=1) const
Definition: TH1.h:315
The Canvas class.
Definition: TCanvas.h:48
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
TPad * pad2
Definition: hcons.C:13
virtual void Update()
Update canvas pad buffers.
Definition: TCanvas.cxx:2179
void Modified(Bool_t flag=1)
Definition: TPad.h:407