Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TDrawFeedback.cxx
Go to the documentation of this file.
1 // @(#)root/proofplayer:$Id$
2 // Author: Maarten Ballintijn 28/10/2003
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 /** \class TDrawFeedback
13 \ingroup proofkernel
14 
15 Utility class to draw objects in the feedback list during queries.
16 Draws histograms in separated canvases and user-defined objects via
17 Draw(). Users requiring advanced treatment should implement their
18 own version following this example. See also TStatsFeedback.
19 
20 */
21 
22 #include "TDrawFeedback.h"
23 
24 #include "THashList.h"
25 #include "TObjString.h"
26 #include "TProof.h"
27 #include "TROOT.h"
28 #include "TH1.h"
29 #include "TH2.h"
30 #include "TError.h"
31 #include "TSeqCollection.h"
32 #include "TVirtualPad.h"
33 #include "TProofDebug.h"
34 
35 ClassImp(TDrawFeedback);
36 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor
40 
41 TDrawFeedback::TDrawFeedback(TProof *proof, TSeqCollection *names)
42  : fAll(kFALSE)
43 {
44  fNames = new THashList;
45  fNames->SetOwner();
46 
47  if (proof == 0) proof = gProof;
48 
49  TProof *p = dynamic_cast<TProof*>(proof);
50  if (p == 0) {
51  Error("TDrawFeedback","no valid proof session found");
52  return;
53  }
54  fProof = p;
55  fName = fProof->GetSessionTag();
56 
57  Bool_t ok = proof->Connect("Feedback(TList*)", "TDrawFeedback",
58  this, "Feedback(TList*)");
59 
60  if ( !ok ) {
61  Error("TDrawFeedback","Connect() failed");
62  return;
63  }
64 
65  if (names != 0) {
66  TIter next(names);
67  TObjString *name;
68  while((name = dynamic_cast<TObjString*>(next())) != 0) {
69  fNames->Add(new TNamed(name->GetName(),""));
70  }
71  } else {
72  fAll = kTRUE;
73  }
74  fOption = 0;
75 }
76 
77 ////////////////////////////////////////////////////////////////////////////////
78 /// Destructor
79 
80 TDrawFeedback::~TDrawFeedback()
81 {
82  delete fNames;
83 
84  // Required since we overload TObject::Hash.
85  ROOT::CallRecursiveRemoveIfNeeded(*this);
86 
87  fProof->Disconnect("Feedback(TList*)", this, "Feedback(TList*");
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// Display feedback
92 
93 void TDrawFeedback::Feedback(TList *objs)
94 {
95  TSeqCollection *canvases = gROOT->GetListOfCanvases();
96  TVirtualPad *save = gPad;
97 
98  PDB(kFeedback,1) Info("Feedback","%d Objects", objs->GetSize());
99 
100  TIter next(objs);
101  TObject *o;
102  while( (o = next()) )
103  {
104  TString name = o->GetName();
105  if (fAll || fNames->FindObject(name.Data())) {
106 
107  if (TH1 *h = dynamic_cast<TH1*>(o)) {
108 
109  // Basic service provided fro histograms, each one drawn in
110  // a separate canvas named '<histogram_name>_canvas'
111 
112  name += "_canvas";
113 
114  TVirtualPad *p = (TVirtualPad*) canvases->FindObject(name.Data());
115 
116  if ( p == 0 ) {
117  gROOT->MakeDefCanvas();
118  gPad->SetName(name);
119  PDB(kFeedback,2) Info("Feedback","Created canvas %s", name.Data());
120  } else {
121  p->cd();
122  PDB(kFeedback,2) Info("Feedback","Used canvas %s", name.Data());
123  }
124 
125  h->DrawCopy(fOption);
126  gPad->Update();
127 
128  } else {
129 
130  // Call the Draw method of the object; this is intended for user-defined
131  // objects handling their canvas needs inside Draw() as needed
132  o->Draw();
133  }
134 
135  }
136  }
137 
138  if (save != 0) {
139  save->cd();
140  } else {
141  gPad = 0;
142  }
143 }