Changeset 23497 for trunk/ippTools/src/pztool.c
- Timestamp:
- Mar 24, 2009, 10:18:19 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pztool.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pztool.c
r21479 r23497 44 44 45 45 static bool clearcommonfaultsMode(pxConfig *config); 46 static bool toadvanceMode(pxConfig *config); 46 47 static bool advanceMode(pxConfig *config); 47 48 48 static bool copydoneCompleteExp(pxConfig *config);49 // static bool copydoneCompleteExp(pxConfig *config); 49 50 static psArray *pzGetPendingCameras(pxConfig *config); 50 51 static psArray *pzArrayZip(psArray *arraySet, psS64 limit); … … 80 81 MODECASE(PZTOOL_MODE_REVERTCOPIED, revertcopiedMode); 81 82 MODECASE(PZTOOL_MODE_CLEARCOMMONFAULTS, clearcommonfaultsMode); 83 MODECASE(PZTOOL_MODE_TOADVANCE, toadvanceMode); 82 84 MODECASE(PZTOOL_MODE_ADVANCE, advanceMode); 83 85 default: … … 403 405 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 404 406 405 // NOTE : the rest of the command-line args are parsed in copydoneCompleteExp406 407 407 // start a transaction early so it will contain any row level locks 408 408 if (!psDBTransaction(config->dbh)) { … … 463 463 } 464 464 465 #ifdef notdef466 // we've changed to use -advance instead467 if (!copydoneCompleteExp(config)) {468 // rollback469 if (!psDBRollback(config->dbh)) {470 psError(PS_ERR_UNKNOWN, false, "database error");471 }472 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");473 return false;474 }475 #endif476 465 // point of no return 477 466 if (!psDBCommit(config->dbh)) { … … 487 476 } 488 477 489 static bool copydoneCompleteExp(pxConfig *config) 490 { 491 // THIS FUNCTION MUST BE INVOKED FROM INSIDE A TRANSACTION!!! 492 493 PS_ASSERT_PTR_NON_NULL(config, false); 494 495 // XXX this is an ugly hack! 496 // we are passing exp level info to a imfile level mode (-copydone) 497 // these options are thrown away unless we just -copydone'd the last imfile 498 // in an exp. 499 500 // optional 501 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false); 502 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 503 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false); 504 PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false); 505 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 478 static bool toadvanceMode(pxConfig *config) 479 { 480 PS_ASSERT_PTR_NON_NULL(config, false); 481 482 // optional args 483 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 506 484 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 507 485 … … 517 495 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 518 496 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 519 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 497 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 498 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 520 499 521 500 if (psListLength(where->list)) { … … 525 504 } 526 505 psFree(where); 506 527 507 528 508 // treat limit == 0 as "no limit" … … 552 532 } 553 533 554 for (long i = 0; i < psArrayLength(output); i++) { 555 psMetadata *row = output->data[i]; 556 557 pzDownloadExpRow *doneExp = pzDownloadExpObjectFromMetadata(row); 558 if (!doneExp) { 559 psError(PS_ERR_UNKNOWN, false, "pzDownloadExpObjectFromMetadata() failed"); 560 psFree(doneExp); 561 psFree(output); 562 return false; 563 } 564 565 if (!newExpInsert(config->dbh, 566 0x0, // exp_id 567 doneExp->exp_name, // tmp_exp_name 568 doneExp->camera, // tmp_camera 569 doneExp->telescope, // tmp_telescope 570 "run", // state 571 workdir, // workdir 572 "dirty", // workdir state 573 NULL, // reduction class 574 dvodb, // dvodb 575 tess_id, // tess_id 576 end_stage, // end_stage 577 label, 578 NULL // epoch 579 ) 534 if (!ippdbPrintMetadatas(stdout, output, "toadvance", !simple)) { 535 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 536 psFree(output); 537 return false; 538 } 539 540 psFree(output); 541 542 return true; 543 } 544 545 static bool advanceMode(pxConfig *config) 546 { 547 PS_ASSERT_PTR_NON_NULL(config, false); 548 549 // required 550 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 551 PXOPT_LOOKUP_STR(inst, config->args, "-inst", true, false); 552 PXOPT_LOOKUP_STR(telescope, config->args, "-telescope", true, false); 553 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 554 555 // optional 556 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 557 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false); 558 PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false); 559 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 560 561 // start a transaction so it's all rows or nothing 562 if (!psDBTransaction(config->dbh)) { 563 psError(PS_ERR_UNKNOWN, false, "database error"); 564 return false; 565 } 566 567 if (!newExpInsert(config->dbh, 568 0x0, // exp_id 569 exp_name, // tmp_exp_name 570 inst, // tmp_camera 571 telescope, // tmp_telescope 572 "run", // state 573 workdir, // workdir 574 "dirty", // workdir state 575 NULL, // reduction class 576 dvodb, // dvodb 577 tess_id, // tess_id 578 end_stage, // end_stage 579 label, // label 580 NULL // epoch 581 ) 580 582 ) { 581 583 psError(PS_ERR_UNKNOWN, false, "database error"); 582 psFree(doneExp);583 psFree(output);584 584 return false; 585 585 } … … 592 592 "INSERT INTO newImfile" 593 593 " SElECT" 594 " %" PRId64 "," // exp_id594 " %" PRId64 "," // exp_id 595 595 " pzDownloadImfile.class_id," // tmp_class_id 596 " pzDownloadImfile.uri," // uri597 " NULL" // epoch596 " pzDownloadImfile.uri," // uri 597 " NULL" // epoch 598 598 " FROM pzDownloadImfile" 599 599 " WHERE" … … 602 602 " AND pzDownloadImfile.telescope = '%s'"; 603 603 604 if (!p_psDBRunQueryF(config->dbh, query, exp_id, doneExp->exp_name, doneExp->camera, doneExp->telescope)) { 605 psError(PS_ERR_UNKNOWN, false, "database error"); 606 psFree(doneExp); 607 psFree(output); 608 return false; 609 } 610 611 // sanity check: we should have inserted at least one row 612 psU64 affected = psDBAffectedRows(config->dbh); 613 if (psDBAffectedRows(config->dbh) < 1) { 614 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected); 615 psFree(doneExp); 616 psFree(output); 617 return false; 618 } 619 } 620 621 // set pzDownloadExp.state to 'stop' 622 if (!pzDownloadExpSetState(config, doneExp->exp_name, doneExp->camera, doneExp->telescope, "stop")) { 623 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", doneExp->exp_name, doneExp->camera, doneExp->telescope); 624 psFree(doneExp); 625 psFree(output); 604 if (!p_psDBRunQueryF(config->dbh, query, exp_id, exp_name, inst, telescope)) { 605 psError(PS_ERR_UNKNOWN, false, "database error"); 626 606 return false; 627 } 628 629 psFree(doneExp); 630 } 631 632 psFree(output); 607 } 608 609 // sanity check: we should have inserted at least one row 610 psU64 affected = psDBAffectedRows(config->dbh); 611 if (psDBAffectedRows(config->dbh) < 1) { 612 psError(PS_ERR_UNKNOWN, false, "should have affected at least 1 row but %" PRIu64 " rows were modified", affected); 613 return false; 614 } 615 } 616 617 // set pzDownloadExp.state to 'stop' 618 if (!pzDownloadExpSetState(config, exp_name, inst, telescope, "stop")) { 619 psError(PS_ERR_UNKNOWN, false, "failed to change pzDownloadExp.state for %s:%s:%s", exp_name, inst, telescope); 620 return false; 621 } 622 623 // point of no return 624 if (!psDBCommit(config->dbh)) { 625 // rollback 626 if (!psDBRollback(config->dbh)) { 627 psError(PS_ERR_UNKNOWN, false, "database error"); 628 } 629 psError(PS_ERR_UNKNOWN, false, "database error"); 630 return false; 631 } 632 633 633 634 634 return true; … … 872 872 } 873 873 874 static bool advanceMode(pxConfig *config)875 {876 PS_ASSERT_PTR_NON_NULL(config, false);877 878 // NOTE : the command-line args are parsed in copydoneCompleteExp879 880 // start a transaction so it's all rows or nothing881 if (!psDBTransaction(config->dbh)) {882 psError(PS_ERR_UNKNOWN, false, "database error");883 return false;884 }885 886 if (!copydoneCompleteExp(config)) {887 // rollback888 if (!psDBRollback(config->dbh)) {889 psError(PS_ERR_UNKNOWN, false, "database error");890 }891 psError(PS_ERR_UNKNOWN, false, "copydoneCompleteExp() failed");892 return false;893 }894 895 // point of no return896 if (!psDBCommit(config->dbh)) {897 // rollback898 if (!psDBRollback(config->dbh)) {899 psError(PS_ERR_UNKNOWN, false, "database error");900 }901 psError(PS_ERR_UNKNOWN, false, "database error");902 return false;903 }904 905 906 return true;907 }908 909 874 910 875 static bool pzDownloadExpSetState(pxConfig *config, const char *exp_name, const char *camera, const char *telescope, const char *state)
Note:
See TracChangeset
for help on using the changeset viewer.
