GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TTreeWatchers.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2004 by Olivier Stezowski *
3  * stezow(AT)ipnl.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_TTreeWatchers
24 #define Gw_TTreeWatchers
25 
26 #include "Watchers.h"
27 #include "GCondition.h"
28 
29 #include "TTree.h"
30 #include "TH1.h"
31 #include "TH2.h"
32 #include "TLeaf.h"
33 
34 namespace Gw
35 {
36 
38 /*
39 
40  DoSpectra (default = 2) :
41  - 0 user spectra are not filled. Spectra under GCondition are always filled
42  - 1 user spectra are filled only if the global conditions for this watcher is passed
43  - 2 user spectra are always filled
44 
45  DoTree (default = 2) :
46  - 0 Tree is not filled
47  - 1 Tree is filled only if condition
48  - 2 Tree is filled and TEntryList is build
49 
50 */
52 {
53 protected:
55  static TString gDefaultPathOfOut;
56  static TString gDefaultTTreeName;
57 
58 protected:
59  // the tree to be filled by the watcher
60  TTree *fMyTree;
61  // true if the tree belongs to this
62  Bool_t fIsOwner;
63 
64 protected:
65  // 0 no, 1 fill spectra only if condition is filled, 2 fill specta in any cases
66  Short_t fDoSpectra;
67  // 0 no, 1 fill the tree only is all conditions passed , 2 fill the tree and the TEntryList
68  Short_t fDoTree;
69 
70 protected:
71  // number of container of conditions (GCondition) on this watcher
72  Short_t fNbConditions;
73 
74 protected:
75  // Should be implemented to set properly the branches in new or update mode
76  virtual void SetBranches() = 0;
78  virtual void FillTree();
79 
80 public:
81  TTreeBuilder(const char *name, const char *title, TTree *tree = 0x0, Short_t do_spectra = 2, Short_t do_tree = 2, Bool_t Overwrite = false);
82  virtual ~TTreeBuilder();
83 
84 
86  Short_t GetDoSpectra() const
87  {
88  return fDoSpectra;
89  }
91  Short_t GetDoTree() const
92  {
93  return fDoTree;
94  }
96  void SetDoSpectra(Short_t do_spectra)
97  {
98  fDoSpectra = do_spectra;
99  }
101  void SetDoTree(Short_t do_tree)
102  {
103  fDoTree = do_tree;
104  }
105 
107  virtual Int_t GetNbConditions() const
108  {
109  return fNbConditions;
110  }
111 
113  TTree *GetTree()
114  { return fMyTree; }
115 };
116 
118 /*
119 
120 */
121 class TTreeMaster : public Watcher, public TTreeBuilder
122 {
123 private:
124  // list of Watchers filling a branch
125  TList fListOfWatchers;
126 
127 protected:
129  TH1 *fErrors;
130 
131 protected:
132  // Should be implemented to set properly the branches in new or update mode
133  virtual void SetBranches()
134  {;}
135 
136 public:
137  TTreeMaster(const char *name, const char *title, Short_t do_spectra = 2, Short_t do_tree = 2, Bool_t Overwrite = false);
138  virtual ~TTreeMaster();
139 
141  static void SetDefaultPathAndName(const char *new_path = "./Out",const char *treename = "TreeMaster");
142 
143  /*
144  virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_for_tag, Bool_t load_objects = true)
145  {
146  Watcher::SetDirectory(mother_dir_of_watcher,mother_dir_for_tag,load_objects);
147  }
148  */
149 
151 
160  virtual UInt_t Snapshot(Option_t * = "*"); //*MENU*
161 
163  template<typename Watcher_T> Watcher_T * Add(const Char_t *name, const Char_t *title, Short_t do_spectra, Short_t do_tree)
164  {
165  Watcher_T *watcher = new Watcher_T(name,title,GetTree(),do_spectra,do_tree);
166  Add( watcher );
167 
168  return watcher;
169  }
171  template<typename Watcher_T> Watcher_T * Add(const Char_t *name, const Char_t *title)
172  {
173  Watcher_T *watcher = new Watcher_T(name,title,GetTree());
174  Add( watcher );
175 
176  return watcher;
177  }
178 
180  template<typename Watcher_T> Watcher_T * AddWatcher(const Char_t *name, const Char_t *title)
181  {
182  Watcher_T *watcher = new Watcher_T(name,title);
183  Add( watcher );
184 
185  return watcher;
186  }
187 
189  virtual void FillTree()
190  {
191  if ( GetTree() )
192  GetTree()->Fill();
193  }
194 
196  virtual void Add(TTask *);
197 
199 
202  virtual void Add(Watcher *, ADF::DFTrigger *);
203 
205  virtual void Exec(Option_t *option="");
206 
207  virtual void Print(Option_t *) const; //*MENU*
208 
209  ClassDef(TTreeMaster,0) // Watcher that owns the tree and call Fill
210 };
211 
214 {
215 private:
216  TLeaf *fData;
217 
218 private:
219  TH1 *fHisto;
220 
221 public:
222  SimpleGCondHandler1D(GCondition *cond, TLeaf *data, TH1 *h) : GCondHandler(cond), fData(data), fHisto(h)
223  {;}
225  {;}
226 
227  virtual Bool_t Check();
228  virtual void Fill()
229  {
230  for (Int_t i = 0; i < fData->GetLen(); i++) {
231  fHisto->Fill(fData->GetValue(i));
232  }
233  }
234 };
235 
237 {
238 private:
239  TLeaf *fData1;
240  TLeaf *fData2;
241 
242 private:
243  TH1 *fHisto;
244 
245 public:
246  SimpleGCondHandler2D(GCondition *cond, TLeaf *data1, TLeaf *data2, TH1 *h) : GCondHandler(cond), fData1(data1), fData2(data2), fHisto(h)
247  {;}
249  {;}
250 
251  virtual Bool_t Check()
252  {
253  Bool_t is_passed = false;
254  //
255  for (Int_t i = 0; i < fData1->GetLen(); i++) {
256  for (Int_t j = 0; j < fData2->GetLen(); j++) {
257  if ( fCond->IsPassed(fData1->GetValue(i),fData2->GetValue(j)) )
258  is_passed = true;
259  }
260  }
261  return is_passed;
262  }
263  virtual void Fill()
264  {
265  for (Int_t i = 0; i < fData1->GetLen(); i++) {
266  for (Int_t j = 0; j < fData2->GetLen(); j++) {
267  fHisto->Fill(fData1->GetValue(i),fData2->GetValue(j));
268  }
269  }
270  }
271 };
272 
274 
278 class TTreeWithConditions : public Watcher, public TTreeBuilder
279 {
280 protected:
282  TTree *fClone;
283 protected:
285  std::list < GCondHandler * > fCondHandler;
286 protected:
288  std::list < GCondition * > fUserGCond;
289 protected:
291  std::vector < TTreeFormula * > fUserTFCond;
292 protected:
294  std::vector < GCondition * > fAllGCond;
295 
296 protected:
298  virtual void Clear(Option_t* = "") = 0;
299 protected:
301  virtual void AddBranches(TTree *tree) = 0;
303  virtual void FillBranches() = 0;
304 
305 protected:
307  virtual void SetBranches()
308  {
309  if ( fDoTree > 0 )
310  AddBranches(GetTree());
312  }
313 protected:
315  virtual void BuildSpectraByUser()
316  {;}
318  virtual void FillSpectraByUser()
319  {;}
320 
321 protected:
323  virtual std::pair< GCond1D *, TH1 * > MakeGCond1D(
324  const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
325  const Char_t *name_hist, const Char_t *title_hist , Int_t bin, Double_t min, Double_t max,
326  Option_t *opt = "F",
327  const Char_t *sub = "");
329  /*
330  The leaf name should have the form X:Y otherwise it fails
331  */
332  virtual std::pair< GCond2D *, TH2 * > MakeGCond2D(
333  const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
334  const Char_t *name_hist, const Char_t *title_hist, Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax,
335  Option_t *opt = "F",
336  const Char_t *sub = "");
337 
339  virtual GCond1D * MakeGCond1D(const Char_t *name_cond, const Char_t *title_cond);
340  virtual GCond2D * MakeGCond2D(const Char_t *name_cond, const Char_t *title_cond);
341 
342 public:
343  virtual Int_t CheckCondByHandler();
344  virtual Int_t CheckTreeFormula();
345 
346  // virtual void FillSpectraByHandler();
347 
348 public:
349  TTreeWithConditions(const char *name, const char *title, TTree *tree = 0x0, Short_t do_spectra = 2, Short_t do_tree = 2);
350  virtual ~TTreeWithConditions();
351 
353 
355  virtual UInt_t Snapshot(Option_t * = "*"); //*MENU*
356 
357  const std::vector < GCondition * > & GetListOfGConditions() const
358  {
359  return fAllGCond;
360  }
361  /*
362  const std::vector < TTreeFormula * > & GetListOfFormula() const
363  {
364  return fUserTFCond;
365  }
366  */
367  //
368  virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag = 0x0, Bool_t load_objects = true);
369 
371  virtual Int_t AddTreeFormula(const Char_t *, const Char_t *); //*MENU*
372 
374  virtual Int_t CheckCond()
375  {
376  return CheckCondByHandler();
377  }
378 
380  virtual void FillSpectra()
381  {
382  // spectra declared with conditions are automatically filled
384  }
385 
387  virtual void Exec(Option_t *option="");
388 
389  ClassDef(TTreeWithConditions,0) // Watcher that owns the tree and call Fill
390 };
391 
392 
393 } // namespace
394 
395 #endif
396 
virtual void AddBranches(TTree *tree)=0
Add the specific branches filled by this watcher to the given tree.
void SetDoTree(Short_t do_tree)
to know spectra mode for this watcher
virtual void SetBranches()=0
virtual Int_t CheckCond()
to be overwitten in case you add your own conditions but TTreeWithConditions::CheckCond() should be c...
virtual Bool_t IsPassed(Double_t, Double_t=0.0) const
returns true if the condition is passed with success
Definition: GCondition.h:97
Base for a Graphical condition 2D.
Definition: GCondition.h:233
virtual Int_t CheckCondByHandler()
std::vector< TTreeFormula * > fUserTFCond
list of formula defined by the user to apply conditions
Watcher_T * AddWatcher(const Char_t *name, const Char_t *title)
Allocate a standard watcher i.e. not a tree builder.
const std::vector< GCondition * > & GetListOfGConditions() const
std::list< GCondition * > fUserGCond
list of conditions defined by the user. spectra are built/filled by the user
virtual void FillBranches()=0
Should be used fill the current event.
To handle a simple branch.
virtual void Exec(Option_t *option="")
watch the current frame
std::vector< GCondition * > fAllGCond
list of all conditions. Used for external and to delete them
virtual UInt_t Snapshot(Option_t *="*")
Save all histograms belonging to this watcher. Should be overloaded in case of spectra not registered...
virtual void FillSpectraByUser()
Fill user spectra ... to be implementted by user only if it defines its ones spectra without conditio...
virtual void BuildSpectraByUser()
define user spectra ... to be implementted by user only if it defines its ones spectra without condit...
Watcher_T * Add(const Char_t *name, const Char_t *title, Short_t do_spectra, Short_t do_tree)
Allocate a watcher in charge of filling one part of the tree ==> Should inherits from TreeBuilder...
Short_t GetDoSpectra() const
to know spectra mode for this watcher
Definition: TTreeWatchers.h:86
GCondition * fCond
Definition: GCondition.h:300
virtual Int_t GetNbConditions() const
return the number of conditions registered in case this tree/branch has some
virtual void SetBranches()
Base class for a Watcher.
Definition: Watchers.h:60
virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag=0x0, Bool_t load_objects=true)
to change the directory in which watcher's objects are stored
SimpleGCondHandler1D(GCondition *cond, TLeaf *data, TH1 *h)
virtual std::pair< GCond2D *, TH2 * > MakeGCond2D(const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf, const Char_t *name_hist, const Char_t *title_hist, Int_t binx, Double_t xmin, Double_t xmax, Int_t biny, Double_t ymin, Double_t ymax, Option_t *opt="F", const Char_t *sub="")
Build a 2D condition using the given leaves. It allocates also the spectrum.
TTree * fClone
Clone of the tree part filled by this watcher with only one entry. Used to test Formulas.
std::list< GCondHandler * > fCondHandler
conditions and spectra are automaticaly handled by the base class
virtual Bool_t Check()
virtual void FillTree()
Fill the tree if it is the owner of the tree.
static TString gDefaultPathOfOut
some global strings to fix the Output directory where the Tree is to be written and its default name ...
Definition: TTreeWatchers.h:55
TTreeBuilder(const char *name, const char *title, TTree *tree=0x0, Short_t do_spectra=2, Short_t do_tree=2, Bool_t Overwrite=false)
virtual std::pair< GCond1D *, TH1 * > MakeGCond1D(const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf, const Char_t *name_hist, const Char_t *title_hist, Int_t bin, Double_t min, Double_t max, Option_t *opt="F", const Char_t *sub="")
Build a 1D condition using the given leaf. It allocates also the spectrum.
Base class for a Watcher that fill a TTree or some branches of a TTree.
Definition: TTreeWatchers.h:51
virtual ~TTreeMaster()
Watcher_T * Add(const Char_t *name, const Char_t *title)
Allocate a watcher in charge of filling one part of the tree ==> Should inherits from TreeBuilder...
TTreeMaster(const char *name, const char *title, Short_t do_spectra=2, Short_t do_tree=2, Bool_t Overwrite=false)
TTreeWithConditions(const char *name, const char *title, TTree *tree=0x0, Short_t do_spectra=2, Short_t do_tree=2)
virtual ~TTreeBuilder()
virtual void FillTree()
Fill the tree if it is the owner of the tree.
Base for a Graphical condition 1D.
Definition: GCondition.h:154
Base class for a trigger on a data flow.
Definition: Trigger.h:155
Watcher to build a tree with branches processed in several watchers.
SimpleGCondHandler2D(GCondition *cond, TLeaf *data1, TLeaf *data2, TH1 *h)
virtual void Clear(Option_t *="")=0
Should be used to reset a various data filled by this watcher.
void SetDoSpectra(Short_t do_spectra)
to know spectra mode for this watcher
Definition: TTreeWatchers.h:96
virtual Int_t AddTreeFormula(const Char_t *, const Char_t *)
Add a general condition (see TTree::Draw()). Return the total number of expression in this watcher on...
virtual void FillSpectra()
to be overwitten in case you add your own conditions/spectra
A watcher filling TTree, Spectra under conditions.
static TString gDefaultTTreeName
Definition: TTreeWatchers.h:56
virtual UInt_t Snapshot(Option_t *="*")
Save all histograms belonging to this watcher + conditions unless !cond is added. ...
Link between the leaf, the condition and the histogram.
Definition: GCondition.h:297
Short_t fNbConditions
Definition: TTreeWatchers.h:72
Short_t GetDoTree() const
to know spectra mode for this watcher
Definition: TTreeWatchers.h:91
virtual void Exec(Option_t *option="")
In principle works for any watchers that inherits from it.
TH1 * fErrors
to get errors while filling the different branches
static void SetDefaultPathAndName(const char *new_path="./Out", const char *treename="TreeMaster")
to change the default value of path for output. It returns the old one
virtual void Print(Option_t *) const
virtual void SetBranches()
add branches to the tree and the ciruclar tree
Base for a Graphical condition on a spectrum (1D, 2D)
Definition: GCondition.h:49
virtual Int_t CheckTreeFormula()
TTree * GetTree()
to get the current Tree