- Timestamp:
- Mar 30, 2012, 2:49:37 PM (14 years ago)
- Location:
- branches/eam_branches/ipp-20111122/ippTools/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20111122/ippTools/src
- Property svn:ignore
-
old new 7 7 Makefile.in 8 8 addtool 9 mergetool 9 10 caltool 10 11 camtool
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/eam_branches/ipp-20111122/ippTools/src/addtool.c
r32851 r33638 141 141 pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label 142 142 PXOPT_COPY_STR(config->args, where, "-reduction", "staticskyyRun.reduction", "=="); 143 pxAddLabelSearchArgs (config, where, "-filter", "stackRun.filter", "=="); // define using camRun label144 }145 if (strcmp(stage, "staticsky_multi")== 0) {146 147 pxAddLabelSearchArgs (config, where, "-label", "staticskyRun.label", "=="); // define using camRun label148 pxAddLabelSearchArgs (config, where, "-data_group","staticskyRun.data_group", "=="); // define using camRun label149 PXOPT_COPY_STR(config->args, where, "-reduction", "staticskyyRun.reduction", "==");150 143 //no filter here 151 144 } … … 227 220 } 228 221 } 222 229 223 if (strcmp(stage,"staticsky") == 0) { 230 if (dvodb ) {231 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_dvo.sql\n%s\n", dvodb,stage);232 // find the cam_id of all the exposures that we want to queue up.233 bare_query = pxDataGet("addtool_find_sky_id_dvo.sql");234 // user supplied dvodb235 psStringAppend(&dvodb_string, "addRun.dvodb = '%s'", dvodb);236 } else {237 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument not found using addtool_find_sky_id.sql\n%s\n",stage);238 // find the cam_id of all the exposures that we want to queue up.239 bare_query = pxDataGet("addtool_find_sky_id.sql");240 // inherit dvodb from camRun, avoid matching NULL241 psStringAppend(&dvodb_string, "(staticskyRun.dvodb IS NOT NULL AND previous_dvodb = staticskyRun.dvodb)");242 }243 }244 245 if (strcmp(stage,"staticsky_multi") == 0) {246 224 if (dvodb ) { 247 225 psTrace("addtool.c", PS_LOG_INFO, "dvodb argument found (%s) using addtool_find_sky_id_multi_dvo.sql\n%s\n", dvodb,stage); … … 292 270 } else { 293 271 //This picks only the unmagicked/uncensored ones 294 if (strcmp(stage,"cam") == 0) { 295 psStringAppend(&query, " AND (camRun.magicked = 0)"); 296 } 272 //if (strcmp(stage,"cam") == 0) { 273 //we can now properly handle the magicked case in ippScripts, so we queue camRuns in any magic state now if -uncensored. 274 //psStringAppend(&query, " AND (camRun.magicked = 0)"); 275 //} 297 276 if (strcmp(stage,"stack") == 0) { 298 277 psStringAppend(&query, " AND (stackRun.magicked = 0)"); … … 309 288 psStringAppend(&query, " GROUP BY stack_id"); 310 289 } 290 // if (strcmp(stage,"staticsky") == 0) { 291 // psStringAppend(&query, " GROUP BY stack_id"); 292 // } 311 293 if (strcmp(stage,"staticsky") == 0) { 312 psStringAppend(&query, " GROUP BY stack_id");313 }314 if (strcmp(stage,"staticsky_multi") == 0) {315 294 psStringAppend(&query, " GROUP BY sky_id"); //some reason it needs this 316 295 } … … 401 380 } 402 381 } 382 403 383 if (strcmp(stage,"staticsky") == 0) { 404 for (long i = 0; i < psArrayLength(output); i++) {405 psMetadata *md = output->data[i];406 407 staticskyRunRow *row = staticskyRunObjectFromMetadata(md);408 409 if (!row) {410 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");411 psFree(output);412 return false;413 }414 415 if (!dvodb) { //there's no staticsky.dvodb416 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined dvodb: label: %s, sky_id %" PRId64, row->label, row->sky_id);417 psFree(output);418 return false;419 }420 if (!workdir && !row->workdir) {421 psError(PS_ERR_UNKNOWN, false, "cannot queue addstar run without a defined workdir: label: %s, sky_id %" PRId64, row->label, row->sky_id);422 psFree(output);423 return false;424 }425 426 psFree(row);427 }428 }429 if (strcmp(stage,"staticsky_multi") == 0) {430 384 for (long i = 0; i < psArrayLength(output); i++) { 431 385 psMetadata *md = output->data[i]; … … 565 519 } 566 520 } 521 567 522 if (strcmp(stage,"staticsky") == 0) { 568 for (long i = 0; i < psArrayLength(output); i++) {569 psMetadata *md = output->data[i];570 psS64 stage_id =0;571 572 staticskyRunRow *row = staticskyRunObjectFromMetadata(md);573 stage_id = row->sky_id;574 575 if (!row) {576 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");577 psFree(output);578 return false;579 }580 581 // queue the exp582 if (!pxaddQueueByCamID(config,583 stage,584 stage_id,585 0,586 workdir ? workdir : row->workdir,587 reduction ? reduction : row->reduction,588 label ? label : row->label,589 data_group ? data_group : (row->data_group ? row->data_group : (label ? label : row->label)),590 dvodb ? dvodb : NULL,591 note ? note : NULL,592 image_only,593 minidvodb,594 minidvodb_group,595 minidvodb_name596 )) {597 if (!psDBRollback(config->dbh)) {598 psError(PS_ERR_UNKNOWN, false, "database error sfg");599 }600 psError(PS_ERR_UNKNOWN, false,601 "failed to trying to queue stage %s %" PRId64,stage, stage_id);602 psFree(row);603 psFree(output);604 return false;605 }606 psFree(row);607 }608 }609 610 if (strcmp(stage,"staticsky_multi") == 0) {611 523 for (long i = 0; i < psArrayLength(output); i++) { 612 524 psMetadata *md = output->data[i]; … … 704 616 query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id"); 705 617 } 706 if (strcmp(stage, "staticsky_multi")==0) { 707 query = psStringCopy("UPDATE addRun JOIN staticskyRun on sky_id = stage_id"); 708 } 618 709 619 710 620 // pxUpdateRun gets parameters from config->args and runs the update query … … 744 654 } 745 655 if (strcmp(stage, "staticsky")==0) { 746 query = pxDataGet("addtool_find_pendingexp_staticsky.sql");747 }748 if (strcmp(stage, "staticsky_multi")==0) {749 656 query = pxDataGet("addtool_find_pendingexp_staticsky_multi.sql"); 750 657 } … … 767 674 psStringAppend(&query, " GROUP BY %s", "stack_id"); 768 675 } 676 //if (strcmp(stage, "staticsky") == 0) { 677 // //this group by is needed to join against all the warps (to get camera) 678 // psStringAppend(&query, " GROUP BY %s", "sky_id"); 679 //} 769 680 if (strcmp(stage, "staticsky") == 0) { 770 //this group by is needed to join against all the warps (to get camera)771 psStringAppend(&query, " GROUP BY %s", "sky_id");772 }773 if (strcmp(stage, "staticsky_multi") == 0) {774 681 //this group by is needed to join against all the warps (to get camera) 775 682 psStringAppend(&query, " GROUP BY %s", "sky_id, stage_extra1"); … … 824 731 PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-minidvodb_name", false, false); 825 732 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 826 733 PXOPT_LOOKUP_S64(stage_extra1, config->args, "-stage_extra1", false, false); 827 734 // generate restrictions 828 735 psMetadata *where = psMetadataAlloc(); … … 902 809 } 903 810 } 904 811 //if there is a stage_extra1, set it in addRun (it's not known until it is processed) 812 if (stage_extra1) { 813 psString setExtra = NULL; 814 psStringAppend (&setExtra, "UPDATE addRun set stage_extra1 = %" PRId64, stage_extra1); 815 psStringAppend (&setExtra, " where add_id = %" PRId64, row->add_id); 816 817 if (!p_psDBRunQuery(config->dbh, setExtra)) { 818 if (!psDBRollback(config->dbh)) { 819 psError(PS_ERR_UNKNOWN, false, "database error"); 820 } 821 psError(PS_ERR_UNKNOWN, false, "database error"); 822 823 return false; 824 } 825 } 905 826 906 827 … … 962 883 } 963 884 if (strcmp (stage,"staticsky") == 0) { 964 query = pxDataGet("addtool_find_processedexp_staticsky.sql");965 }966 if (strcmp (stage,"staticsky_multi") == 0) {967 885 query = pxDataGet("addtool_find_processedexp_staticsky_multi.sql"); 968 886 } … … 1049 967 PXOPT_COPY_S64(config->args, where, "-add_id", "addRun.add_id", "=="); 1050 968 PXOPT_COPY_S64(config->args, where, "-stage_id", "addRun.stage_id", "=="); 1051 PXOPT_LOOKUP_STR(stage, config->args, "-stage", false, false);969 PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false); 1052 970 pxcamGetSearchArgs (config, where); 1053 971 pxAddLabelSearchArgs (config, where, "-label", "addRun.label", "=="); … … 1075 993 query = pxDataGet("addtool_revertprocessedexp_stack.sql"); 1076 994 } 1077 if (strcmp(stage, "staticsky") == 0) { 1078 query = pxDataGet("addtool_revertprocessedexp_staticsky.sql"); 1079 } 1080 if (strcmp(stage, "staticsky_multi") == 0) { 995 if (strcmp(stage, "staticsky") == 0) { 1081 996 query = pxDataGet("addtool_revertprocessedexp_staticsky_multi.sql"); 1082 997 } … … 1221 1136 1222 1137 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", true, false); 1223 PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", true, false); 1224 1225 //optional 1138 //optional 1226 1139 PXOPT_LOOKUP_STR(minidvodb_name, config->args, "-set_minidvodb_name", false, false); 1227 1140 PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false); … … 1238 1151 if (minidvodb_path) { 1239 1152 minidvodbpath = minidvodb_path; 1153 } else { 1154 psError(PS_ERR_UNKNOWN, false, "require minidvodb_path"); 1155 return false; 1240 1156 } 1241 1157 … … 1245 1161 minidvodb_group, 1246 1162 minidvodbpath, 1247 mergedvodb_path, 1248 "new", 1163 "new", 1249 1164 0 1250 1165 )) { … … 1268 1183 psStringAppend(&minidvodb_name, "%s.%" PRIu64,minidvodb_group,minidvodb_id); 1269 1184 } 1270 1271 if (!minidvodb_path) {1272 psStringAppend(&minidvodb_path,"%s/%s",mergedvodb_path,minidvodb_name);1273 }1274 1275 1185 if (minidvodb_path) { 1276 1186 psStringAppend(&minidvodb_path,"/%s",minidvodb_name); … … 1304 1214 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 1305 1215 PXOPT_COPY_STR(config->args, where, "-minidvodb_path", "minidvodb_path", "=="); 1306 PXOPT_COPY_STR(config->args, where, "-mergedvodb_path", "mergedvodb_path", "==");1307 1216 PXOPT_COPY_STR(config->args, where, "-minidvodb_group", "minidvodb_group", "=="); 1308 1217 … … 1310 1219 PXOPT_LOOKUP_STR(minidvodb_path, config->args, "-set_minidvodb_path", false, false); 1311 1220 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1312 PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-set_mergedvodb_path", false, false);1313 1221 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-set_minidvodb_group", false, false); 1314 1222 … … 1345 1253 } 1346 1254 1347 if (mergedvodb_path) {1348 if (cnt) {1349 psStringAppend(&query, "%s", comma);1350 }1351 psStringAppend(&query, " mergedvodb_path = '%s'", mergedvodb_path);1352 cnt++;1353 }1354 1355 1255 if (minidvodb_group) { 1356 1256 if (cnt) { … … 1396 1296 } 1397 1297 1398 psString firstquery = psStringCopy("SELECT * from minidvodbRun where state = 'new' and minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL");1298 psString firstquery = psStringCopy("SELECT * from minidvodbRun where state = 'new' and minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL"); 1399 1299 1400 1300 psString firstwhereClause = psDBGenerateWhereConditionSQL(where, NULL); … … 1444 1344 1445 1345 //now flip new -> active 1446 psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' AND minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL and mergedvodb_path IS NOT NULL");1346 psString query2 = psStringCopy("UPDATE minidvodbRun SET state = 'active' WHERE state = 'new' AND minidvodb_name is NOT NULL and minidvodb_group IS NOT NULL and minidvodb_path IS NOT NULL "); 1447 1347 psStringAppend(&query2, " AND minidvodb_group = '%s' limit 1;", minidvodb_group); 1448 1348 if (!p_psDBRunQuery(config->dbh, query2)) { … … 1480 1380 PXOPT_COPY_STR(config->args, where, "-minidvodb_name", "minidvodbRun.minidvodb_name", "=="); 1481 1381 PXOPT_COPY_STR(config->args, where, "-state", "minidvodbRun.state", "=="); 1482 1483 1382 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", false, false); 1383 1484 1384 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1485 1385 PXOPT_LOOKUP_BOOL(all_addrun_states, config->args, "-all_addrun_states", false); … … 1493 1393 } 1494 1394 1495 psString query = pxDataGet("addtool_checkminidvodbaddrun.sql"); 1496 1497 if (!query) { 1395 if (!minidvodb_group) { 1396 psError(PXTOOLS_ERR_CONFIG, false, "minidvodb_group required"); 1397 return false; 1398 } 1399 1400 1401 psString bare_query = pxDataGet("addtool_checkminidvodbaddrun.sql"); 1402 1403 if (!bare_query) { 1498 1404 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1499 1405 return false; 1500 1406 } 1501 1407 1502 1408 psString where_string = NULL; 1503 1409 if (psListLength(where->list)) { 1504 1410 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1505 psStringAppend(& query, " WHERE %s", whereClause);1411 psStringAppend(&where_string, " WHERE %s", whereClause); 1506 1412 psFree(whereClause); 1507 } 1508 1413 //search params are defined above 1414 } 1415 1416 psString query = NULL; 1417 psStringAppend(&query, bare_query, minidvodb_group); 1418 psStringAppend(&query, where_string); 1419 1420 1421 1422 1423 1509 1424 if (!all_addrun_states) { 1510 1425 psStringAppend(&query, " AND (cnt2 = cnt) "); … … 1519 1434 1520 1435 if (!p_psDBRunQuery(config->dbh, query)) { 1521 psError(PS_ERR_UNKNOWN, false, "database error ");1436 psError(PS_ERR_UNKNOWN, false, "database error,\n\n%s", query); 1522 1437 psFree(query); 1523 1438 return false; … … 1621 1536 // required 1622 1537 PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false); 1623 PXOPT_LOOKUP_STR(mergedvodb_path, config->args, "-mergedvodb_path", true, false);1624 1538 PXOPT_LOOKUP_STR(minidvodb_group, config->args, "-minidvodb_group", true, false); 1625 1539 1626 1540 // optional 1627 PXOPT_LOOKUP_U64(merge_order, config->args, "-merge_order", false, false);1628 1541 PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-dtime_relphot", false, false); 1629 1542 PXOPT_LOOKUP_F32(dtime_resort, config->args, "-dtime_resort", false, false); 1630 PXOPT_LOOKUP_F32(dtime_merge, config->args, "-dtime_merge", false, false);1631 PXOPT_LOOKUP_F32(dtime_verify, config->args, "-dtime_verify", false, false);1632 1543 PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false); 1633 1544 … … 1680 1591 minidvodbProcessedRow *row = minidvodbProcessedRowAlloc( 1681 1592 pendingRow->minidvodb_id, 1682 merge_order,1683 1593 dtime_resort, 1684 1594 dtime_relphot, 1685 dtime_verify,1686 dtime_merge,1687 1595 dtime_script, 1688 1596 epoch, 1689 mergedvodb_path,1690 1597 fault 1691 1598 ); … … 1702 1609 } 1703 1610 1704 1705 1706 1707 //this finds the # of merged things (for the merge order)1708 psString query3 = NULL;1709 psStringAppend(&query3, "select count(*) from minidvodbRun join minidvodbProcessed using (minidvodb_id) where state = 'merged' and minidvodb_group = '%s';", minidvodb_group);1710 1711 if (!p_psDBRunQuery(config->dbh, query3)) {1712 // rollback1713 if (!psDBRollback(config->dbh)) {1714 psError(PS_ERR_UNKNOWN, false, "database error");1715 }1716 psError(PS_ERR_UNKNOWN, false, "database error");1717 psFree(query3);1718 return false;1719 }1720 psArray *output2 = p_psDBFetchResult(config->dbh);1721 if (!output2) {1722 psError(PS_ERR_UNKNOWN, false, "database error");1723 return false;1724 }1725 if (!psArrayLength(output2)) {1726 psTrace("addtool", PS_LOG_INFO, "no rows found");1727 psFree(output);1728 return true;1729 }1730 bool status;1731 psS64 m_order = psMetadataLookupS64(&status, output2->data[0], "count(*)");1732 if (!status) {1733 1734 psAbort("failed to lookup value for count column");1735 return false;1736 }1737 psString final = NULL;1738 psStringAppend(&final, "%" PRIu64, m_order);1739 //return false;1740 psFree(query3);1741 psFree(output2);1742 1743 1744 1745 //update the merge_order1746 1747 psString query4 = NULL;1748 psStringAppend(&query4, "update minidvodbProcessed set merge_order = %"PRIu64,m_order);1749 psStringAppend(&query4," where minidvodb_id = %" PRIu64, minidvodb_id);1750 //printf("%s", query4);1751 if (!p_psDBRunQuery(config->dbh, query4)) {1752 // rollback1753 if (!psDBRollback(config->dbh)) {1754 psError(PS_ERR_UNKNOWN, false, "database error");1755 }1756 psError(PS_ERR_UNKNOWN, false, "database error");1757 psFree(query4);1758 return false;1759 }1760 //1761 psFree(query4);1762 1763 1764 1765 // since there is only one exp per 'new' set mindvodbRun.state = 'merged'1766 1767 1611 psString query2 = NULL ; 1768 1612 psStringAppend(&query2, "UPDATE minidvodbRun SET state = 'merged' WHERE minidvodb_id = %'" PRIu64, row->minidvodb_id); … … 1777 1621 return false; 1778 1622 } 1779 1780 1781 1782 1783 1784 1785 1786 1787 1623 psFree(row); 1788 1624 psFree(pendingRow); … … 1797 1633 return false; 1798 1634 } 1799 1800 1801 //print the merge_order (why not!)1802 printf("%s", final);1803 psFree(final);1804 1805 1635 return true; 1806 1636 } … … 1961 1791 1962 1792 PXOPT_LOOKUP_U64(minidvodb_id, config->args, "-minidvodb_id", true, false); 1963 PXOPT_LOOKUP_U64(merge_order, config->args, "-set_merge_order", false, false);1964 1793 PXOPT_LOOKUP_S16(fault, config->args, "-set_fault", false, false); 1965 1794 PXOPT_LOOKUP_F32(dtime_relphot, config->args, "-set_dtime_relphot", false, false); 1966 1795 PXOPT_LOOKUP_F32(dtime_resort, config->args, "-set_dtime_resort", false, false); 1967 PXOPT_LOOKUP_F32(dtime_merge, config->args, "-set_dtime_merge", false, false);1968 PXOPT_LOOKUP_F32(dtime_verify, config->args, "-set_dtime_verify", false, false);1969 1796 PXOPT_LOOKUP_F32(dtime_script, config->args, "-set_dtime_script", false, false); 1970 1797 PXOPT_COPY_S64(config->args, where, "-minidvodb_id", "minidvodbProcessed.minidvodb_id", "=="); … … 1986 1813 } 1987 1814 1988 if (merge_order) {1989 if (cnt) {1990 psStringAppend(&query, "%s", comma);1991 }1992 1993 psStringAppend(&query, " merge_order = %" PRId64, merge_order);1994 cnt++;1995 }1996 1997 1815 if (dtime_relphot) { 1998 1816 if (cnt) { … … 2011 1829 } 2012 1830 2013 if (dtime_merge) { 2014 if (cnt) { 2015 psStringAppend(&query, "%s", comma); 2016 } 2017 psStringAppend(&query, " dtime_merge = %f", dtime_merge); 2018 cnt++; 2019 } 2020 if (dtime_verify) { 2021 if (cnt) { 2022 psStringAppend(&query, "%s", comma); 2023 } 2024 psStringAppend(&query, " dtime_verify = %f", dtime_verify); 2025 cnt++; 2026 } 2027 if (dtime_script) { 1831 if (dtime_script) { 2028 1832 if (cnt) { 2029 1833 psStringAppend(&query, "%s", comma);
Note:
See TracChangeset
for help on using the changeset viewer.
