IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 6, 2012, 6:32:19 PM (14 years ago)
Author:
watersc1
Message:

merge from trunk. Preliminary versions of stacktool/warptool updates and regenerate_background.pl script. The warp code is finished and tested, and I still need to get the stack version resolved.

Location:
branches/czw_branch/20120906/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20120906/ippTools/src

  • branches/czw_branch/20120906/ippTools/src/stacktool.c

    r34296 r34772  
    3737static bool inputskyfileMode(pxConfig *config);
    3838static bool tosumMode(pxConfig *config);
     39static bool tobkgMode(pxConfig *config);
    3940static bool addsumskyfileMode(pxConfig *config);
    4041static bool sumskyfileMode(pxConfig *config);
     
    7677        MODECASE(STACKTOOL_MODE_INPUTSKYFILE,          inputskyfileMode);
    7778        MODECASE(STACKTOOL_MODE_TOSUM,                 tosumMode);
     79        MODECASE(STACKTOOL_MODE_TOBKG,                 tobkgMode);
    7880        MODECASE(STACKTOOL_MODE_ADDSUMSKYFILE,         addsumskyfileMode);
    7981        MODECASE(STACKTOOL_MODE_SUMSKYFILE,            sumskyfileMode);
     
    748750    PXOPT_COPY_STR(config->args, where, "-state",     "stackRun.state",     "==");
    749751    PXOPT_COPY_S64(config->args, where, "-sass_id",   "stackAssociationMap.sass_id",  "==");
     752    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    750753    if (!psListLength(where->list)) {
    751754        psFree(where);
     
    756759    //CZW join against stackAssociationMap
    757760    psString query = psStringCopy("UPDATE stackRun");
     761
     762    if (fault) {
     763        psStringAppend(&query, " JOIN stackSumSkyfile USING(stack_id)");
     764        PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
     765    }
    758766
    759767    // pxUpdateRun gets parameters from config->args and updates
     
    946954        // negative simple so the default is true
    947955        if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) {
     956            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     957            psFree(output);
     958            return false;
     959        }
     960    }
     961
     962    psFree(output);
     963
     964    return true;
     965}
     966
     967static bool tobkgMode(pxConfig *config)
     968{
     969    PS_ASSERT_PTR_NON_NULL(config, false);
     970
     971    psMetadata *where = psMetadataAlloc();
     972    PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
     973    pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
     974
     975    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     976    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     977
     978    psString query = pxDataGet("stacktool_tobkg.sql");
     979    if (!query) {
     980        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     981        return false;
     982    }
     983
     984    psString whereClause = psStringCopy(""); // WHERE conditions to add
     985    if (psListLength(where->list)) {
     986        psString new = psDBGenerateWhereConditionSQL(where, NULL);
     987        psStringAppend(&whereClause, "\nAND %s", new);
     988        psFree(new);
     989    }
     990    psFree(where);
     991
     992    psStringAppend(&query, "\nORDER by priority DESC, stack_id");
     993
     994    // treat limit == 0 as "no limit"
     995    if (limit) {
     996        psString limitString = psDBGenerateLimitSQL(limit);
     997        psStringAppend(&query, " %s", limitString);
     998        psFree(limitString);
     999    }
     1000
     1001    if (!p_psDBRunQueryF(config->dbh, query, whereClause)) {
     1002        psError(PS_ERR_UNKNOWN, false, "database error");
     1003        psFree(query);
     1004        return false;
     1005    }
     1006    psFree(query);
     1007
     1008    psArray *output = p_psDBFetchResult(config->dbh);
     1009    if (!output) {
     1010        psErrorCode err = psErrorCodeLast();
     1011        switch (err) {
     1012            case PS_ERR_DB_CLIENT:
     1013                psError(PXTOOLS_ERR_SYS, false, "database error");
     1014            case PS_ERR_DB_SERVER:
     1015                psError(PXTOOLS_ERR_PROG, false, "database error");
     1016            default:
     1017                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1018        }
     1019
     1020        return false;
     1021    }
     1022    if (!psArrayLength(output)) {
     1023        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1024        psFree(output);
     1025        return true;
     1026    }
     1027
     1028    if (psArrayLength(output)) {
     1029        // negative simple so the default is true
     1030        if (!ippdbPrintMetadatas(stdout, output, "stackBkgSkyfile", !simple)) {
    9481031            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    9491032            psFree(output);
     
    10001083    PXOPT_LOOKUP_STR(ver_streaks, config->args, "-ver_streaks", false, false);
    10011084
     1085    PXOPT_LOOKUP_S16(background_model, config->args, "-background_model", false, false);
     1086   
    10021087    psTrace("czw.test",1,"Received versions: pslib %s psmodules %s psphot %s ppstats %s ppstack %s streaks %s\n",
    10031088            ver_pslib,ver_psmodules,ver_psphot,ver_ppstats,ver_ppstack,ver_streaks);
     
    10611146                               fault,
    10621147                               software_ver,
     1148                               background_model,
    10631149                               quality
    10641150          )) {
     
    11091195    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "==");
    11101196    PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE");
     1197    PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "==");
    11111198    pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE");
    11121199    pxAddLabelSearchArgs(config, where, "-data_group", "stackRun.data_group", "LIKE");
     
    11141201    PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackSumSkyfile.mjd_obs", ">=");
    11151202    PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackSumSkyfile.mjd_obs", "<=");
    1116 
     1203    PXOPT_COPY_S16(config->args, where, "-background_model","stackSumSkyfile.background_model", "==");
    11171204
    11181205//  The following three selectors are incompatible with the sql so omit them
     
    16711758    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    16721759    PXOPT_LOOKUP_S16(quality, config->args, "-set_quality", false, false);
     1760    PXOPT_LOOKUP_S16(background_model, config->args, "-set_background_model", false, false);
    16731761
    16741762    psMetadata *where = psMetadataAlloc();
    16751763    PXOPT_COPY_S64(config->args, where, "-stack_id",   "stack_id",   "==");
    16761764
    1677     if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
     1765    if (background_model) {
     1766      psMetadata *values = psMetadataAlloc();
     1767      PXOPT_COPY_S16(config->args, values, "-set_background_model", "background_model", "==");
     1768      long rows = psDBUpdateRows(config->dbh,"warpSkyfile", where, values);
     1769      psFree(values);
     1770      if (!rows) {
     1771        // This maybe should rollback and error if rows != 1
     1772        psError(PS_ERR_UNKNOWN, true, "no rows changed");
     1773        return false;
     1774      }
     1775    }
     1776    else {   
     1777      if (!pxSetFaultCode(config->dbh, "stackSumSkyfile", where, fault, quality)) {
    16781778        psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag");
    16791779        psFree (where);
    16801780        return false;
     1781      }
    16811782    }
    16821783    psFree (where);
Note: See TracChangeset for help on using the changeset viewer.