Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TStatsFeedback.cxx
Go to the documentation of this file.
1 // @(#)root/proofplayer:$Id$
2 // Author: G. Ganis May 2012
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
13 /** \class TStatsFeedback
14 \ingroup proofkernel
15 
16 Utility class to display PROOF stats feedback histos during queries
17 
18 */
19 
20 #include "TStatsFeedback.h"
21 
22 #include "TError.h"
23 #include "TH1.h"
24 #include "TH2.h"
25 #include "THashList.h"
26 #include "TObjString.h"
27 #include "TProof.h"
28 #include "TProofDebug.h"
29 #include "TROOT.h"
30 #include "TSeqCollection.h"
31 #include "TStyle.h"
32 #include "TVirtualPad.h"
33 
34 ClassImp(TStatsFeedback);
35 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor
39 
40 TStatsFeedback::TStatsFeedback(TProof *proof)
41 {
42  if (proof == 0) proof = gProof;
43 
44  TProof *p = dynamic_cast<TProof*>(proof);
45  if (p == 0) {
46  Error("TStatsFeedback", "no valid proof session found");
47  SetBit(TObject::kInvalidObject);
48  return;
49  }
50  fProof = p;
51  fName = fProof->GetSessionTag();
52 
53  if (!(proof->Connect("Feedback(TList*)", "TStatsFeedback",
54  this, "Feedback(TList*)"))) {
55  Error("TStatsFeedback", "Connect() failed");
56  SetBit(TObject::kInvalidObject);
57  return;
58  }
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Destructor
63 
64 TStatsFeedback::~TStatsFeedback()
65 {
66  // Required since we overload TObject::Hash.
67  ROOT::CallRecursiveRemoveIfNeeded(*this);
68 
69  fProof->Disconnect("Feedback(TList*)", this, "Feedback(TList*");
70 }
71 
72 ////////////////////////////////////////////////////////////////////////////////
73 /// Display feedback
74 
75 void TStatsFeedback::Feedback(TList *objs)
76 {
77  TSeqCollection *canvases = gROOT->GetListOfCanvases();
78 
79  PDB(kFeedback,1) Info("Feedback", "%d Objects", objs->GetSize());
80 
81  // Attach to the histograms we want to plot
82  TH1D *hevt = 0, *hpck = 0;
83  TH1I *hass = 0;
84  TIter next(objs);
85  TObject *o = 0;
86  while((o = next())) {
87  if (!strcmp(o->GetName(), "PROOF_EventsHist")) {
88  hevt = dynamic_cast<TH1D *>(o);
89  } else if (!strcmp(o->GetName(), "PROOF_PacketsHist")) {
90  hpck = dynamic_cast<TH1D *>(o);
91  } else if (!strcmp(o->GetName(), "PROOF_ProcPcktHist")) {
92  hass = dynamic_cast<TH1I *>(o);
93  }
94  if (hevt && hpck && hass) break;
95  }
96  if (!hevt && !hpck && !hass) {
97  Warning("Feedback", "none of the requested histograms has been found!");
98  return;
99  }
100 
101  // Number of histograms
102  Int_t nh = 3;
103  if (!hass) nh = 2;
104  // Create or attach to canvas
105  TString cvnm = TString::Format("Stats: %s", fProof->GetSessionTag());
106  TVirtualPad *cv = 0;
107  if (gROOT->GetListOfCanvases())
108  cv = (TVirtualPad *) canvases->FindObject(cvnm.Data());
109  if (cv && nh == 3 && !cv->GetPad(3)) SafeDelete(cv);
110  if (!cv) {
111  Int_t h = (nh == 3) ? 600 : 400;
112  TString cvcmd = TString::Format("new TCanvas(\"%s\", \"Feedback Stats\",10,300,600,%d)",
113  cvnm.Data(), h);
114  if (!(cv = (TVirtualPad *) gROOT->ProcessLine(cvcmd))) {
115  Warning("Feedback", "could not create canvas!");
116  return;
117  }
118  PDB(kFeedback,2) Info("Feedback", "created canvas %s", cvnm.Data());
119  // Create pads
120  cv->Divide(1, nh);
121  } else {
122  cv->cd();
123  PDB(kFeedback,2) Info("Feedback", "using canvas %s", cvnm.Data());
124  }
125  TVirtualPad *pd1 = (TVirtualPad *) cv->GetPad(1);
126  TVirtualPad *pd2 = (TVirtualPad *) cv->GetPad(2);
127  TVirtualPad *pd3 = (nh == 3) ? (TVirtualPad *) cv->GetPad(3) : 0;
128 
129  UInt_t optstat = gStyle->GetOptStat();
130  gStyle->SetOptStat(11);
131  // Plot
132  if (hevt) {
133  if (pd1) pd1->cd();
134  hevt->SetFillColor(kGreen);
135  hevt->DrawCopy();
136  }
137  if (hpck) {
138  if (pd2) pd2->cd();
139  hpck->SetFillColor(kAzure-5);
140  hpck->DrawCopy();
141  }
142  if (hass) {
143  if (pd3) pd3->cd();
144  hass->SetFillColor(kGray);
145  hass->SetMaximum(2);
146  hass->DrawCopy();
147  }
148 
149  cv->cd();
150  cv->Update();
151  gStyle->SetOptStat(optstat);
152 }