IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:45:22 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simmosaic_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/simmosaic_branches

  • branches/simmosaic_branches/ippTools/src

    • Property svn:ignore
      •  

        old new  
         1*.la
         2*.lo
        13.deps
        24.gdb_history
         
        46Makefile
        57Makefile.in
         8addtool
         9caltool
         10camtool
         11chiptool
        612config.h
        713config.h.in
        8 stamp-h1
        9 *.la
        10 *.lo
         14detselect
         15dettool
         16difftool
         17disttool
         18dqstatstool
         19faketool
         20flatcorr
         21guidetool
         22magicdstool
         23magictool
         24pstamptool
         25pubtool
         26pxadmin
         27pxdata.c
         28pxinject
        1129pxtoolsErrorCodes.c
        1230pxtoolsErrorCodes.h
        13 pxadmin
        14 pxinject
        15 pztool
        1631pzgetexp
        1732pzgetimfiles
         33pztool
         34receivetool
        1835regtool
        19 guidetool
        20 chiptool
        21 camtool
         36stacktool
         37stamp-h1
        2238warptool
        23 difftool
        24 stacktool
        25 faketool
        26 dettool
        27 detselect
        28 pxdata.c
        29 magictool
        30 magicdstool
        31 caltool
        32 flatcorr
        33 pstamptool
        34 disttool
        35 receivetool
        36 
        37 pubtool
  • branches/simmosaic_branches/ippTools/src/magictool.c

    r24551 r27839  
    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)");
     
    112114    // Required
    113115    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
     116    PXOPT_LOOKUP_STR(label, config->args, "-label", true, false);
    114117
    115118    // Optional
    116     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     119    PXOPT_LOOKUP_STR(data_group, config->args, "-data_group", false, false);
     120    PXOPT_LOOKUP_STR(note, config->args, "-note", false, false);
    117121    PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false);
    118122    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     
    131135        psString query = pxDataGet("magictool_definebyquery_select.sql");
    132136        if (!query) {
    133             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     137            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    134138            return false;
    135139        }
     
    147151        // what if no skycells for the diff run completed?
    148152
    149         if (!rerun) {
    150             psStringAppend(&queryWhereStr, "\n%s magic_id IS NULL", queryWhereStr ? "AND" : "WHERE");
     153        psStringAppend(&queryWhereStr, "\n%s magic_id IS NULL", queryWhereStr ? "AND" : "WHERE");
     154        psString rerunWhereStr = NULL;
     155        if (rerun) {
     156            psStringAppend(&rerunWhereStr, "\n WHERE magicRun.label = '%s'", label);
    151157        }
    152158
     
    172178            queryWhereStr = psStringCopy("");
    173179        }
    174 
    175         if (!p_psDBRunQueryF(config->dbh, query, diffWhereStr, diffWhereStr, queryWhereStr)) {
     180        if (!rerunWhereStr) {
     181            rerunWhereStr = psStringCopy("");
     182        }
     183
     184        if (!p_psDBRunQueryF(config->dbh, query, diffWhereStr, diffWhereStr, rerunWhereStr, queryWhereStr)) {
    176185            psError(PS_ERR_UNKNOWN, false, "database error");
    177186            psFree(diffWhereStr);
    178187            psFree(queryWhereStr);
     188            psFree(rerunWhereStr);
    179189            psFree(query);
    180190            return false;
     
    182192        psFree(diffWhereStr);
    183193        psFree(queryWhereStr);
     194        psFree(rerunWhereStr);
    184195        psFree(query);
    185196    }
     
    234245
    235246        // create a new magicRun for this group
    236         magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, inverse, "new", workdir, "dirty", label,
    237                                             dvodb, registered, 0);
     247        magicRunRow *run = magicRunRowAlloc(0,
     248                                            exp_id,
     249                                            diff_id,
     250                                            inverse,
     251                                            "new",      // state
     252                                            workdir,
     253                                            "dirty",    // workdir_state
     254                                            label,
     255                                            data_group ? data_group : label,
     256                                            dvodb,
     257                                            registered,
     258                                            0,          // fault
     259                                            note);
    238260        if (!run) {
    239261            psAbort("failed to alloc magicRun object");
     
    329351            "dirty",    // workdir_state
    330352            label,
     353            NULL,       // data_group
    331354            dvodb,
    332355            registered,
    333             0
     356            0,          // fault
     357            NULL
    334358    );
    335359
     
    410434    psString query = pxDataGet("magictool_inputskyfile.sql");
    411435    if (!query) {
    412         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     436        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    413437        return false;
    414438    }
     
    483507    psString query = pxDataGet("magictool_totree.sql");
    484508    if (!query) {
    485         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     509        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    486510        return false;
    487511    }
     
    556580
    557581    if (fault > 0) {
    558         char *query = "UPDATE magicRun SET fault = %d, state = 'full' WHERE magic_id = %" PRId64;
     582        char *query = "UPDATE magicRun SET fault = %d WHERE magic_id = %" PRId64;
    559583        if (!p_psDBRunQueryF(config->dbh, query, fault, magic_id)) {
    560584            psError(PS_ERR_UNKNOWN, false,
     
    580604    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    581605    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
     606    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    582607
    583608    psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0");
     
    594619        return false;
    595620    }
     621    psS32 numUpdated = psDBAffectedRows(config->dbh);
     622    psLogMsg("magictool", PS_LOG_INFO, "Reverted %d magic runs", numUpdated);
     623
    596624    return true;
    597625}
     
    617645    psString query = pxDataGet("magictool_inputs.sql");
    618646    if (!query) {
    619         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     647        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    620648        return false;
    621649    }
     
    787815    psString query = pxDataGet("magictool_toprocess_inputs.sql");
    788816    if (!query) {
    789         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     817        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    790818        return false;
    791819    }
     
    801829    // treat limit == 0 as "no limit"
    802830    if (limit) {
    803         psString limitString = psDBGenerateLimitSQL(limit);
     831        // cut limit in half
     832        // hack to prevent pending leaf nodes from blocking branch nodes
     833        psString limitString = psDBGenerateLimitSQL((limit + 1) / 2);
    804834        psStringAppend(&query, " %s", limitString);
    805835        psFree(limitString);
     
    847877
    848878    // 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");
     879
     880    // first find incomplete magicRuns
     881    query = pxDataGet("magictool_toprocess_runs.sql");
    852882    if (!query) {
    853         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    854         return false;
    855     }
    856 
     883        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     884        return false;
     885    }
     886
     887    // we limit the query even though it is cheap (only magic_id is selected)
     888
     889    // XXX: if the first 1000 unfinished magicRuns have no ready nodes
     890    // that haven't faulted, later runs won't get returned even though
     891    // they have work to do. When we used a limit of 100 we actually ran
     892    // into this problem. Since we're using labels a limit of 1000 will
     893    // probably be ok.
     894    {
     895        psString limitString = psDBGenerateLimitSQL( 1000 );
     896        psStringAppend(&query, " %s", limitString);
     897        psFree(limitString);
     898    }
    857899
    858900    if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString :  "")) {
     
    865907    psFree(query);
    866908
    867     psArray *magicTree = p_psDBFetchResult(config->dbh);
    868     if (!magicTree) {
     909    psArray *magicRuns = p_psDBFetchResult(config->dbh);
     910    if (!magicRuns) {
    869911        psErrorCode err = psErrorCodeLast();
    870912        switch (err) {
     
    879921        return false;
    880922    }
    881     if (!psArrayLength(magicTree)) {
     923    if (!psArrayLength(magicRuns)) {
    882924        psTrace("magictool", PS_LOG_INFO, "no rows found");
    883         psFree(magicTree);
     925        psFree(magicRuns);
    884926        return true;
    885927    }
    886928
    887     // entries are ordered by magic_id
    888     long index = 0;
    889     while (index <  psArrayLength(magicTree)) {
    890         bool status;
     929    query = pxDataGet("magictool_toprocess_tree.sql");
     930    if (!query) {
     931        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     932        return false;
     933    }
     934
     935    for (psS64 index = 0; index < psArrayLength(magicRuns); index++) {
    891936        if (limit && (psArrayLength(output) >= limit)) {
    892937            break;
    893938        }
    894         psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id");
     939        bool status;
     940        psS64 magic_id = psMetadataLookupS64(&status, magicRuns->data[index], "magic_id");
    895941        if (!status) {
    896942            psAbort("failed to lookup value for magic_id column");
    897943        }
    898944
    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");
     945        whereString = NULL;
     946        psStringAppend(&whereString, "\nAND (magic_id = %" PRId64 ")", magic_id);
     947        if (!p_psDBRunQueryF(config->dbh, query, whereString )) {
     948            psError(PS_ERR_UNKNOWN, false, "database error");
     949            psFree(whereString);
     950            psFree(query);
     951            return false;
     952        }
     953        psFree(whereString);
     954        psArray *magicTree = p_psDBFetchResult(config->dbh);
     955        if (!magicTree) {
     956            psErrorCode err = psErrorCodeLast();
     957            switch (err) {
     958                case PS_ERR_DB_CLIENT:
     959                    psError(PXTOOLS_ERR_SYS, false, "database error");
     960                case PS_ERR_DB_SERVER:
     961                    psError(PXTOOLS_ERR_PROG, false, "database error");
     962                default:
     963                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
    906964            }
    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);
     965
     966            return false;
     967        }
     968        psS64 length = psArrayLength(magicTree);
     969        if (!length) {
     970            psTrace("magictool", PS_LOG_INFO, "no rows found for magic_id %" PRId64, magic_id);
     971            psFree(magicTree);
     972            continue;
     973        }
     974
     975        psHash *forest = psHashAlloc(length);
    916976
    917977        // convert the array of metadata into a pxTree structure
    918         for (long i = first; i <= last; i++) {
     978        for (long i = 0; i < length; i++) {
    919979            bool status;
    920980            psString node = psMetadataLookupStr(&status, magicTree->data[i], "node");
     
    9411001        pxTreeCrawl(root, findReadyNodes, output);
    9421002        psFree(root);
    943 
    944     }
    945     psFree(magicTree);
     1003        psFree(magicTree);
     1004    }
    9461005
    9471006    if (psArrayLength(output)) {
     
    10011060    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
    10021061    PXOPT_COPY_STR(config->args, where, "-node", "node", "==");
    1003     PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    10041062    PXOPT_COPY_S16(config->args, where, "-fault", "magicNodeResult.fault", "==");
     1063    pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "==");
    10051064
    10061065    psString query = pxDataGet("magictool_revertnode.sql");
    10071066    if (!query) {
    1008         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1067        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    10091068        return false;
    10101069    }
     
    10271086
    10281087    psS32 numUpdated = psDBAffectedRows(config->dbh);
    1029     psLogMsg("magictool", PS_LOG_INFO, "Updated %d magic nodes", numUpdated);
     1088    psLogMsg("magictool", PS_LOG_INFO, "Reverted %d magic nodes", numUpdated);
    10301089
    10311090    return true;
     
    10431102    psString query = pxDataGet("magictool_tomask.sql");
    10441103    if (!query) {
    1045         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1104        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    10461105        return false;
    10471106    }
     
    11311190    psString query = pxDataGet("magictool_addmask.sql");
    11321191    if (!query) {
    1133         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1192        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    11341193        if (!psDBRollback(config->dbh)) {
    11351194            psError(PS_ERR_UNKNOWN, false, "database error");
     
    12381297    psString query = pxDataGet("magictool_mask.sql");
    12391298    if (!query) {
    1240         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1299        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    12411300        return false;
    12421301    }
     
    13671426    return true;
    13681427}
     1428
     1429static bool censorrunMode(pxConfig *config)
     1430{
     1431    PS_ASSERT_PTR_NON_NULL(config, false);
     1432
     1433    psMetadata *where = psMetadataAlloc();
     1434
     1435    PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", false, false);
     1436    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
     1437    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     1438
     1439    if (!magic_id) {
     1440        if (!exp_id && !label) {
     1441            psError(PS_ERR_UNKNOWN, true, "either -magic_id or exp_id and label is required");
     1442            return false;
     1443        }
     1444    }
     1445
     1446    // at least one of these required
     1447    PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "==");
     1448    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     1449    PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     1450
     1451    if (!psListLength(where->list)) {
     1452        psError(PS_ERR_UNKNOWN, true, "either -exp_id or -magic_id is required");
     1453        psFree(where);
     1454        return false;
     1455    }
     1456
     1457    psString query = psStringCopy("UPDATE magicRun SET state = 'censored'");
     1458
     1459    psString whereClause = psDBGenerateWhereConditionSQL(where, "magicRun");
     1460    psFree(where);
     1461    psStringAppend(&query, " WHERE %s", whereClause);
     1462
     1463    if (!psDBTransaction(config->dbh)) {
     1464        psError(PS_ERR_UNKNOWN, false, "database error");
     1465        return false;
     1466    }
     1467
     1468    if (!p_psDBRunQuery(config->dbh, query)) {
     1469        psError(PS_ERR_UNKNOWN, false, "database error");
     1470        psFree(whereClause);
     1471        psFree(query);
     1472        return false;
     1473    }
     1474    psFree(query);
     1475
     1476    psS32 numUpdated = psDBAffectedRows(config->dbh);
     1477    if (numUpdated == 0) {
     1478        psError(PS_ERR_UNKNOWN, false, "failed to censor magicRun");
     1479        psFree(whereClause);
     1480        return false;
     1481    }
     1482
     1483    // Now queue any destreaked files to be re-verted
     1484
     1485    // note: on failure pxmagicRestoreStage issues the rollback
     1486    if (!pxmagicRestoreStage(config, "raw", whereClause, "goto_censored")) {
     1487        psFree(whereClause);
     1488        return false;
     1489    }
     1490    if (!pxmagicRestoreStage(config, "chip", whereClause, "goto_censored")) {
     1491        psFree(whereClause);
     1492        return false;
     1493    }
     1494    if (!pxmagicRestoreStage(config, "camera", whereClause, "goto_censored")) {
     1495        psFree(whereClause);
     1496        return false;
     1497    }
     1498    if (!pxmagicRestoreStage(config, "warp", whereClause, "goto_censored")) {
     1499        psFree(whereClause);
     1500        return false;
     1501    }
     1502    if (!pxmagicRestoreStage(config, "diff", whereClause, "goto_censored")) {
     1503        psFree(whereClause);
     1504        return false;
     1505    }
     1506
     1507    psFree(whereClause);
     1508
     1509    if (!psDBCommit(config->dbh)) {
     1510        psError(PS_ERR_UNKNOWN, false, "database error");
     1511        return false;
     1512    }
     1513
     1514    return true;
     1515}
Note: See TracChangeset for help on using the changeset viewer.