IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 12:45:24 PM (17 years ago)
Author:
eugene
Message:

update from mainline

Location:
branches/eam_branches/20090715
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090715

  • branches/eam_branches/20090715/ippTools/src/magictool.c

    r24551 r25022  
    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)");
     
    580582    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    581583    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
     584    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    582585
    583586    psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0");
     
    801804    // treat limit == 0 as "no limit"
    802805    if (limit) {
    803         psString limitString = psDBGenerateLimitSQL(limit);
     806        // cut limit in half
     807        // hack to prevent pending leaf nodes from blocking branch nodes
     808        psString limitString = psDBGenerateLimitSQL((limit + 1) / 2);
    804809        psStringAppend(&query, " %s", limitString);
    805810        psFree(limitString);
     
    847852
    848853    // look for tree nodes that need to be processed
    849     // XXX: This gets all nodes from all magicRuns that are in 'new'state
    850     // That doens't seem particularly efficient
    851     query = pxDataGet("magictool_toprocess_tree.sql");
     854    query = pxDataGet("magictool_toprocess_runs.sql");
    852855    if (!query) {
    853856        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    855858    }
    856859
     860    {
     861        psString limitString = psDBGenerateLimitSQL( 100 );
     862        psStringAppend(&query, " %s", limitString);
     863        psFree(limitString);
     864    }
    857865
    858866    if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString :  "")) {
     
    865873    psFree(query);
    866874
    867     psArray *magicTree = p_psDBFetchResult(config->dbh);
    868     if (!magicTree) {
     875    psArray *magicRuns = p_psDBFetchResult(config->dbh);
     876    if (!magicRuns) {
    869877        psErrorCode err = psErrorCodeLast();
    870878        switch (err) {
     
    879887        return false;
    880888    }
    881     if (!psArrayLength(magicTree)) {
     889    if (!psArrayLength(magicRuns)) {
    882890        psTrace("magictool", PS_LOG_INFO, "no rows found");
    883         psFree(magicTree);
     891        psFree(magicRuns);
    884892        return true;
    885893    }
    886894
    887     // entries are ordered by magic_id
    888     long index = 0;
    889     while (index <  psArrayLength(magicTree)) {
    890         bool status;
     895    query = pxDataGet("magictool_toprocess_tree.sql");
     896    if (!query) {
     897        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     898        return false;
     899    }
     900
     901    for (psS64 index = 0; index < psArrayLength(magicRuns); index++) {
    891902        if (limit && (psArrayLength(output) >= limit)) {
    892903            break;
    893904        }
    894         psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id");
     905        bool status;
     906        psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id");
    895907        if (!status) {
    896908            psAbort("failed to lookup value for magic_id column");
    897909        }
    898 
    899         // find the end of this block
    900         long first = index;
    901         long last = index;
    902         for (long i = index + 1; i < psArrayLength(magicTree); i++) {
    903             psS64 magic_id = psMetadataLookupS64(&status, magicTree->data[i], "magic_id");
    904             if (!status) {
    905                 psAbort("failed to lookup value for magic_id column");
     910       
     911        whereString = NULL;
     912        psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id);
     913        if (!p_psDBRunQueryF(config->dbh, query, whereString )) {
     914            psError(PS_ERR_UNKNOWN, false, "database error");
     915            psFree(whereString);
     916            psFree(query);
     917            return false;
     918        }
     919        psFree(whereString);
     920        psArray *magicTree = p_psDBFetchResult(config->dbh);
     921        if (!magicTree) {
     922            psErrorCode err = psErrorCodeLast();
     923            switch (err) {
     924                case PS_ERR_DB_CLIENT:
     925                    psError(PXTOOLS_ERR_SYS, false, "database error");
     926                case PS_ERR_DB_SERVER:
     927                    psError(PXTOOLS_ERR_PROG, false, "database error");
     928                default:
     929                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
    906930            }
    907             if (magic_id != current_magic_id) {
    908                 break;
    909             }
    910             last = i;
    911         }
    912 
    913         index = last + 1;
    914 
    915         psHash *forest = psHashAlloc(last - first + 1);
     931
     932            return false;
     933        }
     934        psS64 length = psArrayLength(magicTree);
     935        if (!length) {
     936            psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id);
     937            psFree(magicTree);
     938            continue;
     939        }
     940
     941        psHash *forest = psHashAlloc(length);
    916942
    917943        // convert the array of metadata into a pxTree structure
    918         for (long i = first; i <= last; i++) {
     944        for (long i = 0; i < length; i++) {
    919945            bool status;
    920946            psString node = psMetadataLookupStr(&status, magicTree->data[i], "node");
     
    941967        pxTreeCrawl(root, findReadyNodes, output);
    942968        psFree(root);
    943 
    944     }
    945     psFree(magicTree);
     969        psFree(magicTree);
     970    }
    946971
    947972    if (psArrayLength(output)) {
     
    13671392    return true;
    13681393}
     1394
     1395static bool censorStage(pxConfig *config, psString stage, psString whereClause)
     1396{
     1397    psString queryFile = NULL;
     1398    psStringAppend(&queryFile, "magictool_censor_%s.sql", stage);
     1399    psString query = pxDataGet(queryFile);
     1400    if (!query) {
     1401        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement from %s", queryFile);
     1402        psFree(queryFile);
     1403        if (!psDBRollback(config->dbh)) {
     1404            psError(PS_ERR_UNKNOWN, false, "database error");
     1405        }
     1406        return false;
     1407    }
     1408    psFree(queryFile);
     1409
     1410    psStringAppend(&query, " WHERE %s",  whereClause);
     1411
     1412    if (!p_psDBRunQuery(config->dbh, query)) {
     1413        psError(PS_ERR_UNKNOWN, false, "database error");
     1414        psFree(query);
     1415        if (!psDBRollback(config->dbh)) {
     1416            psError(PS_ERR_UNKNOWN, false, "database error");
     1417        }
     1418        return false;
     1419    }
     1420    psFree(query);
     1421
     1422    return true;
     1423}
     1424
     1425static bool censorrunMode(pxConfig *config)
     1426{
     1427    PS_ASSERT_PTR_NON_NULL(config, false);
     1428
     1429    psError(PS_ERR_PROGRAMMING, true, "-censorrun mode not ready yet");
     1430    return false;
     1431
     1432    psMetadata *where = psMetadataAlloc();
     1433
     1434    // at least one of these required
     1435    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1436    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     1437
     1438    if (!psListLength(where->list)) {
     1439        psError(PS_ERR_UNKNOWN, true, "either -exp_id or -magic_id is required");
     1440        psFree(where);
     1441        return false;
     1442    }
     1443
     1444    psString query = psStringCopy("UPDATE magicRun SET state = 'censored'");
     1445
     1446    psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun");
     1447    psFree(where);
     1448    psStringAppend(&query, " WHERE %s", whereClause);
     1449
     1450    if (!psDBTransaction(config->dbh)) {
     1451        psError(PS_ERR_UNKNOWN, false, "database error");
     1452        return false;
     1453    }
     1454
     1455    if (!p_psDBRunQuery(config->dbh, query)) {
     1456        psError(PS_ERR_UNKNOWN, false, "database error");
     1457        psFree(whereClause);
     1458        psFree(query);
     1459        return false;
     1460    }
     1461    psFree(query);
     1462
     1463    psS32 numUpdated = psDBAffectedRows(config->dbh);
     1464    if (numUpdated == 0) {
     1465        psError(PS_ERR_UNKNOWN, false, "failed to censor magicRun");
     1466        psFree(whereClause);
     1467        return false;
     1468    }
     1469
     1470    // Now queue any destreaked files to be re-verted
     1471
     1472    // note: on failure censorStage issues the rollback
     1473    if (!censorStage(config, "raw", whereClause)) {
     1474        psFree(whereClause);
     1475        return false;
     1476    }
     1477    if (!censorStage(config, "chip", whereClause)) {
     1478        psFree(whereClause);
     1479        return false;
     1480    }
     1481    if (!censorStage(config, "camera", whereClause)) {
     1482        psFree(whereClause);
     1483        return false;
     1484    }
     1485    if (!censorStage(config, "warp", whereClause)) {
     1486        psFree(whereClause);
     1487        return false;
     1488    }
     1489    if (!censorStage(config, "diff", whereClause)) {
     1490        psFree(whereClause);
     1491        return false;
     1492    }
     1493
     1494    psFree(whereClause);
     1495
     1496    if (!psDBCommit(config->dbh)) {
     1497        psError(PS_ERR_UNKNOWN, false, "database error");
     1498        return false;
     1499    }
     1500
     1501    return true;
     1502}
Note: See TracChangeset for help on using the changeset viewer.