00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "TFile.h"
00023 #include "TSystem.h"
00024 #include "TH1.h"
00025 #include "TRandom.h"
00026 #include "TStopwatch.h"
00027 #include "TKey.h"
00028 #include "TTree.h"
00029
00030 const Int_t N = 10000;
00031 TStopwatch timer;
00032
00033 void billw(Int_t compress) {
00034
00035 timer.Start();
00036 TFile f("/tmp/bill.root","recreate","bill benchmark with keys",compress);
00037 TH1F h("h","h",1000,-3,3);
00038 h.FillRandom("gaus",50000);
00039
00040 for (Int_t i=0;i<N;i++) {
00041 char name[20];
00042 sprintf(name,"h%d",i);
00043 h.SetName(name);
00044 h.Fill(2*gRandom->Rndm());
00045 h.Write();
00046 }
00047 timer.Stop();
00048 printf("billw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
00049 (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
00050 }
00051 void billr(Int_t compress) {
00052
00053 timer.Start();
00054 TFile f("/tmp/bill.root");
00055 TIter next(f.GetListOfKeys());
00056 TH1F *h;
00057 TH1::AddDirectory(kFALSE);
00058 TKey *key;
00059 Int_t i=0;
00060 TH1F *hmean = new TH1F("hmean","hist mean from keys",100,0,1);
00061
00062 while ((key=(TKey*)next())) {
00063 h = (TH1F*)key->ReadObj();
00064 hmean->Fill(h->GetMean());
00065 delete h;
00066 i++;
00067 }
00068 timer.Stop();
00069 printf("billr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
00070 }
00071 void billtw(Int_t compress) {
00072
00073 timer.Start();
00074 TFile f("/tmp/billt.root","recreate","bill benchmark with trees",compress);
00075 TH1F *h = new TH1F("h","h",1000,-3,3);
00076 h->FillRandom("gaus",50000);
00077 TTree *T = new TTree("T","test bill");
00078 T->Branch("event","TH1F",&h,64000,0);
00079 for (Int_t i=0;i<N;i++) {
00080 char name[20];
00081 sprintf(name,"h%d",i);
00082 h->SetName(name);
00083 h->Fill(2*gRandom->Rndm());
00084 T->Fill();
00085 }
00086 T->Write();
00087 delete T;
00088 timer.Stop();
00089 printf("billtw%d : RT=%7.3f s, Cpu=%7.3f s, File size= %9d bytes, CX= %g\n",compress,timer.RealTime(),timer.CpuTime(),
00090 (Int_t)f.GetBytesWritten(),f.GetCompressionFactor());
00091 }
00092 void billtr(Int_t compress) {
00093
00094 timer.Start();
00095 TFile f("/tmp/billt.root");
00096 TH1F *h = 0;
00097 TTree *T = (TTree*)f.Get("T");
00098 T->SetBranchAddress("event",&h);
00099 TH1F *hmeant = new TH1F("hmeant","hist mean from tree",100,0,1);
00100 Int_t nentries = (Int_t)T->GetEntries();
00101 for (Int_t i=0;i<nentries;i++) {
00102 T->GetEntry(i);
00103 hmeant->Fill(h->GetMean());
00104 }
00105 timer.Stop();
00106 printf("billtr%d : RT=%7.3f s, Cpu=%7.3f s\n",compress,timer.RealTime(),timer.CpuTime());
00107 }
00108 void bill() {
00109
00110 TStopwatch totaltimer;
00111 totaltimer.Start();
00112 for (Int_t compress=0;compress<2;compress++) {
00113 billw(compress);
00114 billr(compress);
00115 billtw(compress);
00116 billtr(compress);
00117 }
00118 gSystem->Unlink("/tmp/bill.root");
00119 gSystem->Unlink("/tmp/billt.root");
00120 totaltimer.Stop();
00121 Double_t rtime = totaltimer.RealTime();
00122 Double_t ctime = totaltimer.CpuTime();
00123 printf("billtot : RT=%7.3f s, Cpu=%7.3f s\n",rtime,ctime);
00124
00125 Float_t rootmarks = 600*(16.98 + 14.40)/(rtime + ctime);
00126 printf("******************************************************************\n");
00127 printf("* ROOTMARKS =%6.1f * Root%-8s %d/%d\n",rootmarks,gROOT->GetVersion(),gROOT->GetVersionDate(),gROOT->GetVersionTime());
00128 printf("******************************************************************\n");
00129 }
00130