ROOT logo

From $ROOTSYS/tutorials/net/hcons.C

{
   // 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.
   //Author: Fons Rademakers
   
   gROOT->Reset();

   // Create a new canvas and 3 pads
   TCanvas *c1;
   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->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=%d, Mean=%g, RMS=%g\n",hpx->GetEntries(),hpx->GetMean(),hpx->GetRMS());
      }
      gSystem->Sleep(100);   // sleep for 0.1 seconds
      if (gSystem->ProcessEvents())
         break;
   }
}
 hcons.C:1
 hcons.C:2
 hcons.C:3
 hcons.C:4
 hcons.C:5
 hcons.C:6
 hcons.C:7
 hcons.C:8
 hcons.C:9
 hcons.C:10
 hcons.C:11
 hcons.C:12
 hcons.C:13
 hcons.C:14
 hcons.C:15
 hcons.C:16
 hcons.C:17
 hcons.C:18
 hcons.C:19
 hcons.C:20
 hcons.C:21
 hcons.C:22
 hcons.C:23
 hcons.C:24
 hcons.C:25
 hcons.C:26
 hcons.C:27
 hcons.C:28
 hcons.C:29
 hcons.C:30
 hcons.C:31
 hcons.C:32
 hcons.C:33
 hcons.C:34
 hcons.C:35
 hcons.C:36
 hcons.C:37
 hcons.C:38
 hcons.C:39
 hcons.C:40
 hcons.C:41
 hcons.C:42
 hcons.C:43
 hcons.C:44
 hcons.C:45
 hcons.C:46
 hcons.C:47
 hcons.C:48
 hcons.C:49
 hcons.C:50
 hcons.C:51
 hcons.C:52
 hcons.C:53
 hcons.C:54
 hcons.C:55
 hcons.C:56
 hcons.C:57
 hcons.C:58
 hcons.C:59
 hcons.C:60
 hcons.C:61
 hcons.C:62