Changeset 25027 for branches/pap/ippTools/src/difftool.c
- Timestamp:
- Aug 7, 2009, 4:08:25 PM (17 years ago)
- Location:
- branches/pap
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/difftool.c (modified) (33 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/pap
- Property svn:mergeinfo changed
-
branches/pap/ippTools/src
- Property svn:ignore
-
old new 34 34 disttool 35 35 receivetool 36 37 pubtool
-
- Property svn:ignore
-
branches/pap/ippTools/src/difftool.c
r23940 r25027 40 40 static bool revertdiffskyfileMode(pxConfig *config); 41 41 static bool definepoprunMode(pxConfig *config); 42 static bool define byqueryMode(pxConfig *config);42 static bool definewarpstackMode(pxConfig *config); 43 43 static bool definewarpwarpMode(pxConfig *config); 44 44 static bool pendingcleanuprunMode(pxConfig *config); … … 49 49 static bool importrunMode(pxConfig *config); 50 50 51 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, boolmagicked);51 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked); 52 52 static bool diffRunComplete(pxConfig *config); 53 53 … … 79 79 MODECASE(DIFFTOOL_MODE_REVERTDIFFSKYFILE, revertdiffskyfileMode); 80 80 MODECASE(DIFFTOOL_MODE_DEFINEPOPRUN, definepoprunMode); 81 MODECASE(DIFFTOOL_MODE_DEFINE BYQUERY, definebyqueryMode);81 MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACK, definewarpstackMode); 82 82 MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP, definewarpwarpMode); 83 83 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); … … 116 116 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 117 117 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); 118 PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false); 119 PXOPT_LOOKUP_BOOL(exposure, config->args, "-exposure", false); 118 120 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 119 121 PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); 120 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);121 122 122 123 // default … … 133 134 registered, 134 135 tess_id, 135 exp_id, 136 bothways, 137 exposure, 136 138 false 137 139 ); 138 140 if (!run) { 139 141 psError(PS_ERR_UNKNOWN, false, "failed to alloc diffRun object"); 140 return true;142 return false; 141 143 } 142 144 if (!diffRunInsertObject(config->dbh, run)) { 143 145 psError(PS_ERR_UNKNOWN, false, "database error"); 144 146 psFree(run); 145 return true;147 return false; 146 148 } 147 149 … … 150 152 151 153 if (!diffRunPrintObject(stdout, run, !simple)) { 152 psError(PS_ERR_UNKNOWN, false, "failed to print object");153 psFree(run);154 return false;154 psError(PS_ERR_UNKNOWN, false, "failed to print object"); 155 psFree(run); 156 return false; 155 157 } 156 158 … … 487 489 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 488 490 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 489 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);490 491 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", (fault == 0), false); 491 492 … … 511 512 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 512 513 PXOPT_LOOKUP_F32(good_frac, config->args, "-good_frac", false, false); 513 PXOPT_LOOKUP_ BOOL(magicked, config->args, "-magicked", false);514 PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false); 514 515 515 516 if (!psDBTransaction(config->dbh)) { … … 521 522 diff_id, 522 523 skycell_id, 523 uri,524 524 path_base, 525 525 "full", … … 582 582 PXOPT_COPY_STR(config->args, where, "-skycell_id", "diffInputSkyfile.skycell_id", "=="); 583 583 PXOPT_COPY_S64(config->args, where, "-diff_skyfile_id", "diffInputSkyfile.diff_skyfile_id", "=="); 584 PXOPT_COPY_STR(config->args, where, "-tess_id", "diff Skyfile.tess_id", "==");584 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "=="); 585 585 PXOPT_COPY_S16(config->args, where, "-fault", "diffSkyfile.fault", "=="); 586 586 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); … … 662 662 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 663 663 664 if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) { 665 psFree(where); 666 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 667 return false; 668 } 669 664 670 if (!psDBTransaction(config->dbh)) { 665 671 psError(PS_ERR_UNKNOWN, false, "database error"); … … 695 701 psFree(query); 696 702 697 psLogMsg("dif tool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh));703 psLogMsg("difftool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh)); 698 704 } 699 705 … … 739 745 740 746 741 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, boolmagicked)747 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked) 742 748 { 743 749 PS_ASSERT_PTR_NON_NULL(state, false); … … 749 755 } 750 756 751 char *query = "UPDATE diffRun SET state = '%s', magicked = % dWHERE diff_id = %"PRId64;757 char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64; 752 758 753 759 if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) { … … 771 777 psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none 772 778 psS64 template_stack_id, // Stack identifier for template image, PS_MAX_S64 for none 773 psS64 exp_id, // exposure id for input_warp_id (if defined)774 779 pxConfig *config // Configuration 775 780 ) … … 802 807 registered, 803 808 tess_id, 804 exp_id, 805 false // magicked 809 false, 810 false, 811 0 // magicked 806 812 ); 807 813 … … 882 888 PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false); 883 889 PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false); 884 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);885 890 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 886 891 … … 902 907 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 903 908 "No input has been defined (-input_stack_id or -input_warp_id)"); 904 return false;905 }906 if (input_warp_id && !exp_id) {907 psError(PS_ERR_BAD_PARAMETER_VALUE, true,908 "-exp_id is required with -input_warp_id.");909 909 return false; 910 910 } … … 917 917 template_warp_id ? template_warp_id : PS_MAX_S64, 918 918 template_stack_id ? template_stack_id : PS_MAX_S64, 919 exp_id ? exp_id : PS_MAX_S64,920 919 config)) { 921 920 psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun"); … … 935 934 936 935 937 static bool define byqueryMode(pxConfig *config)936 static bool definewarpstackMode(pxConfig *config) 938 937 { 939 938 PS_ASSERT_PTR_NON_NULL(config, false); … … 944 943 945 944 PXOPT_COPY_S64(config->args, expWhere, "-exp_id", "exp_id", "=="); 945 PXOPT_COPY_STR(config->args, expWhere, "-filter", "filter", "=="); 946 946 PXOPT_COPY_S64(config->args, warpWhere, "-warp_id", "warpRun.warp_id", "=="); 947 947 PXOPT_COPY_STR(config->args, warpWhere, "-skycell_id", "warpSkyfile.skycell_id", "=="); 948 948 PXOPT_COPY_STR(config->args, warpWhere, "-tess_id", "warpRun.tess_id", "=="); 949 PXOPT_COPY_STR(config->args, warpWhere, "-filter", "rawExp.filter", "==");950 949 PXOPT_COPY_STR(config->args, warpWhere, "-warp_label", "warpRun.label", "=="); 951 950 PXOPT_COPY_F32(config->args, warpWhere, "-good_frac", "warpSkyfile.good_frac", ">="); … … 960 959 PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false); 961 960 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false); 961 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 962 962 963 963 // find all things to queue 964 psString query = pxDataGet("difftool_define byquery_part1.sql");964 psString query = pxDataGet("difftool_definewarpstack_part1.sql"); 965 965 if (!query) { 966 966 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 1057 1057 } 1058 1058 1059 if (pretend) { 1060 // negative simple so the default is true 1061 if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) { 1062 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1063 psFree(output); 1064 return false; 1065 } 1066 psFree(output); 1067 return true; 1068 } 1069 1059 1070 // create temporary table 1060 query = pxDataGet("difftool_define byquery_temp_create.sql");1071 query = pxDataGet("difftool_definewarpstack_temp_create.sql"); 1061 1072 if (!p_psDBRunQuery(config->dbh, query)) { 1062 1073 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1070 1081 query = NULL; 1071 1082 1072 psString skycell_query = pxDataGet("difftool_define byquery_part2.sql");1083 psString skycell_query = pxDataGet("difftool_definewarpstack_part2.sql"); 1073 1084 1074 1085 psArray *list = psArrayAllocEmpty(16); // List of runs, to print … … 1183 1194 registered, 1184 1195 tess_id, 1185 exp_id, 1186 false // magicked 1196 false, // bothways 1197 true, // exposure 1198 0 // magicked 1187 1199 ); 1188 1200 … … 1282 1294 "ABS(TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs)))", "<="); 1283 1295 1296 // other where restrictions: 1297 PXOPT_COPY_TIME(config->args, selectWhere, "-dateobs_begin", "inputRawExp.dateobs", ">="); 1298 PXOPT_COPY_TIME(config->args, selectWhere, "-dateobs_end", "inputRawExp.dateobs", "<="); 1299 PXOPT_COPY_RADEC(config->args, selectWhere, "-ra_min", "inputRawExp.ra", ">="); 1300 PXOPT_COPY_RADEC(config->args, selectWhere, "-ra_max", "inputRawExp.ra", "<"); 1301 PXOPT_COPY_RADEC(config->args, selectWhere, "-decl_min", "inputRawExp.decl", ">="); 1302 PXOPT_COPY_RADEC(config->args, selectWhere, "-decl_max", "inputRawExp.decl", "<"); 1303 PXOPT_COPY_F32(config->args, selectWhere, "-sat_pixel_frac_min", "inputRawExp.sat_pixel_frac", ">="); 1304 PXOPT_COPY_F32(config->args, selectWhere, "-sat_pixel_frac_max", "inputRawExp.sat_pixel_frac", "<"); 1305 PXOPT_COPY_F64(config->args, selectWhere, "-airmass_min", "inputRawExp.airmass", ">="); 1306 PXOPT_COPY_F64(config->args, selectWhere, "-airmass_max", "inputRawExp.airmass", "<"); 1307 PXOPT_COPY_F32(config->args, selectWhere, "-exp_time_min", "inputRawExp.exp_time", ">="); 1308 PXOPT_COPY_F32(config->args, selectWhere, "-exp_time_max", "inputRawExp.exp_time", "<"); 1309 PXOPT_COPY_F64(config->args, selectWhere, "-bg_min", "inputRawExp.bg", ">="); 1310 PXOPT_COPY_F64(config->args, selectWhere, "-bg_max", "inputRawExp.bg", "<"); 1311 PXOPT_COPY_F64(config->args, selectWhere, "-bg_stdev_min", "inputRawExp.bg_stdev", ">="); 1312 PXOPT_COPY_F64(config->args, selectWhere, "-bg_stdev_max", "inputRawExp.bg_stdev", "<"); 1313 PXOPT_COPY_F64(config->args, selectWhere, "-bg_mean_stdev_min", "inputRawExp.bg_mean_stdev", ">="); 1314 PXOPT_COPY_F64(config->args, selectWhere, "-bg_mean_stdev_max", "inputRawExp.bg_mean_stdev", "<"); 1315 PXOPT_COPY_F64(config->args, selectWhere, "-alt_min", "inputRawExp.alt", ">="); 1316 PXOPT_COPY_F64(config->args, selectWhere, "-alt_max", "inputRawExp.alt", "<"); 1317 PXOPT_COPY_F64(config->args, selectWhere, "-az_min", "inputRawExp.az", ">="); 1318 PXOPT_COPY_F64(config->args, selectWhere, "-az_max", "inputRawExp.az", "<"); 1319 PXOPT_COPY_F32(config->args, selectWhere, "-ccd_temp_min", "inputRawExp.ccd_temp", ">="); 1320 PXOPT_COPY_F32(config->args, selectWhere, "-ccd_temp_max", "inputRawExp.ccd_temp", "<"); 1321 PXOPT_COPY_F64(config->args, selectWhere, "-posang_min", "inputRawExp.posang", ">="); 1322 PXOPT_COPY_F64(config->args, selectWhere, "-posang_max", "inputRawExp.posang", "<"); 1323 PXOPT_COPY_F32(config->args, selectWhere, "-sun_angle_min", "inputRawExp.sun_angle", ">="); 1324 PXOPT_COPY_F32(config->args, selectWhere, "-sun_angle_max", "inputRawExp.sun_angle", "<"); 1325 PXOPT_COPY_STR(config->args, selectWhere, "-comment", "inputRawExp.comment", "LIKE"); 1326 1284 1327 // Haversine formula for great circle distance 1285 1328 PXOPT_COPY_F32(config->args, selectWhere, "-distance", 1286 "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + COS(inputRawExp.decl)*COS(templateRawExp.decl)*POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<="); 1329 "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + " 1330 "COS(inputRawExp.decl)*COS(templateRawExp.decl)*" 1331 "POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<="); 1287 1332 1288 1333 PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false); … … 1308 1353 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1309 1354 1355 if (!psDBTransaction(config->dbh)) { 1356 psError(PS_ERR_UNKNOWN, false, "database error"); 1357 psFree(selectWhere); 1358 psFree(insertWhere); 1359 return false; 1360 } 1361 1362 if (!rerun) { 1363 // Need to build table of exposures with diffs 1364 psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL 1365 if (!tempCreate) { 1366 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1367 psFree(selectWhere); 1368 psFree(insertWhere); 1369 if (!psDBRollback(config->dbh)) { 1370 psError(PS_ERR_UNKNOWN, false, "database error"); 1371 } 1372 return false; 1373 } 1374 1375 if (!p_psDBRunQuery(config->dbh, tempCreate)) { 1376 psError(PS_ERR_UNKNOWN, false, "Unable to create temp table: %s", tempCreate); 1377 psFree(tempCreate); 1378 psFree(selectWhere); 1379 psFree(insertWhere); 1380 if (!psDBRollback(config->dbh)) { 1381 psError(PS_ERR_UNKNOWN, false, "database error"); 1382 } 1383 return false; 1384 } 1385 psFree(tempCreate); 1386 1387 psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table 1388 if (!tempInsert) { 1389 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1390 psFree(selectWhere); 1391 psFree(insertWhere); 1392 if (!psDBRollback(config->dbh)) { 1393 psError(PS_ERR_UNKNOWN, false, "database error"); 1394 } 1395 return false; 1396 } 1397 1398 psString where = psStringCopy(""); // WHERE for insertion 1399 if (label) { 1400 psStringAppend(&where, "\nAND diffRun.label = '%s'", label); 1401 } 1402 1403 if (!p_psDBRunQueryF(config->dbh, tempInsert, where, where)) { 1404 psError(PS_ERR_UNKNOWN, false, "Unable to insert into temp table: %s", tempInsert); 1405 psFree(tempInsert); 1406 psFree(where); 1407 psFree(selectWhere); 1408 psFree(insertWhere); 1409 if (!psDBRollback(config->dbh)) { 1410 psError(PS_ERR_UNKNOWN, false, "database error"); 1411 } 1412 return false; 1413 } 1414 psFree(where); 1415 psFree(tempInsert); 1416 } 1417 1418 // Get list of warps to diff 1310 1419 psString select = pxDataGet("difftool_definewarpwarp_select.sql"); 1311 1420 if (!select) { 1312 1421 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1422 psFree(selectWhere); 1423 psFree(insertWhere); 1424 if (!psDBRollback(config->dbh)) { 1425 psError(PS_ERR_UNKNOWN, false, "database error"); 1426 } 1313 1427 return false; 1314 1428 } … … 1323 1437 psFree(selectWhere); 1324 1438 1439 if (!available) { 1440 psStringAppend(&whereClause, 1441 "\n%s inputWarpRun.state = 'full'" 1442 "AND templateWarpRun.state = 'full'", 1443 whereClause ? "AND" : "WHERE"); 1444 } 1445 1325 1446 if (!rerun) { 1326 psStringAppend(&whereClause, "\n%s (diffRun.diff_id IS NULL", whereClause ? "AND" : "WHERE"); 1327 if (label) { 1328 psStringAppend(&whereClause, " OR diffRun.label != %s", label); 1329 } 1330 psStringAppend(&whereClause, ")"); 1331 } 1332 1333 if (!available) { 1334 psStringAppend(&whereClause, "\n%s inputWarpRun.state = 'full'", whereClause ? "AND" : "WHERE"); 1335 } 1336 1337 if (!psDBTransaction(config->dbh)) { 1338 psError(PS_ERR_UNKNOWN, false, "database error"); 1339 psFree(select); 1340 psFree(whereClause); 1341 psFree(insertWhere); 1342 return false; 1447 psStringAppend(&whereClause, "\n%s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE"); 1343 1448 } 1344 1449 1345 1450 if (!p_psDBRunQueryF(config->dbh, select, 1346 !rerun ? "\n" : "", // Activate LEFT JOIN against diff Run?1451 !rerun ? "\n" : "", // Activate LEFT JOIN against diffs? 1347 1452 whereClause)) { 1348 1453 psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s [WITH] %s", select, whereClause); … … 1414 1519 psMetadata *row = results->data[i]; // Result row from query 1415 1520 1416 psS64 exp_id = psMetadataLookupS64(NULL, row, "input_exp_id");1417 1521 psS64 input_id = psMetadataLookupS64(NULL, row, "input_warp_id"); 1418 1522 const char *template = psMetadataLookupStr(NULL, row, "template_warp_id"); 1419 1523 const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id"); 1420 if (! exp_id || !input_id || !template || !tess_id) {1524 if (!input_id || !template || !tess_id) { 1421 1525 psError(PXTOOLS_ERR_PROG, false, "Identifiers not found"); 1422 1526 psFree(list); … … 1430 1534 1431 1535 diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered, 1432 tess_id, exp_id, false); // Run to insert1536 tess_id, true, true, false); // Run to insert 1433 1537 if (!diffRunInsertObject(config->dbh, run)) { 1434 1538 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1511 1615 1512 1616 psMetadata *where = psMetadataAlloc(); 1513 pxAddLabelSearchArgs (config, where, "-label", " label", "==");1617 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1514 1618 1515 1619 psString query = pxDataGet("difftool_pendingcleanuprun.sql"); … … 1576 1680 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 1577 1681 } 1578 pxAddLabelSearchArgs (config, where, "-label", " label", "==");1682 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1579 1683 1580 1684 psString query = pxDataGet("difftool_pendingcleanupskyfile.sql"); … … 1738 1842 1739 1843 psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id"); 1740 bool magicked = psMetadataLookupBool(NULL, row, "magicked");1844 psS64 magicked = psMetadataLookupS64(NULL, row, "magicked"); 1741 1845 1742 1846 // set diffRun.state to 'stop'
Note:
See TracChangeset
for help on using the changeset viewer.
