Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
hcons.C File Reference

Detailed Description

Histogram consumer script.

Create a canvas and 3 pads. Connect to memory mapped file "hsimple.map", that was created by hprod.C. It reads the histograms from shared memory and displays them in the pads (sleeping for 0.1 seconds before starting a new read-out cycle). This script runs in an infinite loop, so use ctrl-c to stop it.

{
gROOT->Reset();
// Create a new canvas and 3 pads
TPad *pad1, *pad2, *pad3;
if (!gROOT->IsBatch()) {
c1 = new TCanvas("c1","Shared Memory Consumer Example",200,10,700,780);
pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21);
pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21);
pad1->Draw();
pad2->Draw();
pad3->Draw();
}
// Open the memory mapped file "hsimple.map" in "READ" (default) mode.
mfile = TMapFile::Create("hsimple.map");
// Print status of mapped file and list its contents
mfile->Print();
mfile->ls();
// Create pointers to the objects in shared memory.
TH1F *hpx = 0;
TH2F *hpxpy = 0;
TProfile *hprof = 0;
// Loop displaying the histograms. Once the producer stops this
// script will break out of the loop.
Double_t oldentries = 0;
while (1) {
hpx = (TH1F *) mfile->Get("hpx", hpx);
hpxpy = (TH2F *) mfile->Get("hpxpy", hpxpy);
hprof = (TProfile *) mfile->Get("hprof", hprof);
if (!hpx || !hpxpy || !hprof || hpx->GetEntries() == oldentries)
break;
oldentries = hpx->GetEntries();
if (!gROOT->IsBatch()) {
pad1->cd();
hpx->Draw();
pad2->cd();
hprof->Draw();
pad3->cd();
hpxpy->Draw("cont");
c1->Modified();
c1->Update();
} else {
printf("Entries, hpx=%lld, Mean=%g, RMS=%g\n",
(Long64_t)hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
}
gSystem->Sleep(100); // sleep for 0.1 seconds
break;
}
}
double Double_t
Definition RtypesCore.h:59
long long Long64_t
Definition RtypesCore.h:69
#define gROOT
Definition TROOT.h:406
R__EXTERN TSystem * gSystem
Definition TSystem.h:561
The Canvas class.
Definition TCanvas.h:23
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:622
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:7556
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition TH1.cxx:3066
Double_t GetRMS(Int_t axis=1) const
This function returns the Standard Deviation (Sigma) of the distribution not the Root Mean Square (RM...
Definition TH1.h:319
virtual Double_t GetEntries() const
Return the current number of entries.
Definition TH1.cxx:4423
2-D histogram with a float per channel (see TH1 documentation)
Definition TH2.h:307
static TMapFile * Create(const char *name, Option_t *option="READ", Int_t size=kDefaultMapSize, const char *title="")
Create a memory mapped file.
The most important graphics class in the ROOT system.
Definition TPad.h:28
TVirtualPad * cd(Int_t subpadnumber=0) override
Set Current pad.
Definition TPad.cxx:693
void Draw(Option_t *option="") override
Draw Pad in Current pad (re-parent pad if necessary).
Definition TPad.cxx:1364
Profile Histogram.
Definition TProfile.h:32
virtual void Sleep(UInt_t milliSec)
Sleep milliSec milli seconds.
Definition TSystem.cxx:437
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
Definition TSystem.cxx:416
return c1
Definition legend1.C:41
Author
Fons Rademakers

Definition in file hcons.C.