#include #include #include #include #include #include #include #include "G0SQL.h" #include "G0SQLResult.h" #include "MyResult.h" #include #include #include #include #include "Rtypes.h" #include #include TCanvas* c1; TH1F* h1; TGraphErrors* ge; G0SQL* g0sql; Int_t PlotGraphErrors(G0SQLResult* g0res, const string& x_title, const string& y_title, const string& x_title_err = "", const string& y_title_err = "") { //++ Retrieve number of rows and columns UInt_t nrows = g0res->GetNRows(); cerr << "nrows = " << nrows << endl; UInt_t ncols = g0res->GetNColumns(); cerr << "ncols = " << ncols << endl; //++ Initialize arrays Float_t* x_array = 0; Float_t* y_array = 0; Float_t* x_array_err = 0; Float_t* y_array_err = 0; //++ Retrieve arrays from G0SQLResult UInt_t n = 0; // Retrieve array x_array = g0res->GetArrayF(x_title); // Retrieve array name cerr << g0res->GetArrayName(n) << endl; n++; y_array = g0res->GetArrayF(y_title); cerr << g0res->GetArrayName(n) << endl; n++; // Make sure that plotting with errors was requested before // attempting to retrieve error arrays. if (x_title_err.size() > 0) { x_array_err = g0res->GetArrayF(x_title_err); cerr << g0res->GetArrayName(n) << endl; n++; } if (y_title_err.size() > 0) { y_array_err = g0res->GetArrayF(y_title_err); cerr << g0res->GetArrayName(n) << endl; n++; } // Generate a TGraphErrors ge = new TGraphErrors(nrows, x_array, y_array, x_array_err, y_array_err); ge->SetMarkerStyle(20); string title = x_title+":"+y_title; ge->SetTitle(title.c_str()); // Draw the graph ge->Draw("AP"); return(0); } Int_t main(int argc, char **argv) { // Initialize ROOT TApplication theApp("App", &argc, argv); if (gROOT->IsBatch()) { fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]); return 1; } // Initialize objects h1 = NULL; ge = NULL; c1 = NULL; g0sql = NULL; // Create a new G0SQL object const string host = "hallcl7"; const string db = "gzero-eng"; const string user = "g0"; g0sql = new G0SQL(host,db,user,kTRUE); // Load the database lookup file string myfilename = string(getenv("G0ANALYSIS")) + "/Analysis/prminput/" + "G0DB_lookup.dat.v0.7"; g0sql->LoadLookupTable(myfilename);//why not do this in the c-tor? // Construct query strings string selections = "run_number:a_oct1det10proton:a_oct1det10proton_err"; string cuts = "run_number>15406"; string sql_query = g0sql->Translate(selections,cuts); // Perform query on database g0sql->OpenConnection(); TSQLResult* res = g0sql->Query(sql_query); g0sql->CloseConnection(); // Convert TSQLResult into G0SQLResult G0SQLResult* g0res = g0sql->Process(res); // Always remember to delete TSQLResult when done delete res; res = NULL; // Plot results gStyle->SetOptFit(1111); c1 = new TCanvas("c1","c1",800,600); PlotGraphErrors(g0res, string("run_number"), string("a_oct1det10proton"), string(""), string("a_oct1det10proton_err")); c1->SaveAs("c1.ps"); theApp.Run(); // Clean up delete g0res; g0res = NULL; delete g0sql; g0sql = NULL; delete c1; c1 = NULL; delete h1; h1 = NULL; delete ge; ge = NULL; return 0; }