Logo ROOT   6.10/09
Reference Guide
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 
36 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor
40 
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);
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 
81 {
82  delete fNames;
83  fProof->Disconnect("Feedback(TList*)", this, "Feedback(TList*");
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// Display feedback
88 
90 {
91  TSeqCollection *canvases = gROOT->GetListOfCanvases();
92  TVirtualPad *save = gPad;
93 
94  PDB(kFeedback,1) Info("Feedback","%d Objects", objs->GetSize());
95 
96  TIter next(objs);
97  TObject *o;
98  while( (o = next()) )
99  {
100  TString name = o->GetName();
101  if (fAll || fNames->FindObject(name.Data())) {
102 
103  if (TH1 *h = dynamic_cast<TH1*>(o)) {
104 
105  // Basic service provided fro histograms, each one drawn in
106  // a separate canvas named '<histogram_name>_canvas'
107 
108  name += "_canvas";
109 
110  TVirtualPad *p = (TVirtualPad*) canvases->FindObject(name.Data());
111 
112  if ( p == 0 ) {
113  gROOT->MakeDefCanvas();
114  gPad->SetName(name);
115  PDB(kFeedback,2) Info("Feedback","Created canvas %s", name.Data());
116  } else {
117  p->cd();
118  PDB(kFeedback,2) Info("Feedback","Used canvas %s", name.Data());
119  }
120 
121  h->DrawCopy(fOption);
122  gPad->Update();
123 
124  } else {
125 
126  // Call the Draw method of the object; this is intended for user-defined
127  // objects handling their canvas needs inside Draw() as needed
128  o->Draw();
129  }
130 
131  }
132  }
133 
134  if (save != 0) {
135  save->cd();
136  } else {
137  gPad = 0;
138  }
139 }
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:847
Collectable string class.
Definition: TObjString.h:28
virtual void SetOwner(Bool_t enable=kTRUE)
Set whether this collection is the owner (enable==true) of its content.
TH1 * h
Definition: legend2.C:5
THashList * fNames
Definition: TDrawFeedback.h:39
#define gROOT
Definition: TROOT.h:375
Basic string class.
Definition: TString.h:129
bool Bool_t
Definition: RtypesCore.h:59
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:2898
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:202
void Feedback(TList *objs)
Display feedback.
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:213
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
Sequenceable collection abstract base class.
#define PDB(mask, level)
Definition: TProofDebug.h:56
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:34
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:29
TProof * fProof
Definition: TDrawFeedback.h:43
const char * GetSessionTag() const
Definition: TProof.h:913
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:49
void Error(const char *location, const char *msgfmt,...)
A doubly linked list.
Definition: TList.h:43
Option_t * fOption
Definition: TDrawFeedback.h:42
const char * GetName() const
Returns name of object.
Definition: TObjString.h:39
const Bool_t kFALSE
Definition: RtypesCore.h:92
R__EXTERN TProof * gProof
Definition: TProof.h:1081
#define ClassImp(name)
Definition: Rtypes.h:336
This class controls a Parallel ROOT Facility, PROOF, cluster.
Definition: TProof.h:320
The TH1 histogram class.
Definition: TH1.h:56
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:1025
Mother of all ROOT objects.
Definition: TObject.h:37
Utility class to draw objects in the feedback list during queries.
Definition: TDrawFeedback.h:35
#define gPad
Definition: TVirtualPad.h:284
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:364
virtual Int_t GetSize() const
Definition: TCollection.h:89
const Bool_t kTRUE
Definition: RtypesCore.h:91
~TDrawFeedback()
Destructor.
const char * Data() const
Definition: TString.h:347