hcons.C

Go to the documentation of this file.
00001 {
00002    // Histogram consumer script. Create a canvas and 3 pads. Connect
00003    // to memory mapped file "hsimple.map", that was created by hprod.C.
00004    // It reads the histograms from shared memory and displays them
00005    // in the pads (sleeping for 0.1 seconds before starting a new read-out
00006    // cycle). This script runs in an infinite loop, so use ctrl-c to stop it.
00007    //Author: Fons Rademakers
00008    
00009    gROOT->Reset();
00010 
00011    // Create a new canvas and 3 pads
00012    TCanvas *c1;
00013    TPad *pad1, *pad2, *pad3;
00014    if (!gROOT->IsBatch()) {
00015       c1 = new TCanvas("c1","Shared Memory Consumer Example",200,10,700,780);
00016       pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.98,0.98,21);
00017       pad2 = new TPad("pad2","This is pad2",0.02,0.02,0.48,0.48,21);
00018       pad3 = new TPad("pad3","This is pad3",0.52,0.02,0.98,0.48,21);
00019       pad1->Draw();
00020       pad2->Draw();
00021       pad3->Draw();
00022    }
00023 
00024    // Open the memory mapped file "hsimple.map" in "READ" (default) mode.
00025    mfile = TMapFile::Create("hsimple.map");
00026 
00027    // Print status of mapped file and list its contents
00028    mfile->Print();
00029    mfile->ls();
00030 
00031    // Create pointers to the objects in shared memory.
00032    TH1F     *hpx    = 0;
00033    TH2F     *hpxpy  = 0;
00034    TProfile *hprof  = 0;
00035 
00036    // Loop displaying the histograms. Once the producer stops this
00037    // script will break out of the loop.
00038    Double_t oldentries = 0;
00039    while (1) {
00040       hpx    = (TH1F *) mfile->Get("hpx", hpx);
00041       hpxpy  = (TH2F *) mfile->Get("hpxpy", hpxpy);
00042       hprof  = (TProfile *) mfile->Get("hprof", hprof);
00043       if (hpx->GetEntries() == oldentries) break;
00044       oldentries = hpx->GetEntries();
00045       if (!gROOT->IsBatch()) {
00046          pad1->cd();
00047          hpx->Draw();
00048          pad2->cd();
00049          hprof->Draw();
00050          pad3->cd();
00051          hpxpy->Draw("cont");
00052          c1->Modified();
00053          c1->Update();
00054       } else {
00055          printf("Entries, hpx=%d, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
00056       }
00057       gSystem->Sleep(100);   // sleep for 0.1 seconds
00058       if (gSystem->ProcessEvents())
00059          break;
00060    }
00061 }

Generated on Tue Jul 5 15:44:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1