Changeset 30586 for branches/czw_branch/20101203/ippTools/src
- Timestamp:
- Feb 11, 2011, 4:29:48 PM (15 years ago)
- Location:
- branches/czw_branch/20101203
- Files:
-
- 19 edited
-
. (modified) (1 prop)
-
ippTools/src/disttool.c (modified) (1 diff)
-
ippTools/src/dqstatstool.c (modified) (6 diffs)
-
ippTools/src/magicdstool.c (modified) (3 diffs)
-
ippTools/src/magicdstoolConfig.c (modified) (1 diff)
-
ippTools/src/magictool.c (modified) (10 diffs, 1 prop)
-
ippTools/src/magictool.h (modified) (1 diff)
-
ippTools/src/magictoolConfig.c (modified) (3 diffs)
-
ippTools/src/pstamptool.c (modified) (2 diffs)
-
ippTools/src/pstamptoolConfig.c (modified) (1 diff)
-
ippTools/src/pubtool.c (modified) (1 diff)
-
ippTools/src/pubtoolConfig.c (modified) (1 diff)
-
ippTools/src/pztool.c (modified) (6 diffs)
-
ippTools/src/pztool.h (modified) (1 diff)
-
ippTools/src/pztoolConfig.c (modified) (3 diffs)
-
ippTools/src/regtool.c (modified) (31 diffs)
-
ippTools/src/regtool.h (modified) (1 diff)
-
ippTools/src/regtoolConfig.c (modified) (5 diffs)
-
ippTools/src/stacktool.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20101203
- Property svn:mergeinfo changed
-
branches/czw_branch/20101203/ippTools/src/disttool.c
r29067 r30586 857 857 psFree(where); 858 858 859 psStringAppend(&query, "\nORDER BY priority DESC, dist_id"); 860 859 861 // treat limit == 0 as "no limit" 860 862 if (limit) { -
branches/czw_branch/20101203/ippTools/src/dqstatstool.c
r28427 r30586 92 92 } 93 93 else { 94 psStringAppend(&query, " AND ( invalid IS NULL OR invalid = 1) ");94 psStringAppend(&query, " AND (warp_id IS NOT NULL AND invalid IS NULL) "); 95 95 } 96 96 … … 402 402 403 403 if (psMetadataLookupStr(&status,enginedef,"COLNAME")&& 404 isfinite(psMetadataLookupF32(&status,enginedef,"MINIMUM"))&& 405 isfinite(psMetadataLookupF32(&status,enginedef,"MAXIMUM"))) { 404 (strcmp(psMetadataLookupStr(&status,enginedef,"RULETYPE"),"STRICT") == 0)&& 405 (isfinite(psMetadataLookupF32(&status,enginedef,"MINIMUM"))&& 406 isfinite(psMetadataLookupF32(&status,enginedef,"MAXIMUM")))) { 406 407 psArrayAdd(decisionRules,decisionRules->n,enginedef); 408 } 409 else if (psMetadataLookupStr(&status,enginedef,"COLNAME")&& 410 (strcmp(psMetadataLookupStr(&status,enginedef,"RULETYPE"),"CDF") == 0)&& 411 (isfinite(psMetadataLookupF32(&status,enginedef,"CDF00"))&& 412 isfinite(psMetadataLookupF32(&status,enginedef,"CDF50"))&& 413 isfinite(psMetadataLookupF32(&status,enginedef,"CDF100")))) { 414 psArrayAdd(decisionRules,decisionRules->n, enginedef); 415 } 416 else if (strcmp(psMetadataLookupStr(&status,enginedef,"RULETYPE"),"UNUSED") == 0) { 407 417 } 408 418 else { … … 637 647 // Calculate if this exposure was "good" or not. 638 648 bool accept = true; 649 psF32 quality = 1.0; 639 650 for (long j = 0; j < decisionRules->n; j++) { 640 651 psMetadata *rule = decisionRules->data[j]; … … 644 655 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find column name"); 645 656 return(false); 646 }647 psF32 min_value = psMetadataLookupF32(&status,rule,"MINIMUM");648 if (!status) {649 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find min value for %s",colname);650 return(false);651 }652 psF32 max_value = psMetadataLookupF32(&status,rule,"MAXIMUM");653 if (!status) {654 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find max value for %s",colname);655 return(false);656 }657 psString filter = psMetadataLookupStr(&status,rule,"FILTER");658 if (!status) {659 status = true;660 }661 if (filter) {662 psString imfilter = psMetadataLookupStr(&status,tableRow,"FILTER");663 if (strcmp(filter,imfilter) != 0) {664 continue;665 }666 657 } 667 658 // Not happy with this being set to a F32. Can this ever be something else? 668 659 psF32 value = psMetadataLookupF32(&status,tableRow,colname); 669 660 if (!status) { 670 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find column %s (%f %f %f) in compare with rule.",colname,min_value,max_value,value); 661 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find column %s (%f) in compare with rule.", 662 colname,value); 671 663 psFree(colNames); 672 664 psFree(colTypes); … … 677 669 return(false); 678 670 } 679 if ((value > max_value)||(value < min_value)) { 680 accept = false; 681 } 671 psString filter = psMetadataLookupStr(&status,rule,"FILTER"); 672 if (!status) { 673 status = true; 674 } 675 if (filter) { 676 psString imfilter = psMetadataLookupStr(&status,tableRow,"FILTER"); 677 if (strcmp(filter,imfilter) != 0) { 678 continue; 679 } 680 } 681 682 if (strcmp(psMetadataLookupStr(&status,rule,"RULETYPE"),"STRICT") == 0) { 683 psF32 min_value = psMetadataLookupF32(&status,rule,"MINIMUM"); 684 if (!status) { 685 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find min value for %s",colname); 686 return(false); 687 } 688 psF32 max_value = psMetadataLookupF32(&status,rule,"MAXIMUM"); 689 if (!status) { 690 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find max value for %s",colname); 691 return(false); 692 } 693 694 if ((value > max_value)||(value < min_value)) { 695 accept = false; 696 } 697 } // End STRICT min/max rule parsing 698 else if (strcmp(psMetadataLookupStr(&status,rule,"RULETYPE"),"CDF") == 0) { 699 // I'm just going to implement a quick linear interpolation over the points that exist. 700 psF32 min_value,max_value = 99; 701 psF32 min_cdf = 0.0,max_cdf = 1.0; 702 psF32 cdf; 703 psF32 try[22] = {0.00,0.05,0.10,0.15,0.20,0.25,0.30,0.35,0.40,0.45,0.50, 704 0.55,0.60,0.65,0.70,0.75,0.80,0.85,0.90,0.95,0.99,1.00}; 705 int i; 706 int done = 0; 707 status = true; 708 min_value = psMetadataLookupF32(&status,rule,"CDF00"); 709 min_cdf = 0.0; 710 if (!isfinite(value)) { 711 quality = 0.0; 712 continue; 713 } 714 if (!status) { 715 status = true; 716 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find CDF00 value for %s",colname); 717 } 718 if (value < min_value) { 719 if (quality > min_cdf) { 720 quality = 0.0; 721 continue; 722 } 723 } 724 725 for (i = 1; i < 22; i++) { 726 psString label = psStringCopy(""); 727 psStringAppend(&label,"CDF%02d",(int) (100 * try[i])); 728 729 max_value = psMetadataLookupF32(&status,rule,label); 730 max_cdf = try[i]; 731 if (!status) { 732 status = true; 733 psError(PS_EXIT_CONFIG_ERROR, false, "Unable to find %s value for %s",label,colname); 734 } 735 if ((value < max_value)&&(value > min_value)) { 736 cdf = ((value - min_value) * max_cdf + (max_value - value) * min_cdf) / (max_value - min_value); 737 // fprintf(stderr,"value: %f %f %f %f %f %f %d %d %f\n",value,quality,min_cdf,min_value,max_cdf,max_value, value < max_value, value > min_value,cdf); 738 if (quality > cdf) { 739 quality = cdf; 740 done = 1; 741 i = 25; 742 } 743 } 744 min_value = max_value; 745 min_cdf = max_cdf; 746 } 747 if (done) { 748 continue; 749 } 750 // Reached end of array without finding the value; 751 if (value > min_value) { 752 if (quality > min_cdf) { 753 quality = 1.0; 754 } 755 } 756 757 758 } // End CDF rule parsing 682 759 } 683 760 bool success; … … 695 772 return(false); 696 773 } 774 success = psMetadataAddF32(tableRow,PS_LIST_TAIL,"QUALITY",0,"",quality); 775 if (!success) { 776 psError(PS_ERR_UNKNOWN,false, "Error adding exposure quality to fits table row."); 777 psFree(colNames); 778 psFree(colTypes); 779 psFree(contents); 780 psFree(query); 781 psFree(outTable); 782 psFree(statsoutput); 783 psFree(statIter); 784 psFree(tableRow); 785 return(false); 786 } 697 787 698 788 // Add the row to the table array. -
branches/czw_branch/20101203/ippTools/src/magicdstool.c
r30118 r30586 1115 1115 psString queryFile = NULL; 1116 1116 if (state) { 1117 if (! strcmp(state, "new") ) {1117 if (! strcmp(state, "new") || !strcmp(state, "goto_restored")) { 1118 1118 queryFile = "magicdstool_revertdestreakedfile.sql"; 1119 1119 } else if (!strcmp(state, "update")) { … … 1724 1724 PXOPT_LOOKUP_STR(component, config->args, "-component", false, false); 1725 1725 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 1726 PXOPT_LOOKUP_STR(recoveryroot, config->args, "-set_recoveryroot", false, false); 1726 1727 1727 1728 psString query = pxDataGet("magicdstool_setfiletoupdate.sql"); … … 1734 1735 if (label) { 1735 1736 psStringAppend(&setHook, "\n , magicDSRun.label = '%s'", label); 1737 } 1738 if (recoveryroot) { 1739 psStringAppend(&setHook, "\n , magicDSRun.recoveryroot = '%s'", recoveryroot); 1736 1740 } 1737 1741 -
branches/czw_branch/20101203/ippTools/src/magicdstoolConfig.c
r30118 r30586 230 230 psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL); 231 231 psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-set_label", 0, "set new label", NULL); 232 psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-set_recoveryroot", 0, "define new recovery directory", NULL); 232 233 233 234 // -destreakedfile -
branches/czw_branch/20101203/ippTools/src/magictool.c
- Property svn:mergeinfo set to
r29625 r30586 49 49 static bool censorrunMode(pxConfig *config); 50 50 static bool exposureMode(pxConfig *config); 51 static bool setgotocleanedMode(pxConfig *config); 52 static bool tocleanupMode(pxConfig *config); 53 static bool setworkdirstateMode(pxConfig *config); 51 54 52 55 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state, psString setString); … … 89 92 MODECASE(MAGICTOOL_MODE_CENSORRUN, censorrunMode); 90 93 MODECASE(MAGICTOOL_MODE_EXPOSURE, exposureMode); 94 MODECASE(MAGICTOOL_MODE_SETGOTOCLEANED, setgotocleanedMode); 95 MODECASE(MAGICTOOL_MODE_TOCLEANUP, tocleanupMode); 96 MODECASE(MAGICTOOL_MODE_SETWORKDIRSTATE, setworkdirstateMode); 91 97 default: 92 98 psAbort("invalid option (this should not happen)"); … … 621 627 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 622 628 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 623 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");629 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 624 630 625 631 psString query = psStringCopy("UPDATE magicRun SET fault = 0 WHERE state = 'new' AND fault != 0"); … … 829 835 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 830 836 831 // look for "inputs" that need to processed832 psString query = pxDataGet("magictool_toprocess_inputs.sql");833 if (!query) {834 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");835 return false;836 }837 838 837 psString whereString = NULL; 839 838 if (psListLength(where->list)) { … … 844 843 psFree(where); 845 844 846 psStringAppend(&query, "\nORDER BY priority DESC, magic_id"); 847 848 // treat limit == 0 as "no limit" 849 if (limit) { 850 // cut limit in half 851 // hack to prevent pending leaf nodes from blocking branch nodes 852 psString limitString = psDBGenerateLimitSQL((limit + 1) / 2); 853 psStringAppend(&query, " %s", limitString); 854 psFree(limitString); 855 } 856 857 if (!p_psDBRunQueryF(config->dbh, query, whereString, whereString)) { 858 psError(PS_ERR_UNKNOWN, false, "database error"); 859 psFree(whereString); 860 psFree(query); 861 return false; 862 } 863 psFree(query); 864 865 psArray *output = p_psDBFetchResult(config->dbh); 866 if (!output) { 867 psErrorCode err = psErrorCodeLast(); 868 switch (err) { 869 case PS_ERR_DB_CLIENT: 870 psError(PXTOOLS_ERR_SYS, false, "database error"); 871 case PS_ERR_DB_SERVER: 872 psError(PXTOOLS_ERR_PROG, false, "database error"); 873 default: 874 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 875 } 876 877 return false; 878 } 879 if (!psArrayLength(output)) { 880 psTrace("magictool", PS_LOG_INFO, "no rows found"); 881 } 882 883 if (limit) { 884 if (psArrayLength(output) >= limit) { 885 // we've found enough (note that limit was applied to the query so '> limit' won't happen) 886 // negative simple so the default is true 887 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 888 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 889 psFree(output); 890 return false; 891 } 892 psFree(output); 893 return true; 894 } 895 } 896 897 // look for tree nodes that need to be processed 845 // First look for branch nodes that need to be processed. 846 // These get priority over skycells because they are from runs 847 // that are already in progress and there are fewer of them. 848 // When we looked for skycells first we got starved. 898 849 899 850 // first find incomplete magicRuns 900 query = pxDataGet("magictool_toprocess_runs.sql");851 psString query = pxDataGet("magictool_toprocess_runs.sql"); 901 852 if (!query) { 902 853 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 904 855 } 905 856 906 // we limit the query even though it is cheap (only magic_id is selected) 907 908 // XXX: if the first 1000 unfinished magicRuns have no ready nodes 909 // that haven't faulted, later runs won't get returned even though 910 // they have work to do. When we used a limit of 100 we actually ran 911 // into this problem. Since we're using labels a limit of 1000 will 912 // probably be ok. 857 // Find outstanding magicRuns in new state. 858 // We limit the query, but this is problematic. In practice do 859 // we need to? 860 // XXX: If the first 1000 magicRuns have no branch nodes ready 861 // but higher runs do we they won't be noticed. 862 // Perhaps have this limit be an argument. 913 863 { 914 864 psString limitString = psDBGenerateLimitSQL( 1000 ); … … 940 890 return false; 941 891 } 892 942 893 if (!psArrayLength(magicRuns)) { 894 // no pending magicRuns nothing to do 943 895 psTrace("magictool", PS_LOG_INFO, "no rows found"); 944 psFree(magicRuns);945 896 return true; 946 897 } 947 948 query = pxDataGet("magictool_toprocess_tree.sql"); 898 psArray *output = psArrayAllocEmpty(100); 899 900 { 901 query = pxDataGet("magictool_toprocess_tree.sql"); 902 if (!query) { 903 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 904 return false; 905 } 906 907 for (psS64 index = 0; index < psArrayLength(magicRuns); index++) { 908 if (limit && (psArrayLength(output) >= limit)) { 909 break; 910 } 911 bool status; 912 psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id"); 913 if (!status) { 914 psAbort("failed to lookup value for magic_id column"); 915 } 916 917 whereString = NULL; 918 psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id); 919 if (!p_psDBRunQueryF(config->dbh, query, whereString )) { 920 psError(PS_ERR_UNKNOWN, false, "database error"); 921 psFree(whereString); 922 psFree(query); 923 return false; 924 } 925 psFree(whereString); 926 psArray *magicTree = p_psDBFetchResult(config->dbh); 927 if (!magicTree) { 928 psErrorCode err = psErrorCodeLast(); 929 switch (err) { 930 case PS_ERR_DB_CLIENT: 931 psError(PXTOOLS_ERR_SYS, false, "database error"); 932 case PS_ERR_DB_SERVER: 933 psError(PXTOOLS_ERR_PROG, false, "database error"); 934 default: 935 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 936 } 937 938 return false; 939 } 940 psS64 length = psArrayLength(magicTree); 941 if (!length) { 942 psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id); 943 psFree(magicTree); 944 continue; 945 } 946 947 psHash *forest = psHashAlloc(length); 948 949 // convert the array of metadata into a pxTree structure 950 for (long i = 0; i < length; i++) { 951 bool status; 952 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); 953 if (!status) { 954 psAbort("failed to lookup value for node column"); 955 } 956 957 psString dep = psMetadataLookupStr(&status, magicTree->data[i], "dep"); 958 if (!status) { 959 psAbort("failed to lookup value for dep column"); 960 } 961 962 pxTreeBuilder(forest, node, dep, magicTree->data[i]); 963 964 } 965 966 // find the root of the tree 967 pxNode *root = psMemIncrRefCounter(psHashLookup(forest, "root")); 968 psFree(forest); 969 // pxTreePrint(stdout, root); 970 971 // crawl through the tree and looking for nodes with children that are all 972 // "done" 973 pxTreeCrawl(root, findReadyNodes, output); 974 psFree(root); 975 psFree(magicTree); 976 } 977 978 int len = psArrayLength(output); 979 if (len) { 980 if (limit) { 981 if (limit < psArrayLength(output)) { 982 // truncate the array 983 long arrayLength = psArrayLength(output); 984 for (long i = arrayLength - 1; i >= limit; i--) { 985 psArrayRemoveIndex(output, i); 986 } 987 // negative simple so the default is true 988 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 989 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 990 psFree(output); 991 return false; 992 } 993 psFree(output); 994 return true; 995 } else { 996 limit -= len; 997 } 998 } 999 } 1000 } 1001 1002 // look for "inputs" (skycells) that need to processed 1003 query = pxDataGet("magictool_toprocess_inputs.sql"); 949 1004 if (!query) { 950 1005 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 952 1007 } 953 1008 954 for (psS64 index = 0; index < psArrayLength(magicRuns); index++) { 955 if (limit && (psArrayLength(output) >= limit)) { 956 break; 957 } 958 bool status; 959 psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id"); 960 if (!status) { 961 psAbort("failed to lookup value for magic_id column"); 962 } 963 964 whereString = NULL; 965 psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id); 966 if (!p_psDBRunQueryF(config->dbh, query, whereString )) { 967 psError(PS_ERR_UNKNOWN, false, "database error"); 968 psFree(whereString); 969 psFree(query); 970 return false; 971 } 1009 psStringAppend(&query, "\nORDER BY priority DESC, magic_id"); 1010 1011 // treat limit == 0 as "no limit" 1012 if (limit) { 1013 psString limitString = psDBGenerateLimitSQL(limit); 1014 psStringAppend(&query, " %s", limitString); 1015 psFree(limitString); 1016 } 1017 1018 if (!p_psDBRunQueryF(config->dbh, query, whereString, whereString)) { 1019 psError(PS_ERR_UNKNOWN, false, "database error"); 972 1020 psFree(whereString); 973 psArray *magicTree = p_psDBFetchResult(config->dbh); 974 if (!magicTree) { 975 psErrorCode err = psErrorCodeLast(); 976 switch (err) { 977 case PS_ERR_DB_CLIENT: 978 psError(PXTOOLS_ERR_SYS, false, "database error"); 979 case PS_ERR_DB_SERVER: 980 psError(PXTOOLS_ERR_PROG, false, "database error"); 981 default: 982 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 983 } 984 985 return false; 986 } 987 psS64 length = psArrayLength(magicTree); 988 if (!length) { 989 psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id); 990 psFree(magicTree); 991 continue; 992 } 993 994 psHash *forest = psHashAlloc(length); 995 996 // convert the array of metadata into a pxTree structure 997 for (long i = 0; i < length; i++) { 998 bool status; 999 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); 1000 if (!status) { 1001 psAbort("failed to lookup value for node column"); 1002 } 1003 1004 psString dep = psMetadataLookupStr(&status, magicTree->data[i], "dep"); 1005 if (!status) { 1006 psAbort("failed to lookup value for dep column"); 1007 } 1008 1009 pxTreeBuilder(forest, node, dep, magicTree->data[i]); 1010 1011 } 1012 1013 // find the root of the tree 1014 pxNode *root = psMemIncrRefCounter(psHashLookup(forest, "root")); 1015 psFree(forest); 1016 // pxTreePrint(stdout, root); 1017 1018 // crawl through the tree and looking for nodes with children that are all 1019 // "done" 1020 pxTreeCrawl(root, findReadyNodes, output); 1021 psFree(root); 1022 psFree(magicTree); 1023 } 1024 1021 psFree(query); 1022 return false; 1023 } 1024 psFree(query); 1025 1026 psArray *skycellOutput = p_psDBFetchResult(config->dbh); 1027 if (!skycellOutput) { 1028 psErrorCode err = psErrorCodeLast(); 1029 switch (err) { 1030 case PS_ERR_DB_CLIENT: 1031 psError(PXTOOLS_ERR_SYS, false, "database error"); 1032 case PS_ERR_DB_SERVER: 1033 psError(PXTOOLS_ERR_PROG, false, "database error"); 1034 default: 1035 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1036 } 1037 1038 return false; 1039 } 1040 // merge the arrays so that we can print them all at once 1041 if (psArrayLength(skycellOutput)) { 1042 int len = psArrayLength(skycellOutput); 1043 for (int i=0; i < len; i++) { 1044 psArrayAdd(output, 0, skycellOutput->data[i]); 1045 } 1046 } 1047 psFree(skycellOutput); 1025 1048 if (psArrayLength(output)) { 1026 if (limit && (limit < psArrayLength(output))) {1027 // truncate the array1028 long arrayLength = psArrayLength(output);1029 for (long i = arrayLength - 1; i >= limit; i--) {1030 psArrayRemoveIndex(output, i);1031 }1032 }1033 // negative simple so the default is true1034 1049 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 1035 1050 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 1037 1052 return false; 1038 1053 } 1039 } 1040 1054 } else { 1055 psTrace("magictool", PS_LOG_INFO, "no rows found"); 1056 } 1041 1057 psFree(output); 1042 1043 1058 return true; 1044 1059 } … … 1622 1637 return true; 1623 1638 } 1639 static bool setgotocleanedMode(pxConfig *config) 1640 { 1641 PS_ASSERT_PTR_NON_NULL(config, false); 1642 1643 psMetadata *where = psMetadataAlloc(); 1644 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 1645 PXOPT_COPY_S64(config->args, where, "-exp_id", "magicRun.exp_id", "=="); 1646 PXOPT_COPY_STR(config->args, where, "-label", "magicRun.label", "LIKE"); 1647 PXOPT_COPY_STR(config->args, where, "-data_group", "magicRun.data_group", "LIKE"); 1648 1649 PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false); 1650 1651 psString query = psStringCopy("UPDATE magicRun SET workdir_state = 'goto_cleaned'\n"); 1652 if (set_label) { 1653 psStringAppend(&query, ", label = '%s'", set_label); 1654 } 1655 // This mode doubles as a revert function for cleanup errors 1656 PXOPT_LOOKUP_BOOL(clearfault, config->args, "-clearfault", false); 1657 if (!clearfault) { 1658 psStringAppend(&query, "WHERE workdir_state = 'dirty'"); 1659 } else { 1660 psStringAppend(&query, "WHERE workdir_state = 'error_cleaned'"); 1661 } 1662 psStringAppend(&query, "\nAND (magicRun.state = 'full' OR magicRun.state = 'drop')"); 1663 1664 // Require search parameters unless we're just clearing faults 1665 if (psListLength(where->list)) { 1666 psString clause = psDBGenerateWhereConditionSQL(where, NULL); 1667 psStringAppend(&query, "\nAND %s", clause); 1668 psFree(clause); 1669 psFree(where); 1670 } else if ( !clearfault) { 1671 psError(PS_ERR_UNKNOWN, false, "search parameters are required"); 1672 psFree(where); 1673 return false; 1674 } 1675 1676 if (!p_psDBRunQuery(config->dbh, query)) { 1677 psError(PS_ERR_UNKNOWN, false, "database error"); 1678 psFree(query); 1679 return false; 1680 } 1681 psFree(query); 1682 1683 return true; 1684 } 1685 1686 static bool setworkdirstateMode(pxConfig *config) 1687 { 1688 PS_ASSERT_PTR_NON_NULL(config, false); 1689 1690 // required 1691 PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false); 1692 PXOPT_LOOKUP_STR(workdir_state, config->args, "-set_workdir_state", true, false); 1693 1694 if (strcmp(workdir_state, "cleaned") && strcmp(workdir_state, "error_cleaned")) { 1695 psError(PS_ERR_UNKNOWN, true, "%s is not a valid value for workdir_state", workdir_state); 1696 return false; 1697 } 1698 1699 psString query = NULL; 1700 psStringAppend(&query, "UPDATE magicRun SET workdir_state = '%s' WHERE magic_id = %" PRId64, workdir_state, magic_id); 1701 1702 if (!p_psDBRunQuery(config->dbh, query)) { 1703 psError(PS_ERR_UNKNOWN, false, "database error"); 1704 psFree(query); 1705 return false; 1706 } 1707 psFree(query); 1708 1709 return true; 1710 } 1711 static bool tocleanupMode(pxConfig *config) 1712 { 1713 PS_ASSERT_PTR_NON_NULL(config, false); 1714 1715 psMetadata *where = psMetadataAlloc(); 1716 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 1717 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 1718 pxAddLabelSearchArgs (config, where, "-data_group", "magicRun.data_group", "=="); 1719 1720 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1721 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1722 1723 psString query = pxDataGet("magictool_tocleanup.sql"); 1724 if (!query) { 1725 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1726 return false; 1727 } 1728 1729 if (psListLength(where->list)) { 1730 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1731 psStringAppend(&query, " AND %s", whereClause); 1732 psFree(whereClause); 1733 } 1734 psFree(where); 1735 1736 psStringAppend(&query, "\nORDER BY priority DESC, magic_id"); 1737 1738 // treat limit == 0 as "no limit" 1739 if (limit) { 1740 psString limitString = psDBGenerateLimitSQL(limit); 1741 psStringAppend(&query, " %s", limitString); 1742 psFree(limitString); 1743 } 1744 1745 if (!p_psDBRunQuery(config->dbh, query)) { 1746 psError(PS_ERR_UNKNOWN, false, "database error"); 1747 psFree(query); 1748 return false; 1749 } 1750 psFree(query); 1751 1752 psArray *output = p_psDBFetchResult(config->dbh); 1753 if (!output) { 1754 psErrorCode err = psErrorCodeLast(); 1755 switch (err) { 1756 case PS_ERR_DB_CLIENT: 1757 psError(PXTOOLS_ERR_SYS, false, "database error"); 1758 case PS_ERR_DB_SERVER: 1759 psError(PXTOOLS_ERR_PROG, false, "database error"); 1760 default: 1761 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1762 } 1763 1764 return false; 1765 } 1766 if (!psArrayLength(output)) { 1767 psTrace("magictool", PS_LOG_INFO, "no rows found"); 1768 psFree(output); 1769 return true; 1770 } 1771 1772 if (psArrayLength(output)) { 1773 // negative simple so the default is true 1774 if (!ippdbPrintMetadatas(stdout, output, "tocleanup", !simple)) { 1775 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1776 psFree(output); 1777 return false; 1778 } 1779 } 1780 1781 psFree(output); 1782 1783 return true; 1784 } -
branches/czw_branch/20101203/ippTools/src/magictool.h
r27982 r30586 43 43 MAGICTOOL_MODE_CENSORRUN, 44 44 MAGICTOOL_MODE_EXPOSURE, 45 MAGICTOOL_MODE_SETGOTOCLEANED, 46 MAGICTOOL_MODE_TOCLEANUP, 47 MAGICTOOL_MODE_SETWORKDIRSTATE, 45 48 } MAGICtoolMode; 46 49 -
branches/czw_branch/20101203/ippTools/src/magictoolConfig.c
r29495 r30586 114 114 psMetadataAddS64(reverttreeArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magictool ID", 0); 115 115 psMetadataAddS16(reverttreeArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0); 116 psMetadataAddStr(reverttreeArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);116 psMetadataAddStr(reverttreeArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by label", NULL); 117 117 118 118 // -inputs … … 178 178 psMetadataAddBool(exposureArgs, PS_LIST_TAIL, "-inverse", 0, "select the inverse subtraction?", false); 179 179 psMetadataAddBool(exposureArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 180 181 // -setgotocleaned 182 psMetadata *setgotocleanedArgs = psMetadataAlloc(); 183 psMetadataAddS64(setgotocleanedArgs, PS_LIST_TAIL, "-magic_id", 0, "select by magictool ID", 0); 184 psMetadataAddS64(setgotocleanedArgs, PS_LIST_TAIL, "-exp_id", 0, "select by exposure ID)", 0); 185 psMetadataAddStr(setgotocleanedArgs, PS_LIST_TAIL, "-label", 0, "select by label", NULL); 186 psMetadataAddStr(setgotocleanedArgs, PS_LIST_TAIL, "-data_group", 0, "select by data_group", NULL); 187 psMetadataAddStr(setgotocleanedArgs, PS_LIST_TAIL, "-set_label", 0, "set new label", NULL); 188 psMetadataAddBool(setgotocleanedArgs, PS_LIST_TAIL, "-clearfault", 0, "clear cleanup errors", NULL); 189 190 // -tocleanup 191 psMetadata *tocleanupArgs = psMetadataAlloc(); 192 psMetadataAddS64(tocleanupArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magic ID", 0); 193 psMetadataAddStr(tocleanupArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by label", NULL); 194 psMetadataAddStr(tocleanupArgs, PS_LIST_TAIL, "-data_group", PS_META_DUPLICATE_OK, "search by label", NULL); 195 psMetadataAddU64(tocleanupArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 196 psMetadataAddBool(tocleanupArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 197 198 // -setworkdirstate 199 psMetadata *setworkdirstateArgs = psMetadataAlloc(); 200 psMetadataAddS64(setworkdirstateArgs, PS_LIST_TAIL, "-magic_id", 0, "select by magictool ID (required)", 0); 201 psMetadataAddStr(setworkdirstateArgs, PS_LIST_TAIL, "-set_workdir_state", 0, "new workdir_state (required)", 0); 180 202 181 203 psFree(now); … … 202 224 PXOPT_ADD_MODE("-censorrun", "", MAGICTOOL_MODE_CENSORRUN, censorrunArgs); 203 225 PXOPT_ADD_MODE("-exposure", "", MAGICTOOL_MODE_EXPOSURE, exposureArgs); 226 PXOPT_ADD_MODE("-setgotocleaned", "", MAGICTOOL_MODE_SETGOTOCLEANED, setgotocleanedArgs); 227 PXOPT_ADD_MODE("-tocleanup", "", MAGICTOOL_MODE_TOCLEANUP, tocleanupArgs); 228 PXOPT_ADD_MODE("-setworkdirstate", "", MAGICTOOL_MODE_SETWORKDIRSTATE, setworkdirstateArgs); 204 229 205 230 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { -
branches/czw_branch/20101203/ippTools/src/pstamptool.c
r30118 r30586 134 134 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 135 135 PXOPT_LOOKUP_S32(pollInterval, config->args, "-set_poll_interval",false, false); 136 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-set_no_magic", false); 137 138 bool need_magic = ! no_magic; 136 139 137 140 if (!pstampDataStoreInsert(config->dbh, … … 143 146 outProduct, 144 147 uri, 145 pollInterval 148 pollInterval, 149 need_magic 146 150 )) { 147 151 psError(PS_ERR_UNKNOWN, false, "database error"); -
branches/czw_branch/20101203/ippTools/src/pstamptoolConfig.c
r30118 r30586 51 51 psMetadataAddStr(adddatastoreArgs, PS_LIST_TAIL, "-set_label", 0, "define datastore label", NULL); 52 52 psMetadataAddS32(adddatastoreArgs, PS_LIST_TAIL, "-set_poll_interval", 0, "define datastore poll interval (seconds)", 60); 53 psMetadataAddBool(adddatastoreArgs,PS_LIST_TAIL, "-set_no_magic", 0, "set magic not required", true); 53 54 54 55 // -datastore -
branches/czw_branch/20101203/ippTools/src/pubtool.c
r30118 r30586 167 167 PXOPT_COPY_STR(config->args, diffWhere, "-filter", "rawExp.filter", "LIKE"); 168 168 PXOPT_COPY_STR(config->args, diffWhere, "-obs_mode", "rawExp.obs_mode", "LIKE"); 169 PXOPT_COPY_STR(config->args, diffWhere, "-comment", "rawExp.comment", "LIKE"); 169 170 170 171 PXOPT_COPY_S64(config->args, camWhere, "-client_id", "client_id", "=="); -
branches/czw_branch/20101203/ippTools/src/pubtoolConfig.c
r30118 r30586 66 66 psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "set and search by label", NULL); 67 67 psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-data_group", PS_META_DUPLICATE_OK, "search by data_group", NULL); 68 psMetadataAddStr(definerunArgs, PS_LIST_TAIL, "-comment", 0, "search by comment", NULL); 68 69 psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-dateobs_begin", 0, "search for exposures by time (>=)", NULL); 69 70 psMetadataAddTime(definerunArgs, PS_LIST_TAIL, "-dateobs_end", 0, "search for exposures by time (<=)", NULL); -
branches/czw_branch/20101203/ippTools/src/pztool.c
r29982 r30586 47 47 static bool advanceMode(pxConfig *config); 48 48 49 static bool updatepzexpMode(pxConfig *config); 50 static bool updatenewexpMode(pxConfig *config); 51 49 52 // static bool copydoneCompleteExp(pxConfig *config); 50 53 static psArray *pzGetPendingCameras(pxConfig *config); … … 83 86 MODECASE(PZTOOL_MODE_TOADVANCE, toadvanceMode); 84 87 MODECASE(PZTOOL_MODE_ADVANCE, advanceMode); 88 MODECASE(PZTOOL_MODE_UPDATEPZEXP, updatepzexpMode); 89 MODECASE(PZTOOL_MODE_UPDATENEWEXP, updatenewexpMode); 85 90 default: 86 91 psAbort("invalid option (this should not happen)"); … … 294 299 295 300 psMetadata *where = psMetadataAlloc(); 296 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 297 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 298 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 299 PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "=="); 301 PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "=="); 302 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 303 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 304 PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "=="); 305 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">="); 306 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<="); 300 307 301 308 PXOPT_LOOKUP_BOOL(desc, config->args, "-desc", false); … … 325 332 326 333 if (psListLength(where->list)) { 327 psString whereClause = psDBGenerateWhereConditionSQL(where, "pzDownloadImfile");334 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 328 335 psStringAppend(&query, " AND %s", whereClause); 329 336 psFree(whereClause); … … 889 896 || (strncmp(state, "stop", 5) == 0) 890 897 || (strncmp(state, "reg", 4) == 0) 898 || (strncmp(state, "drop", 5) == 0) 891 899 ) 892 900 ) { … … 905 913 } 906 914 915 static bool updatepzexpMode(pxConfig *config) 916 { 917 PS_ASSERT_PTR_NON_NULL(config, false); 918 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 919 PXOPT_LOOKUP_STR(camera, config->args, "-inst", true, false); 920 PXOPT_LOOKUP_STR(telescope,config->args, "-telescope",true, false); 921 PXOPT_LOOKUP_STR(state, config->args, "-set_state",true, false); 922 923 if (!pzDownloadExpSetState(config,exp_name,camera,telescope,state)) { 924 psError(PS_ERR_UNKNOWN, false, "failed to change state for %s:%s:%s", exp_name, camera, telescope); 925 return false; 926 } 927 return true; 928 } 929 930 931 static bool updatenewexpMode(pxConfig *config) 932 { 933 PS_ASSERT_PTR_NON_NULL(config, false); 934 935 psMetadata *where = psMetadataAlloc(); 936 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 937 PXOPT_COPY_STR(config->args, where, "-exp_name", "tmp_exp_name", "=="); 938 939 PXOPT_LOOKUP_STR(new_state, config->args, "-set_state", true, false); 940 941 if (strcmp(new_state, "drop") && strcmp(new_state, "run") && strcmp(new_state, "wait")) { 942 psError(PXTOOLS_ERR_ARGUMENTS, true, "%s is not a valid value for -set_state", new_state); 943 psFree(where); 944 return false; 945 } 946 947 if (psListLength(where->list) < 1) { 948 psFree(where); 949 psError(PXTOOLS_ERR_CONFIG, false, "-exp_name or -exp_id is required"); 950 return false; 951 } 952 953 psString query = NULL; 954 psStringAppend(&query, "UPDATE newExp SET state = '%s'", new_state); 955 956 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 957 psStringAppend(&query, "\nWHERE %s", whereClause); 958 959 psFree(whereClause); 960 psFree(where); 961 962 if (!p_psDBRunQuery(config->dbh, query)) { 963 psError(PS_ERR_UNKNOWN, false, "database error"); 964 psFree(query); 965 return false; 966 } 967 psFree(query); 968 969 return true; 970 } 971 972 973 907 974 908 975 #if 0 -
branches/czw_branch/20101203/ippTools/src/pztool.h
r23497 r30586 36 36 PZTOOL_MODE_CLEARCOMMONFAULTS, 37 37 PZTOOL_MODE_TOADVANCE, 38 PZTOOL_MODE_ADVANCE 38 PZTOOL_MODE_ADVANCE, 39 PZTOOL_MODE_UPDATEPZEXP, 40 PZTOOL_MODE_UPDATENEWEXP, 39 41 } pztoolMode; 40 42 -
branches/czw_branch/20101203/ippTools/src/pztoolConfig.c
r27082 r30586 76 76 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-inst", 0, "define camera ID", NULL); 77 77 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-telescope", 0, "define telescope ID", NULL); 78 psMetadataAddTime(pendingimfileArgs, PS_LIST_TAIL, "-dateobs_begin", 0, "search for exposures by time (>=)", NULL); 79 psMetadataAddTime(pendingimfileArgs, PS_LIST_TAIL, "-dateobs_end", 0, "search for exposures by time (<=)", NULL); 78 80 psMetadataAddStr(pendingimfileArgs, PS_LIST_TAIL, "-exp_type", 0, "define exposure type", NULL); 79 81 psMetadataAddBool(pendingimfileArgs, PS_LIST_TAIL, "-desc", 0, "sort ouput in descending format", false); … … 154 156 psMetadataAddStr(advanceArgs, PS_LIST_TAIL, "-label", 0, "define the label for the chip stage", NULL); 155 157 158 // -updatepzexp 159 psMetadata *updatepzexpArgs = psMetadataAlloc(); 160 psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-exp_name", 0, "search by exposure name (required)", NULL); 161 psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-inst", 0, "search by camera (required)", NULL); 162 psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-telescope", 0, "search by telescope (required)", NULL); 163 psMetadataAddStr(updatepzexpArgs, PS_LIST_TAIL, "-set_state", 0, "define new state (required)", NULL); 164 165 // -updatenewexp 166 psMetadata *updatenewexpArgs = psMetadataAlloc(); 167 psMetadataAddS64(updatenewexpArgs, PS_LIST_TAIL, "-exp_id", 0, "search by exposure ID", 0); 168 169 psMetadataAddStr(updatenewexpArgs, PS_LIST_TAIL, "-exp_name", 0, "define exposure ID", NULL); 170 psMetadataAddStr(updatenewexpArgs, PS_LIST_TAIL, "-set_state", 0, "define new state (required)", NULL); 171 156 172 psMetadata *argSets = psMetadataAlloc(); 157 173 psMetadata *modes = psMetadataAlloc(); … … 169 185 PXOPT_ADD_MODE("-toadvance", "", PZTOOL_MODE_TOADVANCE, toadvanceArgs); 170 186 PXOPT_ADD_MODE("-advance", "", PZTOOL_MODE_ADVANCE, advanceArgs); 187 PXOPT_ADD_MODE("-updatepzexp", "", PZTOOL_MODE_UPDATEPZEXP, updatepzexpArgs); 188 PXOPT_ADD_MODE("-updatenewexp", "", PZTOOL_MODE_UPDATENEWEXP,updatenewexpArgs); 171 189 172 190 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { -
branches/czw_branch/20101203/ippTools/src/regtool.c
r30118 r30586 51 51 static bool updatebyqueryMode(pxConfig *config); 52 52 53 static bool checkstatusMode(pxConfig *config); 54 53 55 static bool exportrunMode(pxConfig *config); 54 56 static bool importrunMode(pxConfig *config); … … 74 76 // imfile 75 77 MODECASE(REGTOOL_MODE_PENDINGIMFILE, pendingimfileMode); 76 MODECASE(REGTOOL_MODE_CHECKBURNTOOLIMFILE, checkburntoolimfileMode);77 MODECASE(REGTOOL_MODE_PENDINGBURNTOOLIMFILE, pendingburntoolimfileMode);78 MODECASE(REGTOOL_MODE_CHECKBURNTOOLIMFILE, checkburntoolimfileMode); 79 MODECASE(REGTOOL_MODE_PENDINGBURNTOOLIMFILE, pendingburntoolimfileMode); 78 80 MODECASE(REGTOOL_MODE_ADDPROCESSEDIMFILE, addprocessedimfileMode); 79 81 MODECASE(REGTOOL_MODE_PROCESSEDIMFILE, processedimfileMode); … … 90 92 MODECASE(REGTOOL_MODE_FINISHCOMPRESSEXP, finishcompressexpMode); 91 93 MODECASE(REGTOOL_MODE_CLEARDUPEXP, cleardupexpMode); 94 MODECASE(REGTOOL_MODE_CHECKSTATUS, checkstatusMode); 92 95 MODECASE(REGTOOL_MODE_EXPORTRUN, exportrunMode); 93 96 MODECASE(REGTOOL_MODE_IMPORTRUN, importrunMode); … … 95 98 psAbort("invalid option (this should not happen)"); 96 99 } 97 100 psTrace("regtool",9,"Attempting to free config\n"); 98 101 psFree(config); 99 102 pmConfigDone(); … … 180 183 } 181 184 185 186 187 182 188 static bool checkburntoolimfileMode(pxConfig *config) 183 189 { … … 187 193 PXOPT_LOOKUP_STR(exp_name, config->args, "-exp_name", true, false); 188 194 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 189 PXOPT_LOOKUP_STR(date, config->args, "-date", true, false); 195 PXOPT_LOOKUP_STR(dateobs_begin, config->args, "-dateobs_begin", true, false); 196 PXOPT_LOOKUP_STR(dateobs_end, config->args, "-dateobs_end", true, false); 190 197 PXOPT_LOOKUP_S32(valid_burntool, config->args, "-valid_burntool", true, false); 191 198 // optional … … 201 208 psFree(query); 202 209 query = rep; 210 211 // convert regular class_id format to summitImfile.class_id format 212 rep = psStringCopy(class_id); 213 psFree(class_id); 214 class_id = rep; 215 216 psStringSubstitute(&class_id,"ota","XY"); 203 217 204 218 psStringSubstitute(&query,exp_name,"@EXP_NAME@"); 205 219 psStringSubstitute(&query,class_id,"@CLASS_ID@"); 206 psStringSubstitute(&query,date,"@DATE@"); 207 208 fprintf(stderr,"%s",query); 220 psStringSubstitute(&query,dateobs_begin,"@DATEOBS_BEGIN@"); 221 psStringSubstitute(&query,dateobs_end,"@DATEOBS_END@"); 222 223 // fprintf(stderr,"%s",query); 209 224 210 225 if (!p_psDBRunQuery(config->dbh, query)) { … … 215 230 } 216 231 psFree(query); 217 232 218 233 psArray *output = p_psDBFetchResult(config->dbh); 219 234 if (!output) { … … 227 242 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 228 243 } 229 244 230 245 return false; 231 246 } 232 247 if (!psArrayLength(output)) { 233 248 psTrace("regtool", PS_LOG_INFO, "no rows found"); 234 psFree(output);235 249 return true; 236 250 } … … 242 256 psMetadata *row = output->data[i]; 243 257 258 if (strcasecmp(psMetadataLookupStr(NULL,row,"download_state"),"drop") == 0) { 259 continue; 260 } 261 244 262 if ((psMetadataLookupS32(NULL,row,"is_downloaded") != 1)|| 245 (psMetadataLookupS32(NULL,row,"is_registered") != 1)) {263 (psMetadataLookupS32(NULL,row,"is_registered") != 1)) { 246 264 ok_to_burn = false; 247 265 } … … 255 273 already_burned = false; 256 274 } 257 275 258 276 if (previous_uri) { 259 277 psMetadataAddStr(row,PS_LIST_TAIL,"previous_uri",PS_META_REPLACE,"",previous_uri); … … 264 282 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); 265 283 } 266 284 267 285 // negate simple so the default is true 268 286 if (!ippdbPrintMetadatas(stdout, output, "regBurntoolImfile", !simple)) { … … 271 289 return false; 272 290 } 273 291 274 292 psFree(output); 275 293 276 294 277 295 return(true); 278 296 279 297 } 280 298 … … 284 302 285 303 // required 286 PXOPT_LOOKUP_STR(date, config->args, "-date", true, false); 304 PXOPT_LOOKUP_STR(dateobs_begin, config->args, "-dateobs_begin", true, false); 305 PXOPT_LOOKUP_STR(dateobs_end, config->args, "-dateobs_end", true, false); 287 306 PXOPT_LOOKUP_S32(valid_burntool, config->args, "-valid_burntool", true, false); 288 307 // optional … … 297 316 psFree(query); 298 317 query = rep; 299 300 psStringSubstitute(&query,date,"@DATE@"); 301 302 // fprintf(stderr,"%s",query); 318 319 psStringSubstitute(&query,dateobs_begin,"@DATEOBS_BEGIN@"); 320 psStringSubstitute(&query,dateobs_end,"@DATEOBS_END@"); 321 322 // fprintf(stderr,"%s",query); 303 323 304 324 if (!p_psDBRunQuery(config->dbh, query)) { … … 309 329 } 310 330 psFree(query); 311 331 312 332 psArray *output = p_psDBFetchResult(config->dbh); 313 333 if (!output) { … … 321 341 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 322 342 } 323 343 324 344 return false; 325 345 } 346 347 // fprintf (stderr, "found %ld rows\n", output->n); 326 348 if (!psArrayLength(output)) { 327 349 psTrace("regtool", PS_LOG_INFO, "no rows found"); … … 337 359 psString this_class_id = NULL; 338 360 psArray *results = psArrayAllocEmpty(60); // List of suggested imfiles to burntool. 339 361 340 362 for (long i = 0; i < output->n; i++) { 341 363 psMetadata *row = output->data[i]; 342 364 365 if (strcasecmp(psMetadataLookupStr(NULL,row,"download_state"),"drop") == 0) { 366 continue; 367 } 368 369 bool status = false; 370 char *tmp_id = psMetadataLookupStr(&status,row,"summit_class_id"); 371 if (!status) { 372 // fprintf (stderr, "incomplete on %s\n", psMetadataLookupStr(NULL,row,"exp_name")); 373 continue; 374 } 375 343 376 // Add the information about this row and the previous, if it exists. 344 377 // Write the class_id stuff for debugging. 345 this_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"tmp_class_id")); 346 psStringSubstitute(&this_class_id,"XY","ota"); 378 // this_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"tmp_class_id")); 379 this_class_id = psStringCopy(tmp_id); 380 347 381 psMetadataAddStr(row,PS_LIST_TAIL,"this_class_id",PS_META_REPLACE,"",this_class_id); 382 348 383 if (previous_class_id) { 349 384 psMetadataAddStr(row,PS_LIST_TAIL,"previous_class_id",PS_META_REPLACE,"",previous_class_id); … … 353 388 continue; 354 389 } 390 391 if (0 && !strcmp(this_class_id, "ota44")) { 392 printf("STAT 1: %s (%d %d) %d %d %d\n", 393 this_class_id, 394 ok_to_burn, already_burned, 395 psMetadataLookupS32(NULL,row,"burntool_state"), 396 psMetadataLookupS32(NULL,row,"is_registered"), 397 psMetadataLookupS32(NULL,row,"is_downloaded")); 398 } 399 355 400 // Determine if we've crossed a class_id boundary, as this resets the bits. 356 401 if (previous_class_id) { 357 402 if (strcmp(this_class_id,previous_class_id) != 0) { 358 ok_to_burn = true; 359 already_burned = true; 360 previous_uri = NULL; 403 ok_to_burn = true; 404 already_burned = true; 405 previous_uri = NULL; 406 // fprintf (stderr, "crossed boundary: %s : %s to %s\n", psMetadataLookupStr(NULL,row,"exp_name"), previous_class_id, this_class_id); 361 407 } 362 408 } … … 364 410 // Write the URIs as well. 365 411 this_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Duplicate, but helpful for my debugging. 366 psMetadataAddStr(row,PS_LIST_TAIL,"this_uri",PS_META_REPLACE,"",this_uri); 412 psMetadataAddStr(row,PS_LIST_TAIL,"this_uri",PS_META_REPLACE,"",this_uri); 367 413 if (previous_uri) { 368 414 psMetadataAddStr(row,PS_LIST_TAIL,"previous_uri",PS_META_REPLACE,"",previous_uri); … … 372 418 // Convert bits of the SQL query into booleans describing the data state 373 419 if ((psMetadataLookupS32(NULL,row,"is_downloaded") != 1)|| 374 (psMetadataLookupS32(NULL,row,"is_registered") != 1)) {375 // printf("I claim this isn't downloaded or registered? %s %s\n",this_uri,this_class_id);376 ok_to_burn = false;420 (psMetadataLookupS32(NULL,row,"is_registered") != 1)) { 421 // printf("I claim this isn't downloaded or registered? %s %s\n",this_uri,this_class_id); 422 ok_to_burn = false; 377 423 } 378 424 if (already_burned == false) { 379 //printf("already_burned looks false %s %s\n",this_uri,this_class_id);380 ok_to_burn = false;425 // printf("already_burned looks false %s %s\n",this_uri,this_class_id); 426 ok_to_burn = false; 381 427 } 382 428 if (abs(psMetadataLookupS32(NULL,row,"burntool_state")) == valid_burntool) { … … 391 437 // Check the uri for this exposure 392 438 if (!this_uri) { 393 ok_to_burn = false; 394 already_burned = false; 395 396 // Save this round for next round. 397 psFree(previous_class_id); 398 psFree(previous_uri); 399 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"tmp_class_id")); 400 psStringSubstitute(&previous_class_id,"XY","ota"); 401 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 402 continue; 403 } 404 405 // printf("STATUS: %s %s %s %s (%d %d) %d %d %d\n",this_uri,previous_uri,this_class_id,previous_class_id,ok_to_burn,already_burned,psMetadataLookupS32(NULL,row,"burntool_state"),psMetadataLookupS32(NULL,row,"is_registered"),psMetadataLookupS32(NULL,row,"is_downloaded")); 406 407 // If the state of this imfile is not "pending_burntool" then we can't burn it. 439 ok_to_burn = false; 440 already_burned = false; 441 442 // fprintf (stderr, "missing uri: %s %s\n", psMetadataLookupStr(NULL,row,"exp_name"), this_class_id); 443 444 // Save this round for next round. 445 psFree(previous_class_id); 446 psFree(previous_uri); 447 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"summit_class_id")); 448 psStringSubstitute(&previous_class_id,"ota","XY"); 449 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 450 continue; 451 } 452 453 if (0 && !strcmp(this_class_id, "ota44")) { 454 printf("STATUS: %s %s %s %s (%d %d) %d %d %d\n",this_uri,previous_uri,this_class_id,previous_class_id,ok_to_burn,already_burned,psMetadataLookupS32(NULL,row,"burntool_state"),psMetadataLookupS32(NULL,row,"is_registered"),psMetadataLookupS32(NULL,row,"is_downloaded")); 455 } 456 // If the state of this imfile is not "pending_burntool" then we can't burn it. 408 457 if (!ignore_state) { 409 458 psString imfile_state = psMetadataLookupStr(NULL,row,"imfile_state"); 410 459 411 460 if (!imfile_state) { // imfile state is NULL, so we probably aren't registered. 412 ok_to_burn = false; 413 414 // Save this round for next round. 415 psFree(previous_class_id); 416 psFree(previous_uri); 417 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"tmp_class_id")); 418 psStringSubstitute(&previous_class_id,"XY","ota"); 419 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 420 continue; 461 ok_to_burn = false; 462 463 // fprintf (stderr, "missing imfile_state: %s %s\n", psMetadataLookupStr(NULL,row,"exp_name"), this_class_id); 464 465 // Save this round for next round. 466 psFree(previous_class_id); 467 psFree(previous_uri); 468 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"summit_class_id")); 469 psStringSubstitute(&previous_class_id,"ota","XY"); 470 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 471 continue; 421 472 } 422 if (strcmp("pending_burntool",imfile_state) != 0) { // Probably the state is full, do not twiddle states 423 // Save this round for next round. 424 psFree(previous_class_id); 425 psFree(previous_uri); 426 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"tmp_class_id")); 427 psStringSubstitute(&previous_class_id,"XY","ota"); 428 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 429 continue; 473 if (strcmp("pending_burntool",imfile_state) != 0) { // Probably the state is full, do not twiddle states 474 475 if (0 && strcmp(imfile_state, "full")) { 476 fprintf (stderr, "not pending nor full: %s %s %s\n", psMetadataLookupStr(NULL,row,"exp_name"), this_class_id, imfile_state); 477 } 478 479 // Save this round for next round. 480 psFree(previous_class_id); 481 psFree(previous_uri); 482 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"summit_class_id")); 483 psStringSubstitute(&previous_class_id,"ota","XY"); 484 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 485 continue; 430 486 } 431 487 } 432 488 433 489 // Determine if we've already suggested an entry for this ota, and if not, copy this 434 490 // suggestion into our output result list. … … 437 493 psFree(previous_class_id); 438 494 psFree(previous_uri); 439 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row," tmp_class_id"));440 psStringSubstitute(&previous_class_id," XY","ota");441 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 495 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"summit_class_id")); 496 psStringSubstitute(&previous_class_id,"ota","XY"); 497 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 442 498 continue; 443 499 } … … 448 504 psFree(previous_class_id); 449 505 psFree(previous_uri); 450 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row," tmp_class_id"));451 psStringSubstitute(&previous_class_id," XY","ota");452 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 453 } 454 506 previous_class_id = psStringCopy(psMetadataLookupStr(NULL,row,"summit_class_id")); 507 psStringSubstitute(&previous_class_id,"ota","XY"); 508 previous_uri = psStringCopy(psMetadataLookupStr(NULL,row,"uri")); // Save for next round. 509 } 510 455 511 // negate simple so the default is true 456 512 if (!ippdbPrintMetadatas(stdout, results, "regPendingBurntoolImfile", !simple)) { … … 460 516 return false; 461 517 } 462 518 463 519 psFree(output); 464 520 psFree(results); 465 521 466 522 467 523 return(true); 468 469 } 470 471 524 525 } 526 527 472 528 473 529 static bool addprocessedimfileMode(pxConfig *config) … … 545 601 PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", false, false); 546 602 PXOPT_LOOKUP_BOOL(video_cells, config->args, "-video_cells", false); 547 603 548 604 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 549 605 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); … … 618 674 bytes, 619 675 md5sum, 620 video_cells, 621 0 // burntool_state676 0, // burntool_state 677 video_cells 622 678 )) { 623 679 psError(PS_ERR_UNKNOWN, false, "database error"); … … 771 827 psStringAppend(&query, " AND %s", whereClause); 772 828 psFree(whereClause); 773 } else {774 psFree(where);775 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");776 return false;777 829 } 778 830 psFree(where); … … 806 858 PXOPT_LOOKUP_STR(set_state, config->args, "-set_state", false, false); 807 859 808 if ((fault == INT16_MAX) && !isfinite(burntool_state) && !(set_state)) {860 if ((fault == INT16_MAX) && (burntool_state == INT16_MAX) && !set_state) { 809 861 psError(PS_ERR_UNKNOWN, false, "one of -fault or -burntool_state or -set_state must be selected"); 810 862 return false; 811 863 } 812 if ((fault != INT16_MAX) && isfinite(burntool_state)) {864 if ((fault != INT16_MAX) && (burntool_state != INT16_MAX)) { 813 865 psError(PS_ERR_UNKNOWN, false, "only one of -fault or -burntool_state must be selected"); 814 866 return false; … … 1312 1364 if (!pxchipQueueByExpTag(config, 1313 1365 exp_id, 1314 chip_workdir,1366 chip_workdir, 1315 1367 label, 1316 data_group,1317 dist_group,1368 data_group, 1369 dist_group, 1318 1370 reduction, 1319 1371 NULL, // expgroup … … 1831 1883 } 1832 1884 1885 static bool checkstatusMode(pxConfig *config) 1886 { 1887 PS_ASSERT_PTR_NON_NULL(config,false); 1888 1889 // required 1890 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 1891 // Conditionally required 1892 PXOPT_LOOKUP_STR(dateobs_begin, config->args, "-dateobs_begin", false, false); 1893 PXOPT_LOOKUP_STR(dateobs_end, config->args, "-dateobs_end", false, false); 1894 PXOPT_LOOKUP_STR(date, config->args, "-date", false, false); 1895 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1896 1897 psString query = pxDataGet("regtool_checkstatus.sql"); 1898 if (!query) { 1899 psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement"); 1900 return false; 1901 } 1902 psString rep = psStringCopy(query); 1903 psFree(query); 1904 query = rep; 1905 psStringSubstitute(&class_id,"ota","XY"); 1906 psStringSubstitute(&query,class_id,"@CLASS_ID@"); 1907 1908 if (!date) { 1909 if (!dateobs_begin || !dateobs_end) { 1910 psError(PXTOOLS_ERR_CONFIG, false, "Either -date or -dateobs_begin -dateobs_end is required"); 1911 psFree(query); 1912 return false; 1913 } 1914 psStringAppend(&query," AND summitExp.dateobs >= '%s' AND summitExp.dateobs <= '%s' ", 1915 dateobs_begin,dateobs_end); 1916 } 1917 else { 1918 psStringAppend(&query," AND summitExp.dateobs >= '%sT00:00:00' AND summitExp.dateobs <= '%sT23:59:59' ", 1919 date,date); 1920 } 1921 1922 psStringAppend(&query," ORDER BY summitExp.dateobs "); 1923 1924 if (!p_psDBRunQuery(config->dbh, query)) { 1925 // XXX PS_EXIT_PROG_ERROR (incorrect SQL) or SYS_ERROR (database comms) 1926 psError(PXTOOLS_ERR_PROG, false, "database error"); 1927 psFree(query); 1928 return false; 1929 } 1930 psFree(query); 1931 1932 psArray *output = p_psDBFetchResult(config->dbh); 1933 if (!output) { 1934 psErrorCode err = psErrorCodeLast(); 1935 switch (err) { 1936 case PS_ERR_DB_CLIENT: 1937 psError(PXTOOLS_ERR_SYS, false, "database error"); 1938 case PS_ERR_DB_SERVER: 1939 psError(PXTOOLS_ERR_PROG, false, "database error"); 1940 default: 1941 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1942 } 1943 1944 return false; 1945 } 1946 if (!psArrayLength(output)) { 1947 psTrace("regtool", PS_LOG_INFO, "no rows found"); 1948 return true; 1949 } 1950 1951 if (!ippdbPrintMetadatas(stdout, output, "regCheckStatus", !simple)) { 1952 psError(PXTOOLS_ERR_PROG, false, "failed to print array"); 1953 psFree(output); 1954 return false; 1955 } 1956 1957 psFree(output); 1958 1959 return(true); 1960 } 1961 1833 1962 bool exportrunMode(pxConfig *config) 1834 1963 { -
branches/czw_branch/20101203/ippTools/src/regtool.h
r29908 r30586 41 41 REGTOOL_MODE_PENDINGCOMPRESSIMFILE, 42 42 REGTOOL_MODE_FINISHCOMPRESSEXP, 43 REGTOOL_MODE_CHECKSTATUS, 43 44 REGTOOL_MODE_EXPORTRUN, 44 45 REGTOOL_MODE_IMPORTRUN -
branches/czw_branch/20101203/ippTools/src/regtoolConfig.c
r30014 r30586 57 57 ADD_OPT(Str, checkburntoolimfileArgs, "-exp_name", "define the exp_name (required)", NULL); 58 58 ADD_OPT(Str, checkburntoolimfileArgs, "-class_id", "define class ID (required)", NULL); 59 ADD_OPT(Str, checkburntoolimfileArgs, "-date", "select the date to process (required)", NULL); 59 ADD_OPT(Str, checkburntoolimfileArgs, "-dateobs_begin", "set the earliest summit dateobs to consider (required)", NULL); 60 ADD_OPT(Str, checkburntoolimfileArgs, "-dateobs_end", "set the latest summit dateobs to consider (required)", NULL); 60 61 ADD_OPT(S32, checkburntoolimfileArgs, "-valid_burntool", "define the good burntool value (required)", 0); 61 62 ADD_OPT(Str, checkburntoolimfileArgs, "-inst", "define the camera name", NULL); … … 65 66 // -pendingburntoolimfile 66 67 psMetadata *pendingburntoolimfileArgs = psMetadataAlloc(); 67 ADD_OPT(Str, pendingburntoolimfileArgs, "-date", "select the date to process (required)", NULL); 68 ADD_OPT(Str, pendingburntoolimfileArgs, "-dateobs_begin", "set the earliest summit dateobs to consider (required)", NULL); 69 ADD_OPT(Str, pendingburntoolimfileArgs, "-dateobs_end", "set the latest summit dateobs to consider (required)", NULL); 68 70 ADD_OPT(S32, pendingburntoolimfileArgs, "-valid_burntool", "define the good burntool value (required)", 0); 69 71 ADD_OPT(Bool, pendingburntoolimfileArgs, "-simple", "use the simple output format", false); 70 72 ADD_OPT(Bool, pendingburntoolimfileArgs, "-ignore_state", "ignore the data_state when deciding what to work on", false); 71 73 ADD_OPT(U64, pendingburntoolimfileArgs, "-limit", "limit result set to N items", 0); 72 74 73 75 // -addprocessedimfile 74 76 psMetadata *addprocessedimfileArgs = psMetadataAlloc(); … … 178 180 ADD_OPT(S64, revertprocessedimfileArgs, "-exp_id_begin", "search by exposure ID", 0); 179 181 ADD_OPT(S64, revertprocessedimfileArgs, "-exp_id_end", "search by exposure ID", 0); 182 // This argument is not used but is needed because the task uses add.poll.args 183 ADD_OPT(U64, revertprocessedimfileArgs, "-limit", "for compatability not used", 0); 180 184 181 185 // -updateprocessedimfile … … 415 419 psMetadataAddBool(finishcompressexpArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 416 420 psMetadataAddU64(finishcompressexpArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 421 422 // -checkstatus 423 psMetadata *checkstatusArgs = psMetadataAlloc(); 424 ADD_OPT(Str, checkstatusArgs, "-dateobs_begin", "set the earlist summit dateobs to consider", NULL); 425 ADD_OPT(Str, checkstatusArgs, "-dateobs_end", "set the latest summit dateobs to consider", NULL); 426 ADD_OPT(Str, checkstatusArgs, "-date", "use default observing extent and look over entire night", NULL); 427 ADD_OPT(Str, checkstatusArgs, "-class_id", "define class ID (required)", NULL); 428 ADD_OPT(Bool, checkstatusArgs, "-simple", "use the simple output format", false); 417 429 418 430 psMetadata *argSets = psMetadataAlloc(); … … 435 447 PXOPT_ADD_MODE("-pendingcompressimfile", "", REGTOOL_MODE_PENDINGCOMPRESSIMFILE, pendingcompressimfileArgs); 436 448 PXOPT_ADD_MODE("-finishcompressexp", "", REGTOOL_MODE_FINISHCOMPRESSEXP, finishcompressexpArgs); 449 PXOPT_ADD_MODE("-checkstatus", "", REGTOOL_MODE_CHECKSTATUS, checkstatusArgs); 437 450 PXOPT_ADD_MODE("-exportrun", "export run for import on other database", REGTOOL_MODE_EXPORTRUN, exportrunArgs); 438 451 PXOPT_ADD_MODE("-importrun", "import run from metadata file", REGTOOL_MODE_IMPORTRUN, importrunArgs); -
branches/czw_branch/20101203/ippTools/src/stacktool.c
r29418 r30586 497 497 psError(PS_ERR_UNKNOWN, false, "database error"); 498 498 psFree(output); 499 psFree(run);500 499 psFree(insert); 501 500 psFree(list); … … 517 516 psError(PS_ERR_UNKNOWN, false, "database error"); 518 517 psFree(output); 519 psFree(run);520 518 psFree(insert); 521 519 psFree(list);
Note:
See TracChangeset
for help on using the changeset viewer.
