- Timestamp:
- 07/05/08 20:01:55 (16 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 added
- 30 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8994 r8996 19 19 -*-*- END OF LINE -*-*- 20 20 21 2008/07/05 Thomas Bretz 22 23 * datacenter/macros/fillcamera.C, datacenter/macros/findcacofiles.C: 24 - changed JOIN to use USING 25 - removed dependence on TEnv 26 - some improvement to includes 27 28 * datacenter/macros/filldotrbk.C, datacenter/macros/fillganymed.C, 29 datacenter/macros/filloptical.C, datacenter/macros/fillsignal.C, 30 datacenter/macros/fillsources.C, datacenter/macros/fillstar.C, 31 datacenter/macros/getdolist.C, datacenter/macros/insertcacofile.C, 32 datacenter/macros/insertdataset.C, datacenter/macros/plotoptical.C, 33 datacenter/macros/plotrundb.C, datacenter/macros/plotstat.C, 34 datacenter/macros/resetallruns.C, 35 datacenter/macros/writedatasetfile.C: 36 - removed dependence on TEnv 37 - some improvement to includes 38 39 * datacenter/macros/filldotrun.C: 40 - make it fail for everything except Magic 1 41 - removed dependence on TEnv 42 - some improvement to includes 43 44 * datacenter/macros/plotoptical.C: 45 - removed MPlot, use MPlot from plotdb instead 46 47 * datacenter/macros/setstatus.C: 48 - some improvement to includes 49 50 * mbase/MTime.[h,cc]: 51 - added function returning day of sunrise as MTime 52 53 * mhflux/MHAlpha.cc: 54 - use BinError instead of BinContents to decide whether the 55 excess time is plotted or not 56 57 * mimage/MHHillas.cc: 58 - changed title of "Center" 59 60 * mjobs/JobsLinkDef.h, mjobs/Makefile: 61 - added new class MSequenceSQL 62 63 * mjobs/MSequenceSQL.[h,cc]: 64 - added 65 66 * mjobs/MSequence.[h,cc]: 67 - replaced ReadLightCondition by the more flexible GetLightCondition 68 - added a new constrcutor constructing a MSequence from the database 69 - fixed the output in the comments in Print() 70 - The day and night was printed in a different format than 71 expected when readin a sequence 72 - fLightCondition and the f*RunsSub were missing in the copy- 73 constructor 74 75 * mjobs/Makefile: 76 - added include of msql 77 78 * msql/MSQLMagic.[h,cc]: 79 - added a comment to ExistStr and allow to set an additional 80 where-clause 81 82 * msql/MSQLServer.cc: 83 - allow to init MSQLServer either by an url or from a named 84 resource file 85 - changed JOIN to use USING 86 - if doing an automatic join join _all_ primaries 87 88 * mtools/MCalendar.cc: 89 - added include of TObjArray needed in newer root versions 90 91 92 21 93 2008/07/03 Thomas Bretz 22 94 … … 44 116 45 117 * sponde.cc: 46 - display only the base name of the ganymed file, not the full path 118 - display only the base name of the ganymed file, not the 119 full path 47 120 48 121 * mbase/MMath.[h,cc]: -
trunk/MagicSoft/Mars/datacenter/macros/fillcamera.C
r8760 r8996 47 47 #include <iomanip> 48 48 49 #include <TEnv.h>50 49 #include <TRegexp.h> 51 50 #include <TObjectTable.h> … … 656 655 // "where MCRunData.fRunNumber=%d;", RunNum)); 657 656 TString query3(Form("SELECT fMCParticleName, fSpectrum FROM MCRunData " 658 "LEFT JOIN MCParticle ON MCRunData.fMCParticleKEY=MCParticle.fMCParticleKEY"659 "LEFT JOIN Spectrum ON Spectrum.fSpectrumKEY=MCRunData.fSpectrumKEY"657 "LEFT JOIN MCParticle USING (fMCParticleKEY) " 658 "LEFT JOIN Spectrum USING (fSpectrumKEY) " 660 659 "WHERE MCRunData.fRunNumber=%d;", RunNum)); 661 660 res = serv.Query(query3); … … 773 772 int fillcamera(TString fname, Bool_t dummy=kTRUE) 774 773 { 775 TEnv env("sql.rc"); 776 777 MSQLMagic serv(env); 774 MSQLMagic serv("sql.rc"); 778 775 if (!serv.IsConnected()) 779 776 { … … 797 794 int fillcamera(TString path="/magic/montecarlo/camera", Bool_t dummy=kTRUE) 798 795 { 799 TEnv env("mcsql.rc"); 800 801 MSQLMagic serv(env); 796 MSQLMagic serv("mcsql.rc"); 802 797 if (!serv.IsConnected()) 803 798 { -
trunk/MagicSoft/Mars/datacenter/macros/filldotrbk.C
r7460 r8996 64 64 #include <fstream> 65 65 66 #include <TEnv.h>67 66 #include <TRegexp.h> 68 67 … … 206 205 int filldotrbk(TString path="/data/MAGIC/Period017/ccdata", Bool_t dummy=kTRUE) 207 206 { 208 TEnv env("sql.rc"); 209 210 MSQLServer serv(env); 207 MSQLServer serv("sql.rc"); 211 208 if (!serv.IsConnected()) 212 209 { -
trunk/MagicSoft/Mars/datacenter/macros/filldotrun.C
r8993 r8996 79 79 #include <fstream> 80 80 81 #include <TEnv.h>82 81 #include <TMath.h> 83 82 #include <TRegexp.h> … … 148 147 { 149 148 cout << "First character is not an M." << endl; 149 cout << strng << endl; 150 strng.ReadLine(fin); 151 continue; 152 } 153 if (strng[1]!='1') 154 { 155 cout << "Only MAGIC 1 implemented so far." << endl; 150 156 cout << strng << endl; 151 157 strng.ReadLine(fin); … … 580 586 int filldotrun(const TString path="/data/MAGIC/Period018/ccdata", Bool_t dummy=kTRUE) 581 587 { 582 TEnv env("sql.rc"); 583 584 MSQLMagic serv(env); 588 MSQLMagic serv("sql.rc"); 585 589 if (!serv.IsConnected()) 586 590 { -
trunk/MagicSoft/Mars/datacenter/macros/fillganymed.C
r7777 r8996 55 55 #include <iomanip> 56 56 57 #include <TEnv.h>58 57 #include <TRegexp.h> 59 58 … … 218 217 int fillganymed(TString fname, Bool_t dummy=kTRUE) 219 218 { 220 TEnv env("sql.rc"); 221 222 MSQLServer serv(env); 219 MSQLServer serv("sql.rc"); 223 220 if (!serv.IsConnected()) 224 221 { -
trunk/MagicSoft/Mars/datacenter/macros/filloptical.C
r8404 r8996 46 46 #include <TVector3.h> 47 47 48 #include <TEnv.h>49 48 #include <TRegexp.h> 50 49 … … 274 273 int filloptical(TString path, Bool_t dummy=kTRUE) 275 274 { 276 TEnv env("sql.rc"); 277 278 MSQLMagic serv(env); 275 MSQLMagic serv("sql.rc"); 279 276 if (!serv.IsConnected()) 280 277 { -
trunk/MagicSoft/Mars/datacenter/macros/fillsources.C
r7518 r8996 36 36 #include <fstream> 37 37 38 #include <TEnv.h>39 40 #include <MSQLServer.h>41 38 #include <TSQLRow.h> 42 39 #include <TSQLResult.h> 40 41 #include "MSQLServer.h" 43 42 44 43 using namespace std; … … 67 66 int fillsources(TString catalog) 68 67 { 69 TEnv env("sql.rc"); 70 71 MSQLServer serv(env); 68 MSQLServer serv("sql.rc"); 72 69 if (!serv.IsConnected()) 73 70 { -
trunk/MagicSoft/Mars/datacenter/macros/fillstar.C
r8987 r8996 59 59 #include <iomanip> 60 60 61 #include <TEnv.h>62 61 #include <TRegexp.h> 63 62 … … 310 309 int fillstar(TString fname, Bool_t dummy=kTRUE) 311 310 { 312 TEnv env("sql.rc"); 313 314 MSQLMagic serv(env); 311 MSQLMagic serv("sql.rc"); 315 312 if (!serv.IsConnected()) 316 313 { -
trunk/MagicSoft/Mars/datacenter/macros/findcacofiles.C
r8482 r8996 57 57 #include <fstream> 58 58 59 #include <TEnv.h>60 59 #include <TSystem.h> 61 60 62 #include "MSQLMagic.h"63 61 #include <TSQLRow.h> 64 62 #include <TSQLResult.h> 63 64 #include "MSQLMagic.h" 65 65 66 66 using namespace std; … … 69 69 int findcacofiles() 70 70 { 71 TEnv env("sql.rc"); 72 73 MSQLMagic serv(env); 71 MSQLMagic serv("sql.rc"); 74 72 if (!serv.IsConnected()) 75 73 { … … 87 85 query+=" DATE_FORMAT(ADDDATE(if(fRunStart='0000-00-00 00:00:00', fRunStop, fRunStart), INTERVAL +13 HOUR), '%Y/%m/%d') "; 88 86 query+=" FROM RunProcessStatus "; 89 query+=" LEFT JOIN RunData ON RunData.fRunNumber=RunProcessStatus.fRunNumber";90 query+=" LEFT JOIN Source ON RunData.fSourceKEY=Source.fSourceKEY";87 query+=" LEFT JOIN RunData USING (fRunNumber) "; 88 query+=" LEFT JOIN Source USING (fSourceKEY) "; 91 89 query+=" WHERE IsNull(fCaCoFileFound) AND fExcludedFDAKEY=1 "; 92 90 query+=" AND RunProcessStatus.fRunNumber > 10000 AND NOT IsNull(fCCFileAvail)"; … … 115 113 116 114 query ="SELECT MAX(fCaCoFileFound) FROM RunProcessStatus "; 117 query+=" LEFT JOIN RunData ON RunData.fRunNumber=RunProcessStatus.fRunNumber";115 query+=" LEFT JOIN RunData USING (fRunNumber) "; 118 116 query+=Form("WHERE DATE_FORMAT(ADDDATE(fRunStart, INTERVAL +13 HOUR), '%%Y/%%m/%%d')='%s' ", 119 117 (*row)[1]); -
trunk/MagicSoft/Mars/datacenter/macros/getdolist.C
r7501 r8996 68 68 #include <TSystem.h> 69 69 70 #include <MSQLServer.h>71 70 #include <TSQLRow.h> 72 71 #include <TSQLResult.h> 73 72 73 #include "MSQLServer.h" 74 74 75 using namespace std; 75 76 … … 77 78 int getdolist(TString table, TString column, TString date, TString listpath) 78 79 { 79 TEnv env("sql.rc"); 80 81 MSQLServer serv(env); 80 MSQLServer serv("sql.rc"); 82 81 if (!serv.IsConnected()) 83 82 { -
trunk/MagicSoft/Mars/datacenter/macros/insertcacofile.C
r7460 r8996 57 57 #include <fstream> 58 58 59 #include <TEnv.h>60 59 #include <TSystem.h> 61 60 62 #include <MSQLServer.h>63 61 #include <TSQLRow.h> 64 62 #include <TSQLResult.h> 63 64 #include "MSQLServer.h" 65 65 66 66 using namespace std; … … 68 68 int insertcacofile(TString runnumber, TString newrunnumber) 69 69 { 70 TEnv env("sql.rc"); 71 72 MSQLServer serv(env); 70 MSQLServer serv("sql.rc"); 73 71 if (!serv.IsConnected()) 74 72 { -
trunk/MagicSoft/Mars/datacenter/macros/insertdataset.C
r8108 r8996 54 54 #include <iomanip> 55 55 56 #include <TEnv.h>57 58 56 #include "MSQLMagic.h" 59 57 … … 62 60 int insertdataset(TString number, TString source, TString wobble, TString comment, Bool_t dummy=kTRUE) 63 61 { 64 TEnv env("sql.rc"); 65 66 MSQLMagic serv(env); 62 MSQLMagic serv("sql.rc"); 67 63 if (!serv.IsConnected()) 68 64 { -
trunk/MagicSoft/Mars/datacenter/macros/plotoptical.C
r8752 r8996 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1. 8 2007-10-07 21:11:01tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotoptical.C,v 1.9 2008-07-05 19:01:42 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 78 78 // 79 79 ///////////////////////////////////////////////////////////////////////////// 80 #include <iostream> 81 #include <iomanip> 82 83 #include <TH1.h> 84 #include <TEnv.h> 85 #include <TPad.h> 86 #include <TLine.h> 87 #include <TText.h> 88 #include <TFrame.h> 89 #include <TStyle.h> 90 #include <TCanvas.h> 91 #include <TPRegexp.h> 92 #include <TSQLRow.h> 93 #include <TSQLResult.h> 94 #include <TGraphErrors.h> 95 96 #include "MTime.h" 97 #include "MAstro.h" 98 #include "MDataSet.h" 99 #include "MSQLMagic.h" 100 #include "MStatusDisplay.h" 101 102 class MPlot : public MParContainer 103 { 104 public: 105 // Possible constants to group-by (average) over a certain period 106 enum GroupBy_t 107 { 108 kNone, 109 kGroupByPrimary, 110 kGroupByHour, 111 kGroupByNight, 112 kGroupByWeek, 113 kGroupByMonth, 114 kGroupBySeason, 115 kGroupByYear 116 }; 117 118 private: 119 MSQLMagic &fServer; // Reference to the sql-server class 120 121 MDataSet *fDataSet; // A possible dtaset to highlite single points 122 123 TString fPrimaryDate; // The name of the data we plot 124 TString fPrimaryNumber; // The corresponding name for the key number 125 TString fSecondary; // The value versus which the second plot is made 126 127 TString fRequestFrom; // Start of a requested date range 128 TString fRequestTo; // End of a requested date range 129 Int_t fRequestPeriod; // A possible requested period 130 131 Float_t fPlotMin; 132 Float_t fPlotMax; 133 134 Float_t fHistMin; 135 Float_t fHistMax; 136 137 TString fDescription; // The description (title) of the plot 138 TString fNameTab; // The name of the tab in the display 139 140 TString fCondition; // An additional condition added to the query 141 GroupBy_t fGroupBy; // A possible Group-By flag 142 143 // -------------------------------------------------------------------------- 144 // 145 // Function to plot the result of the query 146 // 147 void PlotTable(TSQLResult &res, TString name, Float_t fmin, Float_t fmax, Float_t resolution) 148 { 149 // Enable all otions in the statistics box 150 gStyle->SetOptStat(111111); 151 152 // Create TGraph objects 153 TGraph > = res.GetFieldCount()>4 ? *new TGraphErrors : *new TGraph; 154 gt.SetNameTitle(name, Form("%s vs Time", name.Data())); 155 gt.SetMarkerStyle(kFullDotMedium); 156 157 TGraph gz; 158 gz.SetNameTitle(name, Form("%s vs <Zd>", name.Data())); 159 gz.SetMarkerStyle(kFullDotMedium); 160 161 TGraph gt0, gt1; 162 gt0.SetMarkerColor(kRed); 163 gt1.SetMarkerColor(kBlue); 164 gt0.SetMarkerStyle(kFullDotLarge); 165 gt1.SetMarkerStyle(kFullDotLarge); 166 167 TGraph gz0, gz1; 168 gz0.SetMarkerColor(kRed); 169 gz1.SetMarkerColor(kBlue); 170 gz0.SetMarkerStyle(kFullDotLarge); 171 gz1.SetMarkerStyle(kFullDotLarge); 172 173 Int_t first = -1; 174 Int_t last = -1; 175 176 // Loop over the data 177 TSQLRow *row=0; 178 while ((row=res.Next())) 179 { 180 // Get all fields of this row 181 const char *date = (*row)[0]; 182 const char *zd = (*row)[1]; 183 const char *val = (*row)[2]; 184 const char *snum = res.GetFieldCount()>3 ? (*row)[3] : 0; 185 const char *verr = res.GetFieldCount()>4 ? (*row)[5] : 0; 186 187 delete row; 188 189 if (!date || !val || !zd) 190 continue; 191 192 // check if date is valid 193 MTime t(date); 194 if (!t.SetSqlDateTime(date)) 195 continue; 196 197 // check if it belongs to the requested MAGIC period 198 if (fRequestPeriod>0 && MAstro::GetMagicPeriod(t.GetMjd())!=fRequestPeriod) 199 continue; 200 201 // Get axis range 202 if (first<0) 203 first = TMath::Nint(TMath::Floor(t.GetMjd())); 204 last = TMath::Nint(TMath::Ceil(t.GetMjd())); 205 206 // Convert a possible key number into a integer 207 UInt_t seq = snum ? atoi(snum) : 0; 208 209 // convert primary and secondary value into floats 210 Float_t value = atof(val); 211 Float_t zenith = atof(zd); 212 213 // If a datset is given add the point to the special TGraphs 214 // used for highliting these dates 215 if (fDataSet) 216 { 217 if (fDataSet->HasOnSequence(seq)) 218 { 219 gt1.SetPoint(gt1.GetN(), t.GetAxisTime(), value); 220 gz1.SetPoint(gz1.GetN(), zenith, value); 221 } 222 223 if (fDataSet->HasOffSequence(seq)) 224 { 225 gt0.SetPoint(gt0.GetN(), t.GetAxisTime(), value); 226 gz0.SetPoint(gz0.GetN(), zenith, value); 227 } 228 } 229 230 // Add Data to TGraph 231 gt.SetPoint(gt.GetN(), t.GetAxisTime(), value); 232 gz.SetPoint(gz.GetN(), zenith, value); 233 234 // Set error-bar, if one 235 if (verr) 236 static_cast<TGraphErrors&>(gt).SetPointError(gt.GetN()-1, 0, atof(verr)); 237 } 238 239 // If this is done earlier the plots remain empty since root 5.12/00 240 if (fmax>fmin) 241 { 242 gt.SetMinimum(fmin); 243 gt.SetMaximum(fmax); 244 gz.SetMinimum(fmin); 245 gz.SetMaximum(fmax); 246 } 247 248 gROOT->SetSelectedPad(0); 249 250 // Create a TCanvas or open a new tab 251 TString title = fNameTab.IsNull() ? name(name.First('.')+2, name.Length()) : fNameTab; 252 TCanvas &c = fDisplay ? fDisplay->AddTab(title) : *new TCanvas; 253 // Set fillcolor, remove border and divide pad 254 c.SetFillColor(kWhite); 255 c.SetBorderMode(0); 256 c.Divide(1,2); 257 258 // Output mean and rms to console 259 cerr << setprecision(4) << setw(10) << title << ": "; 260 if (gt.GetN()==0) 261 { 262 cerr << " <empty>" << endl; 263 return; 264 } 265 cerr << setw(8) << gt.GetMean(2) << "+-" << setw(8) << gt.GetRMS(2) << " "; 266 if (gt0.GetN()>0 || gt1.GetN()>0) 267 { 268 cerr << setw(8) << gt1.GetMean(2) << "+-" << setw(8) << gt1.GetRMS(2) << " "; 269 cerr << setw(8) << gt0.GetMean(2) << "+-" << setw(8) << gt0.GetRMS(2); 270 } 271 cerr << endl; 272 273 TVirtualPad *pad = gPad; 274 275 // draw contants of pad 2 (counting starts at 0) 276 pad->cd(2); 277 gPad->SetBorderMode(0); 278 gPad->SetFrameBorderMode(0); 279 gPad->SetGridy(); 280 281 gPad->SetLeftMargin(0.06); 282 gPad->SetRightMargin(0.06); 283 gPad->SetBottomMargin(0.08); 284 285 // format axis 286 TH1 *h = gt.GetHistogram(); 287 288 h->SetXTitle("Time"); 289 h->SetYTitle(name); 290 h->GetXaxis()->SetTimeDisplay(1); 291 h->GetYaxis()->SetTitleOffset(0.8); 292 h->GetXaxis()->SetTitleOffset(1.0); 293 h->GetXaxis()->SetLabelOffset(0.01); 294 295 // draw TGraph 296 gt.DrawClone("AP"); 297 if (gt0.GetN()>0) 298 gt0.DrawClone("P"); 299 if (gt1.GetN()>0) 300 gt1.DrawClone("P"); 301 302 // Add lines and text showing the MAGIC periods 303 TLine l; 304 TText t; 305 Int_t num=0; 306 l.SetLineStyle(kDotted); 307 l.SetLineColor(kBlue); 308 t.SetTextColor(kBlue); 309 l.SetLineWidth(1); 310 t.SetTextSize(h->GetXaxis()->GetLabelSize()); 311 t.SetTextAlign(21); 312 Int_t p0 = MAstro::GetMagicPeriod(first); 313 for (Int_t p = first; p<last; p++) 314 { 315 Int_t p1 = MAstro::GetMagicPeriod(p); 316 if (p1!=p0) 317 { 318 l.DrawLine(MTime(p).GetAxisTime(), h->GetMinimum(), MTime(p).GetAxisTime(), h->GetMaximum()); 319 t.DrawText(MTime(p+15).GetAxisTime(), h->GetMaximum(), Form("%d", p1)); 320 num++; 321 } 322 p0 = p1; 323 } 324 if (num<4) 325 gPad->SetGridx(); 326 327 const Double_t min = fHistMin>fHistMax ? h->GetMinimum()-resolution/2 : fHistMin; 328 const Double_t max = fHistMin>fHistMax ? h->GetMaximum()+resolution/2 : fHistMax; 329 330 // Use this to save the pad with the time development to a file 331 //gPad->SaveAs(Form("plotdb-%s.eps", title.Data())); 332 333 // Go back to first (upper) pad, format it and divide it again 334 pad->cd(1); 335 gPad->SetBorderMode(0); 336 gPad->SetFrameBorderMode(0); 337 gPad->Divide(2,1); 338 339 TVirtualPad *pad2 = gPad; 340 341 // format left pad 342 pad2->cd(1); 343 gPad->SetBorderMode(0); 344 gPad->SetFrameBorderMode(0); 345 gPad->SetGridx(); 346 gPad->SetGridy(); 347 348 // Create histogram 349 const Int_t n = resolution>0 ? TMath::Nint((max-min)/resolution) : 50; 350 351 TH1F hist("Hist", Form("Distribution of %s", fDescription.IsNull() ? name.Data() : fDescription.Data()), n, min, max); 352 hist.SetDirectory(0); 353 354 // Fill data into histogra, 355 for (int i=0; i<gt.GetN(); i++) 356 hist.Fill(gt.GetY()[i]); 357 358 // Format histogram 359 if (fDescription.IsNull()) 360 hist.SetXTitle(name); 361 hist.SetYTitle("Counts"); 362 363 // plot histogram 364 hist.DrawCopy(""); 365 366 // format right pad 367 pad2->cd(2); 368 gPad->SetBorderMode(0); 369 gPad->SetFrameBorderMode(0); 370 gPad->SetGridy(); 371 372 // format graph 373 TH1 *h2 = gz.GetHistogram(); 374 375 h2->SetXTitle("Zd"); 376 h2->SetYTitle(name); 377 378 // draw graph 379 gz.DrawClone("AP"); 380 381 if (gz0.GetN()>0) 382 gz0.DrawClone("P"); 383 if (gz1.GetN()>0) 384 gz1.DrawClone("P"); 385 } 386 387 public: 388 MPlot(MSQLMagic &server) : fServer(server), fDataSet(NULL), 389 fRequestPeriod(-1), fPlotMin(0), fPlotMax(-1), fHistMin(0), fHistMax(-1), fGroupBy(kNone) 390 { 391 } 392 ~MPlot() 393 { 394 if (fDataSet) 395 delete fDataSet; 396 } 397 void SetDataSet(const TString filename) 398 { 399 if (fDataSet) 400 { 401 delete fDataSet; 402 fDataSet = NULL; 403 } 404 if (!filename.IsNull()) 405 fDataSet = new MDataSet(filename); 406 } 407 void SetPlotRange(Float_t min, Float_t max, Int_t n=5) { fPlotMin = min; fPlotMax = max; } 408 void SetHistRange(Float_t min, Float_t max) { fHistMin = min; fHistMax = max; } 409 void SetRequestRange(const char *from="", const char *to="") { fRequestFrom = from; fRequestTo = to; } 410 void SetRequestPeriod(Int_t n=-1) { fRequestPeriod = n; } 411 void SetCondition(const char *cond="") { fCondition = cond; } 412 void SetDescription(const char *d, const char *t=0) { fDescription = d; fNameTab = t; } 413 void SetGroupBy(GroupBy_t b=kGroupByWeek) { fGroupBy=b; } 414 void SetPrimaryDate(const char *ts) { fPrimaryDate=ts; } 415 void SetPrimaryNumber(const char *ts) { fPrimaryNumber=ts; } 416 void SetSecondary(const char *ts) { fSecondary=ts; } 417 418 Int_t QueryKeyOfSource(TString src) 419 { 420 return fServer.QueryKeyOfName("Object", src, kFALSE); 421 } 422 423 Bool_t Plot(const char *value, Float_t min=0, Float_t max=-1, Float_t resolution=0) 424 { 425 TString named = fPrimaryDate; 426 TString named2 = fSecondary; 427 TString namev = value; 428 429 TString tablev = namev(0, namev.First('.')); 430 TString valuev = namev(namev.First('.')+1, namev.Length()); 431 432 TString tabled = named(0, named.First('.')); 433 TString valued = named(named.First('.')+1, named.Length()); 434 435 TString query="SELECT "; 436 switch (fGroupBy) 437 { 438 case kNone: 439 case kGroupByPrimary: 440 query += Form("%s AS %s", valued.Data(), valued.Data()+1); 441 break; 442 case kGroupByHour: 443 query += Form("DATE_FORMAT(%s, '%%Y-%%m-%%d %%H:30:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 444 break; 445 case kGroupByNight: 446 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-%%d 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 447 break; 448 case kGroupByWeek: 449 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%x%%v') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 450 break; 451 case kGroupByMonth: 452 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 453 break; 454 case kGroupBySeason: 455 //query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-%%m-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 456 break; 457 case kGroupByYear: 458 query += Form("DATE_FORMAT(ADDDATE(%s,Interval 12 hour), '%%Y-08-15 00:00:00') AS %s ", fPrimaryDate.Data(), valued.Data()+1); 459 break; 460 } 461 462 if (fGroupBy==kNone) 463 { 464 query += ", "; 465 query += fSecondary; 466 query += ", "; 467 query += value; 468 query += ", "; 469 query += fPrimaryNumber; 470 query += " "; 471 } 472 else 473 { 474 query += ", AVG("; 475 query += fSecondary; 476 query += "), AVG("; 477 query += value; 478 query += "), "; 479 query += fPrimaryNumber; 480 query += ", STD("; 481 query += fSecondary; 482 query += "), STD("; 483 query += value; 484 query += ") "; 485 } 486 487 query += Form("FROM %s ", tabled.Data()); 488 489 TString where(fCondition); 490 491 const Bool_t interval = !fRequestFrom.IsNull() && !fRequestTo.IsNull(); 492 if (interval) 493 { 494 if (!where.IsNull()) 495 where += " AND "; 496 where += Form("%s BETWEEN '%s' AND '%s' ", 497 fPrimaryDate.Data(), fRequestFrom.Data(), fRequestTo.Data()); 498 } 499 500 if (!where.IsNull()) 501 where += " AND "; 502 where += fCondition; 503 where += " "; 504 505 // ------------------------------ 506 507 query += fServer.GetJoins(tabled, query+" "+where); 508 509 if (!where.IsNull()) 510 { 511 query += "WHERE "; 512 query += where; 513 } 514 515 if (fGroupBy!=kNone) 516 { 517 query += Form("GROUP BY %s ", valued.Data()+1); 518 //query += Form(" HAVING COUNT(%s)=(COUNT(*)+1)/2 ", valuev.Data()); 519 } 520 query += Form("ORDER BY %s ", valued.Data()+1); 521 522 // ------------------------------ 523 524 TSQLResult *res = fServer.Query(query); 525 if (!res) 526 return kFALSE; 527 528 if (max>min) 529 PlotTable(*res, namev, min, max, resolution); 530 else 531 PlotTable(*res, namev, fPlotMin, fPlotMax, resolution); 532 533 delete res; 534 return kTRUE; 535 } 536 }; 537 538 void plotall(MPlot &plot, TString source) 80 #include "plotdb.C" 81 82 void plotalloptical(MPlot &plot, TString source) 539 83 { 540 84 // Setup here the values for timestamp and secondary (upper/right) plot … … 548 92 if (!source.IsNull()) 549 93 { 550 const Int_t key = plot. QueryKeyOfSource(source);94 const Int_t key = plot.GetServer().QueryKeyOfName("Object", source, kFALSE); 551 95 if (key<0) 552 96 return; 553 97 cond += Form(" AND Object.fObjectKEY=%d", key); 554 555 98 } 556 99 … … 625 168 int plotoptical(TString from, TString to, const char *source=0) 626 169 { 627 TEnv env("sql.rc"); 628 629 MSQLMagic serv(env); 170 MSQLMagic serv("sql.rc"); 630 171 if (!serv.IsConnected()) 631 172 { … … 648 189 plot.SetDisplay(d); 649 190 plot.SetRequestRange(from, to); 650 plotall (plot, source);191 plotalloptical(plot, source); 651 192 // Use this to create output plots automatically 652 193 // d->SaveAsRoot("plotoptical.root"); … … 658 199 int plotoptical(const char *source) 659 200 { 660 TEnv env("sql.rc"); 661 662 MSQLMagic serv(env); 201 MSQLMagic serv("sql.rc"); 663 202 if (!serv.IsConnected()) 664 203 { … … 681 220 plot.SetDisplay(d); 682 221 plot.SetRequestRange("", ""); 683 plotall (plot, source);222 plotalloptical(plot, source); 684 223 // Use this to create output plots automatically 685 224 // d->SaveAsRoot("plotoptical.root"); … … 691 230 int plotoptical(Int_t period, const char *source="") 692 231 { 693 TEnv env("sql.rc"); 694 695 MSQLMagic serv(env); 232 MSQLMagic serv("sql.rc"); 696 233 if (!serv.IsConnected()) 697 234 { … … 714 251 plot.SetDisplay(d); 715 252 plot.SetRequestPeriod(period); 716 plotall (plot, source);253 plotalloptical(plot, source); 717 254 718 255 // Use this to create output plots automatically -
trunk/MagicSoft/Mars/datacenter/macros/plotrundb.C
r8994 r8996 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1. 5 2008-07-03 16:29:48tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotrundb.C,v 1.6 2008-07-05 19:01:42 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 111 111 int plotrundb(TString from, TString to, const char *dataset=0) 112 112 { 113 TEnv env("sql.rc"); 114 115 MSQLMagic serv(env); 113 MSQLMagic serv("sql.rc"); 116 114 if (!serv.IsConnected()) 117 115 { … … 143 141 int plotrundb(const char *ds) 144 142 { 145 TEnv env("sql.rc"); 146 147 MSQLMagic serv(env); 143 MSQLMagic serv("sql.rc"); 148 144 if (!serv.IsConnected()) 149 145 { … … 175 171 int plotrundb(Int_t period, const char *dataset="") 176 172 { 177 TEnv env("sql.rc"); 178 179 MSQLMagic serv(env); 173 MSQLMagic serv("sql.rc"); 180 174 if (!serv.IsConnected()) 181 175 { -
trunk/MagicSoft/Mars/datacenter/macros/plotstat.C
r8983 r8996 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: plotstat.C,v 1. 6 2008-06-19 15:18:57tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: plotstat.C,v 1.7 2008-07-05 19:01:42 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 48 48 49 49 #include <TH2.h> 50 #include <TEnv.h>51 50 #include <TPad.h> 52 51 #include <TLine.h> … … 663 662 int plotstat(Int_t first=-1, Int_t last=-1) 664 663 { 665 TEnv env("sql.rc"); 666 667 MSQLServer serv(env); 664 MSQLServer serv("sql.rc"); 668 665 if (!serv.IsConnected()) 669 666 { -
trunk/MagicSoft/Mars/datacenter/macros/resetallruns.C
r7460 r8996 49 49 #include <fstream> 50 50 51 #include <TEnv.h>52 53 #include <MSQLServer.h>54 51 #include <TSQLRow.h> 55 52 #include <TSQLResult.h> 53 54 #include "MSQLServer.h" 56 55 57 56 using namespace std; … … 60 59 int resetallruns(TString filename, TString column) 61 60 { 62 TEnv env("sql.rc"); 63 64 MSQLServer serv(env); 61 MSQLServer serv("sql.rc"); 65 62 if (!serv.IsConnected()) 66 63 { -
trunk/MagicSoft/Mars/datacenter/macros/setstatus.C
r7486 r8996 18 18 ! Author(s): Daniela Dorner, 01/2005 <mailto:dorner@astro.uni-wuerzburg.de> 19 19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 620 ! Copyright: MAGIC Software Development, 2000-2008 21 21 ! 22 22 ! … … 50 50 // 51 51 ///////////////////////////////////////////////////////////////////////////// 52 53 52 #include <iostream> 54 53 #include <iomanip> … … 56 55 57 56 #include <TEnv.h> 58 59 #include <MTime.h>60 61 #include <MSQLServer.h>62 57 #include <TSQLRow.h> 63 58 #include <TSQLResult.h> 59 60 #include "MTime.h" 61 #include "MSQLServer.h" 64 62 65 63 using namespace std; -
trunk/MagicSoft/Mars/datacenter/macros/writedatasetfile.C
r8248 r8996 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: writedatasetfile.C,v 1. 2 2007-01-12 17:33:10 snruegamExp $2 ! $Name: not supported by cvs2svn $:$Id: writedatasetfile.C,v 1.3 2008-07-05 19:01:43 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 20 20 ! Author(s): Thomas Bretz, 11/2006 <mailto:tbretz@astro.uni-wuerzburg.de> 21 21 ! 22 ! Copyright: MAGIC Software Development, 2000-200 622 ! Copyright: MAGIC Software Development, 2000-2008 23 23 ! 24 24 ! … … 50 50 #include <TSQLResult.h> 51 51 52 #include <TEnv.h>53 52 #include <errno.h> 54 53 … … 91 90 //get sequence information from database 92 91 TString query0(Form("SELECT fSourceName, fComment, fDataSetName, fRunTime, fObservationModeKEY" 93 " FROM DataSets LEFT JOIN Source ON" 94 " Source.fSourceKEY=DataSets.fSourceKEY" 92 " FROM DataSets LEFT JOIN Source USING (fSourceKEY)" 95 93 " WHERE fDataSetNumber=%d", dsno)); 96 94 … … 167 165 int writedatasetfile(Int_t dsno, TString seqpath) 168 166 { 169 TEnv env("sql.rc"); 170 171 MSQLMagic serv(env); 167 MSQLMagic serv("sql.rc"); 172 168 if (!serv.IsConnected()) 173 169 { -
trunk/MagicSoft/Mars/mbase/MTime.cc
r8946 r8996 138 138 // -------------------------------------------------------------------------- 139 139 // 140 // Return date as year(y), month(m), day(d). If the time is afternoon 141 // (>=13:00:00) the date of the next day is returned. 142 // 143 MTime MTime::GetDateOfSunrise() const 144 { 145 UShort_t y; 146 Byte_t m; 147 Byte_t d; 148 149 MAstro::Mjd2Ymd(fMjd, y, m, d); 150 151 return MTime(y, m, d); 152 } 153 154 // -------------------------------------------------------------------------- 155 // 140 156 // GetMoonPhase - calculate phase of moon as a fraction: 141 157 // Returns -1 if calculation failed … … 167 183 // 53257.8 --> 53258 168 184 // 53258.3 --> 53258 169 // Which is the time between 13h and 12:59h of the following day. To185 // Which is the time between 13h and 12:59h of the following day. To 170 186 // this day-period we assign the moon-period at midnight. To get 171 187 // the MAGIC definition we now substract 284. -
trunk/MagicSoft/Mars/mbase/MTime.h
r8988 r8996 117 117 TString GetFileName() const; 118 118 void GetDate(UShort_t &y, Byte_t &m, Byte_t &d) const; 119 MTime GetDateOfSunrise() const; 119 120 void GetDateOfSunrise(UShort_t &y, Byte_t &m, Byte_t &d) const; 120 121 TTime GetRootTime() const; -
trunk/MagicSoft/Mars/mhflux/MHAlpha.cc
r8991 r8996 780 780 delete pad->GetPad(2); 781 781 782 if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1 || fHTime.GetBin Content(1)!=0)782 if (fTimeEffOn && fTime || fHTime.GetNbinsX()>1 || fHTime.GetBinError(1)>0) 783 783 { 784 784 pad->cd(3); -
trunk/MagicSoft/Mars/mimage/MHHillas.cc
r8677 r8996 109 109 bins.Apply(*fSize); 110 110 111 fCenter = new TH2F("Center", "Center of Ellipse", 51, -445, 445, 51, -445, 445);111 fCenter = new TH2F("Center", "Center of gravity", 51, -445, 445, 51, -445, 445); 112 112 fCenter->SetDirectory(NULL); 113 113 fCenter->SetXTitle("x [mm]"); -
trunk/MagicSoft/Mars/mjobs/JobsLinkDef.h
r8988 r8996 6 6 7 7 #pragma link C++ class MSequence+; 8 #pragma link C++ class MSequenceSQL+; 8 9 #pragma link C++ class MDataSet+; 9 10 -
trunk/MagicSoft/Mars/mjobs/MSequence.cc
r8989 r8996 171 171 // 172 172 ///////////////////////////////////////////////////////////////////////////// 173 #include "MSequence .h"173 #include "MSequenceSQL.h" 174 174 175 175 #include <stdlib.h> … … 575 575 // -------------------------------------------------------------------------- 576 576 // 577 // Get LightCondition from resource file and convert it to LIghtCondition_t 578 // 579 MSequence::LightCondition_t MSequence::ReadLightCondition(TEnv &env, const char *prefix) const 580 { 581 TString str = GetEnvValue2(env, prefix, "LightConditions", "n/a"); 577 // Get LightCondition from str and convert it to LightCondition_t 578 // 579 MSequence::LightCondition_t MSequence::GetLightCondition(const TString &str) const 580 { 582 581 if (!str.CompareTo("n/a", TString::kIgnoreCase)) 583 582 return kNA; … … 634 633 fPeriod = GetEnvValue2(env, prefix, "Period", -1); 635 634 636 fLightCondition = ReadLightCondition(env, prefix);637 638 635 TString str; 636 str = GetEnvValue2(env, prefix, "LightConditions", "n/a"); 637 fLightCondition = GetLightCondition(str); 638 639 639 str = GetEnvValue2(env, prefix, "Start", ""); 640 640 fStart.SetSqlDateTime(str); 641 641 642 str = GetEnvValue2(env, prefix, "Night", ""); 642 643 str += " 00:00:00"; … … 667 668 env.PrintUntouched(); 668 669 } 670 } 671 672 MSequence::MSequence(const char *fname, UInt_t seq) 673 { 674 *this = MSequenceSQL(fname, seq); 669 675 } 670 676 … … 875 881 return; 876 882 } 877 out << "# Path: " << GetFileName() << endl; 878 out << "# Name: " << GetBaseName() << endl; 883 if (!fFileName.IsNull()) 884 out << "# FileName: " << fFileName << endl; 885 if (!fDataPath.IsNull()) 886 out << "# DataPath: " << fDataPath << endl; 879 887 out << endl; 880 888 if (pre.IsNull()) … … 885 893 out << pre << "Period: " << fPeriod << endl; 886 894 if (fNight!=MTime()) 887 out << pre << "Night: " << fNight << endl;895 out << pre << "Night: " << fNight.GetStringFmt("%Y-%m-%d") << endl; 888 896 out << endl; 889 897 out << pre << "LightCondition: "; … … 894 902 case kTwilight: out << "Twilight" << endl; break; 895 903 case kMoon: out << "Moon" << endl; break; 896 case kDay: out << "Day" << endl; break;904 case kDay: out << "Day" << endl; break; 897 905 } 898 906 899 907 if (fStart!=MTime()) 900 out << pre << "Start: " << fStart << endl;908 out << pre << "Start: " << fStart.GetSqlDateTime() << endl; 901 909 if (fLastRun>=0) 902 910 out << pre << "LastRun: " << fLastRun << endl; -
trunk/MagicSoft/Mars/mjobs/MSequence.h
r8989 r8996 14 14 class MSequence : public MParContainer 15 15 { 16 friend class MSequenceSQL; 16 17 public: 17 18 enum LightCondition_t { kNA, kNoMoon, kTwilight, kMoon, kDay }; … … 67 68 void Split(const TEnv &env, const TString &prefix, const char *name, TArrayI &data, TArrayI &sub) const; 68 69 69 LightCondition_t ReadLightCondition(TEnv &env, const char *prefix) const;70 LightCondition_t GetLightCondition(const TString &str) const; 70 71 71 72 // Helper for file setup … … 92 93 public: 93 94 MSequence() : fSequence((UInt_t)-1), fLastRun((UInt_t)-1), 94 fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), f MonteCarlo(kFALSE)95 fNumEvents((UInt_t)-1), fPeriod((UInt_t)-1), fLightCondition(kNA), fMonteCarlo(kFALSE) 95 96 { 96 97 fName = "MSequence"; … … 98 99 } 99 100 MSequence(const char *fname, const char *path="", UInt_t id=(UInt_t)-1); 101 MSequence(const char *fname, UInt_t seq); 100 102 MSequence(const MSequence &s) : MParContainer(s), 101 103 fFileName(s.fFileName), fDataPath(s.fDataPath), 102 104 fSequence(s.fSequence), fStart(s.fStart), 103 105 fLastRun(s.fLastRun), fNumEvents(s.fNumEvents), fPeriod(s.fPeriod), 104 fNight(s.fNight), fProject(s.fProject), fSource(s.fSource), 106 fNight(s.fNight), fLightCondition(s.fLightCondition), 107 fProject(s.fProject), fSource(s.fSource), 105 108 fTriggerTable(s.fTriggerTable), fHvSettings(s.fHvSettings), 106 fRuns(s.fRuns), fCalRuns(s.fCalRuns), fPedRuns(s.fPedRuns), 107 fDatRuns(s.fDatRuns), fMonteCarlo(s.fMonteCarlo) { } 109 fRuns(s.fRuns), fRunsSub(s.fRunsSub), fCalRuns(s.fCalRuns), 110 fCalRunsSub(s.fCalRunsSub), fPedRuns(s.fPedRuns), 111 fPedRunsSub(s.fPedRunsSub), fDatRuns(s.fDatRuns), 112 fDatRunsSub(s.fDatRunsSub), fExclRuns(s.fExclRuns), 113 fExclRunsSub(s.fExclRunsSub), fMonteCarlo(s.fMonteCarlo) { } 108 114 109 115 // I/O -
trunk/MagicSoft/Mars/mjobs/Makefile
r8988 r8996 24 24 -I../mtools -I../mimage -I../mpointing -I../mastro -I../mfbase \ 25 25 -I../mhvstime -I../mtrigger -I../mmuon -I../mmc -I../mmovie \ 26 -I../mextralgo -I../mhflux 26 -I../mextralgo -I../mhflux -I../msql 27 27 28 28 SRCFILES = MSequence.cc \ 29 MSequenceSQL.cc \ 29 30 MDataSet.cc \ 30 31 MJob.cc \ -
trunk/MagicSoft/Mars/msql/MSQLMagic.cc
r8987 r8996 187 187 } 188 188 189 Bool_t MSQLMagic::ExistStr(const char *column, const char *table, const char *test) 190 { 191 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test)); 189 // -------------------------------------------------------------------------- 190 // 191 // Check if the column of an entry in a table is existing and not null. 192 // The entry is defined by column=test (column name) and a optional 193 // WHERE statement. 194 // 195 Bool_t MSQLMagic::ExistStr(const char *column, const char *table, const char *test, const char *where) 196 { 197 TString query(Form("SELECT %s FROM %s WHERE %s='%s' %s %s", column, table, column, test, where?"AND":"", where?where:"")); 192 198 TSQLResult *res = Query(query); 193 199 if (!res) -
trunk/MagicSoft/Mars/msql/MSQLMagic.h
r8942 r8996 44 44 Int_t QueryKeyOfVal(const char *col, const char *val); 45 45 Int_t QueryKeyOf(const char *col, const char *ext, const char *val); 46 Bool_t ExistStr(const char *column, const char *table, const char *test );46 Bool_t ExistStr(const char *column, const char *table, const char *test, const char *where=0); 47 47 48 48 Int_t Insert(const char *table, const char *vars, const char *where=0); -
trunk/MagicSoft/Mars/msql/MSQLServer.cc
r8907 r8996 1 1 /* ======================================================================== *\ 2 ! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.1 5 2008-06-02 08:46:49tbretz Exp $2 ! $Name: not supported by cvs2svn $:$Id: MSQLServer.cc,v 1.16 2008-07-05 18:57:35 tbretz Exp $ 3 3 ! -------------------------------------------------------------------------- 4 4 ! … … 668 668 } 669 669 670 // -------------------------------------------------------------------------- 671 // 672 // Instantiate a dabase connection either by 673 // mysql://user:password@url/database 674 // or by a resource file (in teh given string doesn't contain mysql://) 675 // 670 676 MSQLServer::MSQLServer(const char *u) : fType(kIsZombie) /*FOLD00*/ 671 677 { 672 TString url(u); 673 TString user, pasw; 674 675 if (!Split(url, user, pasw)) 676 { 677 fType = kIsZombie; 678 return; 679 } 680 Init(url, user, pasw); 678 if (TString(u).Contains("mysql://", TString::kIgnoreCase)) 679 { 680 TString url(u); 681 TString user, pasw; 682 683 if (!Split(url, user, pasw)) 684 { 685 fType = kIsZombie; 686 return; 687 } 688 Init(url, user, pasw); 689 } 690 else 691 { 692 TEnv env(u); 693 InitEnv(env); 694 } 681 695 } 682 696 … … 781 795 if (key=="PRI") 782 796 { 783 rc = (*row)[0]; 784 break; 797 if (!rc.IsNull()) 798 rc += ", "; 799 rc += (*row)[0]; 785 800 } 786 801 delete row; … … 823 838 824 839 const TString tab = expr(0, expr.First('.')); 825 const TString var = expr(expr.First('.')+1, expr.Length());840 //const TString var = expr(expr.First('.')+1, expr.Length()); 826 841 827 842 // If the table found is the primary table itself skip it. … … 838 853 continue; 839 854 840 joins += Form("LEFT JOIN %s ON %s.%s=%s.%s ", tab.Data(), 841 table, prim.Data(), tab.Data(), prim.Data()); 855 joins += Form("LEFT JOIN %s USING (%s) ", tab.Data(), prim.Data()); 842 856 } 843 857 -
trunk/MagicSoft/Mars/mtools/MCalendar.cc
r8958 r8996 262 262 #include <TPaveText.h> 263 263 #include <THashList.h> 264 #include <TObjArray.h> 264 265 265 266 #include "MEnv.h"
Note:
See TracChangeset
for help on using the changeset viewer.