IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 21, 2010, 2:45:13 PM (16 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/ippTools/src/difftool.c

    r29324 r29515  
    4848static bool pendingcleanuprunMode(pxConfig *config);
    4949static bool pendingcleanupskyfileMode(pxConfig *config);
     50static bool revertcleanupMode(pxConfig *config);
    5051static bool donecleanupMode(pxConfig *config);
    5152static bool updatediffskyfileMode(pxConfig *config);
     
    6061static bool tofullskyfileMode(pxConfig *config);
    6162static bool listrunMode(pxConfig *config);
     63static bool listssrunMode(pxConfig *config);
    6264static bool setskyfiletoupdateMode(pxConfig *config);
    6365
     
    99101        MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
    100102        MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode);
     103        MODECASE(DIFFTOOL_MODE_REVERTCLEANUP,         revertcleanupMode);
    101104        MODECASE(DIFFTOOL_MODE_DONECLEANUP,           donecleanupMode);
    102105        MODECASE(DIFFTOOL_MODE_UPDATEDIFFSKYFILE,     updatediffskyfileMode);
     
    108111        MODECASE(DIFFTOOL_MODE_TOFULLSKYFILE,         tofullskyfileMode);
    109112        MODECASE(DIFFTOOL_MODE_LISTRUN,               listrunMode);
     113        MODECASE(DIFFTOOL_MODE_LISTSSRUN,             listssrunMode);
    110114        MODECASE(DIFFTOOL_MODE_SETSKYFILETOUPDATE,    setskyfiletoupdateMode);
    111115
     
    478482    }
    479483    psFree(where);
     484
     485     psStringAppend(&query, "\nORDER by priority DESC, diff_id");
    480486
    481487    // treat limit == 0 as "no limit"
     
    12361242    PXOPT_COPY_F32(config->args, warp2Where,  "-good_frac", "warpSkyfile.good_frac", ">=");
    12371243    PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "==");
     1244    PXOPT_COPY_STR(config->args, stackWhere, "-stack_data_group", "stackRun.data_group", "==");
    12381245
    12391246    PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false);
     
    16091616    PXOPT_COPY_S64(config->args, selectWhere, "-warp_id", "inputWarpRun.warp_id", "==");
    16101617    PXOPT_COPY_S64(config->args, selectWhere, "-exp_id", "inputRawExp.exp_id", "==");
     1618    PXOPT_COPY_S64(config->args, selectWhere, "-template_exp_id", "templateRawExp.exp_id", "==");
    16111619    PXOPT_COPY_STR(config->args, selectWhere, "-filter", "inputRawExp.filter", "==");
    16121620    PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "inputRawExp.obs_mode", "==");
     
    16471655    PXOPT_COPY_F32(config->args,   selectWhere, "-sun_angle_min",      "inputRawExp.sun_angle",      ">=");
    16481656    PXOPT_COPY_F32(config->args,   selectWhere, "-sun_angle_max",      "inputRawExp.sun_angle",      "<");
    1649     PXOPT_COPY_STR(config->args,   selectWhere, "-comment",            "inputRawExp.comment",        "LIKE");
     1657    PXOPT_COPY_STR(config->args,   selectWhere, "-input_comment",      "inputRawExp.comment",        "LIKE");
     1658    PXOPT_COPY_STR(config->args,   selectWhere, "-template_comment",   "templateRawExp.comment",     "LIKE");
    16501659
    16511660    PXOPT_LOOKUP_BOOL(not_bothways, config->args, "-not-bothways", false);
     
    16801689
    16811690    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1691    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    16821692    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    16831693
     
    18391849    long numGood = 0;                   // Number of good rows added
    18401850    for (long i = 0; i < results->n; i++) {
     1851        if (limit && numGood >= limit) {
     1852            break;
     1853        }
    18411854        psMetadata *row = results->data[i]; // Result row from query
    18421855
     
    25352548
    25362549
     2550static bool revertcleanupMode(pxConfig *config)
     2551{
     2552    PS_ASSERT_PTR_NON_NULL(config, false);
     2553
     2554    psMetadata *where = psMetadataAlloc();
     2555    PXOPT_COPY_S64(config->args, where, "-diff_id",    "diffSkyfile.diff_id", "==");
     2556    pxAddLabelSearchArgs (config, where, "-label",     "diffRun.label", "LIKE");
     2557    pxAddLabelSearchArgs (config, where, "-data_group",   "diffRun.data_group", "LIKE");
     2558
     2559    PXOPT_LOOKUP_STR(state, config->args, "-state", false, false);
     2560
     2561    if (!psListLength(where->list)) {
     2562        psFree(where);
     2563        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     2564        return false;
     2565    }
     2566    if (!state) {
     2567        state = "error_cleaned";
     2568    }
     2569    char *newState = NULL;
     2570    if (!strcmp(state, "error_cleaned")) {
     2571        newState = "goto_cleaned";
     2572    } else if (!strcmp(state, "error_purged")) {
     2573        newState = "goto_purged";
     2574    } else if (!strcmp(state, "error_scrubbed")) {
     2575        newState = "goto_scrubbed";
     2576    } else {
     2577        psError(PXTOOLS_ERR_CONFIG, true, "-state must be either error_cleaned, error_purged, or error_scrubbed");
     2578        return false;
     2579    }
     2580
     2581    psString query = pxDataGet("difftool_revertcleanup.sql");
     2582    if (!query) {
     2583        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     2584        return false;
     2585    }
     2586
     2587    if (psListLength(where->list)) {
     2588        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     2589        psStringAppend(&query, " AND %s", whereClause);
     2590        psFree(whereClause);
     2591    }
     2592    psFree(where);
     2593
     2594    if (!p_psDBRunQueryF(config->dbh, query, newState, state, state)) {
     2595        psError(PS_ERR_UNKNOWN, false, "database error");
     2596        psFree(query);
     2597        return false;
     2598    }
     2599    psFree(query);
     2600
     2601    int numDeleted = psDBAffectedRows(config->dbh);
     2602
     2603    psLogMsg("difftool", PS_LOG_INFO, "Reverted %d diffRuns and diffSkyfiles", numDeleted);
     2604
     2605    return true;
     2606}
    25372607static bool donecleanupMode(pxConfig *config)
    25382608{
     
    28772947
    28782948    psMetadata *where = psMetadataAlloc();
    2879     PXOPT_COPY_S64(config->args, where,  "-diff_id", "diffRun.diff_id", "==");
    2880     PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "==");
    2881     PXOPT_COPY_S64(config->args, where,  "-magicked", "diffRun.magicked", "==");
    2882     pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE");
     2949    PXOPT_COPY_S64(config->args, where,  "-diff_id",    "diffRun.diff_id",  "==");
     2950    PXOPT_COPY_STR(config->args, where,  "-tess_id",    "diffRun.tess_id",  "LIKE");
     2951    PXOPT_COPY_S64(config->args, where,  "-magicked",   "diffRun.magicked", "==");
     2952    PXOPT_COPY_STR(config->args, where,  "-state",      "diffRun.state",    "==");
     2953    pxAddLabelSearchArgs (config, where, "-label",      "diffRun.label", "LIKE");
    28832954    pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE");
    28842955    pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE");
    2885 
     2956   
    28862957    PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
    28872958    if (!template) {
     
    29052976    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    29062977    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
    2907 
     2978    PXOPT_LOOKUP_S16(diff_mode, config->args, "-diff_mode", false, false);
     2979    if (diff_mode) {
     2980      PXOPT_COPY_S16(config->args, where, "-diff_mode", "diffRun.diff_mode", "==");
     2981    }
    29082982
    29092983    psString where2 = NULL;
     
    29833057    return true;
    29843058}
     3059static bool listssrunMode(pxConfig *config)
     3060{
     3061    PS_ASSERT_PTR_NON_NULL(config, false);
     3062
     3063    psMetadata *where = psMetadataAlloc();
     3064    PXOPT_COPY_S64(config->args, where,  "-diff_id",    "diffRun.diff_id",  "==");
     3065    PXOPT_COPY_S64(config->args, where,  "-stack_id",   "stackInput.stack_id",  "==");
     3066    PXOPT_COPY_S64(config->args, where,  "-template_stack_id",  "stackTemplate.stack_id",  "==");
     3067    PXOPT_COPY_STR(config->args, where,  "-tess_id",    "diffRun.tess_id",  "LIKE");
     3068    PXOPT_COPY_STR(config->args, where,  "-state",      "diffRun.state",    "==");
     3069    pxAddLabelSearchArgs (config, where, "-label",      "diffRun.label", "LIKE");
     3070    pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE");
     3071    pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE");
     3072
     3073    // lookup these so we don't compare to zero if they are not supplied
     3074    PXOPT_LOOKUP_F64(mjd_obs_begin, config->args, "-mjd_obs_begin", false, false);
     3075    PXOPT_LOOKUP_F64(mjd_obs_end, config->args, "-mjd_obs_end", false, false);
     3076   
     3077    PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
     3078
     3079    if (!template) {
     3080        if (mjd_obs_begin) {
     3081            PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackInput.mjd_obs",  ">=");
     3082        }
     3083        if (mjd_obs_end) {
     3084            PXOPT_COPY_F64(config->args, where, "-mjd_obs_end",   "stackInput.mjd_obs",  "<=");
     3085        }
     3086        PXOPT_COPY_STR(config->args, where, "-filter",        "stackInputRun.filter", "LIKE");
     3087    } else {
     3088        if (mjd_obs_begin) {
     3089            PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackTemplate.mjd_obs",  ">=");
     3090        }
     3091        if (mjd_obs_end) {
     3092            PXOPT_COPY_F64(config->args, where, "-mjd_obs_end",   "stackTemplate.mjd_obs",  "<=");
     3093        }
     3094        PXOPT_COPY_STR(config->args, where, "-filter",        "stackTemplateRun.filter", "LIKE");
     3095    }
     3096
     3097    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     3098    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     3099    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     3100    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
     3101
     3102    psString where2 = NULL;
     3103    psString query = pxDataGet("difftool_listssrun.sql");
     3104    if (!query) {
     3105        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     3106        return false;
     3107    }
     3108
     3109    if (psListLength(where->list)) {
     3110        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     3111        psStringAppend(&query, " AND %s", whereClause);
     3112        psFree(whereClause);
     3113    } else if (where2) {
     3114        psStringAppend(&query, " AND %s", where2);
     3115    } else if (!all) {
     3116        psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required");
     3117        return false;
     3118    }
     3119    psFree(where);
     3120
     3121    if (pstamp_order) {
     3122        if (template) {
     3123            psStringAppend(&query, " ORDER BY stackTemplate.stack_id, diff_id DESC");
     3124        } else {
     3125            psStringAppend(&query, " ORDER BY stackInput.stack_id, diff_id DESC");
     3126        }
     3127    }
     3128           
     3129    // treat limit == 0 as "no limit"
     3130    if (limit) {
     3131        psString limitString = psDBGenerateLimitSQL(limit);
     3132        psStringAppend(&query, " %s", limitString);
     3133        psFree(limitString);
     3134    }
     3135
     3136    if (!p_psDBRunQuery(config->dbh, query)) {
     3137        psError(PS_ERR_UNKNOWN, false, "database error");
     3138        psFree(query);
     3139        return false;
     3140    }
     3141    psFree(query);
     3142
     3143    psArray *output = p_psDBFetchResult(config->dbh);
     3144    if (!output) {
     3145        psErrorCode err = psErrorCodeLast();
     3146        switch (err) {
     3147            case PS_ERR_DB_CLIENT:
     3148                psError(PXTOOLS_ERR_SYS, false, "database error");
     3149            case PS_ERR_DB_SERVER:
     3150                psError(PXTOOLS_ERR_PROG, false, "database error");
     3151            default:
     3152                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     3153        }
     3154
     3155        return false;
     3156    }
     3157    if (!psArrayLength(output)) {
     3158        psTrace("difftool", PS_LOG_INFO, "no rows found");
     3159        psFree(output);
     3160        return true;
     3161    }
     3162
     3163    if (psArrayLength(output)) {
     3164        // negative simple so the default is true
     3165        if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) {
     3166            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     3167            psFree(output);
     3168            return false;
     3169        }
     3170    }
     3171
     3172    psFree(output);
     3173
     3174    return true;
     3175}
    29853176// a very specfic function to queue a cleaned warpSkyfile to be updated
    29863177static bool setskyfiletoupdateMode(pxConfig *config)
Note: See TracChangeset for help on using the changeset viewer.