Changeset 20973 for trunk/ippTools/src/difftool.c
- Timestamp:
- Dec 13, 2008, 10:17:34 AM (17 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/difftool.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/difftool.c
r20719 r20973 47 47 48 48 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state); 49 static bool diffRunComplete(pxConfig *config); 49 50 50 51 # define MODECASE(caseName, func) \ … … 108 109 // required options 109 110 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 110 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);111 111 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); 112 112 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 113 113 PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); 114 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 114 115 115 116 // default … … 120 121 0, // ID 121 122 "reg", // state 123 workdir, 122 124 label, 123 125 reduction, 124 workdir,125 126 NULL, // dvodb 126 127 registered, 127 skycell_id,128 tess_id128 tess_id, 129 exp_id 129 130 ); 130 131 if (!run) { … … 178 179 179 180 // optional 180 PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false); 181 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", false, false); 182 PXOPT_LOOKUP_STR(kind, config->args, "-kind", false, false); 183 184 // defaults to false 185 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 186 187 // must provide either stack_id or warp_id but not BOTH 188 if (!(stack_id || warp_id)) { 189 psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified"); 190 return false; 191 } 192 if (stack_id && warp_id) { 193 psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified"); 194 return false; 195 } 196 197 // if a warp_id was provided we need to lookup the skycell_id and tess_id 198 // from the warpRun 199 psString skycell_id = NULL; 181 PXOPT_LOOKUP_S64(stack1, config->args, "-stack1", false, false); 182 PXOPT_LOOKUP_S64(stack2, config->args, "-stack2", false, false); 183 PXOPT_LOOKUP_S64(warp1, config->args, "-warp1", false, false); 184 PXOPT_LOOKUP_S64(warp2, config->args, "-warp2", false, false); 185 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 186 187 // must provide either stack1 or warp1 but not BOTH 188 if (!(stack1 || warp1)) { 189 psError(PS_ERR_UNKNOWN, true, "either -stack1 or -warp1 must be specified"); 190 return false; 191 } 192 if (stack1 && warp1) { 193 psError(PS_ERR_UNKNOWN, true, "either -stack1 or -warp1 must be specified"); 194 return false; 195 } 196 // must provide either stack2 or warp2 but not BOTH 197 if (!(stack2 || warp2)) { 198 psError(PS_ERR_UNKNOWN, true, "either -stack2 or -warp2 must be specified"); 199 return false; 200 } 201 if (stack2 && warp2) { 202 psError(PS_ERR_UNKNOWN, true, "either -stack2 or -warp2 must be specified"); 203 return false; 204 } 205 206 // if a warp1 was provided we need to lookup the and tess_id from the diffRun 200 207 psString tess_id = NULL; 201 if (warp _id) {208 if (warp1) { 202 209 if (!p_psDBRunQuery(config->dbh, "SELECT * from diffRun WHERE diff_id = %" PRId64, diff_id)) { 203 210 psError(PS_ERR_UNKNOWN, false, "database error"); … … 217 224 218 225 diffRunRow *run = diffRunObjectFromMetadata(output->data[0]); 219 skycell_id = run->skycell_id;220 226 tess_id = run->tess_id; 221 227 } … … 228 234 if (!diffInputSkyfileInsert(config->dbh, 229 235 diff_id, 230 template,231 stack_id ? stack_id : PS_MAX_S64, // defined or NULL232 warp_id ? warp_id : PS_MAX_S64, // defined or NULL233 236 skycell_id, 234 tess_id, 235 kind 237 warp1 ? warp1 : PS_MAX_S64, // defined or NULL 238 stack1 ? stack1 : PS_MAX_S64, // defined or NULL 239 warp2 ? warp2 : PS_MAX_S64, // defined or NULL 240 stack2 ? stack2 : PS_MAX_S64, // defined or NULL 241 tess_id 236 242 )) { 237 243 if (!psDBRollback(config->dbh)) { … … 298 304 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 299 305 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 300 PXOPT_COPY_STR(config->args, where, "-skycell_id", " skycell_id", "==");306 PXOPT_COPY_STR(config->args, where, "-skycell_id", "diffInputSkyfile.skycell_id", "=="); 301 307 PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "=="); 302 PXOPT_COPY_STR(config->args, where, "-kind", "kind", "==");303 308 304 309 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 349 354 } 350 355 351 if (!p_psDBRunQuery(config->dbh, query, whereClause, whereClause )) {356 if (!p_psDBRunQuery(config->dbh, query, whereClause, whereClause, whereClause, whereClause)) { 352 357 psError(PS_ERR_UNKNOWN, false, "database error"); 353 358 psFree(whereClause); … … 471 476 472 477 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); // required 478 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 473 479 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 474 480 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); … … 503 509 if (!diffSkyfileInsert(config->dbh, 504 510 diff_id, 511 skycell_id, 505 512 uri, 506 513 path_base, … … 524 531 hostname, 525 532 good_frac, 526 code 533 code, 534 0, // diff_image_id 535 0 // magic_ds_id 527 536 )) { 528 537 if (!psDBRollback(config->dbh)) { … … 533 542 } 534 543 535 if (! setdiffRunState(config, diff_id, "full")) {544 if (!diffRunComplete(config)) { 536 545 if (!psDBRollback(config->dbh)) { 537 546 psError(PS_ERR_UNKNOWN, false, "database error"); … … 546 555 return false; 547 556 } 557 548 558 549 559 return true; … … 762 772 psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none 763 773 psS64 template_stack_id, // Stack identifier for template image, PS_MAX_S64 for none 774 psS64 exp_id, // exposure id for input_warp_id (if defined) 764 775 pxConfig *config // Configuration 765 776 ) … … 786 797 0, // ID 787 798 "reg", // state 799 workdir, 788 800 label, 789 801 reduction, 790 workdir,791 802 NULL, // dvodb 792 803 registered, 793 skycell_id,794 tess_id804 tess_id, 805 exp_id 795 806 ); 796 807 … … 817 828 if (!diffInputSkyfileInsert(config->dbh, 818 829 run->diff_id, 819 true, 830 skycell_id, 831 input_warp_id, 832 input_stack_id, 833 template_warp_id, 820 834 template_stack_id, 821 template_warp_id, 822 skycell_id, 823 tess_id, 824 NULL // kind 825 )) { 826 if (!psDBRollback(config->dbh)) { 827 psError(PS_ERR_UNKNOWN, false, "database error"); 828 } 829 psError(PS_ERR_UNKNOWN, false, "database error"); 830 return false; 831 } 832 833 // Input 834 if (!diffInputSkyfileInsert(config->dbh, 835 run->diff_id, 836 false, 837 input_stack_id, 838 input_warp_id, 839 skycell_id, 840 tess_id, 841 NULL // kind 835 tess_id 842 836 )) { 843 837 if (!psDBRollback(config->dbh)) { … … 887 881 PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false); 888 882 PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false); 883 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 889 884 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 890 885 … … 906 901 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 907 902 "No input has been defined (-input_stack_id or -input_warp_id)"); 903 return false; 904 } 905 if (input_warp_id && !exp_id) { 906 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 907 "-exp_id is required with -input_warp_id."); 908 908 return false; 909 909 } … … 916 916 template_warp_id ? template_warp_id : PS_MAX_S64, 917 917 template_stack_id ? template_stack_id : PS_MAX_S64, 918 exp_id, 918 919 config)) { 919 920 psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun"); … … 937 938 PS_ASSERT_PTR_NON_NULL(config, false); 938 939 940 psMetadata *expWhere = psMetadataAlloc(); 939 941 psMetadata *warpWhere = psMetadataAlloc(); 940 942 psMetadata *stackWhere = psMetadataAlloc(); 941 943 944 PXOPT_COPY_S64(config->args, expWhere, "-exp_id", "exp_id", "=="); 942 945 PXOPT_COPY_S64(config->args, warpWhere, "-warp_id", "warpRun.warp_id", "=="); 943 946 PXOPT_COPY_STR(config->args, warpWhere, "-skycell_id", "warpRun.skycell_id", "=="); … … 945 948 PXOPT_COPY_STR(config->args, warpWhere, "-filter", "rawExp.filter", "=="); 946 949 PXOPT_COPY_STR(config->args, warpWhere, "-warp_label", "warpRun.label", "=="); 947 PXOPT_COPY_STR(config->args, warpWhere, "-kind", "warpsToDiff.kind", "==");948 950 PXOPT_COPY_F32(config->args, warpWhere, "-good_frac", "warpSkyfile.good_frac", ">="); 949 951 PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "=="); … … 955 957 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 956 958 PXOPT_LOOKUP_BOOL(newTemplates, config->args, "-new-templates", false); 959 PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false); 960 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false); 957 961 958 962 // find all things to queue 959 psString query = pxDataGet("difftool_definebyquery .sql");963 psString query = pxDataGet("difftool_definebyquery_part1.sql"); 960 964 if (!query) { 961 965 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 963 967 } 964 968 965 if (newTemplates) {966 // Warps that haven't been diffed OR warps that can take a newer template in the diff967 psStringAppend(&query, " WHERE (diff_id IS NULL OR best_stack_id > current_stack_id)");968 } else {969 // Only warps that haven't been diffed970 psStringAppend(&query, " WHERE diff_id IS NULL");971 }972 973 969 psString warpQuery = NULL; 974 970 psString stackQuery = NULL; 975 971 psString expQuery = NULL; 972 973 if (psListLength(expWhere->list)) { 974 psString whereClause = psDBGenerateWhereConditionSQL(expWhere, NULL); 975 psStringAppend(&expQuery, "\n AND %s", whereClause); 976 psFree(whereClause); 977 } else { 978 expQuery = psStringCopy("\n"); 979 } 980 psFree(expWhere); 976 981 if (psListLength(warpWhere->list)) { 977 982 psString whereClause = psDBGenerateWhereConditionSQL(warpWhere, NULL); … … 979 984 psFree(whereClause); 980 985 } else { 981 warpQuery = psStringCopy(" ");986 warpQuery = psStringCopy("\n"); 982 987 } 983 988 psFree(warpWhere); 989 990 if (!available) { 991 // diff what's available, even if warp run has some faults and is incomplete 992 psStringAppend(&warpQuery, " AND warpRun.state = 'full'"); 993 } 994 995 // don't queue for exposures that have already been diff'd unless requested 996 psString diffQuery = NULL; 997 if (! (reRun || newTemplates) ) { 998 psStringAppend(&diffQuery, "\nAND diff_id IS NULL"); 999 } else { 1000 diffQuery = psStringCopy("\n"); 1001 } 984 1002 985 1003 if (psListLength(stackWhere->list)) { 986 1004 psString whereClause = psDBGenerateWhereConditionSQL(stackWhere, NULL); 987 psStringAppend(&stackQuery, "\n AND %s", whereClause);1005 psStringAppend(&stackQuery, "\nAND %s", whereClause); 988 1006 psFree(whereClause); 989 1007 } else { … … 992 1010 psFree(stackWhere); 993 1011 994 psTrace("difftool", 1, query, warpQuery, stackQuery); 995 996 if (!p_psDBRunQuery(config->dbh, query, warpQuery, stackQuery)) { 1012 psTrace("difftool", 1, query, warpQuery, diffQuery, expQuery, stackQuery); 1013 1014 1015 if (!p_psDBRunQuery(config->dbh, query, warpQuery, expQuery, diffQuery)) { 997 1016 psError(PS_ERR_UNKNOWN, false, "database error"); 998 1017 psFree(query); … … 1021 1040 } 1022 1041 1042 // create temporary table 1043 query = pxDataGet("difftool_definebyquery_temp_create.sql"); 1044 if (!p_psDBRunQuery(config->dbh, query)) { 1045 psError(PS_ERR_UNKNOWN, false, "database error"); 1046 psFree(query); 1047 return false; 1048 } 1049 psFree(query); 1050 query = NULL; 1051 1052 psString skycell_query = pxDataGet("difftool_definebyquery_part2.sql"); 1053 1023 1054 psArray *list = psArrayAllocEmpty(16); // List of runs, to print 1024 1055 long numGood = 0; // Number of good rows added 1056 psS64 last_exp_id = 0; 1025 1057 for (long i = 0; i < output->n; i++) { 1026 1058 psMetadata *row = output->data[i]; // Output row from query 1027 1028 // Selected parameters1029 1059 bool mdok; // Status of MD lookup 1030 const char *skycell_id = psMetadataLookupStr(&mdok, row, "skycell_id"); 1031 if (!mdok || !skycell_id) { 1032 psWarning("skycell_id not found --- ignoring row %ld", i); 1060 1061 // Take the first warp for each exposure. 1062 // The list is sorted by exposure id and warp_id and the warps are in descending 1063 // order. 1064 psS64 exp_id = psMetadataLookupS64(&mdok, row, "exp_id"); 1065 if (!mdok) { 1066 psError(PXTOOLS_ERR_PROG, false, "exp_id not found"); 1067 return false; 1068 } 1069 if (exp_id == last_exp_id) { 1033 1070 continue; 1034 1071 } 1035 const char *tess_id = psMetadataLookupStr(&mdok, row, "tess_id");1036 if (!mdok || !tess_id) { 1037 psWarning("tess_id not found --- ignoring row %ld", i);1038 continue;1039 }1040 psS64 stack_id = psMetadataLookupS64(&mdok, row, "best_stack_id");1041 if (!mdok) {1042 ps Warning("stack_id not found --- ignoring row %ld", i);1043 continue;1072 last_exp_id = exp_id; 1073 1074 // clear temporary table 1075 if (!p_psDBRunQuery(config->dbh, "DELETE FROM skycellsToDiff")) { 1076 psError(PS_ERR_UNKNOWN, false, "database error"); 1077 psFree(warpQuery); 1078 psFree(stackQuery); 1079 psFree(skycell_query); 1080 return false; 1044 1081 } 1045 1082 psS64 warp_id = psMetadataLookupS64(&mdok, row, "warp_id"); 1046 1083 if (!mdok) { 1047 psWarning("warp_id not found --- ignoring row %ld", i); 1084 psError(PXTOOLS_ERR_PROG, false, "warp_id not found --- ignoring row %ld", i); 1085 psFree(warpQuery); 1086 psFree(stackQuery); 1087 psFree(skycell_query); 1088 return false; 1089 } 1090 psS64 skycell_count = psMetadataLookupS64(&mdok, row, "skycell_count"); 1091 if (!mdok) { 1092 psError(PXTOOLS_ERR_PROG, false, "skycell_count not found"); 1093 psFree(warpQuery); 1094 psFree(stackQuery); 1095 psFree(skycell_query); 1096 return false; 1097 } 1098 psString tess_id = psMetadataLookupStr(&mdok, row, "tess_id"); 1099 if (!mdok) { 1100 psError(PXTOOLS_ERR_PROG, false, "tess_id not found"); 1101 psFree(warpQuery); 1102 psFree(stackQuery); 1103 psFree(skycell_query); 1104 return false; 1105 } 1106 psString filter = psMetadataLookupStr(&mdok, row, "filter"); 1107 if (!mdok) { 1108 psError(PXTOOLS_ERR_PROG, false, "filter not found"); 1109 psFree(warpQuery); 1110 psFree(stackQuery); 1111 psFree(skycell_query); 1112 return false; 1113 } 1114 if (!p_psDBRunQuery(config->dbh, skycell_query, warp_id, filter, warpQuery, stackQuery)) { 1115 psError(PS_ERR_UNKNOWN, false, "database error"); 1116 psFree(warpQuery); 1117 psFree(stackQuery); 1118 psFree(skycell_query); 1119 return false; 1120 } 1121 psS64 num = psDBAffectedRows(config->dbh); 1122 1123 if (num == 0) { 1124 psTrace("difftool", PS_LOG_INFO, "no skycells with stack found for %" PRId64, warp_id); 1048 1125 continue; 1049 1126 } 1050 1127 1051 if (!populatedrun(list, workdir, skycell_id, tess_id, label, reduction, warp_id, 1052 PS_MAX_S64, PS_MAX_S64, stack_id, config)) { 1053 psWarning("Unable to add run for %s,%s,%" PRId64 ",%" PRId64, skycell_id, tess_id, 1054 warp_id, stack_id); 1055 psErrorClear(); 1128 if (!available && (num != skycell_count)) { 1129 psTrace("difftool", PS_LOG_INFO, "%" PRId64 " skyfiles with stack found for warp_id %" 1130 PRId64 " need %" PRId64, num, skycell_count, warp_id); 1056 1131 continue; 1057 1132 } 1058 1133 1134 // ok we've got one create the diffRun 1135 diffRunRow *run = diffRunRowAlloc( 1136 0, // ID 1137 "reg", // state 1138 workdir, 1139 label, 1140 reduction, 1141 NULL, // dvodb 1142 registered, 1143 tess_id, 1144 exp_id 1145 ); 1146 1147 if (!diffRunInsertObject(config->dbh, run)) { 1148 psError(PS_ERR_UNKNOWN, false, "database error"); 1149 psFree(run); 1150 return true; 1151 } 1152 run->diff_id = psDBLastInsertID(config->dbh); 1153 1154 psStringAppend(&query, "UPDATE skycellsToDiff SET diff_id = %" PRId64, run->diff_id); 1155 if (!p_psDBRunQuery(config->dbh, query)) { 1156 psError(PS_ERR_UNKNOWN, false, "database error"); 1157 psFree(warpQuery); 1158 psFree(stackQuery); 1159 psFree(skycell_query); 1160 psFree(query); 1161 return false; 1162 } 1163 psFree(query); 1164 query = NULL; 1165 psStringAppend(&query, "INSERT INTO diffInputSkyfile SELECT * from skycellsToDiff"); 1166 if (!p_psDBRunQuery(config->dbh, query)) { 1167 psError(PS_ERR_UNKNOWN, false, "database error"); 1168 psFree(warpQuery); 1169 psFree(stackQuery); 1170 psFree(skycell_query); 1171 psFree(query); 1172 return false; 1173 } 1174 psFree(query); 1175 query = NULL; 1176 1177 if (!setdiffRunState(config, run->diff_id, "new")) { 1178 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, 1179 run->diff_id); 1180 psFree(warpQuery); 1181 psFree(stackQuery); 1182 psFree(skycell_query); 1183 psFree(query); 1184 return false; 1185 } 1186 1187 psArrayAdd(list, list->n, run); 1059 1188 numGood++; 1060 1189 } 1061 1190 psFree(output); 1191 psFree(warpQuery); 1192 psFree(stackQuery); 1193 psFree(skycell_query); 1062 1194 1063 1195 if (!diffRunPrintObjects(stdout, list, !simple)) { … … 1274 1406 } 1275 1407 1408 static bool diffRunComplete(pxConfig *config) 1409 { 1410 PS_ASSERT_PTR_NON_NULL(config, false); 1411 1412 // look for completed diffRuns 1413 psString query = pxDataGet("difftool_completed_runs.sql"); 1414 if (!query) { 1415 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1416 return false; 1417 } 1418 1419 if (!p_psDBRunQuery(config->dbh, query)) { 1420 psError(PS_ERR_UNKNOWN, false, "database error"); 1421 psFree(query); 1422 return false; 1423 } 1424 psFree(query); 1425 1426 psArray *output = p_psDBFetchResult(config->dbh); 1427 if (!output) { 1428 psError(PS_ERR_UNKNOWN, false, "database error"); 1429 return false; 1430 } 1431 if (!psArrayLength(output)) { 1432 psTrace("difftool", PS_LOG_INFO, "no rows found"); 1433 psFree(output); 1434 return true; 1435 } 1436 for (long i = 0; i < psArrayLength(output); i++) { 1437 psMetadata *row = output->data[i]; 1438 1439 psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id"); 1440 1441 // set diffRun.state to 'stop' 1442 if (!setdiffRunState(config, diff_id, "full")) { 1443 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, 1444 diff_id); 1445 psFree(output); 1446 return false; 1447 } 1448 } 1449 1450 return true; 1451 } 1452
Note:
See TracChangeset
for help on using the changeset viewer.
