Changeset 25870 for branches/eam_branches/20090820/ippTools/src/warptool.c
- Timestamp:
- Oct 18, 2009, 10:23:28 AM (17 years ago)
- Location:
- branches/eam_branches/20090820
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippTools/src/warptool.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20090820
-
branches/eam_branches/20090820/ippTools/src/warptool.c
r25766 r25870 58 58 static bool exportrunMode(pxConfig *config); 59 59 static bool importrunMode(pxConfig *config); 60 static bool runstateMode(pxConfig *config); 60 61 61 62 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile); … … 108 109 MODECASE(WARPTOOL_MODE_EXPORTRUN, exportrunMode); 109 110 MODECASE(WARPTOOL_MODE_IMPORTRUN, importrunMode); 111 MODECASE(WARPTOOL_MODE_RUNSTATE, runstateMode); 110 112 111 113 default: … … 139 141 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required 140 142 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 143 PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", false, false); 144 PXOPT_LOOKUP_STR(dist_group, config->args, "-dist_group", false, false); 145 PXOPT_LOOKUP_STR(note, config->args, "-note", false, false); 141 146 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 142 147 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); // required (no default TESS) … … 160 165 "dirty", // workdir_state 161 166 label, 167 data_group ? data_group : label, 168 dist_group, 162 169 dvodb, 163 170 tess_id, … … 165 172 end_stage, 166 173 registered, 167 0 // magicked 174 0, // magicked 175 note 168 176 ); 169 177 if (!warpRun) { … … 251 259 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false); 252 260 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 261 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 262 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 253 263 PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false); 254 264 PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false); 255 265 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 256 266 PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false); 267 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 257 268 258 269 PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false); … … 340 351 workdir ? workdir : row->workdir, 341 352 label ? label : row->label, 353 data_group ? data_group: row->data_group, 354 dist_group ? dist_group: row->dist_group, 342 355 dvodb ? dvodb : row->dvodb, 343 356 tess_id ? tess_id : row->tess_id, 344 357 reduction ? reduction : row->reduction, 345 end_stage ? end_stage : row->end_stage)) 358 end_stage ? end_stage : row->end_stage, 359 note)) 346 360 { 347 361 psError(PS_ERR_UNKNOWN, false, "failed to trying to queue fake_id: %" PRId64, row->fake_id); … … 371 385 PXOPT_COPY_STR(config->args, where, "-label", "warpRun.label", "=="); 372 386 PXOPT_COPY_STR(config->args, where, "-state", "warpRun.state", "=="); 373 374 if (!psListLength(where->list) 375 && !psMetadataLookupBool(NULL, config->args, "-all")) { 387 PXOPT_COPY_STR(config->args, where, "-data_group","warpRun.data_group", "=="); 388 PXOPT_COPY_STR(config->args, where, "-dist_group","warpRun.dist_group", "=="); 389 390 if (!psListLength(where->list)) { 376 391 psFree(where); 377 where = NULL;378 392 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 379 393 return false; 380 394 } 381 382 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 383 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 384 385 if ((!state) && (!label)) { 386 psError(PXTOOLS_ERR_DATA, false, "parameters (-state or -label) are required"); 387 psFree(where); 388 return false; 389 } 390 391 if (state) { 392 // set warpRun.state to state 393 if (!pxwarpRunSetStateByQuery(config, where, state)) { 394 psFree(where); 395 return false; 396 } 397 } 398 399 if (label) { 400 // set chipRun.label to label 401 if (!pxwarpRunSetLabelByQuery(config, where, label)) { 402 psFree(where); 403 return false; 404 } 405 } 406 395 396 psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id)"); 397 398 // pxUpdateRun gets parameters from config->args and updates 399 bool result = pxUpdateRun(config, where, &query, "warpRun", true); 400 401 psFree(query); 407 402 psFree(where); 408 403 409 return true; 410 } 411 404 return result; 405 } 412 406 413 407 static bool expMode(pxConfig *config) … … 1204 1198 pxAddLabelSearchArgs (config, where, "-label", "warpRun.label", "LIKE"); 1205 1199 1206 PXOPT_LOOKUP_U64(magicked, config->args, "-magicked", false, false);1207 PXOPT_LOOKUP_BOOL(destreaked, config->args, "-destreaked", false);1208 PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);1209 1210 1200 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1211 1201 … … 1220 1210 } 1221 1211 1212 // generate where strings for arguments that require extra processing 1213 // beyond PXOPT_COPY* 1214 psString where2 = NULL; 1215 if (!pxmagicAddWhere(config, &where2, "warpSkyfile")) { 1216 psError(PXTOOLS_ERR_DATA, false, "pxMagicAddWhere failed"); 1217 return false; 1218 } 1219 if (!pxspaceAddWhere(config, &where2, "rawExp")) { 1220 psError(PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed"); 1221 return false; 1222 } 1223 1222 1224 if (psListLength(where->list)) { 1223 1225 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1224 1226 psStringAppend(&query, " AND %s", whereClause); 1225 1227 psFree(whereClause); 1226 } else if (!all ) {1228 } else if (!all && !where2) { 1227 1229 psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required"); 1228 1230 return false; … … 1230 1232 psFree(where); 1231 1233 1232 if (not_destreaked) { 1233 if (destreaked) { 1234 psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense"); 1235 return false; 1236 } 1237 if (magicked) { 1238 psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense"); 1239 return false; 1240 } 1241 psStringAppend(&query, " AND warpSkyfile.magicked = 0"); 1242 } 1243 if (destreaked) { 1244 psStringAppend(&query, " AND warpSkyfile.magicked != 0"); 1234 if (where2) { 1235 psStringAppend(&query, " %s", where2); 1245 1236 } 1246 1237 … … 1712 1703 PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false); 1713 1704 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1714 1715 psString query = pxDataGet("warptool_updateskyfile.sql"); 1716 1717 if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) { 1718 psError(PS_ERR_UNKNOWN, false, "database error"); 1719 return false; 1720 } 1721 psFree(query); 1705 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 1706 1707 if (!state) { 1708 psString query = pxDataGet("warptool_updateskyfile.sql"); 1709 1710 if (!p_psDBRunQueryF(config->dbh, query, fault, warp_id, skycell_id)) { 1711 psError(PS_ERR_UNKNOWN, false, "database error"); 1712 return false; 1713 } 1714 psFree(query); 1715 } 1716 else { 1717 if (strcmp(state,"error_cleaned") == 0) { 1718 change_skyfile_data_state(config,"error_cleaned","goto_cleaned"); 1719 } 1720 else if (strcmp(state, "error_scrubbed") == 0) { 1721 change_skyfile_data_state(config,"error_scrubbed","goto_scrubbed"); 1722 } 1723 else if (strcmp(state, "error_purged") == 0) { 1724 change_skyfile_data_state(config,"error_purged","goto_purged"); 1725 } 1726 else { 1727 psError(PS_ERR_UNKNOWN, false, "unhandled state given"); 1728 return(false); 1729 } 1730 } 1722 1731 1723 1732 return true; … … 1744 1753 } 1745 1754 1755 if (!pxExportVersion(config, f)) { 1756 psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file"); 1757 return false; 1758 } 1746 1759 psMetadata *where = psMetadataAlloc(); 1747 1760 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); … … 1836 1849 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false); 1837 1850 1838 fprintf (stdout, "---- input ----\n"); 1851 #ifdef notdef 1852 fprintf (stderr, "---- input ----\n"); 1839 1853 psMetadataPrint (stderr, input, 1); 1854 #endif 1855 1856 if (!pxCheckImportVersion(config, input)) { 1857 psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed"); 1858 return false; 1859 } 1840 1860 1841 1861 psMetadataItem *item = psMetadataLookup (input, "warpRun"); … … 1900 1920 return true; 1901 1921 } 1922 1923 static bool runstateMode(pxConfig *config) 1924 { 1925 PS_ASSERT_PTR_NON_NULL(config, false); 1926 1927 psMetadata *where = psMetadataAlloc(); 1928 PXOPT_COPY_S64(config->args, where, "-warp_id", "warpRun.warp_id", "=="); 1929 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 1930 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 1931 pxAddLabelSearchArgs (config, where, "-label", "warpRun.label", "LIKE"); 1932 1933 // PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1934 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 1935 1936 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1937 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1938 1939 psString query = pxDataGet("warptool_runstate.sql"); 1940 if (!query) { 1941 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1942 return false; 1943 } 1944 1945 if (psListLength(where->list)) { 1946 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1947 psStringAppend(&query, " WHERE %s", whereClause); 1948 psFree(whereClause); 1949 } else { 1950 psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required"); 1951 return false; 1952 } 1953 psFree(where); 1954 1955 // treat limit == 0 as "no limit" 1956 if (limit) { 1957 psString limitString = psDBGenerateLimitSQL(limit); 1958 psStringAppend(&query, " %s", limitString); 1959 psFree(limitString); 1960 } 1961 1962 if (!p_psDBRunQuery(config->dbh, query)) { 1963 psError(PS_ERR_UNKNOWN, false, "database error"); 1964 psFree(query); 1965 return false; 1966 } 1967 psFree(query); 1968 1969 psArray *output = p_psDBFetchResult(config->dbh); 1970 if (!output) { 1971 psErrorCode err = psErrorCodeLast(); 1972 switch (err) { 1973 case PS_ERR_DB_CLIENT: 1974 psError(PXTOOLS_ERR_SYS, false, "database error"); 1975 case PS_ERR_DB_SERVER: 1976 psError(PXTOOLS_ERR_PROG, false, "database error"); 1977 default: 1978 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1979 } 1980 1981 return false; 1982 } 1983 if (!psArrayLength(output)) { 1984 psTrace("warptool", PS_LOG_INFO, "no rows found"); 1985 psFree(output); 1986 return true; 1987 } 1988 1989 if (psArrayLength(output)) { 1990 // negative simple so the default is true 1991 if (!ippdbPrintMetadatas(stdout, output, "warpRunState", !simple)) { 1992 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1993 psFree(output); 1994 return false; 1995 } 1996 } 1997 1998 psFree(output); 1999 2000 return true; 2001 }
Note:
See TracChangeset
for help on using the changeset viewer.
