- Timestamp:
- Aug 17, 2023, 4:35:50 PM (3 years ago)
- Location:
- branches/eam_branches/ipp-20230313/ippTools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/ippTools
- Property svn:mergeinfo changed
/trunk/ippTools (added) merged: 42412,42480
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20230313/ippTools/src
- Property svn:mergeinfo changed
/trunk/ippTools/src (added) merged: 42412,42480
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20230313/ippTools/src/fftool.c
r39028 r42524 33 33 34 34 static bool definebyqueryMode(pxConfig *config); 35 static bool defineforstacksMode(pxConfig *config); 35 36 static bool updaterunMode(pxConfig *config); 36 37 static bool todoMode(pxConfig *config); … … 68 69 switch (config->mode) { 69 70 MODECASE(FFTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 71 MODECASE(FFTOOL_MODE_DEFINEFORSTACKS, defineforstacksMode); 70 72 MODECASE(FFTOOL_MODE_UPDATERUN, updaterunMode); 71 73 MODECASE(FFTOOL_MODE_TODO, todoMode); … … 337 339 } 338 340 341 static bool defineforstacksMode(pxConfig *config) 342 { 343 PS_ASSERT_PTR_NON_NULL(config, false); 344 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); 345 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false); 346 347 // optional 348 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 349 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 350 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 351 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 352 353 PXOPT_LOOKUP_STR(sources_path_base, config->args, "-set_sources_path_base", false, false); 354 355 psMetadata *skycalWhereMD = psMetadataAlloc(); 356 pxAddLabelSearchArgs(config, skycalWhereMD, "-select_skycal_label", "skycalRun.label", "LIKE"); 357 pxAddLabelSearchArgs(config, skycalWhereMD, "-select_skycal_data_group", "skycalRun.data_group", "LIKE"); 358 PXOPT_COPY_S64(config->args, skycalWhereMD, "-select_skycal_id", "skycalRun.skycal_id", "=="); 359 360 if (!psListLength(skycalWhereMD->list)) { 361 psError(PXTOOLS_ERR_CONFIG, false, "skycal search parameters are required"); 362 psFree(skycalWhereMD); 363 return false; 364 } 365 366 PXOPT_COPY_STR(config->args, skycalWhereMD, "-select_skycell_id", "stackRun.skycell_id", "LIKE"); 367 PXOPT_COPY_STR(config->args, skycalWhereMD, "-select_tess_id", "stackRun.tess_id", "=="); 368 pxAddLabelSearchArgs(config, skycalWhereMD, "-select_filter", "stackRun.filter", "LIKE"); 369 if (!pxskycellAddWhere(config, skycalWhereMD)) { 370 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); 371 psFree(skycalWhereMD); 372 return false; 373 } 374 375 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 376 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 377 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 378 379 psString select = pxDataGet("fftool_defineforstacks.sql"); 380 if (!select) { 381 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 382 psFree(skycalWhereMD); 383 return false; 384 } 385 386 psString where = NULL; 387 psString whereClause = psDBGenerateWhereConditionSQL(skycalWhereMD, NULL); 388 psStringAppend(&where, "\nAND %s", whereClause); 389 psStringAppend(&select, " %s", where); 390 psFree(whereClause); 391 psFree(skycalWhereMD); 392 393 psString joinHook = NULL; 394 if (!rerun) { 395 psStringAppend(&joinHook, "\nLEFT JOIN fullForceRun ON fullForceRun.skycal_id = skycalRun.skycal_id"); 396 psStringAppend(&joinHook, "\n %s\nAND fullForceRun.label = '%s'", where, label); 397 psStringAppend(&select, "\nAND ff_id IS NULL"); 398 } 399 400 if (!p_psDBRunQueryF(config->dbh, select, joinHook)) { 401 psError(PS_ERR_UNKNOWN, false, "database error"); 402 psFree(select); 403 return false; 404 } 405 psFree(select); 406 psFree(joinHook); 407 408 psArray *output = p_psDBFetchResult(config->dbh); 409 if (!output) { 410 psErrorCode err = psErrorCodeLast(); 411 switch (err) { 412 case PS_ERR_DB_CLIENT: 413 psError(PXTOOLS_ERR_SYS, false, "database error"); 414 case PS_ERR_DB_SERVER: 415 psError(PXTOOLS_ERR_PROG, false, "database error"); 416 default: 417 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 418 } 419 psFree(where); 420 return false; 421 } 422 if (!psArrayLength(output)) { 423 psWarning("fftool: no rows found"); 424 psFree(output); 425 psFree(where); 426 return true; 427 } 428 429 if (pretend) { 430 // negative simple so the default is true 431 if (!ippdbPrintMetadatas(stdout, output, "toFullForce", !simple)) { 432 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 433 psFree(output); 434 psFree(where); 435 return false; 436 } 437 psFree(output); 438 psFree(where); 439 return true; 440 } 441 442 psString warpQueryTemplate = pxDataGet("fftool_defineforstacks_select_warps.sql"); 443 444 for (long i = 0; i < output->n; i++) { 445 psMetadata *row = output->data[i]; // Row from select 446 bool status; 447 448 if (!psDBTransaction(config->dbh)) { 449 psError(PS_ERR_UNKNOWN, false, "database error"); 450 psFree(output); 451 return false; 452 } 453 454 psS64 skycal_id = psMetadataLookupS64(&status, row, "skycal_id"); 455 456 psString path_base = NULL; 457 if (sources_path_base) { 458 path_base = sources_path_base; 459 } else { 460 path_base = psMetadataLookupStr(&status, row, "path_base"); 461 psAssert(status, "failed to find skycal path_base?"); 462 } 463 464 psString skycal_data_group = psMetadataLookupStr(&status, row, "data_group"); 465 466 psString query = NULL; 467 psStringAppend(&query, warpQueryTemplate, skycal_id); 468 469 if (!p_psDBRunQuery(config->dbh, query)) { 470 psError(PS_ERR_UNKNOWN, false, "database error"); 471 psFree(query); 472 return false; 473 } 474 psFree(query); 475 476 // Find the warps for this skycell and filter combination 477 psArray *warpOutput = p_psDBFetchResult(config->dbh); 478 if (!warpOutput) { 479 psErrorCode err = psErrorCodeLast(); 480 switch (err) { 481 case PS_ERR_DB_CLIENT: 482 psError(PXTOOLS_ERR_SYS, false, "database error"); 483 case PS_ERR_DB_SERVER: 484 psError(PXTOOLS_ERR_PROG, false, "database error"); 485 default: 486 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 487 } 488 return false; 489 } 490 if (!psArrayLength(warpOutput)) { 491 // no warps for this skycal. Suprise? 492 psFree(warpOutput); 493 psFree(query); 494 continue; 495 } 496 497 // create a staticskyRun 498 if (!fullForceRunInsert(config->dbh, 499 0x0, // ff_id 500 skycal_id, 501 path_base, 502 "new", // state 503 workdir, 504 label, 505 data_group ? data_group : (skycal_data_group ? skycal_data_group : label), 506 dist_group, 507 note, 508 reduction, 509 NULL // registered 510 ) 511 ) { 512 if (!psDBRollback(config->dbh)) { 513 psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction"); 514 } 515 psError(PS_ERR_UNKNOWN, false, "database error"); 516 psFree(output); 517 return false; 518 } 519 520 psS64 ff_id = psDBLastInsertID(config->dbh); 521 522 for (int j = 0; j < warpOutput->n; j++) { 523 psMetadata *warpRow = warpOutput->data[j]; 524 psS64 warp_id = psMetadataLookupS64(&status, warpRow, "warp_id"); 525 526 if (!fullForceInputInsert(config->dbh, 527 ff_id, 528 warp_id) 529 ) { 530 if (!psDBRollback(config->dbh)) { 531 psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction"); 532 } 533 psError(PS_ERR_UNKNOWN, false, "database error"); 534 psFree(warpOutput); 535 psFree(output); 536 return false; 537 } 538 } 539 540 if (!psDBCommit(config->dbh)) { 541 psError(PS_ERR_UNKNOWN, false, "database error"); 542 psFree(warpOutput); 543 psFree(output); 544 return false; 545 } 546 psFree(warpOutput); 547 } 548 psFree(output); 549 550 return true; 551 } 552 339 553 static bool updaterunMode(pxConfig *config) 340 554 {
Note:
See TracChangeset
for help on using the changeset viewer.
