ROOT  6.06/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 //////////////////////////////////////////////////////////////////////////
13 // //
14 // TDrawFeedback //
15 // //
16 // Utility class to draw objects in the feedback list during queries. //
17 // Draws histograms in separated canvases and user-defined objects via //
18 // Draw(). Users requiring advanced treatment should implement their //
19 // own version following this example. See also TStatsFeedback. //
20 // //
21 //////////////////////////////////////////////////////////////////////////
22 
23 #include "TDrawFeedback.h"
24 
25 #include "THashList.h"
26 #include "TObjString.h"
27 #include "TProof.h"
28 #include "TROOT.h"
29 #include "TH1.h"
30 #include "TH2.h"
31 #include "TError.h"
32 #include "TSeqCollection.h"
33 #include "TVirtualPad.h"
34 #include "TProofDebug.h"
35 
37 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// Constructor
41 
43  : fAll(kFALSE)
44 {
45  fNames = new THashList;
46  fNames->SetOwner();
47 
48  if (proof == 0) proof = gProof;
49 
50  TProof *p = dynamic_cast<TProof*>(proof);
51  if (p == 0) {
52  Error("TDrawFeedback","no valid proof session found");
53  return;
54  }
55  fProof = p;
56  fName = fProof->GetSessionTag();
57 
58  Bool_t ok = proof->Connect("Feedback(TList *objs)", "TDrawFeedback",
59  this, "Feedback(TList *objs)");
60 
61  if ( !ok ) {
62  Error("TDrawFeedback","Connect() failed");
63  return;
64  }
65 
66  if (names != 0) {
67  TIter next(names);
69  while((name = dynamic_cast<TObjString*>(next())) != 0) {
70  fNames->Add(new TNamed(name->GetName(),""));
71  }
72  } else {
73  fAll = kTRUE;
74  }
75  fOption = 0;
76 }
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 /// Destructor
80 
82 {
83  delete fNames;
84  fProof->Disconnect("Feedback(TList*)", this, "Feedback(TList*");
85 }
86 
87 ////////////////////////////////////////////////////////////////////////////////
88 /// Display feedback
89 
91 {
92  TSeqCollection *canvases = gROOT->GetListOfCanvases();
93  TVirtualPad *save = gPad;
94 
95  PDB(kFeedback,1) Info("Feedback","%d Objects", objs->GetSize());
96 
97  TIter next(objs);
98  TObject *o;
99  while( (o = next()) )
100  {
101  TString name = o->GetName();
102  if (fAll || fNames->FindObject(name.Data())) {
103 
104  if (TH1 *h = dynamic_cast<TH1*>(o)) {
105 
106  // Basic service provided fro histograms, each one drawn in
107  // a separate canvas named '<histogram_name>_canvas'
108 
109  name += "_canvas";
110 
111  TVirtualPad *p = (TVirtualPad*) canvases->FindObject(name.Data());
112 
113  if ( p == 0 ) {
114  gROOT->MakeDefCanvas();
115  gPad->SetName(name);
116  PDB(kFeedback,2) Info("Feedback","Created canvas %s", name.Data());
117  } else {
118  p->cd();
119  PDB(kFeedback,2) Info("Feedback","Used canvas %s", name.Data());
120  }
121 
122  h->DrawCopy(fOption);
123  gPad->Update();
124 
125  } else {
126 
127  // Call the Draw method of the object; this is intended for user-defined
128  // objects handling their canvas needs inside Draw() as needed
129  o->Draw();
130  }
131 
132  }
133  }
134 
135  if (save != 0) {
136  save->cd();
137  } else {
138  gPad = 0;
139  }
140 }
const char * GetName() const
Returns name of object.
Definition: TObjString.h:42
virtual TObject * FindObject(const char *name) const
Find an object in this collection using its name.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
Collectable string class.
Definition: TObjString.h:32
TObject * FindObject(const char *name) const
Find object using its name.
Definition: THashList.cxx:212
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
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition: TObject.cxx:892
THashList * fNames
Definition: TDrawFeedback.h:43
#define gROOT
Definition: TROOT.h:340
Basic string class.
Definition: TString.h:137
const char * GetSessionTag() const
Definition: TProof.h:942
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:254
void Feedback(TList *objs)
Display feedback.
ClassImp(TDrawFeedback) TDrawFeedback
Constructor.
virtual TVirtualPad * cd(Int_t subpadnumber=0)=0
const char * Data() const
Definition: TString.h:349
Sequenceable collection abstract base class.
#define PDB(mask, level)
Definition: TProofDebug.h:58
THashList implements a hybrid collection class consisting of a hash table and a list to store TObject...
Definition: THashList.h:36
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
TProof * fProof
Definition: TDrawFeedback.h:47
virtual TH1 * DrawCopy(Option_t *option="", const char *name_postfix="_copy") const
Copy this histogram and Draw in the current pad.
Definition: TH1.cxx:2925
TVirtualPad is an abstract base class for the Pad and Canvas classes.
Definition: TVirtualPad.h:59
void Error(const char *location, const char *msgfmt,...)
A doubly linked list.
Definition: TList.h:47
Option_t * fOption
Definition: TDrawFeedback.h:46
R__EXTERN TProof * gProof
Definition: TProof.h:1110
virtual Int_t GetSize() const
Definition: TCollection.h:95
virtual const char * GetName() const
Returns name of object.
Definition: TObject.cxx:415
Definition: TProof.h:339
The TH1 histogram class.
Definition: TH1.h:80
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:1293
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
const char Int_t const char TProof * proof
Definition: TXSlave.cxx:46
#define gPad
Definition: TVirtualPad.h:288
const Bool_t kTRUE
Definition: Rtypes.h:91
~TDrawFeedback()
Destructor.