GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TTreeWatchers.cpp
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 #include "TTreeWatchers.h"
24 
25 #include "TTreeFormula.h"
26 #include "TRegexp.h"
27 #include "TSystem.h"
28 #include "TSystemDirectory.h"
29 #include "TDirectory.h"
30 #include "TKey.h"
31 
32 using namespace Gw;
33 
34 TString TTreeBuilder::gDefaultPathOfOut = "./Out";
35 TString TTreeBuilder::gDefaultTTreeName = "TreeMaster";
36 
37 TTreeBuilder::TTreeBuilder(const char *name, const char *title, TTree *tree, Short_t do_spectra, Short_t do_tree, Bool_t Overwrite) :
38  fMyTree(tree),
39  fIsOwner(true),
40  fDoSpectra(do_spectra),
41  fDoTree(do_tree),
42  fNbConditions(0)
43 {
44  // no need
45  if ( fMyTree )
46  fIsOwner = false;
47  else {
48 
49  fIsOwner = true;
50 
51  // keep the current directory
52  TDirectory *cdir = gDirectory;
53 
54  // open a TFile with a TTree using the name and title of the watcher
55  // check if a tree already exists, otherwise creates it
56  TString tmp = Form("%s/%s_w0.root",gDefaultPathOfOut.Data(),name);
57 
58  TFile *rootfile = 0x0;
59 
60  if(Overwrite == false)
61  {
62  // Check if such a file exist in the current directory
63  TSystemDirectory dir; dir.SetDirectory(gDefaultPathOfOut.Data()); TList *list = dir.GetListOfFiles();
64  if ( list ) {
65  // loop to find the first free file with the format name_w%d.root
66  int cycle;
67  for ( int i = 0; i <= 1000000; i++ ) { // up to MAXCYCLE files
68 
69  tmp.Form("%s_w%d.root",name,i);
70  cycle = i;
71  if ( !list->FindObject(tmp.Data()) )
72  { break; }
73  }
74  tmp.Form("%s/%s_w%d.root",gDefaultPathOfOut.Data(),name,cycle);
75  delete list;
76  }
77 
78  rootfile = new TFile(tmp.Data(),"NEW");
79  }
80  else
81  rootfile = new TFile(tmp.Data(),"RECREATE");
82 
83  std::cout << " Root file opened by TreeBuilder " << tmp.Data() << std::endl;
84 
85  if ( rootfile )
86  rootfile->cd();
87  fMyTree = new TTree(gDefaultTTreeName.Data(),title);
88 
89  // back to the current directory
90  if ( cdir )
91  cdir->cd();
92  }
93 }
94 
96 {
97  if ( fIsOwner )
98  fMyTree->Fill();
99 }
100 
102 {
103  if ( fIsOwner ) {
104 
105  // keep the current directory
106  TDirectory *cdir = gDirectory;
107 
108  // to get the current root file and save the ttree
109  TFile *rfile = fMyTree->GetCurrentFile();
110  rfile->cd();
111 
112 // fMyTree->Write();
113  rfile->Close();
114 
115  // back to the current directory
116  cdir->cd();
117  }
118 }
119 
120 //ClassImp(/*TTreeMaster*/);
121 
122 TTreeMaster::TTreeMaster(const char *name, const char *title, Short_t do_spectra, Short_t do_tree, Bool_t Overwrite) :
123  Watcher(name,title),
124  TTreeBuilder(name, title, 0x0,do_spectra,do_tree,Overwrite),
125  fListOfWatchers(),
126  fErrors(0x0)
127 {
128  // the watchers are not delete by this !
129  fListOfWatchers.SetOwner(false);
130 
131  //
132  fErrors = MakeTH1 <TH1F>("Errors","Errors in the different watchers filling the branches",0,0,0);
133 }
134 
136 {
137 }
138 
139 void TTreeMaster::SetDefaultPathAndName(const char *new_path, const char *treename)
140 {
141  gDefaultPathOfOut = new_path;
142  gDefaultTTreeName = treename;
143 }
144 
145 UInt_t TTreeMaster::Snapshot(Option_t *opt)
146 {
147  UInt_t bytes = 0u;
148 
149  // for all watchers, ask to snap spectra and conditions
150  TIter loopontask(GetListOfTasks());
151  TObject *task;
152  while ( ((task=loopontask())) ) {
153  Watcher *watcher =
154  dynamic_cast<Watcher *>(task);
155  if ( watcher ) {
156  // to be sure and so that it should not be necessary in watchers
157  bytes += watcher->Snapshot(opt);
158  }
159  }
160  // add additional snap which is just a Write of the tree
161 
162  return bytes;
163 }
164 
165 void TTreeMaster::Add(TTask *task)
166 {
167  if ( task == 0x0 || fTrigger == 0x0 )
168  return;
169  if ( fTrigger->IsZombie() )
170  return;
171 
172  Watcher *watcher =
173  dynamic_cast<Watcher *>(task);
174  if ( watcher )
175  Add(watcher,fTrigger);
176 }
177 
179 {
180  if ( watch == 0x0 || trig == 0x0 )
181  return;
182  if ( trig->IsZombie() )
183  return;
184 
185  // Add a new watcher, associates the trigger, add to the list of watchers, set the directory and allocate histograms
186  TFolder *topfolder =
187  (TFolder *)gROOT->GetRootFolder()->FindObject("//root/GwWatchers");
188  TFolder *w_folder = (TFolder *)gROOT->GetRootFolder()->FindObjectAny( Form("//root/GwWatchers/%s", watch->GetName() ) );
189  if ( w_folder ) { // shoud aways be true ...
190  topfolder->Remove(w_folder);
191  fTopFolder->Add(w_folder);
192  }
193 
194  if ( fDirectory ) {
195  Bool_t ok_dir = false;
196  if ( fTagDirectory ) {
197  ok_dir = MakeDir(fTopFolder, fDirectory, true);
198  if ( fTagDirectory != fDirectory ) {
199  ok_dir = ok_dir && MakeDir(fTopFolder, fTagDirectory, true);
200  }
201  }
202  if (ok_dir) {
203  TDirectory *d1 = fDirectory->GetDirectory(fTopFolder->GetName());
204  TDirectory *d2 = fTagDirectory->GetDirectory(fTopFolder->GetName());
205 
206  watch->SetDirectory(d1,d2,true);
207  }
208  }
209 
210  // to set errors in main loop
211  fErrors->SetBins(fErrors->GetNbinsX()+1,fErrors->GetXaxis()->GetXmin(),fErrors->GetXaxis()->GetXmax()+1.0);
212  fErrors->GetXaxis()->SetBinLabel(fErrors->GetXaxis()->GetNbins()-1,watch->GetName());
213 
214  watch->SetTrigger(trig);
215  TTask::Add(watch);
216  fListOfWatchers.Add(watch);
217 }
218 
219 void TTreeMaster::Exec(Option_t * option)
220 {
221  Short_t do_spectra_token = 2, nb_ok_tree = 0u, nb_watcher_tree = 0u; Int_t pass, current = 0;
222  Bool_t do_tree = true;
223 
224  TTask *task; TObjLink *lnk = GetListOfTasks()->FirstLink();
225  while (lnk) {
226 
227  current++;
228 
229  task = (TTask *)lnk->GetObject();
230  if ( !task->IsActive() ) {
231  // active should set tree and
232  lnk = lnk->Next();
233  continue;
234  }
235  Watcher *watcher =
236  dynamic_cast<Watcher *>(task);
237  TTreeBuilder *t_builder =
238  dynamic_cast<TTreeBuilder *>(task);
239 
240  if ( t_builder ) {
241  nb_watcher_tree++;
242 
243  switch (fDoSpectra ) {
244  case 0:
245  t_builder->SetDoSpectra(0);
246  break;
247  case 1:
248  t_builder->SetDoSpectra(do_spectra_token);
249  break;
250  case 2:
251  default:
252  t_builder->SetDoSpectra(2);
253  break;
254  }
255  }
256  // to be sure and so that it should not be necessary in watchers
257  watcher->SetLastExecStatus(0);
258  // execute
259  watcher->Exec(option);
260  //check the status to know if the tree should be filled
261  pass = watcher->GetLastExecStatus();
262 
263  if ( t_builder ) {
264  if ( pass < 0 ) {
265  // count number of errors
266  do_tree = false;
267  fErrors->SetBinContent( current + 1, fErrors->GetBinContent(current+1) + 1 );
268 
269  break;
270  }
271  else {
272  // to deal with spectra
273  nb_ok_tree++;
274 
275  switch ( fDoSpectra ) {
276  case 0:
277  break;
278  case 1:
279  if ( t_builder->GetNbConditions() == pass ) {
280  do_spectra_token = 1;
281  }
282  else
283  do_spectra_token = 0;
284  break;
285  case 2:
286  break;
287  }
288  }
289  } // t_builder
290 
291  lnk = lnk->Next();
292 
293  if ( !gROOT->IsBatch() ) {
294  gSystem->DispatchOneEvent(true);
295  gSystem->ProcessEvents();
296  }
297  }
298 
299  // fill only if all watchers processed without errors
300  if ( do_tree ) {
301  switch (fDoTree) {
302  case 0:
303  break;
304  case 1:
305  if ( nb_ok_tree == nb_watcher_tree )
306  FillTree();
307  break;
308  default:
309  FillTree();
310  break;
311  }
312  }
313 }
314 
315 void TTreeMaster::Print(Option_t */*option*/) const
316 {
317  std::cout<<std::endl;
318  int size = 3 + 3 + ((TString)GetName()).Length() + 5 + ((TString)GetTitle()).Length() + 3 + 3;
319  for(int i=0; i<size ; i++) std::cout<<"*";
320  std::cout<<std::endl;
321  std::cout<<"*** "<<GetName()<<" --- "<<GetTitle()<<" ***"<<std::endl;
322  for(int i=0; i<size ; i++) std::cout<<"*";
323  std::cout<<std::endl;
324 
325  std::cout<<"TFile : "<<fMyTree->GetCurrentFile()->GetName()<<std::endl;
326  std::cout<<"TTree : "<<fMyTree->GetName()<<" ; "<<fMyTree->GetTitle()<<std::endl;
327  fMyTree->Print();
328  std::cout<<" List of GW Watchers filling this tree:"<<std::endl;
329  for(int i=0 ; i<fListOfWatchers.GetSize() ; i++)
330  {
331  std::cout<<" --−> "<<((Watcher*)fListOfWatchers.At(i))->GetName()<<std::endl;
332  }
333  std::cout<<" List of branches in the tree:"<<std::endl;
334  for(int i=0 ; i<fMyTree->GetListOfBranches()->GetEntries() ; i++)
335  {
336  std::cout<<" --−> "<<((TList*)fMyTree->GetListOfBranches())->At(i)->GetName()<<std::endl;
337  }
338 
339  std::cout<<"Number of written entries : "<<fMyTree->GetEntries()<<std::endl;
340 
341  if ( fIsOwner )
342  {
343  // keep the current directory
344  TDirectory *cdir = gDirectory;
345  // to get the current root file and save the ttree
346  TFile *rfile = fMyTree->GetCurrentFile();
347  rfile->cd();
348  fMyTree->Write();
349  // back to the current directory
350  cdir->cd();
351  }
352 
353  std::cout<<std::endl;
354 }
355 
356 
358 {
359  Bool_t is_passed = false;
360  //
361  for (Int_t i = 0; i < fData->GetLen(); i++) {
362  Double_t val = fData->GetValue(i);
363 
364  if ( fCond->IsPassed( val ) )
365  {
366  is_passed = true;
367  break;
368  }
369  }
370  return is_passed;
371 }
372 
373 //ClassImp(TTreeWithConditions);
374 
375 TTreeWithConditions::TTreeWithConditions(const char *name, const char *title, TTree *tree, Short_t do_spectra, Short_t do_tree) :
376  Watcher(name,title),
377  TTreeBuilder(name,title,tree,do_spectra,do_tree),
378  fClone(0x0),
379  fCondHandler(),
380  fUserGCond(),
381  fUserTFCond(),
382  fAllGCond()
383 {
384  // clone is always set since it is used for coincidences.
385  fClone = new TTree(Form("WC_%s_",name),Form("Clone of %s %s",name,title));
386  if ( fClone ) {
387  fClone->SetDirectory(0);
388  fClone->SetCircular(1);
389  }
390 }
392 {
393  //
394  if ( fClone ) {
395  delete fClone; fClone = 0x0;
396  }
397  // delete all conditions
398  std::vector< GCondition * >::iterator
399  listed_item;
400  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
401  if ( (*listed_item) ) {
402  delete (*listed_item);
403  (*listed_item) = 0x0;
404  }
405  }
406 }
407 
408 UInt_t TTreeWithConditions::Snapshot(Option_t *opt)
409 {
410  TString o = opt; Bool_t save_cond = true; UInt_t bytes = 0u; TDirectory *in_dir = gDirectory;
411 
412  if ( o.Contains("!cond")) {
413  // means do not save conditions
414  save_cond = false; o.ReplaceAll("!cond","");
415  }
416  // save spectra
417  bytes += Watcher::Snapshot(o.Data());
418 
419  if ( save_cond && fDirectory ) {
420 
421  TDirectory *dir_w = fDirectory->GetDirectory(Form("%s",GetName()));
422  TDirectory *dir_cuts = fDirectory->GetDirectory(Form("%s/ListOfGCuts",GetName()));;
423  if ( dir_cuts ) {
424  dir_cuts->cd();
425  }
426 
427  Bool_t wildcard = false;
428  if ( o.Contains("*") )
429  wildcard = true;
430  TRegexp rexp(Form("%s",o.Data()),wildcard);
431 
432  if ( rexp.Status() == TRegexp::kOK ) {
433  // check first it is not already there ?
434  std::vector< GCondition * >::iterator
435  listed_item;
436  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
437  o = (*listed_item)->GetName();
438  if ( o.Contains(rexp) ) {
439  if ( dir_w )
440  bytes += dir_w->WriteTObject((*listed_item));
441 
442  if ( dir_cuts ) {
443  const TObjArray *list_of_individual_cuts = &((*listed_item)->GetListOfConditions());
444 
445  for (Int_t i = 0; i < list_of_individual_cuts->GetSize(); i++) {
446  if ( list_of_individual_cuts->At(i) )
447  bytes += dir_cuts->WriteTObject(list_of_individual_cuts->At(i));
448  }
449  }
450  }
451  }
452  }
453  if ( in_dir )
454  in_dir->cd();
455  else
456  gDirectory = 0x0;
457  }
458 
459  return bytes;
460 }
461 
462 std::pair< GCond1D *, TH1 * > TTreeWithConditions::MakeGCond1D(
463  const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
464  const Char_t *name_hist, const Char_t *title_hist , Int_t bin, Double_t min, Double_t max, Option_t *opt,
465  const Char_t * sub)
466 {
467  TString tmp = opt; std::pair < GCond1D *, TH1 * > p; GCondHandler *handler = 0x0; GCond1D *cond = 0x0; TH1 *hist = 0x0;
468  p.first = 0x0;
469  p.second = 0x0;
470 
471  // check first it is not already there ?
472  std::vector< GCondition * >::iterator
473  listed_item;
474  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
475  tmp = (*listed_item)->GetName();
476  if ( tmp == name_cond ) {
477  std::cout << "Cannot have two conditions wth the same name " << name_cond << std::endl;
478  return p;
479  }
480  }
481 
482  // find leaf in the tree
483  TLeaf *leaf = fClone->GetLeaf(name_leaf);
484  if ( leaf == 0x0 ) {
485  // log to be added
486 
487  return p;
488  }
489 
490  // Associated histogram
491  tmp = opt;
492 
493  if ( tmp.Contains("C") )
494  {
495  hist = MakeTH1<TH1C>(name_hist,title_hist,bin,min,max,sub) ;
496  }
497  else if ( tmp.Contains("S") )
498  {
499  hist = MakeTH1<TH1S>(name_hist,title_hist,bin,min,max,sub);
500  }
501  else if ( tmp.Contains("I") )
502  {
503  hist = MakeTH1<TH1I>(name_hist,title_hist,bin,min,max,sub);
504  }
505  else if ( tmp.Contains("F") )
506  {
507  hist = MakeTH1<TH1F>(name_hist,title_hist,bin,min,max,sub);
508  }
509  else if ( tmp.Contains("D") )
510  {
511  hist = MakeTH1<TH1D>(name_hist,title_hist,bin,min,max,sub);
512  }
513  else if ( tmp.Contains("P") )
514  {
515  // hist = new TProfile(name_hist,title_hist,bin,min,max);
516  }
517 
518  cond = new GCond1D(name_cond,title_cond);
519  if ( cond == 0x0 || hist == 0x0) {
520  if ( cond ) {
521  delete cond;
522  }
523  if ( hist ) {
524  delete hist;
525  }
526  return p;
527  }
528  else {
529  cond->SetVarName(name_leaf,"X");
530  if ( fTopFolder ) {
531  if ( fTopFolder->FindObject("ListOfGCuts") == 0x0 )
532  fTopFolder->AddFolder("ListOfGCuts","To keep list of possible GCuts for that watchers");
533  fTopFolder->Add(cond);
534  }
535 
536  handler = new SimpleGCondHandler1D( cond, leaf, hist );
537  fCondHandler.push_back(handler);
538 
539  fNbConditions++;
540  fAllGCond.push_back(cond);
541  }
542 
543  p.first = cond; p.second = hist; return p;
544 }
545 
546 std::pair< GCond2D *, TH2 * > TTreeWithConditions::MakeGCond2D(
547  const Char_t *name_cond, const Char_t *title_cond, const Char_t *name_leaf,
548  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,
549  const Char_t *sub)
550 {
551  TString tmp = opt, tmp_leaf(name_leaf); std::pair < GCond2D *, TH2 * > p; GCond2D *cond = 0x0; GCondHandler *handler = 0x0; TH2 *hist = 0x0;
552  //
553  p.first = 0x0;
554  p.second = 0x0;
555 
556  // check first it is not already there ?
557  std::vector< GCondition * >::iterator
558  listed_item;
559  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
560  tmp = (*listed_item)->GetName();
561  if ( tmp == name_cond ) {
562  std::cout << "Cannot have two conditions wth the same name " << name_cond << std::endl;
563  return p;
564  }
565  }
566 
567  TObjArray *name_leaves = tmp_leaf.Tokenize(":");
568  if ( name_leaves == 0x0 || name_leaves->GetEntries() != 2 ) {
569  // log to be added
570  printf("Cannot get leafes from %s \n",name_leaf);
571  return p;
572  }
573 
574  // find leaf in the tree
575  TLeaf *leaf1 = fClone->GetLeaf( name_leaves->At(0)->GetName() ), *leaf2 = fClone->GetLeaf( name_leaves->At(1)->GetName() );
576  delete name_leaves;
577 
578  if ( leaf1 == 0x0 || leaf2 == 0x0 ) {
579  // log to be added
580  printf("Cannot find leafes \n");
581 
582  return p;
583  }
584 
585  // Associated histogram
586  tmp = opt;
587 
588  if ( tmp.Contains("C") )
589  {
590  hist = MakeTH2<TH2C>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
591  }
592  else if ( tmp.Contains("S") )
593  {
594  hist = MakeTH2<TH2S>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
595  }
596  else if ( tmp.Contains("I") )
597  {
598  hist = MakeTH2<TH2I>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
599  }
600  else if ( tmp.Contains("F") )
601  {
602  hist = MakeTH2<TH2F>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
603  }
604  else if ( tmp.Contains("D") )
605  {
606  hist = MakeTH2<TH2D>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
607  }
608  else if ( tmp.Contains("P") )
609  {
610  // hist = new TProfile(name_hist,title_hist,bin,min,max);
611  }
612 
613  cond = new GCond2D(name_cond,title_cond);
614  if ( cond == 0x0 || hist == 0x0 ) {
615  if ( cond ) {
616  delete cond;
617  }
618  if ( hist ) {
619  delete hist;
620  }
621  return p;
622  }
623  else {
624  cond->SetVarName(leaf1->GetName(),"X"); cond->SetVarName(leaf2->GetName(),"Y");
625 
626  if ( fTopFolder ) {
627  if ( fTopFolder->FindObject("ListOfGCuts") == 0x0 )
628  fTopFolder->AddFolder("ListOfGCuts","To keep list of possible GCuts for that watchers");
629  fTopFolder->Add(cond);
630  }
631 
632  //
633  handler = new SimpleGCondHandler2D( cond, leaf1, leaf2, hist );
634  //
635  fCondHandler.push_back(handler);
636 
637  fNbConditions++;
638  fAllGCond.push_back(cond);
639  }
640 
641  p.first = cond; p.second = hist; return p;
642 }
643 
644 GCond1D * TTreeWithConditions::MakeGCond1D(const Char_t *name_cond, const Char_t *title_cond)
645 {
646  GCond1D *cond = 0x0;
647 
648  // check first it is not already there ?
649  std::vector< GCondition * >::iterator
650  listed_item;
651  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
652  TString tmp = (*listed_item)->GetName();
653  if ( tmp == name_cond ) {
654  std::cout << "Cannot have two conditions wth the same name " << name_cond << std::endl;
655  return cond;
656  }
657  }
658  cond = new GCond1D(name_cond,title_cond);
659  if ( cond ) {
660  fUserGCond.push_back(cond); fAllGCond.push_back(cond);
661  }
662 
663  return cond;
664 }
665 
666 GCond2D * TTreeWithConditions::MakeGCond2D(const Char_t *name_cond, const Char_t *title_cond)
667 {
668  GCond2D *cond = 0x0;
669 
670  // check first it is not already there ?
671  std::vector< GCondition * >::iterator
672  listed_item;
673  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
674  TString tmp = (*listed_item)->GetName();
675  if ( tmp == name_cond ) {
676  std::cout << "Cannot have two conditions wth the same name " << name_cond << std::endl;
677  return cond;
678  }
679  }
680  cond = new GCond2D(name_cond,title_cond);
681  if ( cond ) {
682  fUserGCond.push_back(cond); fAllGCond.push_back(cond);
683  }
684 
685  return cond;
686 }
687 
688 
689 void TTreeWithConditions::SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag, Bool_t load_objects)
690 {
692  TDirectory *new_cond_dir;
693 
694  // apply modifications of the directtory first for spectra & tagged spectra
695  Watcher::SetDirectory(mother_dir_of_watcher,mother_dir_tag,load_objects);
696  if ( GetDirectory() == 0x0 )
697  return;
698 
699  // add also conditions to the watcher diectory
700  new_cond_dir = GetDirectory()->GetDirectory(Form("%s/ListOfGCuts",GetName()));
701  if ( new_cond_dir == 0x0 )
702  new_cond_dir = GetDirectory()->mkdir(Form("%s/ListOfGCuts",GetName()));
703  //
704  if (new_cond_dir == 0x0 || load_objects == false ) {
705  return;
706  }
707  // load object from the destination directory
708  std::vector< GCondition * >::iterator
709  listed_item;
710  for ( listed_item = fAllGCond.begin() ; listed_item != fAllGCond.end() ; listed_item++ ) {
711  LoadObject((*listed_item), GetDirectory());
712  }
713 
714  // load all predfined cuts in ListOfGcuts
715  TFolder *folder =
716  (TFolder *)fTopFolder->FindObject("ListOfGCuts");
717 
718  TIter it(new_cond_dir->GetListOfKeys()); TKey *key_in_file;
719  // start
720  while ( (key_in_file = static_cast<TKey *>(it())) ) { // next key
721 
722  TString class_name = key_in_file->GetClassName(); // TString objet_name = key_in_file->GetName();
723 
724  if ( class_name.EqualTo("Gw::Peak1D") || class_name.EqualTo("TCutG") ) {
725 
726  if ( !folder->FindObject(key_in_file->GetName()) ) { // not yet in the collection, add highest cycle
727  TKey *last_key_for_that_object =
728  new_cond_dir->FindKey(key_in_file->GetName());
729 
730  TObject *obj = last_key_for_that_object->ReadObj();
731  folder->Add( obj );
732  gROOT->GetListOfSpecials()->Remove( obj );
733  }
734  }
735  }
736 }
737 
739 {
740  Int_t nb = 0;
741 
742  std::list< GCondHandler * >::iterator
743  listed_item;
744  for ( listed_item = fCondHandler.begin() ; listed_item != fCondHandler.end() ; listed_item++ ) {
745  (*listed_item)->Fill();
746  if ( (*listed_item)->Check() )
747  nb++;
748  }
749  /*
750  std::vector< TTreeFormula * >::iterator
751  listed_formula;
752  for ( listed_formula = fUserTFCond.begin() ; listed_formula != fUserTFCond.end() ; listed_formula++ ) {
753  if ( (*listed_formula)->EvalInstance() )
754  nb++;
755  }
756  */
757 
758  return nb;
759 }
760 
762 {
763  Int_t nb = 0;
764 
765  std::vector< TTreeFormula * >::iterator
766  listed_formula;
767  for ( listed_formula = fUserTFCond.begin() ; listed_formula != fUserTFCond.end() ; listed_formula++ ) {
768  if ( (*listed_formula)->EvalInstance() )
769  nb++;
770  }
771 
772  return nb;
773 }
774 
775 /*
776  void TTreeWithConditions::FillSpectraByHandler()
777  {
778  std::list< GCondHandler * >::iterator
779  listed_item;
780  for ( listed_item = fCondHandler.begin() ; listed_item != fCondHandler.end() ; listed_item++ ) {
781  (*listed_item)->Fill();
782  }
783  }
784  */
785 
786 Int_t TTreeWithConditions::AddTreeFormula(const Char_t */*name*/, const Char_t */*expression*/)
787 {
788  /*
789  TTreeFormula *nf = new TTreeFormula(name,expression,fClone);
790 
791  if ( nf->GetTree() ) { // test if it is a good expression ... should log
792  fUserTFCond.push_back(nf);
793  }
794 
795  return fUserTFCond.size();
796  */
797  return 0;
798 }
799 
800 void TTreeWithConditions::Exec(Option_t * /*option*/)
801 {
802  // Clear everything
803  Clear();
804  // fill the event using FillBranches method and set the entry in the clone which is circular with on entry
805  FillBranches();
806 
807  // check conditions
808  fClone->Fill();
809  Short_t nb_cond = CheckCond() ; SetLastExecStatus(nb_cond);
810 
811  switch ( fDoSpectra ) {
812  case 0:
813  break;
814  case 1:
815  if ( nb_cond == GetNbConditions() )
816  FillSpectra();
817  break;
818  case 2:
819  default:
820  FillSpectra();
821  break;
822  }
823 }
824 
825 
826 
827 
virtual Int_t CheckCond()
to be overwitten in case you add your own conditions but TTreeWithConditions::CheckCond() should be c...
printf("******************************************************************** \n")
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
TDirectory * fTagDirectory
Tagged Objects are in folders. They can be saved/load in/from directory. This is the mother in which ...
Definition: Watchers.h:107
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 SetVarName(const Char_t *var_name, const Char_t *which_var="X")
Set var name.
Definition: GCondition.h:254
virtual TDirectory * GetDirectory(Option_t *opt="")
to each watcher a TDirectory is associated
Definition: Watchers.h:308
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...
TFolder * fTopFolder
Top folder in which ae stored all spectra.
Definition: Watchers.h:109
virtual void SetVarName(const Char_t *var_name, const Char_t *="X")
Set var name.
Definition: GCondition.h:181
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...
GCondition * fCond
Definition: GCondition.h:300
virtual Int_t GetNbConditions() const
return the number of conditions registered in case this tree/branch has some
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
TDirectory * fDirectory
Objects are in folders. They can be saved/load in/from directory. This is the mother in which this wa...
Definition: Watchers.h:105
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 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.
void SetLastExecStatus(Short_t s=0)
reset last status. 0 means no error, 0 < means error, > 0 means ok with conditions ...
Definition: Watchers.h:294
Base class for a Watcher that fill a TTree or some branches of a TTree.
Definition: TTreeWatchers.h:51
virtual ~TTreeMaster()
Bool_t MakeDir(TFolder *f, TDirectory *mother_dir, Bool_t do_top=true)
in order to save/load, the structure of the top folders should exists in the root dir ...
Definition: Watchers.cpp:291
TTreeMaster(const char *name, const char *title, Short_t do_spectra=2, Short_t do_tree=2, Bool_t Overwrite=false)
virtual UInt_t Snapshot(Option_t *="*")
change kind of Watcher
Definition: Watchers.cpp:534
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.
Bool_t IsZombie() const
Check if this trigger is in fired state.
Definition: Trigger.h:114
Base for a Graphical condition 1D.
Definition: GCondition.h:154
Base class for a trigger on a data flow.
Definition: Trigger.h:155
ADF::LogMessage & endl(ADF::LogMessage &log)
ADF::DFTrigger * fTrigger
trigger associated to this watcher
Definition: Watchers.h:117
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
Short_t GetLastExecStatus() const
to get the last status
Definition: Watchers.h:300
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
void LoadObject(TObject *new_obj, TDirectory *root_dir)
to specify what kind of watcher
Definition: Watchers.cpp:399
virtual void SetDirectory(TDirectory *mother_dir_of_watcher, TDirectory *mother_dir_tag, Bool_t load_objects=true)
to change the directory in which watcher's objects are stored
Definition: Watchers.cpp:458
virtual Bool_t SetTrigger(ADF::DFTrigger *)
To set the Frames (through a trigger) associated to this watcher.
Definition: Watchers.cpp:829
const Int_t size
Definition: BenchIO.C:24
Short_t fNbConditions
Definition: TTreeWatchers.h:72
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 Int_t CheckTreeFormula()