IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 21, 2009, 2:42:19 PM (17 years ago)
Author:
bills
Message:

Added mode to magictool to censor a magicRun. This is used if unmasked streaks
are found.
This causes any magicDSRuns associated to have the state set to censored
and any de-streaked files to be queued for reverting.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/magictool.c

    r24551 r24883  
    4747static bool revertmaskMode(pxConfig *config);
    4848static bool maskMode(pxConfig *config);
     49static bool censorrunMode(pxConfig *config);
    4950
    5051static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state);
     
    8586        MODECASE(MAGICTOOL_MODE_REVERTMASK,          revertmaskMode);
    8687        MODECASE(MAGICTOOL_MODE_MASK,                maskMode);
     88        MODECASE(MAGICTOOL_MODE_CENSORRUN,           censorrunMode);
    8789        default:
    8890            psAbort("invalid option (this should not happen)");
     
    13671369    return true;
    13681370}
     1371
     1372static bool censorStage(pxConfig *config, psString stage, psString whereClause)
     1373{
     1374    psString queryFile = NULL;
     1375    psStringAppend(&queryFile, "magicdstool_censor_%s.sql", stage);
     1376    psString query = pxDataGet(queryFile);
     1377    if (!query) {
     1378        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", queryFile);
     1379        psFree(queryFile);
     1380        if (!psDBRollback(config->dbh)) {
     1381            psError(PS_ERR_UNKNOWN, false, "database error");
     1382        }
     1383        return false;
     1384    }
     1385    psFree(queryFile);
     1386
     1387    psStringAppend(&query, whereClause);
     1388
     1389    if (!p_psDBRunQuery(config->dbh, query)) {
     1390        psError(PS_ERR_UNKNOWN, false, "database error");
     1391        psFree(query);
     1392        if (!psDBRollback(config->dbh)) {
     1393            psError(PS_ERR_UNKNOWN, false, "database error");
     1394        }
     1395        return false;
     1396    }
     1397    psFree(query);
     1398
     1399    return true;
     1400}
     1401
     1402static bool censorrunMode(pxConfig *config)
     1403{
     1404    PS_ASSERT_PTR_NON_NULL(config, false);
     1405
     1406    psMetadata *where = psMetadataAlloc();
     1407
     1408    // at least one of these required
     1409    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1410    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     1411
     1412    if (!psListLength(where->list)) {
     1413        psError(PS_ERR_UNKNOWN, true, "either -exp_id or -magic_id is required");
     1414        psFree(where);
     1415        return false;
     1416    }
     1417
     1418    psString query = psStringCopy("UPDATE magicRun SET state = 'censored'");
     1419
     1420    psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun");
     1421    psFree(where);
     1422    psStringAppend(&query, " WHERE %s", whereClause);
     1423
     1424    if (!psDBTransaction(config->dbh)) {
     1425        psError(PS_ERR_UNKNOWN, false, "database error");
     1426        return false;
     1427    }
     1428
     1429    if (!p_psDBRunQuery(config->dbh, query)) {
     1430        psError(PS_ERR_UNKNOWN, false, "database error");
     1431        psFree(whereClause);
     1432        psFree(query);
     1433        return false;
     1434    }
     1435    psFree(query);
     1436
     1437    // Now queue any destreaked files to be re-verted
     1438
     1439    // note: on failure censorStage issues the rollback
     1440    if (!censorStage(config, "raw", whereClause)) {
     1441        psFree(whereClause);
     1442        return false;
     1443    }
     1444    if (!censorStage(config, "chip", whereClause)) {
     1445        psFree(whereClause);
     1446        return false;
     1447    }
     1448    if (!censorStage(config, "camera", whereClause)) {
     1449        psFree(whereClause);
     1450        return false;
     1451    }
     1452    if (!censorStage(config, "warp", whereClause)) {
     1453        psFree(whereClause);
     1454        return false;
     1455    }
     1456    if (!censorStage(config, "diff", whereClause)) {
     1457        psFree(whereClause);
     1458        return false;
     1459    }
     1460
     1461    psFree(whereClause);
     1462
     1463    if (!psDBCommit(config->dbh)) {
     1464        psError(PS_ERR_UNKNOWN, false, "database error");
     1465        return false;
     1466    }
     1467
     1468    return true;
     1469}
Note: See TracChangeset for help on using the changeset viewer.