GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PadManager.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004-2006 by Olivier Stezowski & Christian Finck *
3  * stezow(AT)ipnl.in2p3.fr, cfinck(AT)ires.in2p3.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
20 
23 #ifndef Gw_PadManager
24 #define Gw_PadManager
25 
26 #include <list>
27 
28 #include "Rtypes.h"
29 #include "GwLogMessage.h"
30 
31 #include "TVirtualPad.h"
32 #include "TList.h"
33 #include "TObjArray.h"
34 #include "TH1.h"
35 #include "TFolder.h"
36 #include "TRegexp.h"
37 
38 class TF1;
39 class TGraph;
40 class TPolyLine;
41 
42 namespace Gw {
43 
47 class PadManager
48 {
49 public:
51 
60 
61 protected:
62  mutable LogMessage fLog; // log message
63 
64 public:
65  PadManager() ;
66  virtual ~PadManager() ;
67 
69  static TH1 * GetHisto(TVirtualPad *pad = 0x0 , Option_t *op = "");
70  static TGraph * GetGraph(TVirtualPad *pad = 0x0, Option_t *op = "" );
71 
72 
74  // static Bool_t IsActionOn(TVirtualPad *pad, EActionMode);
76  // static EActionMode WhatActionOn(TVirtualPad *pad);
78  // static EActionMode SetActionOn(TVirtualPad *pad, EActionMode amode);
79 
81  template <typename Data_T> static void Collect(TList &list, TVirtualPad *pad = 0x0)
82  {
83  // to get the pad on which the creator is added
84  TVirtualPad *locpad = 0x0;
85  if ( pad == 0x0 )
86  if ( TVirtualPad::Pad() == 0x0 )
87  return ;
88  else
89  locpad = TVirtualPad::Pad();
90  else
91  locpad = pad;
92 
93  TObject* obj = 0x0; TIter next(locpad->GetListOfPrimitives());
94  while ( (obj = next()) ) { //
95  if ( obj->InheritsFrom(Data_T::Class_Name()) )
96  list.Add(obj);
97  }
98  }
100  template <typename Data_T> static void Collect(std::vector<Data_T *> &array, TVirtualPad *pad = 0x0)
101  {
102  // to get the pad on which the creator is added
103  TVirtualPad *locpad = 0x0;
104  if ( pad == 0x0 )
105  if ( TVirtualPad::Pad() == 0x0 )
106  return ;
107  else
108  locpad = TVirtualPad::Pad();
109  else
110  locpad = pad;
111 
112  TObject* obj = 0x0; TIter next(locpad->GetListOfPrimitives());
113  while ( (obj = next()) ) { //
114  if ( obj->InheritsFrom(Data_T::Class_Name()) )
115  array.push_back((Data_T *)obj);
116  }
117  }
119  template <typename Data_T> static void Collect(TList *collected, TFolder *from,
120  const char *inc = "*", const char *exc = "",
121  const char *inc_class = "TFH1*", const char *exc_class = "-", Int_t depth = kMaxInt)
122  {
123  TString include(inc), exclude(exc), include_class(inc_class), exclude_class(exc_class), tmp_obj = "", tmp_token = "", tmp_class = "";
124  Bool_t wildcard;
125  TIter next(from->GetListOfFolders()); TObject *an_obj = 0x0, *a_token = 0x0;
126 
127  // collect objects from the current folder. if a folder is found, recursive call of this
128  while ( (an_obj=next()) ) {
129 
130  tmp_obj = an_obj->GetName(); tmp_class = an_obj->ClassName();
131 
132  // tokenize include and exclude filter
133  TObjArray *all_token_include = include.Tokenize(" "),
134  *all_token_exclude = exclude.Tokenize(" "), *all_token_include_class = include_class.Tokenize(" "), *all_token_exclude_class = exclude_class.Tokenize(" ");
135  Bool_t add_it = false, exclude_it = false, add_it_class = false, exclude_it_class = false;
136 
137  // check include
138  TIter token_include(all_token_include);
139  while ( (a_token = token_include()) ) {
140 
141  tmp_token = a_token->GetName();
142 
143  // pattern expression
144  wildcard = false;
145  if ( tmp_token.Contains("*") )
146  wildcard = true;
147  TRegexp kept(tmp_token,wildcard);
148 
149  if ( tmp_obj.Contains(kept) && an_obj->InheritsFrom(Data_T::Class_Name()) ) {
150  add_it = true;
151  break;
152  }
153  }
154  // check exclude
155  TIter token_exclude(all_token_exclude);
156  while ( (a_token = token_exclude()) ) {
157 
158  tmp_token = a_token->GetName();
159 
160  // pattern expression
161  wildcard = false;
162  if ( tmp_token.Contains("*") )
163  wildcard = true;
164  TRegexp nokept(tmp_token,wildcard);
165 
166  if ( tmp_obj.Contains(nokept) && an_obj->InheritsFrom(Data_T::Class_Name()) ) {
167  exclude_it = true;
168  break;
169  }
170  }
171  // check include class name
172  TIter token_include_class(all_token_include_class);
173  while ( (a_token = token_include_class()) ) {
174 
175  tmp_token = a_token->GetName();
176 
177  // pattern expression
178  wildcard = false;
179  if ( tmp_token.Contains("*") )
180  wildcard = true;
181  TRegexp kept(tmp_token,wildcard);
182 
183  if ( tmp_class.Contains(kept) ) {
184  add_it_class = true;
185  break;
186  }
187  }
188  // check exclude
189  TIter token_exclude_class(all_token_exclude_class);
190  while ( (a_token = token_exclude_class()) ) {
191 
192  tmp_token = a_token->GetName();
193 
194  // pattern expression
195  wildcard = false;
196  if ( tmp_token.Contains("*") )
197  wildcard = true;
198  TRegexp nokept(tmp_token,wildcard);
199 
200  if ( tmp_class.Contains(nokept) ) {
201  exclude_it = true;
202  break;
203  }
204  }
205 
206  // it is the charge of the user to delete Tokenized collection
207  if ( all_token_include ) {
208  delete all_token_include; all_token_include = 0x0;
209  }
210  if ( all_token_exclude ) {
211  delete all_token_exclude; all_token_exclude = 0x0;
212  }
213  if ( all_token_include_class ) {
214  delete all_token_include_class; all_token_include_class = 0x0;
215  }
216  if ( all_token_exclude_class ) {
217  delete all_token_exclude_class; all_token_exclude_class = 0x0;
218  }
219 
220  //printf("%s %s with filter %s , %s , %s , %s \n",tmp_obj.Data(),tmp_class.Data(),inc,exc,inc_class,exc_class);
221  // now if it passes the filters, add it
222  if ( add_it && !exclude_it && add_it_class && !exclude_it_class && !an_obj->InheritsFrom("TFolder") ) {
223  collected->Add(an_obj);
224  }
225  // and check recursively if it is required
226  if ( an_obj->InheritsFrom("TFolder") && depth > 0 ) { // recursive call through the tree
227  Collect<Data_T>(collected,(TFolder *)an_obj,inc,exc,inc_class,exc_class,depth--);
228  continue;
229  }
230  }
231  }
232 
234  static TPolyLine *ShowDiff(const TH1 *h, const TF1 *f, Double_t xmin, Double_t xmax);
235 
236 
237 
238  ClassDef(PadManager, 0); // to manage ROOT pads and canvases
239 };
240 
241 } // end namespace
242 
243 #endif
Base class for a Log message.
Definition: GwLogMessage.h:94
LogMessage fLog
Definition: PadManager.h:62
static TPolyLine * ShowDiff(const TH1 *h, const TF1 *f, Double_t xmin, Double_t xmax)
show a polyline calculated as the difference between an histogram and a function (used for instance f...
Definition: PadManager.cpp:128
header file for GwLogMessage.cpp
static EActionMode gActionMode
Global to be applied on Canvas that are not Gw::Canvas or dont't have an individual mode...
Definition: PadManager.h:59
static void Collect(TList *collected, TFolder *from, const char *inc="*", const char *exc="", const char *inc_class="TFH1*", const char *exc_class="-", Int_t depth=kMaxInt)
Collect kind of object from a tfolder applying a pattern, excuding another one and digging up to dept...
Definition: PadManager.h:119
virtual ~PadManager()
Definition: PadManager.cpp:61
static void Collect(TList &list, TVirtualPad *pad=0x0)
check if the action is
Definition: PadManager.h:81
ClassDef(PadManager, 0)
static TH1 * GetHisto(TVirtualPad *pad=0x0, Option_t *op="")
look for an histogram into the pad
Definition: PadManager.cpp:67
static void Collect(std::vector< Data_T * > &array, TVirtualPad *pad=0x0)
Collect kind of object from a pad.
Definition: PadManager.h:100
static TGraph * GetGraph(TVirtualPad *pad=0x0, Option_t *op="")
Definition: PadManager.cpp:101