- 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/warptool.c (modified) (32 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/warptool.c
r23594 r24244 30 30 #include "pxtools.h" 31 31 #include "warptool.h" 32 #include "pxwarp.h"33 32 34 33 static psS64 definerunMode(pxConfig *config); … … 42 41 static bool towarpedMode(pxConfig *config); 43 42 static bool addwarpedMode(pxConfig *config); 43 static bool advancerunMode(pxConfig *config); 44 44 static bool warpedMode(pxConfig *config); 45 45 static bool revertwarpedMode(pxConfig *config); … … 89 89 MODECASE(WARPTOOL_MODE_TOWARPED, towarpedMode); 90 90 MODECASE(WARPTOOL_MODE_ADDWARPED, addwarpedMode); 91 MODECASE(WARPTOOL_MODE_ADVANCERUN, advancerunMode); 91 92 MODECASE(WARPTOOL_MODE_WARPED, warpedMode); 92 93 MODECASE(WARPTOOL_MODE_REVERTWARPED, revertwarpedMode); … … 135 136 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 136 137 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 137 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false);138 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); // required (no default TESS) 138 139 PXOPT_LOOKUP_STR(end_stage, config->args, "-end_stage", false, false); 139 140 PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false); … … 191 192 192 193 psMetadata *where = psMetadataAlloc(); 193 pxwarpGetSearchArgs (config, where); 194 PXOPT_COPY_STR(config->args, where, "-reduction", "fakeRun.reduction", "=="); 195 PXOPT_COPY_STR(config->args, where, "-label", "fakeRun.label", "=="); 194 PXOPT_COPY_S64(config->args, where, "-fake_id", "fakeRun.fake_id", "=="); 195 PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "=="); 196 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 197 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 198 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 199 PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.camera", "=="); 200 PXOPT_COPY_STR(config->args, where, "-telescope", "rawExp.telescope", "=="); 201 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawExp.dateobs", ">="); 202 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawExp.dateobs", "<="); 203 PXOPT_COPY_STR(config->args, where, "-exp_tag", "rawExp.exp_tag", "=="); 204 PXOPT_COPY_STR(config->args, where, "-exp_type", "rawExp.exp_type", "=="); 205 PXOPT_COPY_STR(config->args, where, "-filelevel", "rawExp.filelevel", "=="); 206 PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "=="); 207 PXOPT_COPY_F64(config->args, where, "-airmass_min", "rawExp.airmass", ">="); 208 PXOPT_COPY_F64(config->args, where, "-airmass_max", "rawExp.airmass", "<"); 209 PXOPT_COPY_F64(config->args, where, "-ra_min", "rawExp.ra", ">="); 210 PXOPT_COPY_F64(config->args, where, "-ra_max", "rawExp.ra", "<"); 211 PXOPT_COPY_F64(config->args, where, "-decl_min", "rawExp.decl", ">="); 212 PXOPT_COPY_F64(config->args, where, "-decl_max", "rawExp.decl", "<"); 213 PXOPT_COPY_F32(config->args, where, "-exp_time_min", "rawExp.exp_time", ">="); 214 PXOPT_COPY_F32(config->args, where, "-exp_time_max", "rawExp.exp_time", "<"); 215 PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_min", "rawExp.sat_pixel_frac", ">="); 216 PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_max", "rawExp.sat_pixel_frac", "<"); 217 PXOPT_COPY_F64(config->args, where, "-bg_min", "rawExp.bg", ">="); 218 PXOPT_COPY_F64(config->args, where, "-bg_max", "rawExp.bg", "<"); 219 PXOPT_COPY_F64(config->args, where, "-bg_stdev_min", "rawExp.bg_stdev", ">="); 220 PXOPT_COPY_F64(config->args, where, "-bg_stdev_max", "rawExp.bg_stdev", "<"); 221 PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_min", "rawExp.bg_mean_stdev", ">="); 222 PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_max", "rawExp.bg_mean_stdev", "<"); 223 PXOPT_COPY_F64(config->args, where, "-alt_min", "rawExp.alt", ">="); 224 PXOPT_COPY_F64(config->args, where, "-alt_max", "rawExp.alt", "<"); 225 PXOPT_COPY_F64(config->args, where, "-az_min", "rawExp.az", ">="); 226 PXOPT_COPY_F64(config->args, where, "-az_max", "rawExp.az", "<"); 227 PXOPT_COPY_F32(config->args, where, "-ccd_temp_min", "rawExp.ccd_temp", ">="); 228 PXOPT_COPY_F32(config->args, where, "-ccd_temp_max", "rawExp.ccd_temp", "<"); 229 PXOPT_COPY_F64(config->args, where, "-posang_min", "rawExp.posang", ">="); 230 PXOPT_COPY_F64(config->args, where, "-posang_max", "rawExp.posang", "<"); 231 PXOPT_COPY_STR(config->args, where, "-object", "rawExp.object", "=="); 232 PXOPT_COPY_F32(config->args, where, "-solang_min", "rawExp.solang", ">="); 233 PXOPT_COPY_F32(config->args, where, "-solang_max", "rawExp.solang", "<"); 234 PXOPT_COPY_STR(config->args, where, "-reduction", "fakeRun.reduction", "=="); 235 pxAddLabelSearchArgs (config, where, "-label", "fakeRun.label", "=="); 196 236 197 237 if (!psListLength(where->list) && … … 227 267 228 268 // use psDBGenerateWhereSQL because the SQL yields an intermediate table 229 if ( where &&psListLength(where->list)) {230 psString whereClause = psDBGenerateWhere SQL(where, NULL);231 psStringAppend(&query, " %s", whereClause);269 if (psListLength(where->list)) { 270 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 271 psStringAppend(&query, "AND %s", whereClause); 232 272 psFree(whereClause); 233 273 } … … 256 296 // data out so we have the option of changing these values or leaving the 257 297 // old values in place (i.e., passing the values through). 298 299 // loop over our list of fakeRun rows to check the supplied and selected tess_id values: 300 for (long i = 0; i < psArrayLength(output); i++) { 301 psMetadata *md = output->data[i]; 302 303 fakeRunRow *row = fakeRunObjectFromMetadata(md); 304 if (!row) { 305 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fakeRun"); 306 psFree(output); 307 return false; 308 } 309 310 if (!tess_id && !row->tess_id) { 311 psError(PS_ERR_UNKNOWN, false, "cannot queue warp run without a defined tess id: label: %s, fake_id %" PRId64, row->label, row->fake_id); 312 psFree(output); 313 return false; 314 } 315 316 psFree(row); 317 } 318 psFree(output); 258 319 259 320 // loop over our list of fakeRun rows … … 299 360 300 361 psMetadata *where = psMetadataAlloc(); 301 pxwarpGetSearchArgs (config, where);302 362 PXOPT_COPY_S64(config->args, where, "-warp_id", "warpRun.warp_id", "=="); 303 363 PXOPT_COPY_STR(config->args, where, "-reduction", "warpRun.reduction", "=="); 304 PXOPT_COPY_STR(config->args, where, "-label", "warpRun.label", "==");305 PXOPT_COPY_STR(config->args, where, "-state", "warpRun.state", "==");364 PXOPT_COPY_STR(config->args, where, "-label", "warpRun.label", "=="); 365 PXOPT_COPY_STR(config->args, where, "-state", "warpRun.state", "=="); 306 366 307 367 if (!psListLength(where->list) … … 498 558 psMetadata *where = psMetadataAlloc(); 499 559 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 500 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");560 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 501 561 502 562 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 572 632 PXOPT_LOOKUP_STR(mapfile, config->args, "-mapfile", false, false); 573 633 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", false, false); 574 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);634 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 575 635 576 636 if (!psDBTransaction(config->dbh)) { … … 579 639 } 580 640 581 if ( code== 0) {641 if (fault == 0) { 582 642 if (!parseAndInsertSkyCellMap(config, mapfile)) { 583 643 psError(PS_ERR_UNKNOWN, false, "failed to inject mapfile: %s into the database", mapfile); … … 594 654 NULL, // tess_id 595 655 NULL, // class_id 596 code// fault656 fault // fault 597 657 ); 598 658 } … … 770 830 psMetadata *where = psMetadataAlloc(); 771 831 PXOPT_COPY_S64(config->args, where, "-warp_id", "warpSkyCellMap.warp_id", "=="); 772 PXOPT_COPY_STR(config->args, where, "-label", "warpRun.label", "==");832 pxAddLabelSearchArgs (config, where, "-label", "warpRun.label", "=="); 773 833 774 834 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 859 919 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 860 920 PXOPT_LOOKUP_F32(good_frac, config->args, "-good_frac", false, false); 861 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);862 921 PXOPT_LOOKUP_BOOL(magicked, config->args, "-magicked", false); 863 922 864 923 // default values 865 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 924 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 925 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 866 926 867 927 // we don't want to insert the last skyfile in a run but then not mark the … … 890 950 ymin, 891 951 ymax, 892 !accept,893 code,952 fault, 953 quality, 894 954 magicked 895 955 )) { … … 901 961 } 902 962 903 if (!warpCompletedRuns(config)) {904 if (!psDBRollback(config->dbh)) {905 psError(PS_ERR_UNKNOWN, false, "database error");906 }907 psError(PS_ERR_UNKNOWN, false, "database error");908 return false;909 }910 911 963 // point of no return 912 964 if (!psDBCommit(config->dbh)) { … … 914 966 return false; 915 967 } 968 969 return true; 970 } 971 972 static bool advancerunMode(pxConfig *config) 973 { 974 PS_ASSERT_PTR_NON_NULL(config, false); 975 976 psMetadata *where = psMetadataAlloc(); 977 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 978 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 979 980 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 981 982 psString query = pxDataGet("warptool_finished_run_select.sql"); 983 if (!query) { 984 psError(PXTOOLS_ERR_DATA, false, "failed to retrieve SQL statement"); 985 return false; 986 } 987 988 if (psListLength(where->list)) { 989 psString whereClause = psDBGenerateWhereSQL(where, NULL); 990 psStringAppend(&query, " %s", whereClause); 991 psFree(whereClause); 992 } 993 psFree(where); 994 995 if (!p_psDBRunQuery(config->dbh, query)) { 996 psError(PS_ERR_UNKNOWN, false, "database error"); 997 psFree(query); 998 return false; 999 } 1000 psFree(query); 1001 1002 psArray *output = p_psDBFetchResult(config->dbh); 1003 if (!output) { 1004 psError(PS_ERR_UNKNOWN, false, "database error"); 1005 return false; 1006 } 1007 if (!psArrayLength(output)) { 1008 psTrace("warptool", PS_LOG_INFO, "no rows found"); 1009 psFree(output); 1010 return true; 1011 } 1012 1013 query = pxDataGet("warptool_finish_run.sql"); 1014 for (long i = 0; i < psArrayLength(output); i++) { 1015 psMetadata *row = output->data[i]; 1016 1017 bool status; 1018 psS64 warp_id = psMetadataLookupS64(&status, row, "warp_id"); 1019 if (!status) { 1020 psError(PS_ERR_UNKNOWN, false, "failed to look up value for warp_id"); 1021 psFree(output); 1022 psFree(query); 1023 return false; 1024 } 1025 psS32 magicked = psMetadataLookupS64(&status, row, "magicked"); 1026 if (!status) { 1027 psError(PS_ERR_UNKNOWN, false, "failed to look up value for magicked"); 1028 psFree(output); 1029 psFree(query); 1030 return false; 1031 } 1032 if (!p_psDBRunQueryF(config->dbh, query, magicked, warp_id)) { 1033 psError(PS_ERR_UNKNOWN, false, "database error"); 1034 psFree(output); 1035 psFree(query); 1036 return false; 1037 } 1038 1039 psS64 numUpdated = psDBAffectedRows(config->dbh); 1040 1041 if (numUpdated != 1) { 1042 psError(PS_ERR_UNKNOWN, false, "should have affected 1 row"); 1043 psFree(query); 1044 psFree(output); 1045 return false; 1046 } 1047 } 1048 psFree(output); 1049 psFree(query); 916 1050 917 1051 return true; … … 1070 1204 1071 1205 psMetadata *where = psMetadataAlloc(); 1072 pxwarpGetSearchArgs (config, where);1073 1206 PXOPT_COPY_S64(config->args, where, "-warp_id", "warpSkyfile.warp_id", "=="); 1074 1207 PXOPT_COPY_STR(config->args, where, "-skycell_id", "warpSkyfile.skycell_id", "=="); … … 1076 1209 PXOPT_COPY_STR(config->args, where, "-reduction", "rawExp.reduction", "=="); 1077 1210 PXOPT_COPY_STR(config->args, where, "-label", "warpRun.label", "=="); 1078 PXOPT_COPY_S16(config->args, where, "- code", "warpSkyfile.fault", "==");1211 PXOPT_COPY_S16(config->args, where, "-fault", "warpSkyfile.fault", "=="); 1079 1212 1080 1213 if (!psListLength(where->list) … … 1092 1225 1093 1226 1227 #ifdef notdef 1228 int numUpdated = 0; // Number updated 1229 { 1094 1230 // Update state to 'new' 1095 int numUpdated; // Number updated1096 {1097 1231 // This query is no longer necessary because we do not set warpRun's to full statte 1098 1232 // if they have faulted skyfiles. … … 1140 1274 psLogMsg("warptool", PS_LOG_INFO, "Updated %d warp runs", numUpdated); 1141 1275 1276 #endif // notdef 1277 1142 1278 // Delete product 1143 1279 int numDeleted; // Number deleted … … 1261 1397 1262 1398 psMetadata *where = psMetadataAlloc(); 1263 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");1399 pxAddLabelSearchArgs (config, where, "-label", "warpRun.label", "=="); 1264 1400 1265 1401 psString query = pxDataGet("warptool_pendingcleanuprun.sql"); … … 1324 1460 psMetadata *where = psMetadataAlloc(); 1325 1461 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 1326 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");1462 pxAddLabelSearchArgs (config, where, "-label", "warpRun.label", "=="); 1327 1463 1328 1464 psString query = pxDataGet("warptool_pendingcleanupskyfile.sql"); … … 1524 1660 PS_ASSERT_PTR_NON_NULL(config, false); 1525 1661 1526 // warp_id, skycell_id, codeare required1662 // warp_id, skycell_id, fault are required 1527 1663 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false); 1528 1664 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 1529 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);1665 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1530 1666 1531 1667 psString query = pxDataGet("warptool_updateskyfile.sql"); 1532 1668 1533 if (!p_psDBRunQueryF(config->dbh, query, code, warp_id, skycell_id)) {1669 if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) { 1534 1670 psError(PS_ERR_UNKNOWN, false, "database error"); 1535 1671 return false; … … 1549 1685 PS_ASSERT_PTR_NON_NULL(config, NULL); 1550 1686 1551 PXOPT_LOOKUP_S64(det_id, config->args, "-warp_id", true, false);1687 PXOPT_LOOKUP_S64(det_id, config->args, "-warp_id", true, false); 1552 1688 PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true, false); 1553 1689 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1690 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 1554 1691 1555 1692 FILE *f = fopen (outfile, "w"); … … 1566 1703 {"warpImfile", "warptool_export_imfile.sql"}, 1567 1704 {"warpSkyfile", "warptool_export_skyfile.sql"}, 1568 {"warpSkyCellMap", "warptool_export_sky _cell_map.sql"},1705 {"warpSkyCellMap", "warptool_export_skycell_map.sql"}, 1569 1706 }; 1570 1707 1571 1572 for (int i=0; i < sizeof(tables); i++) { 1708 int numTables = sizeof(tables)/sizeof(tables[0]); 1709 1710 for (int i=0; i < numTables; i++) { 1573 1711 psString query = pxDataGet(tables[i].sqlFilename); 1574 1712 if (!query) { … … 1603 1741 } 1604 1742 if (!psArrayLength(output)) { 1605 ps Trace("regtool", PS_LOG_INFO, "no rows found");1743 psError(PS_ERR_UNKNOWN, true, "no rows found"); 1606 1744 psFree(output); 1607 return true;1745 return false; 1608 1746 } 1747 1748 if (clean) { 1749 bool success = true; 1750 if (!strcmp(tables[i].tableName, "warpRun")) { 1751 success = pxSetStateCleaned("warpRun", "state", output); 1752 } else if (!strcmp(tables[i].tableName, "warpSkyfile")) { 1753 success = pxSetStateCleaned("warpSkyfile", "data_state", output); 1754 } 1755 if (!success) { 1756 psFree(output); 1757 psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s", tables[i].tableName); 1758 return false; 1759 } 1760 } 1609 1761 1610 1762 // we must write the export table in non-simple (true) format … … 1627 1779 1628 1780 int numImportTables = 3; 1629 1781 1630 1782 char tables[3] [80] = {"warpImfile", "warpSkyfile", "warpSkyCellMap"}; 1631 1783 1632 1784 PS_ASSERT_PTR_NON_NULL(config, NULL); 1633 1785 1634 1786 PXOPT_LOOKUP_STR(infile, config->args, "-infile", true, false); 1635 1787 … … 1642 1794 psAssert (item, "entry not in input?"); 1643 1795 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 1644 1796 1645 1797 psMetadataItem *entry = psListGet (item->data.list, 0); 1646 1798 assert (entry); … … 1656 1808 psAssert (item, "entry not in input?"); 1657 1809 psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?"); 1658 1810 1659 1811 switch (i) { 1660 case 0: 1812 case 0: 1661 1813 for (int i = 0; i < item->data.list->n; i++) { 1662 1814 entry = psListGet (item->data.list, i); … … 1670 1822 } 1671 1823 break; 1672 1673 case 1: 1824 1825 case 1: 1674 1826 for (int i = 0; i < item->data.list->n; i++) { 1675 1827 entry = psListGet (item->data.list, i); … … 1683 1835 } 1684 1836 break; 1685 1686 case 2: 1837 1838 case 2: 1687 1839 for (int i = 0; i < item->data.list->n; i++) { 1688 1840 entry = psListGet (item->data.list, i);
Note:
See TracChangeset
for help on using the changeset viewer.
