Changeset 34772 for branches/czw_branch/20120906/ippTools/src/stacktool.c
- Timestamp:
- Dec 6, 2012, 6:32:19 PM (14 years ago)
- Location:
- branches/czw_branch/20120906/ippTools/src
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
stacktool.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20120906/ippTools/src
- Property svn:mergeinfo changed
/branches/eam_branches/ipp-20120905/ippTools/src (added) merged: 34428,34466,34566,34575,34735,34747
- Property svn:mergeinfo changed
-
branches/czw_branch/20120906/ippTools/src/stacktool.c
r34296 r34772 37 37 static bool inputskyfileMode(pxConfig *config); 38 38 static bool tosumMode(pxConfig *config); 39 static bool tobkgMode(pxConfig *config); 39 40 static bool addsumskyfileMode(pxConfig *config); 40 41 static bool sumskyfileMode(pxConfig *config); … … 76 77 MODECASE(STACKTOOL_MODE_INPUTSKYFILE, inputskyfileMode); 77 78 MODECASE(STACKTOOL_MODE_TOSUM, tosumMode); 79 MODECASE(STACKTOOL_MODE_TOBKG, tobkgMode); 78 80 MODECASE(STACKTOOL_MODE_ADDSUMSKYFILE, addsumskyfileMode); 79 81 MODECASE(STACKTOOL_MODE_SUMSKYFILE, sumskyfileMode); … … 748 750 PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "=="); 749 751 PXOPT_COPY_S64(config->args, where, "-sass_id", "stackAssociationMap.sass_id", "=="); 752 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 750 753 if (!psListLength(where->list)) { 751 754 psFree(where); … … 756 759 //CZW join against stackAssociationMap 757 760 psString query = psStringCopy("UPDATE stackRun"); 761 762 if (fault) { 763 psStringAppend(&query, " JOIN stackSumSkyfile USING(stack_id)"); 764 PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "=="); 765 } 758 766 759 767 // pxUpdateRun gets parameters from config->args and updates … … 946 954 // negative simple so the default is true 947 955 if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) { 956 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 957 psFree(output); 958 return false; 959 } 960 } 961 962 psFree(output); 963 964 return true; 965 } 966 967 static bool tobkgMode(pxConfig *config) 968 { 969 PS_ASSERT_PTR_NON_NULL(config, false); 970 971 psMetadata *where = psMetadataAlloc(); 972 PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "=="); 973 pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "=="); 974 975 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 976 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 977 978 psString query = pxDataGet("stacktool_tobkg.sql"); 979 if (!query) { 980 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 981 return false; 982 } 983 984 psString whereClause = psStringCopy(""); // WHERE conditions to add 985 if (psListLength(where->list)) { 986 psString new = psDBGenerateWhereConditionSQL(where, NULL); 987 psStringAppend(&whereClause, "\nAND %s", new); 988 psFree(new); 989 } 990 psFree(where); 991 992 psStringAppend(&query, "\nORDER by priority DESC, stack_id"); 993 994 // treat limit == 0 as "no limit" 995 if (limit) { 996 psString limitString = psDBGenerateLimitSQL(limit); 997 psStringAppend(&query, " %s", limitString); 998 psFree(limitString); 999 } 1000 1001 if (!p_psDBRunQueryF(config->dbh, query, whereClause)) { 1002 psError(PS_ERR_UNKNOWN, false, "database error"); 1003 psFree(query); 1004 return false; 1005 } 1006 psFree(query); 1007 1008 psArray *output = p_psDBFetchResult(config->dbh); 1009 if (!output) { 1010 psErrorCode err = psErrorCodeLast(); 1011 switch (err) { 1012 case PS_ERR_DB_CLIENT: 1013 psError(PXTOOLS_ERR_SYS, false, "database error"); 1014 case PS_ERR_DB_SERVER: 1015 psError(PXTOOLS_ERR_PROG, false, "database error"); 1016 default: 1017 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1018 } 1019 1020 return false; 1021 } 1022 if (!psArrayLength(output)) { 1023 psTrace("stacktool", PS_LOG_INFO, "no rows found"); 1024 psFree(output); 1025 return true; 1026 } 1027 1028 if (psArrayLength(output)) { 1029 // negative simple so the default is true 1030 if (!ippdbPrintMetadatas(stdout, output, "stackBkgSkyfile", !simple)) { 948 1031 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 949 1032 psFree(output); … … 1000 1083 PXOPT_LOOKUP_STR(ver_streaks, config->args, "-ver_streaks", false, false); 1001 1084 1085 PXOPT_LOOKUP_S16(background_model, config->args, "-background_model", false, false); 1086 1002 1087 psTrace("czw.test",1,"Received versions: pslib %s psmodules %s psphot %s ppstats %s ppstack %s streaks %s\n", 1003 1088 ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppstack,ver_streaks); … … 1061 1146 fault, 1062 1147 software_ver, 1148 background_model, 1063 1149 quality 1064 1150 )) { … … 1109 1195 PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "=="); 1110 1196 PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE"); 1197 PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "=="); 1111 1198 pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE"); 1112 1199 pxAddLabelSearchArgs(config, where, "-data_group", "stackRun.data_group", "LIKE"); … … 1114 1201 PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackSumSkyfile.mjd_obs", ">="); 1115 1202 PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackSumSkyfile.mjd_obs", "<="); 1116 1203 PXOPT_COPY_S16(config->args, where, "-background_model","stackSumSkyfile.background_model", "=="); 1117 1204 1118 1205 // The following three selectors are incompatible with the sql so omit them … … 1671 1758 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 1672 1759 PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false); 1760 PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false); 1673 1761 1674 1762 psMetadata *where = psMetadataAlloc(); 1675 1763 PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "=="); 1676 1764 1677 if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) { 1765 if (background_model) { 1766 psMetadata *values = psMetadataAlloc(); 1767 PXOPT_COPY_S16(config->args, values, "-set_background_model", "background_model", "=="); 1768 long rows = psDBUpdateRows(config->dbh,"warpSkyfile", where, values); 1769 psFree(values); 1770 if (!rows) { 1771 // This maybe should rollback and error if rows != 1 1772 psError(PS_ERR_UNKNOWN, true, "no rows changed"); 1773 return false; 1774 } 1775 } 1776 else { 1777 if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) { 1678 1778 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1679 1779 psFree (where); 1680 1780 return false; 1781 } 1681 1782 } 1682 1783 psFree (where);
Note:
See TracChangeset
for help on using the changeset viewer.
