Changeset 8992 for trunk/MagicSoft/Mars
- Timestamp:
- 07/03/08 16:28:37 (16 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r8991 r8992 18 18 19 19 -*-*- END OF LINE -*-*- 20 21 2008/07/03 Thomas Bretz 22 23 * datacenter/macros/filldotrun.C: 24 - Replaced MSQKServer by MSQLMagic 25 - this made local functions obsolete 26 - added new format 20080519 including telescope- and file-number 27 - simplified the if-clauses testing for version numbers (due to the 28 initial check only some version numbers allowed anyway) 29 30 20 31 21 32 2008/07/01 Thomas Bretz -
trunk/MagicSoft/Mars/datacenter/macros/filldotrun.C
r8881 r8992 19 19 ! Author(s): Thomas Bretz, 08/2004 <mailto:tbretz@astro.uni-wuerzburg.de> 20 20 ! 21 ! Copyright: MAGIC Software Development, 2000-200 621 ! Copyright: MAGIC Software Development, 2000-2008 22 22 ! 23 23 ! … … 42 42 // 070416-0, 43 43 // 080220-0 44 // 080519-0 44 45 // 45 46 // Usage: … … 82 83 #include <TRegexp.h> 83 84 84 #include <TSQLRow.h>85 #include <TSQLResult.h>86 87 85 #include "MTime.h" 88 86 #include "MDirIter.h" 89 #include "MSQL Server.h"87 #include "MSQLMagic.h" 90 88 91 89 using namespace std; 92 90 93 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, const char *test) 94 { 95 TString query(Form("SELECT %s FROM %s WHERE %s='%s'", column, table, column, test)); 96 TSQLResult *res = serv.Query(query); 97 if (!res) 98 return kFALSE; 99 100 Bool_t rc = kFALSE; 101 102 TSQLRow *row=res->Next(); 103 if (row && (*row)[0]) 104 rc=kTRUE; 105 106 delete res; 107 return rc; 108 } 109 110 //get key for the value 111 // if value is not existing, insert value and get key 112 Int_t QueryNameKEY(MSQLServer &serv, Bool_t dummy, const char *col, const char *name, Bool_t insert=kTRUE) 113 { 114 TString query; 115 116 query = Form("SELECT f%sKEY FROM %s WHERE f%sName='%s'", col, col, col, name); 117 TSQLResult *res = serv.Query(query); 118 if (!res) 119 return -1; 120 121 TSQLRow *row=res->Next(); 122 123 Int_t rc = row && (*row)[0] ? atoi((*row)[0]) : -1; 124 125 delete res; 126 127 if (rc>=0) 128 return rc; 129 130 if (!insert) 131 return -1; 132 133 //insert new value 134 query = Form("INSERT %s (f%sName) VALUES (\"%s\");", col, col, name); 135 136 if (dummy) 137 { 138 cout << query << endl; 139 return 0; 140 } 141 142 res=serv.Query(query); 143 if (!res) 144 return -1; 145 146 delete res; 147 148 Int_t key = QueryNameKEY(serv, dummy, col, name, kFALSE); 149 if (key>0) 150 { 151 cout << "New " << col << ": " << name << endl; 152 return key; 153 } 154 155 cout << "ERROR: " << query << endl; 156 return kFALSE; 157 } 158 159 160 Int_t insert(MSQLServer &serv, Bool_t dummy, TString filename) 91 92 Int_t insert(MSQLMagic &serv, Bool_t dummy, TString filename) 161 93 { 162 94 ifstream fin(filename); … … 193 125 version!=200603300 && version!=200604010 && version!=200608080 && 194 126 version!=200704160 && 195 version!=200802200) 127 version!=200802200 && 128 version!=200805190) 196 129 { 197 130 cout << filename << ": File Version unknown - please update the macro!" << endl; … … 206 139 while (1) 207 140 { 141 Int_t telnumber = 1; 142 if (version >=200805190) 143 { 144 strng.ReadToDelim(fin, ' '); 145 if (!fin) 146 break; 147 if (strng[0]!='M') 148 { 149 cout << "First character is not an M." << endl; 150 cout << strng << endl; 151 strng.ReadLine(fin); 152 continue; 153 } 154 155 telnumber = atoi(strng.Data()+1); 156 } 157 208 158 // ========== Col 1: Run Number ========= 209 159 //Reading the line … … 224 174 } 225 175 226 //cout << "RunNo: " << runnumber << " "; 227 228 if (ExistStr(serv, "fRunNumber", "RunData", strng.Data())) 176 Int_t filenumber = 0; 177 if (version >=200805190) 178 { 179 strng.ReadToDelim(fin, ' '); 180 filenumber = atoi(strng.Data()); 181 } 182 183 if (serv.ExistStr("fRunNumber", "RunData", strng)) 229 184 { 230 185 // FIXME: Maybe we can implement an switch to update mode? … … 239 194 strng="n/a"; 240 195 241 Int_t runtype = QueryNameKEY(serv, dummy, "RunType", strng.Data(), kFALSE);196 Int_t runtype = serv.QueryKeyOfName("RunType", strng, kFALSE); 242 197 if (runtype<0) 243 198 { … … 275 230 strng="Unavailable"; 276 231 277 Int_t sourcekey = QueryNameKEY(serv, dummy,"Source", strng.Data());232 Int_t sourcekey = serv.QueryKeyOfName("Source", strng.Data()); 278 233 if (sourcekey<0) 279 234 { … … 303 258 strng="Unavailable"; 304 259 305 Int_t projkey = QueryNameKEY(serv, dummy, "Project", strng.Data());260 Int_t projkey = serv.QueryKeyOfName("Project", strng); 306 261 if (projkey<0) 307 262 { … … 321 276 if (version >=200411130) 322 277 { 323 l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", strng.Data());278 l1triggerkey = serv.QueryKeyOfName("L1TriggerTable", strng); 324 279 if (l1triggerkey<0) 325 280 { … … 332 287 strng="n/a"; 333 288 334 l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", strng.Data());289 l2triggerkey = serv.QueryKeyOfName("L2TriggerTable", strng); 335 290 if (l2triggerkey<0) 336 291 { … … 356 311 case 0: 357 312 { 358 l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", strng.Data());313 l2triggerkey = serv.QueryKeyOfName("L2TriggerTable", strng); 359 314 if (l2triggerkey<0) 360 315 { … … 374 329 L1TT=strng(0,6); 375 330 376 l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", L1TT.Data());331 l1triggerkey = serv.QueryKeyOfName("L1TriggerTable", L1TT); 377 332 if (l1triggerkey<0) 378 333 { … … 381 336 } 382 337 383 l2triggerkey = QueryNameKEY(serv, dummy, "L2TriggerTable", L2TT.Data());338 l2triggerkey = serv.QueryKeyOfName("L2TriggerTable", L2TT); 384 339 if (l2triggerkey<0) 385 340 { … … 392 347 case 2: 393 348 { 394 l1triggerkey = QueryNameKEY(serv, dummy, "L1TriggerTable", strng.Data());349 l1triggerkey = serv.QueryKeyOfName("L1TriggerTable", strng); 395 350 if (l1triggerkey<0) 396 351 { … … 443 398 strng="n/a"; 444 399 445 Int_t hvkey = QueryNameKEY(serv, dummy, "HvSettings", strng.Data());400 Int_t hvkey = serv.QueryKeyOfName("HvSettings", strng); 446 401 if (hvkey<0) 447 402 { … … 458 413 Int_t triggerdelaytablekey=1; 459 414 Int_t calibrationscriptkey=1; 460 if (version==200411130 || version==200412090 || version==200412210 461 || version==200502240 || version==200503170 || version==200503220 462 || version==200504010 || version==200504130 || version==200504150 463 || version==200507140 || version==200507190 || version==200508290 464 || version==200510250 || version==200603300 || version==200604010 465 || version==200608080 || version==200704160 || version==200802200) 415 if (version>=200411130) 466 416 { 467 417 // ========== Col 19-35: DC and HV-values, mjd ========= … … 476 426 strng="n/a"; 477 427 478 testflagkey = QueryNameKEY(serv, dummy, "TestFlag", strng.Data());428 testflagkey = serv.QueryKeyOfName("TestFlag", strng); 479 429 if (testflagkey<0) 480 430 { … … 488 438 strng="n/a"; 489 439 490 lightcondkey = QueryNameKEY(serv, dummy, "LightConditions", strng.Data());440 lightcondkey = serv.QueryKeyOfName("LightConditions", strng); 491 441 if (lightcondkey<0) 492 442 { … … 500 450 strng="n/a"; 501 451 502 dttablekey = QueryNameKEY(serv, dummy, "DiscriminatorThresholdTable", strng.Data());452 dttablekey = serv.QueryKeyOfName("DiscriminatorThresholdTable", strng); 503 453 if (dttablekey<0) 504 454 { … … 512 462 strng="n/a"; 513 463 514 triggerdelaytablekey = QueryNameKEY(serv, dummy, "TriggerDelayTable", strng.Data());464 triggerdelaytablekey = serv.QueryKeyOfName("TriggerDelayTable", strng); 515 465 if (triggerdelaytablekey<0) 516 466 { … … 524 474 525 475 // ========== Col 42: Calibration Script ========= 526 if (version==200411130 || version==200412090 || version==200412210 527 || version==200502240 || version==200503170 || version==200503220 528 || version==200504010 || version==200504130 || version==200504150 529 || version==200507140 || version==200507190 || version==200508290 530 || version==200510250) 476 if (version>=200411130 && version<=200510250) 531 477 strng.ReadToDelim(fin, '\n'); 532 478 else … … 535 481 strng="n/a"; 536 482 537 calibrationscriptkey = QueryNameKEY(serv, dummy, "CalibrationScript", strng.Data());483 calibrationscriptkey = serv.QueryKeyOfName("CalibrationScript", strng); 538 484 if (calibrationscriptkey<0) 539 485 { … … 545 491 546 492 Int_t observationmodekey=1; 547 if (version ==200603300 || version==200604010 || version==200608080 || version==200704160 || version==200802200)493 if (version>=200603300) 548 494 { 549 495 // ========== Col 43: Observation Mode ========= … … 552 498 strng="n/a"; 553 499 554 observationmodekey = QueryNameKEY(serv, dummy, "ObservationMode", strng.Data());500 observationmodekey = serv.QueryKeyOfName("ObservationMode", strng); 555 501 if (observationmodekey<0) 556 502 { … … 574 520 //assemlbe the query that is needed to insert the values of this run 575 521 TString query; 576 query += "INSERT RunData SET ";577 578 query += Form("f RunNumber=%d, ", runnumber);579 query += Form("fRunTypeKEY=%d, ", runtype);580 query += Form("fProjectKEY=%d, ", projkey);581 query += Form("fSourceKEY=%d, ", sourcekey);582 query += Form("fNumEvents=%d, ", evtno);522 query += Form("fTelescopeNumber=%d, ", telnumber); 523 query += Form("fRunNumber=%d, ", runnumber); 524 query += Form("fFileNumber=%d, ", filenumber); 525 query += Form("fRunTypeKEY=%d, ", runtype); 526 query += Form("fProjectKEY=%d, ", projkey); 527 query += Form("fSourceKEY=%d, ", sourcekey); 528 query += Form("fNumEvents=%d, ", evtno); 583 529 query += Form("fRunStart=\"%s %s\", ", startdate.Data(), starttime.Data()); 584 530 query += Form("fRunStop=\"%s %s\", ", stopdate.Data(), stoptime.Data()); … … 610 556 cnt++; 611 557 612 if (dummy)613 continue;614 615 558 //send query, add dataset to DB 616 TSQLResult *res = serv.Query(query); 617 if (!res) 559 if (serv.Insert("RunData", query)==kFALSE) 618 560 return -1; 619 delete res; 620 621 //create entry in table RunProcessStatus for this runnumber 622 TString query2=Form("INSERT RunProcessStatus SET fRunNumber=%d, fTimingCorrection='1970-01-01 00:00:00', fCompmux='1970-01-01 00:00:00'", 561 562 TString query2=Form("fRunNumber=%d, fTimingCorrection='1970-01-01 00:00:00', fCompmux='1970-01-01 00:00:00'", 623 563 runnumber); 624 564 if (testflagkey==3) 625 565 query2+=" , fDataCheckDone='1970-01-01 00:00:00'"; 626 res = serv.Query(query2); 627 if (!res) 566 567 //create entry in table RunProcessStatus for this runnumber 568 if (serv.Insert("RunProcessStatus", query2)==kFALSE) 628 569 return -1; 629 delete res;630 570 } 631 571 … … 639 579 TEnv env("sql.rc"); 640 580 641 MSQL Serverserv(env);581 MSQLMagic serv(env); 642 582 if (!serv.IsConnected()) 643 583 { … … 652 592 cout << endl; 653 593 594 serv.SetIsDummy(dummy); 595 654 596 if (path.EndsWith(".run")) 655 597 {
Note:
See TracChangeset
for help on using the changeset viewer.