- Timestamp:
- May 26, 2009, 1:59:32 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/difftool.c (modified) (37 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090301/ippTools/src
- Property svn:ignore
-
old new 33 33 pstamptool 34 34 disttool 35 receivetool
-
- Property svn:ignore
-
branches/cnb_branches/cnb_branch_20090301/ippTools/src/difftool.c
r23594 r24244 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); … … 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 … … 412 414 psMetadata *where = psMetadataAlloc(); 413 415 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 414 PXOPT_COPY_STR(config->args, where,"-label", "diffRun.label", "==");416 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 415 417 416 418 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 485 487 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); // required 486 488 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 487 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);488 PXOPT_LOOKUP_S TR(uri, config->args, "-uri", (code == 0), false);489 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", ( code== 0), false);489 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 490 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 491 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", (fault == 0), false); 490 492 491 493 // optional … … 506 508 PXOPT_LOOKUP_F32(kernel_xy, config->args, "-kernel_xy", false, false); 507 509 PXOPT_LOOKUP_F32(kernel_yy, config->args, "-kernel_yy", false, false); 510 PXOPT_LOOKUP_F32(deconv_max, config->args, "-deconv_max", false, false); 508 511 PXOPT_LOOKUP_S32(sources, config->args, "-sources", false, false); 509 512 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); … … 519 522 diff_id, 520 523 skycell_id, 521 uri,522 524 path_base, 525 "full", 523 526 bg, 524 527 bg_stdev, … … 533 536 kernel_xy, 534 537 kernel_yy, 538 deconv_max, 535 539 sources, 536 540 dtime_diff, … … 540 544 hostname, 541 545 good_frac, 542 code, 546 fault, 547 quality, 543 548 magicked 544 549 )) { … … 578 583 PXOPT_COPY_S64(config->args, where, "-diff_skyfile_id", "diffInputSkyfile.diff_skyfile_id", "=="); 579 584 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffSkyfile.tess_id", "=="); 580 PXOPT_COPY_S16(config->args, where, "- code", "diffSkyfile.fault", "==");585 PXOPT_COPY_S16(config->args, where, "-fault", "diffSkyfile.fault", "=="); 581 586 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 582 587 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); … … 655 660 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffSkyfile.diff_id", "=="); 656 661 PXOPT_COPY_STR(config->args, where, "-label", "diffRun.label", "=="); 657 PXOPT_COPY_S16(config->args, where, "- code", "fault", "==");662 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 658 663 659 664 if (!psDBTransaction(config->dbh)) { … … 690 695 psFree(query); 691 696 692 psLogMsg("dif tool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh));697 psLogMsg("difftool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh)); 693 698 } 694 699 … … 766 771 psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none 767 772 psS64 template_stack_id, // Stack identifier for template image, PS_MAX_S64 for none 768 psS64 exp_id, // exposure id for input_warp_id (if defined)769 773 pxConfig *config // Configuration 770 774 ) … … 797 801 registered, 798 802 tess_id, 799 exp_id, 803 false, 804 false, 800 805 false // magicked 801 806 ); … … 877 882 PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false); 878 883 PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false); 879 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);880 884 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 881 885 … … 897 901 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 898 902 "No input has been defined (-input_stack_id or -input_warp_id)"); 899 return false;900 }901 if (input_warp_id && !exp_id) {902 psError(PS_ERR_BAD_PARAMETER_VALUE, true,903 "-exp_id is required with -input_warp_id.");904 903 return false; 905 904 } … … 912 911 template_warp_id ? template_warp_id : PS_MAX_S64, 913 912 template_stack_id ? template_stack_id : PS_MAX_S64, 914 exp_id ? exp_id : PS_MAX_S64,915 913 config)) { 916 914 psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun"); … … 930 928 931 929 932 static bool define byqueryMode(pxConfig *config)930 static bool definewarpstackMode(pxConfig *config) 933 931 { 934 932 PS_ASSERT_PTR_NON_NULL(config, false); … … 955 953 PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false); 956 954 PXOPT_LOOKUP_BOOL(available, config->args, "-available", false); 955 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 957 956 958 957 // find all things to queue 959 psString query = pxDataGet("difftool_define byquery_part1.sql");958 psString query = pxDataGet("difftool_definewarpstack_part1.sql"); 960 959 if (!query) { 961 960 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 1052 1051 } 1053 1052 1053 if (pretend) { 1054 // negative simple so the default is true 1055 if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) { 1056 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1057 psFree(output); 1058 return false; 1059 } 1060 psFree(output); 1061 return true; 1062 } 1063 1054 1064 // create temporary table 1055 query = pxDataGet("difftool_define byquery_temp_create.sql");1065 query = pxDataGet("difftool_definewarpstack_temp_create.sql"); 1056 1066 if (!p_psDBRunQuery(config->dbh, query)) { 1057 1067 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1065 1075 query = NULL; 1066 1076 1067 psString skycell_query = pxDataGet("difftool_define byquery_part2.sql");1077 psString skycell_query = pxDataGet("difftool_definewarpstack_part2.sql"); 1068 1078 1069 1079 psArray *list = psArrayAllocEmpty(16); // List of runs, to print … … 1178 1188 registered, 1179 1189 tess_id, 1180 exp_id, 1190 false, // bothways 1191 true, // exposure 1181 1192 false // magicked 1182 1193 ); … … 1269 1280 PXOPT_COPY_S64(config->args, selectWhere, "-exp_id", "inputRawExp.exp_id", "=="); 1270 1281 PXOPT_COPY_STR(config->args, selectWhere, "-filter", "inputRawExp.filter", "=="); 1282 PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "inputRawExp.obs_mode", "=="); 1283 PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "templateRawExp.obs_mode", "=="); 1271 1284 PXOPT_COPY_STR(config->args, selectWhere, "-input_label", "inputWarpRun.label", "=="); 1272 1285 PXOPT_COPY_STR(config->args, selectWhere, "-template_label", "templateWarpRun.label", "=="); 1286 PXOPT_COPY_F32(config->args, selectWhere, "-rotdiff", "ABS(inputRawExp.posang - templateRawExp.posang)", "<="); 1273 1287 PXOPT_COPY_F32(config->args, selectWhere, "-timediff", 1274 1288 "ABS(TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs)))", "<="); 1275 PXOPT_COPY_F32(config->args, selectWhere, "-rotdiff", "ABS(inputRawExp.posang - templateRawExp.posang)", "<="); 1289 1290 // Haversine formula for great circle distance 1291 PXOPT_COPY_F32(config->args, selectWhere, "-distance", 1292 "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + " 1293 "COS(inputRawExp.decl)*COS(templateRawExp.decl)*" 1294 "POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<="); 1295 1296 PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false); 1297 1298 psMetadataAddF32(selectWhere, PS_LIST_TAIL, 1299 "TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs))", 1300 PS_META_DUPLICATE_OK, backwards ? "<" : ">", 0.0); 1276 1301 1277 1302 // Restrictions for inserting skycells … … 1289 1314 PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false); 1290 1315 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1291 1292 1316 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1317 1318 if (!psDBTransaction(config->dbh)) { 1319 psError(PS_ERR_UNKNOWN, false, "database error"); 1320 psFree(selectWhere); 1321 psFree(insertWhere); 1322 return false; 1323 } 1324 1325 if (!rerun) { 1326 // Need to build table of exposures with diffs 1327 psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL 1328 if (!tempCreate) { 1329 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1330 psFree(selectWhere); 1331 psFree(insertWhere); 1332 if (!psDBRollback(config->dbh)) { 1333 psError(PS_ERR_UNKNOWN, false, "database error"); 1334 } 1335 return false; 1336 } 1337 1338 if (!p_psDBRunQuery(config->dbh, tempCreate)) { 1339 psError(PS_ERR_UNKNOWN, false, "Unable to create temp table: %s", tempCreate); 1340 psFree(tempCreate); 1341 psFree(selectWhere); 1342 psFree(insertWhere); 1343 if (!psDBRollback(config->dbh)) { 1344 psError(PS_ERR_UNKNOWN, false, "database error"); 1345 } 1346 return false; 1347 } 1348 psFree(tempCreate); 1349 1350 psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table 1351 if (!tempInsert) { 1352 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1353 psFree(selectWhere); 1354 psFree(insertWhere); 1355 if (!psDBRollback(config->dbh)) { 1356 psError(PS_ERR_UNKNOWN, false, "database error"); 1357 } 1358 return false; 1359 } 1360 1361 psString where = psStringCopy(""); // WHERE for insertion 1362 if (label) { 1363 psStringAppend(&where, "\nAND diffRun.label = '%s'", label); 1364 } 1365 1366 if (!p_psDBRunQueryF(config->dbh, tempInsert, where, where)) { 1367 psError(PS_ERR_UNKNOWN, false, "Unable to insert into temp table: %s", tempInsert); 1368 psFree(tempInsert); 1369 psFree(where); 1370 psFree(selectWhere); 1371 psFree(insertWhere); 1372 if (!psDBRollback(config->dbh)) { 1373 psError(PS_ERR_UNKNOWN, false, "database error"); 1374 } 1375 return false; 1376 } 1377 psFree(where); 1378 psFree(tempInsert); 1379 } 1380 1381 // Get list of warps to diff 1293 1382 psString select = pxDataGet("difftool_definewarpwarp_select.sql"); 1294 1383 if (!select) { 1295 1384 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1385 psFree(selectWhere); 1386 psFree(insertWhere); 1387 if (!psDBRollback(config->dbh)) { 1388 psError(PS_ERR_UNKNOWN, false, "database error"); 1389 } 1296 1390 return false; 1297 1391 } … … 1306 1400 psFree(selectWhere); 1307 1401 1402 if (!available) { 1403 psStringAppend(&whereClause, 1404 "\n%s inputWarpRun.state = 'full'" 1405 "AND templateWarpRun.state = 'full'", 1406 whereClause ? "AND" : "WHERE"); 1407 } 1408 1308 1409 if (!rerun) { 1309 psStringAppend(&whereClause, "\n%s diffRun.diff_id IS NULL", whereClause ? "AND" : "WHERE"); 1310 } 1311 1312 if (!available) { 1313 psStringAppend(&whereClause, "\n%s inputWarpRun.state = 'full'", whereClause ? "AND" : "WHERE"); 1314 } 1315 1316 if (!psDBTransaction(config->dbh)) { 1317 psError(PS_ERR_UNKNOWN, false, "database error"); 1318 psFree(select); 1319 psFree(whereClause); 1320 psFree(insertWhere); 1321 return false; 1410 psStringAppend(&whereClause, "\n%s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE"); 1322 1411 } 1323 1412 1324 1413 if (!p_psDBRunQueryF(config->dbh, select, 1325 !rerun ? "\n" : "", // Activate LEFT JOIN against diff Run?1414 !rerun ? "\n" : "", // Activate LEFT JOIN against diffs? 1326 1415 whereClause)) { 1327 1416 psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s [WITH] %s", select, whereClause); … … 1368 1457 } 1369 1458 1459 if (pretend) { 1460 // negative simple so the default is true 1461 if (!ippdbPrintMetadatas(stdout, results, "diffRun", !simple)) { 1462 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1463 psFree(results); 1464 return false; 1465 } 1466 psFree(results); 1467 return true; 1468 } 1469 1370 1470 psString insert = pxDataGet("difftool_definewarpwarp_insert.sql"); // Insertion for each new run 1371 1471 1372 1472 if (psListLength(insertWhere->list)) { 1373 1473 psString whereClause = psDBGenerateWhereConditionSQL(insertWhere, NULL); 1374 psStringAppend(&insert, "\n %s", whereClause);1474 psStringAppend(&insert, "\nAND %s", whereClause); 1375 1475 psFree(whereClause); 1376 1476 } … … 1382 1482 psMetadata *row = results->data[i]; // Result row from query 1383 1483 1384 psS64 exp_id = psMetadataLookupS64(NULL, row, "input_exp_id");1385 1484 psS64 input_id = psMetadataLookupS64(NULL, row, "input_warp_id"); 1386 psS64 template_id = psMetadataLookupS64(NULL, row, "template_warp_id");1485 const char *template = psMetadataLookupStr(NULL, row, "template_warp_id"); 1387 1486 const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id"); 1388 if (! exp_id || !input_id || !template_id|| !tess_id) {1487 if (!input_id || !template || !tess_id) { 1389 1488 psError(PXTOOLS_ERR_PROG, false, "Identifiers not found"); 1390 1489 psFree(list); … … 1398 1497 1399 1498 diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered, 1400 tess_id, exp_id, false); // Run to insert1499 tess_id, true, true, false); // Run to insert 1401 1500 if (!diffRunInsertObject(config->dbh, run)) { 1402 1501 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1413 1512 1414 1513 // Convert identifiers to string, for insertion into query 1415 psString diff = NULL, input = NULL , template = NULL; // String versions of identifiers1514 psString diff = NULL, input = NULL; // String versions of identifiers 1416 1515 psStringAppend(&diff, "%" PRId64, run->diff_id); 1417 1516 psStringAppend(&input, "%" PRId64, input_id); 1418 psStringAppend(&template, "%" PRId64, template_id);1419 1517 1420 1518 if (!p_psDBRunQueryF(config->dbh, insert, diff, input, template, input, template)) { 1421 1519 psError(PS_ERR_UNKNOWN, false, "database error"); 1422 1520 psFree(input); 1423 psFree(template);1424 1521 psFree(diff); 1425 1522 psFree(run); … … 1433 1530 } 1434 1531 psFree(input); 1435 psFree(template);1436 1532 psFree(diff); 1437 1533 … … 1482 1578 1483 1579 psMetadata *where = psMetadataAlloc(); 1484 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");1580 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1485 1581 1486 1582 psString query = pxDataGet("difftool_pendingcleanuprun.sql"); … … 1547 1643 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 1548 1644 } 1549 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");1645 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "=="); 1550 1646 1551 1647 psString query = pxDataGet("difftool_pendingcleanupskyfile.sql"); … … 1662 1758 PS_ASSERT_PTR_NON_NULL(config, false); 1663 1759 1664 PXOPT_LOOKUP_S16( code, config->args, "-code", true, false);1760 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 1665 1761 1666 1762 psMetadata *where = psMetadataAlloc(); 1667 1763 PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "=="); 1668 1764 1669 if (!pxSetFaultCode(config->dbh, "diffSkyfile", where, code)) {1765 if (!pxSetFaultCode(config->dbh, "diffSkyfile", where, fault)) { 1670 1766 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1671 1767 psFree (where); … … 1737 1833 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false); 1738 1834 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1835 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1739 1836 1740 1837 FILE *f = fopen (outfile, "w"); … … 1782 1879 psArray *output = p_psDBFetchResult(config->dbh); 1783 1880 if (!output) { 1784 psError(PS_ERR_UNKNOWN, false, "database error");1785 1881 return false; 1786 1882 } 1787 1883 if (!psArrayLength(output)) { 1788 ps Trace("regtool", PS_LOG_INFO, "no rows found");1884 psError(PS_ERR_UNKNOWN, true, "no rows found"); 1789 1885 psFree(output); 1790 return true; 1886 return false; 1887 } 1888 1889 if (clean) { 1890 bool success = true; 1891 if (!strcmp(tables[i].tableName, "diffRun")) { 1892 success = pxSetStateCleaned("diffRun", "state", output); 1893 #ifdef notyet 1894 // diffSkyfile doesn't have dataState yet 1895 } else if (!strcmp(tables[i].tableName, "diffSkyfile")) { 1896 success = pxSetStateCleaned("diffSkyfile", "data_state", output); 1897 #endif 1898 } 1899 if (!success) { 1900 psFree(output); 1901 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s", tables[i].tableName); 1902 return false; 1903 } 1791 1904 } 1792 1905
Note:
See TracChangeset
for help on using the changeset viewer.
