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 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081 
00082 
00083 #include <stdlib.h>
00084 
00085 #include "Riostream.h"
00086 #include "TROOT.h"
00087 #include "TFile.h"
00088 #include "TNetFile.h"
00089 #include "TRandom.h"
00090 #include "TTree.h"
00091 #include "TBranch.h"
00092 #include "TClonesArray.h"
00093 #include "TStopwatch.h"
00094 
00095 #include "Event.h"
00096 
00097 
00098 
00099 int main(int argc, char **argv)
00100 {
00101    Int_t nevent = 400;     
00102    Int_t comp   = 1;       
00103    Int_t split  = 1;       
00104    Int_t write  = 1;       
00105    Int_t hfill  = 0;       
00106    Int_t read   = 0;
00107    Int_t arg4   = 1;
00108    Int_t arg5   = 600;     
00109    Int_t netf   = 0;
00110    Int_t punzip = 0;
00111 
00112    if (argc > 1)  nevent = atoi(argv[1]);
00113    if (argc > 2)  comp   = atoi(argv[2]);
00114    if (argc > 3)  split  = atoi(argv[3]);
00115    if (argc > 4)  arg4   = atoi(argv[4]);
00116    if (argc > 5)  arg5   = atoi(argv[5]);
00117    if (arg4 ==  0) { write = 0; hfill = 0; read = 1;}
00118    if (arg4 ==  1) { write = 1; hfill = 0;}
00119    if (arg4 ==  2) { write = 0; hfill = 0;}
00120    if (arg4 == 10) { write = 0; hfill = 1;}
00121    if (arg4 == 11) { write = 1; hfill = 1;}
00122    if (arg4 == 20) { write = 0; read  = 1;}  
00123    if (arg4 == 21) { write = 0; read  = 1;  punzip = 1;}  
00124    if (arg4 == 25) { write = 0; read  = 2;}  
00125    if (arg4 >= 30) { netf  = 1; }            
00126    if (arg4 == 30) { write = 0; read  = 1;}  
00127    if (arg4 == 35) { write = 0; read  = 2;}  
00128    if (arg4 == 36) { write = 1; }            
00129    Int_t branchStyle = 1; 
00130    if (split < 0) {branchStyle = 0; split = -1-split;}
00131 
00132    TFile *hfile;
00133    TTree *tree;
00134    Event *event = 0;
00135 
00136    
00137    
00138    TStopwatch timer;
00139    timer.Start();
00140    Long64_t nb = 0;
00141    Int_t ev;
00142    Int_t bufsize;
00143    Double_t told = 0;
00144    Double_t tnew = 0;
00145    Int_t printev = 100;
00146    if (arg5 < 100) printev = 1000;
00147    if (arg5 < 10)  printev = 10000;
00148 
00149 
00150    if (read) {
00151       if (netf) {
00152          hfile = new TNetFile("root://localhost/root/test/EventNet.root");
00153       } else
00154          hfile = new TFile("Event.root");
00155       tree = (TTree*)hfile->Get("T");
00156       TBranch *branch = tree->GetBranch("event");
00157       branch->SetAddress(&event);
00158       Int_t nentries = (Int_t)tree->GetEntries();
00159       nevent = TMath::Min(nevent,nentries);
00160       if (read == 1) {  
00161          
00162          Int_t cachesize = -1; 
00163          if (punzip) tree->SetParallelUnzip();
00164          tree->SetCacheSize(cachesize);
00165          tree->SetCacheLearnEntries(1); 
00166          tree->SetCacheEntryRange(0,nevent);
00167          for (ev = 0; ev < nevent; ev++) {
00168             tree->LoadTree(ev);  
00169             if (ev%printev == 0) {
00170                tnew = timer.RealTime();
00171                printf("event:%d, rtime=%f s\n",ev,tnew-told);
00172                told=tnew;
00173                timer.Continue();
00174             }
00175             nb += tree->GetEntry(ev);        
00176          }
00177       } else {    
00178          Int_t evrandom;
00179          for (ev = 0; ev < nevent; ev++) {
00180             if (ev%printev == 0) cout<<"event="<<ev<<endl;
00181             evrandom = Int_t(nevent*gRandom->Rndm(1));
00182             nb += tree->GetEntry(evrandom);  
00183          }
00184       }
00185    } else {
00186 
00187       
00188       
00189       
00190       
00191       if (netf) {
00192          hfile = new TNetFile("root://localhost/root/test/EventNet.root","RECREATE","TTree benchmark ROOT file");
00193       } else
00194          hfile = new TFile("Event.root","RECREATE","TTree benchmark ROOT file");
00195       hfile->SetCompressionLevel(comp);
00196 
00197      
00198      Float_t curtime = -0.5;
00199      Int_t ntime = nevent/printev;
00200      TH1F *htime = new TH1F("htime","Real-Time to write versus time",ntime,0,ntime);
00201      HistogramManager *hm = 0;
00202      if (hfill) {
00203         TDirectory *hdir = new TDirectory("histograms", "all histograms");
00204         hm = new HistogramManager(hdir);
00205      }
00206 
00207      
00208       tree = new TTree("T","An example of a ROOT tree");
00209       tree->SetAutoSave(1000000000); 
00210       tree->SetCacheSize(10000000);  
00211       bufsize = 64000;
00212       if (split)  bufsize /= 4;
00213       event = new Event();
00214       TTree::SetBranchStyle(branchStyle);
00215       TBranch *branch = tree->Branch("event", &event, bufsize,split);
00216       branch->SetAutoDelete(kFALSE);
00217       if(split >= 0 && branchStyle) tree->BranchRef();
00218       Float_t ptmin = 1;
00219 
00220       for (ev = 0; ev < nevent; ev++) {
00221          if (ev%printev == 0) {
00222             tnew = timer.RealTime();
00223             printf("event:%d, rtime=%f s\n",ev,tnew-told);
00224             htime->Fill(curtime,tnew-told);
00225             curtime += 1;
00226             told=tnew;
00227             timer.Continue();
00228          }
00229 
00230          event->Build(ev, arg5, ptmin);
00231 
00232          if (write) nb += tree->Fill();  
00233 
00234          if (hm) hm->Hfill(event);      
00235       }
00236       if (write) {
00237          hfile = tree->GetCurrentFile(); 
00238          hfile->Write();
00239          tree->Print();
00240       }
00241    }
00242 
00243    
00244    timer.Stop();
00245    Float_t mbytes = 0.000001*nb;
00246    Double_t rtime = timer.RealTime();
00247    Double_t ctime = timer.CpuTime();
00248 
00249 
00250    printf("\n%d events and %lld bytes processed.\n",nevent,nb);
00251    printf("RealTime=%f seconds, CpuTime=%f seconds\n",rtime,ctime);
00252    if (read) {
00253       tree->PrintCacheStats();
00254       printf("You read %f Mbytes/Realtime seconds\n",mbytes/rtime);
00255       printf("You read %f Mbytes/Cputime seconds\n",mbytes/ctime);
00256    } else {
00257       printf("compression level=%d, split=%d, arg4=%d\n",comp,split,arg4);
00258       printf("You write %f Mbytes/Realtime seconds\n",mbytes/rtime);
00259       printf("You write %f Mbytes/Cputime seconds\n",mbytes/ctime);
00260       
00261    }
00262    hfile->Close();
00263    return 0;
00264 }