IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3434disttool
        3535receivetool
         36
         37pubtool
  • branches/pap/ippTools/src/stacktool.c

    r23921 r25027  
    133133    PXOPT_COPY_F32(config->args,  where, "-select_posang_min",         "rawExp.posang", ">=");
    134134    PXOPT_COPY_F32(config->args,  where, "-select_posang_max",         "rawExp.posang", "<=");
    135     PXOPT_COPY_F32(config->args,  where, "-select_solang_min",         "rawExp.solang", ">=");
    136     PXOPT_COPY_F32(config->args,  where, "-select_solang_max",         "rawExp.solang", "<=");
     135    PXOPT_COPY_F32(config->args,  where, "-select_sun_angle_min",      "rawExp.sun_angle", ">=");
     136    PXOPT_COPY_F32(config->args,  where, "-select_sun_angle_max",      "rawExp.sun_angle", "<=");
     137    PXOPT_COPY_F32(config->args,  where, "-select_fwhm_major_min",     "camProcessedExp.fwhm_major", ">=");
     138    PXOPT_COPY_F32(config->args,  where, "-select_fwhm_major_max",     "camProcessedExp.fwhm_major", "<=");
     139    PXOPT_COPY_F32(config->args,  where, "-select_fwhm_minor_min",     "camProcessedExp.fwhm_minor", ">=");
     140    PXOPT_COPY_F32(config->args,  where, "-select_fwhm_minor_max",     "camProcessedExp.fwhm_minor", "<=");
    137141    PXOPT_COPY_STR(config->args,  where, "-select_exp_type",           "rawExp.exp_type", "==");
    138142    PXOPT_COPY_F32(config->args,  where, "-select_good_frac_min",      "warpSkyfile.good_frac", ">=");
    139143    PXOPT_COPY_STR(config->args,  where, "-select_skycell_id",         "warpSkyfile.skycell_id", "==");
    140     PXOPT_COPY_STR(config->args,  where, "-select_label",              "warpRun.label", "==");
     144    pxAddLabelSearchArgs (config, where, "-select_label",              "warpRun.label", "LIKE");
    141145
    142146    // these are used to build the HAVING restriction
     
    149153
    150154    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     155    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    151156    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
    152157
     
    232237    }
    233238    if (!psArrayLength(output)) {
    234         psTrace("stacktool", PS_LOG_INFO, "no rows found");
     239        psWarning("stacktool: no rows found");
     240        psFree(output);
     241        psFree(where);
     242        return true;
     243    }
     244    if (pretend) {
     245        // negative simple so the default is true
     246        if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
     247            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     248            psFree(output);
     249            psFree(where);
     250            return false;
     251        }
    235252        psFree(output);
    236253        psFree(where);
     
    358375        psFree(idString);
    359376
     377        // replace @FILTER@, @SKYCELL_ID@, @RANDOM_LIMIT@
     378        psStringSubstitute(&thisInsert, filter, "@FILTER@");
     379        psStringSubstitute(&thisInsert, skycell_id, "@SKYCELL_ID@");
     380
     381        if (randomLimit > 0) {
     382          psString limString = NULL;
     383          psStringAppend(&limString, "%d", randomLimit);
     384          psStringSubstitute(&thisInsert, limString, "@RANDOM_LIMIT@");
     385          psFree(limString);
     386        }
     387
    360388        // XXX this insert uses a select to generate the list of warp_ids for the stack,
    361389        // we have applied a set of criteria above (WHERE) to select the relevant warps
    362390        // this insert needs to use exactly the same restrictions (race condition is probably not critical)
    363391        // the insert below seems to only restrict matches to the skycell, tess, and filter
    364         if ((randomLimit > 0 && !p_psDBRunQueryF(config->dbh, thisInsert, skycell_id, filter, randomLimit)) ||
    365             (randomLimit <= 0 && !p_psDBRunQueryF(config->dbh, thisInsert, skycell_id, filter))) {
     392        if (!p_psDBRunQuery(config->dbh, thisInsert)) {
    366393            psError(PS_ERR_UNKNOWN, false, "database error");
    367394            psFree(thisInsert);
     
    375402        }
    376403        psFree(thisInsert);
     404
     405# if (0)
     406        {
     407          psArray *output = p_psDBFetchResult(config->dbh);
     408          if (!output) {
     409            psErrorCode err = psErrorCodeLast();
     410            switch (err) {
     411            case PS_ERR_DB_CLIENT:
     412              psError(PXTOOLS_ERR_SYS, false, "database error");
     413            case PS_ERR_DB_SERVER:
     414              psError(PXTOOLS_ERR_PROG, false, "database error");
     415            default:
     416              psError(PXTOOLS_ERR_PROG, false, "unknown error");
     417            }
     418            psFree(where);
     419            return false;
     420          }
     421          if (!psArrayLength(output)) {
     422            psWarning("stacktool (definebyquery, insert): no rows found");
     423            psFree(output);
     424            psFree(where);
     425            return true;
     426          }
     427          // negative simple so the default is true
     428          if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
     429            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     430            psFree(output);
     431            psFree(where);
     432            return false;
     433          }
     434          psFree(output);
     435          psFree(where);
     436          return true;
     437        }
     438# endif
     439
    377440    }
    378441    psFree(output);
     
    765828    }
    766829
    767     if (!setstackRunState(config, stack_id, "full")) {
    768         if (!psDBRollback(config->dbh)) {
    769             psError(PS_ERR_UNKNOWN, false, "database error");
    770         }
    771         psError(PS_ERR_UNKNOWN, false, "failed to change stackRun's state");
    772         return false;
     830    if (fault == 0) {
     831        if (!setstackRunState(config, stack_id, "full")) {
     832            if (!psDBRollback(config->dbh)) {
     833                psError(PS_ERR_UNKNOWN, false, "database error");
     834            }
     835            psError(PS_ERR_UNKNOWN, false, "failed to change stackRun's state");
     836            return false;
     837        }
    773838    }
    774839
     
    792857    PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "==");
    793858    PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "==");
     859    PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "==");
     860    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "==");
    794861
    795862    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    866933    PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
    867934
    868     if (!psDBTransaction(config->dbh)) {
    869         psError(PS_ERR_UNKNOWN, false, "database error");
     935    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
    870936        psFree(where);
    871         return false;
    872     }
    873 
    874     int numStacks;                      // Number of stacks affected
    875 
    876     // Update state to 'new'
    877     {
    878         psString update = pxDataGet("stacktool_revertsumskyfile_update.sql");
    879         if (!update) {
    880             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    881             if (!psDBRollback(config->dbh)) {
    882                 psError(PS_ERR_UNKNOWN, false, "database error");
    883             }
    884             return false;
    885         }
    886 
    887         if (psListLength(where->list)) {
    888             psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    889             psStringAppend(&update, " AND %s", whereClause);
    890             psFree(whereClause);
    891         }
    892 
    893         if (!p_psDBRunQuery(config->dbh, update)) {
    894             psError(PS_ERR_UNKNOWN, false, "database error");
    895             psFree(update);
    896             psFree(where);
    897             if (!psDBRollback(config->dbh)) {
    898                 psError(PS_ERR_UNKNOWN, false, "database error");
    899             }
    900             return false;
    901         }
    902         psFree(update);
    903 
    904         numStacks = psDBAffectedRows(config->dbh);
    905 
    906         if (numStacks < 1) {
    907             psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
    908             if (!psDBRollback(config->dbh)) {
    909                 psError(PS_ERR_UNKNOWN, false, "database error");
    910             }
    911             return false;
    912         }
     937        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     938        return false;
    913939    }
    914940
    915941    // Delete product
    916     {
    917         psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql");
    918         if (!delete) {
    919             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    920             if (!psDBRollback(config->dbh)) {
    921                 psError(PS_ERR_UNKNOWN, false, "database error");
    922             }
    923             return false;
    924         }
    925 
    926         if (psListLength(where->list)) {
    927             psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    928             psStringAppend(&delete, " AND %s", whereClause);
    929             psFree(whereClause);
    930         }
    931 
    932         if (!p_psDBRunQuery(config->dbh, delete)) {
    933             psError(PS_ERR_UNKNOWN, false, "database error");
    934             psFree(delete);
    935             psFree(where);
    936             if (!psDBRollback(config->dbh)) {
    937                 psError(PS_ERR_UNKNOWN, false, "database error");
    938             }
    939             return false;
    940         }
     942    psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql");
     943    if (!delete) {
     944        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     945        return false;
     946    }
     947
     948    if (psListLength(where->list)) {
     949        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     950        psStringAppend(&delete, " AND %s", whereClause);
     951        psFree(whereClause);
     952    }
     953
     954    if (!p_psDBRunQuery(config->dbh, delete)) {
     955        psError(PS_ERR_UNKNOWN, false, "database error");
    941956        psFree(delete);
    942 
    943         if (psDBAffectedRows(config->dbh) != numStacks) {
    944             psError(PS_ERR_UNKNOWN, true, "Updated and deleted different number of entries!");
    945             psFree(where);
    946             if (!psDBRollback(config->dbh)) {
    947                 psError(PS_ERR_UNKNOWN, false, "database error");
    948             }
    949             return false;
    950         }
    951 
    952     }
    953 
    954     if (!psDBCommit(config->dbh)) {
    955         psError(PS_ERR_UNKNOWN, false, "database error");
    956         return false;
    957     }
     957        psFree(where);
     958        return false;
     959    }
     960    psFree(delete);
     961
     962    int numRows = psDBAffectedRows(config->dbh); // Number of row affected
     963    psLogMsg("stacktool", PS_LOG_INFO, "Deleted %d rows", numRows);
    958964
    959965    psFree(where);
     
    991997
    992998    psMetadata *where = psMetadataAlloc();
    993     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     999    pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
    9941000
    9951001    psString query = pxDataGet("stacktool_pendingcleanuprun.sql");
     
    10551061        PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
    10561062    }
    1057     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     1063    pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
    10581064
    10591065    psString query = pxDataGet("stacktool_pendingcleanupskyfile.sql");
Note: See TracChangeset for help on using the changeset viewer.