Changeset 42591 for branches/eam_branches/ipp-20230313/ippTools/src
- Timestamp:
- Jan 15, 2024, 1:11:21 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20230313/ippTools/src/xcfftool.c
r42588 r42591 105 105 } 106 106 107 107 // NOTE: if I denormalize and populate (tess_id, skycell_id) in xcForceRun the I do not need 108 // to join back to xcstackRun to get that info 108 109 static bool definebyqueryMode(pxConfig *config) 109 110 { … … 116 117 PXOPT_LOOKUP_STR(xcamera, config->args, "-xcamera", true, false); 117 118 118 // get this camera_id from the database: 119 psS64 xcamera_id = getCameraIDfromName(config, xcamera); 120 if (!xcamera_id) { 119 // get camera_id for the working database: 120 // XXX need to extract the camera name (-dbname) from the config 121 psS64 camera_id = getCameraIDfromName(config, config->dbh->camera); 122 if (!camera_id) { 121 123 psError(PXTOOLS_ERR_SYS, false, "failed to find xcamera in database"); 122 124 return false; … … 144 146 145 147 // XXX do these need to specify stackRun? can the filters be different between stackRun and xcstackRun? 146 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_skycell_id", " stackRun.skycell_id", "LIKE");147 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_tess_id", " stackRun.tess_id", "==");148 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_filter", " stackRun.filter", "LIKE");148 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_skycell_id", "xcstackRun.skycell_id", "LIKE"); 149 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_tess_id", "xcstackRun.tess_id", "=="); 150 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_filter", "xcstackRun.filter", "LIKE"); 149 151 if (!pxskycellAddWhere(config, xccalWhereMD)) { 150 152 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); … … 164 166 } 165 167 PXOPT_COPY_F32(config->args, warpWhereMD, "-select_good_frac_min", "warpSkyfile.good_frac", ">="); 168 // XXX do I need these or not? the warp skyfiles need to match the stack skycells 166 169 PXOPT_COPY_STR(config->args, warpWhereMD, "-select_tess_id", "warpRun.tess_id", "=="); 167 170 pxAddLabelSearchArgs(config, warpWhereMD, "-select_filter", "rawExp.filter", "LIKE"); … … 188 191 psString joinHook = NULL; 189 192 if (!rerun) { 190 psStringAppend(&joinHook, "\nLEFT JOIN xcForceRun ON xcForceRun.xccal_id = xccalRun.xccal_id");193 psStringAppend(&joinHook, "\nLEFT JOIN xcForceRun ON xcForceRun.xccal_id = %s.xccalRun.xccal_id", xcamera); 191 194 psStringAppend(&joinHook, "\n %s\nAND xcForceRun.label = '%s'", where, label); 192 195 psStringAppend(&select, "\nAND ff_id IS NULL"); 193 196 } 194 197 198 // XXX need to add the xcamera name here to match definebyquery.sql 195 199 if (!p_psDBRunQueryF(config->dbh, select, joinHook)) { 196 200 psError(PS_ERR_UNKNOWN, false, "database error"); … … 297 301 } 298 302 299 // create a staticskyRun303 // create an xcForceRun 300 304 if (!xcForceRunInsert(config->dbh, 301 305 0x0, // ff_id … … 320 324 } 321 325 322 psS64 ff_id = psDBLastInsertID(config->dbh);326 psS64 xcff_id = psDBLastInsertID(config->dbh); 323 327 324 328 for (int j = 0; j < warpOutput->n; j++) { … … 326 330 psS64 warp_id = psMetadataLookupS64(&status, warpRow, "warp_id"); 327 331 328 if (!xcForceInputInsert(config->dbh, 329 ff_id, 330 warp_id) 332 if (!xcForceInputInsert(config->dbh, ff_id, warp_id, xcamera_id) 331 333 ) { 332 334 if (!psDBRollback(config->dbh)) { … … 353 355 } 354 356 355 static bool defineforstacksMode(pxConfig *config)356 {357 PS_ASSERT_PTR_NON_NULL(config, false);358 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);359 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false);360 361 // optional362 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);363 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);364 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);365 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);366 367 PXOPT_LOOKUP_STR(sources_path_base, config->args, "-set_sources_path_base", false, false);368 369 psMetadata *xccalWhereMD = psMetadataAlloc();370 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_xccal_label", "xccalRun.label", "LIKE");371 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_xccal_data_group", "xccalRun.data_group", "LIKE");372 PXOPT_COPY_S64(config->args, xccalWhereMD, "-select_xccal_id", "xccalRun.xccal_id", "==");373 374 if (!psListLength(xccalWhereMD->list)) {375 psError(PXTOOLS_ERR_CONFIG, false, "xccal search parameters are required");376 psFree(xccalWhereMD);377 return false;378 }379 380 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_skycell_id", "stackRun.skycell_id", "LIKE");381 PXOPT_COPY_STR(config->args, xccalWhereMD, "-select_tess_id", "stackRun.tess_id", "==");382 pxAddLabelSearchArgs(config, xccalWhereMD, "-select_filter", "stackRun.filter", "LIKE");383 if (!pxskycellAddWhere(config, xccalWhereMD)) {384 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");385 psFree(xccalWhereMD);386 return false;387 }388 389 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);390 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);391 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);392 393 psString select = pxDataGet("xcfftool_defineforstacks.sql");394 if (!select) {395 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");396 psFree(xccalWhereMD);397 return false;398 }399 400 psString where = NULL;401 psString whereClause = psDBGenerateWhereConditionSQL(xccalWhereMD, NULL);402 psStringAppend(&where, "\nAND %s", whereClause);403 psStringAppend(&select, " %s", where);404 psFree(whereClause);405 psFree(xccalWhereMD);406 407 psString joinHook = NULL;408 if (!rerun) {409 psStringAppend(&joinHook, "\nLEFT JOIN xcForceRun ON xcForceRun.xccal_id = xccalRun.xccal_id");410 psStringAppend(&joinHook, "\n %s\nAND xcForceRun.label = '%s'", where, label);411 psStringAppend(&select, "\nAND ff_id IS NULL");412 }413 414 if (!p_psDBRunQueryF(config->dbh, select, joinHook)) {415 psError(PS_ERR_UNKNOWN, false, "database error");416 psFree(select);417 return false;418 }419 psFree(select);420 psFree(joinHook);421 422 psArray *output = p_psDBFetchResult(config->dbh);423 if (!output) {424 psErrorCode err = psErrorCodeLast();425 switch (err) {426 case PS_ERR_DB_CLIENT:427 psError(PXTOOLS_ERR_SYS, false, "database error");428 case PS_ERR_DB_SERVER:429 psError(PXTOOLS_ERR_PROG, false, "database error");430 default:431 psError(PXTOOLS_ERR_PROG, false, "unknown error");432 }433 psFree(where);434 return false;435 }436 if (!psArrayLength(output)) {437 psWarning("xcfftool: no rows found");438 psFree(output);439 psFree(where);440 return true;441 }442 443 if (pretend) {444 // negative simple so the default is true445 if (!ippdbPrintMetadatas(stdout, output, "toFullForce", !simple)) {446 psError(PS_ERR_UNKNOWN, false, "failed to print array");447 psFree(output);448 psFree(where);449 return false;450 }451 psFree(output);452 psFree(where);453 return true;454 }455 456 psString warpQueryTemplate = pxDataGet("xcfftool_defineforstacks_select_warps.sql");457 458 for (long i = 0; i < output->n; i++) {459 psMetadata *row = output->data[i]; // Row from select460 bool status;461 462 if (!psDBTransaction(config->dbh)) {463 psError(PS_ERR_UNKNOWN, false, "database error");464 psFree(output);465 return false;466 }467 468 psS64 xccal_id = psMetadataLookupS64(&status, row, "xccal_id");469 470 psString path_base = NULL;471 if (sources_path_base) {472 path_base = sources_path_base;473 } else {474 path_base = psMetadataLookupStr(&status, row, "path_base");475 psAssert(status, "failed to find xccal path_base?");476 }477 478 psString xccal_data_group = psMetadataLookupStr(&status, row, "data_group");479 480 psString query = NULL;481 psStringAppend(&query, warpQueryTemplate, xccal_id);482 483 if (!p_psDBRunQuery(config->dbh, query)) {484 psError(PS_ERR_UNKNOWN, false, "database error");485 psFree(query);486 return false;487 }488 psFree(query);489 490 // Find the warps for this skycell and filter combination491 psArray *warpOutput = p_psDBFetchResult(config->dbh);492 if (!warpOutput) {493 psErrorCode err = psErrorCodeLast();494 switch (err) {495 case PS_ERR_DB_CLIENT:496 psError(PXTOOLS_ERR_SYS, false, "database error");497 case PS_ERR_DB_SERVER:498 psError(PXTOOLS_ERR_PROG, false, "database error");499 default:500 psError(PXTOOLS_ERR_PROG, false, "unknown error");501 }502 return false;503 }504 if (!psArrayLength(warpOutput)) {505 // no warps for this xccal. Suprise?506 psFree(warpOutput);507 psFree(query);508 continue;509 }510 511 // create a staticskyRun512 if (!xcForceRunInsert(config->dbh,513 0x0, // ff_id514 xccal_id,515 path_base,516 "new", // state517 workdir,518 label,519 data_group ? data_group : (xccal_data_group ? xccal_data_group : label),520 dist_group,521 note,522 reduction,523 NULL // registered524 )525 ) {526 if (!psDBRollback(config->dbh)) {527 psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");528 }529 psError(PS_ERR_UNKNOWN, false, "database error");530 psFree(output);531 return false;532 }533 534 psS64 ff_id = psDBLastInsertID(config->dbh);535 536 for (int j = 0; j < warpOutput->n; j++) {537 psMetadata *warpRow = warpOutput->data[j];538 psS64 warp_id = psMetadataLookupS64(&status, warpRow, "warp_id");539 540 if (!xcForceInputInsert(config->dbh,541 ff_id,542 warp_id)543 ) {544 if (!psDBRollback(config->dbh)) {545 psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");546 }547 psError(PS_ERR_UNKNOWN, false, "database error");548 psFree(warpOutput);549 psFree(output);550 return false;551 }552 }553 554 if (!psDBCommit(config->dbh)) {555 psError(PS_ERR_UNKNOWN, false, "database error");556 psFree(warpOutput);557 psFree(output);558 return false;559 }560 psFree(warpOutput);561 }562 psFree(output);563 564 return true;565 }566 567 357 static bool updaterunMode(pxConfig *config) 568 358 { … … 570 360 571 361 psMetadata *where = psMetadataAlloc(); 572 PXOPT_COPY_S64(config->args, where, "- ff_id", "ff_id", "==");362 PXOPT_COPY_S64(config->args, where, "-xcff_id", "xcff_id", "=="); 573 363 PXOPT_COPY_STR(config->args, where, "-label", "xcForceRun.label", "=="); 574 364 PXOPT_COPY_STR(config->args, where, "-data_group", "xcForceRun.data_group", "=="); … … 585 375 } 586 376 587 psString query = psStringCopy("UPDATE xcForceRun JOIN xccalRun USING(xccal_id) JOIN stackRun USING(stack_id) JOIN skycell USING(tess_id, skycell_id)"); 377 psString query = pxDataGet("xcfftool_updaterun.sql"); 378 if (!select) { 379 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 380 return false; 381 } 588 382 589 383 // pxUpdateRun gets parameters from config->args and updates
Note:
See TracChangeset
for help on using the changeset viewer.
