Changeset 8185 for trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
- Timestamp:
- 11/01/06 08:29:46 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/plotdb.C
r8169 r8185 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1. 29 2006-10-27 13:36:18tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotdb.C,v 1.30 2006-11-01 08:29:45 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 70 70 #include <TStyle.h> 71 71 #include <TCanvas.h> 72 #include <TPRegexp.h> 72 73 #include <TSQLRow.h> 73 74 #include <TSQLResult.h> … … 77 78 #include "MAstro.h" 78 79 #include "MDataSet.h" 79 #include "MSQL Server.h"80 #include "MSQLMagic.h" 80 81 #include "MStatusDisplay.h" 81 82 … … 86 87 { 87 88 kNone, 88 kGroupByDay, 89 kGroupByPrimary, 90 kGroupByHour, 91 kGroupByNight, 89 92 kGroupByWeek, 90 93 kGroupByMonth, … … 92 95 }; 93 96 private: 94 MSQL Server&fServer;97 MSQLMagic &fServer; 95 98 96 99 MDataSet *fDataSet; 100 101 TString fPrimary; 102 TString fSecondary; 97 103 98 104 TString fRequestFrom; … … 146 152 const char *zd = (*row)[1]; 147 153 const char *val = (*row)[2]; 148 const char *snum = (*row)[3];154 const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0; 149 155 const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0; 150 if (!date || !val || !zd || !snum)156 if (!date || !val || !zd) 151 157 continue; 152 158 … … 162 168 last = TMath::Nint(TMath::Ceil(t.GetMjd())); 163 169 164 UInt_t seq = atoi(snum);170 UInt_t seq = snum ? atoi(snum) : 0; 165 171 166 172 Float_t value = atof(val); … … 207 213 208 214 cerr << setprecision(4) << setw(10) << title << ": "; 215 if (gt.GetN()==0) 216 { 217 cerr << " <empty>" << endl; 218 return; 219 } 209 220 cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " "; 210 221 if (gt0.GetN()>0 || gt1.GetN()>0) … … 314 325 315 326 public: 316 MPlot(MSQL Server&server) : fServer(server), fDataSet(NULL),327 MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL), 317 328 fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone) 318 329 { … … 337 348 void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; } 338 349 void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; } 350 void SetCondition(const char *cond="") { fCondition = cond; } 339 351 void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; } 340 void SetCondition(const char *cond="") { fCondition = cond; }341 352 void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; } 353 void SetPrimary(const char *ts) { fPrimary=ts; } 354 void SetSecondary(const char *ts) { fSecondary=ts; } 342 355 343 356 Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0) 344 357 { 345 TString named = "Sequences.fRunStart";346 TString named2 = "(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2";358 TString named = fPrimary; 359 TString named2 = fSecondary; 347 360 TString namev = value; 348 361 TString join = "fSequenceFirst"; … … 354 367 TString valued = named(named.First('.')+1, named.Length()); 355 368 356 TString query; 369 TString query="SELECT "; 370 query += valued; 357 371 if (fGroupBy==kNone) 358 query = Form("select %s, %s, %s, Sequences.fSequenceFirst ", valued.Data(), named2.Data(), valuev.Data()); 372 { 373 query += ", "; 374 query += fSecondary; 375 query += ", "; 376 query += value; 377 query += ", "; 378 query += " Sequences.fSequenceFirst "; 379 } 359 380 else 360 query = Form("select %s, AVG(%s), AVG(%s), Sequences.fSequenceFirst, STD(%s), STD(%s) ", valued.Data(), named2.Data(), valuev.Data(), named2.Data(), valuev.Data()); 381 { 382 query += ", AVG("; 383 query += fSecondary; 384 query += "), AVG("; 385 query += value; 386 query += "), Sequences.fSequenceFirst, STD("; 387 query += fSecondary; 388 query += "), STD("; 389 query += value; 390 query += ") "; 391 } 361 392 362 393 switch (fGroupBy) 363 394 { 364 395 case kNone: 396 case kGroupByPrimary: 365 397 break; 366 case kGroupByDay: 367 query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m-%%d') as %s ", named.Data(), valued.Data()); 398 case kGroupByHour: 399 query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data()); 400 break; 401 case kGroupByNight: 402 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data()); 368 403 break; 369 404 case kGroupByWeek: 370 query += Form(", date_format(adddate(%s,Interval 12 hour), '%%x%%v') as%s ", named.Data(), valued.Data());405 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data()); 371 406 break; 372 407 case kGroupByMonth: 373 query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y-%%m') as%s ", named.Data(), valued.Data());408 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data()); 374 409 break; 375 410 case kGroupByYear: 376 query += Form(", date_format(adddate(%s,Interval 12 hour), '%%Y') as%s ", named.Data(), valued.Data());411 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data()); 377 412 break; 378 413 } 379 414 380 query += Form("from %s left join %s ", tabled.Data(), tablev.Data()); 381 query += Form("on %s.%s=%s.%s ", tabled.Data(), join.Data(), tablev.Data(), join.Data()); 415 query += Form("FROM %s ", tabled.Data()); 382 416 383 417 const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull(); 384 418 419 TString where(fCondition); 385 420 if (!fDataSet && !interval && tablev=="Star") 386 421 { 387 if (!query.Contains("Star.fSequenceFirst")) 388 query += "left join Star on Sequences.fSequenceFirst=Star.fSequenceFirst "; 389 // This is from a plot PSF/MuonNumber 390 query += "where Star.fMuonNumber>300 "; 422 if (!where.IsNull()) 423 where += " AND "; 424 where += "Star.fMuonNumber>300 "; 391 425 } 392 426 393 427 if (interval) 394 428 { 395 query += query.Contains(" where ") ? "and " : "where "; 396 query += Form("fRunStart between '%s' and '%s' ", 397 fRequestFrom.Data(), fRequestTo.Data()); 429 if (!where.IsNull()) 430 where += " AND "; 431 where += Form("%s BETWEEN '%s' AND '%s' ", 432 fPrimary.Data(), fRequestFrom.Data(), fRequestTo.Data()); 433 } 434 435 // ------------------------------ 436 437 query += fServer.GetJoins(tabled, query+" "+where); 438 439 if (!where.IsNull()) 440 { 441 query += "WHERE "; 442 query += where; 398 443 } 399 444 400 445 if (fGroupBy!=kNone) 401 446 { 402 query += Form(" 447 query += Form("GROUP BY %s ", valued.Data()); 403 448 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 404 449 } 405 406 query += "order by fRunStart"; 450 query += Form("ORDER BY %s ", fPrimary.Data()); 451 452 453 // ------------------------------ 407 454 408 455 TSQLResult *res = fServer.Query(query); … … 427 474 { 428 475 //plot.SetGroupBy(MPlot::kGroupByWeek); 476 477 plot.SetPrimary("Sequences.fRunStart"); 478 plot.SetSecondary("(Sequences.fZenithDistanceMin+Sequences.fZenithDistanceMax)/2"); 429 479 430 480 //inner camera … … 457 507 plot.SetDescription("Hi-/Lo-Gain ratio;", "HiLoRatio"); 458 508 plot.Plot("Calibration.fHiLoGainRatioMed", 10, 12.5, 0.05); 509 510 //plot.SetDescription("Pulse Variance;", "PulVar"); 511 //plot.Plot("Calibration.fPulsePosVar", 0, 0.03, 0.001); 459 512 460 513 //from star*.root … … 522 575 TEnv env("sql.rc"); 523 576 524 MSQL Serverserv(env);577 MSQLMagic serv(env); 525 578 if (!serv.IsConnected()) 526 579 { … … 554 607 TEnv env("sql.rc"); 555 608 556 MSQL Serverserv(env);609 MSQLMagic serv(env); 557 610 if (!serv.IsConnected()) 558 611 { … … 586 639 TEnv env("sql.rc"); 587 640 588 MSQL Serverserv(env);641 MSQLMagic serv(env); 589 642 if (!serv.IsConnected()) 590 643 {
Note:
See TracChangeset
for help on using the changeset viewer.