- Timestamp:
- Jan 3, 2014, 1:54:29 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/bills_branches/bills_201312/ippTools/src/fftool.c
r36411 r36417 39 39 static bool revertMode(pxConfig *config); 40 40 static bool updateresultMode(pxConfig *config); 41 42 // static bool setfullForceRunState(pxConfig *config, psS64 sky_id, const char *state); 41 static bool toadvanceMode(pxConfig *config); 42 static bool addsummaryMode(pxConfig *config); 43 static bool revertsummaryMode(pxConfig *config); 44 static bool updatesummaryMode(pxConfig *config); 45 static bool summaryMode(pxConfig *config); 46 47 static bool setfullForceRunState(pxConfig *config, psS64 sky_id, const char *state); 43 48 44 49 # define MODECASE(caseName, func) \ … … 67 72 MODECASE(FFTOOL_MODE_REVERT, revertMode); 68 73 MODECASE(FFTOOL_MODE_UPDATERESULT, updateresultMode); 74 MODECASE(FFTOOL_MODE_TOADVANCE, toadvanceMode); 75 MODECASE(FFTOOL_MODE_ADDSUMMARY, addsummaryMode); 76 MODECASE(FFTOOL_MODE_REVERTSUMMARY, revertsummaryMode); 77 MODECASE(FFTOOL_MODE_UPDATESUMMARY, updatesummaryMode); 78 MODECASE(FFTOOL_MODE_SUMMARY, summaryMode); 69 79 default: 70 80 psAbort("invalid option (this should not happen)"); … … 403 413 } 404 414 405 // the where clause is required and matches the WHERE hook format string406 415 if (!p_psDBRunQuery(config->dbh, query)) { 407 416 psError(PS_ERR_UNKNOWN, false, "database error"); … … 462 471 463 472 // XXX not sure we need a transaction here... 464 if (!psDBTransaction(config->dbh)) {465 psError(PS_ERR_UNKNOWN, false, "database error");466 return false;467 }468 469 473 if (!fullForceResultInsert(config->dbh, 470 474 ff_id, … … 484 488 } 485 489 486 #ifdef notdef487 if (!fault) {488 if (!setfullForceRunState(config, ff_id, "full")) {489 if (!psDBRollback(config->dbh)) {490 psError(PS_ERR_UNKNOWN, false, "database error");491 }492 psError(PS_ERR_UNKNOWN, false, "failed to change staticskyRun state");493 return false;494 }495 }496 #endif497 498 // point of no return499 if (!psDBCommit(config->dbh)) {500 psError(PS_ERR_UNKNOWN, false, "database error");501 return false;502 }503 504 490 return true; 505 491 } … … 594 580 psMetadata *where = psMetadataAlloc(); 595 581 PXOPT_COPY_S64(config->args, where, "-ff_id", "fullForceRun.ff_id", "=="); 582 PXOPT_COPY_S64(config->args, where, "-warp_id", "fullForceResult.warp_id", "=="); 596 583 pxAddLabelSearchArgs(config, where, "-label", "fullForceRun.label", "=="); 597 584 PXOPT_COPY_S16(config->args, where, "-fault", "fullForceResult.fault", "=="); … … 645 632 psMetadata *where = psMetadataAlloc(); 646 633 PXOPT_COPY_S64(config->args, where, "-ff_id", "ff_id", "=="); 647 PXOPT_COPY_S64(config->args, where, "-warp_id", "ff_id", "=="); 648 634 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 649 635 650 636 if (!pxSetFaultCode(config->dbh, "fullForceResult", where, fault, quality)) { … … 656 642 return true; 657 643 } 658 #ifdef notyet 644 659 645 static bool setfullForceRunState(pxConfig *config, psS64 ff_id, const char *state) 660 646 { … … 667 653 return true; 668 654 } 669 #endif 670 655 656 static bool toadvanceMode(pxConfig *config) { 657 PS_ASSERT_PTR_NON_NULL(config, false); 658 659 psMetadata *whereMD = psMetadataAlloc(); 660 PXOPT_COPY_S64(config->args, whereMD, "-ff_id", "ff_id", "=="); 661 pxAddLabelSearchArgs (config, whereMD, "-label", "fullForceRun.label", "=="); 662 pxskycellAddWhere(config, whereMD); 663 664 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 665 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 666 667 psString query = pxDataGet("fftool_toadvance.sql"); 668 if (!query) { 669 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 670 return false; 671 } 672 673 if (!psListLength(whereMD->list)) { 674 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 675 psFree(whereMD); 676 return false; 677 } 678 679 psString whereClause = NULL; 680 psString temp = psDBGenerateWhereConditionSQL(whereMD, NULL); 681 psStringAppend(&whereClause, "\n AND %s", temp); 682 psFree(temp); 683 psFree(whereMD); 684 685 // treat limit == 0 as "no limit" 686 if (limit) { 687 psString limitString = psDBGenerateLimitSQL(limit); 688 psStringAppend(&query, " %s", limitString); 689 psFree(limitString); 690 } 691 692 // the where clause is required and is added to the query by the "WHERE hook" format string 693 if (!p_psDBRunQueryF(config->dbh, query, whereClause)) { 694 psError(PS_ERR_UNKNOWN, false, "database error"); 695 psFree(whereClause); 696 psFree(query); 697 return false; 698 } 699 psFree(whereClause); 700 psFree(query); 701 702 psArray *output = p_psDBFetchResult(config->dbh); 703 if (!output) { 704 psErrorCode err = psErrorCodeLast(); 705 switch (err) { 706 case PS_ERR_DB_CLIENT: 707 psError(PXTOOLS_ERR_SYS, false, "database error"); 708 case PS_ERR_DB_SERVER: 709 psError(PXTOOLS_ERR_PROG, false, "database error"); 710 default: 711 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 712 } 713 714 return false; 715 } 716 if (!psArrayLength(output)) { 717 psTrace("fftool", PS_LOG_INFO, "no rows found"); 718 psFree(output); 719 return true; 720 } 721 722 if (psArrayLength(output)) { 723 // negative simple so the default is true 724 if (!ippdbPrintMetadatas(stdout, output, "fullForceRun", !simple)) { 725 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 726 psFree(output); 727 return false; 728 } 729 } 730 731 psFree(output); 732 return true; 733 } 734 735 static bool addsummaryMode(pxConfig *config) { 736 PS_ASSERT_PTR_NON_NULL(config, false); 737 // required 738 PXOPT_LOOKUP_S64(ff_id, config->args, "-ff_id", true, false); 739 740 // optional 741 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 742 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", true, false); 743 PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false); 744 PXOPT_LOOKUP_STR(software_ver, config->args, "-software_ver", false, false); 745 746 // default values 747 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 748 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 749 750 if (!psDBTransaction(config->dbh)) { 751 psError(PS_ERR_UNKNOWN, false, "database error"); 752 return false; 753 } 754 755 if (!fullForceSummaryInsert(config->dbh, 756 ff_id, 757 path_base, 758 dtime_script, 759 quality, 760 hostname, 761 software_ver, 762 fault 763 )) { 764 if (!psDBRollback(config->dbh)) { 765 psError(PS_ERR_UNKNOWN, false, "database error"); 766 } 767 psError(PS_ERR_UNKNOWN, false, "database error"); 768 return false; 769 } 770 771 if (!fault) { 772 if (!setfullForceRunState(config, ff_id, "full")) { 773 if (!psDBRollback(config->dbh)) { 774 psError(PS_ERR_UNKNOWN, false, "database error"); 775 } 776 psError(PS_ERR_UNKNOWN, false, "failed to change staticskyRun state"); 777 return false; 778 } 779 } 780 781 // point of no return 782 if (!psDBCommit(config->dbh)) { 783 psError(PS_ERR_UNKNOWN, false, "database error"); 784 return false; 785 } 786 787 return true; 788 } 789 790 static bool revertsummaryMode(pxConfig *config) { 791 PS_ASSERT_PTR_NON_NULL(config, false); 792 793 psMetadata *where = psMetadataAlloc(); 794 PXOPT_COPY_S64(config->args, where, "-ff_id", "fullForceRun.ff_id", "=="); 795 pxAddLabelSearchArgs(config, where, "-label", "fullForceRun.label", "=="); 796 PXOPT_COPY_S16(config->args, where, "-fault", "fullForceSummary.fault", "=="); 797 798 if (!pxskycellAddWhere(config, where)) { 799 psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments"); 800 return false; 801 } 802 803 if (!psListLength(where->list)) { 804 psFree(where); 805 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 806 return false; 807 } 808 809 // Delete product 810 psString delete = pxDataGet("fftool_revertsummary.sql"); 811 if (!delete) { 812 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 813 return false; 814 } 815 816 if (psListLength(where->list)) { 817 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 818 psStringAppend(&delete, " AND %s", whereClause); 819 psFree(whereClause); 820 } 821 822 if (!p_psDBRunQuery(config->dbh, delete)) { 823 psError(PS_ERR_UNKNOWN, false, "database error"); 824 psFree(delete); 825 psFree(where); 826 return false; 827 } 828 psFree(delete); 829 830 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 831 psLogMsg("fftool", PS_LOG_INFO, "Deleted %d rows", numRows); 832 833 psFree(where); 834 return true; 835 } 836 static bool updatesummaryMode(pxConfig *config) { 837 PS_ASSERT_PTR_NON_NULL(config, false); 838 839 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 840 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 841 842 psMetadata *where = psMetadataAlloc(); 843 PXOPT_COPY_S64(config->args, where, "-ff_id", "ff_id", "=="); 844 845 846 if (!pxSetFaultCode(config->dbh, "fullForceSummary", where, fault, quality)) { 847 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 848 psFree (where); 849 return false; 850 } 851 psFree (where); 852 return true; 853 } 854 static bool summaryMode(pxConfig *config) { 855 PS_ASSERT_PTR_NON_NULL(config, false); 856 857 psMetadata *where = psMetadataAlloc(); 858 PXOPT_COPY_S64(config->args, where, "-ff_id", "fullForceRun.ff_id", "=="); 859 PXOPT_COPY_S64(config->args, where, "-warp_id", "fullForceInput.warp_id", "=="); 860 PXOPT_COPY_S64(config->args, where, "-skycal_id", "fullForceRun.skycal_id", "=="); 861 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackRun.stack_id", "=="); 862 PXOPT_COPY_STR(config->args, where, "-label", "fullForceRun.label", "=="); 863 PXOPT_COPY_STR(config->args, where, "-data_group", "fullForceRun.data_group", "LIKE"); 864 PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "LIKE"); 865 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE"); 866 PXOPT_COPY_S16(config->args, where, "-fault", "staticskyResult.fault", "=="); 867 pxskycellAddWhere(config, where); 868 869 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 870 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 871 872 psString query = pxDataGet("fftool_summary.sql"); 873 if (!query) { 874 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 875 return false; 876 } 877 878 if (psListLength(where->list)) { 879 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 880 psStringAppend(&query, " WHERE %s", whereClause); 881 psFree(whereClause); 882 } else { 883 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 884 return false; 885 } 886 887 psFree(where); 888 889 // treat limit == 0 as "no limit" 890 if (limit) { 891 psString limitString = psDBGenerateLimitSQL(limit); 892 psStringAppend(&query, "\n%s", limitString); 893 psFree(limitString); 894 } 895 896 if (!p_psDBRunQuery(config->dbh, query)) { 897 psError(PS_ERR_UNKNOWN, false, "database error"); 898 psFree(query); 899 return false; 900 } 901 psFree(query); 902 903 psArray *output = p_psDBFetchResult(config->dbh); 904 if (!output) { 905 psErrorCode err = psErrorCodeLast(); 906 switch (err) { 907 case PS_ERR_DB_CLIENT: 908 psError(PXTOOLS_ERR_SYS, false, "database error"); 909 case PS_ERR_DB_SERVER: 910 psError(PXTOOLS_ERR_PROG, false, "database error"); 911 default: 912 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 913 } 914 915 return false; 916 } 917 if (!psArrayLength(output)) { 918 psTrace("fftool", PS_LOG_INFO, "no rows found"); 919 psFree(output); 920 return true; 921 } 922 923 if (psArrayLength(output)) { 924 if (!ippdbPrintMetadatas(stdout, output, "fullForceSummary", !simple)) { 925 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 926 psFree(output); 927 return false; 928 } 929 } 930 931 psFree(output); 932 933 return true; 934 }
Note:
See TracChangeset
for help on using the changeset viewer.
