- Timestamp:
- 07/17/08 16:08:04 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
r8968 r9006 159 159 UInt_t fMax; 160 160 161 static UInt_t GetId(const TString &str) 162 { 163 const Ssiz_t dot = str.First('.'); 164 165 const UInt_t run = str.Atoi(); 166 const UInt_t sub = dot<0 ? 0 : atoi(str.Data()+dot+1); 167 168 return run*1000+sub; 169 } 170 161 171 void Init(const TObjArray &arr, Int_t idx=0) 162 172 { … … 179 189 case 2: fRegexp1 = TPRegexp(Form("^%s$", str.Data())); break; 180 190 case 3: fRegexp2 = TPRegexp(Form("^%s$", str.Data())); break; 181 case 4: fMin = str.Atoi(); break;182 case 5: fMax = str.Atoi(); break;191 case 4: fMin = GetId(str); break; 192 case 5: fMax = GetId(str); break; 183 193 } 184 194 } 185 //cout << endl;186 195 } 187 196 … … 257 266 TString fPathSequences; 258 267 268 Int_t fTelescopeNumber; 269 259 270 TMap fMap; 260 271 TList fListRegexp; … … 286 297 const TString runtime = 287 298 "SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))), "; 288 //"SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0," 289 //" TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60," 290 //" TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart))), "; 291 292 const TString where = Form("(fRunNumber BETWEEN %d AND %d) AND fExcludedFDAKEY=1", 293 from, to); 299 300 const TString where = Form("(fRunNumber*1000+fFileNumber BETWEEN %d AND %d) " 301 "AND fTelescopeNumber=%d AND fExcludedFDAKEY=1", 302 from, to, fTelescopeNumber); 294 303 295 304 TString query; … … 359 368 } 360 369 361 const TString set = Form("fSequenceFirst=%d ", from);370 const TString set = Form("fSequenceFirst=%d, fTelescopeNumber=%d ", from/1000, fTelescopeNumber); 362 371 363 372 TString query1; 364 373 query1 += set; 365 query1 += Form(",fSequenceLast=%d,", to );374 query1 += Form(",fSequenceLast=%d,", to/1000); 366 375 query1 += Form(" fSourceKEY=%s,", (*row)[0]); 367 376 query1 += Form(" fProjectKEY=%s,", (*row)[1]); … … 400 409 } 401 410 402 if (!Insert("SequenceProcessStatus", set)) 411 TString prio = set; 412 prio += Form(", fPriority=%d ", from/1000); 413 if (!Insert("SequenceProcessStatus", prio)) 403 414 { 404 415 cout << "ERROR - Could not insert Sequence into SequenceProcessStatus." << endl; … … 458 469 Int_t CheckSequence(Int_t runstart, Int_t runstop) 459 470 { 460 const char *fmt1 = "SELECT fRunNumber FROM RunData WHERE";461 const char *fmt2 = "AND fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4) ORDER BY fRunNumber";462 463 const TString query1 = Form("%s f SequenceFirst=%d %s", fmt1, runstart, fmt2);464 const TString query2 = Form("%s f RunNumber BETWEEN %d AND %d %s", fmt1, runstart, runstop, fmt2);471 const char *fmt1 = "SELECT fRunNumber*1000+fFileNumber AS Id FROM RunData WHERE"; 472 const char *fmt2 = "AND fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4) ORDER BY Id"; 473 474 const TString query1 = Form("%s fTelescopeNumber=%d AND fSequenceFirst=%d %s", fmt1, fTelescopeNumber, runstart/1000, fTelescopeNumber, fmt2); 475 const TString query2 = Form("%s fTelescopeNumber=%d AND fRunNumber*1000+fFileNumber BETWEEN %d AND %d %s", fmt1, fTelescopeNumber, runstart, runstop, fmt2); 465 476 466 477 TSQLResult *res1 = Query(query1); … … 499 510 TString query= 500 511 Form("SELECT fSequenceFirst FROM RunData " 501 " WHERE fRunNumber BETWEEN %d AND %d AND "502 " f SequenceFirst>0 AND "512 " WHERE fRunNumber*1000+fFileNumber BETWEEN %d AND %d AND " 513 " fTelescopeNumber=%d AND fSequenceFirst>0 AND " 503 514 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)" 504 " GROUP BY fSequenceFirst", runstart, runstop);515 " GROUP BY fSequenceFirst", fTelescopeNumber, runstart, runstop); 505 516 506 517 TSQLResult *res = Query(query); … … 554 565 Bool_t ReadResources(const char *fname) 555 566 { 556 TPRegexp regexp("^\\[.*\\]$"); 567 // Check for the section header 568 TPRegexp regexp("^\\[(Transition|Regexp):?[0-9 ]*\\]$"); 569 // Check if section header contains a number 570 TPRegexp regnum("[0-9]"); 571 // Check if section header contains the telescope number 572 TPRegexp regtel(Form("[^0-9]0*%d[^0-9]", fTelescopeNumber)); 557 573 558 574 ifstream fin(fname); … … 579 595 continue; 580 596 581 if (txt[0]=='[' && section!=2)597 if (txt[0]=='['/* && section!=2*/) 582 598 { 583 //cout << txt << endl; 584 section = 0; 585 if (txt(regexp)=="[Transition]") 586 section = 1; 587 if (txt(regexp)=="[Regexp]") 588 section = 2; 589 continue; 599 TString sec = txt(regexp); 600 if (!sec.IsNull()) 601 { 602 section = 0; 603 604 // Skip sections with the wrong telescope number 605 if (!sec(regnum).IsNull() && !sec(regtel).IsNull()) 606 continue; 607 608 // Check which section we are in 609 if (sec.BeginsWith("[Transition")) 610 section = 1; 611 if (sec.BeginsWith("[Regexp]")) 612 section = 2; 613 continue; 614 } 615 616 if (section!=2) 617 { 618 cout << "WARNING - Line starts with [ but we are not in the Regexp section." << endl; 619 cout << txt << endl; 620 continue; 621 } 590 622 } 623 591 624 592 625 TObjArray *arr = txt.Tokenize(" "); … … 705 738 { 706 739 return Form("SELECT RunData.f%sKEY, f%sName FROM RunData " 707 "LEFT JOIN %s ON RunData.f%sKEY=%s.f%sKEY " 708 "WHERE %s GROUP BY f%sName", 709 col, col, col, col, col, col, cond, col); 740 "LEFT JOIN %s USING (f%sKEY) WHERE %s GROUP BY f%sName", 741 col, col, col, col, cond, col); 710 742 } 711 743 … … 864 896 // Request data necessary to split block into sequences 865 897 const TString query= 866 Form("SELECT fRunNumber , fRunTypeKEY, fRunStart, fRunStop"898 Form("SELECT fRunNumber*1000+fFileNumber AS Id, fRunTypeKEY, fRunStart, fRunStop" 867 899 " FROM RunData " 868 " WHERE fRunNumber BETWEEN %d AND %d AND "900 " WHERE fRunNumber*1000+fFileNumber BETWEEN %d AND %d AND " 869 901 " fExcludedFDAKEY=1 AND (fRunTypeKEY BETWEEN 2 AND 4)" 870 " ORDER BY fRunNumber", runstart, runstop);902 " ORDER BY Id", runstart, runstop); 871 903 872 904 // Send query … … 1084 1116 1085 1117 public: 1086 SequenceBuild(TEnv &env) : MSQLMagic(env) 1087 { 1088 cout << "buildsequences" << endl; 1089 cout << "--------------" << endl; 1090 cout << endl; 1091 cout << "Connected to " << GetName() << endl; 1092 1118 SequenceBuild(Int_t tel=1, const char *rc="sql.rc") : MSQLMagic(rc), fTelescopeNumber(tel) 1119 { 1093 1120 fListRegexp.SetOwner(); 1094 1121 … … 1097 1124 return; 1098 1125 } 1099 SequenceBuild() 1126 1127 SequenceBuild(TEnv &env, Int_t tel=1) : MSQLMagic(env), fTelescopeNumber(tel) 1128 { 1129 fListRegexp.SetOwner(); 1130 1131 // FIXME: THIS IS NOT YET HANDLED 1132 if (ReadResources("resources/sequences.rc")) 1133 return; 1134 } 1135 ~SequenceBuild() 1100 1136 { 1101 1137 fMap.DeleteAll(); … … 1113 1149 const TString cond = 1114 1150 Form("(fRunStart>ADDDATE(\"%s\", INTERVAL -1 DAY) AND fRunStart<\"%s\") " 1115 "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 ", 1116 day.Data(), day.Data()); 1151 "AND fExcludedFDAKEY=1 AND fRunTypeKEY BETWEEN 2 AND 4 " 1152 "AND fTelescopeNumber=%d ", 1153 day.Data(), day.Data(), fTelescopeNumber); 1117 1154 1118 1155 //query all sources observed in this night … … 1128 1165 // Setup query to get all values from the database, 1129 1166 // that are relevant for building sequences 1130 TString query("SELECT fRunNumber , fRunTypeKEY, ");1167 TString query("SELECT fRunNumber*1000+fFileNumber AS Id, fRunTypeKEY, "); 1131 1168 query += elts; 1132 1169 query += ", "; … … 1142 1179 query += mapkey->GetName(); 1143 1180 } 1144 query += Form(" FROM RunData WHERE %s ORDER BY fRunNumber", cond.Data());1181 query += Form(" FROM RunData WHERE %s ORDER BY Id", cond.Data()); 1145 1182 1146 1183 TSQLResult *res = Query(query); … … 1176 1213 ClassImp(SequenceBuild); 1177 1214 1178 int buildsequenceentries(TString day, TString datapath, TString sequpath, Bool_t dummy=kTRUE)1215 int buildsequenceentries(TString day, TString datapath, TString sequpath, Int_t tel=1, Bool_t dummy=kTRUE) 1179 1216 { 1180 TEnv env("sql.rc"); 1181 1182 SequenceBuild serv(env); 1217 SequenceBuild serv(tel, "sql.rc"); 1183 1218 if (!serv.IsConnected()) 1184 1219 { … … 1186 1221 return 0; 1187 1222 } 1223 1224 cout << "buildsequenceentries" << endl; 1225 cout << "--------------------" << endl; 1226 cout << endl; 1227 cout << "Connected to " << serv.GetName() << endl; 1228 if (!datapath.IsNull()) 1229 cout << "DataPath: " << datapath << endl; 1230 if (!sequpath.IsNull()) 1231 cout << "SeqPath: " << sequpath << endl; 1232 cout << "Day: " << day << endl; 1233 cout << "Telescope: " << tel << endl; 1234 cout << endl; 1188 1235 1189 1236 serv.SetIsDummy(dummy); … … 1196 1243 // Build Sequences for all Nights 1197 1244 // 1198 int buildsequenceentries(TString datapath, TString sequpath, Bool_t dummy=kTRUE)1245 int buildsequenceentries(TString datapath, TString sequpath, Int_t tel=1, Bool_t dummy=kTRUE) 1199 1246 { 1200 TEnv env("sql.rc"); 1201 1202 SequenceBuild serv(env); 1247 SequenceBuild serv(tel, "sql.rc"); 1203 1248 if (!serv.IsConnected()) 1204 1249 { … … 1206 1251 return 0; 1207 1252 } 1253 1254 cout << "buildsequenceentries" << endl; 1255 cout << "--------------------" << endl; 1256 cout << endl; 1257 cout << "Connected to " << serv.GetName() << endl; 1258 cout << "DataPath: " << datapath << endl; 1259 cout << "SeqPath: " << sequpath << endl; 1260 cout << "Telescope: " << tel << endl; 1261 cout << endl; 1208 1262 1209 1263 serv.SetIsDummy(dummy); … … 1213 1267 } 1214 1268 1215 int buildsequenceentries( Bool_t dummy=kTRUE)1269 int buildsequenceentries(Int_t tel=1, Bool_t dummy=kTRUE) 1216 1270 { 1217 return buildsequenceentries("", "", dummy);1271 return buildsequenceentries("", "", tel, dummy); 1218 1272 } 1219 1273 1220 int buildsequenceentries(TString day, Bool_t dummy=kTRUE)1274 int buildsequenceentries(TString day, Int_t tel=1, Bool_t dummy=kTRUE) 1221 1275 { 1222 return buildsequenceentries(day, "", "", dummy);1276 return buildsequenceentries(day, "", "", tel, dummy); 1223 1277 }
Note:
See TracChangeset
for help on using the changeset viewer.