Changeset 34538 for trunk/ippTools/src/difftool.c
- Timestamp:
- Oct 23, 2012, 4:07:36 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/difftool.c (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/difftool.c
r34503 r34538 97 97 MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP, definewarpwarpMode); 98 98 MODECASE(DIFFTOOL_MODE_DEFINESTACKSTACK, definestackstackMode); 99 MODECASE(DIFFTOOL_MODE_TOSUMMARY, tosummaryMode);100 MODECASE(DIFFTOOL_MODE_ADDSUMMARY, addsummaryMode);99 MODECASE(DIFFTOOL_MODE_TOSUMMARY, tosummaryMode); 100 MODECASE(DIFFTOOL_MODE_ADDSUMMARY, addsummaryMode); 101 101 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); 102 102 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode); … … 170 170 exposure, 171 171 false, 172 NULL, // software version173 0, // mask stat npix174 NAN, // static175 NAN, // dynamic176 NAN, // magic177 NAN, // advisory172 NULL, // software version 173 0, // mask stat npix 174 NAN, // static 175 NAN, // dynamic 176 NAN, // magic 177 NAN, // advisory 178 178 diff_mode, 179 179 note … … 579 579 PXOPT_LOOKUP_F32(maskfrac_magic, config->args, "-maskfrac_magic", false, false); 580 580 PXOPT_LOOKUP_F32(maskfrac_advisory, config->args, "-maskfrac_advisory", false, false); 581 581 582 582 psTrace("czw.test",1,"Received versions: pslib %s psmodules %s psphot %s ppstats %s ppsub %s streaks %s\n", 583 ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppsub,ver_streaks);583 ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppsub,ver_streaks); 584 584 psString ver_code = NULL; 585 585 if ((ver_pslib)&&(ver_psmodules)) { … … 631 631 fault, 632 632 quality, 633 magicked,634 ver_code,635 maskfrac_npix,636 maskfrac_static,637 maskfrac_dynamic,638 maskfrac_magic,639 maskfrac_advisory633 magicked, 634 ver_code, 635 maskfrac_npix, 636 maskfrac_static, 637 maskfrac_dynamic, 638 maskfrac_magic, 639 maskfrac_advisory 640 640 )) { 641 641 if (!psDBRollback(config->dbh)) { … … 726 726 psS64 magicked = psMetadataLookupS64(NULL, row, "magicked"); 727 727 728 psString software_ver = NULL;729 psS64 maskfrac_npix = 0;730 psF32 maskfrac_static = 0;731 psF32 maskfrac_dynamic = 0;732 psF32 maskfrac_magic = 0;733 psF32 maskfrac_advisory = 0;734 735 // Calculate run level masking and software state736 if (!pxCoalesceRunStatus(config,"difftool_coalesce_run.sql",diff_id,737 &software_ver,&maskfrac_npix,738 &maskfrac_static,&maskfrac_dynamic,739 &maskfrac_magic,&maskfrac_advisory)) {740 psError(PS_ERR_UNKNOWN, false, "failed to generate run level statistics");741 psFree(output);742 if (!psDBRollback(config->dbh)) {743 psError(PS_ERR_UNKNOWN, false, "database error");744 }745 return(false);746 }747 // Set diffRun.software_ver to the appropriate value748 if (software_ver) {749 if (!pxSetRunSoftware(config, "diffRun", "diff_id", diff_id, software_ver)) {750 psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,751 diff_id);752 psFree(output);753 if (!psDBRollback(config->dbh)) {754 psError(PS_ERR_UNKNOWN, false, "database error");755 }756 return(false);757 }758 }759 // Set diffRun.maskfrac* to the appropriate values.760 if (maskfrac_npix) {761 if (!pxSetRunMaskfrac(config, "diffRun", "diff_id", diff_id, maskfrac_npix, maskfrac_static,762 maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) {763 psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64,764 diff_id);765 psFree(output);766 if (!psDBRollback(config->dbh)) {767 psError(PS_ERR_UNKNOWN, false, "database error");768 }769 return(false);770 }771 }728 psString software_ver = NULL; 729 psS64 maskfrac_npix = 0; 730 psF32 maskfrac_static = 0; 731 psF32 maskfrac_dynamic = 0; 732 psF32 maskfrac_magic = 0; 733 psF32 maskfrac_advisory = 0; 734 735 // Calculate run level masking and software state 736 if (!pxCoalesceRunStatus(config,"difftool_coalesce_run.sql",diff_id, 737 &software_ver,&maskfrac_npix, 738 &maskfrac_static,&maskfrac_dynamic, 739 &maskfrac_magic,&maskfrac_advisory)) { 740 psError(PS_ERR_UNKNOWN, false, "failed to generate run level statistics"); 741 psFree(output); 742 if (!psDBRollback(config->dbh)) { 743 psError(PS_ERR_UNKNOWN, false, "database error"); 744 } 745 return(false); 746 } 747 // Set diffRun.software_ver to the appropriate value 748 if (software_ver) { 749 if (!pxSetRunSoftware(config, "diffRun", "diff_id", diff_id, software_ver)) { 750 psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64, 751 diff_id); 752 psFree(output); 753 if (!psDBRollback(config->dbh)) { 754 psError(PS_ERR_UNKNOWN, false, "database error"); 755 } 756 return(false); 757 } 758 } 759 // Set diffRun.maskfrac* to the appropriate values. 760 if (maskfrac_npix) { 761 if (!pxSetRunMaskfrac(config, "diffRun", "diff_id", diff_id, maskfrac_npix, maskfrac_static, 762 maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) { 763 psError(PS_ERR_UNKNOWN, false, "failed to set diffRun.software_ver for diff_id: %" PRId64, 764 diff_id); 765 psFree(output); 766 if (!psDBRollback(config->dbh)) { 767 psError(PS_ERR_UNKNOWN, false, "database error"); 768 } 769 return(false); 770 } 771 } 772 772 // set diffRun.state to 'full' 773 773 if (!setdiffRunState(config, diff_id, "full", magicked)) { … … 857 857 } 858 858 } 859 859 860 860 // treat limit == 0 as "no limit" 861 861 if (limit) { … … 1092 1092 false, 1093 1093 0, // magicked 1094 NULL, // software version1095 0, // mask stat npix1096 NAN, // static1097 NAN, // dynamic1098 NAN, // magic1099 NAN, // advisory1094 NULL, // software version 1095 0, // mask stat npix 1096 NAN, // static 1097 NAN, // dynamic 1098 NAN, // magic 1099 NAN, // advisory 1100 1100 diff_mode, // diff_mode 1101 1101 note … … 1475 1475 } 1476 1476 1477 psString warp_data_group = psMetadataLookupStr(&mdok, row, "data_group");1478 if (!mdok) {1479 psError(PXTOOLS_ERR_PROG, false, "warp data_group not found");1480 psFree(warp2Query);1481 psFree(stackQuery);1482 psFree(skycell_query);1483 if (!psDBRollback(config->dbh)) {1484 psError(PS_ERR_UNKNOWN, false, "database error");1485 }1486 return false;1487 }1488 if (!data_group && warp_data_group) {1489 data_group = warp_data_group;1490 }1491 1477 psString warp_data_group = psMetadataLookupStr(&mdok, row, "data_group"); 1478 if (!mdok) { 1479 psError(PXTOOLS_ERR_PROG, false, "warp data_group not found"); 1480 psFree(warp2Query); 1481 psFree(stackQuery); 1482 psFree(skycell_query); 1483 if (!psDBRollback(config->dbh)) { 1484 psError(PS_ERR_UNKNOWN, false, "database error"); 1485 } 1486 return false; 1487 } 1488 if (!data_group && warp_data_group) { 1489 data_group = warp_data_group; 1490 } 1491 1492 1492 if (!p_psDBRunQueryF(config->dbh, skycell_query, stackQuery, warp_id, filter, warp2Query)) { 1493 1493 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1515 1515 // ok we've got one create the diffRun 1516 1516 diffRunRow *run = diffRunRowAlloc( 1517 0, // ID1518 "reg", // state1517 0, // ID 1518 "reg", // state 1519 1519 workdir, 1520 1520 label, … … 1522 1522 dist_group, 1523 1523 reduction, 1524 NULL, // dvodb1524 NULL, // dvodb 1525 1525 registered, 1526 1526 tess_id, 1527 1527 bothways, // bothways (default is false) 1528 true, // exposure1529 0, // magicked1530 NULL,// software version1531 0,// mask stat npix1532 NAN,// static1533 NAN,// dynamic1534 NAN,// magic1535 NAN,// advisory1528 true, // exposure 1529 0, // magicked 1530 NULL, // software version 1531 0, // mask stat npix 1532 NAN, // static 1533 NAN, // dynamic 1534 NAN, // magic 1535 NAN, // advisory 1536 1536 IPP_DIFF_MODE_WARP_STACK, 1537 1537 note … … 1562 1562 psFree(query); 1563 1563 query = NULL; 1564 psStringAppend(&query, "INSERT INTO diffInputSkyfile SELECT * from skycellsToDiff"); 1564 psStringAppend(&query, 1565 "INSERT INTO diffInputSkyfile(diff_id, skycell_id, warp1, stack1, warp2, stack2, tess_id) SELECT diff_id, skycell_id, warp1, stack1, warp2, stack2, tess_id from skycellsToDiff"); 1565 1566 if (!p_psDBRunQuery(config->dbh, query)) { 1566 1567 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1868 1869 const char *template = psMetadataLookupStr(NULL, row, "template_warp_id"); 1869 1870 const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id"); 1870 psString input_data_group = psMetadataLookupStr(NULL, row, "input_data_group");1871 if (!data_group) {1872 data_group = input_data_group;1873 }1871 psString input_data_group = psMetadataLookupStr(NULL, row, "input_data_group"); 1872 if (!data_group) { 1873 data_group = input_data_group; 1874 } 1874 1875 1875 1876 if (!input_id || !template || !tess_id) { … … 1883 1884 return false; 1884 1885 } 1885 1886 1886 1887 diffRunRow *run = diffRunRowAlloc(0, 1887 1888 "reg", … … 1897 1898 true, // exposure 1898 1899 false, // magicked 1899 NULL, // software version1900 0, // mask stat npix1901 NAN, // static1902 NAN, // dynamic1903 NAN, // magic1904 NAN, // advisory 1900 NULL, // software version 1901 0, // mask stat npix 1902 NAN, // static 1903 NAN, // dynamic 1904 NAN, // magic 1905 NAN, // advisory 1905 1906 IPP_DIFF_MODE_WARP_WARP, 1906 1907 note); // Run to insert … … 1958 1959 // seem to be a way to pass in NULL for skycell_id, stack1 and stack2 1959 1960 psString dummyQuery = NULL; 1960 psStringAppend(&dummyQuery, 1961 psStringAppend(&dummyQuery, 1961 1962 "INSERT INTO diffInputSkyfile VALUES(%" PRId64 ", NULL, %s, NULL, %s, NULL, '%s', 0)", 1962 run->diff_id, 1963 run->diff_id, 1963 1964 input, // warp1 1964 1965 template, // warp2 … … 1980 1981 psFree(dummyQuery); 1981 1982 psString finishQuery = NULL; 1982 psStringAppend( &finishQuery, 1983 psStringAppend( &finishQuery, 1983 1984 "UPDATE diffRun set state ='full', dist_group = NULL, note = 'dummy run - no overlap' WHERE diff_id = %" PRId64, 1984 1985 run->diff_id); … … 2063 2064 2064 2065 if (!(label)) { 2065 PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false);2066 PXOPT_LOOKUP_STR(label,config->args, "-input_label",true,false); 2066 2067 } 2067 2068 … … 2071 2072 2072 2073 if (psListLength(stack1Where->list)) { 2073 psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL);2074 psStringAppend(&stack1Query, "AND %s", whereClause);2075 psFree(whereClause);2076 } 2074 psString whereClause = psDBGenerateWhereConditionSQL(stack1Where, NULL); 2075 psStringAppend(&stack1Query, "AND %s", whereClause); 2076 psFree(whereClause); 2077 } 2077 2078 psFree(stack1Where); 2078 2079 2079 2080 if (psListLength(stack2Where->list)) { 2080 psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL);2081 psStringAppend(&stack2Query, "AND %s", whereClause);2082 psFree(whereClause);2083 } 2081 psString whereClause = psDBGenerateWhereConditionSQL(stack2Where, NULL); 2082 psStringAppend(&stack2Query, "AND %s", whereClause); 2083 psFree(whereClause); 2084 } 2084 2085 psFree(stack2Where); 2085 2086 2086 2087 // don't queue for stacks that have already been diffed unless requested 2087 2088 psString diffQuery0 = NULL; 2088 2089 psString diffQuery1 = NULL; 2089 2090 if (! (reRun || newTemplates) ) { 2090 psStringAppend(&diffQuery0, "AND diffExp.diff_id IS NULL");2091 psStringAppend(&diffQuery1, "HAVING n_diff = 0");2092 } 2091 psStringAppend(&diffQuery0, "AND diffExp.diff_id IS NULL"); 2092 psStringAppend(&diffQuery1, "HAVING n_diff = 0"); 2093 } 2093 2094 2094 2095 // find the distinct set of data_groups and filters 2095 2096 psString query = pxDataGet("difftool_definestackstack_part0.sql"); 2096 2097 if (!query) { 2097 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");2098 return(false);2098 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2099 return(false); 2099 2100 } 2100 2101 psTrace("difftool",1,query,stack2Query,stack1Query,diffQuery0,stack1Query); 2101 2102 2102 2103 if (!psDBTransaction(config->dbh)) { 2103 psError(PS_ERR_UNKNOWN, false, "database error");2104 return(false);2104 psError(PS_ERR_UNKNOWN, false, "database error"); 2105 return(false); 2105 2106 } 2106 2107 … … 2110 2111 2111 2112 if (!p_psDBRunQuery(config->dbh, query)) { 2112 psError(PS_ERR_UNKNOWN, false, "database error");2113 psFree(query);2114 if (!psDBRollback(config->dbh)) {2115 psError(PS_ERR_UNKNOWN, false, "database error");2116 }2117 return false;2113 psError(PS_ERR_UNKNOWN, false, "database error"); 2114 psFree(query); 2115 if (!psDBRollback(config->dbh)) { 2116 psError(PS_ERR_UNKNOWN, false, "database error"); 2117 } 2118 return false; 2118 2119 } 2119 2120 … … 2122 2123 psArray *output = p_psDBFetchResult(config->dbh); 2123 2124 if (!output) { 2124 psErrorCode err = psErrorCodeLast();2125 switch (err) {2126 case PS_ERR_DB_CLIENT:2127 psError(PXTOOLS_ERR_SYS, false, "database error");2128 break;2129 case PS_ERR_DB_SERVER:2130 psError(PXTOOLS_ERR_PROG, false, "database error");2131 break;2132 default:2133 psError(PXTOOLS_ERR_PROG, false, "unknown error");2134 break;2135 }2136 if (!psDBRollback(config->dbh)) {2137 psError(PS_ERR_UNKNOWN, false, "database error");2138 }2139 return false;2125 psErrorCode err = psErrorCodeLast(); 2126 switch (err) { 2127 case PS_ERR_DB_CLIENT: 2128 psError(PXTOOLS_ERR_SYS, false, "database error"); 2129 break; 2130 case PS_ERR_DB_SERVER: 2131 psError(PXTOOLS_ERR_PROG, false, "database error"); 2132 break; 2133 default: 2134 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2135 break; 2136 } 2137 if (!psDBRollback(config->dbh)) { 2138 psError(PS_ERR_UNKNOWN, false, "database error"); 2139 } 2140 return false; 2140 2141 } 2141 2142 if (!psArrayLength(output)) { 2142 psTrace("difftool", PS_LOG_INFO, "no rows found");2143 psFree(output);2144 if (!psDBCommit(config->dbh)) {2145 psError(PS_ERR_UNKNOWN, false, "database error");2146 return false;2147 }2148 return true;2149 } 2150 2151 2143 psTrace("difftool", PS_LOG_INFO, "no rows found"); 2144 psFree(output); 2145 if (!psDBCommit(config->dbh)) { 2146 psError(PS_ERR_UNKNOWN, false, "database error"); 2147 return false; 2148 } 2149 return true; 2150 } 2151 2152 2152 2153 if (pretend) { 2153 // negative simple so the default is true2154 if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) {2155 psError(PS_ERR_UNKNOWN, false, "failed to print array");2156 psFree(output);2157 return false;2158 }2159 psFree(output);2160 return true;2154 // negative simple so the default is true 2155 if (!ippdbPrintMetadatas(stdout, output, "diffRunTemp", !simple)) { 2156 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2157 psFree(output); 2158 return false; 2159 } 2160 psFree(output); 2161 return true; 2161 2162 } 2162 2163 … … 2165 2166 query = pxDataGet("difftool_definestackstack_part1.sql"); 2166 2167 2167 2168 psMetadata *row = output->data[i]; // Output row from query2169 bool mdok; // Status of MD lookup2170 2171 // psMetadataPrint(stderr, row, 1);2172 2173 psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id");2174 psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group");2175 psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group");2176 psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label");2177 2178 psString this_stack1Query = psStringCopy(stack1Query);2179 2180 psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL);2181 psStringSubstitute(&thisWhere,"stackRun.","INPUT_");2182 psStringAppend(&this_stack1Query,"AND %s", thisWhere);2183 psFree(thisWhere);2184 2185 psStringSubstitute(&query, this_stack1Query, "@STACK1_QUERY@");2186 psStringSubstitute(&query, stack2Query, "@STACK2_QUERY@");2187 psStringSubstitute(&query, diffQuery1, "@DIFF1_QUERY@");2188 2189 psTrace("difftool", 1, "%s", query);2190 if (!psDBTransaction(config->dbh)) {2191 psError(PS_ERR_UNKNOWN, false, "database error");2192 return(false);2193 }2194 2195 if (!p_psDBRunQuery(config->dbh, query)) {2196 psError(PS_ERR_UNKNOWN, false, "database error");2197 psFree(query);2198 if (!psDBRollback(config->dbh)) {2199 psError(PS_ERR_UNKNOWN, false, "database error");2200 }2201 return false;2202 }2203 psFree(this_stack1Query);2204 2205 psArray *diff_id_output = p_psDBFetchResult(config->dbh);2206 if (!diff_id_output) {2207 psErrorCode err = psErrorCodeLast();2208 switch (err) {2209 case PS_ERR_DB_CLIENT:2210 psError(PXTOOLS_ERR_SYS, false, "database error");2211 break;2212 case PS_ERR_DB_SERVER:2213 psError(PXTOOLS_ERR_PROG, false, "database error");2214 break;2215 default:2216 psError(PXTOOLS_ERR_PROG, false, "unknown error");2217 break;2218 }2219 if (!psDBRollback(config->dbh)) {2220 psError(PS_ERR_UNKNOWN, false, "database error");2221 }2222 return false;2223 }2224 if (!psArrayLength(diff_id_output)) {2225 psTrace("difftool", PS_LOG_INFO, "no rows found");2226 psFree(diff_id_output);2227 if (!psDBCommit(config->dbh)) {2228 psError(PS_ERR_UNKNOWN, false, "database error");2229 return false;2230 }2231 return true;2232 }2233 2234 // ok we've got one create the diffRun2235 diffRunRow *run = diffRunRowAlloc(2236 0, // ID2237 "reg", // state2238 workdir,2239 label ? label : this_label,2240 data_group ? data_group : this_data_group,2241 dist_group ? dist_group : this_dist_group,2242 reduction,2243 NULL, // dvodb2244 registered,2245 tess_id,2246 bothways, // bothways2247 false, // exposure2248 0, // magicked2249 NULL, // software version2250 0, // mask stat npix2251 NAN, // static2252 NAN, // dynamic2253 NAN, // magic2254 NAN, // advisory 2255 IPP_DIFF_MODE_STACK_STACK, // diff_mode2256 note2257 );2258 // Commit to database2259 if (!diffRunInsertObject(config->dbh, run)) {2260 psError(PS_ERR_UNKNOWN, false, "database error");2261 psFree(run);2262 if (!psDBRollback(config->dbh)) {2263 psError(PS_ERR_UNKNOWN, false, "database error");2264 }2265 return false;2266 }2267 // diffRunPrintObject(stdout,run,1);2268 run->diff_id = psDBLastInsertID(config->dbh);2269 2270 for (long j = 0; j < diff_id_output->n; j++) {2271 psMetadata *input_row = diff_id_output->data[j]; // Output row from query2272 bool mdok;2273 psString in_skycell_id = psMetadataLookupStr(&mdok,input_row,"skycell_id");2274 psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id");2275 psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id");2276 psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id");2277 psTrace("difftool",1,"%s %" PRId64 " %" PRId64 " %s\n",2278 in_skycell_id, in_input_stack_id, in_template_stack_id, in_tess_id);2279 diffInputSkyfileRow *input = diffInputSkyfileRowAlloc(2280 run->diff_id, // ID2281 in_skycell_id,2282 PS_MAX_S64, // warp1_id -> NULL2283 in_input_stack_id, // stack12284 PS_MAX_S64, // warp2_id -> NULL2285 in_template_stack_id, // stack22286 in_tess_id,2287 0 // diff_skyfile_id2288 );2289 2290 // Commit to database the input2291 if (!diffInputSkyfileInsertObject(config->dbh, input)) {2292 psError(PS_ERR_UNKNOWN, false, "database error");2293 psFree(input);2294 if (!psDBRollback(config->dbh)) {2295 psError(PS_ERR_UNKNOWN, false, "database error");2296 }2297 return false;2298 }2168 2169 psMetadata *row = output->data[i]; // Output row from query 2170 bool mdok; // Status of MD lookup 2171 2172 // psMetadataPrint(stderr, row, 1); 2173 2174 psString tess_id = psMetadataLookupStr(&mdok,row,"INPUT_tess_id"); 2175 psString this_data_group = psMetadataLookupStr(&mdok,row,"INPUT_data_group"); 2176 psString this_dist_group = psMetadataLookupStr(&mdok,row,"INPUT_dist_group"); 2177 psString this_label = psMetadataLookupStr(&mdok,row,"INPUT_label"); 2178 2179 psString this_stack1Query = psStringCopy(stack1Query); 2180 2181 psString thisWhere = psDBGenerateWhereConditionSQL(row,NULL); 2182 psStringSubstitute(&thisWhere,"stackRun.","INPUT_"); 2183 psStringAppend(&this_stack1Query,"AND %s", thisWhere); 2184 psFree(thisWhere); 2185 2186 psStringSubstitute(&query, this_stack1Query, "@STACK1_QUERY@"); 2187 psStringSubstitute(&query, stack2Query, "@STACK2_QUERY@"); 2188 psStringSubstitute(&query, diffQuery1, "@DIFF1_QUERY@"); 2189 2190 psTrace("difftool", 1, "%s", query); 2191 if (!psDBTransaction(config->dbh)) { 2192 psError(PS_ERR_UNKNOWN, false, "database error"); 2193 return(false); 2194 } 2195 2196 if (!p_psDBRunQuery(config->dbh, query)) { 2197 psError(PS_ERR_UNKNOWN, false, "database error"); 2198 psFree(query); 2199 if (!psDBRollback(config->dbh)) { 2200 psError(PS_ERR_UNKNOWN, false, "database error"); 2201 } 2202 return false; 2203 } 2204 psFree(this_stack1Query); 2205 2206 psArray *diff_id_output = p_psDBFetchResult(config->dbh); 2207 if (!diff_id_output) { 2208 psErrorCode err = psErrorCodeLast(); 2209 switch (err) { 2210 case PS_ERR_DB_CLIENT: 2211 psError(PXTOOLS_ERR_SYS, false, "database error"); 2212 break; 2213 case PS_ERR_DB_SERVER: 2214 psError(PXTOOLS_ERR_PROG, false, "database error"); 2215 break; 2216 default: 2217 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2218 break; 2219 } 2220 if (!psDBRollback(config->dbh)) { 2221 psError(PS_ERR_UNKNOWN, false, "database error"); 2222 } 2223 return false; 2224 } 2225 if (!psArrayLength(diff_id_output)) { 2226 psTrace("difftool", PS_LOG_INFO, "no rows found"); 2227 psFree(diff_id_output); 2228 if (!psDBCommit(config->dbh)) { 2229 psError(PS_ERR_UNKNOWN, false, "database error"); 2230 return false; 2231 } 2232 return true; 2233 } 2234 2235 // ok we've got one create the diffRun 2236 diffRunRow *run = diffRunRowAlloc( 2237 0, // ID 2238 "reg", // state 2239 workdir, 2240 label ? label : this_label, 2241 data_group ? data_group : this_data_group, 2242 dist_group ? dist_group : this_dist_group, 2243 reduction, 2244 NULL, // dvodb 2245 registered, 2246 tess_id, 2247 bothways, // bothways 2248 false, // exposure 2249 0, // magicked 2250 NULL, // software version 2251 0, // mask stat npix 2252 NAN, // static 2253 NAN, // dynamic 2254 NAN, // magic 2255 NAN, // advisory 2256 IPP_DIFF_MODE_STACK_STACK, // diff_mode 2257 note 2258 ); 2259 // Commit to database 2260 if (!diffRunInsertObject(config->dbh, run)) { 2261 psError(PS_ERR_UNKNOWN, false, "database error"); 2262 psFree(run); 2263 if (!psDBRollback(config->dbh)) { 2264 psError(PS_ERR_UNKNOWN, false, "database error"); 2265 } 2266 return false; 2267 } 2268 // diffRunPrintObject(stdout,run,1); 2269 run->diff_id = psDBLastInsertID(config->dbh); 2270 2271 for (long j = 0; j < diff_id_output->n; j++) { 2272 psMetadata *input_row = diff_id_output->data[j]; // Output row from query 2273 bool mdok; 2274 psString in_skycell_id = psMetadataLookupStr(&mdok,input_row,"skycell_id"); 2275 psS64 in_input_stack_id = psMetadataLookupS64(&mdok,input_row,"stack_id"); 2276 psS64 in_template_stack_id = psMetadataLookupS64(&mdok,input_row,"max_stack_id"); 2277 psString in_tess_id = psMetadataLookupStr(&mdok,input_row,"tess_id"); 2278 psTrace("difftool",1,"%s %" PRId64 " %" PRId64 " %s\n", 2279 in_skycell_id, in_input_stack_id, in_template_stack_id, in_tess_id); 2280 diffInputSkyfileRow *input = diffInputSkyfileRowAlloc( 2281 run->diff_id, // ID 2282 in_skycell_id, 2283 PS_MAX_S64, // warp1_id -> NULL 2284 in_input_stack_id, // stack1 2285 PS_MAX_S64, // warp2_id -> NULL 2286 in_template_stack_id, // stack2 2287 in_tess_id, 2288 0 // diff_skyfile_id 2289 ); 2290 2291 // Commit to database the input 2292 if (!diffInputSkyfileInsertObject(config->dbh, input)) { 2293 psError(PS_ERR_UNKNOWN, false, "database error"); 2294 psFree(input); 2295 if (!psDBRollback(config->dbh)) { 2296 psError(PS_ERR_UNKNOWN, false, "database error"); 2297 } 2298 return false; 2299 } 2299 2300 2300 2301 /* diffInputSkyfilePrintObject(stdout,input,1); */ 2301 psFree(input);2302 }2303 2304 if (!setdiffRunState(config, run->diff_id, "new", false)) {2305 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, run->diff_id);2306 psFree(stack1Query);2307 psFree(stack2Query);2308 psFree(diffQuery0);2309 psFree(diffQuery1);2310 psFree(run);2311 psFree(list);2312 if (!psDBRollback(config->dbh)) {2313 psError(PS_ERR_UNKNOWN, false, "database error");2314 }2315 return false;2316 }2317 psArrayAdd(list, list->n, run);2318 psFree(run);2302 psFree(input); 2303 } 2304 2305 if (!setdiffRunState(config, run->diff_id, "new", false)) { 2306 psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64, run->diff_id); 2307 psFree(stack1Query); 2308 psFree(stack2Query); 2309 psFree(diffQuery0); 2310 psFree(diffQuery1); 2311 psFree(run); 2312 psFree(list); 2313 if (!psDBRollback(config->dbh)) { 2314 psError(PS_ERR_UNKNOWN, false, "database error"); 2315 } 2316 return false; 2317 } 2318 psArrayAdd(list, list->n, run); 2319 psFree(run); 2319 2320 } 2320 2321 2321 2322 if (!psDBCommit(config->dbh)) { 2322 psError(PS_ERR_UNKNOWN, false, "database error");2323 psFree(list);2324 return false;2323 psError(PS_ERR_UNKNOWN, false, "database error"); 2324 psFree(list); 2325 return false; 2325 2326 } 2326 2327 2327 2328 if (!diffRunPrintObjects(stdout, list, !simple)) { 2328 psError(PS_ERR_UNKNOWN, false, "failed to print object");2329 psFree(list);2330 return false;2329 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 2330 psFree(list); 2331 return false; 2331 2332 } 2332 2333 … … 2340 2341 2341 2342 if (!psDBCommit(config->dbh)) { 2342 psError(PS_ERR_UNKNOWN, false, "database error");2343 psFree(list);2344 return false;2343 psError(PS_ERR_UNKNOWN, false, "database error"); 2344 psFree(list); 2345 return false; 2345 2346 } 2346 2347 … … 2350 2351 static bool tosummaryMode(pxConfig *config) { 2351 2352 PS_ASSERT_PTR_NON_NULL(config, NULL); 2352 2353 2353 2354 psMetadata *where = psMetadataAlloc(); 2354 2355 PXOPT_COPY_S64(config->args, where, "-warp_id", "diffSkyfile.warp_id", "=="); … … 2366 2367 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2367 2368 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2368 2369 2369 2370 // find all rawImfiles matching the default query 2370 2371 psString query = pxDataGet("difftool_tosummary.sql"); … … 2381 2382 return false; 2382 2383 } 2383 2384 2384 2385 if (psListLength(where->list)) { 2385 2386 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 2390 2391 return false; 2391 2392 } 2392 2393 2393 2394 if (where2) { 2394 2395 if (psListLength(where->list)) { … … 2406 2407 psFree(limitString); 2407 2408 } 2408 2409 2409 2410 if (!p_psDBRunQuery(config->dbh, query)) { 2410 2411 psError(PS_ERR_UNKNOWN, false, "database error"); … … 2425 2426 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 2426 2427 } 2427 2428 2428 2429 return false; 2429 2430 } … … 2433 2434 return true; 2434 2435 } 2435 2436 2436 2437 if (psArrayLength(output)) { 2437 2438 // negative simple so the default is true … … 2442 2443 } 2443 2444 } 2444 2445 2445 2446 psFree(output); 2446 2447 return(true); … … 2464 2465 } 2465 2466 psS64 numUpdated = psDBAffectedRows(config->dbh); 2466 2467 2467 2468 if (numUpdated != 1) { 2468 2469 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row"); … … 2470 2471 return false; 2471 2472 } 2472 2473 2473 2474 psFree(query); 2474 2475 2475 2476 // Print anything here? 2476 2477 2477 2478 return(true); 2478 2479 } … … 2514 2515 psString limitString = psDBGenerateLimitSQL(limit); 2515 2516 psStringAppend(&query, " %s", limitString); 2516 psStringSubstitute(&query,limitString,"@INNERLIMITS@");2517 psStringSubstitute(&query,limitString,"@INNERLIMITS@"); 2517 2518 psFree(limitString); 2518 2519 … … 3028 3029 3029 3030 PXOPT_COPY_S64(config->args, where, "-template_exp_id", "rawTemplate.exp_id", "=="); 3030 3031 3031 3032 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 3032 3033 if (!template) { … … 3083 3084 } 3084 3085 } 3085 3086 3086 3087 // treat limit == 0 as "no limit" 3087 3088 if (limit) { … … 3148 3149 PXOPT_LOOKUP_F64(mjd_obs_begin, config->args, "-mjd_obs_begin", false, false); 3149 3150 PXOPT_LOOKUP_F64(mjd_obs_end, config->args, "-mjd_obs_end", false, false); 3150 3151 3151 3152 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 3152 3153 … … 3200 3201 } 3201 3202 } 3202 3203 3203 3204 // treat limit == 0 as "no limit" 3204 3205 if (limit) {
Note:
See TracChangeset
for help on using the changeset viewer.
