IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ippTools/src

    • Property svn:ignore
      •  

        old new  
        1616difftool
        1717disttool
         18dqstatstool
        1819faketool
        1920flatcorr
  • branches/tap_branches/ippTools/src/camtool.c

    r25851 r27838  
    109109    psMetadata *where = psMetadataAlloc();
    110110    pxcamGetSearchArgs (config, where);
    111     pxAddLabelSearchArgs (config, where, "-label", "camRun.label", "==");
    112     PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
     111    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "=="); // define using chipRun label
     112    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
    113113
    114114    if (!psListLength(where->list) &&
    115115        !psMetadataLookupBool(NULL, config->args, "-all")) {
    116116        psFree(where);
    117         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     117        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    118118        return false;
    119119    }
     
    133133    psString query = pxDataGet("camtool_find_chip_id.sql");
    134134    if (!query) {
    135         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     135        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    136136        psFree(where);
    137137        return false;
     
    184184        bool status;
    185185        char *end_stage = psMetadataLookupStr(&status, md, "end_stage");
    186         if (end_stage && strcasecmp(end_stage, "warp")) continue;
     186        if (end_stage && strcasecmp(end_stage, "warp")) continue;
    187187
    188188        char *raw_tess_id   = psMetadataLookupStr(&status, md, "tess_id");
    189         if (raw_tess_id || tess_id) continue;
     189        if (raw_tess_id || tess_id) continue;
    190190
    191191        char *label  = psMetadataLookupStr(&status, md, "label");
     
    193193
    194194        if (!status) {
    195             psError(PS_ERR_UNKNOWN, false, "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, label, exp_id);
     195            psError(PS_ERR_UNKNOWN, false, "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, label, exp_id);
    196196            psFree(output);
    197197            return false;
     
    199199    }
    200200
    201     // loop over our list of camRun rows
     201    // loop over our list of chipRun rows
    202202    for (long i = 0; i < psArrayLength(output); i++) {
    203203        psMetadata *md = output->data[i];
    204204
    205         camRunRow *row = camRunObjectFromMetadata(md);
     205        chipRunRow *row = chipRunObjectFromMetadata(md);
    206206        if (!row) {
    207             psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into camRun");
     207            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun");
    208208            psFree(output);
    209209            return false;
     
    222222                    tess_id     ? tess_id   : row->tess_id,
    223223                    end_stage   ? end_stage : row->end_stage,
     224                    row->magicked,
    224225                    note
    225226        )) {
     
    254255    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id", "==");
    255256    PXOPT_COPY_STR(config->args, where, "-label",     "camRun.label", "==");
     257    PXOPT_COPY_STR(config->args, where, "-data_group","camRun.data_group", "==");
    256258    PXOPT_COPY_STR(config->args, where, "-state",     "camRun.state", "==");
    257259    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
     
    259261    if (!psListLength(where->list)) {
    260262        psFree(where);
    261         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     263        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    262264        return false;
    263265    }
     
    265267
    266268    // pxUpdateRun gets parameters from config->args and updates
    267     bool result = pxUpdateRun(config, where, &query, "camRun", true);
     269    bool result = pxUpdateRun(config, where, &query, "camRun", "cam_id", "camProcessedExp", true);
    268270    if (!result) {
    269         psError(PXTOOLS_ERR_DATA, false, "pxUpdateRun failed");
     271        psError(psErrorCodeLast(), false, "pxUpdateRun failed");
    270272    }
    271273
     
    292294    psString query = pxDataGet("camtool_find_pendingexp.sql");
    293295    if (!query) {
    294         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     296        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    295297        return false;
    296298    }
     
    357359    psString query = pxDataGet("camtool_find_pendingimfile.sql");
    358360    if (!query) {
    359         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     361        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    360362        return false;
    361363    }
     
    479481    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    480482    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
    481    
    482     PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
     483
     484//    Get this from the chipRun
     485//    PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
    483486
    484487    // generate restrictions
     
    488491    psString query = pxDataGet("camtool_find_pendingexp.sql");
    489492    if (!query) {
    490         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     493        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    491494        return false;
    492495    }
     
    523526        return false;
    524527    }
     528
     529    bool status;
     530    psS64 chip_magicked = psMetadataLookupS64(&status, output->data[0], "chip_magicked");
    525531
    526532    camRunRow *pendingRow = camRunObjectFromMetadata(output->data[0]);
     
    603609    }
    604610
    605     // since there is only one exp per 'new' set camRun.state = 'full'
    606     if (!pxcamRunSetState(config, row->cam_id, "full", magicked)) {
    607         psError(PS_ERR_UNKNOWN, false, "failed to change camRun.state for cam_id: %" PRId64, row->cam_id);
    608         psFree(row);
    609         psFree(pendingRow);
    610         return false;
    611     }
    612 
    613     // NULL for end_stage means go as far as possible
    614     // EAM : skip here if fault != 0
    615     // Also, we can run fake even if tess_id is not defined
    616     if (fault || (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "cam"))) {
     611    if (fault) {
    617612        psFree(row);
    618613        psFree(pendingRow);
     
    623618        return true;
    624619    }
     620    // else continue on...
     621
     622    // since there is only one exp per 'new' set camRun.state = 'full'
     623    // propagate magicked state from chipRun
     624    if (!pxcamRunSetState(config, row->cam_id, "full", chip_magicked)) {
     625        psError(PS_ERR_UNKNOWN, false, "failed to change camRun.state for cam_id: %" PRId64, row->cam_id);
     626        psFree(row);
     627        psFree(pendingRow);
     628        return false;
     629    }
    625630    psFree(row);
    626     // else continue on...
     631
     632    // EAM:  NULL for end_stage means go as far as possible
     633    // Also, we can run fake even if tess_id is not defined
     634    if (pendingRow->end_stage && psStrcasestr(pendingRow->end_stage, "cam")) {
     635        psFree(pendingRow);
     636        if (!psDBCommit(config->dbh)) {
     637            psError(PS_ERR_UNKNOWN, false, "database error");
     638            return false;
     639        }
     640        return true;
     641    }
    627642
    628643    if (!pxfakeQueueByCamID(config,
     
    666681    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    667682    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
     683    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
    668684
    669685    // generate restrictions
     
    672688    PXOPT_COPY_S64(config->args, where, "-cam_id",    "camRun.cam_id",    "==");
    673689    pxAddLabelSearchArgs (config, where, "-label",    "camRun.label",     "==");
     690    pxAddLabelSearchArgs (config, where, "-data_group", "camRun.data_group",     "LIKE");
    674691    PXOPT_COPY_STR(config->args, where, "-reduction", "camRun.reduction", "==");
    675692
    676     if (!psListLength(where->list) &&
     693    psString where2 = NULL;
     694    if (!pxspaceAddWhere(config, &where2, "rawExp")) {
     695        psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed");
     696        return false;
     697    }
     698    if (!pxmagicAddWhere(config, &where2, "chipRun")) {
     699        psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed");
     700        return false;
     701    }
     702    if (!psListLength(where->list) && !where2 &&
    677703        !psMetadataLookupBool(NULL, config->args, "-all")) {
    678704        psFree(where);
    679         psError(PXTOOLS_ERR_DATA, false, "search parameters (or -all) are required");
     705        psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required");
    680706        return false;
    681707    }
     
    683709    psString query = pxDataGet("camtool_find_processedexp.sql");
    684710    if (!query) {
    685         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     711        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    686712        return false;
    687713    }
     
    691717        psStringAppend(&query, " WHERE %s", whereClause);
    692718        psFree(whereClause);
    693     } 
     719    }
    694720
    695721    // we either add AND (condition) or WHERE (condition):
     
    697723        // list only faulted rows
    698724        psStringAppend(&query, " %s", " AND camProcessedExp.fault != 0");
    699     } 
     725    }
    700726    if (where->list && !faulted) {
    701727        // don't list faulted rows
     
    705731        // list only faulted rows
    706732        psStringAppend(&query, " %s", " WHERE camProcessedExp.fault != 0");
    707     } 
     733    }
    708734    if (!where->list && !faulted) {
    709735        // don't list faulted rows
     
    711737    }
    712738    psFree(where);
    713 
    714     // order by cam_id so that the postage stamp parser can easliy find the 'latest' astrometry
    715     psStringAppend(&query, " ORDER BY cam_id");
     739    if (where2) {
     740        psStringAppend(&query, " %s", where2);
     741        psFree(where2);
     742    }
     743
     744
     745    if (pstamp_order) {
     746        // put runs in order of exposure id with newest chip Runs first
     747        // The postage stamp parser depends on this behavior
     748        psStringAppend(&query, " ORDER BY exp_id, cam_id DESC");
     749    }
    716750
    717751    // treat limit == 0 as "no limit"
     
    766800    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    767801        psFree(where);
    768         psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     802        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    769803        return false;
    770804    }
     
    779813        psString query = pxDataGet("camtool_reset_faulted_runs.sql");
    780814        if (!query) {
    781             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     815            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    782816            psFree(where);
    783817            return false;
     
    811845                psError(PS_ERR_UNKNOWN, false, "database error");
    812846            }
    813             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     847            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    814848            psFree(where);
    815849            return false;
     
    951985    psString query = pxDataGet("camtool_pendingcleanuprun.sql");
    952986    if (!query) {
    953         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     987        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    954988        return false;
    955989    }
     
    10161050    psString query = pxDataGet("camtool_pendingcleanupexp.sql");
    10171051    if (!query) {
    1018         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1052        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    10191053        return false;
    10201054    }
     
    10771111    psString query = pxDataGet("camtool_donecleanup.sql");
    10781112    if (!query) {
    1079         psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1113        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    10801114        return false;
    10811115    }
     
    11631197    psString query = pxDataGet(tables[i].sqlFilename);
    11641198    if (!query) {
    1165       psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1199      psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    11661200      return false;
    11671201    }
Note: See TracChangeset for help on using the changeset viewer.