Logo ROOT   6.08/07
Reference Guide
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 
35 
36 
37 ////////////////////////////////////////////////////////////////////////////////
38 /// Constructor
39 
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");
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");
57  return;
58  }
59 }
60 
61 ////////////////////////////////////////////////////////////////////////////////
62 /// Destructor
63 
65 {
66  fProof->Disconnect("Feedback(TList*)", this, "Feedback(TList*");
67 }
68 
69 ////////////////////////////////////////////////////////////////////////////////
70 /// Display feedback
71 
73 {
74  TSeqCollection *canvases = gROOT->GetListOfCanvases();
75 
76  PDB(kFeedback,1) Info("Feedback", "%d Objects", objs->GetSize());
77 
78  // Attach to the histograms we want to plot
79  TH1D *hevt = 0, *hpck = 0;
80  TH1I *hass = 0;
81  TIter next(objs);
82  TObject *o = 0;
83  while((o = next())) {
84  if (!strcmp(o->GetName(), "PROOF_EventsHist")) {
85  hevt = dynamic_cast<TH1D *>(o);
86  } else if (!strcmp(o->GetName(), "PROOF_PacketsHist")) {
87  hpck = dynamic_cast<TH1D *>(o);
88  } else if (!strcmp(o->GetName(), "PROOF_ProcPcktHist")) {
89  hass = dynamic_cast<TH1I *>(o);
90  }
91  if (hevt && hpck && hass) break;
92  }
93  if (!hevt && !hpck && !hass) {
94  Warning("Feedback", "none of the requested histograms has been found!");
95  return;
96  }
97 
98  // Number of histograms
99  Int_t nh = 3;
100  if (!hass) nh = 2;
101  // Create or attach to canvas
102  TString cvnm = TString::Format("Stats: %s", fProof->GetSessionTag());
103  TVirtualPad *cv = 0;
104  if (gROOT->GetListOfCanvases())
105  cv = (TVirtualPad *) canvases->FindObject(cvnm.Data());
106  if (cv && nh == 3 && !cv->GetPad(3)) SafeDelete(cv);
107  if (!cv) {
108  Int_t h = (nh == 3) ? 600 : 400;
109  TString cvcmd = TString::Format("new TCanvas(\"%s\", \"Feedback Stats\",10,300,600,%d)",
110  cvnm.Data(), h);
111  if (!(cv = (TVirtualPad *) gROOT->ProcessLine(cvcmd))) {
112  Warning("Feedback", "could not create canvas!");
113  return;
114  }
115  PDB(kFeedback,2) Info("Feedback", "created canvas %s", cvnm.Data());
116  // Create pads
117  cv->Divide(1, nh);
118  } else {
119  cv->cd();
120  PDB(kFeedback,2) Info("Feedback", "using canvas %s", cvnm.Data());
121  }
122  TVirtualPad *pd1 = (TVirtualPad *) cv->GetPad(1);
123  TVirtualPad *pd2 = (TVirtualPad *) cv->GetPad(2);
124  TVirtualPad *pd3 = (nh == 3) ? (TVirtualPad *) cv->GetPad(3) : 0;
125 
126  UInt_t optstat = gStyle->GetOptStat();
127  gStyle->SetOptStat(11);
128  // Plot
129  if (hevt) {
130  if (pd1) pd1->cd();
131  hevt->SetFillColor(kGreen);
132  hevt->DrawCopy();
133  }
134  if (hpck) {
135  if (pd2) pd2->cd();
136  hpck->SetFillColor(kAzure-5);
137  hpck->DrawCopy();
138  }
139  if (hass) {
140  if (pd3) pd3->cd();
141  hass->SetFillColor(kGray);
142  hass->SetMaximum(2);
143  hass->DrawCopy();
144  }
145 
146  cv->cd();
147  cv->Update();
148  gStyle->SetOptStat(optstat);
149 }
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:899
virtual TVirtualPad * GetPad(Int_t subpadnumber) const =0
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:399
R__EXTERN TStyle * gStyle
Definition: TStyle.h:418
TH1 * h
Definition: legend2.C:5
Definition: Rtypes.h:60
#define gROOT
Definition: TROOT.h:364
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:2897
Definition: Rtypes.h:61
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
#define SafeDelete(p)
Definition: RConfig.h:507
Sequenceable collection abstract base class.
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2335
#define PDB(mask, level)
Definition: TProofDebug.h:58
void Feedback(TList *objs)
Display feedback.
const char * GetSessionTag() const
Definition: TProof.h:939
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
Definition: Rtypes.h:62
void Error(const char *location, const char *msgfmt,...)
A doubly linked list.
Definition: TList.h:47
~TStatsFeedback()
Destructor.
if object ctor succeeded but object should not be used
Definition: TObject.h:63
virtual void SetFillColor(Color_t fcolor)
Set the fill area color.
Definition: TAttFill.h:42
tomato 1-D histogram with an int per channel (see TH1 documentation)}
Definition: TH1.h:534
unsigned int UInt_t
Definition: RtypesCore.h:42
tomato 1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:618
R__EXTERN TProof * gProof
Definition: TProof.h:1107
#define ClassImp(name)
Definition: Rtypes.h:279
Int_t GetOptStat() const
Definition: TStyle.h:245
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:346
Bool_t Disconnect(const char *signal=0, void *receiver=0, const char *slot=0)
Disconnects signal of this object from slot of receiver.
Definition: TQObject.cxx:1295
Mother of all ROOT objects.
Definition: TObject.h:37
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition: TStyle.cxx:1257
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
Utility class to display PROOF stats feedback histos during queries.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:416
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:911
const char * Data() const
Definition: TString.h:349