Changeset 27839 for branches/simmosaic_branches/ippTools/src/magictool.c
- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/magictool.c (modified) (27 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/ippTools/src
- Property svn:ignore
-
old new 1 *.la 2 *.lo 1 3 .deps 2 4 .gdb_history … … 4 6 Makefile 5 7 Makefile.in 8 addtool 9 caltool 10 camtool 11 chiptool 6 12 config.h 7 13 config.h.in 8 stamp-h1 9 *.la 10 *.lo 14 detselect 15 dettool 16 difftool 17 disttool 18 dqstatstool 19 faketool 20 flatcorr 21 guidetool 22 magicdstool 23 magictool 24 pstamptool 25 pubtool 26 pxadmin 27 pxdata.c 28 pxinject 11 29 pxtoolsErrorCodes.c 12 30 pxtoolsErrorCodes.h 13 pxadmin14 pxinject15 pztool16 31 pzgetexp 17 32 pzgetimfiles 33 pztool 34 receivetool 18 35 regtool 19 guidetool 20 chiptool 21 camtool 36 stacktool 37 stamp-h1 22 38 warptool 23 difftool24 stacktool25 faketool26 dettool27 detselect28 pxdata.c29 magictool30 magicdstool31 caltool32 flatcorr33 pstamptool34 disttool35 receivetool36 37 pubtool
-
- Property svn:ignore
-
branches/simmosaic_branches/ippTools/src/magictool.c
r24551 r27839 47 47 static bool revertmaskMode(pxConfig *config); 48 48 static bool maskMode(pxConfig *config); 49 static bool censorrunMode(pxConfig *config); 49 50 50 51 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state); … … 85 86 MODECASE(MAGICTOOL_MODE_REVERTMASK, revertmaskMode); 86 87 MODECASE(MAGICTOOL_MODE_MASK, maskMode); 88 MODECASE(MAGICTOOL_MODE_CENSORRUN, censorrunMode); 87 89 default: 88 90 psAbort("invalid option (this should not happen)"); … … 112 114 // Required 113 115 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false); 116 PXOPT_LOOKUP_STR(label, config->args, "-label", true, false); 114 117 115 118 // Optional 116 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 119 PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", false, false); 120 PXOPT_LOOKUP_STR(note, config->args, "-note", false, false); 117 121 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 118 122 PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false); … … 131 135 psString query = pxDataGet("magictool_definebyquery_select.sql"); 132 136 if (!query) { 133 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");137 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 134 138 return false; 135 139 } … … 147 151 // what if no skycells for the diff run completed? 148 152 149 if (!rerun) { 150 psStringAppend(&queryWhereStr, "\n%s magic_id IS NULL", queryWhereStr ? "AND" : "WHERE"); 153 psStringAppend(&queryWhereStr, "\n%s magic_id IS NULL", queryWhereStr ? "AND" : "WHERE"); 154 psString rerunWhereStr = NULL; 155 if (rerun) { 156 psStringAppend(&rerunWhereStr, "\n WHERE magicRun.label = '%s'", label); 151 157 } 152 158 … … 172 178 queryWhereStr = psStringCopy(""); 173 179 } 174 175 if (!p_psDBRunQueryF(config->dbh, query, diffWhereStr, diffWhereStr, queryWhereStr)) { 180 if (!rerunWhereStr) { 181 rerunWhereStr = psStringCopy(""); 182 } 183 184 if (!p_psDBRunQueryF(config->dbh, query, diffWhereStr, diffWhereStr, rerunWhereStr, queryWhereStr)) { 176 185 psError(PS_ERR_UNKNOWN, false, "database error"); 177 186 psFree(diffWhereStr); 178 187 psFree(queryWhereStr); 188 psFree(rerunWhereStr); 179 189 psFree(query); 180 190 return false; … … 182 192 psFree(diffWhereStr); 183 193 psFree(queryWhereStr); 194 psFree(rerunWhereStr); 184 195 psFree(query); 185 196 } … … 234 245 235 246 // create a new magicRun for this group 236 magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, inverse, "new", workdir, "dirty", label, 237 dvodb, registered, 0); 247 magicRunRow *run = magicRunRowAlloc(0, 248 exp_id, 249 diff_id, 250 inverse, 251 "new", // state 252 workdir, 253 "dirty", // workdir_state 254 label, 255 data_group ? data_group : label, 256 dvodb, 257 registered, 258 0, // fault 259 note); 238 260 if (!run) { 239 261 psAbort("failed to alloc magicRun object"); … … 329 351 "dirty", // workdir_state 330 352 label, 353 NULL, // data_group 331 354 dvodb, 332 355 registered, 333 0 356 0, // fault 357 NULL 334 358 ); 335 359 … … 410 434 psString query = pxDataGet("magictool_inputskyfile.sql"); 411 435 if (!query) { 412 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");436 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 413 437 return false; 414 438 } … … 483 507 psString query = pxDataGet("magictool_totree.sql"); 484 508 if (!query) { 485 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");509 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 486 510 return false; 487 511 } … … 556 580 557 581 if (fault > 0) { 558 char *query = "UPDATE magicRun SET fault = %d , state = 'full'WHERE magic_id = %" PRId64;582 char *query = "UPDATE magicRun SET fault = %d WHERE magic_id = %" PRId64; 559 583 if (!p_psDBRunQueryF(config->dbh, query, fault, magic_id)) { 560 584 psError(PS_ERR_UNKNOWN, false, … … 580 604 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 581 605 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 606 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 582 607 583 608 psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0"); … … 594 619 return false; 595 620 } 621 psS32 numUpdated = psDBAffectedRows(config->dbh); 622 psLogMsg("magictool", PS_LOG_INFO, "Reverted %d magic runs", numUpdated); 623 596 624 return true; 597 625 } … … 617 645 psString query = pxDataGet("magictool_inputs.sql"); 618 646 if (!query) { 619 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");647 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 620 648 return false; 621 649 } … … 787 815 psString query = pxDataGet("magictool_toprocess_inputs.sql"); 788 816 if (!query) { 789 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");817 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 790 818 return false; 791 819 } … … 801 829 // treat limit == 0 as "no limit" 802 830 if (limit) { 803 psString limitString = psDBGenerateLimitSQL(limit); 831 // cut limit in half 832 // hack to prevent pending leaf nodes from blocking branch nodes 833 psString limitString = psDBGenerateLimitSQL((limit + 1) / 2); 804 834 psStringAppend(&query, " %s", limitString); 805 835 psFree(limitString); … … 847 877 848 878 // look for tree nodes that need to be processed 849 // XXX: This gets all nodes from all magicRuns that are in 'new'state 850 // That doens't seem particularly efficient851 query = pxDataGet("magictool_toprocess_ tree.sql");879 880 // first find incomplete magicRuns 881 query = pxDataGet("magictool_toprocess_runs.sql"); 852 882 if (!query) { 853 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 854 return false; 855 } 856 883 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 884 return false; 885 } 886 887 // we limit the query even though it is cheap (only magic_id is selected) 888 889 // XXX: if the first 1000 unfinished magicRuns have no ready nodes 890 // that haven't faulted, later runs won't get returned even though 891 // they have work to do. When we used a limit of 100 we actually ran 892 // into this problem. Since we're using labels a limit of 1000 will 893 // probably be ok. 894 { 895 psString limitString = psDBGenerateLimitSQL( 1000 ); 896 psStringAppend(&query, " %s", limitString); 897 psFree(limitString); 898 } 857 899 858 900 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { … … 865 907 psFree(query); 866 908 867 psArray *magic Tree= p_psDBFetchResult(config->dbh);868 if (!magic Tree) {909 psArray *magicRuns = p_psDBFetchResult(config->dbh); 910 if (!magicRuns) { 869 911 psErrorCode err = psErrorCodeLast(); 870 912 switch (err) { … … 879 921 return false; 880 922 } 881 if (!psArrayLength(magic Tree)) {923 if (!psArrayLength(magicRuns)) { 882 924 psTrace("magictool", PS_LOG_INFO, "no rows found"); 883 psFree(magic Tree);925 psFree(magicRuns); 884 926 return true; 885 927 } 886 928 887 // entries are ordered by magic_id 888 long index = 0; 889 while (index < psArrayLength(magicTree)) { 890 bool status; 929 query = pxDataGet("magictool_toprocess_tree.sql"); 930 if (!query) { 931 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 932 return false; 933 } 934 935 for (psS64 index = 0; index < psArrayLength(magicRuns); index++) { 891 936 if (limit && (psArrayLength(output) >= limit)) { 892 937 break; 893 938 } 894 psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id"); 939 bool status; 940 psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id"); 895 941 if (!status) { 896 942 psAbort("failed to lookup value for magic_id column"); 897 943 } 898 944 899 // find the end of this block 900 long first = index; 901 long last = index; 902 for (long i = index + 1; i < psArrayLength(magicTree); i++) { 903 psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id"); 904 if (!status) { 905 psAbort("failed to lookup value for magic_id column"); 945 whereString = NULL; 946 psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id); 947 if (!p_psDBRunQueryF(config->dbh, query, whereString )) { 948 psError(PS_ERR_UNKNOWN, false, "database error"); 949 psFree(whereString); 950 psFree(query); 951 return false; 952 } 953 psFree(whereString); 954 psArray *magicTree = p_psDBFetchResult(config->dbh); 955 if (!magicTree) { 956 psErrorCode err = psErrorCodeLast(); 957 switch (err) { 958 case PS_ERR_DB_CLIENT: 959 psError(PXTOOLS_ERR_SYS, false, "database error"); 960 case PS_ERR_DB_SERVER: 961 psError(PXTOOLS_ERR_PROG, false, "database error"); 962 default: 963 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 906 964 } 907 if (magic_id != current_magic_id) { 908 break; 909 } 910 last = i; 911 } 912 913 index = last + 1; 914 915 psHash *forest = psHashAlloc(last - first + 1); 965 966 return false; 967 } 968 psS64 length = psArrayLength(magicTree); 969 if (!length) { 970 psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id); 971 psFree(magicTree); 972 continue; 973 } 974 975 psHash *forest = psHashAlloc(length); 916 976 917 977 // convert the array of metadata into a pxTree structure 918 for (long i = first; i <= last; i++) {978 for (long i = 0; i < length; i++) { 919 979 bool status; 920 980 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); … … 941 1001 pxTreeCrawl(root, findReadyNodes, output); 942 1002 psFree(root); 943 944 } 945 psFree(magicTree); 1003 psFree(magicTree); 1004 } 946 1005 947 1006 if (psArrayLength(output)) { … … 1001 1060 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1002 1061 PXOPT_COPY_STR(config->args, where, "-node", "node", "=="); 1003 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");1004 1062 PXOPT_COPY_S16(config->args, where, "-fault", "magicNodeResult.fault", "=="); 1063 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 1005 1064 1006 1065 psString query = pxDataGet("magictool_revertnode.sql"); 1007 1066 if (!query) { 1008 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1067 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1009 1068 return false; 1010 1069 } … … 1027 1086 1028 1087 psS32 numUpdated = psDBAffectedRows(config->dbh); 1029 psLogMsg("magictool", PS_LOG_INFO, " Updated %d magic nodes", numUpdated);1088 psLogMsg("magictool", PS_LOG_INFO, "Reverted %d magic nodes", numUpdated); 1030 1089 1031 1090 return true; … … 1043 1102 psString query = pxDataGet("magictool_tomask.sql"); 1044 1103 if (!query) { 1045 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1104 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1046 1105 return false; 1047 1106 } … … 1131 1190 psString query = pxDataGet("magictool_addmask.sql"); 1132 1191 if (!query) { 1133 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1192 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1134 1193 if (!psDBRollback(config->dbh)) { 1135 1194 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1238 1297 psString query = pxDataGet("magictool_mask.sql"); 1239 1298 if (!query) { 1240 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1299 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1241 1300 return false; 1242 1301 } … … 1367 1426 return true; 1368 1427 } 1428 1429 static bool censorrunMode(pxConfig *config) 1430 { 1431 PS_ASSERT_PTR_NON_NULL(config, false); 1432 1433 psMetadata *where = psMetadataAlloc(); 1434 1435 PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", false, false); 1436 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 1437 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 1438 1439 if (!magic_id) { 1440 if (!exp_id && !label) { 1441 psError(PS_ERR_UNKNOWN, true, "either -magic_id or exp_id and label is required"); 1442 return false; 1443 } 1444 } 1445 1446 // at least one of these required 1447 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1448 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1449 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1450 1451 if (!psListLength(where->list)) { 1452 psError(PS_ERR_UNKNOWN, true, "either -exp_id or -magic_id is required"); 1453 psFree(where); 1454 return false; 1455 } 1456 1457 psString query = psStringCopy("UPDATE magicRun SET state = 'censored'"); 1458 1459 psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun"); 1460 psFree(where); 1461 psStringAppend(&query, " WHERE %s", whereClause); 1462 1463 if (!psDBTransaction(config->dbh)) { 1464 psError(PS_ERR_UNKNOWN, false, "database error"); 1465 return false; 1466 } 1467 1468 if (!p_psDBRunQuery(config->dbh, query)) { 1469 psError(PS_ERR_UNKNOWN, false, "database error"); 1470 psFree(whereClause); 1471 psFree(query); 1472 return false; 1473 } 1474 psFree(query); 1475 1476 psS32 numUpdated = psDBAffectedRows(config->dbh); 1477 if (numUpdated == 0) { 1478 psError(PS_ERR_UNKNOWN, false, "failed to censor magicRun"); 1479 psFree(whereClause); 1480 return false; 1481 } 1482 1483 // Now queue any destreaked files to be re-verted 1484 1485 // note: on failure pxmagicRestoreStage issues the rollback 1486 if (!pxmagicRestoreStage(config, "raw", whereClause, "goto_censored")) { 1487 psFree(whereClause); 1488 return false; 1489 } 1490 if (!pxmagicRestoreStage(config, "chip", whereClause, "goto_censored")) { 1491 psFree(whereClause); 1492 return false; 1493 } 1494 if (!pxmagicRestoreStage(config, "camera", whereClause, "goto_censored")) { 1495 psFree(whereClause); 1496 return false; 1497 } 1498 if (!pxmagicRestoreStage(config, "warp", whereClause, "goto_censored")) { 1499 psFree(whereClause); 1500 return false; 1501 } 1502 if (!pxmagicRestoreStage(config, "diff", whereClause, "goto_censored")) { 1503 psFree(whereClause); 1504 return false; 1505 } 1506 1507 psFree(whereClause); 1508 1509 if (!psDBCommit(config->dbh)) { 1510 psError(PS_ERR_UNKNOWN, false, "database error"); 1511 return false; 1512 } 1513 1514 return true; 1515 }
Note:
See TracChangeset
for help on using the changeset viewer.
