Changeset 8185 for trunk/MagicSoft/Mars
- Timestamp:
- 11/01/06 08:29:46 (18 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8182 r8185 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 2006/11/01 Thomas Bretz 22 23 * datacenter/macros/plotdb.C, datacenter/macros/plotoptical.C: 24 - a lot of changes starting to unify the different plot macros 25 - use the new function to get the joins automatically 26 - further improved grouping 27 28 * msql/MSQLServer.[h,cc]: 29 - implemented a new function returning the primary key of a table 30 - added a new function to return the joins automatically 31 necessary to do a query 32 - changed the call to GetTables and GetColumns 33 34 20 35 21 36 2006/10/31 Daniela Dorner -
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 { -
trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C
r8140 r8185 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1. 2 2006-10-20 18:26:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.3 2006-11-01 08:29:45 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 69 69 #include <TFrame.h> 70 70 #include <TStyle.h> 71 #include <TGraph.h>72 71 #include <TCanvas.h> 72 #include <TPRegexp.h> 73 73 #include <TSQLRow.h> 74 74 #include <TSQLResult.h> 75 #include <TGraphErrors.h> 75 76 76 77 #include "MTime.h" … … 82 83 class MPlot : public MParContainer 83 84 { 85 public: 86 enum GroupBy_t 87 { 88 kNone, 89 kGroupByPrimary, 90 kGroupByHour, 91 kGroupByNight, 92 kGroupByWeek, 93 kGroupByMonth, 94 kGroupByYear 95 }; 84 96 private: 85 97 MSQLMagic &fServer; … … 87 99 MDataSet *fDataSet; 88 100 89 TString fRequestFrom; 90 TString fRequestTo; 91 Int_t fRequestPeriod; 92 93 Float_t fPlotMin; 94 Float_t fPlotMax; 95 96 Float_t fHistMin; 97 Float_t fHistMax; 98 99 TString fDescription; 100 TString fNameTab; 101 102 TString fCondition; 103 Bool_t fGroupBy; 101 TString fPrimary; 102 TString fSecondary; 103 104 TString fRequestFrom; 105 TString fRequestTo; 106 Int_t fRequestPeriod; 107 108 Float_t fPlotMin; 109 Float_t fPlotMax; 110 111 Float_t fHistMin; 112 Float_t fHistMax; 113 114 TString fDescription; 115 TString fNameTab; 116 117 TString fCondition; 118 GroupBy_t fGroupBy; 104 119 105 120 void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution) … … 109 124 TSQLRow *row; 110 125 111 TGraph gt;126 TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph; 112 127 gt.SetNameTitle(name, Form("%s vs Time", name.Data())); 113 128 gt.SetMarkerStyle(kFullDotMedium); … … 138 153 const char *val = (*row)[2]; 139 154 const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0; 155 const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0; 140 156 if (!date || !val || !zd) 141 157 continue; … … 174 190 gt.SetPoint(gt.GetN(), t.GetAxisTime(), value); 175 191 gz.SetPoint(gz.GetN(), zenith, value); 176 } 177 178 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 179 cerr << setprecision(4) << setw(10) << title << ": "; 180 if (gt.GetN()==0) 181 { 182 cerr << " <empty>" << endl; 183 return; 184 } 185 cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " "; 186 if (gt0.GetN()>0 || gt1.GetN()>0) 187 { 188 cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " "; 189 cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2); 190 } 191 cerr << endl; 192 193 if (verr) 194 static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr)); 195 } 192 196 193 197 // If this is done earlier the plots remain empty since root 5.12/00 … … 202 206 gROOT->SetSelectedPad(0); 203 207 208 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 204 209 TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas; 205 210 c.SetFillColor(kWhite); 206 211 c.SetBorderMode(0); 207 212 c.Divide(1,2); 213 214 cerr << setprecision(4) << setw(10) << title << ": "; 215 if (gt.GetN()==0) 216 { 217 cerr << " <empty>" << endl; 218 return; 219 } 220 cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " "; 221 if (gt0.GetN()>0 || gt1.GetN()>0) 222 { 223 cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " "; 224 cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2); 225 } 226 cerr << endl; 208 227 209 228 TVirtualPad *pad = gPad; … … 308 327 public: 309 328 MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL), 310 fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(k FALSE)329 fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone) 311 330 { 312 331 } … … 326 345 fDataSet = new MDataSet(filename); 327 346 } 328 void SetPlotRange(Float_t min, Float_t max, Int_t n=5) 329 { fPlotMin = min; fPlotMax = max; } 330 void SetHistRange(Float_t min, Float_t max) 331 { fHistMin = min; fHistMax = max; } 332 void SetRequestRange(const char *from="", const char *to="") 333 { fRequestFrom = from; fRequestTo = to; } 334 void SetRequestPeriod(Int_t n=-1) 335 { fRequestPeriod = n; } 336 void SetCondition(const char *cond="") 337 { fCondition = cond; } 347 void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; } 348 void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; } 349 void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; } 350 void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; } 351 void SetCondition(const char *cond="") { fCondition = cond; } 338 352 void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; } 339 void EnableGroupBy(Bool_t b=kTRUE) { fGroupBy=b; } 353 void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; } 354 void SetPrimary(const char *ts) { fPrimary=ts; } 355 void SetSecondary(const char *ts) { fSecondary=ts; } 340 356 341 357 Int_t QueryKeyOfSource(TString src) … … 346 362 Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0) 347 363 { 348 TString named = "OpticalData.fTimeStamp";349 TString named2 = f GroupBy ? "AVG(fZenithDistance)" : "fZenithDistance";364 TString named = fPrimary; 365 TString named2 = fSecondary; 350 366 TString namev = value; 351 367 TString join = "fSequenceFirst"; … … 357 373 TString valued = named(named.First('.')+1, named.Length()); 358 374 359 TString query; 360 query = Form("select %s, %s, %s ", valued.Data(), named2.Data(), value); 361 query += Form("from %s ", tabled.Data()); 362 363 //const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull(); 364 365 if (TString(value).Contains("Object.")) 366 { 367 query += "left join Object on Object.fObjectKEY=OpticalData.fObjectKEY "; 368 } 369 370 if (!fCondition.IsNull()) 371 { 372 query += "where "; 373 query += fCondition; 374 query += " "; 375 } 376 377 if (fGroupBy) 378 query += " GROUP BY fTimeStamp "; 379 380 query += "order by fTimeStamp"; 375 TString query="SELECT "; 376 query += valued; 377 if (fGroupBy==kNone) 378 { 379 query += ", "; 380 query += fSecondary; 381 query += ", "; 382 query += value; 383 query += ", 0 "; 384 } 385 else 386 { 387 query += ", AVG("; 388 query += fSecondary; 389 query += "), AVG("; 390 query += value; 391 query += "), COUNT(*), STD("; 392 query += fSecondary; 393 query += "), STD("; 394 query += value; 395 query += ") "; 396 } 397 398 switch (fGroupBy) 399 { 400 case kNone: 401 case kGroupByPrimary: 402 break; 403 case kGroupByHour: 404 query += Form(", DATE_FORMAT(%s, '%%Y-%%m-%%d %%H') AS %s ", named.Data(), valued.Data()); 405 break; 406 case kGroupByNight: 407 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d') AS %s ", named.Data(), valued.Data()); 408 break; 409 case kGroupByWeek: 410 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", named.Data(), valued.Data()); 411 break; 412 case kGroupByMonth: 413 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m') AS %s ", named.Data(), valued.Data()); 414 break; 415 case kGroupByYear: 416 query += Form(", DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y') AS %s ", named.Data(), valued.Data()); 417 break; 418 } 419 420 query += Form("FROM %s ", tabled.Data()); 421 422 TString where(fCondition); 423 424 if (!where.IsNull()) 425 where += " AND "; 426 427 where += fCondition; 428 where += " "; 429 430 // ------------------------------ 431 432 query += fServer.GetJoins(tabled, query+" "+where); 433 434 if (!where.IsNull()) 435 { 436 query += "WHERE "; 437 query += where; 438 } 439 440 if (fGroupBy!=kNone) 441 { 442 query += Form("GROUP BY %s ", valued.Data()); 443 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 444 } 445 query += Form("ORDER BY %s ", fPrimary.Data()); 446 447 448 // ------------------------------ 381 449 382 450 TSQLResult *res = fServer.Query(query); … … 396 464 void plotall(MPlot &plot, TString source) 397 465 { 466 plot.SetPrimary("OpticalData.fTimeStamp"); 467 plot.SetSecondary("fZenithDistance"); 468 469 470 398 471 TString cond = "fStatusKEY=13"; 399 472 if (!source.IsNull()) … … 402 475 if (key<0) 403 476 return; 404 cond += Form(" andfObjectKEY=%d", key);477 cond += Form(" AND Object.fObjectKEY=%d", key); 405 478 406 479 } … … 418 491 plot.SetDescription("Aperture Radius;R_{A}", "ApRad"); 419 492 plot.Plot("OpticalData.fApertureRadius", 0, 10, 1); 420 /* 421 plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s"); 422 plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure", 0, 0.2, 0.005); 423 424 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}\\cdot s^{-1}", "MagErr/s"); 425 plot.Plot("OpticalData.fInstrumentalMagErr/OpticalData.fExposure", 0, 0.01, 0.0002); 426 427 plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag"); 428 plot.Plot("OpticalData.fInstrumentalMag", 0, 30, 0.5); 429 430 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr"); 431 plot.Plot("OpticalData.fInstrumentalMagErr", 0, 1, 0.01); 432 */ 493 494 /* 495 plot.SetDescription("Instrumental Magnitude;M_{I}\\cdot s^{-1}", "InstMag/s"); 496 plot.Plot("OpticalData.fInstrumentalMag/OpticalData.fExposure", 0, 0.2, 0.005); 497 498 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}\\cdot s^{-1}", "MagErr/s"); 499 plot.Plot("OpticalData.fInstrumentalMagErr/OpticalData.fExposure", 0, 0.01, 0.0002); 500 501 plot.SetDescription("Instrumental Magnitude;M_{I}", "InstMag"); 502 plot.Plot("OpticalData.fInstrumentalMag", 0, 30, 0.5); 503 504 plot.SetDescription("Instrumental Magnitude Error;\\sigma_{M}", "MagErr"); 505 plot.Plot("OpticalData.fInstrumentalMagErr", 0, 1, 0.01); 506 */ 507 433 508 plot.SetDescription("m_{1};m_{1}", "M1"); 434 509 plot.Plot("OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)", 10, 35, 0.2); 435 510 436 cond += " and Object.fObjectName not like '%/BL' and not IsNull(Object.fMagnitude) ";511 cond += " AND Object.fObjectName NOT LIKE '%/BL' AND NOT ISNULL(Object.fMagnitude) "; 437 512 plot.SetCondition(cond); 438 513 439 514 TString ext("3080/25.0*pow(10, (OpticalData.fInstrumentalMag+2.5*log10(OpticalData.fExposure)-Object.fMagnitude)/-2.5)"); 440 515 ext += "+0.0028*fZenithDistance-0.08"; 441 /* 442 plot.SetDescription("m_{1}-m_{true} (Extinction per Object);m_{1}-m_{true}", "ExtObj"); 443 plot.Plot(ext, 0.5, 1.2, 0.01); 444 */ 445 446 plot.EnableGroupBy(); 516 517 plot.SetGroupBy(MPlot::kGroupByPrimary); 447 518 plot.SetDescription("m_{1}-m_{true} (Extinction per Image);m_{1}-m_{true}", "ExtImg"); 448 plot.Plot(Form("AVG(%s)", ext.Data()), 0.05, 1.2, 0.01); 449 450 plot.SetDescription("Error m_{1}-m_{true} (Extinction per Image);ERR m_{1}-m_{true}", "ExtImgErr"); 451 plot.Plot(Form("STD(%s)", ext.Data()), 0, 0.3, 0.005); 452 519 plot.Plot(ext/*Form("AVG(%s)", ext.Data())*/, 0.05, 1.2, 0.01); 520 521 plot.SetGroupBy(MPlot::kGroupByHour); 453 522 plot.SetDescription("m_{1}-m_{true} (Extinction per Hour);m_{1}-m_{true}", "ExtHour"); 454 plot.Plot( Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data()),523 plot.Plot(ext/*Form("AVG(%s), date_format(fTimeStamp, '%%Y-%%m-%%d %%H') as fTimeStamp", ext.Data())*/, 455 524 0.5, 1.2, 0.01); 456 525 526 plot.SetGroupBy(MPlot::kGroupByNight); 457 527 plot.SetDescription("m_{1}-m_{true} (Extinction per Night);m_{1}-m_{true}", "ExtNight"); 458 plot.Plot( Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data()),528 plot.Plot(ext/*Form("AVG(%s), date_format(adddate(fTimeStamp,Interval 12 hour),'%%Y-%%m-%%d') as fTimeStamp", ext.Data())*/, 459 529 0.5, 1.2, 0.01); 460 530 } -
trunk/MagicSoft/Mars/mhflux/MHFalseSource.cc
r8106 r8185 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.2 0 2006-10-17 17:16:00tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MHFalseSource.cc,v 1.21 2006-11-01 08:29:45 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 121 121 #include <TF2.h> 122 122 #include <TH2.h> 123 #include <TLatex.h> 123 124 #include <TGraph.h> 124 125 #include <TStyle.h> 125 126 #include <TCanvas.h> 126 127 #include <TRandom.h> 128 #include <TEllipse.h> 127 129 #include <TPaveText.h> 128 130 #include <TStopwatch.h> … … 640 642 // source plot. 641 643 // 642 TObject *MHFalseSource::GetCatalog() 643 { 644 const Double_t maxr = 0.98*TMath::Abs(fHist.GetBinCenter(1));644 TObject *MHFalseSource::GetCatalog() const 645 { 646 const Double_t maxr = TMath::Abs(fHist.GetBinLowEdge(1))*TMath::Sqrt(2); 645 647 646 648 // Create catalog... … … 1251 1253 } 1252 1254 } 1255 1256 void MHFalseSource::DrawNicePlot() const 1257 { 1258 Int_t newc = kTRUE; 1259 Float_t zoom = 0.95; 1260 Int_t col = kBlue+180; 1261 1262 if (!newc && !fDisplay) 1263 return; 1264 1265 TH1 *h = dynamic_cast<TH1*>(FindObjectInPad("Alpha_yx_on")); 1266 if (!h) 1267 return; 1268 1269 // Open and setup canvas/pad 1270 TCanvas &c = newc ? *new TCanvas("Excess", "Excess Plot", TMath::Nint(500.), TMath::Nint(500*0.77/0.89)) : fDisplay->AddTab("ThetsSq"); 1271 1272 //c.SetPad(0.15, 0, 0.90, 1); 1273 1274 c.SetBorderMode(0); 1275 c.SetFrameBorderMode(0); 1276 c.SetFillColor(kWhite); 1277 1278 c.SetLeftMargin(0.11); 1279 c.SetRightMargin(0.12); 1280 c.SetBottomMargin(0.10); 1281 c.SetTopMargin(0.01); 1282 1283 TH1 *h1 = (TH1*)h->Clone(""); 1284 h1->SetDirectory(0); 1285 h1->SetTitle(""); 1286 h1->SetContour(99); 1287 h1->SetBit(TH1::kNoStats); 1288 h1->SetBit(TH1::kCanDelete); 1289 1290 if (h1->FindObject("stats")) 1291 delete h1->FindObject("stats"); 1292 1293 TAxis &x = *h1->GetXaxis(); 1294 TAxis &y = *h1->GetYaxis(); 1295 TAxis &z = *h1->GetZaxis(); 1296 1297 x.SetRangeUser(-zoom, zoom); 1298 y.SetRangeUser(-zoom, zoom); 1299 1300 x.SetTitleOffset(1.1); 1301 y.SetTitleOffset(1.3); 1302 1303 x.SetTickLength(0.025); 1304 y.SetTickLength(0.025); 1305 1306 x.SetAxisColor(kWhite); 1307 y.SetAxisColor(kWhite); 1308 1309 x.CenterTitle(); 1310 y.CenterTitle(); 1311 1312 x.SetTitle("Offset [#circ]"); 1313 y.SetTitle("Offset [#circ]"); 1314 1315 x.SetDecimals(); 1316 y.SetDecimals(); 1317 z.SetDecimals(); 1318 1319 MH::SetPalette("glowsym", 99); 1320 1321 const Float_t max = TMath::Max(h1->GetMinimum(), h1->GetMaximum()); 1322 1323 h1->SetMinimum(-max); 1324 h1->SetMaximum(max); 1325 1326 h1->Draw("colz"); 1327 1328 // ------ 1329 // Convert pave coordinates from NDC to Pad coordinates. 1330 1331 gPad->Update(); 1332 1333 Float_t x0 = 0.80; 1334 Float_t y0 = 0.88; 1335 1336 Double_t dx = gPad->GetX2() - gPad->GetX1(); 1337 Double_t dy = gPad->GetY2() - gPad->GetY1(); 1338 1339 // Check if pave initialisation has been done. 1340 // This operation cannot take place in the Pave constructor because 1341 // the Pad range may not be known at this time. 1342 Float_t px = gPad->GetX1() + x0*dx; 1343 Float_t py = gPad->GetY1() + y0*dy; 1344 // ------- 1345 1346 TEllipse *el = new TEllipse(px, py, 0.12, 0.12, 0, 360, 0); 1347 el->SetFillStyle(4100); 1348 el->SetFillColor(kBlack); 1349 el->SetLineWidth(2); 1350 el->SetLineColor(kWhite); 1351 el->SetBit(kCanDelete); 1352 el->Draw(); 1353 1354 TString str1("el.SetX1(gPad->GetX1()+0.9*(gPad->GetX2()-gPad->GetX1()));"); 1355 TString str2("el.SetY1(gPad->GetY1()+0.9*(gPad->GetY2()-gPad->GetY1()));"); 1356 1357 str1.ReplaceAll("el.", Form("((TEllipse*)%p)->", el)); 1358 str2.ReplaceAll("el.", Form("((TEllipse*)%p)->", el)); 1359 1360 str1.ReplaceAll("0.9", Form("%f", x0)); 1361 str2.ReplaceAll("0.9", Form("%f", y0)); 1362 1363 TLatex tex; 1364 tex.SetBit(TText::kTextNDC); 1365 tex.SetTextColor(kWhite); 1366 tex.SetTextAlign(22); 1367 tex.SetTextSize(0.04); 1368 tex.SetTextAngle(0); 1369 tex.DrawLatex(x0, y0, "psf"); 1370 1371 TPad *pad = new TPad("pad", "Catalog Pad", 1372 c.GetLeftMargin(), c.GetBottomMargin(), 1373 1-c.GetRightMargin(), 1-c.GetTopMargin()); 1374 1375 pad->SetFillStyle(4000); 1376 pad->SetFillColor(kBlack); 1377 pad->SetBorderMode(0); 1378 pad->SetFrameBorderMode(0); 1379 pad->SetBit(kCanDelete); 1380 pad->Draw(); 1381 1382 pad->Range(x.GetBinLowEdge(x.GetFirst()), 1383 y.GetBinLowEdge(y.GetFirst()), 1384 x.GetBinLowEdge(x.GetLast()+1), 1385 y.GetBinLowEdge(y.GetLast()+1)); 1386 1387 TString str3("pad->Range(x.GetBinLowEdge(x.GetFirst())," 1388 "y.GetBinLowEdge(y.GetFirst())," 1389 "x.GetBinLowEdge(x.GetLast()+1)," 1390 "y.GetBinLowEdge(y.GetLast()+1));"); 1391 1392 str3.ReplaceAll("x.", Form("((TAxis*)%p)->", &x)); 1393 str3.ReplaceAll("y.", Form("((TAxis*)%p)->", &y)); 1394 // str3.ReplaceAll("pad", Form("((TPad*)(%p))", pad)); 1395 1396 c.AddExec("SetPosX", str1); 1397 c.AddExec("SetPosY", str2); 1398 c.AddExec("Resize", str3); 1399 1400 pad->cd(); 1401 gROOT->SetSelectedPad(0); 1402 1403 MAstroCatalog *cat = (MAstroCatalog*)GetCatalog(); 1404 1405 cat->GetAttLineSky().SetLineColor(col); 1406 cat->GetAttLineSky().SetLineWidth(2); 1407 cat->GetAttLineSky().SetLineStyle(7); 1408 1409 cat->GetList()->Clear(); 1410 cat->SetBit(kCanDelete); 1411 // cat->AddObject(MAstro::Hms2Hor(12,17,52)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(30,7,0), 6, "1ES1215+303"); 1412 // cat->AddObject(MAstro::Hms2Hor(12,18,27)*TMath::Pi()/12, TMath::DegToRad()*MAstro::Dms2Deg(29,48,46), 6, "Mrk766"); 1413 1414 cat->Draw("mirror same"); 1415 1416 /* 1417 Int_t col = kBlue+180; 1418 1419 TLatex tex; 1420 tex.SetTextColor(col); 1421 tex.SetTextAlign(21); 1422 tex.SetTextSize(0.04); 1423 tex.DrawLatex(-0.79, -0.8, "43.0\\circ"); 1424 tex.DrawLatex(-0.78, 0.2, "42.0\\circ"); 1425 1426 tex.SetTextAngle(-90); 1427 tex.DrawLatex(-0.45, -0.55, "22.00h"); 1428 tex.DrawLatex( 0.30, -0.55, "22.07h"); 1429 */ 1430 } -
trunk/MagicSoft/Mars/mhflux/MHFalseSource.h
r7188 r8185 46 46 Double_t fDec; 47 47 48 TObject *GetCatalog() ;48 TObject *GetCatalog() const; 49 49 void MakeSymmetric(TH1 *h); 50 50 … … 87 87 } 88 88 89 void DrawNicePlot() const; //*MENU* 90 89 91 // MParContainer 90 92 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE); -
trunk/MagicSoft/Mars/msql/MSQLServer.cc
r7940 r8185 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.13 2006-11-01 08:29:45 tbretz Exp $ 3 ! -------------------------------------------------------------------------- 2 4 ! 3 5 ! * … … 18 20 ! Author(s): Thomas Bretz 2/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 19 21 ! 20 ! Copyright: MAGIC Software Development, 2000-200 422 ! Copyright: MAGIC Software Development, 2000-2006 21 23 ! 22 24 ! … … 47 49 #include <TH1.h> 48 50 #include <TEnv.h> 51 #include <TPRegexp.h> 49 52 50 53 #include <TSQLResult.h> … … 519 522 } 520 523 521 TSQLResult *MSQLServer::GetTables(const char * dbname, const char *wild) /*FOLD00*/522 { 523 return fType==kIsServer && fServ ? fServ->GetTables(dbname , wild) : NULL;524 } 525 526 TSQLResult *MSQLServer::GetColumns(const char * dbname, const char *table, const char *wild) /*FOLD00*/527 { 528 return fType==kIsServer && fServ ? fServ->GetColumns(dbname , table, wild) : NULL;524 TSQLResult *MSQLServer::GetTables(const char *wild, const char *dbname) /*FOLD00*/ 525 { 526 return fType==kIsServer && fServ ? fServ->GetTables(dbname?dbname:fDataBase.Data(), wild) : NULL; 527 } 528 529 TSQLResult *MSQLServer::GetColumns(const char *table, const char *wild, const char *dbname) /*FOLD00*/ 530 { 531 return fType==kIsServer && fServ ? fServ->GetColumns(dbname?dbname:fDataBase.Data(), table, wild) : NULL; 529 532 } 530 533 … … 604 607 } 605 608 else 606 SetBit(kZombie);609 fType = kIsZombie; 607 610 608 611 fList.SetOwner(); … … 749 752 } 750 753 754 // -------------------------------------------------------------------------- 755 // 756 // Return the name of the (first) column with a primary key 757 // 758 TString MSQLServer::GetPrimaryKey(const char *table) 759 { 760 TSQLResult *res = GetColumns(table); 761 if (!res) 762 return ""; 763 764 TString rc; 765 766 TSQLRow *row = 0; 767 while ((row=res->Next())) 768 { 769 TString key = (*row)[3]; 770 if (key!="PRI") 771 continue; 772 773 rc = (*row)[0]; 774 break; 775 } 776 777 delete res; 778 return rc; 779 } 780 781 // -------------------------------------------------------------------------- 782 // 783 // Searches in the text for patterns like "Table.Column". If such a pettern 784 // is found the primary key of the table is requested a "LEFT JOIN" 785 // with this Table is added ON the identity of the primary key of Table 786 // with the given table. 787 // 788 TString MSQLServer::GetJoins(const char *table, const TString text) 789 { 790 Int_t p=0; 791 792 TString mods; 793 TArrayI pos; 794 795 // Find all Table.Column expression. Because also floating point 796 // numbers can contain a dot the result has to be checked carefully 797 TString joins; 798 TPRegexp reg = TPRegexp("\\w+[.]\\w+"); 799 while (1) 800 { 801 // Check whether expression is found 802 if (reg.Match(text, mods, p, 130, &pos)==0) 803 break; 804 805 // Get expression from text 806 const TString expr = text(pos[0], pos[1]-pos[0]); 807 p = pos[1]; 808 809 if (expr.IsFloat()) 810 continue; 811 812 const TString tab = expr(0, expr.First('.')); 813 const TString var = expr(expr.First('.')+1, expr.Length()); 814 815 // If the table found is the primary table itself skip it. 816 if (tab==table) 817 continue; 818 819 // If this join has already be set, skip it. 820 if (joins.Contains(Form(" %s ", tab.Data()))) 821 continue; 822 823 // Now get the primary key of the table to be joined 824 const TString prim = GetPrimaryKey(tab); 825 if (prim.IsNull()) 826 continue; 827 828 joins += Form("LEFT JOIN %s ON %s.%s=%s.%s ", tab.Data(), 829 table, prim.Data(), tab.Data(), prim.Data()); 830 } 831 832 if (!joins.IsNull()) 833 joins += " "; 834 835 return joins; 836 } 837 751 838 void MSQLServer::RecursiveRemove(TObject *obj) 752 839 { -
trunk/MagicSoft/Mars/msql/MSQLServer.h
r7940 r8185 113 113 Int_t SelectDataBase(const char *dbname); 114 114 TSQLResult *GetDataBases(const char *wild = 0); 115 TSQLResult *GetTables(const char * dbname, const char *wild= 0);116 TSQLResult *GetColumns(const char * dbname, const char *table, const char *wild= 0);115 TSQLResult *GetTables(const char *wild = 0, const char *dbname = 0); 116 TSQLResult *GetColumns(const char *table, const char *wild = 0, const char *dbname = 0); 117 117 Int_t CreateDataBase(const char *dbname); 118 118 Int_t DropDataBase(const char *dbname); … … 123 123 124 124 TString GetEntry(const char *where, const char *col=0, const char *table=0) const; 125 TString GetPrimaryKey(const char *table); 126 TString GetJoins(const char *table, const TString text); 125 127 126 128 void RecursiveRemove(TObject *obj);
Note:
See TracChangeset
for help on using the changeset viewer.