Changeset 18641 for branches/eam_branch_20080719/ippTools/src/dettool.c
- Timestamp:
- Jul 21, 2008, 11:12:12 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/ippTools/src/dettool.c
r18627 r18641 28 28 static bool inputMode(pxConfig *config); 29 29 static bool rawMode(pxConfig *config); 30 // processedimfile 31 static bool toprocessedimfileMode(pxConfig *config); 32 static bool addprocessedimfileMode(pxConfig *config); 33 static bool processedimfileMode(pxConfig *config); 34 static bool revertprocessedimfileMode(pxConfig *config); 35 // processedexp 36 static bool toprocessedexpMode(pxConfig *config); 37 static bool addprocessedexpMode(pxConfig *config); 38 static bool processedexpMode(pxConfig *config); 39 static bool revertprocessedexpMode(pxConfig *config); 40 // stackedimfile 41 static bool tostackedMode(pxConfig *config); 42 static bool addstackedMode(pxConfig *config); 43 static bool stackedMode(pxConfig *config); 44 static bool revertstackedMode(pxConfig *config); 45 // normalizedstat 46 static bool tonormalizedstatMode(pxConfig *config); 47 static bool addnormalizedstatMode(pxConfig *config); 48 static bool normalizedstatMode(pxConfig *config); 49 static bool revertnormalizedstatMode(pxConfig *config); 50 // normalizedimfile 51 static bool tonormalizeMode(pxConfig *config); 52 static bool addnormalizedimfileMode(pxConfig *config); 53 static bool normalizedimfileMode(pxConfig *config); 54 static bool revertnormalizedimfileMode(pxConfig *config); 55 // normalizedexp 56 static bool tonormalizedexpMode(pxConfig *config); 57 static bool addnormalizedexpMode(pxConfig *config); 58 static bool normalizedexpMode(pxConfig *config); 59 static bool revertnormalizedexpMode(pxConfig *config); 60 // residimfile 61 static bool toresidimfileMode(pxConfig *config); 62 static bool addresidimfileMode(pxConfig *config); 63 static bool residimfileMode(pxConfig *config); 64 static bool revertresidimfileMode(pxConfig *config); 65 // residexp 66 static bool toresidexpMode(pxConfig *config); 67 static bool addresidexpMode(pxConfig *config); 68 static bool residexpMode(pxConfig *config); 69 static bool revertresidexpMode(pxConfig *config); 70 static bool updateresidexpMode(pxConfig *config); 71 // detrunsummary 72 static bool todetrunsummaryMode(pxConfig *config); 73 static bool adddetrunsummaryMode(pxConfig *config); 74 static bool detrunsummaryMode(pxConfig *config); 75 static bool revertdetrunsummaryMode(pxConfig *config); 76 static bool updatedetrunsummaryMode(pxConfig *config); 30 77 31 // run 78 32 static bool updatedetrunMode(pxConfig *config); … … 81 35 static bool register_detrendMode(pxConfig *config); 82 36 83 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row);84 37 //static psArray *validDetInputClassIds(pxConfig *config, const char *det_id); 85 38 //static psArray *searchInputImfiles(pxConfig *config, const char *det_id); 86 39 static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS64 det_id, psS32 iteration); 87 static psArray *searchRawImfiles(pxConfig *config);88 static bool startNewIteration(pxConfig *config, psS64 det_id);89 40 static psS32 incrementIteration(pxConfig *config, psS64 det_id); 90 static bool setDetRunState(pxConfig *config, psS64 det_id, const char *state);91 41 static bool isValidMode(pxConfig *config, const char *mode); 92 42 … … 1251 1201 } 1252 1202 1253 1254 1255 1256 /* The SQL returns a list of detrend runs (with detrend id, iteration and detrend type) which1257 * have completed all residexps.1258 */1259 1260 static bool todetrunsummaryMode(pxConfig *config)1261 {1262 PS_ASSERT_PTR_NON_NULL(config, false);1263 1264 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);1265 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);1266 1267 psString query = pxDataGet("dettool_todetrunsummary.sql");1268 if (!query) {1269 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");1270 return false;1271 }1272 1273 // treat limit == 0 as "no limit"1274 if (limit) {1275 psString limitString = psDBGenerateLimitSQL(limit);1276 psStringAppend(&query, " %s", limitString);1277 psFree(limitString);1278 }1279 1280 if (!p_psDBRunQuery(config->dbh, query)) {1281 psError(PS_ERR_UNKNOWN, false, "database error");1282 psFree(query);1283 return false;1284 }1285 psFree(query);1286 1287 psArray *output = p_psDBFetchResult(config->dbh);1288 if (!output) {1289 psError(PS_ERR_UNKNOWN, false, "database error");1290 return false;1291 }1292 if (!psArrayLength(output)) {1293 psTrace("dettool", PS_LOG_INFO, "no rows found");1294 psFree(output);1295 return true;1296 }1297 1298 // negative simple so the default is true1299 if (!ippdbPrintMetadatas(stdout, output, "detRejectExp", !simple)) {1300 psError(PS_ERR_UNKNOWN, false, "failed to print array");1301 psFree(output);1302 return false;1303 }1304 1305 psFree(output);1306 1307 return true;1308 }1309 1310 // this function is used to generate the detrunSummary entries used below1311 // XXX why is this a separate function? roll it back into adddetrunsummary?1312 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row)1313 {1314 PS_ASSERT_PTR_NON_NULL(config, false);1315 1316 bool status = false;1317 // from row1318 psS64 det_id = psMetadataLookupS64(&status, row, "det_id");1319 if (!status) {1320 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");1321 return false;1322 }1323 psS32 iteration = psMetadataLookupS32(&status, row, "iteration");1324 if (!status) {1325 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration");1326 return false;1327 }1328 1329 // optional1330 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);1331 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);1332 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false);1333 1334 // default values1335 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);1336 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);1337 1338 return detRunSummaryRowAlloc(1339 det_id,1340 iteration,1341 bg,1342 bg_stdev,1343 bg_mean_stdev,1344 accept,1345 code1346 );1347 }1348 1349 static bool adddetrunsummaryMode(pxConfig *config)1350 {1351 PS_ASSERT_PTR_NON_NULL(config, false);1352 1353 // build a query to search by det_id, iteration, exp_id1354 psMetadata *where = psMetadataAlloc();1355 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");1356 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");1357 1358 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required1359 PXOPT_LOOKUP_BOOL(again, config->args, "-again", false);1360 1361 // The values supplied as arguments on the command (eg, -bg) are parsed1362 // by mdToDetRunSummary below.1363 // XXX why is there ever more than one?1364 1365 psString query = pxDataGet("dettool_find_completed_runs.sql");1366 if (!query) {1367 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");1368 return false;1369 }1370 1371 if (psListLength(where->list)) {1372 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);1373 psStringAppend(&query, " WHERE %s", whereClause);1374 psFree(whereClause);1375 }1376 psFree(where);1377 1378 if (!p_psDBRunQuery(config->dbh, query)) {1379 psError(PS_ERR_UNKNOWN, false, "database error");1380 psFree(query);1381 return false;1382 }1383 psFree(query);1384 1385 psArray *output = p_psDBFetchResult(config->dbh);1386 if (!output) {1387 psError(PS_ERR_UNKNOWN, false, "database error");1388 return false;1389 }1390 if (!psArrayLength(output)) {1391 psTrace("dettool", PS_LOG_INFO, "no rows found");1392 psFree(output);1393 return true;1394 }1395 1396 // start a transaction so it's all rows or nothing1397 if (!psDBTransaction(config->dbh)) {1398 psError(PS_ERR_UNKNOWN, false, "database error");1399 psFree(output);1400 return false;1401 }1402 1403 // XXX why is there ever more than one result here?1404 for (long i = 0; i < psArrayLength(output); i++) {1405 psMetadata *row = output->data[i];1406 // convert metadata into a detResidExp object1407 detRunSummaryRow *runSummary = mdToDetRunSummary(config, row);1408 if (!runSummary) {1409 if (!psDBRollback(config->dbh)) {1410 psError(PS_ERR_UNKNOWN, false, "database error");1411 }1412 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata to detResidExp");1413 psFree(output);1414 return false;1415 }1416 // insert detResidExp object into the database1417 if (!detRunSummaryInsertObject(config->dbh, runSummary)) {1418 if (!psDBRollback(config->dbh)) {1419 psError(PS_ERR_UNKNOWN, false, "database error");1420 }1421 psError(PS_ERR_UNKNOWN, false, "database error");1422 psFree(runSummary);1423 psFree(output);1424 return false;1425 }1426 psFree(runSummary);1427 }1428 1429 psFree(output);1430 1431 // XXX this logic does not deal with the case of -code being set1432 // XXX it should be an error for -again and -code to both be set1433 if (again) {1434 if (!startNewIteration(config, (psS64)atoll(det_id))) {1435 if (!psDBRollback(config->dbh)) {1436 psError(PS_ERR_UNKNOWN, false, "database error");1437 }1438 psError(PS_ERR_UNKNOWN, false, "failed to start new iteration");1439 return false;1440 }1441 } else {1442 // set detRun.state to stop1443 if (!setDetRunState(config, (psS64)atoll(det_id), "stop")) {1444 if (!psDBRollback(config->dbh)) {1445 psError(PS_ERR_UNKNOWN, false, "database error");1446 }1447 psError(PS_ERR_UNKNOWN, false, "failed to set detRun.state");1448 return false;1449 }1450 }1451 1452 if (!psDBCommit(config->dbh)) {1453 psError(PS_ERR_UNKNOWN, false, "database error");1454 return false;1455 }1456 return true;1457 }1458 1459 static bool detrunsummaryMode(pxConfig *config)1460 {1461 PS_ASSERT_PTR_NON_NULL(config, false);1462 1463 psMetadata *where = psMetadataAlloc();1464 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");1465 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");1466 1467 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);1468 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);1469 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);1470 1471 psString query = pxDataGet("dettool_detrunsummary.sql");1472 if (!query) {1473 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");1474 psFree(where);1475 return false;1476 }1477 1478 if (psListLength(where->list)) {1479 psString whereClause = psDBGenerateWhereConditionSQL(where, "NULL");1480 psStringAppend(&query, " AND %s", whereClause);1481 psFree(whereClause);1482 }1483 psFree(where);1484 1485 if (faulted) {1486 // list only faulted rows1487 psStringAppend(&query, " %s", "AND detRunSummary.fault != 0");1488 } else {1489 // don't list faulted rows1490 psStringAppend(&query, " %s", "AND detRunSummary.fault = 0");1491 }1492 1493 // treat limit == 0 as "no limit"1494 if (limit) {1495 psString limitString = psDBGenerateLimitSQL(limit);1496 psStringAppend(&query, " %s", limitString);1497 psFree(limitString);1498 }1499 1500 if (!p_psDBRunQuery(config->dbh, query)) {1501 psError(PS_ERR_UNKNOWN, false, "database error");1502 psFree(query);1503 return false;1504 }1505 psFree(query);1506 1507 psArray *output = p_psDBFetchResult(config->dbh);1508 if (!output) {1509 psError(PS_ERR_UNKNOWN, false, "database error");1510 return false;1511 }1512 if (!psArrayLength(output)) {1513 psTrace("dettool", PS_LOG_INFO, "no rows found");1514 psFree(output);1515 return true;1516 }1517 1518 // negative simple so the default is true1519 if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) {1520 psError(PS_ERR_UNKNOWN, false, "failed to print array");1521 psFree(output);1522 return false;1523 }1524 1525 psFree(output);1526 1527 return true;1528 }1529 1530 1531 static bool revertdetrunsummaryMode(pxConfig *config)1532 {1533 PS_ASSERT_PTR_NON_NULL(config, false);1534 1535 psMetadata *where = psMetadataAlloc();1536 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");1537 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");1538 PXOPT_COPY_STR(config->args, where, "-code", "fault", "==");1539 1540 psString query = pxDataGet("dettool_revertdetrunsummary.sql");1541 if (!query) {1542 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");1543 return false;1544 }1545 1546 if (psListLength(where->list)) {1547 psString whereClause = psDBGenerateWhereConditionSQL(where, "detRunSummary");1548 psStringAppend(&query, " AND %s", whereClause);1549 psFree(whereClause);1550 }1551 psFree(where);1552 1553 if (!p_psDBRunQuery(config->dbh, query)) {1554 psError(PS_ERR_UNKNOWN, false, "database error");1555 psFree(query);1556 return false;1557 }1558 psFree(query);1559 1560 if (psDBAffectedRows(config->dbh) < 1) {1561 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");1562 return false;1563 }1564 1565 return true;1566 }1567 1568 1569 static bool updatedetrunsummaryMode(pxConfig *config)1570 {1571 PS_ASSERT_PTR_NON_NULL(config, false);1572 1573 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required1574 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);1575 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false);1576 1577 if (accept && reject) {1578 psError(PS_ERR_UNKNOWN, true, "-accept and -reject are exclusive");1579 return false;1580 }1581 1582 if (!(accept || reject)) {1583 psError(PS_ERR_UNKNOWN, true, "either -accept or -reject is required");1584 return false;1585 }1586 1587 char *query = "UPDATE detRunSummary SET accept = %d WHERE det_id = %"PRId64;1588 if (!p_psDBRunQuery(config->dbh, query, accept, (psS64)atoll(det_id))) {1589 psError(PS_ERR_UNKNOWN, false, "database error");1590 return false;1591 }1592 1593 return true;1594 }1595 1596 1597 1203 static bool updatedetrunMode(pxConfig *config) 1598 1204 { … … 1629 1235 1630 1236 // used by updatedetrunMode 1631 staticbool startNewIteration(pxConfig *config, psS64 det_id)1237 bool startNewIteration(pxConfig *config, psS64 det_id) 1632 1238 { 1633 1239 PS_ASSERT_PTR_NON_NULL(config, false); … … 2077 1683 } 2078 1684 2079 staticbool setDetRunState(pxConfig *config, psS64 det_id, const char *state)1685 bool setDetRunState(pxConfig *config, psS64 det_id, const char *state) 2080 1686 { 2081 1687 PS_ASSERT_PTR_NON_NULL(config, false);
Note:
See TracChangeset
for help on using the changeset viewer.
