Changeset 7243 for trunk/MagicSoft
- Timestamp:
- 07/31/05 18:41:31 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/datacenter/macros/buildsequenceentries.C
r7242 r7243 177 177 Bool_t CheckSequence(MSQLServer &serv, TString datapath, TString sequpath, Int_t from, Int_t to, Bool_t dummy) 178 178 { 179 Bool_t rc=kFALSE; 180 181 TString query("SELECT fSequenceFirst, count(*) FROM RunData "); 182 query += Form(" WHERE fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)" 183 " GROUP BY fSequenceFirst", from, to); 179 Int_t rc=0; //rc=0 means sequence is still the same -> insert not neccessary 180 //rc=1 means deleting sequence(s) worked -> insert 181 //if deleting sequence doesn't work -> return -1 182 183 184 //getting # of sequence (in sequDB) between from and to 185 TString query(Form("SELECT fSequenceFirst FROM Sequences WHERE fSequenceFirst BETWEEN %d and %d", from, to)); 184 186 185 187 TSQLResult *res = serv.Query(query); 186 188 if (!res) 187 return kFALSE; 188 189 Int_t count=0; 190 Int_t nor=0; 191 TArrayI sequences; 189 return -1; 190 191 TArrayI Sequences; 192 Int_t numsequ=0; 192 193 193 194 TSQLRow *row=0; 194 while ((row=res->Next())) 195 { 196 sequences.Set(count+1); 197 sequences.AddAt(atoi((*row)[0]), count); 198 // cout << "sequence: " << sequences.At(count) << endl; 199 nor=atoi((*row)[1]); 200 count++; 201 } 202 203 delete res; 204 205 if (sequences.GetSize()>1) 206 { 195 while ((row=res.Next())) 196 { 197 numsequ++; 198 sequences.Set(numsequ); 199 sequences.AddAt(atoi((*row)[0]), numsequ-1); 200 } 201 delete res; 202 203 //if there's no sequence in the table Sequences -> check other tables 204 //if there's one sequence -> check if the sequence is identical 205 //if there are more sequences -> delete them 206 switch (numsequ) 207 { 208 case 0: 209 cout << "found no sequence in Sequ-DB -> check other tables" << endl; 210 cout << " deleting every sequence found in Calibration, Star or SequenceProcessStatus between " 211 << from << " and " << to << endl; 212 213 //calibration table 214 query(Form("SELECT fSequenceFirst FROM Calibration WHERE fSequenceFirst BETWEEN %d and %d", from, to)); 215 res = serv.Query(query); 216 if (!res) 217 return -1; 218 row=0; 219 while ((row=res.Next())) 220 { 221 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy)) 222 return -1; 223 else 224 rc=1; 225 } 226 delete res; 227 228 //Star table 229 query(Form("SELECT fSequenceFirst FROM Star WHERE fSequenceFirst BETWEEN %d and %d", from, to)); 230 res = serv.Query(query); 231 if (!res) 232 return -1; 233 row=0; 234 while ((row=res.Next())) 235 { 236 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy)) 237 return -1; 238 else 239 rc=1; 240 } 241 delete res; 242 243 //SequenceProcessStatus table 244 query(Form("SELECT fSequenceFirst FROM SequenceProcessStatus WHERE fSequenceFirst BETWEEN %d and %d", from, to)); 245 res = serv.Query(query); 246 if (!res) 247 return -1; 248 row=0; 249 while ((row=res.Next())) 250 { 251 if(!DeleteSequence(serv, datapath, sequpath, atoi((*row)[0]), dummy)) 252 return -1; 253 else 254 rc=1; 255 } 256 delete res; 257 258 259 case 1: 260 cout << "found 1 sequence: " << sequences.At(0) << " -> check sequ# " << endl; 261 if (sequences.At(0)!=from) 262 { 263 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy)) 264 return -1; 265 else 266 rc=1; 267 } 268 else 269 { 270 cout << "sequence# is the same -> checking the runs " << endl; 271 272 //getting olf runs 273 query(Form("SELECT fRunNumber FROM RunData WHERE fSequenceFirst=%d ", from)); 274 res = serv.Query(query); 275 if (!res) 276 return -1; 277 278 TArrayI oldruns; 279 Int_t count=0; 280 row=0; 281 while ((row=res.Next())) 282 { 283 count++; 284 oldruns.Set(count); 285 oldruns.AddAt(atoi((*row)[0]), count-1); 286 } 287 delete res; 288 289 //getting new runs 290 query(Form("SELECT fRunNumber FROM RunData WHERE fRunNumber BETWEEN %d and %d AND fExcludedFDAKEY=1", from, to)); 291 res = serv.Query(query); 292 if (!res) 293 return -1; 294 TArrayI newruns; 295 count=0; 296 row=0; 297 while ((row=res.Next())) 298 { 299 count++; 300 oldruns.Set(count); 301 oldruns.AddAt(atoi((*row)[0]), count-1); 302 } 303 delete res; 304 305 //comparing old and new runs (first the # of runs, if it is the same, also the single runnumbers 306 if (oldruns.GetSize()!=newruns.GetSize()) 307 { 308 cout << " number of runs is not the same -> deleting sequence " << sequences.At(0) << endl; 309 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy)) 310 return -1; 311 else 312 rc=1; 313 } 314 else 315 { 316 cout << " number of runs is the same -> checking the single runnumbers " << endl; 317 318 for (Int_t i=0;i<newruns.GetSize();i++) 319 { 320 if (newruns.At(i)==oldruns.At(i)) 321 continue; 322 323 cout << i << ". run is not the same ( " << oldruns.At(i) << " -- " << newruns.At(i) 324 << ") -> deleting sequence " << sequences.At(0) << endl; 325 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy)) 326 return -1; 327 else 328 rc=1; 329 break; 330 } 331 } 332 } 333 334 default: 335 cout << "found " << numsequ << " sequences -> deleting them " << endl; 336 207 337 for (Int_t i=0;i<sequences.GetSize();i++) 208 338 { 209 rc=kTRUE;210 if (sequences.At(i)!=0)211 {212 339 cout << "deleting sequence " << sequences.At(i) << "... <" << i << ">" << endl; 213 340 if(!DeleteSequence(serv, datapath, sequpath, sequences.At(i), dummy)) 214 rc=kFALSE; 215 } 216 } 217 // return rc; 218 } 219 220 if (sequences.At(0)==0) 221 return kTRUE; 222 223 224 query="SELECT fRunNumber FROM RunData "; 225 query += Form(" WHERE fExcludedFDAKEY=1 AND (fRunNumber BETWEEN %d AND %d)" 226 " ORDER BY fRunNumber", from, to); 227 228 res = serv.Query(query); 229 if (!res) 230 return kFALSE; 231 232 TArrayI runs; 233 count=0; 234 row=0; 235 while ((row=res->Next())) 236 { 237 runs.Set(count+1); 238 runs.AddAt(atoi((*row)[0]), count); 239 count++; 240 } 241 242 delete res; 243 244 245 if (nor==runs.GetSize() && sequences.GetSize()==1) 246 { 247 query="SELECT fRunNumber FROM RunData "; 248 query += Form(" WHERE fSequenceFirst=%d ", sequences.At(0)); 249 250 res = serv.Query(query); 251 if (!res) 252 return kFALSE; 253 254 TArrayI oldruns; 255 count=0; 256 row=0; 257 while ((row=res->Next())) 258 { 259 oldruns.Set(count+1); 260 oldruns.AddAt(atoi((*row)[0]), count); 261 count++; 262 } 263 264 if (runs.GetSize()!=oldruns.GetSize()) 265 { 266 cout << "different sequsizes -> deleting sequence " << sequences.At(0) << endl; 267 // return DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy); 268 rc=DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy); 269 } 270 271 for (Int_t i=0; i<runs.GetSize(); i++) 272 { 273 if (runs.At(i)==oldruns.At(i)) 274 continue; 275 cout << "different runs -> deleting sequence " << sequences.At(0) << endl; 276 rc=DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy); 277 // return DeleteSequence(serv, datapath, sequpath, sequences.At(0), dummy); 278 } 279 280 delete res; 281 } 282 283 query="SELECT fSequenceFirst FROM Sequences "; 284 query += Form(" WHERE fSequenceFirst BETWEEN %d AND %d " 285 " ORDER BY fSequenceFirst", from, to); 286 287 cout << query << endl; 288 289 res = serv.Query(query); 290 if (!res) 291 return kFALSE; 292 293 Int_t sequ=0; 294 while ((row=res->Next())) 295 { 296 sequ=atoi((*row)[0]); 297 cout << "deleting sequence " << sequ << endl; 298 if(!DeleteSequence(serv, datapath, sequpath, sequ, dummy)) 299 rc=kFALSE; 300 } 301 302 delete res; 303 304 305 cout << "same sequence -> nothing to do..." << endl; 341 return -1; 342 else 343 rc=1; 344 } 345 } 346 306 347 return rc; 307 348 } … … 451 492 cout << "checking Sequence..." << endl; 452 493 453 if (!CheckSequence(serv, datapath, sequpath, from, to, dummy)) 454 { 494 Bool_t rc=kFALSE; 495 switch (CheckSequence(serv, datapath, sequpath, from, to, dummy)) 496 { 497 case 0: 455 498 cout << " inserting sequence not necessary" << endl; 456 499 return kTRUE; 457 } 458 459 460 if (dummy) 461 return kTRUE; 462 463 Bool_t rc = InsertSequence(serv, from, to); 464 if (!rc) 465 cout << "InsertSequence failed!" << endl; 500 501 case 1: 502 cout << " deleting successfully finished -> inserting sequence " << from << endl; 503 if (dummy) 504 return kTRUE; 505 rc = InsertSequence(serv, from, to); 506 if (!rc) 507 cout << "InsertSequence failed!" << endl; 508 509 case -1: 510 cout << " deleting went wrong " << endl; 511 rc=kFALSE; 512 } 513 466 514 467 515 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.