Changeset 18627
- Timestamp:
- Jul 20, 2008, 8:33:43 AM (18 years ago)
- Location:
- branches/eam_branch_20080719/ippTools
- Files:
-
- 5 edited
-
notes.txt (modified) (1 diff)
-
src/camtool.c (modified) (2 diffs)
-
src/dettool.c (modified) (1 diff)
-
src/faketool.c (modified) (2 diffs)
-
src/warptool.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080719/ippTools/notes.txt
r18622 r18627 1 2 2008.07.19 EAM 3 4 * need to add cleanup modes to all stages. here is the minimum list 5 of stages that need the cleanups: 6 7 * chiptool - DONE 8 * camtool 9 * faketool 10 * warptool 11 * difftool 12 * stacktool 13 * magictool 14 * dettool processedimfile 15 * dettool processedexp 16 * dettool stackedimfile 17 * dettool normalizedstat 18 * dettool normalizedimfile 19 * dettool normalizedexp 20 * dettool residimfile 21 * dettool residexp 1 22 2 23 2008.07.11 EAM -
branches/eam_branch_20080719/ippTools/src/camtool.c
r18561 r18627 41 41 static bool maskedMode(pxConfig *config); 42 42 static bool unblockMode(pxConfig *config); 43 static bool pendingcleanuprunMode(pxConfig *config); 44 static bool pendingcleanupexpMode(pxConfig *config); 45 static bool donecleanupMode(pxConfig *config); 43 46 44 47 # define MODECASE(caseName, func) \ … … 914 917 return true; 915 918 } 919 920 static bool pendingcleanuprunMode(pxConfig *config) 921 { 922 PS_ASSERT_PTR_NON_NULL(config, NULL); 923 924 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 925 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 926 927 psMetadata *where = psMetadataAlloc(); 928 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 929 930 psString query = pxDataGet("camtool_pendingcleanuprun.sql"); 931 if (!query) { 932 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 933 return false; 934 } 935 936 if (where && psListLength(where->list)) { 937 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 938 psStringAppend(&query, " AND %s", whereClause); 939 psFree(whereClause); 940 } 941 psFree(where); 942 943 // treat limit == 0 as "no limit" 944 if (limit) { 945 psString limitString = psDBGenerateLimitSQL(limit); 946 psStringAppend(&query, " %s", limitString); 947 psFree(limitString); 948 } 949 950 if (!p_psDBRunQuery(config->dbh, query)) { 951 psError(PS_ERR_UNKNOWN, false, "database error"); 952 psFree(query); 953 return false; 954 } 955 psFree(query); 956 957 psArray *output = p_psDBFetchResult(config->dbh); 958 if (!output) { 959 psError(PS_ERR_UNKNOWN, false, "database error"); 960 return false; 961 } 962 if (!psArrayLength(output)) { 963 psTrace("camtool", PS_LOG_INFO, "no rows found"); 964 psFree(output); 965 return true; 966 } 967 968 // negative simple so the default is true 969 if (!ippdbPrintMetadatas(stdout, output, "camPendingCleanupRun", !simple)) { 970 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 971 psFree(output); 972 return false; 973 } 974 975 psFree(output); 976 977 return true; 978 } 979 980 981 static bool pendingcleanupexpMode(pxConfig *config) 982 { 983 PS_ASSERT_PTR_NON_NULL(config, NULL); 984 985 PXOPT_LOOKUP_S64(cam_id, config->args, "-cam_id", false, false); 986 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 987 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 988 989 psMetadata *where = psMetadataAlloc(); 990 if (chip_id) { 991 PXOPT_COPY_S64(config->args, where, "-cam_id", "cam_id", "=="); 992 } 993 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 994 995 psString query = pxDataGet("camtool_pendingcleanupexp.sql"); 996 if (!query) { 997 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 998 return false; 999 } 1000 1001 if (where && psListLength(where->list)) { 1002 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1003 psStringAppend(&query, " AND %s", whereClause); 1004 psFree(whereClause); 1005 } 1006 psFree(where); 1007 1008 // treat limit == 0 as "no limit" 1009 if (limit) { 1010 psString limitString = psDBGenerateLimitSQL(limit); 1011 psStringAppend(&query, " %s", limitString); 1012 psFree(limitString); 1013 } 1014 1015 if (!p_psDBRunQuery(config->dbh, query)) { 1016 psError(PS_ERR_UNKNOWN, false, "database error"); 1017 psFree(query); 1018 return false; 1019 } 1020 psFree(query); 1021 1022 psArray *output = p_psDBFetchResult(config->dbh); 1023 if (!output) { 1024 psError(PS_ERR_UNKNOWN, false, "database error"); 1025 return false; 1026 } 1027 if (!psArrayLength(output)) { 1028 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 1029 psFree(output); 1030 return true; 1031 } 1032 1033 // negative simple so the default is true 1034 if (!ippdbPrintMetadatas(stdout, output, "camPendingCleanupExp", !simple)) { 1035 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1036 psFree(output); 1037 return false; 1038 } 1039 1040 psFree(output); 1041 1042 return true; 1043 } 1044 1045 1046 static bool donecleanupMode(pxConfig *config) 1047 { 1048 PS_ASSERT_PTR_NON_NULL(config, NULL); 1049 1050 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1051 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1052 1053 psMetadata *where = psMetadataAlloc(); 1054 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1055 1056 psString query = pxDataGet("camtool_donecleanup.sql"); 1057 if (!query) { 1058 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1059 return false; 1060 } 1061 1062 if (where && psListLength(where->list)) { 1063 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1064 psStringAppend(&query, " AND %s", whereClause); 1065 psFree(whereClause); 1066 } 1067 psFree(where); 1068 1069 // treat limit == 0 as "no limit" 1070 if (limit) { 1071 psString limitString = psDBGenerateLimitSQL(limit); 1072 psStringAppend(&query, " %s", limitString); 1073 psFree(limitString); 1074 } 1075 1076 if (!p_psDBRunQuery(config->dbh, query)) { 1077 psError(PS_ERR_UNKNOWN, false, "database error"); 1078 psFree(query); 1079 return false; 1080 } 1081 psFree(query); 1082 1083 psArray *output = p_psDBFetchResult(config->dbh); 1084 if (!output) { 1085 psError(PS_ERR_UNKNOWN, false, "database error"); 1086 return false; 1087 } 1088 if (!psArrayLength(output)) { 1089 psTrace("camtool", PS_LOG_INFO, "no rows found"); 1090 psFree(output); 1091 return true; 1092 } 1093 1094 // negative simple so the default is true 1095 if (!ippdbPrintMetadatas(stdout, output, "camDoneCleanup", !simple)) { 1096 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1097 psFree(output); 1098 return false; 1099 } 1100 1101 psFree(output); 1102 1103 return true; 1104 } -
branches/eam_branch_20080719/ippTools/src/dettool.c
r18561 r18627 1251 1251 } 1252 1252 1253 static bool toprocessedimfileMode(pxConfig *config) 1254 { 1255 PS_ASSERT_PTR_NON_NULL(config, false); 1256 1257 psMetadata *where = psMetadataAlloc(); 1258 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1259 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1260 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 1261 1262 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1263 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1264 1265 psString query = pxDataGet("dettool_toprocessedimfile.sql"); 1266 if (!query) { 1267 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1268 return false; 1269 } 1270 1271 if (psListLength(where->list)) { 1272 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawImfile"); 1273 psStringAppend(&query, " AND %s", whereClause); 1274 psFree(whereClause); 1275 } 1276 psFree (where); 1277 1278 // treat limit == 0 as "no limit" 1279 if (limit) { 1280 psString limitString = psDBGenerateLimitSQL(limit); 1281 psStringAppend(&query, " %s", limitString); 1282 psFree(limitString); 1283 } 1284 1285 if (!p_psDBRunQuery(config->dbh, query)) { 1286 psError(PS_ERR_UNKNOWN, false, "database error"); 1287 psFree(query); 1288 return false; 1289 } 1290 psFree(query); 1291 1292 psArray *output = p_psDBFetchResult(config->dbh); 1293 if (!output) { 1294 psError(PS_ERR_UNKNOWN, false, "database error"); 1295 return false; 1296 } 1297 if (!psArrayLength(output)) { 1298 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1299 psFree(output); 1300 return true; 1301 } 1302 1303 // negative simple so the default is true 1304 if (!ippdbPrintMetadatas(stdout, output, "detPendingProcessedImfile", !simple)) { 1305 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1306 psFree(output); 1307 return false; 1308 } 1309 1310 psFree(output); 1311 1312 return true; 1313 } 1314 1315 static bool addprocessedimfileMode(pxConfig *config) 1316 { 1317 PS_ASSERT_PTR_NON_NULL(config, false); 1318 1319 // det_id, exp_id, class_id, uri, recipe, -bg, -bg_stdev are required 1320 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 1321 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); 1322 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 1323 1324 // default values 1325 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 1326 1327 // Required if code == 0 1328 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); 1329 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 1330 1331 // optional 1332 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 1333 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 1334 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 1335 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 1336 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); 1337 PXOPT_LOOKUP_F64(fringe_2, config->args, "-fringe_2", false, false); 1338 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 1339 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 1340 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 1341 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 1342 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 1343 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 1344 1345 // find the matching rawImfile by exp_id/class_id 1346 psMetadata *where = psMetadataAlloc(); 1347 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1348 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 1349 1350 psArray *rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0); 1351 psFree(where); 1352 1353 if (!rawImfiles) { 1354 psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found "); 1355 return false; 1356 } 1357 1358 // create a new detProcessedImfile object 1359 detProcessedImfileRow *detRow = detProcessedImfileRowAlloc( 1360 (psS64)atoll(det_id), 1361 (psS64)atoll(exp_id), 1362 class_id, 1363 uri, 1364 recipe, 1365 bg, 1366 bg_stdev, 1367 bg_mean_stdev, 1368 fringe_0, 1369 fringe_1, 1370 fringe_2, 1371 user_1, 1372 user_2, 1373 user_3, 1374 user_4, 1375 user_5, 1376 path_base, 1377 code 1378 ); 1379 psFree(rawImfiles); 1380 1381 // insert the new row into the detProcessedImfile table 1382 if (!detProcessedImfileInsertObject(config->dbh, detRow)) { 1383 psError(PS_ERR_UNKNOWN, false, "database error"); 1384 psFree(detRow); 1385 return false; 1386 } 1387 1388 psFree(detRow); 1389 1390 return true; 1391 } 1392 1393 static bool processedimfileMode(pxConfig *config) 1394 { 1395 PS_ASSERT_PTR_NON_NULL(config, false); 1396 1397 char *value = NULL; 1398 1399 PXOPT_LOOKUP_BOOL(included, config->args, "-included", false); 1400 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 1401 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1402 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1403 1404 psMetadata *where = psMetadataAlloc(); 1405 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1406 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1407 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 1408 1409 psString query = pxDataGet("dettool_processedimfile.sql"); 1410 if (!query) { 1411 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1412 psFree(where); 1413 return false; 1414 } 1415 1416 // add the two required restrictions: detRun.state and detRun.mode 1417 // NOTE the above query requires one of the following two WHERE statements 1418 { 1419 bool status; 1420 if ((value = psMetadataLookupStr(&status, config->args, "-select_state"))) { 1421 psStringAppend(&query, " WHERE detRun.state = '%s'", value); 1422 } else { 1423 psStringAppend(&query, " WHERE detRun.state = 'run'"); 1424 } 1425 if ((value = psMetadataLookupStr(&status, config->args, "-select_mode"))) { 1426 psStringAppend(&query, " AND detRun.mode = '%s'", value); 1427 } else { 1428 psStringAppend(&query, " AND detRun.mode = 'master'"); 1429 } 1430 } 1431 1432 if (psListLength(where->list)) { 1433 psString whereClause = psDBGenerateWhereConditionSQL(where, "detProcessedImfile"); 1434 psStringAppend(&query, " AND %s", whereClause); 1435 psFree(whereClause); 1436 } 1437 psFree (where); 1438 1439 // restrict search to included imfiles 1440 if (included) { 1441 psStringAppend(&query, " AND detInputExp.include = 1"); 1442 } 1443 1444 if (faulted) { 1445 // list only faulted rows 1446 psStringAppend(&query, " %s", "AND detProcessedImfile.fault != 0"); 1447 } else { 1448 // don't list faulted rows 1449 psStringAppend(&query, " %s", "AND detProcessedImfile.fault = 0"); 1450 } 1451 1452 // treat limit == 0 as "no limit" 1453 if (limit) { 1454 psString limitString = psDBGenerateLimitSQL(limit); 1455 psStringAppend(&query, " %s", limitString); 1456 psFree(limitString); 1457 } 1458 1459 if (!p_psDBRunQuery(config->dbh, query)) { 1460 psError(PS_ERR_UNKNOWN, false, "database error"); 1461 psFree(query); 1462 return false; 1463 } 1464 psFree(query); 1465 1466 psArray *output = p_psDBFetchResult(config->dbh); 1467 if (!output) { 1468 psError(PS_ERR_UNKNOWN, false, "database error"); 1469 return false; 1470 } 1471 if (!psArrayLength(output)) { 1472 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1473 psFree(output); 1474 return true; 1475 } 1476 1477 // negative simple so the default is true 1478 if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) { 1479 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1480 psFree(output); 1481 return false; 1482 } 1483 1484 psFree(output); 1485 1486 return true; 1487 } 1488 1489 static bool revertprocessedimfileMode(pxConfig *config) 1490 { 1491 PS_ASSERT_PTR_NON_NULL(config, false); 1492 1493 psMetadata *where = psMetadataAlloc(); 1494 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1495 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1496 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 1497 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 1498 1499 psString query = pxDataGet("dettool_revertprocessedimfile.sql"); 1500 if (!query) { 1501 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1502 return false; 1503 } 1504 1505 if (psListLength(where->list)) { 1506 psString whereClause = psDBGenerateWhereConditionSQL(where, "detProcessedImfile"); 1507 psStringAppend(&query, " AND %s", whereClause); 1508 psFree(whereClause); 1509 } 1510 psFree(where); 1511 1512 if (!p_psDBRunQuery(config->dbh, query)) { 1513 psError(PS_ERR_UNKNOWN, false, "database error"); 1514 psFree(query); 1515 return false; 1516 } 1517 psFree(query); 1518 1519 if (psDBAffectedRows(config->dbh) < 1) { 1520 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 1521 return false; 1522 } 1523 1524 return true; 1525 } 1526 1527 static bool toprocessedexpMode(pxConfig *config) 1528 { 1529 PS_ASSERT_PTR_NON_NULL(config, false); 1530 1531 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1532 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1533 1534 psString query = pxDataGet("dettool_toprocessedexp.sql"); 1535 if (!query) { 1536 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1537 return false; 1538 } 1539 1540 // treat limit == 0 as "no limit" 1541 if (limit) { 1542 psString limitString = psDBGenerateLimitSQL(limit); 1543 psStringAppend(&query, " %s", limitString); 1544 psFree(limitString); 1545 } 1546 1547 if (!p_psDBRunQuery(config->dbh, query)) { 1548 psError(PS_ERR_UNKNOWN, false, "database error"); 1549 psFree(query); 1550 return false; 1551 } 1552 psFree(query); 1553 1554 psArray *output = p_psDBFetchResult(config->dbh); 1555 if (!output) { 1556 psError(PS_ERR_UNKNOWN, false, "database error"); 1557 return false; 1558 } 1559 if (!psArrayLength(output)) { 1560 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1561 psFree(output); 1562 return true; 1563 } 1564 1565 // negative simple so the default is true 1566 if (!ippdbPrintMetadatas(stdout, output, "detPendingProcessedExp", !simple)) { 1567 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1568 psFree(output); 1569 return false; 1570 } 1571 1572 psFree(output); 1573 1574 return true; 1575 } 1576 1577 static bool addprocessedexpMode(pxConfig *config) 1578 { 1579 PS_ASSERT_PTR_NON_NULL(config, false); 1580 1581 // det_id, exp_id, recip, -bg, -bg_stdev 1582 // are required 1583 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 1584 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); 1585 1586 // default values 1587 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 1588 1589 // Required if code == 0 1590 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 1591 1592 // optional 1593 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 1594 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 1595 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 1596 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 1597 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); 1598 PXOPT_LOOKUP_F64(fringe_2, config->args, "-fringe_2", false, false); 1599 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 1600 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 1601 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 1602 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 1603 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 1604 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false); 1605 1606 psString query = pxDataGet("dettool_addprocessedexp.sql"); 1607 if (!query) { 1608 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1609 return false; 1610 } 1611 1612 if (!p_psDBRunQuery(config->dbh, query, det_id, exp_id)) { 1613 psError(PS_ERR_UNKNOWN, false, "database error"); 1614 psFree(query); 1615 return false; 1616 } 1617 psFree(query); 1618 1619 psArray *output = p_psDBFetchResult(config->dbh); 1620 if (!output) { 1621 psError(PS_ERR_UNKNOWN, false, "database error"); 1622 return false; 1623 } 1624 if (!psArrayLength(output)) { 1625 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1626 psFree(output); 1627 return true; 1628 } 1629 psFree(output); 1630 1631 // create a new detProcessedImfile object 1632 detProcessedExpRow *detRow = detProcessedExpRowAlloc( 1633 (psS64)atoll(det_id), 1634 (psS64)atoll(exp_id), 1635 recipe, 1636 bg, 1637 bg_stdev, 1638 bg_mean_stdev, 1639 fringe_0, 1640 fringe_1, 1641 fringe_2, 1642 user_1, 1643 user_2, 1644 user_3, 1645 user_4, 1646 user_5, 1647 path_base, 1648 code 1649 ); 1650 1651 // insert the new row into the detProcessedImfile table 1652 if (!detProcessedExpInsertObject(config->dbh, detRow)) { 1653 psError(PS_ERR_UNKNOWN, false, "database error"); 1654 psFree(detRow); 1655 return false; 1656 } 1657 1658 psFree(detRow); 1659 1660 return true; 1661 } 1662 1663 static bool processedexpMode(pxConfig *config) 1664 { 1665 PS_ASSERT_PTR_NON_NULL(config, false); 1666 1667 psMetadata *where = psMetadataAlloc(); 1668 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1669 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1670 1671 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1672 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 1673 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1674 1675 psString query = psStringCopy("SELECT * FROM detProcessedExp"); 1676 1677 if (psListLength(where->list)) { 1678 psString whereClause = psDBGenerateWhereSQL(where, NULL); 1679 psStringAppend(&query, " %s", whereClause); 1680 psFree(whereClause); 1681 } 1682 psFree(where); 1683 1684 if (faulted) { 1685 // list only faulted rows 1686 psStringAppend(&query, " %s", "AND detProcessedExp.fault != 0"); 1687 } else { 1688 // don't list faulted rows 1689 psStringAppend(&query, " %s", "AND detProcessedExp.fault = 0"); 1690 } 1691 1692 // treat limit == 0 as "no limit" 1693 if (limit) { 1694 psString limitString = psDBGenerateLimitSQL(limit); 1695 psStringAppend(&query, " %s", limitString); 1696 psFree(limitString); 1697 } 1698 1699 if (!p_psDBRunQuery(config->dbh, query)) { 1700 psError(PS_ERR_UNKNOWN, false, "database error"); 1701 psFree(query); 1702 return false; 1703 } 1704 psFree(query); 1705 1706 psArray *output = p_psDBFetchResult(config->dbh); 1707 if (!output) { 1708 psError(PS_ERR_UNKNOWN, false, "database error"); 1709 return false; 1710 } 1711 if (!psArrayLength(output)) { 1712 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1713 psFree(output); 1714 return true; 1715 } 1716 1717 // negative simple so the default is true 1718 if (!ippdbPrintMetadatas(stdout, output, "detProcessedExp", !simple)) { 1719 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1720 psFree(output); 1721 return false; 1722 } 1723 1724 psFree(output); 1725 1726 return true; 1727 } 1728 1729 1730 static bool revertprocessedexpMode(pxConfig *config) 1731 { 1732 PS_ASSERT_PTR_NON_NULL(config, false); 1733 1734 psMetadata *where = psMetadataAlloc(); 1735 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1736 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 1737 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 1738 1739 psString query = pxDataGet("dettool_revertprocessedexp.sql"); 1740 if (!query) { 1741 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1742 return false; 1743 } 1744 1745 if (psListLength(where->list)) { 1746 psString whereClause = psDBGenerateWhereConditionSQL(where, "detProcessedExp"); 1747 psStringAppend(&query, " AND %s", whereClause); 1748 psFree(whereClause); 1749 } 1750 psFree(where); 1751 1752 if (!p_psDBRunQuery(config->dbh, query)) { 1753 psError(PS_ERR_UNKNOWN, false, "database error"); 1754 psFree(query); 1755 return false; 1756 } 1757 psFree(query); 1758 1759 if (psDBAffectedRows(config->dbh) < 1) { 1760 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 1761 return false; 1762 } 1763 1764 return true; 1765 } 1766 1767 1768 static bool tostackedMode(pxConfig *config) 1769 { 1770 PS_ASSERT_PTR_NON_NULL(config, false); 1771 1772 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1773 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1774 1775 psString query = pxDataGet("dettool_tostacked.sql"); 1776 if (!query) { 1777 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1778 return false; 1779 } 1780 1781 // treat limit == 0 as "no limit" 1782 if (limit) { 1783 psString limitString = psDBGenerateLimitSQL(limit); 1784 psStringAppend(&query, " %s", limitString); 1785 psFree(limitString); 1786 } 1787 1788 if (!p_psDBRunQuery(config->dbh, query)) { 1789 psError(PS_ERR_UNKNOWN, false, "database error"); 1790 psFree(query); 1791 return false; 1792 } 1793 psFree(query); 1794 1795 psArray *output = p_psDBFetchResult(config->dbh); 1796 if (!output) { 1797 psError(PS_ERR_UNKNOWN, false, "database error"); 1798 return false; 1799 } 1800 if (!psArrayLength(output)) { 1801 psTrace("dettool", PS_LOG_INFO, "no rows found"); 1802 psFree(output); 1803 return true; 1804 } 1805 1806 // negative simple so the default is true 1807 if (!ippdbPrintMetadatas(stdout, output, "detPendingStackedImfile", !simple)) { 1808 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1809 psFree(output); 1810 return false; 1811 } 1812 1813 psFree(output); 1814 1815 return true; 1816 } 1817 1818 // this is NOT a command-line mode : it is used by 'addstackedMode' 1819 static psArray *searchRawImfiles(pxConfig *config) 1820 { 1821 PS_ASSERT_PTR_NON_NULL(config, NULL); 1822 1823 psMetadata *where = psMetadataAlloc(); 1824 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1825 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 1826 1827 // select exp_ids from detInputExp matching det_id & iteration 1828 // where query should be pre-generated 1829 psArray *detInputExp = detInputExpSelectRowObjects(config->dbh, where, 0); 1830 psFree (where); 1831 1832 if (!detInputExp) { 1833 psError(PS_ERR_UNKNOWN, false, "no rawExp rows found"); 1834 return NULL; 1835 } 1836 1837 // generate where query with just the exp_ids 1838 psMetadata *where_exp_ids = psMetadataAlloc(); 1839 for (long i = 0; i < psArrayLength(detInputExp); i++) { 1840 detInputExpRow *row = detInputExp->data[i]; 1841 if (!psMetadataAddS64(where_exp_ids, PS_LIST_TAIL, "exp_id", 1842 PS_META_DUPLICATE_OK, "==", row->exp_id) 1843 ) { 1844 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 1845 psFree(detInputExp); 1846 psFree(where_exp_ids); 1847 return NULL; 1848 } 1849 } 1850 psFree(detInputExp); 1851 1852 // select rawImfiles with matching exp_ids 1853 psArray *rawImfiles = 1854 rawImfileSelectRowObjects(config->dbh, where_exp_ids, 0); 1855 psFree(where_exp_ids); 1856 if (!rawImfiles) { 1857 psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found"); 1858 return NULL; 1859 } 1860 1861 return rawImfiles; 1862 } 1863 1864 static bool addstackedMode(pxConfig *config) 1865 { 1866 PS_ASSERT_PTR_NON_NULL(config, false); 1867 1868 // det_id, iteration, class_id, uri, & recipe are required 1869 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 1870 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", true, false); 1871 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 1872 1873 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 1874 1875 // Required if code == 0 1876 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); 1877 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 1878 1879 // optional 1880 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 1881 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 1882 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 1883 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 1884 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 1885 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 1886 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 1887 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 1888 1889 // correlate the class_id against the input exposure(s) 1890 // searchRawImfiles defines a where clause to search by det_id and iteration 1891 psArray *rawImfiles = searchRawImfiles(config); 1892 1893 if (!rawImfiles) { 1894 psError(PS_ERR_UNKNOWN, false, "failed to get rawImfiles from db"); 1895 return false; 1896 } 1897 1898 bool valid_class_id = false; 1899 if (rawImfiles) { 1900 for (long i = 0; i < psArrayLength(rawImfiles); i++) { 1901 if (!rawImfiles->data[i]) { 1902 fprintf (stderr, "*"); 1903 continue; 1904 } 1905 if (strcmp(class_id, ((rawImfileRow *)rawImfiles->data[i])->class_id) == 0) { 1906 valid_class_id = true; 1907 break; 1908 } 1909 } 1910 psFree(rawImfiles); 1911 } 1912 1913 if (!valid_class_id) { 1914 psError(PS_ERR_UNKNOWN, true, 1915 "class_id can not be correlated with the input exposures"); 1916 return false; 1917 } 1918 1919 // create a new detStackedImfile object 1920 detStackedImfileRow *stackedImfile = detStackedImfileRowAlloc( 1921 (psS64)atoll(det_id), 1922 iteration, 1923 class_id, 1924 uri, 1925 recipe, 1926 bg, 1927 bg_stdev, 1928 bg_mean_stdev, 1929 user_1, 1930 user_2, 1931 user_3, 1932 user_4, 1933 user_5, 1934 code 1935 ); 1936 1937 // insert the new row into the detProcessedImfile table 1938 if (!detStackedImfileInsertObject(config->dbh, stackedImfile)) { 1939 psError(PS_ERR_UNKNOWN, false, "database error"); 1940 psFree(stackedImfile); 1941 return false; 1942 } 1943 1944 psFree(stackedImfile); 1945 1946 return true; 1947 } 1948 1949 static bool stackedMode(pxConfig *config) 1950 { 1951 PS_ASSERT_PTR_NON_NULL(config, false); 1952 1953 psMetadata *where = psMetadataAlloc(); 1954 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 1955 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 1956 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 1957 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 1958 1959 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1960 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 1961 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1962 1963 psString query = pxDataGet("dettool_stacked.sql"); 1964 if (!query) { 1965 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1966 psFree(where); 1967 return false; 1968 } 1969 1970 if (psListLength(where->list)) { 1971 psString whereClause = psDBGenerateWhereConditionSQL(where, "detStackedImfile"); 1972 psStringAppend(&query, " AND %s", whereClause); 1973 psFree(whereClause); 1974 } 1975 psFree(where); 1976 1977 if (faulted) { 1978 // list only faulted rows 1979 psStringAppend(&query, " %s", "AND detStackedImfile.fault != 0"); 1980 } else { 1981 // don't list faulted rows 1982 psStringAppend(&query, " %s", "AND detStackedImfile.fault = 0"); 1983 } 1984 1985 // treat limit == 0 as "no limit" 1986 if (limit) { 1987 psString limitString = psDBGenerateLimitSQL(limit); 1988 psStringAppend(&query, " %s", limitString); 1989 psFree(limitString); 1990 } 1991 1992 if (!p_psDBRunQuery(config->dbh, query)) { 1993 psError(PS_ERR_UNKNOWN, false, "database error"); 1994 psFree(query); 1995 return false; 1996 } 1997 psFree(query); 1998 1999 psArray *output = p_psDBFetchResult(config->dbh); 2000 if (!output) { 2001 psError(PS_ERR_UNKNOWN, false, "database error"); 2002 return false; 2003 } 2004 if (!psArrayLength(output)) { 2005 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2006 psFree(output); 2007 return true; 2008 } 2009 2010 // negative simple so the default is true 2011 if (!ippdbPrintMetadatas(stdout, output, "rawImfile", !simple)) { 2012 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2013 psFree(output); 2014 return false; 2015 } 2016 2017 psFree(output); 2018 2019 return true; 2020 } 2021 2022 2023 static bool revertstackedMode(pxConfig *config) 2024 { 2025 PS_ASSERT_PTR_NON_NULL(config, false); 2026 2027 psMetadata *where = psMetadataAlloc(); 2028 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2029 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2030 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2031 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2032 2033 psString query = pxDataGet("dettool_revertstacked.sql"); 2034 if (!query) { 2035 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2036 return false; 2037 } 2038 2039 if (psListLength(where->list)) { 2040 psString whereClause = psDBGenerateWhereConditionSQL(where, "detStackedImfile"); 2041 psStringAppend(&query, " AND %s", whereClause); 2042 psFree(whereClause); 2043 } 2044 psFree(where); 2045 2046 if (!p_psDBRunQuery(config->dbh, query)) { 2047 psError(PS_ERR_UNKNOWN, false, "database error"); 2048 psFree(query); 2049 return false; 2050 } 2051 psFree(query); 2052 2053 if (psDBAffectedRows(config->dbh) < 1) { 2054 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2055 return false; 2056 } 2057 2058 return true; 2059 } 2060 2061 static bool tonormalizedstatMode(pxConfig *config) 2062 { 2063 PS_ASSERT_PTR_NON_NULL(config, false); 2064 2065 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2066 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2067 2068 psString query = pxDataGet("dettool_tonormalizedstat.sql"); 2069 if (!query) { 2070 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2071 return false; 2072 } 2073 2074 // treat limit == 0 as "no limit" 2075 if (limit) { 2076 psString limitString = psDBGenerateLimitSQL(limit); 2077 psStringAppend(&query, " %s", limitString); 2078 psFree(limitString); 2079 } 2080 2081 if (!p_psDBRunQuery(config->dbh, query)) { 2082 psError(PS_ERR_UNKNOWN, false, "database error"); 2083 psFree(query); 2084 return false; 2085 } 2086 psFree(query); 2087 2088 psArray *output = p_psDBFetchResult(config->dbh); 2089 if (!output) { 2090 psError(PS_ERR_UNKNOWN, false, "database error"); 2091 return false; 2092 } 2093 if (!psArrayLength(output)) { 2094 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2095 psFree(output); 2096 return true; 2097 } 2098 2099 // negative simple so the default is true 2100 if (!ippdbPrintMetadatas(stdout, output, "detPendingNormStatImfile", !simple)) { 2101 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2102 psFree(output); 2103 return false; 2104 } 2105 2106 psFree(output); 2107 2108 return true; 2109 } 2110 2111 static bool addnormalizedstatMode(pxConfig *config) 2112 { 2113 PS_ASSERT_PTR_NON_NULL(config, NULL); 2114 2115 // required 2116 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 2117 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 2118 2119 // optional 2120 PXOPT_LOOKUP_F32(norm, config->args, "-norm", false, false); 2121 2122 // default 2123 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2124 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2125 2126 if (!detNormalizedStatImfileInsert(config->dbh, 2127 (psS64)atoll(det_id), 2128 iteration, 2129 class_id, 2130 norm, 2131 code 2132 )) { 2133 psError(PS_ERR_UNKNOWN, false, "database error"); 2134 return false; 2135 } 2136 2137 return true; 2138 } 2139 2140 2141 static bool normalizedstatMode(pxConfig *config) 2142 { 2143 PS_ASSERT_PTR_NON_NULL(config, false); 2144 2145 psMetadata *where = psMetadataAlloc(); 2146 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2147 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2148 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2149 2150 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2151 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2152 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2153 2154 psString query = pxDataGet("dettool_normalizedstat.sql"); 2155 if (!query) { 2156 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2157 return false; 2158 } 2159 2160 if (faulted) { 2161 // list only faulted rows 2162 psStringAppend(&query, " %s", "WHERE fault != 0"); 2163 } else { 2164 // don't list faulted rows 2165 psStringAppend(&query, " %s", "WHERE fault = 0"); 2166 } 2167 2168 if (psListLength(where->list)) { 2169 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 2170 psStringAppend(&query, " AND %s", whereClause); 2171 psFree(whereClause); 2172 } 2173 psFree(where); 2174 2175 // treat limit == 0 as "no limit" 2176 if (limit) { 2177 psString limitString = psDBGenerateLimitSQL(limit); 2178 psStringAppend(&query, " %s", limitString); 2179 psFree(limitString); 2180 } 2181 2182 if (!p_psDBRunQuery(config->dbh, query)) { 2183 psError(PS_ERR_UNKNOWN, false, "database error"); 2184 psFree(query); 2185 return false; 2186 } 2187 psFree(query); 2188 2189 psArray *output = p_psDBFetchResult(config->dbh); 2190 if (!output) { 2191 psError(PS_ERR_UNKNOWN, false, "database error"); 2192 return false; 2193 } 2194 if (!psArrayLength(output)) { 2195 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2196 psFree(output); 2197 return true; 2198 } 2199 2200 // negative simple so the default is true 2201 if (!ippdbPrintMetadatas(stdout, output, "detNormalizedStatImfile", !simple)) { 2202 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2203 psFree(output); 2204 return false; 2205 } 2206 2207 psFree(output); 2208 2209 return true; 2210 } 2211 2212 static bool revertnormalizedstatMode(pxConfig *config) 2213 { 2214 PS_ASSERT_PTR_NON_NULL(config, false); 2215 2216 psMetadata *where = psMetadataAlloc(); 2217 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2218 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2219 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2220 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2221 2222 psString query = pxDataGet("dettool_revertnormalizedstat.sql"); 2223 if (!query) { 2224 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2225 return false; 2226 } 2227 2228 if (psListLength(where->list)) { 2229 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedStatImfile"); 2230 psStringAppend(&query, " AND %s", whereClause); 2231 psFree(whereClause); 2232 } 2233 psFree(where); 2234 2235 if (!p_psDBRunQuery(config->dbh, query)) { 2236 psError(PS_ERR_UNKNOWN, false, "database error"); 2237 psFree(query); 2238 return false; 2239 } 2240 psFree(query); 2241 2242 if (psDBAffectedRows(config->dbh) < 1) { 2243 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2244 return false; 2245 } 2246 2247 return true; 2248 } 2249 2250 static bool tonormalizeMode(pxConfig *config) 2251 { 2252 PS_ASSERT_PTR_NON_NULL(config, false); 2253 2254 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2255 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2256 2257 psString query = pxDataGet("dettool_tonormalize.sql"); 2258 if (!query) { 2259 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2260 return false; 2261 } 2262 2263 // treat limit == 0 as "no limit" 2264 if (limit) { 2265 psString limitString = psDBGenerateLimitSQL(limit); 2266 psStringAppend(&query, " %s", limitString); 2267 psFree(limitString); 2268 } 2269 2270 if (!p_psDBRunQuery(config->dbh, query)) { 2271 psError(PS_ERR_UNKNOWN, false, "database error"); 2272 psFree(query); 2273 return false; 2274 } 2275 psFree(query); 2276 2277 psArray *output = p_psDBFetchResult(config->dbh); 2278 if (!output) { 2279 psError(PS_ERR_UNKNOWN, false, "database error"); 2280 return false; 2281 } 2282 if (!psArrayLength(output)) { 2283 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2284 psFree(output); 2285 return true; 2286 } 2287 2288 // negative simple so the default is true 2289 if (!ippdbPrintMetadatas(stdout, output, "detPendingNormImfile", !simple)) { 2290 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2291 psFree(output); 2292 return false; 2293 } 2294 2295 psFree(output); 2296 2297 return true; 2298 } 2299 2300 static bool addnormalizedimfileMode(pxConfig *config) 2301 { 2302 PS_ASSERT_PTR_NON_NULL(config, false); 2303 2304 // required 2305 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 2306 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2307 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 2308 2309 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2310 2311 // Required if code == 0 2312 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); 2313 2314 // optional 2315 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 2316 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 2317 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 2318 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 2319 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 2320 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 2321 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 2322 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 2323 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 2324 2325 if (!detNormalizedImfileInsert(config->dbh, 2326 (psS64)atoll(det_id), 2327 iteration, 2328 class_id, 2329 uri, 2330 bg, 2331 bg_stdev, 2332 bg_mean_stdev, 2333 user_1, 2334 user_2, 2335 user_3, 2336 user_4, 2337 user_5, 2338 path_base, 2339 code 2340 )) { 2341 psError(PS_ERR_UNKNOWN, false, "database error"); 2342 return false; 2343 } 2344 2345 return true; 2346 } 2347 2348 static bool normalizedimfileMode(pxConfig *config) 2349 { 2350 PS_ASSERT_PTR_NON_NULL(config, false); 2351 2352 psMetadata *where = psMetadataAlloc(); 2353 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2354 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2355 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2356 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 2357 2358 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2359 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2360 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2361 2362 psString query = pxDataGet("dettool_normalizedimfile.sql"); 2363 if (!query) { 2364 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2365 return false; 2366 } 2367 2368 if (psListLength(where->list)) { 2369 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile"); 2370 psStringAppend(&query, " AND %s", whereClause); 2371 psFree(whereClause); 2372 } 2373 psFree(where); 2374 2375 if (faulted) { 2376 // list only faulted rows 2377 psStringAppend(&query, " %s", "AND detNormalizedImfile.fault != 0"); 2378 } else { 2379 // don't list faulted rows 2380 psStringAppend(&query, " %s", "AND detNormalizedImfile.fault = 0"); 2381 } 2382 2383 // treat limit == 0 as "no limit" 2384 if (limit) { 2385 psString limitString = psDBGenerateLimitSQL(limit); 2386 psStringAppend(&query, " %s", limitString); 2387 psFree(limitString); 2388 } 2389 2390 if (!p_psDBRunQuery(config->dbh, query)) { 2391 psError(PS_ERR_UNKNOWN, false, "database error"); 2392 psFree(query); 2393 return false; 2394 } 2395 psFree(query); 2396 2397 psArray *output = p_psDBFetchResult(config->dbh); 2398 if (!output) { 2399 psError(PS_ERR_UNKNOWN, false, "database error"); 2400 return false; 2401 } 2402 if (!psArrayLength(output)) { 2403 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2404 psFree(output); 2405 return true; 2406 } 2407 2408 // negative simple so the default is true 2409 if (!ippdbPrintMetadatas(stdout, output, "detNormalizedImfile", !simple)) { 2410 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2411 psFree(output); 2412 return false; 2413 } 2414 2415 psFree(output); 2416 2417 return true; 2418 } 2419 2420 2421 static bool revertnormalizedimfileMode(pxConfig *config) 2422 { 2423 PS_ASSERT_PTR_NON_NULL(config, false); 2424 2425 psMetadata *where = psMetadataAlloc(); 2426 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2427 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2428 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2429 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2430 2431 psString query = pxDataGet("dettool_revertnormalizedimfile.sql"); 2432 if (!query) { 2433 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2434 return false; 2435 } 2436 2437 if (psListLength(where->list)) { 2438 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile"); 2439 psStringAppend(&query, " AND %s", whereClause); 2440 psFree(whereClause); 2441 } 2442 psFree(where); 2443 2444 if (!p_psDBRunQuery(config->dbh, query)) { 2445 psError(PS_ERR_UNKNOWN, false, "database error"); 2446 psFree(query); 2447 return false; 2448 } 2449 psFree(query); 2450 2451 if (psDBAffectedRows(config->dbh) < 1) { 2452 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2453 return false; 2454 } 2455 2456 return true; 2457 } 2458 2459 static bool tonormalizedexpMode(pxConfig *config) 2460 { 2461 PS_ASSERT_PTR_NON_NULL(config, false); 2462 2463 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2464 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2465 2466 psString query = pxDataGet("dettool_tonormalizedexp.sql"); 2467 if (!query) { 2468 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2469 return false; 2470 } 2471 2472 // treat limit == 0 as "no limit" 2473 if (limit) { 2474 psString limitString = psDBGenerateLimitSQL(limit); 2475 psStringAppend(&query, " %s", limitString); 2476 psFree(limitString); 2477 } 2478 2479 if (!p_psDBRunQuery(config->dbh, query)) { 2480 psError(PS_ERR_UNKNOWN, false, "database error"); 2481 psFree(query); 2482 return false; 2483 } 2484 psFree(query); 2485 2486 psArray *output = p_psDBFetchResult(config->dbh); 2487 if (!output) { 2488 psError(PS_ERR_UNKNOWN, false, "database error"); 2489 return false; 2490 } 2491 if (!psArrayLength(output)) { 2492 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2493 psFree(output); 2494 return true; 2495 } 2496 2497 // negative simple so the default is true 2498 if (!ippdbPrintMetadatas(stdout, output, "detPendingNormExp", !simple)) { 2499 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2500 psFree(output); 2501 return false; 2502 } 2503 2504 psFree(output); 2505 2506 return true; 2507 } 2508 2509 static bool addnormalizedexpMode(pxConfig *config) 2510 { 2511 PS_ASSERT_PTR_NON_NULL(config, false); 2512 2513 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 2514 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2515 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2516 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 2517 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 2518 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 2519 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 2520 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 2521 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 2522 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 2523 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 2524 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 2525 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 2526 2527 psString query = pxDataGet("dettool_tonormalizedexp.sql"); 2528 if (!query) { 2529 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2530 return false; 2531 } 2532 2533 // XXX in some other places, we put the arguments in the .sql and supply them to RunQuery 2534 psStringAppend(&query, " WHERE det_id = %s AND iteration = %d", det_id, iteration); 2535 2536 if (!p_psDBRunQuery(config->dbh, query)) { 2537 psError(PS_ERR_UNKNOWN, false, "database error"); 2538 psFree(query); 2539 return false; 2540 } 2541 psFree(query); 2542 2543 psArray *output = p_psDBFetchResult(config->dbh); 2544 if (!output) { 2545 psError(PS_ERR_UNKNOWN, false, "database error"); 2546 return false; 2547 } 2548 if (!psArrayLength(output)) { 2549 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2550 psFree(output); 2551 return true; 2552 } 2553 psFree(output); 2554 2555 // insert the new row into the detProcessedImfile table 2556 if (!detNormalizedExpInsert(config->dbh, 2557 (psS64)atoll(det_id), 2558 iteration, 2559 recipe, 2560 bg, 2561 bg_stdev, 2562 bg_mean_stdev, 2563 user_1, 2564 user_2, 2565 user_3, 2566 user_4, 2567 user_5, 2568 path_base, 2569 code 2570 )) { 2571 psError(PS_ERR_UNKNOWN, false, "database error"); 2572 return false; 2573 } 2574 2575 return true; 2576 } 2577 2578 2579 static bool normalizedexpMode(pxConfig *config) 2580 { 2581 PS_ASSERT_PTR_NON_NULL(config, false); 2582 2583 psMetadata *where = psMetadataAlloc(); 2584 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2585 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2586 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 2587 2588 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2589 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2590 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2591 2592 psString query = pxDataGet("dettool_normalizedexp.sql"); 2593 if (!query) { 2594 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2595 return false; 2596 } 2597 2598 if (psListLength(where->list)) { 2599 psString whereClause = psDBGenerateWhereSQL(where, NULL); 2600 psStringAppend(&query, " %s", whereClause); 2601 psFree(whereClause); 2602 } 2603 psFree(where); 2604 2605 if (faulted) { 2606 // list only faulted rows 2607 psStringAppend(&query, " %s", "AND detNormalizedExp.fault != 0"); 2608 } else { 2609 // don't list faulted rows 2610 psStringAppend(&query, " %s", "AND detNormalizedExp.fault = 0"); 2611 } 2612 2613 // treat limit == 0 as "no limit" 2614 if (limit) { 2615 psString limitString = psDBGenerateLimitSQL(limit); 2616 psStringAppend(&query, " %s", limitString); 2617 psFree(limitString); 2618 } 2619 2620 if (!p_psDBRunQuery(config->dbh, query)) { 2621 psError(PS_ERR_UNKNOWN, false, "database error"); 2622 psFree(query); 2623 return false; 2624 } 2625 psFree(query); 2626 2627 psArray *output = p_psDBFetchResult(config->dbh); 2628 if (!output) { 2629 psError(PS_ERR_UNKNOWN, false, "database error"); 2630 return false; 2631 } 2632 if (!psArrayLength(output)) { 2633 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2634 psFree(output); 2635 return true; 2636 } 2637 2638 // negative simple so the default is true 2639 if (!ippdbPrintMetadatas(stdout, output, "detNormalizedExp", !simple)) { 2640 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2641 psFree(output); 2642 return false; 2643 } 2644 2645 psFree(output); 2646 2647 return true; 2648 } 2649 2650 2651 2652 static bool revertnormalizedexpMode(pxConfig *config) 2653 { 2654 PS_ASSERT_PTR_NON_NULL(config, false); 2655 2656 psMetadata *where = psMetadataAlloc(); 2657 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2658 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2659 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2660 2661 psString query = pxDataGet("dettool_revertnormalizedexp.sql"); 2662 if (!query) { 2663 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2664 return false; 2665 } 2666 2667 if (psListLength(where->list)) { 2668 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedExp"); 2669 psStringAppend(&query, " AND %s", whereClause); 2670 psFree(whereClause); 2671 } 2672 psFree(where); 2673 2674 if (!p_psDBRunQuery(config->dbh, query)) { 2675 psError(PS_ERR_UNKNOWN, false, "database error"); 2676 psFree(query); 2677 return false; 2678 } 2679 psFree(query); 2680 2681 if (psDBAffectedRows(config->dbh) < 1) { 2682 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2683 return false; 2684 } 2685 2686 return true; 2687 } 2688 2689 2690 static bool toresidimfileMode(pxConfig *config) 2691 { 2692 PS_ASSERT_PTR_NON_NULL(config, false); 2693 2694 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2695 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2696 2697 psString query = pxDataGet("dettool_toresidimfile.sql"); 2698 if (!query) { 2699 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2700 return false; 2701 } 2702 2703 // treat limit == 0 as "no limit" 2704 if (limit) { 2705 psString limitString = psDBGenerateLimitSQL(limit); 2706 psStringAppend(&query, " %s", limitString); 2707 psFree(limitString); 2708 } 2709 2710 if (!p_psDBRunQuery(config->dbh, query)) { 2711 psError(PS_ERR_UNKNOWN, false, "database error"); 2712 psFree(query); 2713 return false; 2714 } 2715 psFree(query); 2716 2717 psArray *output = p_psDBFetchResult(config->dbh); 2718 if (!output) { 2719 psError(PS_ERR_UNKNOWN, false, "database error"); 2720 return false; 2721 } 2722 if (!psArrayLength(output)) { 2723 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2724 psFree(output); 2725 return true; 2726 } 2727 2728 // negative simple so the default is true 2729 if (!ippdbPrintMetadatas(stdout, output, "detPendingResidImfile", !simple)) { 2730 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2731 psFree(output); 2732 return false; 2733 } 2734 2735 psFree(output); 2736 2737 return true; 2738 } 2739 2740 2741 static bool addresidimfileMode(pxConfig *config) 2742 { 2743 PS_ASSERT_PTR_NON_NULL(config, false); 2744 2745 2746 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 2747 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2748 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required 2749 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required 2750 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2751 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); // Required if code == 0 2752 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 2753 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 2754 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 2755 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 2756 PXOPT_LOOKUP_F64(bg_skewness, config->args, "-bg_skewness", false, false); 2757 PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false); 2758 PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false); 2759 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 2760 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); 2761 PXOPT_LOOKUP_F64(fringe_2, config->args, "-fringe_2", false, false); 2762 PXOPT_LOOKUP_F64(fringe_resid_0, config->args, "-fringe_resid_0", false, false); 2763 PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false); 2764 PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false); 2765 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 2766 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 2767 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 2768 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 2769 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 2770 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 2771 2772 if (!detResidImfileInsert(config->dbh, 2773 (psS64)atoll(det_id), 2774 iteration, 2775 (psS64)atoll(exp_id), 2776 class_id, 2777 uri, 2778 recipe, 2779 bg, 2780 bg_stdev, 2781 bg_mean_stdev, 2782 bg_skewness, 2783 bg_kurtosis, 2784 bin_stdev, 2785 fringe_0, 2786 fringe_1, 2787 fringe_2, 2788 fringe_resid_0, 2789 fringe_resid_1, 2790 fringe_resid_2, 2791 user_1, 2792 user_2, 2793 user_3, 2794 user_4, 2795 user_5, 2796 path_base, 2797 code 2798 )) { 2799 psError(PS_ERR_UNKNOWN, false, "database error"); 2800 return false; 2801 } 2802 2803 return true; 2804 } 2805 2806 2807 static bool residimfileMode(pxConfig *config) 2808 { 2809 PS_ASSERT_PTR_NON_NULL(config, false); 2810 2811 psMetadata *where = psMetadataAlloc(); 2812 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2813 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2814 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 2815 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2816 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 2817 2818 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2819 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2820 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2821 2822 psString query = pxDataGet("dettool_residimfile.sql"); 2823 if (!query) { 2824 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2825 return false; 2826 } 2827 2828 // NOTE: the query ends in a WHERE, add the required restriction on detRun.state 2829 char *value = NULL; 2830 bool status; 2831 if ((value = psMetadataLookupStr(&status, config->args, "-select_state"))) { 2832 psStringAppend(&query, " detRun.state = '%s'", value); 2833 } else { 2834 psStringAppend(&query, " detRun.state = 'run'"); 2835 } 2836 2837 if (psListLength(where->list)) { 2838 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile"); 2839 psStringAppend(&query, " AND %s", whereClause); 2840 psFree(whereClause); 2841 } 2842 psFree(where); 2843 2844 if (faulted) { 2845 // list only faulted rows 2846 psStringAppend(&query, " %s", "AND detResidImfile.fault != 0"); 2847 } else { 2848 // don't list faulted rows 2849 psStringAppend(&query, " %s", "AND detResidImfile.fault = 0"); 2850 } 2851 2852 // treat limit == 0 as "no limit" 2853 if (limit) { 2854 psString limitString = psDBGenerateLimitSQL(limit); 2855 psStringAppend(&query, " %s", limitString); 2856 psFree(limitString); 2857 } 2858 2859 if (!p_psDBRunQuery(config->dbh, query)) { 2860 psError(PS_ERR_UNKNOWN, false, "database error"); 2861 psFree(query); 2862 return false; 2863 } 2864 psFree(query); 2865 2866 psArray *output = p_psDBFetchResult(config->dbh); 2867 if (!output) { 2868 psError(PS_ERR_UNKNOWN, false, "database error"); 2869 return false; 2870 } 2871 if (!psArrayLength(output)) { 2872 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2873 psFree(output); 2874 return true; 2875 } 2876 2877 // negative simple so the default is true 2878 if (!ippdbPrintMetadatas(stdout, output, "rawResidImfile", !simple)) { 2879 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2880 psFree(output); 2881 return false; 2882 } 2883 2884 psFree(output); 2885 2886 return true; 2887 } 2888 2889 2890 static bool revertresidimfileMode(pxConfig *config) 2891 { 2892 PS_ASSERT_PTR_NON_NULL(config, false); 2893 2894 psMetadata *where = psMetadataAlloc(); 2895 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2896 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2897 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 2898 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2899 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2900 2901 psString query = pxDataGet("dettool_revertresidimfile.sql"); 2902 if (!query) { 2903 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2904 return false; 2905 } 2906 2907 if (psListLength(where->list)) { 2908 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile"); 2909 psStringAppend(&query, " AND %s", whereClause); 2910 psFree(whereClause); 2911 } 2912 psFree(where); 2913 2914 if (!p_psDBRunQuery(config->dbh, query)) { 2915 psError(PS_ERR_UNKNOWN, false, "database error"); 2916 psFree(query); 2917 return false; 2918 } 2919 psFree(query); 2920 2921 if (psDBAffectedRows(config->dbh) < 1) { 2922 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 2923 return false; 2924 } 2925 2926 return true; 2927 } 2928 2929 2930 /* 2931 The SQL returns a list of exposures for which all component class ids have had residuals 2932 created. This list includes the detrend id, iteration, exposure id, detrend type, and 2933 whether the exposure was included in the stack for this iteration. 2934 */ 2935 2936 static bool toresidexpMode(pxConfig *config) 2937 { 2938 PS_ASSERT_PTR_NON_NULL(config, false); 2939 2940 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2941 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2942 2943 psString query = pxDataGet("dettool_toresidexp.sql"); 2944 if (!query) { 2945 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2946 return false; 2947 } 2948 2949 // treat limit == 0 as "no limit" 2950 if (limit) { 2951 psString limitString = psDBGenerateLimitSQL(limit); 2952 psStringAppend(&query, " %s", limitString); 2953 psFree(limitString); 2954 } 2955 2956 if (!p_psDBRunQuery(config->dbh, query)) { 2957 psError(PS_ERR_UNKNOWN, false, "database error"); 2958 psFree(query); 2959 return false; 2960 } 2961 psFree(query); 2962 2963 psArray *output = p_psDBFetchResult(config->dbh); 2964 if (!output) { 2965 psError(PS_ERR_UNKNOWN, false, "database error"); 2966 return false; 2967 } 2968 if (!psArrayLength(output)) { 2969 psTrace("dettool", PS_LOG_INFO, "no rows found"); 2970 psFree(output); 2971 return true; 2972 } 2973 2974 // negative simple so the default is true 2975 if (!ippdbPrintMetadatas(stdout, output, "detPendingResidExp", !simple)) { 2976 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2977 psFree(output); 2978 return false; 2979 } 2980 2981 psFree(output); 2982 2983 return true; 2984 } 2985 2986 /* 2987 The SQL returns a list of exposures for which all component class ids have had residuals 2988 created. This list includes the detrend id, iteration, exposure id, detrend type, and 2989 whether the exposure was included in the stack for this iteration. 2990 */ 2991 2992 static bool addresidexpMode(pxConfig *config) 2993 { 2994 PS_ASSERT_PTR_NON_NULL(config, false); 2995 2996 // limit search by det_id, iteration, exp_id 2997 psMetadata *where = psMetadataAlloc(); 2998 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2999 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3000 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3001 3002 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 3003 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 3004 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required 3005 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 3006 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 3007 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 3008 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 3009 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 3010 PXOPT_LOOKUP_F64(bg_skewness, config->args, "-bg_skewness", false, false); 3011 PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false); 3012 PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false); 3013 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 3014 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); 3015 PXOPT_LOOKUP_F64(fringe_2, config->args, "-fringe_2", false, false); 3016 PXOPT_LOOKUP_F64(fringe_resid_0, config->args, "-fringe_resid_0", false, false); 3017 PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false); 3018 PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false); 3019 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 3020 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); 3021 PXOPT_LOOKUP_F64(user_3, config->args, "-user_3", false, false); 3022 PXOPT_LOOKUP_F64(user_4, config->args, "-user_4", false, false); 3023 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 3024 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 3025 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3026 3027 psString query = pxDataGet("dettool_toresidexp.sql"); 3028 if (!query) { 3029 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 3030 return false; 3031 } 3032 3033 if (psListLength(where->list)) { 3034 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3035 psStringAppend(&query, " WHERE %s", whereClause); 3036 psFree(whereClause); 3037 } 3038 psFree(where); 3039 3040 if (!p_psDBRunQuery(config->dbh, query)) { 3041 psError(PS_ERR_UNKNOWN, false, "database error"); 3042 psFree(query); 3043 return false; 3044 } 3045 psFree(query); 3046 3047 psArray *output = p_psDBFetchResult(config->dbh); 3048 if (!output) { 3049 psError(PS_ERR_UNKNOWN, false, "database error"); 3050 return false; 3051 } 3052 if (!psArrayLength(output)) { 3053 // XXX check psError here 3054 psError(PS_ERR_UNKNOWN, false, "no detResidImfile rows found"); 3055 psFree(output); 3056 return false; 3057 } 3058 psFree(output); 3059 3060 if (!detResidExpInsert(config->dbh, 3061 (psS64)atoll(det_id), 3062 iteration, 3063 (psS64)atoll(exp_id), 3064 recipe, 3065 bg, 3066 bg_stdev, 3067 bg_mean_stdev, 3068 bg_skewness, 3069 bg_kurtosis, 3070 bin_stdev, 3071 fringe_0, 3072 fringe_1, 3073 fringe_2, 3074 fringe_resid_0, 3075 fringe_resid_1, 3076 fringe_resid_2, 3077 user_1, 3078 user_2, 3079 user_3, 3080 user_4, 3081 user_5, 3082 path_base, 3083 !reject, 3084 code 3085 )) { 3086 psError(PS_ERR_UNKNOWN, false, "database error"); 3087 return false; 3088 } 3089 3090 return true; 3091 } 3092 3093 static bool residexpMode(pxConfig *config) 3094 { 3095 PS_ASSERT_PTR_NON_NULL(config, false); 3096 3097 psMetadata *where = psMetadataAlloc(); 3098 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3099 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3100 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3101 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 3102 3103 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 3104 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3105 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 3106 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3107 3108 psString query = pxDataGet("dettool_residexp.sql"); 3109 if (!query) { 3110 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 3111 return false; 3112 } 3113 3114 if (psListLength(where->list)) { 3115 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp"); 3116 psStringAppend(&query, " AND %s", whereClause); 3117 psFree(whereClause); 3118 } 3119 psFree(where); 3120 3121 if (faulted) { 3122 // list only faulted rows 3123 psStringAppend(&query, " %s", "AND detResidExp.fault != 0"); 3124 } else { 3125 // don't list faulted rows 3126 psStringAppend(&query, " %s", "AND detResidExp.fault = 0"); 3127 } 3128 3129 // list only accepted rows 3130 // XXX the usage of this flag is unclear : -reject means "accepted"? 3131 if (reject) { 3132 psStringAppend(&query, " %s", "AND detResidExp.accept != 0"); 3133 } 3134 3135 // treat limit == 0 as "no limit" 3136 if (limit) { 3137 psString limitString = psDBGenerateLimitSQL(limit); 3138 psStringAppend(&query, " %s", limitString); 3139 psFree(limitString); 3140 } 3141 3142 if (!p_psDBRunQuery(config->dbh, query)) { 3143 psError(PS_ERR_UNKNOWN, false, "database error"); 3144 psFree(query); 3145 return false; 3146 } 3147 psFree(query); 3148 3149 psArray *output = p_psDBFetchResult(config->dbh); 3150 if (!output) { 3151 psError(PS_ERR_UNKNOWN, false, "database error"); 3152 return false; 3153 } 3154 if (!psArrayLength(output)) { 3155 psTrace("dettool", PS_LOG_INFO, "no rows found"); 3156 psFree(output); 3157 return true; 3158 } 3159 3160 // negative simple so the default is true 3161 if (!ippdbPrintMetadatas(stdout, output, "detResidExp", !simple)) { 3162 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 3163 psFree(output); 3164 return false; 3165 } 3166 3167 psFree(output); 3168 3169 return true; 3170 } 3171 3172 3173 static bool revertresidexpMode(pxConfig *config) 3174 { 3175 PS_ASSERT_PTR_NON_NULL(config, false); 3176 3177 psMetadata *where = psMetadataAlloc(); 3178 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3179 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3180 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3181 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 3182 3183 psString query = pxDataGet("dettool_revertresidexp.sql"); 3184 if (!query) { 3185 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 3186 return false; 3187 } 3188 3189 if (psListLength(where->list)) { 3190 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp"); 3191 psStringAppend(&query, " AND %s", whereClause); 3192 psFree(whereClause); 3193 } 3194 psFree(where); 3195 3196 if (!p_psDBRunQuery(config->dbh, query)) { 3197 psError(PS_ERR_UNKNOWN, false, "database error"); 3198 psFree(query); 3199 return false; 3200 } 3201 psFree(query); 3202 3203 if (psDBAffectedRows(config->dbh) < 1) { 3204 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); 3205 return false; 3206 } 3207 3208 return true; 3209 } 3210 3211 3212 static bool updateresidexpMode(pxConfig *config) 3213 { 3214 PS_ASSERT_PTR_NON_NULL(config, false); 3215 3216 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3217 3218 // build a query to search by det_id, iteration, exp_id 3219 psMetadata *where = psMetadataAlloc(); 3220 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3221 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3222 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3223 3224 // find the values we're going to set 3225 // copy everything but det_id, iteration, & exp_id from the args and 3226 // remove the '-' prefix 3227 psMetadata *set = psMetadataAlloc(); 3228 PXOPT_COPY_STR(config->args, set, "-recip", "recipe", "=="); 3229 PXOPT_COPY_F64(config->args, set, "-bg", "bg", "=="); 3230 PXOPT_COPY_F64(config->args, set, "-bg_stdev", "bg_stdev", "=="); 3231 PXOPT_COPY_F64(config->args, set, "-bg_mean_stdev", "bg_mean_stdev", "=="); 3232 PXOPT_COPY_STR(config->args, set, "-path_base", "path_base", "=="); 3233 3234 // this can't be PXOPT_ macro-ized as reject is !'d 3235 if (!psMetadataAddBool(set, PS_LIST_TAIL, "accept", 0, "==", !reject)) { 3236 psError(PS_ERR_UNKNOWN, false, "failed to add item accept"); 3237 psFree(set); 3238 psFree(where); 3239 return false; 3240 } 3241 3242 long changed = psDBUpdateRows(config->dbh, "detResidExp", where, set); 3243 psFree(set); 3244 psFree(where); 3245 3246 if (changed < 0) { 3247 psError(PS_ERR_UNKNOWN, false, "no rows were updated"); 3248 return false; 3249 } 3250 3251 return true; 3252 } 1253 1254 3253 1255 3254 1256 /* The SQL returns a list of detrend runs (with detrend id, iteration and detrend type) which -
branches/eam_branch_20080719/ippTools/src/faketool.c
r18336 r18627 45 45 static bool unmaskedMode(pxConfig *config); 46 46 static bool unblockMode(pxConfig *config); 47 static bool pendingcleanuprunMode(pxConfig *config); 48 static bool pendingcleanupimfileMode(pxConfig *config); 49 static bool donecleanupMode(pxConfig *config); 47 50 48 51 static bool fakeProcessedCompleteExp(pxConfig *config); … … 854 857 } 855 858 859 static bool pendingcleanuprunMode(pxConfig *config) 860 { 861 PS_ASSERT_PTR_NON_NULL(config, NULL); 862 863 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 864 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 865 866 psMetadata *where = psMetadataAlloc(); 867 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 868 869 psString query = pxDataGet("faketool_pendingcleanuprun.sql"); 870 if (!query) { 871 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 872 return false; 873 } 874 875 if (where && psListLength(where->list)) { 876 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 877 psStringAppend(&query, " AND %s", whereClause); 878 psFree(whereClause); 879 } 880 psFree(where); 881 882 // treat limit == 0 as "no limit" 883 if (limit) { 884 psString limitString = psDBGenerateLimitSQL(limit); 885 psStringAppend(&query, " %s", limitString); 886 psFree(limitString); 887 } 888 889 if (!p_psDBRunQuery(config->dbh, query)) { 890 psError(PS_ERR_UNKNOWN, false, "database error"); 891 psFree(query); 892 return false; 893 } 894 psFree(query); 895 896 psArray *output = p_psDBFetchResult(config->dbh); 897 if (!output) { 898 psError(PS_ERR_UNKNOWN, false, "database error"); 899 return false; 900 } 901 if (!psArrayLength(output)) { 902 psTrace("faketool", PS_LOG_INFO, "no rows found"); 903 psFree(output); 904 return true; 905 } 906 907 // negative simple so the default is true 908 if (!ippdbPrintMetadatas(stdout, output, "fakePendingCleanupRun", !simple)) { 909 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 910 psFree(output); 911 return false; 912 } 913 914 psFree(output); 915 916 return true; 917 } 918 919 920 static bool pendingcleanupimfileMode(pxConfig *config) 921 { 922 PS_ASSERT_PTR_NON_NULL(config, NULL); 923 924 PXOPT_LOOKUP_S64(fake_id, config->args, "-fake_id", false, false); 925 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 926 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 927 928 psMetadata *where = psMetadataAlloc(); 929 if (fake_id) { 930 PXOPT_COPY_S64(config->args, where, "-fake_id", "fake_id", "=="); 931 } 932 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 933 934 psString query = pxDataGet("faketool_pendingcleanupimfile.sql"); 935 if (!query) { 936 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 937 return false; 938 } 939 940 if (where && psListLength(where->list)) { 941 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 942 psStringAppend(&query, " AND %s", whereClause); 943 psFree(whereClause); 944 } 945 psFree(where); 946 947 // treat limit == 0 as "no limit" 948 if (limit) { 949 psString limitString = psDBGenerateLimitSQL(limit); 950 psStringAppend(&query, " %s", limitString); 951 psFree(limitString); 952 } 953 954 if (!p_psDBRunQuery(config->dbh, query)) { 955 psError(PS_ERR_UNKNOWN, false, "database error"); 956 psFree(query); 957 return false; 958 } 959 psFree(query); 960 961 psArray *output = p_psDBFetchResult(config->dbh); 962 if (!output) { 963 psError(PS_ERR_UNKNOWN, false, "database error"); 964 return false; 965 } 966 if (!psArrayLength(output)) { 967 psTrace("faketool", PS_LOG_INFO, "no rows found"); 968 psFree(output); 969 return true; 970 } 971 972 // negative simple so the default is true 973 if (!ippdbPrintMetadatas(stdout, output, "fakePendingCleanupImfile", !simple)) { 974 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 975 psFree(output); 976 return false; 977 } 978 979 psFree(output); 980 981 return true; 982 } 983 984 985 static bool donecleanupMode(pxConfig *config) 986 { 987 PS_ASSERT_PTR_NON_NULL(config, NULL); 988 989 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 990 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 991 992 psMetadata *where = psMetadataAlloc(); 993 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 994 995 psString query = pxDataGet("faketool_donecleanup.sql"); 996 if (!query) { 997 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 998 return false; 999 } 1000 1001 if (where && psListLength(where->list)) { 1002 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1003 psStringAppend(&query, " AND %s", whereClause); 1004 psFree(whereClause); 1005 } 1006 psFree(where); 1007 1008 // treat limit == 0 as "no limit" 1009 if (limit) { 1010 psString limitString = psDBGenerateLimitSQL(limit); 1011 psStringAppend(&query, " %s", limitString); 1012 psFree(limitString); 1013 } 1014 1015 if (!p_psDBRunQuery(config->dbh, query)) { 1016 psError(PS_ERR_UNKNOWN, false, "database error"); 1017 psFree(query); 1018 return false; 1019 } 1020 psFree(query); 1021 1022 psArray *output = p_psDBFetchResult(config->dbh); 1023 if (!output) { 1024 psError(PS_ERR_UNKNOWN, false, "database error"); 1025 return false; 1026 } 1027 if (!psArrayLength(output)) { 1028 psTrace("faketool", PS_LOG_INFO, "no rows found"); 1029 psFree(output); 1030 return true; 1031 } 1032 1033 // negative simple so the default is true 1034 if (!ippdbPrintMetadatas(stdout, output, "fakeDoneCleanup", !simple)) { 1035 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1036 psFree(output); 1037 return false; 1038 } 1039 1040 psFree(output); 1041 1042 return true; 1043 } 856 1044 857 1045 static bool fakeProcessedCompleteExp(pxConfig *config) -
branches/eam_branch_20080719/ippTools/src/warptool.c
r18561 r18627 46 46 static bool maskedMode(pxConfig *config); 47 47 static bool unblockMode(pxConfig *config); 48 static bool pendingcleanuprunMode(pxConfig *config); 49 static bool pendingcleanupwarpMode(pxConfig *config); 50 static bool donecleanupMode(pxConfig *config); 48 51 49 52 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile); … … 1121 1124 } 1122 1125 1123 1124 1126 static bool unblockMode(pxConfig *config) 1125 1127 { … … 1138 1140 } 1139 1141 1142 static bool pendingcleanuprunMode(pxConfig *config) 1143 { 1144 PS_ASSERT_PTR_NON_NULL(config, NULL); 1145 1146 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1147 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1148 1149 psMetadata *where = psMetadataAlloc(); 1150 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1151 1152 psString query = pxDataGet("warptool_pendingcleanuprun.sql"); 1153 if (!query) { 1154 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1155 return false; 1156 } 1157 1158 if (where && psListLength(where->list)) { 1159 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1160 psStringAppend(&query, " AND %s", whereClause); 1161 psFree(whereClause); 1162 } 1163 psFree(where); 1164 1165 // treat limit == 0 as "no limit" 1166 if (limit) { 1167 psString limitString = psDBGenerateLimitSQL(limit); 1168 psStringAppend(&query, " %s", limitString); 1169 psFree(limitString); 1170 } 1171 1172 if (!p_psDBRunQuery(config->dbh, query)) { 1173 psError(PS_ERR_UNKNOWN, false, "database error"); 1174 psFree(query); 1175 return false; 1176 } 1177 psFree(query); 1178 1179 psArray *output = p_psDBFetchResult(config->dbh); 1180 if (!output) { 1181 psError(PS_ERR_UNKNOWN, false, "database error"); 1182 return false; 1183 } 1184 if (!psArrayLength(output)) { 1185 psTrace("warptool", PS_LOG_INFO, "no rows found"); 1186 psFree(output); 1187 return true; 1188 } 1189 1190 // negative simple so the default is true 1191 if (!ippdbPrintMetadatas(stdout, output, "warpPendingCleanupRun", !simple)) { 1192 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1193 psFree(output); 1194 return false; 1195 } 1196 1197 psFree(output); 1198 1199 return true; 1200 } 1201 1202 1203 static bool pendingcleanupwarpMode(pxConfig *config) 1204 { 1205 PS_ASSERT_PTR_NON_NULL(config, NULL); 1206 1207 PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", false, false); 1208 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1209 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1210 1211 psMetadata *where = psMetadataAlloc(); 1212 if (warp_id) { 1213 PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "=="); 1214 } 1215 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1216 1217 psString query = pxDataGet("warptool_pendingcleanupwarp.sql"); 1218 if (!query) { 1219 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1220 return false; 1221 } 1222 1223 if (where && psListLength(where->list)) { 1224 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1225 psStringAppend(&query, " AND %s", whereClause); 1226 psFree(whereClause); 1227 } 1228 psFree(where); 1229 1230 // treat limit == 0 as "no limit" 1231 if (limit) { 1232 psString limitString = psDBGenerateLimitSQL(limit); 1233 psStringAppend(&query, " %s", limitString); 1234 psFree(limitString); 1235 } 1236 1237 if (!p_psDBRunQuery(config->dbh, query)) { 1238 psError(PS_ERR_UNKNOWN, false, "database error"); 1239 psFree(query); 1240 return false; 1241 } 1242 psFree(query); 1243 1244 psArray *output = p_psDBFetchResult(config->dbh); 1245 if (!output) { 1246 psError(PS_ERR_UNKNOWN, false, "database error"); 1247 return false; 1248 } 1249 if (!psArrayLength(output)) { 1250 psTrace("warptool", PS_LOG_INFO, "no rows found"); 1251 psFree(output); 1252 return true; 1253 } 1254 1255 // negative simple so the default is true 1256 if (!ippdbPrintMetadatas(stdout, output, "warpPendingCleanupWarp", !simple)) { 1257 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1258 psFree(output); 1259 return false; 1260 } 1261 1262 psFree(output); 1263 1264 return true; 1265 } 1266 1267 1268 static bool donecleanupMode(pxConfig *config) 1269 { 1270 PS_ASSERT_PTR_NON_NULL(config, NULL); 1271 1272 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1273 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1274 1275 psMetadata *where = psMetadataAlloc(); 1276 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1277 1278 psString query = pxDataGet("warptool_donecleanup.sql"); 1279 if (!query) { 1280 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1281 return false; 1282 } 1283 1284 if (where && psListLength(where->list)) { 1285 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1286 psStringAppend(&query, " AND %s", whereClause); 1287 psFree(whereClause); 1288 } 1289 psFree(where); 1290 1291 // treat limit == 0 as "no limit" 1292 if (limit) { 1293 psString limitString = psDBGenerateLimitSQL(limit); 1294 psStringAppend(&query, " %s", limitString); 1295 psFree(limitString); 1296 } 1297 1298 if (!p_psDBRunQuery(config->dbh, query)) { 1299 psError(PS_ERR_UNKNOWN, false, "database error"); 1300 psFree(query); 1301 return false; 1302 } 1303 psFree(query); 1304 1305 psArray *output = p_psDBFetchResult(config->dbh); 1306 if (!output) { 1307 psError(PS_ERR_UNKNOWN, false, "database error"); 1308 return false; 1309 } 1310 if (!psArrayLength(output)) { 1311 psTrace("warptool", PS_LOG_INFO, "no rows found"); 1312 psFree(output); 1313 return true; 1314 } 1315 1316 // negative simple so the default is true 1317 if (!ippdbPrintMetadatas(stdout, output, "warpDoneCleanup", !simple)) { 1318 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1319 psFree(output); 1320 return false; 1321 } 1322 1323 psFree(output); 1324 1325 return true; 1326 } 1140 1327 1141 1328 static bool isValidMode(pxConfig *config, const char *mode)
Note:
See TracChangeset
for help on using the changeset viewer.
