00001
00002
00003
00004
00005
00006
00007 const char* dbname = "mysql://host.domain/test";
00008 const char* username = "user";
00009 const char* userpass = "pass";
00010
00011
00012
00013
00014
00015
00016 void sqlcanvas()
00017 {
00018 canvas_write();
00019 canvas_read();
00020 }
00021
00022 void canvas_write()
00023 {
00024
00025 delete gROOT->GetListOfFiles()->FindObject("hsimple.root");
00026 delete gROOT->GetListOfCanvases()->FindObject("c1");
00027
00028 gBenchmark->Start("ntuple1");
00029
00030
00031
00032 TFile *f1 = new TFile("hsimple.root");
00033
00034
00035
00036 TCanvas *c1 = new TCanvas("c1","The Ntuple canvas",200,10,700,780);
00037 TPad *pad1 = new TPad("pad1","This is pad1",0.02,0.52,0.48,0.98,21);
00038 TPad *pad2 = new TPad("pad2","This is pad2",0.52,0.52,0.98,0.98,21);
00039 TPad *pad3 = new TPad("pad3","This is pad3",0.02,0.02,0.48,0.48,21);
00040 TPad *pad4 = new TPad("pad4","This is pad4",0.52,0.02,0.98,0.48,1);
00041 pad1->Draw();
00042 pad2->Draw();
00043 pad3->Draw();
00044 pad4->Draw();
00045
00046
00047 gStyle->SetStatW(0.30);
00048 gStyle->SetStatH(0.20);
00049 gStyle->SetStatColor(42);
00050
00051
00052
00053 pad1->cd();
00054 pad1->SetGrid();
00055 pad1->SetLogy();
00056 pad1->GetFrame()->SetFillColor(15);
00057 TNtuple *ntuple = (TNtuple*)f1->Get("ntuple");
00058 ntuple->SetLineColor(1);
00059 ntuple->SetFillStyle(1001);
00060 ntuple->SetFillColor(45);
00061 ntuple->Draw("3*px+2","px**2+py**2>1");
00062 ntuple->SetFillColor(38);
00063 ntuple->Draw("2*px+2","pz>2","same");
00064 ntuple->SetFillColor(5);
00065 ntuple->Draw("1.3*px+2","(px^2+py^2>4) && py>0","same");
00066 pad1->RedrawAxis();
00067
00068
00069
00070
00071 pad2->cd();
00072 pad2->SetGrid();
00073 pad2->GetFrame()->SetFillColor(32);
00074 ntuple->Draw("pz:px>>hprofs","","goffprofs");
00075 TProfile *hprofs = (TProfile*)gDirectory->Get("hprofs");
00076 hprofs->SetMarkerColor(5);
00077 hprofs->SetMarkerSize(0.7);
00078 hprofs->SetMarkerStyle(21);
00079 hprofs->Fit("pol2");
00080
00081 TF1 *fpol2 = hprofs->GetFunction("pol2");
00082 fpol2->SetLineWidth(4);
00083 fpol2->SetLineColor(2);
00084
00085
00086
00087 pad3->cd();
00088 pad3->GetFrame()->SetFillColor(38);
00089 pad3->GetFrame()->SetBorderSize(8);
00090 ntuple->SetMarkerColor(1);
00091 ntuple->Draw("py:px","pz>1");
00092 ntuple->SetMarkerColor(2);
00093 ntuple->Draw("py:px","pz<1","same");
00094
00095
00096 pad4->cd();
00097 ntuple->Draw("pz:py:px","(pz<10 && pz>6)+(pz<4 && pz>3)");
00098 ntuple->SetMarkerColor(4);
00099 ntuple->Draw("pz:py:px","pz<6 && pz>4","same");
00100 ntuple->SetMarkerColor(5);
00101 ntuple->Draw("pz:py:px","pz<4 && pz>3","same");
00102 TPaveText *l4 = new TPaveText(-0.9,0.5,0.9,0.95);
00103 l4->SetFillColor(42);
00104 l4->SetTextAlign(12);
00105 l4->AddText("You can interactively rotate this view in 2 ways:");
00106 l4->AddText(" - With the RotateCube in clicking in this pad");
00107 l4->AddText(" - Selecting View with x3d in the View menu");
00108 l4->Draw();
00109
00110 c1->cd();
00111 c1->Update();
00112 gStyle->SetStatColor(19);
00113 gBenchmark->Show("ntuple1");
00114
00115 TSQLFile* fsql1 = new TSQLFile(dbname, "recreate", username, userpass);
00116 if (fsql1->IsZombie()) { delete fsql1; return; }
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 gBenchmark->Start("writeSQL");
00132 c1->Write("Canvas");
00133 gBenchmark->Show("writeSQL");
00134 delete fsql1;
00135 }
00136
00137 void canvas_read()
00138 {
00139 TFile* f2 = new TSQLFile(dbname, "open", username, userpass);
00140 if (f2->IsZombie()) { delete f2; return; }
00141
00142 f2->ls();
00143 gBenchmark->Start("readSQL");
00144 TCanvas* cc = (TCanvas*) f2->Get("Canvas");
00145 gBenchmark->Show("readSQL");
00146 if (cc!=0) cc->Draw();
00147
00148 delete f2;
00149 }
00150