25 #include "TTreeFormula.h"
28 #include "TSystemDirectory.h"
29 #include "TDirectory.h"
40 fDoSpectra(do_spectra),
52 TDirectory *cdir = gDirectory;
58 TFile *rootfile = 0x0;
60 if(Overwrite ==
false)
63 TSystemDirectory dir; dir.SetDirectory(
gDefaultPathOfOut.Data()); TList *list = dir.GetListOfFiles();
67 for (
int i = 0; i <= 1000000; i++ ) {
69 tmp.Form(
"%s_w%d.root",name,i);
71 if ( !list->FindObject(tmp.Data()) )
78 rootfile =
new TFile(tmp.Data(),
"NEW");
81 rootfile =
new TFile(tmp.Data(),
"RECREATE");
83 std::cout <<
" Root file opened by TreeBuilder " << tmp.Data() <<
std::endl;
106 TDirectory *cdir = gDirectory;
109 TFile *rfile =
fMyTree->GetCurrentFile();
124 TTreeBuilder(name, title, 0x0,do_spectra,do_tree,Overwrite),
129 fListOfWatchers.SetOwner(
false);
132 fErrors = MakeTH1 <TH1F>(
"Errors",
"Errors in the different watchers filling the branches",0,0,0);
150 TIter loopontask(GetListOfTasks());
152 while ( ((task=loopontask())) ) {
167 if ( task == 0x0 ||
fTrigger == 0x0 )
180 if ( watch == 0x0 || trig == 0x0 )
187 (TFolder *)gROOT->GetRootFolder()->FindObject(
"//root/GwWatchers");
188 TFolder *w_folder = (TFolder *)gROOT->GetRootFolder()->FindObjectAny( Form(
"//root/GwWatchers/%s", watch->GetName() ) );
190 topfolder->Remove(w_folder);
195 Bool_t ok_dir =
false;
212 fErrors->GetXaxis()->SetBinLabel(
fErrors->GetXaxis()->GetNbins()-1,watch->GetName());
216 fListOfWatchers.Add(watch);
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;
224 TTask *task; TObjLink *lnk = GetListOfTasks()->FirstLink();
229 task = (TTask *)lnk->GetObject();
230 if ( !task->IsActive() ) {
259 watcher->Exec(option);
267 fErrors->SetBinContent( current + 1,
fErrors->GetBinContent(current+1) + 1 );
280 do_spectra_token = 1;
283 do_spectra_token = 0;
293 if ( !gROOT->IsBatch() ) {
294 gSystem->DispatchOneEvent(
true);
295 gSystem->ProcessEvents();
305 if ( nb_ok_tree == nb_watcher_tree )
318 int size = 3 + 3 + ((TString)GetName()).Length() + 5 + ((TString)GetTitle()).Length() + 3 + 3;
319 for(
int i=0; i<
size ; i++) std::cout<<
"*";
321 std::cout<<
"*** "<<GetName()<<
" --- "<<GetTitle()<<
" ***"<<
std::endl;
322 for(
int i=0; i<
size ; i++) std::cout<<
"*";
328 std::cout<<
" List of GW Watchers filling this tree:"<<
std::endl;
329 for(
int i=0 ; i<fListOfWatchers.GetSize() ; i++)
331 std::cout<<
" --−> "<<((
Watcher*)fListOfWatchers.At(i))->GetName()<<
std::endl;
333 std::cout<<
" List of branches in the tree:"<<
std::endl;
334 for(
int i=0 ; i<
fMyTree->GetListOfBranches()->GetEntries() ; i++)
336 std::cout<<
" --−> "<<((TList*)
fMyTree->GetListOfBranches())->At(i)->GetName()<<
std::endl;
339 std::cout<<
"Number of written entries : "<<
fMyTree->GetEntries()<<
std::endl;
344 TDirectory *cdir = gDirectory;
346 TFile *rfile =
fMyTree->GetCurrentFile();
359 Bool_t is_passed =
false;
361 for (Int_t i = 0; i < fData->GetLen(); i++) {
362 Double_t val = fData->GetValue(i);
385 fClone =
new TTree(Form(
"WC_%s_",name),Form(
"Clone of %s %s",name,title));
398 std::vector< GCondition * >::iterator
400 for ( listed_item =
fAllGCond.begin() ; listed_item !=
fAllGCond.end() ; listed_item++ ) {
401 if ( (*listed_item) ) {
402 delete (*listed_item);
403 (*listed_item) = 0x0;
410 TString o = opt; Bool_t save_cond =
true; UInt_t bytes = 0u; TDirectory *in_dir = gDirectory;
412 if ( o.Contains(
"!cond")) {
414 save_cond =
false; o.ReplaceAll(
"!cond",
"");
421 TDirectory *dir_w =
fDirectory->GetDirectory(Form(
"%s",GetName()));
422 TDirectory *dir_cuts =
fDirectory->GetDirectory(Form(
"%s/ListOfGCuts",GetName()));;
427 Bool_t wildcard =
false;
428 if ( o.Contains(
"*") )
430 TRegexp rexp(Form(
"%s",o.Data()),wildcard);
432 if ( rexp.Status() == TRegexp::kOK ) {
434 std::vector< GCondition * >::iterator
436 for ( listed_item =
fAllGCond.begin() ; listed_item !=
fAllGCond.end() ; listed_item++ ) {
437 o = (*listed_item)->GetName();
438 if ( o.Contains(rexp) ) {
440 bytes += dir_w->WriteTObject((*listed_item));
443 const TObjArray *list_of_individual_cuts = &((*listed_item)->GetListOfConditions());
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));
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,
467 TString
tmp = opt; std::pair < GCond1D *, TH1 * > p;
GCondHandler *handler = 0x0;
GCond1D *cond = 0x0; TH1 *hist = 0x0;
472 std::vector< GCondition * >::iterator
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;
483 TLeaf *leaf =
fClone->GetLeaf(name_leaf);
493 if ( tmp.Contains(
"C") )
495 hist = MakeTH1<TH1C>(name_hist,title_hist,bin,min,max,sub) ;
497 else if ( tmp.Contains(
"S") )
499 hist = MakeTH1<TH1S>(name_hist,title_hist,bin,min,max,sub);
501 else if ( tmp.Contains(
"I") )
503 hist = MakeTH1<TH1I>(name_hist,title_hist,bin,min,max,sub);
505 else if ( tmp.Contains(
"F") )
507 hist = MakeTH1<TH1F>(name_hist,title_hist,bin,min,max,sub);
509 else if ( tmp.Contains(
"D") )
511 hist = MakeTH1<TH1D>(name_hist,title_hist,bin,min,max,sub);
513 else if ( tmp.Contains(
"P") )
518 cond =
new GCond1D(name_cond,title_cond);
519 if ( cond == 0x0 || hist == 0x0) {
531 if (
fTopFolder->FindObject(
"ListOfGCuts") == 0x0 )
532 fTopFolder->AddFolder(
"ListOfGCuts",
"To keep list of possible GCuts for that watchers");
543 p.first = cond; p.second = hist;
return p;
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,
551 TString
tmp = opt, tmp_leaf(name_leaf); std::pair < GCond2D *, TH2 * > p;
GCond2D *cond = 0x0;
GCondHandler *handler = 0x0; TH2 *hist = 0x0;
557 std::vector< GCondition * >::iterator
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;
567 TObjArray *name_leaves = tmp_leaf.Tokenize(
":");
568 if ( name_leaves == 0x0 || name_leaves->GetEntries() != 2 ) {
570 printf(
"Cannot get leafes from %s \n",name_leaf);
575 TLeaf *leaf1 =
fClone->GetLeaf( name_leaves->At(0)->GetName() ), *leaf2 =
fClone->GetLeaf( name_leaves->At(1)->GetName() );
578 if ( leaf1 == 0x0 || leaf2 == 0x0 ) {
580 printf(
"Cannot find leafes \n");
588 if ( tmp.Contains(
"C") )
590 hist = MakeTH2<TH2C>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
592 else if ( tmp.Contains(
"S") )
594 hist = MakeTH2<TH2S>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
596 else if ( tmp.Contains(
"I") )
598 hist = MakeTH2<TH2I>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
600 else if ( tmp.Contains(
"F") )
602 hist = MakeTH2<TH2F>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
604 else if ( tmp.Contains(
"D") )
606 hist = MakeTH2<TH2D>(name_hist,title_hist,binx,xmin,xmax,biny,ymin,ymax,sub);
608 else if ( tmp.Contains(
"P") )
613 cond =
new GCond2D(name_cond,title_cond);
614 if ( cond == 0x0 || hist == 0x0 ) {
627 if (
fTopFolder->FindObject(
"ListOfGCuts") == 0x0 )
628 fTopFolder->AddFolder(
"ListOfGCuts",
"To keep list of possible GCuts for that watchers");
641 p.first = cond; p.second = hist;
return p;
649 std::vector< GCondition * >::iterator
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;
658 cond =
new GCond1D(name_cond,title_cond);
671 std::vector< GCondition * >::iterator
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;
680 cond =
new GCond2D(name_cond,title_cond);
692 TDirectory *new_cond_dir;
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()));
704 if (new_cond_dir == 0x0 || load_objects ==
false ) {
708 std::vector< GCondition * >::iterator
710 for ( listed_item =
fAllGCond.begin() ; listed_item !=
fAllGCond.end() ; listed_item++ ) {
716 (TFolder *)
fTopFolder->FindObject(
"ListOfGCuts");
718 TIter it(new_cond_dir->GetListOfKeys()); TKey *key_in_file;
720 while ( (key_in_file = static_cast<TKey *>(it())) ) {
722 TString class_name = key_in_file->GetClassName();
724 if ( class_name.EqualTo(
"Gw::Peak1D") || class_name.EqualTo(
"TCutG") ) {
726 if ( !folder->FindObject(key_in_file->GetName()) ) {
727 TKey *last_key_for_that_object =
728 new_cond_dir->FindKey(key_in_file->GetName());
730 TObject *obj = last_key_for_that_object->ReadObj();
732 gROOT->GetListOfSpecials()->Remove( obj );
742 std::list< GCondHandler * >::iterator
745 (*listed_item)->Fill();
746 if ( (*listed_item)->Check() )
765 std::vector< TTreeFormula * >::iterator
768 if ( (*listed_formula)->EvalInstance() )
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
Base for a Graphical condition 2D.
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 ...
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.
virtual TDirectory * GetDirectory(Option_t *opt="")
to each watcher a TDirectory is associated
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.
virtual void SetVarName(const Char_t *var_name, const Char_t *="X")
Set var name.
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...
virtual Int_t GetNbConditions() const
return the number of conditions registered in case this tree/branch has some
Base class for a Watcher.
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...
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 ...
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 ...
Base class for a Watcher that fill a TTree or some branches of a TTree.
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 ...
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
TTreeWithConditions(const char *name, const char *title, TTree *tree=0x0, Short_t do_spectra=2, Short_t do_tree=2)
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.
Base for a Graphical condition 1D.
Base class for a trigger on a data flow.
virtual ~TTreeWithConditions()
ADF::LogMessage & endl(ADF::LogMessage &log)
ADF::DFTrigger * fTrigger
trigger associated to this watcher
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
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
static TString gDefaultTTreeName
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.
void LoadObject(TObject *new_obj, TDirectory *root_dir)
to specify what kind of watcher
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
virtual Bool_t SetTrigger(ADF::DFTrigger *)
To set the Frames (through a trigger) associated to this watcher.
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()