Changeset 27838 for branches/tap_branches/ippTools/src/difftool.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/difftool.c (modified) (68 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippTools/src
- Property svn:ignore
-
old new 16 16 difftool 17 17 disttool 18 dqstatstool 18 19 faketool 19 20 flatcorr
-
- Property svn:ignore
-
branches/tap_branches/ippTools/src/difftool.c
r25851 r27838 43 43 static bool definewarpstackMode(pxConfig *config); 44 44 static bool definewarpwarpMode(pxConfig *config); 45 static bool definestackstackMode(pxConfig *config); 45 46 static bool pendingcleanuprunMode(pxConfig *config); 46 47 static bool pendingcleanupskyfileMode(pxConfig *config); … … 55 56 static bool topurgedskyfileMode(pxConfig *config); 56 57 static bool toscrubbedskyfileMode(pxConfig *config); 58 static bool tofullskyfileMode(pxConfig *config); 59 static bool listrunMode(pxConfig *config); 60 static bool setskyfiletoupdateMode(pxConfig *config); 57 61 58 62 … … 88 92 MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACK, definewarpstackMode); 89 93 MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP, definewarpwarpMode); 94 MODECASE(DIFFTOOL_MODE_DEFINESTACKSTACK, definestackstackMode); 90 95 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); 91 96 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode); … … 94 99 MODECASE(DIFFTOOL_MODE_EXPORTRUN, exportrunMode); 95 100 MODECASE(DIFFTOOL_MODE_IMPORTRUN, importrunMode); 96 MODECASE(DIFFTOOL_MODE_TOCLEANEDSKYFILE, tocleanedskyfileMode); 97 MODECASE(DIFFTOOL_MODE_TOPURGEDSKYFILE, topurgedskyfileMode); 98 MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE, toscrubbedskyfileMode); 101 MODECASE(DIFFTOOL_MODE_TOCLEANEDSKYFILE, tocleanedskyfileMode); 102 MODECASE(DIFFTOOL_MODE_TOPURGEDSKYFILE, topurgedskyfileMode); 103 MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE, toscrubbedskyfileMode); 104 MODECASE(DIFFTOOL_MODE_TOFULLSKYFILE, tofullskyfileMode); 105 MODECASE(DIFFTOOL_MODE_LISTRUN, listrunMode); 106 MODECASE(DIFFTOOL_MODE_SETSKYFILETOUPDATE, setskyfiletoupdateMode); 99 107 100 108 default: … … 132 140 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 133 141 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 134 PXOPT_LOOKUP_STR(reduction, config->args, "-rset_eduction", false, false); 142 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 143 PXOPT_LOOKUP_S16(diff_mode, config->args, "-set_diff_mode", false, false); 135 144 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 136 145 … … 153 162 exposure, 154 163 false, 164 diff_mode, 155 165 note 156 166 ); … … 186 196 psMetadata *where = psMetadataAlloc(); 187 197 188 PXOPT_COPY_S64(config->args, where, "-diff_id", " stack_id", "==");198 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 189 199 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 200 PXOPT_COPY_STR(config->args, where, "-data_group","data_group", "=="); 190 201 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 191 202 if (!psListLength(where->list)) { 192 203 psFree(where); 193 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");204 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 194 205 return false; 195 206 } … … 198 209 199 210 // pxUpdateRun gets parameters from config->args and updates 200 bool result = pxUpdateRun(config, where, &query, "diffRun", true);211 bool result = pxUpdateRun(config, where, &query, "diffRun", "diff_id", "diffSkyfile", true); 201 212 202 213 psFree(query); … … 204 215 205 216 return result; 206 207 #ifdef notdef208 // required options209 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);210 PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);211 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);212 213 // Copy of my hacky work around from stacktool.c214 if ((state)&&(diff_id)) {215 // set detRun.state to state216 return setdiffRunState(config, diff_id, state, false);217 }218 219 if ((state)&&(label)) {220 return setdiffRunStateByLabel(config, label, state);221 }222 223 psError(PS_ERR_UNKNOWN, false, "Required options not found.");224 225 return false;226 #endif227 217 } 228 218 … … 379 369 psString query = pxDataGet("difftool_inputskyfile.sql"); 380 370 if (!query) { 381 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");382 return false; 383 } 384 385 psString whereClause = NULL;371 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 372 return false; 373 } 374 375 psString whereClause = psStringCopy(""); 386 376 if (psListLength(where->list)) { 387 377 whereClause = psDBGenerateWhereConditionSQL(where, NULL); 388 psStringPrepend(&whereClause, "\n AND");378 psStringPrepend(&whereClause, "\n WHERE "); 389 379 } 390 380 psFree(where); 391 381 392 382 // Add condition to get only templates or only inputs 383 psString templateClause = psStringCopy(""); 393 384 { 394 psString templateClause = NULL;395 385 if (template) { 396 psStringAppend(&templateClause, " %s", " template != 0");386 psStringAppend(&templateClause, "\n WHERE %s", " template != 0"); 397 387 } else if (input) { 398 psStringAppend(&templateClause, " %s", " template = 0"); 399 } 400 if (templateClause) { 401 psStringAppend(&whereClause, "\n AND %s", templateClause); 402 } 403 psFree(templateClause); 388 psStringAppend(&templateClause, "\n WHERE %s", " template = 0"); 389 } 404 390 } 405 391 … … 412 398 } 413 399 414 if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause, whereClause, whereClause)) { 415 psError(PS_ERR_UNKNOWN, false, "database error"); 400 if (!p_psDBRunQueryF(config->dbh, query, whereClause, whereClause, whereClause, whereClause, templateClause)) { 401 psError(PS_ERR_UNKNOWN, false, "database error"); 402 psFree(templateClause); 416 403 psFree(whereClause); 417 404 psFree(query); 418 405 return false; 419 406 } 407 psFree(templateClause); 420 408 psFree(whereClause); 421 409 psFree(query); … … 469 457 psString query = pxDataGet("difftool_todiffskyfile.sql"); 470 458 if (!query) { 471 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");459 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 472 460 return false; 473 461 } … … 626 614 psString query = pxDataGet("difftool_completed_runs.sql"); 627 615 if (!query) { 628 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");616 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 629 617 return false; 630 618 } … … 717 705 PXOPT_COPY_S64(config->args, where, "-magicked", "diffSkyfile.magicked", "=="); 718 706 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 719 707 pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE"); 708 709 PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false); 720 710 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 721 711 if (!template) { … … 725 715 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawInput.dateobs", ">="); 726 716 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawInput.dateobs", "<="); 727 PXOPT_COPY_STR(config->args, where, "-filter", "rawInput.filter", " ==");717 PXOPT_COPY_STR(config->args, where, "-filter", "rawInput.filter", "LIKE"); 728 718 } else { 729 719 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawTemplate.exp_id", "=="); … … 732 722 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawTemplate.dateobs", ">="); 733 723 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawTemplate.dateobs", "<="); 734 PXOPT_COPY_STR(config->args, where, "-filter", "rawTemplate.filter", " ==");724 PXOPT_COPY_STR(config->args, where, "-filter", "rawTemplate.filter", "LIKE"); 735 725 } 736 726 … … 745 735 psString query = pxDataGet("difftool_skyfile.sql"); 746 736 if (!query) { 747 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");737 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 748 738 return false; 749 739 } … … 756 746 psStringAppend(&query, " WHERE diffRun.diff_id is not null %s", where2); 757 747 } else if (!all) { 758 psError(PXTOOLS_ERR_ DATA, true, "search parameters or -all are required");748 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 759 749 return false; 760 750 } 761 751 psFree(where); 762 752 753 if (pstamp_order) { 754 if (template) { 755 psStringAppend(&query, " ORDER BY rawTemplate.exp_id, diff_id DESC"); 756 } else { 757 psStringAppend(&query, " ORDER BY rawInput.exp_id, diff_id DESC"); 758 } 759 } 760 763 761 // treat limit == 0 as "no limit" 764 762 if (limit) { … … 816 814 psMetadata *where = psMetadataAlloc(); 817 815 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffSkyfile.diff_id", "=="); 818 PXOPT_COPY_STR(config->args, where, "-label", "diffRun.label", "=="); 816 PXOPT_COPY_STR(config->args, where, "-skycell_id", "diffSkyfile.skycell_id", "=="); 817 pxAddLabelSearchArgs(config, where, "-label", "diffRun.label", "=="); 819 818 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 820 819 821 820 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 822 821 psFree(where); 823 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 824 return false; 825 } 826 827 if (!psDBTransaction(config->dbh)) { 828 psError(PS_ERR_UNKNOWN, false, "database error"); 829 psFree(where); 830 return false; 831 } 832 833 // Update state to 'new' 822 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 823 return false; 824 } 825 834 826 { 835 psString query = pxDataGet("difftool_revertdiffskyfile_ update.sql");827 psString query = pxDataGet("difftool_revertdiffskyfile_delete.sql"); 836 828 if (!query) { 837 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 838 if (!psDBRollback(config->dbh)) { 839 psError(PS_ERR_UNKNOWN, false, "database error"); 840 } 829 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 830 return false; 831 } 832 psString query_updated = pxDataGet("difftool_revertdiffskyfile_updated.sql"); 833 if (!query_updated) { 834 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 841 835 return false; 842 836 } … … 845 839 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 846 840 psStringAppend(&query, " AND %s", whereClause); 841 psStringAppend(&query_updated, " AND %s", whereClause); 847 842 psFree(whereClause); 848 843 } … … 851 846 psError(PS_ERR_UNKNOWN, false, "database error"); 852 847 psFree(query); 853 if (!psDBRollback(config->dbh)) {854 psError(PS_ERR_UNKNOWN, false, "database error");855 }856 848 return false; 857 849 } 858 850 psFree(query); 851 psLogMsg("difftool", PS_LOG_INFO, "Deleted %" PRIu64 " rows", psDBAffectedRows(config->dbh)); 852 853 if (!p_psDBRunQuery(config->dbh, query_updated)) { 854 psError(PS_ERR_UNKNOWN, false, "database error"); 855 psFree(query_updated); 856 return false; 857 } 858 psFree(query_updated); 859 859 860 860 psLogMsg("difftool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh)); 861 861 } 862 862 863 // Delete product864 {865 psString query = pxDataGet("difftool_revertdiffskyfile_delete.sql");866 if (!query) {867 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");868 if (!psDBRollback(config->dbh)) {869 psError(PS_ERR_UNKNOWN, false, "database error");870 }871 return false;872 }873 874 if (psListLength(where->list)) {875 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);876 psStringAppend(&query, " AND %s", whereClause);877 psFree(whereClause);878 }879 880 if (!p_psDBRunQuery(config->dbh, query)) {881 psError(PS_ERR_UNKNOWN, false, "database error");882 psFree(query);883 if (!psDBRollback(config->dbh)) {884 psError(PS_ERR_UNKNOWN, false, "database error");885 }886 return false;887 }888 psFree(query);889 890 psLogMsg("difftool", PS_LOG_INFO, "Deleted %" PRIu64 " rows", psDBAffectedRows(config->dbh));891 }892 893 863 psFree(where); 894 864 895 if (!psDBCommit(config->dbh)) {896 psError(PS_ERR_UNKNOWN, false, "database error");897 return false;898 }899 865 900 866 return true; … … 914 880 if (magicked) { 915 881 char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64; 916 882 917 883 if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) { 918 884 psError(PS_ERR_UNKNOWN, false, … … 923 889 else { 924 890 char *query = "UPDATE diffRun SET state = '%s' WHERE diff_id = %"PRId64; 925 891 926 892 if (!p_psDBRunQueryF(config->dbh, query, state, diff_id)) { 927 893 psError(PS_ERR_UNKNOWN, false, … … 930 896 } 931 897 } 932 898 933 899 return true; 934 900 } … … 948 914 if (!p_psDBRunQueryF(config->dbh,query,state,label)) { 949 915 psError(PS_ERR_UNKNOWN, false, 950 "failed to change state for label %s", label);916 "failed to change state for label %s", label); 951 917 return(false); 952 918 } … … 986 952 return false; 987 953 } 954 psS16 diff_mode = IPP_DIFF_MODE_UNDEFINED; 955 if ((input_warp_id != PS_MAX_S64) && (template_warp_id != PS_MAX_S64)) { 956 diff_mode = IPP_DIFF_MODE_WARP_WARP; 957 } 958 else if ((input_warp_id != PS_MAX_S64) && (template_stack_id != PS_MAX_S64)) { 959 diff_mode = IPP_DIFF_MODE_WARP_STACK; 960 } 961 else if ((input_stack_id != PS_MAX_S64) && (template_warp_id != PS_MAX_S64)) { 962 diff_mode = IPP_DIFF_MODE_STACK_WARP; 963 } 964 else if ((input_stack_id != PS_MAX_S64) && (template_stack_id != PS_MAX_S64)) { 965 diff_mode = IPP_DIFF_MODE_STACK_STACK; 966 } 967 988 968 989 969 // default … … 1005 985 false, 1006 986 0, // magicked 987 diff_mode, // diff_mode 1007 988 note 1008 989 ); … … 1110 1091 1111 1092 psArray *list = psArrayAllocEmpty(16); // List of runs, to print 1112 1093 // Populated Run will generate the diff_mode value 1113 1094 if (!populatedrun(list, workdir, skycell_id, tess_id, label, data_group ? data_group : label, dist_group, reduction, note, 1114 1095 input_warp_id ? input_warp_id : PS_MAX_S64, … … 1138 1119 1139 1120 psMetadata *expWhere = psMetadataAlloc(); 1140 psMetadata *warpWhere = psMetadataAlloc(); 1121 psMetadata *warp1Where = psMetadataAlloc(); // First set of restrictions on warp 1122 psMetadata *warp2Where = psMetadataAlloc(); // Second set of restriction on warp 1141 1123 psMetadata *stackWhere = psMetadataAlloc(); 1142 1124 1143 1125 PXOPT_COPY_S64(config->args, expWhere, "-exp_id", "exp_id", "=="); 1144 1126 PXOPT_COPY_STR(config->args, expWhere, "-filter", "filter", "=="); 1145 PXOPT_COPY_S64(config->args, warpWhere, "-warp_id", "warpRun.warp_id", "=="); 1146 PXOPT_COPY_STR(config->args, warpWhere, "-skycell_id", "warpSkyfile.skycell_id", "=="); 1147 PXOPT_COPY_STR(config->args, warpWhere, "-tess_id", "warpRun.tess_id", "=="); 1148 PXOPT_COPY_STR(config->args, warpWhere, "-warp_label", "warpRun.label", "=="); 1149 PXOPT_COPY_F32(config->args, warpWhere, "-good_frac", "warpSkyfile.good_frac", ">="); 1127 PXOPT_COPY_STR(config->args, expWhere, "-comment", "comment", "LIKE"); 1128 PXOPT_COPY_S64(config->args, warp1Where, "-warp_id", "warpRun.warp_id", "=="); 1129 PXOPT_COPY_STR(config->args, warp1Where, "-warp_label", "warpRun.label", "=="); 1130 PXOPT_COPY_STR(config->args, warp1Where, "-tess_id", "warpRun.tess_id", "=="); 1131 PXOPT_COPY_STR(config->args, warp1Where, "-data_group", "warpRun.data_group", "=="); 1132 PXOPT_COPY_S64(config->args, warp2Where, "-warp_id", "warpRun.warp_id", "=="); 1133 PXOPT_COPY_STR(config->args, warp2Where, "-tess_id", "warpRun.tess_id", "=="); 1134 PXOPT_COPY_STR(config->args, warp2Where, "-data_group", "warpRun.data_group", "=="); 1135 PXOPT_COPY_STR(config->args, warp2Where, "-skycell_id", "warpSkyfile.skycell_id", "=="); 1136 PXOPT_COPY_STR(config->args, warp2Where, "-warp_label", "warpRun.label", "=="); 1137 PXOPT_COPY_F32(config->args, warp2Where, "-good_frac", "warpSkyfile.good_frac", ">="); 1150 1138 PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "=="); 1151 1139 … … 1167 1155 psString query = pxDataGet("difftool_definewarpstack_part1.sql"); 1168 1156 if (!query) { 1169 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1170 return false; 1171 } 1172 1173 psString warpQuery = NULL; 1157 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1158 return false; 1159 } 1160 1161 psString warp1Query = NULL; 1162 psString warp2Query = NULL; 1174 1163 psString stackQuery = NULL; 1175 1164 psString expQuery = NULL; … … 1183 1172 } 1184 1173 psFree(expWhere); 1185 if (psListLength(warp Where->list)) {1186 psString whereClause = psDBGenerateWhereConditionSQL(warp Where, NULL);1187 psStringAppend(&warp Query, "\n AND %s", whereClause);1174 if (psListLength(warp1Where->list)) { 1175 psString whereClause = psDBGenerateWhereConditionSQL(warp1Where, NULL); 1176 psStringAppend(&warp1Query, "\n AND %s", whereClause); 1188 1177 psFree(whereClause); 1189 1178 } else { 1190 warpQuery = psStringCopy("\n"); 1191 } 1192 psFree(warpWhere); 1193 1194 if (!available) { 1195 // diff what's available, even if warp run has some faults and is incomplete 1196 psStringAppend(&warpQuery, " AND warpRun.state = 'full'"); 1197 } 1179 warp1Query = psStringCopy("\n"); 1180 } 1181 psFree(warp1Where); 1182 if (psListLength(warp2Where->list)) { 1183 psString whereClause = psDBGenerateWhereConditionSQL(warp2Where, NULL); 1184 psStringAppend(&warp2Query, "\n AND %s", whereClause); 1185 psFree(whereClause); 1186 } else { 1187 warp2Query = psStringCopy("\n"); 1188 } 1189 psFree(warp2Where); 1198 1190 1199 1191 // don't queue for exposures that have already been diff'd unless requested … … 1214 1206 psFree(stackWhere); 1215 1207 1216 psTrace("difftool", 1, query, warp Query, diffQuery, expQuery, stackQuery);1208 psTrace("difftool", 1, query, warp1Query, warp2Query, diffQuery, expQuery, stackQuery); 1217 1209 1218 1210 if (!psDBTransaction(config->dbh)) { … … 1221 1213 } 1222 1214 1223 if (!p_psDBRunQueryF(config->dbh, query, warp Query, expQuery, diffQuery)) {1215 if (!p_psDBRunQueryF(config->dbh, query, warp1Query, warp2Query, expQuery, diffQuery)) { 1224 1216 psError(PS_ERR_UNKNOWN, false, "database error"); 1225 1217 psFree(query); … … 1281 1273 return false; 1282 1274 } 1275 psFree(warp1Query); 1283 1276 psFree(query); 1284 1277 query = NULL; … … 1312 1305 if (!p_psDBRunQuery(config->dbh, "DELETE FROM skycellsToDiff")) { 1313 1306 psError(PS_ERR_UNKNOWN, false, "database error"); 1314 psFree(warp Query);1307 psFree(warp2Query); 1315 1308 psFree(stackQuery); 1316 1309 psFree(skycell_query); … … 1323 1316 if (!mdok) { 1324 1317 psError(PXTOOLS_ERR_PROG, false, "warp_id not found --- ignoring row %ld", i); 1325 psFree(warp Query);1318 psFree(warp2Query); 1326 1319 psFree(stackQuery); 1327 1320 psFree(skycell_query); … … 1334 1327 if (!mdok) { 1335 1328 psError(PXTOOLS_ERR_PROG, false, "skycell_count not found"); 1336 psFree(warp Query);1329 psFree(warp2Query); 1337 1330 psFree(stackQuery); 1338 1331 psFree(skycell_query); … … 1345 1338 if (!mdok) { 1346 1339 psError(PXTOOLS_ERR_PROG, false, "tess_id not found"); 1347 psFree(warp Query);1340 psFree(warp2Query); 1348 1341 psFree(stackQuery); 1349 1342 psFree(skycell_query); … … 1353 1346 return false; 1354 1347 } 1348 1355 1349 psString filter = psMetadataLookupStr(&mdok, row, "filter"); 1356 1350 if (!mdok) { 1357 1351 psError(PXTOOLS_ERR_PROG, false, "filter not found"); 1358 psFree(warp Query);1352 psFree(warp2Query); 1359 1353 psFree(stackQuery); 1360 1354 psFree(skycell_query); … … 1364 1358 return false; 1365 1359 } 1366 if (!p_psDBRunQueryF(config->dbh, skycell_query, stackQuery, warp_id, filter, warpQuery)) { 1367 psError(PS_ERR_UNKNOWN, false, "database error"); 1368 psFree(warpQuery); 1360 1361 psString warp_data_group = psMetadataLookupStr(&mdok, row, "data_group"); 1362 if (!mdok) { 1363 psError(PXTOOLS_ERR_PROG, false, "warp data_group not found"); 1364 psFree(warp2Query); 1365 psFree(stackQuery); 1366 psFree(skycell_query); 1367 if (!psDBRollback(config->dbh)) { 1368 psError(PS_ERR_UNKNOWN, false, "database error"); 1369 } 1370 return false; 1371 } 1372 if (warp_data_group) { 1373 data_group = warp_data_group; 1374 } 1375 1376 if (!p_psDBRunQueryF(config->dbh, skycell_query, stackQuery, warp_id, filter, warp2Query)) { 1377 psError(PS_ERR_UNKNOWN, false, "database error"); 1378 psFree(warp2Query); 1369 1379 psFree(stackQuery); 1370 1380 psFree(skycell_query); … … 1377 1387 1378 1388 if (num == 0) { 1379 psTrace("difftool", PS_LOG_INFO, "no skycells with stack found for %" PRId64, warp_id);1389 psTrace("difftool", PS_LOG_INFO, "no skycells with stack found for warp_id %" PRId64, warp_id); 1380 1390 continue; 1381 1391 } … … 1383 1393 if (!available && (num != skycell_count)) { 1384 1394 psTrace("difftool", PS_LOG_INFO, "%" PRId64 " skyfiles with stack found for warp_id %" PRId64 1385 " need %" PRId64, num, warp_id, skycell_count);1395 " but need %" PRId64, num, warp_id, skycell_count); 1386 1396 continue; 1387 1397 } … … 1402 1412 true, // exposure 1403 1413 0, // magicked 1414 IPP_DIFF_MODE_WARP_STACK, 1404 1415 note 1405 1416 ); … … 1418 1429 if (!p_psDBRunQuery(config->dbh, query)) { 1419 1430 psError(PS_ERR_UNKNOWN, false, "database error"); 1420 psFree(warp Query);1431 psFree(warp2Query); 1421 1432 psFree(stackQuery); 1422 1433 psFree(skycell_query); … … 1432 1443 if (!p_psDBRunQuery(config->dbh, query)) { 1433 1444 psError(PS_ERR_UNKNOWN, false, "database error"); 1434 psFree(warp Query);1445 psFree(warp2Query); 1435 1446 psFree(stackQuery); 1436 1447 psFree(skycell_query); … … 1447 1458 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, 1448 1459 run->diff_id); 1449 psFree(warp Query);1460 psFree(warp2Query); 1450 1461 psFree(stackQuery); 1451 1462 psFree(skycell_query); … … 1461 1472 } 1462 1473 psFree(output); 1463 psFree(warp Query);1474 psFree(warp2Query); 1464 1475 psFree(stackQuery); 1465 1476 psFree(skycell_query); … … 1549 1560 // Additional controls 1550 1561 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 1551 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false);1552 1562 1553 1563 // Settings to apply to defined run … … 1574 1584 psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL 1575 1585 if (!tempCreate) { 1576 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1586 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1577 1587 psFree(selectWhere); 1578 1588 psFree(insertWhere); … … 1597 1607 psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table 1598 1608 if (!tempInsert) { 1599 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1609 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1600 1610 psFree(selectWhere); 1601 1611 psFree(insertWhere); … … 1629 1639 psString select = pxDataGet("difftool_definewarpwarp_select.sql"); 1630 1640 if (!select) { 1631 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1641 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1632 1642 psFree(selectWhere); 1633 1643 psFree(insertWhere); … … 1642 1652 if (psListLength(selectWhere->list)) { 1643 1653 psString new = psDBGenerateWhereConditionSQL(selectWhere, NULL); 1644 psStringAppend(&whereClause, "\n %s %s", whereClause ? "AND" : "WHERE", new);1654 psStringAppend(&whereClause, "\nAND %s", new); 1645 1655 psFree(new); 1646 1656 } 1647 1657 psFree(selectWhere); 1648 1658 1649 if (!available) {1650 psStringAppend(&whereClause,1651 "\n%s inputWarpRun.state = 'full'"1652 "AND templateWarpRun.state = 'full'",1653 whereClause ? "AND" : "WHERE");1654 }1655 1656 1659 if (!rerun) { 1657 psStringAppend(&whereClause, "\n %s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE");1660 psStringAppend(&whereClause, "\nAND diffs.diff_id IS NULL"); 1658 1661 } 1659 1662 … … 1732 1735 const char *template = psMetadataLookupStr(NULL, row, "template_warp_id"); 1733 1736 const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id"); 1737 psString input_data_group = psMetadataLookupStr(NULL, row, "input_data_group"); 1738 if (input_data_group) { 1739 data_group = input_data_group; 1740 } 1741 1734 1742 if (!input_id || !template || !tess_id) { 1735 1743 psError(PXTOOLS_ERR_PROG, false, "Identifiers not found"); … … 1742 1750 return false; 1743 1751 } 1744 1745 diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, data_group ? data_group : label, dist_group, reduction, NULL, registered, 1746 tess_id, true, true, false, note); // Run to insert 1752 1753 diffRunRow *run = diffRunRowAlloc(0, 1754 "reg", 1755 workdir, 1756 label, 1757 data_group ? data_group : label, 1758 dist_group, 1759 reduction, 1760 NULL, // dvodb 1761 registered, 1762 tess_id, 1763 true, // bothways 1764 true, // exposure 1765 false, // magicked 1766 IPP_DIFF_MODE_WARP_WARP, 1767 note); // Run to insert 1747 1768 if (!diffRunInsertObject(config->dbh, run)) { 1748 1769 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1816 1837 } 1817 1838 1839 static bool definestackstackMode(pxConfig *config) { 1840 PS_ASSERT_PTR_NON_NULL(config, false); 1841 1842 psMetadata *stack1Where = psMetadataAlloc(); 1843 psMetadata *stack2Where = psMetadataAlloc(); 1844 1845 PXOPT_COPY_STR(config->args, stack1Where, "-tess_id", "stackRun.tess_id", "=="); 1846 PXOPT_COPY_STR(config->args, stack2Where, "-tess_id", "stackRun.tess_id", "=="); 1847 PXOPT_COPY_STR(config->args, stack1Where, "-filter", "stackRun.filter", "=="); 1848 PXOPT_COPY_STR(config->args, stack2Where, "-filter", "stackRun.filter", "=="); 1849 PXOPT_COPY_STR(config->args, stack1Where, "-skycell_id", "stackRun.skycell_id", "=="); 1850 PXOPT_COPY_STR(config->args, stack2Where, "-skycell_id", "stackRun.skycell_id", "=="); 1851 PXOPT_COPY_STR(config->args, stack1Where, "-input_label", "stackRun.label","=="); 1852 PXOPT_COPY_STR(config->args, stack2Where, "-template_label", "stackRun.label","=="); 1853 PXOPT_COPY_F32(config->args, stack1Where, "-good_frac", "stackSumSkyfile.good_frac", ">="); 1854 PXOPT_COPY_F32(config->args, stack2Where, "-good_frac", "stackSumSkyfile.good_frac", ">="); 1855 1856 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required option 1857 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option 1858 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option 1859 PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false); 1860 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 1861 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 1862 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 1863 1864 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1865 PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false); 1866 PXOPT_LOOKUP_BOOL(newTemplates,config->args,"-new-templates", false); 1867 1868 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false); 1869 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1870 1871 if (!(label)) { 1872 PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false); 1873 } 1874 1875 // Organize the config information into queries. 1876 psString stack1Query = NULL; 1877 psString stack2Query = NULL; 1878 1879 if (psListLength(stack1Where->list)) { 1880 psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL); 1881 psStringAppend(&stack1Query, "\n AND %s", whereClause); 1882 psFree(whereClause); 1883 } else { 1884 stack1Query = psStringCopy("\n"); 1885 } 1886 psFree(stack1Where); 1887 1888 if (psListLength(stack2Where->list)) { 1889 psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL); 1890 psStringAppend(&stack2Query, "\n AND %s", whereClause); 1891 psFree(whereClause); 1892 } else { 1893 stack2Query = psStringCopy("\n"); 1894 } 1895 psFree(stack2Where); 1896 1897 // don't queue for stacks that have already been diffed unless requested 1898 psString diffQuery = NULL; 1899 if (! (reRun || newTemplates) ) { 1900 psStringAppend(&diffQuery, "\n AND diffExp.diff_id IS NULL"); 1901 } else { 1902 diffQuery = psStringCopy("\n"); 1903 } 1904 1905 // find the distinct set of data_groups and filters 1906 psString query = pxDataGet("difftool_definestackstack_part0.sql"); 1907 if (!query) { 1908 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1909 return(false); 1910 } 1911 psTrace("difftool",1,query,stack2Query,stack1Query,diffQuery,stack1Query); 1912 /* exit(10); */ 1913 1914 if (!psDBTransaction(config->dbh)) { 1915 psError(PS_ERR_UNKNOWN, false, "database error"); 1916 return(false); 1917 } 1918 1919 if (!p_psDBRunQueryF(config->dbh, query, stack2Query, stack1Query, diffQuery, stack1Query)) { 1920 psError(PS_ERR_UNKNOWN, false, "database error"); 1921 psFree(query); 1922 if (!psDBRollback(config->dbh)) { 1923 psError(PS_ERR_UNKNOWN, false, "database error"); 1924 } 1925 return false; 1926 } 1927 1928 psFree(query); 1929 1930 psArray *output = p_psDBFetchResult(config->dbh); 1931 if (!output) { 1932 psErrorCode err = psErrorCodeLast(); 1933 switch (err) { 1934 case PS_ERR_DB_CLIENT: 1935 psError(PXTOOLS_ERR_SYS, false, "database error"); 1936 break; 1937 case PS_ERR_DB_SERVER: 1938 psError(PXTOOLS_ERR_PROG, false, "database error"); 1939 break; 1940 default: 1941 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1942 break; 1943 } 1944 if (!psDBRollback(config->dbh)) { 1945 psError(PS_ERR_UNKNOWN, false, "database error"); 1946 } 1947 return false; 1948 } 1949 if (!psArrayLength(output)) { 1950 psTrace("difftool", PS_LOG_INFO, "no rows found"); 1951 psFree(output); 1952 if (!psDBCommit(config->dbh)) { 1953 psError(PS_ERR_UNKNOWN, false, "database error"); 1954 return false; 1955 } 1956 return true; 1957 } 1958 1959 query = pxDataGet("difftool_definestackstack_part1.sql"); 1960 if (pretend) { 1961 // negative simple so the default is true 1962 if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) { 1963 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1964 psFree(output); 1965 return false; 1966 } 1967 psFree(output); 1968 return true; 1969 } 1970 1971 psArray *list = psArrayAllocEmpty(16); // List of runs defined, to print 1972 for (long i = 0; i < output->n; i++) { 1973 psMetadata *row = output->data[i]; // Output row from query 1974 bool mdok; // Status of MD lookup 1975 1976 psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id"); 1977 psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group"); 1978 psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group"); 1979 psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label"); 1980 1981 psString this_stack1Query = psStringCopy(stack1Query); 1982 1983 psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL); 1984 psStringSubstitute(&thisWhere,"stackRun.","INPUT_"); 1985 psStringAppend(&this_stack1Query,"\n AND %s", thisWhere); 1986 psFree(thisWhere); 1987 1988 psTrace("difftool",1, query,stack2Query,this_stack1Query,diffQuery,this_stack1Query); 1989 if (!psDBTransaction(config->dbh)) { 1990 psError(PS_ERR_UNKNOWN, false, "database error"); 1991 return(false); 1992 } 1993 1994 if (!p_psDBRunQueryF(config->dbh, query, stack2Query, this_stack1Query, diffQuery, this_stack1Query)) { 1995 psError(PS_ERR_UNKNOWN, false, "database error"); 1996 psFree(query); 1997 if (!psDBRollback(config->dbh)) { 1998 psError(PS_ERR_UNKNOWN, false, "database error"); 1999 } 2000 return false; 2001 } 2002 psFree(this_stack1Query); 2003 2004 psArray *diff_id_output = p_psDBFetchResult(config->dbh); 2005 if (!diff_id_output) { 2006 psErrorCode err = psErrorCodeLast(); 2007 switch (err) { 2008 case PS_ERR_DB_CLIENT: 2009 psError(PXTOOLS_ERR_SYS, false, "database error"); 2010 break; 2011 case PS_ERR_DB_SERVER: 2012 psError(PXTOOLS_ERR_PROG, false, "database error"); 2013 break; 2014 default: 2015 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2016 break; 2017 } 2018 if (!psDBRollback(config->dbh)) { 2019 psError(PS_ERR_UNKNOWN, false, "database error"); 2020 } 2021 return false; 2022 } 2023 if (!psArrayLength(diff_id_output)) { 2024 psTrace("difftool", PS_LOG_INFO, "no rows found"); 2025 psFree(diff_id_output); 2026 if (!psDBCommit(config->dbh)) { 2027 psError(PS_ERR_UNKNOWN, false, "database error"); 2028 return false; 2029 } 2030 return true; 2031 } 2032 2033 // ok we've got one create the diffRun 2034 diffRunRow *run = diffRunRowAlloc( 2035 0, // ID 2036 "reg", // state 2037 workdir, 2038 label ? label : this_label, 2039 data_group ? data_group : this_data_group, 2040 dist_group ? dist_group : this_dist_group, 2041 reduction, 2042 NULL, // dvodb 2043 registered, 2044 tess_id, 2045 false, // bothways 2046 false, // exposure 2047 0, // magicked 2048 IPP_DIFF_MODE_STACK_STACK, // diff_mode 2049 note 2050 ); 2051 // Commit to database 2052 if (!diffRunInsertObject(config->dbh, run)) { 2053 psError(PS_ERR_UNKNOWN, false, "database error"); 2054 psFree(run); 2055 if (!psDBRollback(config->dbh)) { 2056 psError(PS_ERR_UNKNOWN, false, "database error"); 2057 } 2058 return false; 2059 } 2060 /* diffRunPrintObject(stdout,run,1); */ 2061 run->diff_id = psDBLastInsertID(config->dbh); 2062 for (long j = 0; j < diff_id_output->n; j++) { 2063 psMetadata *input_row = diff_id_output->data[j]; // Output row from query 2064 bool mdok; 2065 psString in_skycell_id = psMetadataLookupStr(&mdok,input_row,"skycell_id"); 2066 psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id"); 2067 psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id"); 2068 psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id"); 2069 psTrace("difftool",1,"%s %" PRId64 " %" PRId64 " %s\n", 2070 in_skycell_id, in_input_stack_id, in_template_stack_id, in_tess_id); 2071 diffInputSkyfileRow *input = diffInputSkyfileRowAlloc( 2072 run->diff_id, // ID 2073 in_skycell_id, 2074 PS_MAX_S64, // warp1_id -> NULL 2075 in_input_stack_id, // stack1 2076 PS_MAX_S64, // warp2_id -> NULL 2077 in_template_stack_id, // stack2 2078 in_tess_id, 2079 0 // diff_skyfile_id 2080 ); 2081 // Commit to database the input 2082 if (!diffInputSkyfileInsertObject(config->dbh, input)) { 2083 psError(PS_ERR_UNKNOWN, false, "database error"); 2084 psFree(input); 2085 if (!psDBRollback(config->dbh)) { 2086 psError(PS_ERR_UNKNOWN, false, "database error"); 2087 } 2088 return false; 2089 } 2090 2091 /* diffInputSkyfilePrintObject(stdout,input,1); */ 2092 psFree(input); 2093 } 2094 2095 if (!setdiffRunState(config, run->diff_id, "new", false)) { 2096 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, run->diff_id); 2097 psFree(stack1Query); 2098 psFree(stack2Query); 2099 psFree(diffQuery); 2100 psFree(run); 2101 psFree(list); 2102 if (!psDBRollback(config->dbh)) { 2103 psError(PS_ERR_UNKNOWN, false, "database error"); 2104 } 2105 return false; 2106 } 2107 psArrayAdd(list, list->n, run); 2108 psFree(run); 2109 } 2110 2111 if (!psDBCommit(config->dbh)) { 2112 psError(PS_ERR_UNKNOWN, false, "database error"); 2113 psFree(list); 2114 return false; 2115 } 2116 2117 if (!diffRunPrintObjects(stdout, list, !simple)) { 2118 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 2119 psFree(list); 2120 return false; 2121 } 2122 2123 psFree(query); 2124 psFree(stack1Query); 2125 psFree(stack2Query); 2126 psFree(diffQuery); 2127 psFree(output); 2128 psFree(list); 2129 2130 if (!psDBCommit(config->dbh)) { 2131 psError(PS_ERR_UNKNOWN, false, "database error"); 2132 psFree(list); 2133 return false; 2134 } 2135 2136 return(true); 2137 } 1818 2138 1819 2139 static bool pendingcleanuprunMode(pxConfig *config) … … 1825 2145 1826 2146 psMetadata *where = psMetadataAlloc(); 1827 pxAddLabelSearchArgs (config, where, "-label", " label", "==");2147 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1828 2148 1829 2149 psString query = pxDataGet("difftool_pendingcleanuprun.sql"); 1830 2150 if (!query) { 1831 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1832 return false; 1833 } 2151 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2152 return false; 2153 } 2154 // pxDataGet/psStringSubstitute workaround 2155 psString queryCopy = psStringCopy(query); 2156 psFree(query); 2157 query = queryCopy; 1834 2158 1835 2159 if (where && psListLength(where->list)) { 1836 2160 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1837 psStringAppend(&query, " AND %s", whereClause); 2161 psStringAppend(&whereClause, " AND "); 2162 psStringSubstitute(&query,whereClause,"@INNERCONSTRAINT@"); 1838 2163 psFree(whereClause); 2164 } 2165 else { 2166 psStringSubstitute(&query,NULL,"@INNERCONSTRAINT@"); 1839 2167 } 1840 2168 psFree(where); … … 1846 2174 psFree(limitString); 1847 2175 } 1848 1849 2176 // fprintf(stderr,"%s",query); 2177 2178 //fprintf(stderr,"%s",query); 1850 2179 if (!p_psDBRunQuery(config->dbh, query)) { 1851 2180 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1895 2224 psString query = pxDataGet("difftool_pendingcleanupskyfile.sql"); 1896 2225 if (!query) { 1897 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");2226 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1898 2227 return false; 1899 2228 } … … 1955 2284 psString query = pxDataGet("difftool_donecleanup.sql"); 1956 2285 if (!query) { 1957 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");2286 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1958 2287 return false; 1959 2288 } … … 2010 2339 psMetadata *where = psMetadataAlloc(); 2011 2340 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 2341 PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell_id", "=="); 2012 2342 2013 2343 if (!pxSetFaultCode(config->dbh, "diffSkyfile", where, fault)) { … … 2027 2357 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); 2028 2358 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 2359 2360 2361 psS64 magicked = 0; 2362 if (!strcmp(data_state, "full")) { 2363 PXOPT_LOOKUP_S64(set_magicked, config->args, "-magicked", 0, false); 2364 magicked = set_magicked; 2365 } 2029 2366 2030 2367 psString query = pxDataGet("difftool_change_skyfile_data_state.sql"); … … 2035 2372 } 2036 2373 2374 psString set_magicked_skyfile = psStringCopy(""); 2375 psString set_magicked_run = psStringCopy(""); 2376 if (magicked != 0 && !strcmp(data_state, "full")) { 2377 psStringAppend(&set_magicked_skyfile, "\n , diffSkyfile.magicked = %" PRId64, magicked); 2378 psStringAppend(&set_magicked_run, "\n , diffRun.magicked = %" PRId64, magicked); 2379 2380 } else if (!strcmp(data_state, "cleaned") || !strcmp(data_state, "purged")) { 2381 psStringAppend(&set_magicked_skyfile, "\n, diffSkyfile.magicked = IF(diffSkyfile.magicked = 0, 0, -1)"); 2382 psStringAppend(&set_magicked_run, "\n, diffRun.magicked = IF(diffRun.magicked = 0, 0, -1)"); 2383 } 2384 2037 2385 // Uses the unconstrained (diffRun.state [NEED NOT EQUAL] run_state) version from warptool.c 2038 2386 2039 if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, skycell_id)) {2387 if (!p_psDBRunQueryF(config->dbh, query, data_state, set_magicked_skyfile, diff_id, skycell_id)) { 2040 2388 psError(PS_ERR_UNKNOWN, false, "database error"); 2041 2389 // rollback … … 2044 2392 } 2045 2393 psError(PS_ERR_UNKNOWN, false, "database error"); 2394 psFree(set_magicked_skyfile); 2046 2395 return(false); 2047 2396 } 2397 psFree(set_magicked_skyfile); 2048 2398 psFree(query); 2049 2399 2050 2400 query = pxDataGet("difftool_change_run_state.sql"); 2051 if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, data_state)) {2401 if (!p_psDBRunQueryF(config->dbh, query, data_state, set_magicked_run, diff_id, data_state)) { 2052 2402 // rollback 2053 2403 if (!psDBRollback(config->dbh)) { … … 2055 2405 } 2056 2406 psError(PS_ERR_UNKNOWN, false, "database error"); 2407 psFree(set_magicked_run); 2057 2408 return(false); 2058 2409 } … … 2060 2411 if (!psDBCommit(config->dbh)) { 2061 2412 psError(PS_ERR_UNKNOWN, false, "database error"); 2413 psFree(set_magicked_run); 2062 2414 return(false); 2063 2415 } 2064 2416 psFree(set_magicked_run); 2417 2065 2418 return(true); 2066 2419 } … … 2074 2427 static bool toscrubbedskyfileMode(pxConfig *config) { 2075 2428 return change_skyfile_data_state(config, "scrubbed", "goto_scrubbed"); 2429 } 2430 static bool tofullskyfileMode(pxConfig *config) { 2431 return change_skyfile_data_state(config, "full", "update"); 2076 2432 } 2077 2433 … … 2115 2471 psString query = pxDataGet(tables[i].sqlFilename); 2116 2472 if (!query) { 2117 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");2473 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2118 2474 return false; 2119 2475 } … … 2252 2608 return true; 2253 2609 } 2610 2611 static bool listrunMode(pxConfig *config) 2612 { 2613 PS_ASSERT_PTR_NON_NULL(config, false); 2614 2615 psMetadata *where = psMetadataAlloc(); 2616 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 2617 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "=="); 2618 PXOPT_COPY_S64(config->args, where, "-magicked", "diffRun.magicked", "=="); 2619 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 2620 pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE"); 2621 pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE"); 2622 2623 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 2624 if (!template) { 2625 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawInput.exp_id", "=="); 2626 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawInput.exp_name", "=="); 2627 PXOPT_COPY_STR(config->args, where, "-warp_id", "warpInput.warp_id", "=="); 2628 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawInput.dateobs", ">="); 2629 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawInput.dateobs", "<="); 2630 PXOPT_COPY_STR(config->args, where, "-filter", "rawInput.filter", "LIKE"); 2631 } else { 2632 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawTemplate.exp_id", "=="); 2633 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawTemplate.exp_name", "=="); 2634 PXOPT_COPY_STR(config->args, where, "-warp_id", "warpTemplate.warp_id", "=="); 2635 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawTemplate.dateobs", ">="); 2636 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawTemplate.dateobs", "<="); 2637 PXOPT_COPY_STR(config->args, where, "-filter", "rawTemplate.filter", "LIKE"); 2638 } 2639 2640 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 2641 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2642 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2643 PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false); 2644 2645 2646 psString where2 = NULL; 2647 pxmagicAddWhere(config, &where2, "diffRun"); 2648 pxspaceAddWhere(config, &where2, template ? "rawTemplate" : "rawInput"); 2649 psString query = pxDataGet("difftool_listrun.sql"); 2650 if (!query) { 2651 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2652 return false; 2653 } 2654 2655 if (psListLength(where->list)) { 2656 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 2657 psStringAppend(&query, " WHERE %s", whereClause); 2658 psFree(whereClause); 2659 } else if (where2) { 2660 psStringAppend(&query, " WHERE diffRun.diff_id is not null %s", where2); 2661 } else if (!all) { 2662 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 2663 return false; 2664 } 2665 psFree(where); 2666 2667 if (pstamp_order) { 2668 if (template) { 2669 psStringAppend(&query, " ORDER BY rawTemplate.exp_id, diff_id DESC"); 2670 } else { 2671 psStringAppend(&query, " ORDER BY rawInput.exp_id, diff_id DESC"); 2672 } 2673 } 2674 2675 // treat limit == 0 as "no limit" 2676 if (limit) { 2677 psString limitString = psDBGenerateLimitSQL(limit); 2678 psStringAppend(&query, " %s", limitString); 2679 psFree(limitString); 2680 } 2681 2682 if (!p_psDBRunQuery(config->dbh, query)) { 2683 psError(PS_ERR_UNKNOWN, false, "database error"); 2684 psFree(query); 2685 return false; 2686 } 2687 psFree(query); 2688 2689 psArray *output = p_psDBFetchResult(config->dbh); 2690 if (!output) { 2691 psErrorCode err = psErrorCodeLast(); 2692 switch (err) { 2693 case PS_ERR_DB_CLIENT: 2694 psError(PXTOOLS_ERR_SYS, false, "database error"); 2695 case PS_ERR_DB_SERVER: 2696 psError(PXTOOLS_ERR_PROG, false, "database error"); 2697 default: 2698 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2699 } 2700 2701 return false; 2702 } 2703 if (!psArrayLength(output)) { 2704 psTrace("difftool", PS_LOG_INFO, "no rows found"); 2705 psFree(output); 2706 return true; 2707 } 2708 2709 if (psArrayLength(output)) { 2710 // negative simple so the default is true 2711 if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) { 2712 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2713 psFree(output); 2714 return false; 2715 } 2716 } 2717 2718 psFree(output); 2719 2720 return true; 2721 } 2722 // a very specfic function to queue a cleaned warpSkyfile to be updated 2723 static bool setskyfiletoupdateMode(pxConfig *config) 2724 { 2725 PS_ASSERT_PTR_NON_NULL(config, NULL); 2726 2727 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); 2728 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", false, false); 2729 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 2730 2731 psString query = pxDataGet("difftool_setskyfiletoupdate.sql"); 2732 if (!query) { 2733 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2734 return false; 2735 } 2736 2737 psString setHook = psStringCopy(""); 2738 if (label) { 2739 psStringAppend(&setHook, "\n , diffRun.label = '%s'", label); 2740 } 2741 2742 if (skycell_id) { 2743 psStringAppend(&query, " AND (diffSkyfile.skycell_id = '%s')", skycell_id); 2744 } 2745 2746 if (!p_psDBRunQueryF(config->dbh, query, setHook, diff_id)) { 2747 psError(PS_ERR_UNKNOWN, false, "database error"); 2748 return false; 2749 } 2750 2751 psFree(setHook); 2752 psFree(query); 2753 2754 return true; 2755 }
Note:
See TracChangeset
for help on using the changeset viewer.
