IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2010, 11:24:56 AM (16 years ago)
Author:
bills
Message:

Add difftool -listrun mode
Add diff_mode to the output form -diffskyfile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/difftool.c

    r27723 r27743  
    5757static bool toscrubbedskyfileMode(pxConfig *config);
    5858static bool tofullskyfileMode(pxConfig *config);
     59static bool listrunMode(pxConfig *config);
    5960
    6061
     
    101102        MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE,     toscrubbedskyfileMode);
    102103        MODECASE(DIFFTOOL_MODE_TOFULLSKYFILE,         tofullskyfileMode);
     104        MODECASE(DIFFTOOL_MODE_LISTRUN,               listrunMode);
    103105
    104106        default:
     
    194196    PXOPT_COPY_S64(config->args, where, "-diff_id",  "diff_id",   "==");
    195197    PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
     198    PXOPT_COPY_STR(config->args, where, "-data_group","data_group",     "==");
    196199    PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
    197200    if (!psListLength(where->list)) {
     
    702705    pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE");
    703706
     707    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
    704708    PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
    705709    if (!template) {
     
    745749    psFree(where);
    746750
     751    if (pstamp_order) {
     752        if (template) {
     753            psStringAppend(&query, " ORDER BY rawTemplate.exp_id, diff_id DESC");
     754        } else {
     755            psStringAppend(&query, " ORDER BY rawInput.exp_id, diff_id DESC");
     756        }
     757    }
     758           
    747759    // treat limit == 0 as "no limit"
    748760    if (limit) {
     
    971983        return false;
    972984    }
    973     psS16 diff_mode = 0;
     985    psS16 diff_mode = IPP_DIFF_MODE_UNDEFINED;
    974986    if ((input_warp_id != PS_MAX_S64) && (template_warp_id != PS_MAX_S64)) {
    975       diff_mode = 1;
     987      diff_mode = IPP_DIFF_MODE_WARP_WARP;
    976988    }
    977989    else if ((input_warp_id != PS_MAX_S64) && (template_stack_id != PS_MAX_S64)) {
    978       diff_mode = 2;
     990      diff_mode = IPP_DIFF_MODE_WARP_STACK;
    979991    }
    980992    else if ((input_stack_id != PS_MAX_S64) && (template_warp_id != PS_MAX_S64)) {
    981       diff_mode = 3;
     993      diff_mode = IPP_DIFF_MODE_STACK_WARP;
    982994    }
    983995    else if ((input_stack_id != PS_MAX_S64) && (template_stack_id != PS_MAX_S64)) {
    984       diff_mode = 4;
     996      diff_mode = IPP_DIFF_MODE_STACK_STACK;
    985997    }
    986998
     
    14311443                true,                   // exposure
    14321444                0,       // magicked
    1433                 2,       // diff_mode for warp-stack difference
     1445                IPP_DIFF_MODE_WARP_STACK,
    14341446                note
    14351447        );
     
    17831795                                          true,  // exposure
    17841796                                          false, // magicked
    1785                                           1,     // diff_mode for warp-warp diff
     1797                                          IPP_DIFF_MODE_WARP_WARP,
    17861798                                          note); // Run to insert
    17871799        if (!diffRunInsertObject(config->dbh, run)) {
     
    20652077                                      false,                 // exposure
    20662078                                      0,       // magicked
    2067                                       4,      // diff_mode
     2079                                      IPP_DIFF_MODE_STACK_STACK, // diff_mode
    20682080                                      note
    20692081                                      );
     
    26262638  return true;
    26272639}
     2640
     2641static bool listrunMode(pxConfig *config)
     2642{
     2643    PS_ASSERT_PTR_NON_NULL(config, false);
     2644
     2645    psMetadata *where = psMetadataAlloc();
     2646    PXOPT_COPY_S64(config->args, where,  "-diff_id", "diffRun.diff_id", "==");
     2647    PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "==");
     2648    PXOPT_COPY_S64(config->args, where,  "-magicked", "diffRun.magicked", "==");
     2649    pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE");
     2650    pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE");
     2651    pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE");
     2652
     2653    PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
     2654    if (!template) {
     2655        PXOPT_COPY_S64(config->args, where, "-exp_id", "rawInput.exp_id", "==");
     2656        PXOPT_COPY_STR(config->args, where, "-exp_name", "rawInput.exp_name", "==");
     2657        PXOPT_COPY_STR(config->args, where, "-warp_id", "warpInput.warp_id", "==");
     2658        PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawInput.dateobs",  ">=");
     2659        PXOPT_COPY_TIME(config->args, where, "-dateobs_end",   "rawInput.dateobs",  "<=");
     2660        PXOPT_COPY_STR(config->args, where, "-filter",     "rawInput.filter", "LIKE");
     2661    } else {
     2662        PXOPT_COPY_S64(config->args, where, "-exp_id", "rawTemplate.exp_id", "==");
     2663        PXOPT_COPY_STR(config->args, where, "-exp_name", "rawTemplate.exp_name", "==");
     2664        PXOPT_COPY_STR(config->args, where, "-warp_id", "warpTemplate.warp_id", "==");
     2665        PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawTemplate.dateobs",  ">=");
     2666        PXOPT_COPY_TIME(config->args, where, "-dateobs_end",   "rawTemplate.dateobs",  "<=");
     2667        PXOPT_COPY_STR(config->args, where, "-filter",     "rawTemplate.filter", "LIKE");
     2668    }
     2669
     2670    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     2671    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     2672    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     2673    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
     2674
     2675
     2676    psString where2 = NULL;
     2677    pxmagicAddWhere(config, &where2, "diffRun");
     2678    pxspaceAddWhere(config, &where2, template ? "rawTemplate" : "rawInput");
     2679    psString query = pxDataGet("difftool_listrun.sql");
     2680    if (!query) {
     2681        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     2682        return false;
     2683    }
     2684
     2685    if (psListLength(where->list)) {
     2686        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     2687        psStringAppend(&query, " WHERE %s", whereClause);
     2688        psFree(whereClause);
     2689    } else if (where2) {
     2690        psStringAppend(&query, " WHERE diffRun.diff_id is not null %s", where2);
     2691    } else if (!all) {
     2692        psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required");
     2693        return false;
     2694    }
     2695    psFree(where);
     2696
     2697    if (pstamp_order) {
     2698        if (template) {
     2699            psStringAppend(&query, " ORDER BY rawTemplate.exp_id, diff_id DESC");
     2700        } else {
     2701            psStringAppend(&query, " ORDER BY rawInput.exp_id, diff_id DESC");
     2702        }
     2703    }
     2704           
     2705    // treat limit == 0 as "no limit"
     2706    if (limit) {
     2707        psString limitString = psDBGenerateLimitSQL(limit);
     2708        psStringAppend(&query, " %s", limitString);
     2709        psFree(limitString);
     2710    }
     2711
     2712    if (!p_psDBRunQuery(config->dbh, query)) {
     2713        psError(PS_ERR_UNKNOWN, false, "database error");
     2714        psFree(query);
     2715        return false;
     2716    }
     2717    psFree(query);
     2718
     2719    psArray *output = p_psDBFetchResult(config->dbh);
     2720    if (!output) {
     2721        psErrorCode err = psErrorCodeLast();
     2722        switch (err) {
     2723            case PS_ERR_DB_CLIENT:
     2724                psError(PXTOOLS_ERR_SYS, false, "database error");
     2725            case PS_ERR_DB_SERVER:
     2726                psError(PXTOOLS_ERR_PROG, false, "database error");
     2727            default:
     2728                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     2729        }
     2730
     2731        return false;
     2732    }
     2733    if (!psArrayLength(output)) {
     2734        psTrace("difftool", PS_LOG_INFO, "no rows found");
     2735        psFree(output);
     2736        return true;
     2737    }
     2738
     2739    if (psArrayLength(output)) {
     2740        // negative simple so the default is true
     2741        if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) {
     2742            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     2743            psFree(output);
     2744            return false;
     2745        }
     2746    }
     2747
     2748    psFree(output);
     2749
     2750    return true;
     2751}
Note: See TracChangeset for help on using the changeset viewer.