Logo ROOT   6.18/05
Reference Guide
hcons.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_net
3/// Histogram consumer script. Create a canvas and 3 pads. Connect
4/// to memory mapped file "hsimple.map", that was created by hprod.C.
5/// It reads the histograms from shared memory and displays them
6/// in the pads (sleeping for 0.1 seconds before starting a new read-out
7/// cycle). This script runs in an infinite loop, so use ctrl-c to stop it.
8///
9/// \macro_code
10///
11/// \author Fons Rademakers
12
13{
14 gROOT->Reset();
15
16 // Create a new canvas and 3 pads
17 TCanvas *c1;
18 TPad *pad1, *pad2, *pad3;
19 if (!gROOT->IsBatch()) {
20 c1 = new TCanvas("c1","Shared Memory Consumer Example",200,10,700,780);
21 pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
22 pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21);
23 pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21);
24 pad1->Draw();
25 pad2->Draw();
26 pad3->Draw();
27 }
28
29 // Open the memory mapped file "hsimple.map" in "READ" (default) mode.
30 mfile = TMapFile::Create("hsimple.map");
31
32 // Print status of mapped file and list its contents
33 mfile->Print();
34 mfile->ls();
35
36 // Create pointers to the objects in shared memory.
37 TH1F *hpx = 0;
38 TH2F *hpxpy = 0;
39 TProfile *hprof = 0;
40
41 // Loop displaying the histograms. Once the producer stops this
42 // script will break out of the loop.
43 Double_t oldentries = 0;
44 while (1) {
45 hpx = (TH1F *) mfile->Get("hpx", hpx);
46 hpxpy = (TH2F *) mfile->Get("hpxpy", hpxpy);
47 hprof = (TProfile *) mfile->Get("hprof", hprof);
48 if (hpx->GetEntries() == oldentries) break;
49 oldentries = hpx->GetEntries();
50 if (!gROOT->IsBatch()) {
51 pad1->cd();
52 hpx->Draw();
53 pad2->cd();
54 hprof->Draw();
55 pad3->cd();
56 hpxpy->Draw("cont");
57 c1->Modified();
58 c1->Update();
59 } else {
60 printf("Entries, hpx=%d, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
61 }
62 gSystem->Sleep(100); // sleep for 0.1 seconds
64 break;
65 }
66}
double Double_t
Definition: RtypesCore.h:55
#define gROOT
Definition: TROOT.h:414
R__EXTERN TSystem * gSystem
Definition: TSystem.h:560
The Canvas class.
Definition: TCanvas.h:31
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:571
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:7050
Double_t GetRMS(Int_t axis=1) const
Definition: TH1.h:311
virtual Double_t GetEntries() const
Return the current number of entries.
Definition: TH1.cxx:4277
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2981
2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:248
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:1142
The most important graphics class in the ROOT system.
Definition: TPad.h:29
virtual void Draw(Option_t *option="")
Draw Pad in Current pad (re-parent pad if necessary).
Definition: TPad.cxx:1285
TVirtualPad * cd(Int_t subpadnumber=0)
Set Current pad.
Definition: TPad.cxx:594
Profile Histogram.
Definition: TProfile.h:32
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition: TSystem.cxx:446
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition: TSystem.cxx:425
return c1
Definition: legend1.C:41