void TestSQL() { TSQLServer* db = TSQLServer::Connect("sqlite://LearningAnalytics.db", "", ""); printf("Server info: %s\n", db->ServerInfo()); TSQLRow* row; TSQLResult* res; // printf("\nList all databases on server %s\n", db->GetHost()); // res = db->GetDataBases(); // while ((row = res->Next())) { // printf("%s\n", row->GetField(0)); // delete row; // } // delete res; printf("\nList all tables in database \"LearningAnalytics\" on server %s\n", db->GetHost()); res = db->GetTables("LearningAnalytics"); while ((row = res->Next())) { printf("%s\n", row->GetField(0)); delete row; } delete res; }
Int_t getsipm( Char_t *start_datetime, Char_t *end_datetime ) { TSQLServer *serv = TSQLServer::Connect("pgsql://phnxdb1.phenix.bnl.gov/daq", "phnxrc", ""); // Create the sql query TString sql = "SELECT EXTRACT(EPOCH FROM read_datetime)::INT AS read_timestamp,current FROM sipm WHERE read_datetime >= \'"; sql += start_datetime; sql += "\' AND read_datetime < \'"; sql += end_datetime; sql += "\'"; std::cout << "sql query: " << sql << std::endl; TSQLResult *res; res = serv->Query(sql); // Extract the result of the query into vectors Int_t nrows = res->GetRowCount(); Int_t nfields = res->GetFieldCount(); std::cout << "rows: " << nrows << " columns: " << nfields << std::endl; TString fieldname; TString field; TSQLRow *row; // std::vector<double> read_timestamp; // std::vector<double> read_current; for (Int_t i = 0; i < nrows; i++) { row = res->Next(); for (Int_t j = 0; j < nfields; j++) { fieldname = TString( res->GetFieldName(j) ); field = TString( row->GetField(j) ); // std::cout << "fieldname: " << fieldname << " field: " << field << std::endl; if ( fieldname == "read_timestamp" ) read_time_sipm[0].push_back( field.Atof() ); if ( fieldname.Contains( "current" ) ) sipm_current[0].push_back( field.Atof() ); } } return nrows; }
void target() { TSQLResult *res; TSQLRow *row; TSQLServer *db = TSQLServer::Connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD); if ( !db ) {cout << "CONNECTION ERROR\n"; return; } /*** create the histogram ******************************************/ c1 = new TCanvas("c1", "Target"); c1->SetGrid(); c1->SetFillColor(20); THStack * TargetSummary= new THStack("TargetSummary", "Data Taken w.r.t Target"); TH1D * hq= new TH1D("hq", "Quartz", 5, 0, 5); hq->SetFillColor(42); TH1D * hag= new TH1D("hag", "Ag", 5, 0, 5); hag->SetFillColor(50); TH1D * hak= new TH1D("hak", "AK3", 5, 0, 5); hak->SetFillColor(30); // TH1D TargetSummary("Target Summary", "Target Summary", 3, 0, 3); //TargetSummary.Draw(); /*** total data size collected with quartz target ******************/ res = db->Query("select sum(size) " "from Runlog " "where " "target = 'quartz' " "and " "quality = 'y'" ); row = res->Next(); Double_t quartz_size = atof(row->GetField(0)); // *os << "<h3>Quartz</h3>\n" // << "total size written: " << quartz_size/(1024.*1024.*1024.*1024.) << " Tb<br>\n" // << endl; //Convert to Tb quartz_size = quartz_size/(1024.*1024.*1024.*1024.); cout << "Quartz" << endl; cout << "total size written: " << quartz_size << " Tb " << endl; cout << "-----------------------------------------------" << endl; // fill the quartz bin of the histogram with data hq->SetBinContent(2, quartz_size); //TargetSummary.Draw(); delete row; delete res; /*** total data size collected with Ag target **********************/ res = db->Query("select sum(size) " "from Runlog " "where target = 'Ag' " "and " "quality = 'y'" ); row = res->Next(); Double_t Ag_size = atof(row->GetField(0)); //*os << "<h3>Ag</h3>\n" // << "total size written: " << Ag_size/(1024.*1024.*1024.*1024.) << " Tb<br>\n" //<< endl; //Convert to Tb Ag_size = Ag_size/(1024.*1024.*1024.*1024.); cout << "Ag" << endl; cout << "total size written: " << Ag_size/(1024.*1024.*1024.*1024.) << " Tb " << endl; cout << "-----------------------------------------------" << endl; // fill the Ag bin of the histogram with data hag->SetBinContent(3, Ag_size); //TargetSummary.Draw() delete row; delete res; /*** total data size collected with AK3 target **********************/ res = db->Query("select sum(size) " "from Runlog " "where target = 'AK3' " "and " "quality = 'y'" ); row = res->Next(); Double_t AK3_size = atof(row->GetField(0)); // *os << "<h3>AK3</h3>\n" //<< "total size written: " << AK3_size/(1024.*1024.*1024.*1024.) << " Tb<br>\n" //<< endl; //Convert to Tb AK3_size = AK3_size/(1024.*1024.*1024.*1024.); cout << "AK3" << endl; cout << "total size written: " << AK3_size/(1024.*1024.*1024.*1024.) << "Tb " << endl; cout << "-----------------------------------------------" << endl; // fill the AK3 bin of the histogram with data hak->SetBinContent(4, AK3_size); //TargetSummary.Draw() delete row; delete res; /*** Draw the Histogram!*******************************************/ TargetSummary->Add(hq); TargetSummary->Add(hag); TargetSummary->Add(hak); TargetSummary->Draw("nostack"); TargetSummary->GetXaxis()->SetTitle("Target Type"); TargetSummary->GetYaxis()->SetTitle("Tb"); TargetSummary->GetXaxis()->SetBinLabel(2, "Quartz"); TargetSummary->GetXaxis()->SetBinLabel(3, "Ag"); TargetSummary->GetXaxis()->SetBinLabel(4, "AK3"); hq->GetXaxis()->SetTitle("Target Type"); hq->GetYaxis()->SetTitle("Tb"); hq->GetXaxis()->SetBinLabel(2, "Quartz"); hq->GetXaxis()->SetBinLabel(3, "Ag"); hq->GetXaxis()->SetBinLabel(4, "AK3"); hag->GetXaxis()->SetTitle("Target Type"); hag->GetYaxis()->SetTitle("Tb"); hag->GetXaxis()->SetBinLabel(2, "Quartz"); hag->GetXaxis()->SetBinLabel(3, "Ag"); hag->GetXaxis()->SetBinLabel(4, "AK3"); hak->GetXaxis()->SetTitle("Target Type"); hak->GetYaxis()->SetTitle("Tb"); hak->GetXaxis()->SetBinLabel(2, "Quartz"); hak->GetXaxis()->SetBinLabel(3, "Ag"); hak->GetXaxis()->SetBinLabel(4, "AK3"); }
//============================================================= int readDB(string sDate0, string sDate1) { double time; double timebegin=0; double timeend=0; string mthn = "main()"; int inTempId; int nnTemp; int thePad=0; string allDateBegin; string allDateEnd; int maxChars=256; char lineList[maxChars]; ifstream inList; map <int,int> nLines; map <int, TGraph *> tempGraphs; stringstream allDateBefBeg; stringstream allDateAftEnd; stringstream sTemp; stringstream tempTitle; stringstream tempName; inList.open("temp.txt",ifstream::in); inList.seekg(ios::beg) ; inList.getline(lineList,maxChars); inList.getline(lineList,maxChars); nnTemp=atoi(lineList); cout<< "NUMBER OF TEMPERATURES TO READ: "<< nnTemp << endl; inList.getline(lineList,maxChars); QRegExp rTemp("(\\d+)\\s+//\\s+\\w+"); for (int iTemp=0;iTemp<nnTemp; iTemp++){ inList.getline(lineList,maxChars); QString qinList=lineList; if (rTemp.search(lineList)>=0){ int inTempId=rTemp.cap(1).toInt(); // inTempId=atoi(lineList); tempId[iTemp]=inTempId; cout << iTemp << " Temperature ID: "<< tempId[iTemp] << endl; } } allDateBegin=sDate0; allDateEnd=sDate1; inList.close(); inList.clear() ; for (int iTemp=0; iTemp<nnTemp;iTemp++){ inTempId=tempId[iTemp]; sTemp.str(""); sTemp<<"TemperatureID_"<<tempId[iTemp]; cout << sTemp.str()<<endl; tempGraphs[iTemp] = new TGraph(); nLines[iTemp] = 1; } int nTemp=(int)round(nnTemp/2); TCanvas * canvas4 = new TCanvas("canvas4", "c4", 0, 0, 800, 800 ) ; canvas4->Divide(nTemp,2); for (int iTemp=0;iTemp<nnTemp;iTemp++){ if (thePad>nnTemp){ thePad=0; } thePad++; inTempId=tempId[iTemp]; DBReader * dbR = new DBReader(); QRegExp rStringDate("(\\w\\w\\w)\\s+(\\d+)\\s+(\\d+):(\\d+):(\\d+)\\s+(\\d+)"); QString qTime1=allDateBegin; if (rStringDate.search(qTime1)>=0){ double hour=rStringDate.cap(3).toDouble(); double min =rStringDate.cap(4).toDouble(); double sec =rStringDate.cap(5).toDouble(); string month=rStringDate.cap(1); int day =rStringDate.cap(2).toInt(); int year =rStringDate.cap(6).toInt(); timebegin=hour*3600+min*60+sec; hour=hour-1; if (hour<0){ hour=hour+1; min=0; } allDateBefBeg.str(""); allDateBefBeg<<month<<" "<<day<<" "<<hour<<":"<<min<<":"<<sec<<" "<<year; } QString qTime2=allDateEnd; if (rStringDate.search(qTime2)>=0){ double hour=rStringDate.cap(3).toDouble(); double min =rStringDate.cap(4).toDouble(); double sec =rStringDate.cap(5).toDouble(); string month=rStringDate.cap(1); int day =rStringDate.cap(2).toInt(); int year =rStringDate.cap(6).toInt(); timeend=hour*3600+min*60+sec; hour=hour+1; if (hour>=24){ hour=hour-1; min=59; } allDateAftEnd.str(""); allDateAftEnd<<month<<" "<<day<<" "<<hour<<":"<<min<<":"<<sec<<" "<<year; } //======= Searching point before the first datum dbR->makeSelection(inTempId,allDateBefBeg.str(),allDateAftEnd.str()); if( dbR->connectToDB() == 0 ) { return -1; } if( dbR->queryDB() == 0 ) {return -2;} string mthn = "[DBReader::getSelectionResult()]\t" ; TSQLResult * selectionResult = dbR->getSelectionResult(); int nRows = selectionResult->GetRowCount(); cout << mthn << "Found " << nRows << " elements" << endl ; cout << nRows<< endl; pair<string, string> timeTemp ; int controlEnd=0; if (nRows > 0){ TSQLRow* row = NULL; while ((row = selectionResult->Next()) ){ QString qTime=row->GetField(0); if (rStringDate.search(qTime)>=0){ double hour=rStringDate.cap(3).toDouble(); double min =rStringDate.cap(4).toDouble(); double sec =rStringDate.cap(5).toDouble(); time=hour*3600+min*60+sec; timeTemp.first = row->GetField(0); timeTemp.second = row->GetField(1); RTDmap[iTemp].push_back(timeTemp) ; double temperature=strtod(row->GetField(1),NULL); if (time>=timebegin && time<=timeend){ tempGraphs[iTemp]->SetPoint(nLines[iTemp],time,temperature); nLines[iTemp]++; }else if(time<timebegin){ tempGraphs[iTemp]->SetPoint(0,time,temperature); }else if(time>timeend && controlEnd==0){ tempGraphs[iTemp]->SetPoint(nLines[iTemp],time,temperature); controlEnd=1; } if (tempGraphs[iTemp]!=NULL ){ if( tempGraphs[iTemp]->GetXaxis() != NULL ){ tempGraphs[iTemp]->GetXaxis()->SetLabelSize(0.03); tempGraphs[iTemp]->GetXaxis()->SetTimeDisplay(1); tempGraphs[iTemp]->GetXaxis()->SetTimeFormat("%H:%M:%S"); tempGraphs[iTemp]->SetMarkerStyle(20); tempGraphs[iTemp]->SetMarkerSize(0.3); } } canvas4->cd(thePad); tempGraphs[iTemp]->Draw("AP"); tempTitle.str(""); tempName.str(""); tempTitle<<"Temperature ID "<<tempId[iTemp]; tempName<<"Temperature_ID_"<<tempId[iTemp]; } } } else { cout << "There are no entries for your selection!!!" << endl; } tempGraphs[iTemp]->SetTitle(tempTitle.str().c_str()); tempGraphs[iTemp]->SetName(tempName.str().c_str()); tempGraphs[iTemp]->Write(); delete dbR; } canvas4->Modified(); canvas4->Update(); canvas4->Write(); return 0; }
void hinge() { TSQLServer *db = TSQLServer::Connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD); if ( !db ) {cout << "CONNECTION ERROR\n"; return; } // *** open HTML file for output *** // ofstream *os = new ofstream ("../html/runsummary.html"); // ================================================================== // *** Hinge Orientation *** // ================================================================== c1 = new TCanvas("c1", "Hinge Orientation"); c1->SetGrid(); c1->SetFillColor(20); /*** create the histogram ******************************************/ THStack * HingeOrient= new THStack("HingeOrient","Data Taken w.r.t Hinge Orientation"); TH1D * hq = new TH1D("hq", "Quartz", 17, 0, 17); TH1D * hag= new TH1D("hag", "Ag", 17, 0, 17); TH1D * hak= new TH1D("hak", "AK3", 17,0, 17); TH1D * htarget[] = {hq, hag, hak}; htarget[0]->SetFillColor(42); htarget[1]->SetFillColor(50); htarget[2]->SetFillColor(30); /*** extract data size w.r.t hinge orientation collected with each target ***/ TSQLResult *res = db->Query("select target, " "emc_magnet, " "sum(size) " "from Runlog " "where " "quality = 'y'" "group by target, " "emc_magnet" ); const int nrows = res->GetRowCount(); hquery * hdata [nrows]; for ( int i=0; i<nrows; i++ ) { TSQLRow *row = res->Next(); hdata[i] = new hquery; hdata[i]->SetTarget(row->GetField(0)); hdata[i]->SetHinge(row->GetField(1)); hdata[i]->SetSize(atof(row->GetField(2))/(1024.*1024.*1024.*1024.)); cout << "i = " << i << endl; cout << "target is: " << hdata[i]->GetTarget() << endl; cout << "hinge is oriented: " << hdata[i]->GetHinge() << endl; cout << "total size written: " << hdata[i]->GetSize() << " Tb" << endl; cout << "-----------------------------------------------" << endl; delete row; } /*** fill the histogram with data **********************************/ string tbin[3] = {"uartz", "g", "3"}; string hbin[5] = {"own", "eft", "ight", "p", "one"}; size_t tfound; size_t hfound; for ( int i=0; i<nrows; i ++) { for (int j=0; j<3; j++) { for (int k=0; k<5; k++) { tfound=hdata[i]->GetTarget().find(tbin[j]); hfound=hdata[i]->GetHinge().find(hbin[k]); if (tfound!=string::npos && hfound!=string::npos) { cout << "data found" << endl; if (k==0) htarget[j]->SetBinContent(j+2, hdata[i]->GetSize()); else if (k==1 || k==4) htarget[j]->SetBinContent(j+6, hdata[i]->GetSize()); else if (k==2) htarget[j]->SetBinContent(j+10, hdata[i]->GetSize()); else if (k==3) htarget[j]->SetBinContent(j+14, hdata[i]->GetSize()); else cout << "error assigning data to bin\n"; } } } } delete res; delete hdata; /*** Draw the Histogram!*******************************************/ for (int i=0; i<3; i++) HingeOrient->Add(htarget[i]); Double_t fmax; fmax = HingeOrient->GetMaximum(); cout << fmax << endl; cout << fmax*13./12. << endl; TH1D * pretty = new TH1D("pretty", "pretty", 17, 0, 17); pretty->SetFillColor(28); pretty->SetLineColor(20); pretty->SetFillStyle(3018); for (int i=1; i<18; i+= 4) pretty->SetBinContent(i, fmax*13./12.); HingeOrient->Add(pretty); HingeOrient->Draw("nostack"); HingeOrient->GetXaxis()->SetTitle("Hinge Orientation"); HingeOrient->GetYaxis()->SetTitle("Tb"); HingeOrient->GetXaxis()->SetBinLabel(1, " "); HingeOrient->GetXaxis()->SetBinLabel(2, " "); //Q D HingeOrient->GetXaxis()->SetBinLabel(3, "Down"); //Ag D HingeOrient->GetXaxis()->SetBinLabel(4, " "); //AK D HingeOrient->GetXaxis()->SetBinLabel(5, " "); HingeOrient->GetXaxis()->SetBinLabel(6, " "); //Q L HingeOrient->GetXaxis()->SetBinLabel(7, "Left"); //Ag L HingeOrient->GetXaxis()->SetBinLabel(8, " "); //AK L HingeOrient->GetXaxis()->SetBinLabel(9, " "); HingeOrient->GetXaxis()->SetBinLabel(10, " "); //Q R HingeOrient->GetXaxis()->SetBinLabel(11, "Right"); //Ag R HingeOrient->GetXaxis()->SetBinLabel(12, " "); //AK R HingeOrient->GetXaxis()->SetBinLabel(13, " "); HingeOrient->GetXaxis()->SetBinLabel(14, " "); //Q U HingeOrient->GetXaxis()->SetBinLabel(15, "Up"); //Ag U HingeOrient->GetXaxis()->SetBinLabel(16, " "); //AK U HingeOrient->GetXaxis()->SetBinLabel(17, " "); hq->GetXaxis()->SetTitle("Hinge Orientation"); hq->GetYaxis()->SetTitle("Tb"); hq->GetXaxis()->SetBinLabel(1, " "); hq->GetXaxis()->SetBinLabel(2, " "); //Q D hq->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hq->GetXaxis()->SetBinLabel(4, " "); //AK D hq->GetXaxis()->SetBinLabel(5, " "); hq->GetXaxis()->SetBinLabel(6, " "); //Q L hq->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hq->GetXaxis()->SetBinLabel(8, " "); //AK L hq->GetXaxis()->SetBinLabel(9, " "); hq->GetXaxis()->SetBinLabel(10, " "); //Q R hq->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hq->GetXaxis()->SetBinLabel(12, " "); //AK R hq->GetXaxis()->SetBinLabel(13, " "); hq->GetXaxis()->SetBinLabel(14, " "); //Q U hq->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hq->GetXaxis()->SetBinLabel(16, " "); //AK U hq->GetXaxis()->SetBinLabel(17, " "); hag->GetXaxis()->SetTitle("Hinge Orientation"); hag->GetYaxis()->SetTitle("Tb"); hag->GetXaxis()->SetBinLabel(1, " "); hag->GetXaxis()->SetBinLabel(2, " "); //Q D hag->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hag->GetXaxis()->SetBinLabel(4, " "); //AK D hag->GetXaxis()->SetBinLabel(5, " "); hag->GetXaxis()->SetBinLabel(6, " "); //Q L hag->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hag->GetXaxis()->SetBinLabel(8, " "); //AK L hag->GetXaxis()->SetBinLabel(9, " "); hag->GetXaxis()->SetBinLabel(10, " "); //Q R hag->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hag->GetXaxis()->SetBinLabel(12, " "); //AK R hag->GetXaxis()->SetBinLabel(13, " "); hag->GetXaxis()->SetBinLabel(14, " "); //Q U hag->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hag->GetXaxis()->SetBinLabel(16, " "); //AK U hag->GetXaxis()->SetBinLabel(17, " "); hak->GetXaxis()->SetTitle("Hinge Orientation"); hak->GetYaxis()->SetTitle("Tb"); hak->GetXaxis()->SetBinLabel(1, " "); hak->GetXaxis()->SetBinLabel(2, " "); //Q D hak->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hak->GetXaxis()->SetBinLabel(4, " "); //AK D hak->GetXaxis()->SetBinLabel(5, " "); hak->GetXaxis()->SetBinLabel(6, " "); //Q L hak->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hak->GetXaxis()->SetBinLabel(8, " "); //AK L hak->GetXaxis()->SetBinLabel(9, " "); hak->GetXaxis()->SetBinLabel(10, " "); //Q R hak->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hak->GetXaxis()->SetBinLabel(12, " "); //AK R hak->GetXaxis()->SetBinLabel(13, " "); hak->GetXaxis()->SetBinLabel(14, " "); //Q U hak->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hak->GetXaxis()->SetBinLabel(16, " "); //AK U hak->GetXaxis()->SetBinLabel(17, " "); for (int i=0; i<3; i++) htarget[i]->SetAxisRange(0, fmax*13./12., "Y"); pretty->SetAxisRange(0, fmax*13./12., "Y"); HingeOrient->SetMaximum(fmax*13./12.); legend = new TLegend(0.67,0.72,0.88,0.89); legend->AddEntry(hq, "Quartz", "f"); legend->AddEntry(hag, "Ag", "f"); legend->AddEntry(hak, "AK3", "f"); legend->SetHeader("Target"); legend->Draw(); }
void histo_plot(void) { // Store constants for connecting to database (fill in blanks as // appropriate) const Char_t *dbusername = "******"; // username for DB access const Char_t *dbpasswd = "parity"; // password for DB access const Char_t *dbname = "pandb"; // name of DB const Char_t *dbhostname = "alquds.jlab.org"; // hostname of DB server computer // Connect to MySQL server Char_t *dburl = new Char_t[50]; sprintf(dburl,"mysql://%s/%s", dbhostname, dbname); TSQLServer *db = TSQLServer::Connect(dburl, dbusername, dbpasswd); delete []dburl; dburl=NULL; // Get name of dbtablename Char_t * dbtablename= new Char_t[50]; const Char_t *inputtable = "Please enter desired table: "; cout << inputtable; cin.getline(dbtablename, 49); cout << dbtablename << endl; // Get name of column to plot Char_t *column = new Char_t[50]; const Char_t *inputcolumn = "Please enter desired column: "; cout << inputcolumn; cin.getline(column, 49); cout << column << endl; // Construct query Char_t *sql = new Char_t[4200]; sprintf(sql, "SELECT %s FROM %s", column, dbtablename); cout << sql << endl; // start timer TStopwatch timer; timer.Start(); // Submit query to server TSQLRow *row; TSQLResult *res; res = db->Query(sql); // Process results Int_t nrows = res->GetRowCount(); cout << "Got " << nrows << " rows in result." << endl; Int_t nfields = res->GetFieldCount(); cout << "Got " << nfields << " fields in result." << endl; if (nfields != 1) { cerr << "Select only one column to average over!" << endl; exit; } // Get histogram ranges Char_t *lowrangechar = new Char_t[10]; const Char_t *lowrangemessage = "Please enter lower limit of " "the histogram range: "; cout << lowrangemessage; cin.getline(lowrangechar, 9); Float_t lowrangefloat = atof(lowrangechar); Char_t *highrangechar = new Char_t[10]; const Char_t *highrangemessage = "Please enter upper limit of " "the histogram range: "; cout << highrangemessage; cin.getline(highrangechar, 9); Float_t highrangefloat = atof(highrangechar); // Create histogram TH1F *histo = new TH1F("histo", column, 50, lowrangefloat, highrangefloat); // Fill histogram for (Int_t i = 0; i<nrows; i++) { row = res->Next(); Float_t field = atof(row->GetField(0)); delete row; histo->Fill(field); } histo->Draw(); // stop timer and print results timer.Stop(); Double_t rtime = timer.RealTime(); Double_t ctime = timer.CpuTime(); printf("\nRealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime); // Clean up delete []sql; delete []dbtablename; delete []column; delete []lowrangechar; delete []highrangechar; delete res; delete db; }
void magnetorient() { /*** connect to MySQL online Runlog database ***********************/ TSQLServer *db = TSQLServer::Connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD); if ( !db ) {cout << "CONNECTION ERROR\n"; return; } /*** create canvas, stack of histograms and histograms *************/ //create canvas c1 = new TCanvas("c1", "Magnet Orientation"); //create gridlines c1->SetGrid(); //color the canvas c1->SetFillColor(20); //create a pointer to a stack of histograms /* An individual histogram can only be one color. A stack of histograms was used so that the final result would look like one histogram which was color coded. */ THStack * Magnet= new THStack("MagnetOrient","Data Taken w.r.t Magnet Orientation"); /*create pointer to histogram pretty which will be used for purely aesetic reasons. (It will separate the down, left, right, and up data.)*/ TH1D * pretty = new TH1D("pretty", "pretty", 17, 0, 17); //set the fill color, line color and pattern of the bars in pretty pretty->SetFillColor(28); pretty->SetLineColor(20); pretty->SetFillStyle(3018); /*create a histogram for each target that the data was taken on: Quartz, Silver, and AK3. Set a different fill color for each histogram*/ TH1D * hq = new TH1D("hq", "Quartz", 17, 0, 17); hq->SetFillColor(42); TH1D * hag= new TH1D("hag", "Ag", 17, 0, 17); hag->SetFillColor(50); TH1D * hak= new TH1D("hak", "AK3", 17, 0, 17); hak->SetFillColor(30); //create an array of the histogram pointers. //This will make filling the histograms with data easier TH1D * htarget[] = {hq, hag, hak}; /*** extract information from MySQL online Runlog database *********/ // extract data size w.r.t hinge orientation collected with each target /*Query MySQL. MySQL will return 3 columns: target, target_magnet, sum(size). MySQL calculates the total amount of data that was taken on each target with different orientations of the magnet and lists this value in the column sum(size).*/ TSQLResult *res = db->Query("select target, " "target_magnet, " "sum(size) " "from Runlog " "where " "quality = 'y'" "and (target = 'quartz' " "or target = 'ag' " "or target = 'ak3') " "group by target, " "target_magnet" ); //how many rows did the query return? const int nrows = res->GetRowCount(); //create an array of pointers called mdata that is of class mquery and is //big enough to point to enough space for all of the data from the query mquery * mdata [nrows]; // mquery * mdata = new mquery[nrows]; //store the data to the locations just created using functions defined //in the mquery class and other fancy root-SQL commands for ( int i=0; i<nrows; i++ ) { TSQLRow *row = res->Next(); mdata[i] = new mquery; mdata[i]->SetTarget(row->GetField(0)); mdata[i]->SetMagnet(row->GetField(1)); mdata[i]->SetSize(atof(row->GetField(2))/(1024.*1024.*1024.*1024.)); //print the data to the screen using fuctions defined in the //mquery class cout << "i = " << i << endl; cout << "target is: " << mdata[i]->GetTarget() << endl; cout << "magnet is oriented: " << mdata[i]->GetMagnet() << endl; cout << "total size written: " << mdata[i]->GetSize() << " Tb" << endl; cout << "-----------------------------------------------" << endl; delete row; } delete res; db->Close(); /*** fill the histogram with data **********************************/ /*Use the string find function to figure out which histogram and bin each data piece should be assigned to */ /*tbin is the string used to figure out what target the data was taken on and mbin used to determine the orientation of the magnet. The first letters of the targets or magnet orientations are left out because I wanted to avoid any problems with case sensitivity. */ string tbin[3] = {"uartz", "g", "3"}; string mbin[4] = {"own", "eft", "ight", "p"}; size_t tfound; size_t mfound; Double_t fdata [17]; int counter = 0; for (i=0; i<17; i++) fdata[i] = 0.; for ( int i=0; i<nrows; i++) { for (int j=0; j<3; j++) { for (int k=0; k<4; k++) { tfound=mdata[i]->GetTarget().find(tbin[j]); mfound=mdata[i]->GetMagnet().find(mbin[k]); //(t/h)found will equal npos if it does not find the string it //was searching for //if the data was found then it is assigned to the appropriate //histogram and bin if (tfound!=string::npos && mfound!=string::npos) { cout << "data found" << endl; if (k==0) htarget[j]->SetBinContent(j+2, mdata[i]->GetSize()); else if (k==1) htarget[j]->SetBinContent(j+6, mdata[i]->GetSize()); else if (k==2) htarget[j]->SetBinContent(j+10, mdata[i]->GetSize()); else if (k==3) htarget[j]->SetBinContent(j+14, mdata[i]->GetSize()); else cout << "error assigning data to bin\n"; fdata[counter] = mdata[i]->GetSize(); counter++; } } } } //delete hdata; /*** Draw the Histogram!*******************************************/ //find the maximum data size value to set the Y axis of the final //histogram appropriately and to fill the "pretty histogram" int ftotal = sizeof(fdata)/sizeof(Double_t); Double_t fmax = Max(fdata, ftotal); cout << "fdata:" << i << ": " << fdata[i] << endl; for (i=0; i<nrows; i++) cout << "hdata:" << i << ": " << mdata[i]->GetSize() << endl; cout << fmax << endl; cout << fmax*13./12. << endl; Magnet->SetMaximum(fmax*13./12.); for (int i=1; i<18; i+= 4) pretty->SetBinContent(i, fmax*13./12.); pretty->SetAxisRange(0, fmax*13./12., "Y"); Magnet->Add(pretty); for (int i=0; i<3; i++) Magnet->Add(htarget[i]); for (int i=0; i<3; i++) htarget[i]->SetAxisRange(0, fmax*13./12., "Y"); /*Double_t fmax; fmax = HingeOrient->GetMaximum(); */ Magnet->Draw("nostack"); Magnet->GetXaxis()->SetTitle("Magnet Orientation"); Magnet->GetYaxis()->SetTitle("Tb"); Magnet->GetXaxis()->SetBinLabel(1, " "); Magnet->GetXaxis()->SetBinLabel(2, " "); //Q D Magnet->GetXaxis()->SetBinLabel(3, "Down"); //Ag D Magnet->GetXaxis()->SetBinLabel(4, " "); //AK D Magnet->GetXaxis()->SetBinLabel(5, " "); Magnet->GetXaxis()->SetBinLabel(6, " "); //Q L Magnet->GetXaxis()->SetBinLabel(7, "Left"); //Ag L Magnet->GetXaxis()->SetBinLabel(8, " "); //AK L Magnet->GetXaxis()->SetBinLabel(9, " "); Magnet->GetXaxis()->SetBinLabel(10, " "); //Q R Magnet->GetXaxis()->SetBinLabel(11, "Right"); //Ag R Magnet->GetXaxis()->SetBinLabel(12, " "); //AK R Magnet->GetXaxis()->SetBinLabel(13, " "); Magnet->GetXaxis()->SetBinLabel(14, " "); //Q U Magnet->GetXaxis()->SetBinLabel(15, "Up"); //Ag U Magnet->GetXaxis()->SetBinLabel(16, " "); //AK U Magnet->GetXaxis()->SetBinLabel(17, " "); hq->GetXaxis()->SetTitle("Magnet Orientation"); hq->GetYaxis()->SetTitle("Tb"); hq->GetXaxis()->SetBinLabel(1, " "); hq->GetXaxis()->SetBinLabel(2, " "); //Q D hq->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hq->GetXaxis()->SetBinLabel(4, " "); //AK D hq->GetXaxis()->SetBinLabel(5, " "); hq->GetXaxis()->SetBinLabel(6, " "); //Q L hq->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hq->GetXaxis()->SetBinLabel(8, " "); //AK L hq->GetXaxis()->SetBinLabel(9, " "); hq->GetXaxis()->SetBinLabel(10, " "); //Q R hq->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hq->GetXaxis()->SetBinLabel(12, " "); //AK R hq->GetXaxis()->SetBinLabel(13, " "); hq->GetXaxis()->SetBinLabel(14, " "); //Q U hq->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hq->GetXaxis()->SetBinLabel(16, " "); //AK U hq->GetXaxis()->SetBinLabel(17, " "); hag->GetXaxis()->SetTitle("Magnet Orientation"); hag->GetYaxis()->SetTitle("Tb"); hag->GetXaxis()->SetBinLabel(1, " "); hag->GetXaxis()->SetBinLabel(2, " "); //Q D hag->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hag->GetXaxis()->SetBinLabel(4, " "); //AK D hag->GetXaxis()->SetBinLabel(5, " "); hag->GetXaxis()->SetBinLabel(6, " "); //Q L hag->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hag->GetXaxis()->SetBinLabel(8, " "); //AK L hag->GetXaxis()->SetBinLabel(9, " "); hag->GetXaxis()->SetBinLabel(10, " "); //Q R hag->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hag->GetXaxis()->SetBinLabel(12, " "); //AK R hag->GetXaxis()->SetBinLabel(13, " "); hag->GetXaxis()->SetBinLabel(14, " "); //Q U hag->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hag->GetXaxis()->SetBinLabel(16, " "); //AK U hag->GetXaxis()->SetBinLabel(17, " "); hak->GetXaxis()->SetTitle("Magnet Orientation"); hak->GetYaxis()->SetTitle("Tb"); hak->GetXaxis()->SetBinLabel(1, " "); hak->GetXaxis()->SetBinLabel(2, " "); //Q D hak->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hak->GetXaxis()->SetBinLabel(4, " "); //AK D hak->GetXaxis()->SetBinLabel(5, " "); hak->GetXaxis()->SetBinLabel(6, " "); //Q L hak->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hak->GetXaxis()->SetBinLabel(8, " "); //AK L hak->GetXaxis()->SetBinLabel(9, " "); hak->GetXaxis()->SetBinLabel(10, " "); //Q R hak->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hak->GetXaxis()->SetBinLabel(12, " "); //AK R hak->GetXaxis()->SetBinLabel(13, " "); hak->GetXaxis()->SetBinLabel(14, " "); //Q U hak->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hak->GetXaxis()->SetBinLabel(16, " "); //AK U hak->GetXaxis()->SetBinLabel(17, " "); legend = new TLegend(0.67,0.72,0.88,0.89); legend->SetFillColor(10); legend->AddEntry(hq, "Quartz", "f"); legend->AddEntry(hag, "Ag", "f"); legend->AddEntry(hak, "AK3", "f"); legend->SetHeader("Target"); legend->Draw(); delete mdata; }
void hingeABM() { /*** connect to MySQL online Runlog database ***********************/ TSQLServer *db = TSQLServer::Connect(MYSQL_SERVER,MYSQL_USER,MYSQL_PASSWD); if ( !db ) {cout << "CONNECTION ERROR\n"; return; } /*** create canvas, stack of histograms and histograms *************/ //create canvas c1 = new TCanvas("c1", "Hinge Orientation"); //create gridlines c1->SetGrid(); //color the canvas c1->SetFillColor(20); //create a pointer to a stack of histograms /* An individual histogram can only be one color. A stack of histograms was used so that the final result would look like one histogram which was color coded. */ THStack * HingeOrient= new THStack("HingeOrient","Data Taken w.r.t Hinge Orientation (target and magnet aligned & centered)"); /*create pointer to histogram pretty which will be used for purely aesetic reasons. (It will separate the down, left, right, and up data.)*/ TH1D * pretty = new TH1D("pretty", "pretty", 17, 0, 17); //set the fill color, line color and pattern of the bars in pretty pretty->SetFillColor(28); pretty->SetLineColor(20); pretty->SetFillStyle(3018); /*create a histogram for each target that the data was taken on: Quartz, Silver, and AK3. Set a different fill color for each histogram*/ TH1D * hq = new TH1D("hq", "Quartz", 17, 0, 17); hq->SetFillColor(42); TH1D * hag= new TH1D("hag", "Ag", 17, 0, 17); hag->SetFillColor(50); TH1D * hak= new TH1D("hak", "AK3", 17, 0, 17); hak->SetFillColor(30); //create an array of the histogram pointers. //This will make filling the histograms with data easier TH1D * htarget[] = {hq, hag, hak}; /*** extract information from MySQL online Runlog database *********/ // extract data size w.r.t hinge orientation collected with each target /*Query MySQL. MySQL will return 3 columns: target, emc_magnet, sum(size). Mid-Summer it was decided that the field emc_magnet would actually be used for the position of the hinge/flapper. Before this decision the field contained entries that all read "none". During this time when the field reads "none" the flapper was positioned "left". MySQL calculates the total amount of data that was taken on each target with different orientations of the flapper and lists this value in the column sum(size).*/ TSQLResult *res = db->Query("select target, " "emc_magnet, " "sum(N*tau*0.451*0.776/20.0/1e9*nsegments/nevents_analyzed) " "from Runlog as r " "left join RunInfo using (run) " "left join RunScalers using (run) " "where " "tau between 1900 and 2400 " "and quality='Y' " "and time>10 and starttime >0 and stoptime >0 and r.run>64204 " "and N is not null " "and nevents_analyzed>0 " "and nsegments is not null " "group by target, " "emc_magnet " ); //how many rows did the query return? const int nrows = res->GetRowCount(); //create an array of pointers called hdata that is of class hquery and is //big enough to point to enough space for all of the data from the query hquery * hdata [nrows]; //store the data to the locations just created using functions defined //in the hquery class and other fancy root-SQL commands for ( int i=0; i<nrows; i++ ) { TSQLRow *row = res->Next(); hdata[i] = new hquery; hdata[i]->SetTarget(row->GetField(0)); hdata[i]->SetHinge(row->GetField(1)); hdata[i]->SetSize(atof(row->GetField(2))); //print the data to the screen using fuctions defined in the //hquery class cout << "i = " << i << endl; cout << "target is: " << hdata[i]->GetTarget() << endl; cout << "hinge is oriented: " << hdata[i]->GetHinge() << endl; cout << "total muons collected: " << hdata[i]->GetSize() << endl; cout << "-----------------------------------------------" << endl; delete row; } delete res; db->Close(); /*** fill the histogram with data **********************************/ /*Use the string find function to figure out which histogram and bin each data piece should be assigned to */ /*tbin is the string used to figure out what target the data was taken on and hbin used to determine the orientation of the hinge. The first letters of the targets or hinge orientations are left out because I wanted to avoid any problems with case sensitivity. */ string tbin[3] = {"uartz", "g", "3"}; string hbin[5] = {"own", "eft", "ight", "p", "one"}; size_t tfound; size_t hfound; Double_t ldata[3]= {0., 0., 0.}; Double_t odata[14]; int counter = 0; for (i=0; i<14; i++) odata[i] = 0.; for ( int i=0; i<nrows; i ++) { for (int j=0; j<3; j++) { for (int k=0; k<5; k++) { tfound=hdata[i]->GetTarget().find(tbin[j]); hfound=hdata[i]->GetHinge().find(hbin[k]); //(t/h)found will equal npos if it does not find the string it //was searching for //if the data was found then it is assigned to the appropriate //histogram and bin if (tfound!=string::npos && hfound!=string::npos) { cout << "data found" << endl; if (k==0) htarget[j]->SetBinContent(j+2, hdata[i]->GetSize()); /*(the following else if accounts for the fact that the hinge position records marked as "none" should be considered "left")*/ else if (k==1 || k==4){ htarget[j]->Fill(j+5.5, hdata[i]->GetSize()); ldata[j] = ldata[j] + hdata[i]->GetSize(); } else if (k==2) htarget[j]->SetBinContent(j+10, hdata[i]->GetSize()); else if (k==3) htarget[j]->SetBinContent(j+14, hdata[i]->GetSize()); else cout << "error assigning data to bin\n"; //the following lines are used in preparation for setting the // Y axis of the final histogram and filling pretty's bins if (k!=1 && k!=4){ if (counter<14); odata[counter] = hdata[i]->GetSize(); counter++; } } } } } /*** Draw the Histogram!*******************************************/ //find the maximum data size value to set the Y axis of the final //histogram appropriately and to fill the "pretty histogram" Double_t fdata [17]; for (i=0; i<3; i++) fdata[i] = ldata[i]; for (i=0; i<14; i++) fdata[i+3] = odata[i]; int ftotal = sizeof(fdata)/sizeof(Double_t); Double_t fmax = Max(fdata, ftotal); for (i=0; i<3; i++) cout << "ldata:" << i << ": " << ldata[i] << endl; for (i=0; i<14; i++) cout << "odata:" << i << ": " << odata[i] << endl; for (i=0; i<17; i++) cout << "fdata:" << i << ": " << fdata[i] << endl; for (i=0; i<nrows; i++) cout << "hdata:" << i << ": " << hdata[i]->GetSize() << endl; cout << fmax << endl; cout << fmax*13./12. << endl; HingeOrient->SetMaximum(fmax*13./12.); for (int i=1; i<18; i+= 4) pretty->SetBinContent(i, fmax*13./12.); pretty->SetAxisRange(0, fmax*13./12., "Y"); HingeOrient->Add(pretty); for (int i=0; i<3; i++) HingeOrient->Add(htarget[i]); for (int i=0; i<3; i++) htarget[i]->SetAxisRange(0, fmax*13./12., "Y"); /*Double_t fmax; fmax = HingeOrient->GetMaximum(); */ HingeOrient->Draw("nostack"); HingeOrient->GetXaxis()->SetTitle("Hinge Orientation"); HingeOrient->GetYaxis()->SetTitle("muons"); HingeOrient->GetXaxis()->SetBinLabel(1, " "); HingeOrient->GetXaxis()->SetBinLabel(2, " "); //Q D HingeOrient->GetXaxis()->SetBinLabel(3, "Down"); //Ag D HingeOrient->GetXaxis()->SetBinLabel(4, " "); //AK D HingeOrient->GetXaxis()->SetBinLabel(5, " "); HingeOrient->GetXaxis()->SetBinLabel(6, " "); //Q L HingeOrient->GetXaxis()->SetBinLabel(7, "Left"); //Ag L HingeOrient->GetXaxis()->SetBinLabel(8, " "); //AK L HingeOrient->GetXaxis()->SetBinLabel(9, " "); HingeOrient->GetXaxis()->SetBinLabel(10, " "); //Q R HingeOrient->GetXaxis()->SetBinLabel(11, "Right"); //Ag R HingeOrient->GetXaxis()->SetBinLabel(12, " "); //AK R HingeOrient->GetXaxis()->SetBinLabel(13, " "); HingeOrient->GetXaxis()->SetBinLabel(14, " "); //Q U HingeOrient->GetXaxis()->SetBinLabel(15, "Up"); //Ag U HingeOrient->GetXaxis()->SetBinLabel(16, " "); //AK U HingeOrient->GetXaxis()->SetBinLabel(17, " "); hq->GetXaxis()->SetTitle("Hinge Orientation"); hq->GetYaxis()->SetTitle("muons"); hq->GetXaxis()->SetBinLabel(1, " "); hq->GetXaxis()->SetBinLabel(2, " "); //Q D hq->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hq->GetXaxis()->SetBinLabel(4, " "); //AK D hq->GetXaxis()->SetBinLabel(5, " "); hq->GetXaxis()->SetBinLabel(6, " "); //Q L hq->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hq->GetXaxis()->SetBinLabel(8, " "); //AK L hq->GetXaxis()->SetBinLabel(9, " "); hq->GetXaxis()->SetBinLabel(10, " "); //Q R hq->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hq->GetXaxis()->SetBinLabel(12, " "); //AK R hq->GetXaxis()->SetBinLabel(13, " "); hq->GetXaxis()->SetBinLabel(14, " "); //Q U hq->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hq->GetXaxis()->SetBinLabel(16, " "); //AK U hq->GetXaxis()->SetBinLabel(17, " "); hag->GetXaxis()->SetTitle("Hinge Orientation"); hag->GetYaxis()->SetTitle("muons"); hag->GetXaxis()->SetBinLabel(1, " "); hag->GetXaxis()->SetBinLabel(2, " "); //Q D hag->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hag->GetXaxis()->SetBinLabel(4, " "); //AK D hag->GetXaxis()->SetBinLabel(5, " "); hag->GetXaxis()->SetBinLabel(6, " "); //Q L hag->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hag->GetXaxis()->SetBinLabel(8, " "); //AK L hag->GetXaxis()->SetBinLabel(9, " "); hag->GetXaxis()->SetBinLabel(10, " "); //Q R hag->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hag->GetXaxis()->SetBinLabel(12, " "); //AK R hag->GetXaxis()->SetBinLabel(13, " "); hag->GetXaxis()->SetBinLabel(14, " "); //Q U hag->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hag->GetXaxis()->SetBinLabel(16, " "); //AK U hag->GetXaxis()->SetBinLabel(17, " "); hak->GetXaxis()->SetTitle("Hinge Orientation"); hak->GetYaxis()->SetTitle("muons"); hak->GetXaxis()->SetBinLabel(1, " "); hak->GetXaxis()->SetBinLabel(2, " "); //Q D hak->GetXaxis()->SetBinLabel(3, "Down"); //Ag D hak->GetXaxis()->SetBinLabel(4, " "); //AK D hak->GetXaxis()->SetBinLabel(5, " "); hak->GetXaxis()->SetBinLabel(6, " "); //Q L hak->GetXaxis()->SetBinLabel(7, "Left"); //Ag L hak->GetXaxis()->SetBinLabel(8, " "); //AK L hak->GetXaxis()->SetBinLabel(9, " "); hak->GetXaxis()->SetBinLabel(10, " "); //Q R hak->GetXaxis()->SetBinLabel(11, "Right"); //Ag R hak->GetXaxis()->SetBinLabel(12, " "); //AK R hak->GetXaxis()->SetBinLabel(13, " "); hak->GetXaxis()->SetBinLabel(14, " "); //Q U hak->GetXaxis()->SetBinLabel(15, "Up"); //Ag U hak->GetXaxis()->SetBinLabel(16, " "); //AK U hak->GetXaxis()->SetBinLabel(17, " "); legend = new TLegend(0.77,0.72,0.88,0.89); legend->SetFillColor(10); legend->AddEntry(hq, "Quartz", "f"); legend->AddEntry(hag, "Ag", "f"); legend->AddEntry(hak, "AK3", "f"); legend->SetHeader("Target"); legend->Draw(); delete hdata; }
Int_t getscaler( Int_t scalervector, Int_t scalerchannel, Char_t *start_datetime, Char_t *end_datetime ) { TSQLServer *serv = TSQLServer::Connect("mysql://phnxdb1.phenix.bnl.gov/scalers", "phoncs", "phenix7815"); // Create the sql query Int_t which_table, which_rate; which_table = (scalerchannel/16) + 1; which_rate = ( scalerchannel%16 ) + 1; TString scaler_field_name = "rate"; scaler_field_name += which_rate; TString columns = "UNIX_TIMESTAMP(rs.read_datetime) AS read_timestamp,rs."; columns += scaler_field_name; columns += ", (@csum:=@csum+60.0*rs."; columns += scaler_field_name; columns += ") as cum"; TString sql = "SELECT "; sql += columns; sql += " FROM rhicscaler"; sql += which_table; sql += " AS rs WHERE"; sql += " rs.read_datetime>=\""; sql += start_datetime; sql += "\" AND rs.read_datetime<=\""; sql += end_datetime; sql += "\";"; cout << "sql query: " << sql << endl; TSQLResult *res; res = serv->Query("SET @csum=0.0;"); res = serv->Query(sql); // Extract the result of the query into vectors Int_t nrows = res->GetRowCount(); Int_t nfields = res->GetFieldCount(); cout << "rows: " << nrows << " columns: " << nfields << endl; TString fieldname; TString field; TSQLRow *row; Double_t read_timestamp; Double_t cum; Double_t running_sum = 0.0; Double_t summand = 0.0; sread_time[scalervector].clear(); cum_scaler_db[scalervector].clear(); cum_scaler_sum[scalervector].clear(); for (Int_t i = 0; i < nrows; i++) { row = res->Next(); for (Int_t j = 0; j < nfields; j++) { fieldname = TString( res->GetFieldName(j) ); field = TString( row->GetField(j) ); // Extract all columns of each row // std::cout << "fieldname: " << fieldname << " field: " << field << std::endl; if ( fieldname == "read_timestamp" ) read_timestamp = field.Atof(); if ( fieldname == "cum" ) cum = field.Atof(); if ( fieldname == scaler_field_name ) summand = field.Atof(); } // Save all the columns in this row in vectors for plotting sread_time[scalervector].push_back(read_timestamp); cum_scaler_db[scalervector].push_back(cum); running_sum += 60.0*summand; cum_scaler_sum[scalervector].push_back(running_sum); } return nrows; }
Int_t getradmon( Char_t *start_datetime, Char_t *end_datetime ) { TSQLServer *serv = TSQLServer::Connect("pgsql://phnxdb0.phenix.bnl.gov/daq", "phnxrc", ""); // Create the sql query TString columns = "id, EXTRACT(EPOCH FROM read_datetime)::INT AS read_timestamp, channel, i_n_set, i_n, v_n, i_k_set, i_k, v_k, i_s_set, i_s, v_s, i_r_set, i_r, v_r"; TString sql = "SELECT "; sql += columns; sql += " FROM radmon WHERE read_datetime>=\'"; sql += start_datetime; sql += "\' AND read_datetime<=\'"; sql += end_datetime; sql += "\'"; sql += " AND ABS( (i_r/i_r_set) - 1.0 ) < 0.01"; sql += " AND ABS( (i_s/i_s_set) - 1.0 ) < 0.01"; sql += " AND ABS( (i_n/i_n_set) - 1.0 ) < 0.01"; sql += " AND v_n > 0.4 AND v_n < 2.0"; // key sql += " AND v_r < 20.0 AND v_s < 20.0"; // sql += " AND v_r < 50.0 AND v_s < 50.0"; sql += ";"; cout << "sql query: " << sql << endl; TSQLResult *res; res = serv->Query(sql); // Extract the result of the query into vectors Int_t nrows = res->GetRowCount(); Int_t nfields = res->GetFieldCount(); cout << "rows: " << nrows << " columns: " << nfields << endl; TString fieldname; TString field; TSQLRow *row; Int_t channel = 0; Double_t read_timestamp; Double_t v_k = 0.0, v_n = 0.0, v_s = 0.0, v_r = 0.0; Double_t i_k = 0.0, i_n = 0.0, i_s = 0.0, i_r = 0.0; // zero point and temperature correction for radfet // Run 14 after 373780 May 28, 2014 // Double_t a0[nsensor] = { 3.923, 7.513, 5.395, 6.038, 4.140, 3.306, 3.263 }; // Beginning of Run 15 Jan 14, 2015 // Double_t a0[nsensor] = { 3.971, 7.871, 5.645, 7.566, 3.322, 3.108, 3.214 }; // after adding CAN 1 and CAN 2 2015.04.15 // Double_t a0[nsensor] = { 3.971, 7.871, 5.645, 7.566, 3.322, 3.108, 3.214, 3.274, 3.643 }; Double_t a0[nsensor] = { 3.36, 3.36, 3.36, 3.36, 3.36, 3.36, 3.36, 3.36, 3.36 }; // Here's at the beginning of Run 14 in January // Double_t a0[nsensor] = { 3.78, 6.74, 4.94, 3.40, 3.45, 3.306, 3.263 }; // zero point correction for Si detector // Run 14 after 373780 May 28, 2014 // Double_t s0[nsensor] = { 4.290, 7.220, 6.250, 2.694, 2.050, 1.054, 1.051 }; // Begining of Run 15 Jan 14, 2015 // Double_t s0[nsensor] = { 4.326, 7.078, 6.208, 3.349, 1.108, 1.048, 1.058 }; // after adding CAN 1 and CAN 2 2015.04.15 // Double_t s0[nsensor] = { 4.326, 7.078, 6.208, 3.349, 1.108, 1.048, 1.058, 1.046, 1.048 }; // Here's the beginning of Run 14 in January // Double_t s0[nsensor] = { 3.60, 6.20, 5.26, 1.16, 1.18, 1.054, 1.051 }; Double_t s0[nsensor] = { 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05, 1.05 }; for ( channel = 0; channel < nsensor; channel++ ) { V_s[channel].clear(); V_r[channel].clear(); R_n[channel].clear(); T_n[channel].clear(); R_k[channel].clear(); R_r[channel].clear(); read_time[channel].clear(); V_r_corrected[channel].clear(); V_s_corrected[channel].clear(); dose_r[channel].clear(); dose_s[channel].clear(); rs_ratio[channel].clear(); } Double_t v_r_c = 0.0; Double_t v_s_c = 0.0; for (Int_t i = 0; i < nrows; i++) { row = res->Next(); for (Int_t j = 0; j < nfields; j++) { fieldname = TString( res->GetFieldName(j) ); field = TString( row->GetField(j) ); // Extract all columns of each row // std::cout << "fieldname: " << fieldname << " field: " << field << std::endl; if ( fieldname == "read_timestamp" ) read_timestamp = field.Atof(); if ( fieldname == "channel" ) channel = field.Atoi(); if ( fieldname == "v_k" ) v_k = field.Atof(); if ( fieldname == "v_n" ) v_n = field.Atof(); if ( fieldname == "v_s" ) v_s = field.Atof(); if ( fieldname == "v_r" ) v_r = field.Atof(); if ( fieldname == "i_k" ) i_k = field.Atof(); if ( fieldname == "i_n" ) i_n = field.Atof(); if ( fieldname == "i_s" ) i_s = field.Atof(); if ( fieldname == "i_r" ) i_r = field.Atof(); } // Save all the columns in this row in vectors for plotting V_s[channel].push_back(v_s); V_r[channel].push_back(v_r); R_n[channel].push_back(v_n/i_n); T_n[channel].push_back( temperature(v_n,i_n) ); R_k[channel].push_back(v_k/i_k); R_r[channel].push_back(v_r/i_r); read_time[channel].push_back(read_timestamp); v_r_c = v_r - a0[channel]; V_r_corrected[channel].push_back( v_r_c ); // std::cout << channel << ": " << v_r_c << " " << radfet_dose( &v_r_c, 0 ) << std::endl; dose_r[channel].push_back( radfet_dose( &v_r_c, 0 ) ); v_s_c = v_s - s0[channel]; V_s_corrected[channel].push_back( v_s_c ); dose_s[channel].push_back( si_dose( &v_s_c, 0 ) ); if ( TMath::Abs( v_s_c ) > 1E-9 ) { rs_ratio[channel].push_back( (v_r - a0[channel])/v_s_c ); } else { rs_ratio[channel].push_back( 0.0 ); }; } return nrows; }