Changeset 20954 for branches/bills_081204/ippTools/src/difftool.c
- Timestamp:
- Dec 10, 2008, 6:11:39 PM (18 years ago)
- File:
-
- 1 edited
-
branches/bills_081204/ippTools/src/difftool.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/bills_081204/ippTools/src/difftool.c
r20903 r20954 121 121 0, // ID 122 122 "reg", // state 123 workdir, 123 124 label, 124 125 reduction, 125 workdir,126 126 NULL, // dvodb 127 127 registered, 128 exp_id,129 tess_id128 tess_id, 129 exp_id 130 130 ); 131 131 if (!run) { … … 234 234 if (!diffInputSkyfileInsert(config->dbh, 235 235 diff_id, 236 skycell_id, 236 237 warp1 ? warp1 : PS_MAX_S64, // defined or NULL 238 stack1 ? stack1 : PS_MAX_S64, // defined or NULL 237 239 warp2 ? warp2 : PS_MAX_S64, // defined or NULL 238 stack1 ? stack1 : PS_MAX_S64, // defined or NULL239 240 stack2 ? stack2 : PS_MAX_S64, // defined or NULL 240 skycell_id,241 241 tess_id 242 242 )) { … … 304 304 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 305 305 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 306 PXOPT_COPY_STR(config->args, where, "-skycell_id", " skycell_id", "==");306 PXOPT_COPY_STR(config->args, where, "-skycell_id", "diffInputSkyfile.skycell_id", "=="); 307 307 PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "=="); 308 308 … … 531 531 hostname, 532 532 good_frac, 533 code 533 code, 534 0, // diff_image_id 535 0 // magic_ds_id 534 536 )) { 535 537 if (!psDBRollback(config->dbh)) { … … 795 797 0, // ID 796 798 "reg", // state 799 workdir, 797 800 label, 798 801 reduction, 799 workdir,800 802 NULL, // dvodb 801 803 registered, 802 exp_id,803 tess_id804 tess_id, 805 exp_id 804 806 ); 805 807 … … 826 828 if (!diffInputSkyfileInsert(config->dbh, 827 829 run->diff_id, 830 skycell_id, 828 831 input_warp_id, 832 input_stack_id, 829 833 template_warp_id, 830 input_stack_id,831 834 template_stack_id, 832 skycell_id,833 835 tess_id 834 836 )) { … … 936 938 PS_ASSERT_PTR_NON_NULL(config, false); 937 939 940 psMetadata *expWhere = psMetadataAlloc(); 938 941 psMetadata *warpWhere = psMetadataAlloc(); 939 942 psMetadata *stackWhere = psMetadataAlloc(); 940 943 944 PXOPT_COPY_S64(config->args, expWhere, "-exp_id", "exp_id", "=="); 941 945 PXOPT_COPY_S64(config->args, warpWhere, "-warp_id", "warpRun.warp_id", "=="); 942 946 PXOPT_COPY_STR(config->args, warpWhere, "-skycell_id", "warpRun.skycell_id", "=="); … … 953 957 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 954 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); 955 961 956 962 // find all things to queue 957 psString query = pxDataGet("difftool_definebyquery .sql");963 psString query = pxDataGet("difftool_definebyquery_part1.sql"); 958 964 if (!query) { 959 965 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 961 967 } 962 968 963 if (newTemplates) {964 // Warps that haven't been diffed OR warps that can take a newer template in the diff965 psStringAppend(&query, " WHERE (diff_id IS NULL OR best_stack_id > current_stack_id)");966 } else {967 // Only warps that haven't been diffed968 psStringAppend(&query, " WHERE diff_id IS NULL");969 }970 971 969 psString warpQuery = NULL; 972 970 psString stackQuery = NULL; 973 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); 974 981 if (psListLength(warpWhere->list)) { 975 982 psString whereClause = psDBGenerateWhereConditionSQL(warpWhere, NULL); … … 977 984 psFree(whereClause); 978 985 } else { 979 warpQuery = psStringCopy(" ");986 warpQuery = psStringCopy("\n"); 980 987 } 981 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 } 982 1000 983 1001 if (psListLength(stackWhere->list)) { 984 1002 psString whereClause = psDBGenerateWhereConditionSQL(stackWhere, NULL); 985 psStringAppend(&stackQuery, "\n AND %s", whereClause);1003 psStringAppend(&stackQuery, "\nAND %s", whereClause); 986 1004 psFree(whereClause); 987 1005 } else { … … 990 1008 psFree(stackWhere); 991 1009 992 psTrace("difftool", 1, query, warpQuery, stackQuery); 993 994 if (!p_psDBRunQuery(config->dbh, query, warpQuery, stackQuery)) { 1010 psTrace("difftool", 1, query, warpQuery, diffQuery, expQuery, stackQuery); 1011 1012 1013 if (!p_psDBRunQuery(config->dbh, query, warpQuery, expQuery, diffQuery)) { 995 1014 psError(PS_ERR_UNKNOWN, false, "database error"); 996 1015 psFree(query); … … 1019 1038 } 1020 1039 1040 // create temporary table 1041 query = pxDataGet("difftool_definebyquery_temp_create.sql"); 1042 if (!p_psDBRunQuery(config->dbh, query)) { 1043 psError(PS_ERR_UNKNOWN, false, "database error"); 1044 psFree(query); 1045 return false; 1046 } 1047 psFree(query); 1048 query = NULL; 1049 1050 psString skycell_query = pxDataGet("difftool_definebyquery_part2.sql"); 1051 1021 1052 psArray *list = psArrayAllocEmpty(16); // List of runs, to print 1022 1053 long numGood = 0; // Number of good rows added 1054 psS64 last_exp_id = 0; 1023 1055 for (long i = 0; i < output->n; i++) { 1024 1056 psMetadata *row = output->data[i]; // Output row from query 1025 1026 // Selected parameters1027 1057 bool mdok; // Status of MD lookup 1028 const char *skycell_id = psMetadataLookupStr(&mdok, row, "skycell_id"); 1029 if (!mdok || !skycell_id) { 1030 psWarning("skycell_id not found --- ignoring row %ld", i); 1058 1059 // Take the first warp for each exposure. 1060 // The list is sorted by exposure id and warp_id and the warps are in descending 1061 // order. 1062 psS64 exp_id = psMetadataLookupS64(&mdok, row, "exp_id"); 1063 if (!mdok) { 1064 psError(PXTOOLS_ERR_PROG, false, "exp_id not found"); 1065 return false; 1066 } 1067 if (exp_id == last_exp_id) { 1031 1068 continue; 1032 1069 } 1033 const char *tess_id = psMetadataLookupStr(&mdok, row, "tess_id");1034 if (!mdok || !tess_id) { 1035 psWarning("tess_id not found --- ignoring row %ld", i);1036 continue;1037 }1038 psS64 stack_id = psMetadataLookupS64(&mdok, row, "best_stack_id");1039 if (!mdok) {1040 ps Warning("stack_id not found --- ignoring row %ld", i);1041 continue;1070 last_exp_id = exp_id; 1071 1072 // clear temporary table 1073 if (!p_psDBRunQuery(config->dbh, "DELETE FROM skycellsToDiff")) { 1074 psError(PS_ERR_UNKNOWN, false, "database error"); 1075 psFree(warpQuery); 1076 psFree(stackQuery); 1077 psFree(skycell_query); 1078 return false; 1042 1079 } 1043 1080 psS64 warp_id = psMetadataLookupS64(&mdok, row, "warp_id"); 1044 1081 if (!mdok) { 1045 psWarning("warp_id not found --- ignoring row %ld", i); 1082 psError(PXTOOLS_ERR_PROG, false, "warp_id not found --- ignoring row %ld", i); 1083 psFree(warpQuery); 1084 psFree(stackQuery); 1085 psFree(skycell_query); 1086 return false; 1087 } 1088 psS64 skycell_count = psMetadataLookupS64(&mdok, row, "skycell_count"); 1089 if (!mdok) { 1090 psError(PXTOOLS_ERR_PROG, false, "skycell_count not found"); 1091 psFree(warpQuery); 1092 psFree(stackQuery); 1093 psFree(skycell_query); 1094 return false; 1095 } 1096 psString tess_id = psMetadataLookupStr(&mdok, row, "tess_id"); 1097 if (!mdok) { 1098 psError(PXTOOLS_ERR_PROG, false, "tess_id not found"); 1099 psFree(warpQuery); 1100 psFree(stackQuery); 1101 psFree(skycell_query); 1102 return false; 1103 } 1104 if (!p_psDBRunQuery(config->dbh, skycell_query, warp_id, warpQuery, stackQuery)) { 1105 psError(PS_ERR_UNKNOWN, false, "database error"); 1106 psFree(warpQuery); 1107 psFree(stackQuery); 1108 psFree(skycell_query); 1109 return false; 1110 } 1111 psS64 num = psDBAffectedRows(config->dbh); 1112 1113 if (num == 0) { 1114 psTrace("difftool", PS_LOG_INFO, "no skycells with stack found for %" PRId64, warp_id); 1046 1115 continue; 1047 1116 } 1048 psS64 exp_id = psMetadataLookupS64(&mdok, row, "exp_id"); 1049 if (!mdok) { 1050 psWarning("exp_id not found --- ignoring row %ld", i); 1117 1118 if (!available && (num != skycell_count)) { 1119 psTrace("difftool", PS_LOG_INFO, "%" PRId64 " skyfiles with stack found for warp_id %" 1120 PRId64 " need %" PRId64, num, skycell_count, warp_id); 1051 1121 continue; 1052 1122 } 1053 1123 1054 if (!populatedrun(list, workdir, skycell_id, tess_id, label, reduction, warp_id, 1055 PS_MAX_S64, PS_MAX_S64, stack_id, exp_id, config)) { 1056 psWarning("Unable to add run for %s,%s,%" PRId64 ",%" PRId64, skycell_id, tess_id, 1057 warp_id, stack_id); 1058 psErrorClear(); 1059 continue; 1060 } 1061 1124 // ok we've got one create the diffRun 1125 diffRunRow *run = diffRunRowAlloc( 1126 0, // ID 1127 "reg", // state 1128 workdir, 1129 label, 1130 reduction, 1131 NULL, // dvodb 1132 registered, 1133 tess_id, 1134 exp_id 1135 ); 1136 1137 if (!diffRunInsertObject(config->dbh, run)) { 1138 psError(PS_ERR_UNKNOWN, false, "database error"); 1139 psFree(run); 1140 return true; 1141 } 1142 run->diff_id = psDBLastInsertID(config->dbh); 1143 1144 psStringAppend(&query, "UPDATE skycellsToDiff SET diff_id = %" PRId64, run->diff_id); 1145 if (!p_psDBRunQuery(config->dbh, query)) { 1146 psError(PS_ERR_UNKNOWN, false, "database error"); 1147 psFree(warpQuery); 1148 psFree(stackQuery); 1149 psFree(skycell_query); 1150 psFree(query); 1151 return false; 1152 } 1153 psFree(query); 1154 query = NULL; 1155 psStringAppend(&query, "INSERT INTO diffInputSkyfile SELECT * from skycellsToDiff"); 1156 if (!p_psDBRunQuery(config->dbh, query)) { 1157 psError(PS_ERR_UNKNOWN, false, "database error"); 1158 psFree(warpQuery); 1159 psFree(stackQuery); 1160 psFree(skycell_query); 1161 psFree(query); 1162 return false; 1163 } 1164 1165 if (!setdiffRunState(config, run->diff_id, "new")) { 1166 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, 1167 run->diff_id); 1168 psFree(warpQuery); 1169 psFree(stackQuery); 1170 psFree(skycell_query); 1171 psFree(query); 1172 return false; 1173 } 1174 1175 psArrayAdd(list, list->n, run); 1062 1176 numGood++; 1063 1177 }
Note:
See TracChangeset
for help on using the changeset viewer.
