AliRoot Core  edcc906 (edcc906)
AliTreePlayerTest.C
Go to the documentation of this file.
1 
30 
32 #include "TStatToolkit.h"
33 #include "Riostream.h"
34 #include <iostream>
35 #include "TSystem.h"
36 #include "TNamed.h"
37 #include "TFile.h"
38 #include "TTree.h"
39 #include "TPRegexp.h"
40 #include "TFriendElement.h"
41 #include "AliExternalInfo.h"
42 #include "TTreeFormula.h"
43 #include "TTreeFormulaManager.h"
44 #include "AliTreePlayer.h"
45 
46 TTree *testTree = 0x0;
47 
48 void testSelectMetadata();
49 void testselectTreeInfo();
50 //void testselectWhatWhereOrderBy();
51 void testConvertTree();
52 
55  TTree *treeLogbook = info.GetTree("Logbook","LHC15o","cpass1_pass1","QA.TPC;QA.TRD;QA.TOF;");
56  TTree *treeTPC = info.GetTree("QA.TPC","LHC15o","cpass1_pass1","QA.TRD;QA.TPC;QA.TOF;QA.TOF;Logbook");
57  TTree *treeTRD = info.GetTree("QA.TRD","LHC15o","cpass1_pass1","QA.TPC;QA.TRD;QA.TOF;Logbook;");
58  testTree = treeLogbook;
60  testTree = treeTPC;
63 }
64 
66  //
67  // test selectMetadata function
68  //
69  // 1.) Init trees
70  TObjArray *array =0;
71  if (testTree==NULL){
73  testTree= info.GetTree("Logbook","LHC15o","cpass1_pass1","QA.TPC;QA.TRD;QA.TOF;");
74  if (testTree==NULL){
75  ::Error("AliTreePlayerTest.testSelectMetadata","Input not available");
76  }
77  }
78  // 2.) Make test
79  // 2.a) AND invariant test N(A)=N(A&&B)+N(A&&(!B))
80  Int_t statAll, stat0, stat1;
81  array = AliTreePlayer::selectMetadata(testTree, "[class==\"Logbook&&(Stat)\"]",0);
82  statAll=array->GetEntries();
83  array = AliTreePlayer::selectMetadata(testTree, "[class==\"Logbook&&(Stat&&Base)\"]",0);
84  stat0=array->GetEntries();
85  array = AliTreePlayer::selectMetadata(testTree, "[class==\"Logbook&&(Stat&&(!Base))\"]",0);
86  stat1=array->GetEntries();
87  if (statAll!=stat0+stat1 || statAll==0){
88  ::Error("AliTreePlayerTest.testSelectMetadata AND invariant","Test ERROR: N(Logbook&&(Stat))!=N(Logbook&&(Stat&&Base))+N(Logbook&&(Stat&&(!Base))) ");
89  }else{
90  ::Info("AliTreePlayerTest.testSelectMetadata AND invariant","Test OK: N(Logbook&&(Stat))=N(Logbook&&(Stat&&Base))+N(Logbook&&(Stat&&(!Base)))\t %d=%d+%d",statAll,stat0,stat1);
91  }
92  // 2.b) Negation test N(!(A||B))=N((!A)&&(!B))
93  Int_t stat2b_0=AliTreePlayer::selectMetadata(testTree, "[class==\"!(Stat||Time)\"]",0)->GetEntries();
94  Int_t stat2b_1=AliTreePlayer::selectMetadata(testTree, "[class==\"(!Stat&&!Time)\"]",0)->GetEntries();
95  if (stat2b_0!=stat2b_1){
96  ::Error("AliTreePlayerTest.testSelectMetadata Negatioation test","Test ERROR: N(!(A||B))!=N((!A)&&(!B)) ");
97  }else{
98  ::Info("AliTreePlayerTest.testSelectMetadata Negatioation test","Test OK: N(!(A||B))=N((!A)&&(!B)) %d==%d",stat2b_0,stat2b_1);
99  }
100 }
101 
103  //
104  // test using as and input the QA.TPC tree
105  //
106  Int_t stat2a_0 = AliTreePlayer::selectTreeInfo(testTree, "([.name:meanMIP] )",0)->GetEntries();
107  Int_t stat2a_1 = AliTreePlayer::selectTreeInfo(testTree, "([.name:meanMIP] && ![.name:_])",0)->GetEntries();
108  Int_t stat2a_2 = AliTreePlayer::selectTreeInfo(testTree, "([.name:meanMIP] && [.name:_])",0)->GetEntries();
109  if (stat2a_0!=stat2a_1+stat2a_2){
110  ::Error("AliTreePlayerTest.testselectTreeInfo","Test ERROR: N(A))!=N(A&&B)&&N(A&&!B)) ");
111  }else{
112  ::Info("AliTreePlayerTest.testselectTreeInfo","Test OK: N(A))==N(A&&B)&&N(A&&!B)) %d=%d+%d",stat2a_0,stat2a_1,stat2a_2);
113  }
114 }
115 
116 
118  // aim of test -
119  // 1.) code not crashing
120  // 2.) test unique IDs (currently ther is a bug in )
121  // 3.) define properties in case of missing information
122  // Bug in the TTree::Scan
123  //
124  // Export algorithm:
125  // 1.) Load trees
126  // 2.) Set metadata (appropriate config file)
127  // 3.) Export default table
128  //
130  TTree * treeTRD0 = info.GetTree("QA.TRD","LHC15o","cpass1_pass1","QA.TRD;Logbook;");
131  TTree * treeTRD = info.GetTree("QA.TRD","LHC15o","cpass1_pass1","QA.TPC;QA.TRD;QA.TOF;Logbook;MonALISA.RCT");
132  TTree * treeTPC = info.GetTree("QA.TPC","LHC15o","cpass1_pass1","QA.TPC;QA.TRD;QA.TOF;Logbook;MonALISA.RCT");
133  // check/filter available data : AliTreePlayer::selectTreeInfo(treeTRD, "([.name:bz])",0)->Print();
134 
135  TString what0="";
136  what0+="Entry$:QA.TRD.run:QA.TPC.run:Logbook.run:Logbook.LHCperiod:QA.TPC.pass.GetName():QA.TPC.bz:Logbook.totalEventsPhysics:"; // add run properties
137  AliTreePlayer::selectWhatWhereOrderBy(treeTRD,what0.Data(),"1", "", 0,1000,"json","qatrdtest0.json");
138  AliTreePlayer::selectWhatWhereOrderBy(treeTPC,what0.Data(),"1", "", 0,1000,"json","qatpctest0.json");
139  //
140  //what+="MonALISA.RCT.tpc_value:MonALISA.RCT.trd_value:MonALISA.RCT.hlt_mode_value:"; // add MONALISA
141  // what+="TPCTRDmatchEffPosAll:TPCTRDmatchEffNegAll:TRDTOFmatchEffPosAll:TRDTOFmatchEffPosAll"; // add eff.
142  // what+="";
143 
144 }
145 
147  // test root->csv conversion
148  // test proper match of indexes
149  // In case of corruption of the indices test was failing
150  //
152  TTree *treeTPC = info.GetTree("QA.TPC", "LHC15o", "cpass1_pass1");
153  TTree *treeTRD = info.GetTree("QA.TRD", "LHC15o", "cpass1_pass1");
154  TTree *treeTRD2 = info.GetTree("QA.TRD", "LHC15o", "cpass1_pass1");
155 
156  treeTPC->BuildIndex("run");
157  treeTRD->BuildIndex("run");
158  treeTRD->AddFriend(treeTRD2,"QA.TRD");
159  treeTRD->AddFriend(treeTPC,"QA.TPC");
160 
161  AliTreePlayer::selectWhatWhereOrderBy(treeTRD,"run:QA.TRD.run:QA.TPC.run","1", "", 0,1000,"csv","sparsetest.csv");
162  // test that the 1 and 2 columns are the same - count different collumns
163  // cat sparsetest.csv | grep -v "run" | gawk '{ sum+=($1!=$2) } END {print sum} '
164  Int_t mismatch0 = (gSystem->GetFromPipe(" cat sparsetest.csv | grep -v \"run\" | gawk '{ sum+=($1!=$2) } END {print sum} '")).Atoi(); // should be 0 count run mismatch
165  // cat sparsetest.csv | grep -v "run" | gawk '{sum+=($1==prev); prev=$1;} END {print sum} '
166  Int_t mismatch1=(gSystem->GetFromPipe("cat sparsetest.csv | grep -v \"run\" | gawk '{sum+=($1==prev); prev=$1;} END {print sum} '")).Atoi();
167  if (mismatch0>0||mismatch1){
168  ::Error("AliTreePlayerTest.testConvertTree","Test ERROR Run mismatch for sparse trees");
169  }else{
170  ::Info("AliTreePlayerTest.testConvertTree","Test OK");
171  }
172 }
173 
174 
175 
176 
177 
179  //
180  // In case name and title correspond each other - Freind trees corraltion works properly
181  // In old implementation of the TTreeSredirector branch name and title were different
182  //
183  TTreeSRedirector *pcstream = new TTreeSRedirector("testSparseTree.root","recreate");
184  Int_t nruns=100;
185  for (Int_t irun=0; irun<nruns;irun++) {
186  (*pcstream)<<"runAll"<<"run="<<irun<<"\n";
187  if (irun%2==0) (*pcstream)<<"run2"<<"run="<<irun<<"\n";
188  if (irun%3==0) (*pcstream)<<"run3"<<"run="<<irun<<"\n";
189  if (irun%4==0) (*pcstream)<<"run4"<<"run="<<irun<<"\n";
190  if (gRandom->Rndm()<0.5) (*pcstream)<<"runR05"<<"run="<<irun<<"\n";
191  }
192  delete pcstream;
193  pcstream = new TTreeSRedirector("testSparseTree.root");
194  TList * tlist = pcstream->GetFile()->GetListOfKeys();
195  TTree * tree = (TTree*)pcstream->GetFile()->Get(tlist->At(0)->GetName());
196  tree->BuildIndex("run");
197  TTree * treeR = (TTree*)pcstream->GetFile()->Get("runR05");
198  treeR->BuildIndex("run");
199  for (Int_t ikey=0; ikey<=tlist->GetLast(); ikey++) {
200  TTree *treeF = (TTree*)pcstream->GetFile()->Get(tlist->At(ikey)->GetName());
201  treeF->BuildIndex("run");
202  tree->AddFriend(treeF, tlist->At(ikey)->GetName());
203  treeR->AddFriend(treeF, tlist->At(ikey)->GetName());
204  }
205  printf("printed entries should be unioue per row and the same within the row or not defined (in case of sparse)");
206  treeR->Scan("run:run2.run:run3.run:run4.run:runR05.run","","",20);
207 
208 }
void testConvertTree()
printf("Chi2/npoints = %f\n", TMath::Sqrt(chi2/npoints))
void AliTreePlayerTest()
#define TObjArray
TFile * GetFile()
Definition: TTreeStream.h:95
static TObjArray * selectTreeInfo(TTree *tree, TString query, Int_t verbose)
TTreeSRedirector * pcstream
TTree * tree
AliExternalInfo info
TObjArray * array
Definition: AnalyzeLaser.C:12
TTree * testTree
test of AliTreePlayer class
static TObjArray * selectMetadata(TTree *tree, TString query, Int_t verbose, TString *idList=NULL)
TTree * GetTree(TString type, TString period, TString pass, Int_t buildIndex=1)
static Int_t selectWhatWhereOrderBy(TTree *tree, TString what, TString where, TString orderBy, Int_t firstentry, Int_t nentries, TString outputFormat, TString outputName)
void reproduceIndexProblem()
This class gives you an interface to different trees of information spread throughout ALICE...
void testselectTreeInfo()
void testSelectMetadata()
void testselectWhatWhereOrderByForTRD()