00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <stdlib.h>
00039 #include "TApplication.h"
00040 #include "TEntryList.h"
00041 #include "TEventList.h"
00042 #include "TTree.h"
00043 #include "TChain.h"
00044 #include "TRandom.h"
00045 #include "TH1F.h"
00046 #include "TCut.h"
00047 #include "TFile.h"
00048 #include "TSystem.h"
00049
00050 Int_t stressEntryList(Int_t nentries = 10000, Int_t nfiles = 10);
00051 void MakeTrees(Int_t nentries, Int_t nfiles);
00052
00053 Bool_t Test1()
00054 {
00055
00056
00057
00058
00059 Int_t wrongentries1, wrongentries2, wrongentries3, wrongentries4, wrongentries5;
00060 TChain *bigchain = new TChain("bigchain", "bigchain");
00061 bigchain->Add("stressEntryListTrees*.root/tree1");
00062 bigchain->Add("stressEntryListTrees*.root/tree2");
00063
00064 TChain *smallchain = new TChain("smallchain", "smallchain");
00065 smallchain->Add("stressEntryListTrees*.root/tree1");
00066
00067
00068 TCut cut = "x<0 && y>0";
00069 smallchain->Draw(">>elist_small", cut, "entrylist");
00070 TEntryList *elist_small = (TEntryList*)gDirectory->Get("elist_small");
00071
00072
00073 Int_t range = 100;
00074 TH1F *hx = new TH1F("hx", "hx", range, -range, range);
00075 smallchain->Draw("x >> hx", cut, "goff");
00076 TH1F *hcheck = new TH1F("hcheck", "hcheck", range, -range, range);
00077
00078 smallchain->SetEntryList(elist_small);
00079 smallchain->Draw("x >> hcheck", "", "goff");
00080 wrongentries1 = 0;
00081 for (Int_t i=1; i<=range; i++){
00082 if (TMath::Abs(hx->GetBinContent(i)-hcheck->GetBinContent(i)) > 0.1){
00083 wrongentries1++;
00084 }
00085 }
00086 if (wrongentries1 >0)
00087 printf("\nsmall list and small chain: number of wrong bins=%d\n", wrongentries1);
00088
00089
00090 bigchain->SetEntryList(elist_small);
00091 bigchain->Draw("x >> hcheck_", "", "goff");
00092 wrongentries2 = 0;
00093 for (Int_t i=1; i<=range; i++){
00094 if (TMath::Abs(hx->GetBinContent(i)-hcheck->GetBinContent(i)) > 0.1){
00095 wrongentries2++;
00096 }
00097 }
00098 if (wrongentries2 >0)
00099 printf("\nsmall elist and big chain: number of wrong bins=%d\n", wrongentries2);
00100
00101 smallchain->SetEntryList(0);
00102 bigchain->SetEntryList(0);
00103
00104
00105 bigchain->Draw(">>elist_big", cut, "entrylist");
00106 TEntryList* elist_big = (TEntryList*)gDirectory->Get("elist_big");
00107
00108
00109 TEntryList *list_extracted = new TEntryList("list_extracted", "list_extracted");
00110 TEntryList *elist_temp;
00111 TList *lists = elist_big->GetLists();
00112 TIter next(lists);
00113 while ((elist_temp = (TEntryList*)next())){
00114 if (!strcmp(elist_temp->GetTreeName(),"tree1"))
00115 list_extracted->Add(elist_temp);
00116 }
00117
00118
00119 Long64_t entry1, entry2;
00120 Int_t n=list_extracted->GetN();
00121 wrongentries3 = 0;
00122 for (Int_t i=0; i<n; i++){
00123 entry1 = list_extracted->GetEntry(i);
00124 entry2 = elist_small->GetEntry(i);
00125 if (entry1 != entry2){
00126 if (wrongentries3<10) printf("wrong entry: %d list2=%lld elist_small=%lld\n", i, entry1, entry2);
00127 wrongentries3++;
00128 }
00129 }
00130 if (wrongentries3 >0)
00131 printf("\nsmall list and extracted list: number of wrong entries = %d, n=%d\n", wrongentries3,n);
00132
00133
00134 elist_temp = (TEntryList*)lists->Last();
00135 list_extracted->Add(elist_temp);
00136 smallchain->SetEntryList(list_extracted);
00137 smallchain->Draw("x>>hcheck", "", "goff");
00138 wrongentries4 = 0;
00139 for (Int_t i=1; i<=range; i++){
00140 if (TMath::Abs(hx->GetBinContent(i)-hcheck->GetBinContent(i)) > 0.1){
00141
00142 wrongentries4++;
00143 }
00144 }
00145 if (wrongentries4 >0)
00146 printf("\nextracted list with 1 wrong: number of wrong bins=%d\n", wrongentries4);
00147
00148
00149
00150 smallchain->SetEntryList(elist_big);
00151 smallchain->Draw("x >> hcheck", "", "goff");
00152 wrongentries5 = 0;
00153 for (Int_t i=1; i<=range; i++){
00154 if (TMath::Abs(hx->GetBinContent(i)-hcheck->GetBinContent(i)) > 0.1){
00155
00156 wrongentries5++;
00157 }
00158 }
00159 if (wrongentries5 >0)
00160 printf("\nbig elist and small chain: number of wrong bins = %d\n", wrongentries5);
00161
00162 delete bigchain;
00163 delete smallchain;
00164 delete hx;
00165 delete hcheck;
00166 delete elist_big;
00167 delete elist_small;
00168 delete list_extracted;
00169
00170 if (wrongentries1>0 || wrongentries2>0 || wrongentries3>0 || wrongentries4>0 || wrongentries5>0)
00171 return kFALSE;
00172 return kTRUE;
00173 }
00174
00175 Bool_t Test2()
00176 {
00177
00178
00179 Int_t wrongentries1, wrongentries2, wrongentries3, wrongentries4, wrongentries5;
00180 TChain *chain = new TChain("chain", "chain");
00181 chain->Add("stressEntryListTrees_0.root/tree1");
00182 chain->Add("stressEntryListTrees_0.root/tree2");
00183
00184
00185 TCut cut1("cut1", "x>0");
00186 TCut cut2("cut2", "y<0.1 && y>-0.1");
00187 TEntryList *elist1 = new TEntryList("elist1", "elist1");
00188 chain->Draw(">>elist1", cut1, "entrylist");
00189 TEntryList *elist2 = new TEntryList("elist2", "elist2");
00190 chain->Draw(">>elist2", cut2, "entrylist");
00191
00192
00193 TEntryList *elistsum = new TEntryList("elistsum", "elistsum");
00194 elistsum->Add(elist1);
00195 elistsum->Add(elist2);
00196
00197 TEntryList *elistcheck = new TEntryList("elistcheck", "elistcheck");
00198 chain->Draw(">>elistcheck", cut1 || cut2, "entrylist");
00199
00200 Int_t n=elistcheck->GetN();
00201 Long64_t entry1, entry2;
00202 wrongentries1=0;
00203 for (Int_t i=0; i<n; i++){
00204 entry1 = elistsum->GetEntry(i);
00205 entry2 = elistcheck->GetEntry(i);
00206 if (entry1 != entry2) {
00207
00208 wrongentries1++;
00209 }
00210 }
00211 if (wrongentries1>0)
00212 printf("\nwrong entries (1+2)=%d\n", wrongentries1);
00213
00214
00215 TEntryList *elistsum2 = new TEntryList("elistsum2", "elistsum2");
00216 elistsum2->Add(elist2);
00217 elistsum2->Add(elist1);
00218 wrongentries2 = 0;
00219 for (Int_t i=0; i<n; i++){
00220 entry1 = elistsum2->GetEntry(i);
00221 entry2 = elistcheck->GetEntry(i);
00222 if (entry1 != entry2) {
00223
00224 wrongentries2++;
00225 }
00226 }
00227 if (wrongentries2>0)
00228 printf("\nwrong entries (2+1)=%d\n", wrongentries2);
00229
00230
00231
00232 TEntryList *elistsum3 = new TEntryList("elistsum3", "elistsum3");
00233 chain->Draw(">>elistsum3", cut1, "entrylist");
00234 chain->Draw(">>+elistsum3", cut2, "entrylist");
00235 wrongentries3 = 0;
00236 for (Int_t i=0; i<n; i++){
00237 entry1 = elistsum3->GetEntry(i);
00238 entry2 = elistcheck->GetEntry(i);
00239 if (entry1 != entry2) {
00240
00241 wrongentries3++;
00242 }
00243 }
00244 if (wrongentries3>0)
00245 printf("\nwrong entries with \"+\" in TChain::Draw =%d\n", wrongentries3);
00246
00247
00248 elistsum->Subtract(elist2);
00249 n = elistsum->GetN();
00250 TEntryList *elistcheck2 = new TEntryList("elistcheck2","elistcheck2");
00251 chain->Draw(">>elistcheck2", "x>0 && (y>0.1 || y<-0.1)", "entrylist");
00252
00253 wrongentries4 = 0;
00254 for (Int_t i=0; i<n; i++){
00255 entry1 = elistsum->GetEntry(i);
00256 entry2 = elistcheck2->GetEntry(i);
00257 if (entry1 != entry2){
00258
00259 wrongentries4++;
00260 }
00261 }
00262 if (wrongentries4>0)
00263 printf("\nwrong entries after subtract 2 = %d\n", wrongentries4);
00264
00265
00266 elistsum2->Subtract(elist1);
00267 elistcheck2->Reset();
00268 chain->Draw(">>elistcheck2", "x<0 && y<0.1 && y>-0.1", "entrylist");
00269 wrongentries5 = 0;
00270 n = elistcheck2->GetN();
00271 for (Int_t i=0; i<n; i++){
00272 entry1 = elistsum2->GetEntry(i);
00273 entry2 = elistcheck2->GetEntry(i);
00274 if (entry1 != entry2){
00275
00276 wrongentries5++;
00277 }
00278 }
00279 if (wrongentries5>0)
00280 printf("\nwrong entries after subtract 1 = %d\n", wrongentries5);
00281
00282 delete elist1;
00283 delete elist2;
00284 delete elistsum;
00285 delete elistsum2;
00286 delete elistsum3;
00287 delete elistcheck;
00288 delete elistcheck2;
00289
00290 if (wrongentries1>0 || wrongentries2>0 || wrongentries3>0 || wrongentries4>0 || wrongentries5>0)
00291 return kFALSE;
00292 return kTRUE;
00293 }
00294
00295 Bool_t Test3()
00296 {
00297
00298
00299 TChain *chain = new TChain("chain", "chain");
00300 chain->Add("stressEntryListTrees*.root/tree1");
00301 chain->Add("stressEntryListTrees*.root/tree2");
00302
00303 TCut cut = "x<0 && y>0";
00304
00305 chain->Draw(">>evlist", cut, "");
00306 TEventList *evlist = (TEventList*)gDirectory->Get("evlist");
00307 chain->Draw("x>>h1", cut, "goff");
00308 TH1F *h1 = (TH1F*)gDirectory->Get("h1");
00309 chain->SetEventList(evlist);
00310 chain->Draw("x>>h2", "", "goff");
00311 TH1F *h2 = (TH1F*)gDirectory->Get("h2");
00312
00313 chain->SetEventList(0);
00314 chain->Draw(">>enlist", cut, "entrylist");
00315 TEntryList *enlist = (TEntryList*)gDirectory->Get("enlist");
00316 chain->SetEntryList(enlist);
00317
00318 chain->Draw("x>>h3", "", "goff");
00319 TH1F *h3 = (TH1F*)gDirectory->Get("h3");
00320
00321 Int_t wrongbins = 0;
00322 Int_t nbins1 = h1->GetNbinsX();
00323
00324 Double_t bin1,bin2,bin3;
00325 for (Int_t i=0; i<nbins1; i++){
00326 bin1 = h1->GetBinContent(i);
00327 bin2 = h2->GetBinContent(i);
00328 bin3 = h3->GetBinContent(i);
00329 if (TMath::Abs(bin1-bin2) > 0.1 || TMath::Abs(bin1-bin3) || TMath::Abs(bin2-bin3) > 0.1) {
00330
00331 wrongbins++;
00332 }
00333 }
00334 if (wrongbins>0)
00335 printf("wrongbins=%d\n", wrongbins);
00336
00337 delete chain;
00338 delete h1;
00339 delete h2;
00340 delete h3;
00341 delete evlist;
00342 delete enlist;
00343 if (wrongbins>0)
00344 return kFALSE;
00345 return kTRUE;
00346 }
00347
00348 Bool_t Test4()
00349 {
00350
00351
00352 TFile f("stressEntryListTrees_0.root");
00353 TTree *tree = (TTree*)f.Get("tree1");
00354 TCut cut = "x<0 && y>0";
00355 tree->Draw(">>evlist", cut, "");
00356 TEventList *evlist = (TEventList*)gDirectory->Get("evlist");
00357 tree->Draw("x>>h1", cut, "goff");
00358 TH1F *h1 = (TH1F*)gDirectory->Get("h1");
00359 tree->SetEventList(evlist);
00360 tree->Draw("x>>h2", "", "goff");
00361 TH1F *h2 = (TH1F*)gDirectory->Get("h2");
00362
00363 tree->SetEventList(0);
00364 tree->Draw(">>enlist", cut, "entrylist");
00365 TEntryList *enlist = (TEntryList*)gDirectory->Get("enlist");
00366 tree->SetEntryList(enlist);
00367 tree->Draw("x>>h3", "", "goff");
00368 TH1F *h3 = (TH1F*)gDirectory->Get("h3");
00369 Int_t wrongbins = 0;
00370 Int_t nbins1 = h1->GetNbinsX();
00371
00372 Double_t bin1,bin2,bin3;
00373 for (Int_t i=0; i<nbins1; i++){
00374 bin1 = h1->GetBinContent(i);
00375 bin2 = h2->GetBinContent(i);
00376 bin3 = h3->GetBinContent(i);
00377 if (TMath::Abs(bin1-bin2) > 0.1 || TMath::Abs(bin1-bin3) || TMath::Abs(bin2-bin3) > 0.1) {
00378
00379 wrongbins++;
00380 }
00381 }
00382 if (wrongbins>0)
00383 printf("wrongbins=%d\n", wrongbins);
00384
00385 delete h1;
00386 delete h2;
00387 delete h3;
00388 delete evlist;
00389 delete enlist;
00390 f.Close();
00391
00392 if (wrongbins>0)
00393 return kFALSE;
00394 return kTRUE;
00395 }
00396
00397 Bool_t Test5()
00398 {
00399
00400
00401
00402 TChain *chain = new TChain("chain", "chain");
00403 chain->Add("stressEntryListTrees*.root/tree1");
00404 chain->Add("stressEntryListTrees*.root/tree2");
00405 Int_t wrongentries1=0;
00406 Int_t wrongentries2=0;
00407 Int_t wrongentries3=0;
00408 Int_t wrongentries4=0;
00409 Int_t wrongentries5=0;
00410
00411 chain->Draw(">>elfull", "", "entrylist");
00412 TEntryList *elfull = (TEntryList*)gDirectory->Get("elfull");
00413
00414
00415
00416 Long64_t cur, real;
00417 Int_t ntrees = chain->GetNtrees();
00418 Long64_t *offset = chain->GetTreeOffset();
00419
00420 for (Int_t itree=0; itree<ntrees; itree++){
00421 for (Int_t i=offset[itree]; i<offset[itree+1]; i++){
00422 real = i-offset[itree];
00423 cur = elfull->GetEntry(i);
00424 if (TMath::Abs(real-cur)>0.1){
00425
00426 wrongentries1++;
00427 }
00428 }
00429 }
00430
00431
00432 for (Int_t itree=0; itree<ntrees; itree++){
00433 for (Int_t i=offset[itree]; i<offset[itree+1]; i+=2){
00434 real = i-offset[itree];
00435 cur = elfull->GetEntry(i);
00436 if (TMath::Abs(real-cur)>0.1){
00437
00438 wrongentries2++;
00439 }
00440 }
00441 }
00442
00443
00444
00445
00446 chain->Draw(">>elempty", "x>0 && x<0", "entrylist");
00447 TEntryList *elempty = (TEntryList*)gDirectory->Get("elempty");
00448
00449 Long64_t temp = elempty->GetEntry(3);
00450 if (TMath::Abs(temp+1)>0.1)
00451 wrongentries5++;
00452
00453
00454
00455
00456
00457
00458 elfull->Remove(3, chain);
00459 elempty->Enter(3, chain);
00460 elfull->Add(elempty);
00461
00462
00463 for (Int_t itree=0; itree<ntrees-1; itree++){
00464 for (Int_t i=offset[itree]; i<offset[itree+1]; i++){
00465 real = i-offset[itree];
00466 cur = elfull->GetEntry(i);
00467 if (TMath::Abs(real-cur)>0.1){
00468
00469 wrongentries3++;
00470 }
00471 }
00472 }
00473
00474
00475
00476 for (Int_t itree=0; itree<ntrees-1; itree++){
00477 for (Int_t i=offset[itree]; i<offset[itree+1]; i+=2){
00478 real = i-offset[itree];
00479 cur = elfull->GetEntry(i);
00480 if (TMath::Abs(real-cur)>0.1){
00481
00482 wrongentries4++;
00483 }
00484 }
00485 }
00486
00487
00488
00489 chain->SetEntryList(elfull);
00490 chain->Draw("x>>hx", "", "goff");
00491 TH1F *hx = (TH1F*)gDirectory->Get("hx");
00492 if (TMath::Abs(hx->GetEntries()-chain->GetEntries())>0.1){
00493 wrongentries5++;
00494
00495 }
00496
00497 elempty->Remove(3);
00498
00499 chain->SetEntryList(elempty);
00500 Long64_t nen = chain->Draw("x", "", "goff");
00501 if (nen!=0) wrongentries5++;
00502
00503
00504
00505 delete elempty;
00506 delete elfull;
00507 delete hx;
00508 if (wrongentries1>0 || wrongentries2>0 || wrongentries3>0 || wrongentries4>0 || wrongentries5>0)
00509 return kFALSE;
00510 else
00511 return kTRUE;
00512 }
00513
00514
00515 void MakeTrees(Int_t nentries, Int_t nfiles)
00516 {
00517
00518
00519 TFile *f1;
00520 TTree *tree1, *tree2;
00521
00522 Double_t x, y, z;
00523 Double_t range = nentries/100.;
00524
00525 char buffer[50];
00526 for (Int_t ifile=0; ifile<nfiles; ifile++){
00527 sprintf(buffer, "stressEntryListTrees_%d.root", ifile);
00528 f1 = new TFile(buffer, "UPDATE");
00529 tree1 = new TTree("tree1", "tree1");
00530 tree1->Branch("x", &x, "x/D");
00531 tree1->Branch("y", &y, "y/D");
00532 tree1->Branch("z", &z, "z/D");
00533 tree2 = new TTree("tree2", "tree2");
00534 tree2->Branch("x", &x, "x/D");
00535 tree2->Branch("y", &y, "y/D");
00536 tree2->Branch("z", &z, "z/D");
00537 for (Int_t i=0; i<nentries; i++){
00538 x = gRandom->Uniform(-range, range);
00539 y = gRandom->Uniform(-range, range);
00540 z = gRandom->Uniform(-range, range);
00541 tree1->Fill();
00542 x = gRandom->Uniform(-range, range);
00543 y = gRandom->Uniform(-range, range);
00544 z = gRandom->Uniform(-range, range);
00545 tree2->Fill();
00546 }
00547 tree1->Write();
00548 tree2->Write();
00549
00550 f1->Write();
00551 f1->Close();
00552 }
00553
00554 }
00555
00556 void CleanUp(Int_t nfiles)
00557 {
00558 char buffer[50];
00559 for (Int_t i=0; i<nfiles; i++){
00560 sprintf(buffer, "stressEntryListTrees_%d.root", i);
00561 gSystem->Unlink(buffer);
00562 }
00563 }
00564
00565 Int_t stressEntryList(Int_t nentries, Int_t nfiles)
00566 {
00567
00568
00569 MakeTrees(nentries, nfiles);
00570 printf("**********************************************************************\n");
00571 printf("***************Starting TEntryList stress test************************\n");
00572 printf("**********************************************************************\n");
00573 printf("**********Generating %d data files, 2 trees of %d in each**********\n", nfiles, nentries);
00574 printf("**********************************************************************\n");
00575
00576 Bool_t ok1=kTRUE;
00577 Bool_t ok2=kTRUE;
00578 Bool_t ok3=kTRUE;
00579 Bool_t ok4=kTRUE;
00580 Bool_t ok5=kTRUE;
00581
00582 ok1 = Test1();
00583 if (ok1)
00584 printf("Test1: Applying different entry lists to different chains --------- OK\n");
00585 else{
00586 printf("Test1: Applying different entry lists to different chains --------- FAILED\n");
00587
00588 }
00589 ok2 = Test2();
00590 if (ok2)
00591 printf("Test2: Adding and subtracting entry lists-------------------------- OK\n");
00592 else{
00593 printf("Test1: Adding and subtracting entry lists-------------------------- FAILED\n");
00594 }
00595
00596 ok3 = Test3();
00597 if (ok3)
00598 printf("Test3: TEntryList and TEventList for TChain------------------------ OK\n");
00599 else{
00600 printf("Test3: TEntryList and TEventList for TChain------------------------ FAILED\n");
00601 }
00602
00603 ok4 = Test4();
00604 if (ok4)
00605 printf("Test4: TEntryList and TEventList for TTree------------------------- OK\n");
00606 else{
00607 printf("Test4: TEntryList and TEventList for TTree------------------------- FAILED\n");
00608 }
00609
00610 ok5 = Test5();
00611 if (ok5)
00612 printf("Test5: Full and Empty TEntryList----------------------------------- OK\n");
00613 else
00614 printf("Test5: Full and Empty TEntryList----------------------------------- FAILED\n");
00615
00616 printf("**********************************************************************\n");
00617 printf("*******************Deleting the data files****************************\n");
00618 printf("**********************************************************************\n");
00619 CleanUp(nfiles);
00620 return 0;
00621 }
00622
00623 #ifndef __CINT__
00624
00625 int main(int argc, char *argv[])
00626 {
00627 TApplication theApp("App", &argc, argv);
00628 Int_t nentries = 10000;
00629 Int_t nfiles = 10;
00630 if (argc > 1) nentries = atoi(argv[1]);
00631 if (argc > 2) nfiles = atoi(argv[2]);
00632 stressEntryList(nentries, nfiles);
00633 return 0;
00634 }
00635
00636 #endif
00637