IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18480


Ignore:
Timestamp:
Jul 11, 2008, 10:32:44 AM (18 years ago)
Author:
eugene
Message:

major cleanup of argument handling

Location:
branches/eam_branch_20080706/ippTools/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080706/ippTools/src/dettool.c

    r18468 r18480  
    1818 */
    1919
    20 #ifdef HAVB_CONFIG_H
    21 #include <config.h>
    22 #endif
    23 
    24 #include <stdio.h>
    25 #include <string.h>
    26 #include <stdlib.h>
    27 #include <stdint.h>
    28 #include <inttypes.h>
    29 
    30 #include <ippdb.h>
    31 
    32 #include "pxtools.h"
    3320#include "dettool.h"
    3421
     
    9885//static psArray *searchInputImfiles(pxConfig *config, const char *det_id);
    9986static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS64 det_id, psS32 iteration);
    100 static psArray *searchRawImfiles(pxConfig *config, psMetadata *where);
     87static psArray *searchRawImfiles(pxConfig *config);
    10188static bool startNewIteration(pxConfig *config, psS64 det_id);
    10289static psS32 incrementIteration(pxConfig *config, psS64 det_id);
     
    812799    }
    813800
    814     if (camera) {
    815         psFree(detRun->camera);
    816         detRun->camera = psStringCopy(camera);
    817     }
    818 
    819     if (telescope) {
    820         psFree(detRun->telescope);
    821         detRun->telescope = psStringCopy(telescope);
    822     }
    823 
    824801    if (exp_type) {
    825802        psFree(detRun->exp_type);
     
    16301607    if (!query) {
    16311608        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    1632         psFree(where);
    16331609        return false;
    16341610    }
     
    18411817
    18421818// this is NOT a command-line mode : it is used by 'addstackedMode'
    1843 static psArray *searchRawImfiles(pxConfig *config, psMetadata *where)
     1819static psArray *searchRawImfiles(pxConfig *config)
    18441820{
    18451821    PS_ASSERT_PTR_NON_NULL(config, NULL);
     
    24602436
    24612437    if (psListLength(where->list)) {
    2462         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedImfile");
     2438        psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile");
    24632439        psStringAppend(&query, " AND %s", whereClause);
    24642440        psFree(whereClause);
     
    25342510{
    25352511    PS_ASSERT_PTR_NON_NULL(config, false);
    2536 
    2537     // required
    2538     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    2539 
     2512   
     2513    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     2514    PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
    25402515    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    2541 
    2542     // Required if code == 0
    2543     PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
    2544 
    2545     // optional
     2516    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
    25462517    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    25472518    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
     
    25542525    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    25552526
    2556     // default values
    2557     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
    2558 
    25592527    psString query = pxDataGet("dettool_tonormalizedexp.sql");
    25602528    if (!query) {
     
    25632531    }
    25642532
    2565     psStringAppend(&query,
    2566             " WHERE det_id = %s"
    2567             " AND iteration = %d", det_id, iteration);
    2568 
     2533    // XXX in some other places, we put the arguments in the .sql and supply them to RunQuery
     2534    psStringAppend(&query, " WHERE det_id = %s AND iteration = %d", det_id, iteration);
    25692535
    25702536    if (!p_psDBRunQuery(config->dbh, query)) {
     
    26152581    PS_ASSERT_PTR_NON_NULL(config, false);
    26162582
     2583    psMetadata *where = psMetadataAlloc();
     2584    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     2585    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     2586    PXOPT_COPY_STR(config->args, where, "-recip",  "recipe", "==");
     2587
    26172588    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    26182589    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    26192590    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    26202591
    2621     psString query = psStringCopy(
    2622         "SELECT"
    2623         "   detNormalizedExp.*"
    2624         " FROM detNormalizedExp"
    2625         " JOIN detRun"
    2626         "   USING(det_id, iteration)"
    2627         " WHERE"
    2628         "   detRun.state = 'run'"
    2629         "   AND detRun.mode = 'master'"
    2630     );
    2631 
    2632     if (config->where) {
    2633         psString whereClause = psDBGenerateWhereSQL(config->where, NULL);
     2592    psString query = pxDataGet("dettool_normalizedexp.sql");
     2593    if (!query) {
     2594        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     2595        return false;
     2596    }
     2597
     2598    if (psListLength(where->list)) {
     2599        psString whereClause = psDBGenerateWhereSQL(where, NULL);
    26342600        psStringAppend(&query, " %s", whereClause);
    26352601        psFree(whereClause);
    26362602    }
     2603    psFree(where);
    26372604
    26382605    if (faulted) {
     
    26872654    PS_ASSERT_PTR_NON_NULL(config, false);
    26882655
     2656    psMetadata *where = psMetadataAlloc();
     2657    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     2658    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     2659    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
     2660
    26892661    psString query = pxDataGet("dettool_revertnormalizedexp.sql");
    26902662    if (!query) {
     
    26932665    }
    26942666
    2695     if (config->where) {
    2696         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedExp");
     2667    if (psListLength(where->list)) {
     2668        psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedExp");
    26972669        psStringAppend(&query, " AND %s", whereClause);
    26982670        psFree(whereClause);
    26992671    }
     2672    psFree(where);
    27002673
    27012674    if (!p_psDBRunQuery(config->dbh, query)) {
     
    27272700        return false;
    27282701    }
    2729 
    2730     // XXX does it make sense to accept any search params?
    2731 #if 0
    2732     if (config->where) {
    2733         psString whereClause = psDBGenerateWhereConditionSQL(config->where);
    2734         psStringAppend(&query, " AND %s", whereClause);
    2735         psFree(whereClause);
    2736     }
    2737 #endif
    27382702
    27392703    // treat limit == 0 as "no limit"
     
    27792743    PS_ASSERT_PTR_NON_NULL(config, false);
    27802744
    2781     // required
    2782     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    2783     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
    2784     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false);
    2785 
     2745   
     2746    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     2747    PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
     2748    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required
     2749    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required
    27862750    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    2787 
    2788     // Required if code == 0
    2789     PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
    2790     PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
    2791 
    2792     // optional
     2751    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); // Required if code == 0
     2752    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
    27932753    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    27942754    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
     
    27972757    PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false);
    27982758    PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false);
    2799 
    28002759    PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false);
    28012760    PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false);
     
    28042763    PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false);
    28052764    PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false);
    2806 
    28072765    PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false);
    28082766    PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false);
     
    28112769    PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false);
    28122770    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    2813 
    2814     // default values
    2815     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
    28162771
    28172772    if (!detResidImfileInsert(config->dbh,
     
    28542809    PS_ASSERT_PTR_NON_NULL(config, false);
    28552810
     2811    psMetadata *where = psMetadataAlloc();
     2812    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     2813    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     2814    PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
     2815    PXOPT_COPY_STR(config->args, where, "-recip",      "recipe", "==");
     2816
    28562817    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    28572818    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    28582819    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    28592820
    2860     // select detResidImfile.*
    2861     // by:
    2862     // where det_id, iteration, exp_id is not in detResidExp;
    2863 
    2864     psString query = psStringCopy(
    2865         "SELECT"
    2866         "   detRun.det_type,"
    2867         "   detRun.mode,"
    2868         "   detResidImfile.*,"
    2869         "   rawExp.exp_time"
    2870         " FROM detResidImfile"
    2871         " JOIN detRun"
    2872         "   USING(det_id, iteration)"
    2873         " JOIN rawExp"
    2874         "   USING(exp_id)"
    2875         " WHERE"
    2876     );
    2877     // NOTE the above WHERE is completed with the following line:
    2878 
     2821    psString query = pxDataGet("dettool_residimfile.sql");
     2822    if (!query) {
     2823        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     2824        return false;
     2825    }
     2826
     2827    // NOTE: the query ends in a WHERE, add the required restriction on detRun.state
    28792828    char *value = NULL;
    2880 
    2881     // add the two required restrictions: detRun.state and detRun.mode
    28822829    bool status;
    28832830    if ((value = psMetadataLookupStr(&status, config->args, "-select_state"))) {
     
    28872834    }
    28882835
    2889     if (config->where) {
    2890         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidImfile");
     2836    if (psListLength(where->list)) {
     2837        psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile");
    28912838        psStringAppend(&query, " AND %s", whereClause);
    28922839        psFree(whereClause);
    28932840    }
     2841    psFree(where);
    28942842
    28952843    if (faulted) {
     
    29432891    PS_ASSERT_PTR_NON_NULL(config, false);
    29442892
     2893    psMetadata *where = psMetadataAlloc();
     2894    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     2895    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     2896    PXOPT_COPY_STR(config->args, where, "-exp_id",  "exp_id", "==");
     2897    PXOPT_COPY_STR(config->args, where, "-class_id",  "class_id", "==");
     2898    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
     2899
    29452900    psString query = pxDataGet("dettool_revertresidimfile.sql");
    29462901    if (!query) {
     
    29492904    }
    29502905
    2951     if (config->where) {
    2952         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidImfile");
     2906    if (psListLength(where->list)) {
     2907        psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile");
    29532908        psStringAppend(&query, " AND %s", whereClause);
    29542909        psFree(whereClause);
    29552910    }
     2911    psFree(where);
    29562912
    29572913    if (!p_psDBRunQuery(config->dbh, query)) {
     
    29712927
    29722928
     2929/*
     2930  The SQL returns a list of exposures for which all component class ids have had residuals
     2931  created.  This list includes the detrend id, iteration, exposure id, detrend type, and
     2932  whether the exposure was included in the stack for this iteration.
     2933*/
     2934
    29732935static bool toresidexpMode(pxConfig *config)
    29742936{
    29752937    PS_ASSERT_PTR_NON_NULL(config, false);
    2976 
    2977     /*
    2978 which returns a list of exposures for which all component class ids
    2979 have had residuals created.  This list includes the detrend id,
    2980 iteration, exposure id, detrend type, and whether the exposure was
    2981 included in the stack for this iteration.
    2982     */
    29832938
    29842939    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    29902945        return false;
    29912946    }
    2992 
    2993     // XXX does it make sense to accept any search params?
    2994 #if 0
    2995     if (config->where) {
    2996         psString whereClause = psDBGenerateWhereConditionSQL(config->where);
    2997         psStringAppend(&query, " AND %s", whereClause);
    2998         psFree(whereClause);
    2999     }
    3000 #endif
    30012947
    30022948    // treat limit == 0 as "no limit"
     
    30372983}
    30382984
     2985/*
     2986  The SQL returns a list of exposures for which all component class ids have had residuals
     2987  created.  This list includes the detrend id, iteration, exposure id, detrend type, and
     2988  whether the exposure was included in the stack for this iteration.
     2989*/
     2990
    30392991static bool addresidexpMode(pxConfig *config)
    30402992{
    30412993    PS_ASSERT_PTR_NON_NULL(config, false);
    30422994
    3043     // required
    3044     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    3045     PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false);
    3046 
     2995    // limit search by det_id, iteration, exp_id
     2996    psMetadata *where = psMetadataAlloc();
     2997    PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");
     2998    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     2999    PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "==");
     3000
     3001    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     3002    PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
     3003    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required
    30473004    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    3048 
    3049     // Required if code == 0
    3050     PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false);
    3051 
    3052     // optional
     3005    PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0
    30533006    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    30543007    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
     
    30573010    PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false);
    30583011    PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false);
    3059 
    30603012    PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false);
    30613013    PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false);
     
    30643016    PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false);
    30653017    PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false);
    3066 
    30673018    PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false);
    30683019    PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false);
     
    30713022    PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false);
    30723023    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    3073 
    3074     // default values
    3075     PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);
    30763024    PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false);
    3077 
    3078     /*
    3079 which returns a list of exposures for which all component class ids
    3080 have had residuals created.  This list includes the detrend id,
    3081 iteration, exposure id, detrend type, and whether the exposure was
    3082 included in the stack for this iteration.
    3083     */
    30843025
    30853026    psString query = pxDataGet("dettool_toresidexp.sql");
     
    30893030    }
    30903031
    3091     {
    3092         // build a query to search by det_id, iteration, exp_id
    3093         psMetadata *where = psMetadataAlloc();
    3094 
    3095         PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");
    3096         PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
    3097         PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "==");
    3098 
    3099 
    3100         // there's not
    3101         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    3102         psFree(where);
    3103         if (whereClause) {
    3104             psStringAppend(&query, " WHERE %s", whereClause);
    3105             psFree(whereClause);
    3106         }
    3107     }
     3032    if (psListLength(where->list)) {
     3033        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     3034        psStringAppend(&query, " WHERE %s", whereClause);
     3035        psFree(whereClause);
     3036    }
     3037    psFree(where);
    31083038
    31093039    if (!p_psDBRunQuery(config->dbh, query)) {
     
    31643094    PS_ASSERT_PTR_NON_NULL(config, false);
    31653095
    3166     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    3167     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     3096    psMetadata *where = psMetadataAlloc();
     3097    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     3098    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     3099    PXOPT_COPY_STR(config->args, where, "-exp_id",    "exp_id", "==");
     3100    PXOPT_COPY_STR(config->args, where, "-recip",     "recipe", "==");
     3101
     3102    PXOPT_LOOKUP_U64(limit,    config->args, "-limit", false, false);
     3103    PXOPT_LOOKUP_BOOL(simple,  config->args, "-simple", false);
    31683104    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    3169 
    3170     psString query = psStringCopy(
    3171         "SELECT"
    3172         "   detRun.mode,"
    3173         "   detResidExp.*,"
    3174         "   detInputExp.include"
    3175         " FROM detRun"
    3176         " JOIN detInputExp"
    3177         "   USING(det_id, iteration)"
    3178         " JOIN detResidExp"
    3179         "   USING(det_id, iteration, exp_id)"
    3180         " WHERE"
    3181         "   detRun.state = 'run'"
    3182     );
    3183 
    3184     if (config->where) {
    3185         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidExp");
     3105    PXOPT_LOOKUP_BOOL(reject,  config->args, "-reject", false);
     3106
     3107    psString query = pxDataGet("dettool_residexp.sql");
     3108    if (!query) {
     3109        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     3110        return false;
     3111    }
     3112
     3113    if (psListLength(where->list)) {
     3114        psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp");
    31863115        psStringAppend(&query, " AND %s", whereClause);
    31873116        psFree(whereClause);
    31883117    }
     3118    psFree(where);
    31893119
    31903120    if (faulted) {
     
    31963126    }
    31973127
     3128    // list only accepted rows
     3129    // XXX the usage of this flag is unclear : -reject means "accepted"?
     3130    if (reject) {
     3131        psStringAppend(&query, " %s", "AND detResidExp.accept != 0");
     3132    }
     3133
    31983134    // treat limit == 0 as "no limit"
    31993135    if (limit) {
     
    32383174    PS_ASSERT_PTR_NON_NULL(config, false);
    32393175
     3176    psMetadata *where = psMetadataAlloc();
     3177    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     3178    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     3179    PXOPT_COPY_STR(config->args, where, "-exp_id",    "exp_id", "==");
     3180    PXOPT_COPY_S16(config->args, where, "-code",      "fault", "==");
     3181
    32403182    psString query = pxDataGet("dettool_revertresidexp.sql");
    32413183    if (!query) {
     
    32443186    }
    32453187
    3246     if (config->where) {
    3247         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidExp");
     3188    if (psListLength(where->list)) {
     3189        psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp");
    32483190        psStringAppend(&query, " AND %s", whereClause);
    32493191        psFree(whereClause);
    32503192    }
     3193    psFree(where);
    32513194
    32523195    if (!p_psDBRunQuery(config->dbh, query)) {
     
    32663209
    32673210
     3211static bool updateresidexpMode(pxConfig *config)
     3212{
     3213    PS_ASSERT_PTR_NON_NULL(config, false);
     3214
     3215    PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false);
     3216
     3217    // build a query to search by det_id, iteration, exp_id
     3218    psMetadata *where = psMetadataAlloc();
     3219    PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");
     3220    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     3221    PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "==");
     3222
     3223    // find the values we're going to set
     3224    // copy everything but det_id, iteration, & exp_id from the args and
     3225    // remove the '-' prefix
     3226    psMetadata *set = psMetadataAlloc();
     3227    PXOPT_COPY_STR(config->args, set, "-recip", "recipe", "==");
     3228    PXOPT_COPY_F64(config->args, set, "-bg", "bg", "==");
     3229    PXOPT_COPY_F64(config->args, set, "-bg_stdev", "bg_stdev", "==");
     3230    PXOPT_COPY_F64(config->args, set, "-bg_mean_stdev", "bg_mean_stdev", "==");
     3231    PXOPT_COPY_STR(config->args, set, "-path_base", "path_base", "==");
     3232
     3233    // this can't be PXOPT_ macro-ized as reject is !'d
     3234    if (!psMetadataAddBool(set, PS_LIST_TAIL, "accept", 0, "==", !reject)) {
     3235        psError(PS_ERR_UNKNOWN, false, "failed to add item accept");
     3236        psFree(set);
     3237        psFree(where);
     3238        return false;
     3239    }
     3240
     3241    long changed = psDBUpdateRows(config->dbh, "detResidExp", where, set);
     3242    psFree(set);
     3243    psFree(where);
     3244
     3245    if (changed < 0) {
     3246        psError(PS_ERR_UNKNOWN, false, "no rows were updated");
     3247        return false;
     3248    }
     3249
     3250    return true;
     3251}
     3252
     3253/* The SQL returns a list of detrend runs (with detrend id, iteration and detrend type) which
     3254 * have completed all residexps.
     3255 */
     3256
    32683257static bool todetrunsummaryMode(pxConfig *config)
    32693258{
     
    32723261    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    32733262    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    3274 
    3275     /* which returns a list of detrend runs (with detrend id, iteration and
    3276      * detrend type) which have completed all residexps.
    3277      */
    32783263
    32793264    psString query = pxDataGet("dettool_todetrunsummary.sql");
     
    32823267        return false;
    32833268    }
    3284 
    3285     // XXX does it make sense to accept any search params?
    3286 #if 0
    3287     if (config->where) {
    3288         psString whereClause = psDBGenerateWhereConditionSQL(config->where);
    3289         psStringAppend(&query, " AND %s", whereClause);
    3290         psFree(whereClause);
    3291     }
    3292 #endif
    32933269
    32943270    // treat limit == 0 as "no limit"
     
    33293305}
    33303306
    3331 static bool updateresidexpMode(pxConfig *config)
    3332 {
    3333     PS_ASSERT_PTR_NON_NULL(config, false);
    3334 
    3335     PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false);
    3336 
     3307// this function is used to generate the detrunSummary entries used below
     3308// XXX why is this a separate function?  roll it back into adddetrunsummary?
     3309static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row)
     3310{
     3311    PS_ASSERT_PTR_NON_NULL(config, false);
     3312
     3313    bool status = false;
     3314    // from row
     3315    psS64 det_id = psMetadataLookupS64(&status, row, "det_id");
     3316    if (!status) {
     3317        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");
     3318        return false;
     3319    }
     3320    psS32 iteration = psMetadataLookupS32(&status, row, "iteration");
     3321    if (!status) {
     3322        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration");
     3323        return false;
     3324    }
     3325
     3326    // optional
     3327    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
     3328    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
     3329    PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false);
     3330
     3331    // default values
     3332    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
     3333    PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
     3334
     3335    return detRunSummaryRowAlloc(
     3336            det_id,
     3337            iteration,
     3338            bg,
     3339            bg_stdev,
     3340            bg_mean_stdev,
     3341            accept,
     3342            code
     3343        );
     3344}
     3345
     3346static bool adddetrunsummaryMode(pxConfig *config)
     3347{
     3348    PS_ASSERT_PTR_NON_NULL(config, false);
     3349   
    33373350    // build a query to search by det_id, iteration, exp_id
    33383351    psMetadata *where = psMetadataAlloc();
    33393352    PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");
    33403353    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
    3341     PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "==");
    3342 
    3343     // find the values we're going to set
    3344     // copy everything but det_id, iteration, & exp_id from the args and
    3345     // remove the '-' prefix
    3346     psMetadata *set = psMetadataAlloc();
    3347     // XXX if PXOPT_COPY_* errors here the where md will leak
    3348     PXOPT_COPY_STR(config->args, set, "-recip", "recipe", "==");
    3349     PXOPT_COPY_F64(config->args, set, "-bg", "bg", "==");
    3350     PXOPT_COPY_F64(config->args, set, "-bg_stdev", "bg_stdev", "==");
    3351     PXOPT_COPY_F64(config->args, set, "-bg_mean_stdev", "bg_mean_stdev", "==");
    3352     PXOPT_COPY_STR(config->args, set, "-path_base", "path_base", "==");
    3353 
    3354     // this can't be PXOPT_ macro-ized as reject is !'d
    3355     if (!psMetadataAddBool(set, PS_LIST_TAIL, "accept", 0, "==", !reject)) {
    3356         psError(PS_ERR_UNKNOWN, false, "failed to add item accept");
    3357         psFree(set);
    3358         psFree(where);
    3359         return false;
    3360     }
    3361 
    3362     long changed = psDBUpdateRows(config->dbh, "detResidExp", where, set);
    3363     psFree(set);
    3364     psFree(where);
    3365 
    3366     if (changed < 0) {
    3367         psError(PS_ERR_UNKNOWN, false, "no rows were updated");
    3368         return false;
    3369     }
    3370 
    3371     return true;
    3372 }
    3373 
    3374 static bool adddetrunsummaryMode(pxConfig *config)
    3375 {
    3376     PS_ASSERT_PTR_NON_NULL(config, false);
    3377 
    3378     // required
    3379     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    3380 
    3381     // optional
     3354
     3355    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
    33823356    PXOPT_LOOKUP_BOOL(again, config->args, "-again", false);
     3357
     3358    // The values supplied as arguments on the command (eg, -bg) are parsed
     3359    // by mdToDetRunSummary below.
     3360    // XXX why is there ever more than one?
    33833361
    33843362    psString query = pxDataGet("dettool_find_completed_runs.sql");
     
    33883366    }
    33893367
    3390     // build a query to search by det_id, iteration, exp_id
    3391     psMetadata *where = psMetadataAlloc();
    3392     PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "==");
    3393     PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
    3394 
    3395     {
    3396         // there's not
     3368    if (psListLength(where->list)) {
    33973369        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    3398         psFree(where);
    3399         if (whereClause) {
    3400             psStringAppend(&query, " WHERE %s", whereClause);
    3401             psFree(whereClause);
    3402         }
    3403     }
     3370        psStringAppend(&query, " WHERE %s", whereClause);
     3371        psFree(whereClause);
     3372    }
     3373    psFree(where);
    34043374
    34053375    if (!p_psDBRunQuery(config->dbh, query)) {
     
    34283398    }
    34293399
     3400    // XXX why is there ever more than one result here?
    34303401    for (long i = 0; i < psArrayLength(output); i++) {
    34313402        psMetadata *row = output->data[i];
     
    34563427
    34573428    // XXX this logic does not deal with the case of -code being set
     3429    // XXX it should be an error for -again and -code to both be set
    34583430    if (again) {
    34593431        if (!startNewIteration(config, (psS64)atoll(det_id))) {
     
    34823454}
    34833455
    3484 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row)
    3485 {
    3486     PS_ASSERT_PTR_NON_NULL(config, false);
    3487 
    3488     bool status = false;
    3489     // from row
    3490     psS64 det_id = psMetadataLookupS64(&status, row, "det_id");
    3491     if (!status) {
    3492         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");
    3493         return false;
    3494     }
    3495     psS32 iteration = psMetadataLookupS32(&status, row, "iteration");
    3496     if (!status) {
    3497         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration");
    3498         return false;
    3499     }
    3500 
    3501     // optional
    3502     PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    3503     PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
    3504     PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false);
    3505     // default values
    3506     PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
    3507     PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    3508 
    3509     return detRunSummaryRowAlloc(
    3510             det_id,
    3511             iteration,
    3512             bg,
    3513             bg_stdev,
    3514             bg_mean_stdev,
    3515             accept,
    3516             code
    3517         );
    3518 }
    3519 
    35203456static bool detrunsummaryMode(pxConfig *config)
    35213457{
    35223458    PS_ASSERT_PTR_NON_NULL(config, false);
     3459
     3460    psMetadata *where = psMetadataAlloc();
     3461    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     3462    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
    35233463
    35243464    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    35263466    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
    35273467
    3528     psString query = psStringCopy(
    3529         "SELECT DISTINCT\n"
    3530         "   detRunSummary.*,\n"
    3531         "   detRun.det_type,\n"
    3532         "   detRun.mode\n"
    3533         " FROM detRun\n"
    3534         " JOIN detRunSummary\n"
    3535         "   USING(det_id, iteration)\n"
    3536         " WHERE\n"
    3537         "   detRun.state = 'run'\n"
    3538         );
    3539 
    3540     if (config->where) {
    3541         psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL);
     3468    psString query = pxDataGet("dettool_detrunsummary.sql");
     3469    if (!query) {
     3470        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     3471        psFree(where);
     3472        return false;
     3473    }
     3474
     3475    if (psListLength(where->list)) {
     3476        psString whereClause = psDBGenerateWhereConditionSQL(where, "NULL");
    35423477        psStringAppend(&query, " AND %s", whereClause);
    35433478        psFree(whereClause);
    35443479    }
     3480    psFree(where);
    35453481
    35463482    if (faulted) {
     
    35943530    PS_ASSERT_PTR_NON_NULL(config, false);
    35953531
     3532    psMetadata *where = psMetadataAlloc();
     3533    PXOPT_COPY_STR(config->args, where, "-det_id",    "det_id", "==");
     3534    PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "==");
     3535    PXOPT_COPY_STR(config->args, where, "-code",      "fault", "==");
     3536
    35963537    psString query = pxDataGet("dettool_revertdetrunsummary.sql");
    35973538    if (!query) {
     
    36003541    }
    36013542
    3602     if (config->where) {
    3603         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detRunSummary");
     3543    if (psListLength(where->list)) {
     3544        psString whereClause = psDBGenerateWhereConditionSQL(where, "detRunSummary");
    36043545        psStringAppend(&query, " AND %s", whereClause);
    36053546        psFree(whereClause);
    36063547    }
     3548    psFree(where);
    36073549
    36083550    if (!p_psDBRunQuery(config->dbh, query)) {
     
    36253567{
    36263568    PS_ASSERT_PTR_NON_NULL(config, false);
    3627 
    3628     // required
    3629     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    3630 
     3569   
     3570    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
    36313571    PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);
    36323572    PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false);
     
    36563596    PS_ASSERT_PTR_NON_NULL(config, false);
    36573597
    3658     // det_id is required
    3659     // XXX this isn't strictly nessicary but not having the det_id complicates
    3660     // incrementing the iteration number
    3661     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    3662 
     3598    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
    36633599    PXOPT_LOOKUP_BOOL(again, config->args, "-again", false);
    36643600    PXOPT_LOOKUP_STR(state, config->args, "-state", false, false);
     3601
    36653602    // either -rerun or -state must be specified
    36663603    if (!(again || state)) {
     
    36693606    }
    36703607    if (again && state) {
    3671         psError(PS_ERR_UNKNOWN, true, "either -again or -state must be specified");
     3608        psError(PS_ERR_UNKNOWN, true, "-accept and -reject are exclusive");
    36723609        return false;
    36733610    }
     
    36883625}
    36893626
     3627// used by updatedetrunMode
    36903628static bool startNewIteration(pxConfig *config, psS64 det_id)
    36913629{
     
    36983636    }
    36993637
    3700     // XXX this query was not restricted by det_id, resulting
    3701     // in an inconsistent UPDATE below.  I added this AND clause
    3702     // though there may be a cleaner method (EAM 2006.10.08)
     3638    // restrict the update only to the specified det_id
    37033639    psStringAppend(&query, " WHERE det_id = %" PRId64 , det_id);
    37043640
     
    39533889    PS_ASSERT_PTR_NON_NULL(config, false);
    39543890
    3955     // required
    3956     PXOPT_LOOKUP_STR(det_type, config->args, "-det_type", true, false);
    3957     PXOPT_LOOKUP_STR(filelevel, config->args, "-filelevel", false, false);
    3958 
    3959     // optional
     3891    PXOPT_LOOKUP_STR(det_type, config->args, "-det_type", true, false); // required
     3892    PXOPT_LOOKUP_STR(filelevel, config->args, "-filelevel", true, false); // required
    39603893    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false);
    39613894    PXOPT_LOOKUP_STR(camera, config->args, "-inst", false, false);
     
    39803913    PXOPT_LOOKUP_STR(parent, config->args, "-parent", false, false);
    39813914    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    3982 
    3983     // default
    39843915    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    39853916
     
    39933924                      0,            // the iteration is fixed at 0
    39943925                      det_type,
    3995                       "register",   // mode
     3926                      "register",   // mode is required to be "register"
    39963927                      "register",   // state
    39973928                      filelevel,
     
    40643995}
    40653996
     3997// NOTE : this function is also used by addcorrectimfileMode
    40663998bool register_detrend_imfileMode(pxConfig *config)
    40673999{
    40684000    PS_ASSERT_PTR_NON_NULL(config, false);
    4069 
    4070     // required
    4071     PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false);
    4072     PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false);
    4073     PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false);
    4074 
    4075     // optional
     4001   
     4002    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     4003    PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required
     4004    PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); // required
    40764005    PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    40774006    PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
  • branches/eam_branch_20080706/ippTools/src/dettool.h

    r18157 r18480  
    1717 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1818 */
     19
     20#ifdef HAVE_CONFIG_H
     21#include <config.h>
     22#endif
    1923
    2024#ifndef DETTOOL_H
  • branches/eam_branch_20080706/ippTools/src/dettoolConfig.c

    r18468 r18480  
    1818 */
    1919
    20 #ifdef HAVE_CONFIG_H
    21 #include <config.h>
    22 #endif
    23 
    24 #include <psmodules.h>
    25 
    26 #include "pxtools.h"
    2720#include "dettool.h"
    2821
     
    167160    psMetadataAddStr(definebydetrunArgs, PS_LIST_TAIL, "-set_input_end", 0,       "require input exp to be in this period", NULL);
    168161
    169     // XXX EAM : it looks like the corresponding dettool functions don't exist:
     162    // *** these are in dettool_correction.c ***
    170163    // -makecorrection
    171164    psMetadata *makecorrectionArgs = psMetadataAlloc();
     
    224217    psMetadataAddStr(inputArgs, PS_LIST_TAIL, "-det_id", 0,            "search for detrend ID", NULL);
    225218    psMetadataAddS32(inputArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
    226     psMetadataAddS64(inputArgs, PS_LIST_TAIL, "-exp_id",  0,            "search for exp ID", NULL);
     219    psMetadataAddS64(inputArgs, PS_LIST_TAIL, "-exp_id",  0,            "search for exp ID", 0);
    227220    psMetadataAddBool(inputArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    228221
     
    428421    psMetadataAddS16(revertnormalizedimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
    429422
    430     XXX EAM : cleaned to this point
    431         break into separate files
    432 
    433423    // -tonormalizedexp
    434424    psMetadata *tonormalizedexpArgs = psMetadataAlloc();
     
    440430    psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-det_id",  0,            "define detrend ID (required)", NULL);
    441431    psMetadataAddS32(addnormalizedexpArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
     432    psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    442433    psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-recip",  0,            "search for recipe", NULL);
    443434    psMetadataAddF64(addnormalizedexpArgs, PS_LIST_TAIL, "-bg",  0,            "define exposure background", NAN);
     
    450441    psMetadataAddF64(addnormalizedexpArgs, PS_LIST_TAIL, "-user_5",  0,            "define user statistic (5)", NAN);
    451442    psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
    452     psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    453443
    454444    // -normalizedexp
    455445    psMetadata *normalizedexpArgs = psMetadataAlloc();
    456     psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-det_id",  0,            "define detrend ID", NULL);
    457     psMetadataAddS32(normalizedexpArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
     446    psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-det_id",  0,            "search by detrend ID", NULL);
     447    psMetadataAddS32(normalizedexpArgs, PS_LIST_TAIL, "-iteration",  0,            "search by iteration number", 0);
    458448    psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-recip",  0,            "search for recipe", NULL);
    459     psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg",  0,            "define exposure background", NAN);
    460     psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg_stdev",  0,            "define exposure background stdev", NAN);
    461     psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg_mean_stdev",  0,            "define exposure background mean stdev", NAN);
    462     psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
    463449    psMetadataAddU64(normalizedexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    464450    psMetadataAddBool(normalizedexpArgs, PS_LIST_TAIL, "-faulted",  0,            "only return imfiles with a fault status set", false);
     
    475461    psMetadataAddU64(toresidimfileArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    476462    psMetadataAddBool(toresidimfileArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    477 
    478     // -toresidexp
    479     psMetadata *toresidexpArgs = psMetadataAlloc();
    480     psMetadataAddU64(toresidexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    481     psMetadataAddBool(toresidexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    482463
    483464    // -addresidimfile
     
    487468    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "define detrend ID (required)", NULL);
    488469    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "define class ID (required)", NULL);
     470    psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    489471    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri",  0,            "define resid file URI", NULL);
    490472    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-recip",  0,            "define recipe", NULL);
     
    507489    psMetadataAddF64(addresidimfileArgs, PS_LIST_TAIL, "-user_5",  0,            "define user statistic (5)", NAN);
    508490    psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
    509     psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    510491
    511492    // -residimfile
     
    513494    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-det_id",  0,            "search for detrend ID", NULL);
    514495    psMetadataAddS32(residimfileArgs, PS_LIST_TAIL, "-iteration",  0,            "search for iteration number", 0);
    515     psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "define detrend ID", NULL);
     496    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by detrend ID", NULL);
    516497    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "search for class ID", NULL);
    517498    psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-recip",  0,            "search for recipe", NULL);
     
    523504    // -revertresidimfile
    524505    psMetadata *revertresidimfileArgs =  psMetadataAlloc();
    525     psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-det_id", 0,            "search by detrend ID (required)", NULL);
    526     psMetadataAddS32(revertresidimfileArgs, PS_LIST_TAIL, "-iteration", 0,            "search by iteration number", 0);
    527     psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by detrend ID", NULL);
    528     psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,            "search for class ID", NULL);
    529     psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
     506    psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-det_id", 0,          "search by detrend ID (required)", NULL);
     507    psMetadataAddS32(revertresidimfileArgs, PS_LIST_TAIL, "-iteration", 0,       "search by iteration number", 0);
     508    psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-exp_id",  0,         "search by detrend ID", NULL);
     509    psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-class_id",  0,       "search for class ID", NULL);
     510    psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-code",  0,           "search by fault code", 0);
     511
     512    // -toresidexp
     513    psMetadata *toresidexpArgs = psMetadataAlloc();
     514    psMetadataAddU64(toresidexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     515    psMetadataAddBool(toresidexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    530516
    531517    // -addresidexp
     
    534520    psMetadataAddS32(addresidexpArgs, PS_LIST_TAIL, "-iteration",  0,            "define iteration number", 0);
    535521    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "define detrend ID (required)", NULL);
     522    psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    536523    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-recip",  0,            "define recipe", NULL);
    537524    psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-bg",  0,            "define exposure background", NAN);
     
    553540    psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-user_5",  0,            "define user statistic (5)", NAN);
    554541    psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-path_base",  0,            "define base output location", NULL);
    555     psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-code",  0,            "set fault code", 0);
    556542    psMetadataAddBool(addresidexpArgs, PS_LIST_TAIL, "-reject",  0,            "exposure is not to be stacked in the next iteration", false);
    557543
     
    562548    psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "search for exp ID", NULL);
    563549    psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-recip",  0,            "search for recipe", NULL);
     550    psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-reject",  0,            "search for acceptable residuals", false);
    564551    psMetadataAddU64(residexpArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    565552    psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-faulted",  0,            "only return imfiles with a fault status set", false);
    566     psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-reject",  0,            "search for acceptable residuals", false);
    567553    psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    568554
     
    573559    psMetadataAddStr(revertresidexpArgs, PS_LIST_TAIL, "-exp_id",  0,            "search by detrend ID", NULL);
    574560    psMetadataAddS16(revertresidexpArgs, PS_LIST_TAIL, "-code",  0,            "search by fault code", 0);
    575 
    576     // -todetrunsummary
    577     psMetadata *todetrunsummaryArgs = psMetadataAlloc();
    578     psMetadataAddBool(todetrunsummaryArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    579     psMetadataAddU64(todetrunsummaryArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    580561
    581562    // -updateresidexp
     
    591572    psMetadataAddBool(updateresidexpArgs, PS_LIST_TAIL, "-reject",  0,            "exposure is not to be stacked in the next iteration", false);
    592573
     574    // -todetrunsummary
     575    psMetadata *todetrunsummaryArgs = psMetadataAlloc();
     576    psMetadataAddBool(todetrunsummaryArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
     577    psMetadataAddU64(todetrunsummaryArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
     578
    593579    // -adddetrunsummary
    594580    psMetadata *adddetrunsummaryArgs = psMetadataAlloc();
     
    605591    psMetadata *detrunsummaryArgs = psMetadataAlloc();
    606592    psMetadataAddStr(detrunsummaryArgs, PS_LIST_TAIL, "-det_id",  0,            "search for detrend ID", NULL);
     593    psMetadataAddS32(detrunsummaryArgs, PS_LIST_TAIL, "-iteration",  0,            "search for iteration number", 0);
    607594    psMetadataAddU64(detrunsummaryArgs, PS_LIST_TAIL, "-limit",  0,                     "limit result set to N items", 0);
    608     psMetadataAddS32(detrunsummaryArgs, PS_LIST_TAIL, "-iteration",  0,            "search for iteration number", 0);
    609595    psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-faulted",  0,            "only return imfiles with a fault status set", false);
     596    psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    610597    psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-reject",  0,            "search for acceptable residuals", false);
    611     psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-simple",  0,            "use the simple output format", false);
    612598
    613599    // -revertdetrunsummary
     
    637623    psMetadata *register_detrendArgs = psMetadataAlloc();
    638624    psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-det_type",  0,            "define the type of detrend run (required)", NULL);
    639     psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-mode",  0,            "define the mode of this detrend run", "master");
    640625    psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-filelevel",  0,            "define filelevel (required)", NULL);
    641626    psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-workdir",  0,            "define workdir", NULL);
     
    648633    psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-exp_time_min",  0,            "define min exposure time", NAN);
    649634    psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-exp_time_max",  0,            "define max exposure time", NAN);
    650     psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_min",  0,            "define min ccd tempature", NAN);
    651     psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_max",  0,            "define max ccd tempature", NAN);
     635    psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_min",  0,            "define min ccd tempature", NAN);
     636    psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_max",  0,            "define max ccd tempature", NAN);
    652637    psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-posang_min",  0,            "define min rotator position angle", NAN);
    653638    psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-posang_max",  0,            "define max rotator position angle", NAN);
     
    750735    psFree(modes);
    751736
    752     // generate SQL where clause
    753     config->where = psMetadataAlloc();
    754 
    755     addWhereStr(det_id);
    756     PXOPT_ADD_WHERE_S32(iteration);
    757     PXOPT_ADD_WHERE_STR(det_type);
    758     PXOPT_ADD_WHERE_STR(exp_id);
    759     PXOPT_ADD_WHERE_STR(class_id);
    760     PXOPT_ADD_WHERE_STR_ALIAS("-inst","camera");
    761     PXOPT_ADD_WHERE_STR(telescope);
    762     PXOPT_ADD_WHERE_STR(exp_type);
    763     PXOPT_ADD_WHERE_S32(imfiles);
    764     PXOPT_ADD_WHERE_STR(filter);
    765     PXOPT_ADD_WHERE_STR(recipe);
    766     PXOPT_ADD_WHERE_S32(guide_version);
    767     PXOPT_ADD_WHERE_BOOL_ALIAS_INVERT("-reject", "accept");
    768     PXOPT_ADD_WHERE_S16_ALIAS("-code", "fault");
    769 
    770     if (config->where->list->n < 1) {
    771         psFree(config->where);
    772         config->where = NULL;
    773     }
    774 
    775737    // define Database handle, if used
    776738    // do this last so we don't setup a connection before CLI options are
  • branches/eam_branch_20080706/ippTools/src/dettool_correction.c

    r18336 r18480  
    1818 */
    1919
    20 #ifdef HAVB_CONFIG_H
    21 #include <config.h>
    22 #endif
    23 
    24 #include <stdio.h>
    25 #include <string.h>
    26 #include <stdlib.h>
    27 #include <stdint.h>
    28 #include <inttypes.h>
    29 
    30 #include <ippdb.h>
    31 
    32 #include "pxtools.h"
    3320#include "dettool.h"
    3421
     
    3724    PS_ASSERT_PTR_NON_NULL(config, false);
    3825
    39     bool status     = false;
    40     psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
    41     if (!status) {
    42         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
    43         return false;
    44     }
    45     if (!det_id) {
    46         psError(PS_ERR_UNKNOWN, true, "-det_id is required");
    47         return false;
    48     }
    49 
    50     psArray *runs = detRunSelectRowObjects(config->dbh, config->where, 1);
     26    PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required
     27    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); // optional
     28
     29    // build the needed where
     30    psMetadata *where = psMetadataAlloc();
     31    psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", (psS64)atoll(det_id));
     32    psArray *runs = detRunSelectRowObjects(config->dbh, where, 1);
     33    psFree (where);
     34
    5135    if (!psArrayLength(runs)) {
    5236        psError(PS_ERR_UNKNOWN, false, "database error");
     
    10387    }
    10488
    105     psArray *detRuns = NULL;
    106     {
    107         psMetadata *where = psMetadataAlloc();
    108         psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id);
    109         detRuns = psDBSelectRows(config->dbh, "detRun", where, 0);
    110         psFree(where);
    111     }
     89    psMetadata *where_new = psMetadataAlloc();
     90    psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id);
     91    psArray *detRuns = psDBSelectRows(config->dbh, "detRun", where_new, 0);
     92    psFree(where_new);
     93
    11294    if (!detRuns) {
    11395        psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created");
     
    118100        psAbort("found more then one detRun matching det_id %" PRId64 "(this should not happen)", new_det_id);
    119101        return false;
    120     }
    121 
    122     bool simple = false;
    123     {
    124         bool status = false;
    125         simple = psMetadataLookupBool(&status, config->args, "-simple");
    126         if (!status) {
    127             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    128             return false;
    129         }
    130102    }
    131103
     
    145117    PS_ASSERT_PTR_NON_NULL(config, false);
    146118
    147     bool status = false;
    148     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    149     if (!status) {
    150         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    151         return false;
    152     }
     119    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     120    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    153121
    154122    psString query = pxDataGet("dettool_tocorrectexp.sql");
     
    183151    }
    184152
    185     bool simple = false;
    186     {
    187         bool status = false;
    188         simple = psMetadataLookupBool(&status, config->args, "-simple");
    189         if (!status) {
    190             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    191             return false;
    192         }
    193     }
    194 
    195153    // negative simple so the default is true
    196154    if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) {
     
    209167    PS_ASSERT_PTR_NON_NULL(config, false);
    210168
    211     bool status = false;
    212     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    213     if (!status) {
    214         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    215         return false;
    216     }
     169    psMetadata *where = psMetadataAlloc();
     170    PXOPT_COPY_STR(config->args, where, "-det_type", "det_type", "==");
     171
     172    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     173    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    217174
    218175    psString query = pxDataGet("dettool_tocorrectimfile.sql");
     
    222179    }
    223180
    224     if (config->where) {
    225         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "det1");
     181    if (psListLength(where->list)) {
     182        // NOTE the SQL uses an intermediate table 'det1' for this query
     183        psString whereClause = psDBGenerateWhereConditionSQL(where, "det1");
    226184        psStringAppend(&query, " AND %s", whereClause);
    227185        psFree(whereClause);
    228186    }
     187    psFree (where);
    229188
    230189    // treat limit == 0 as "no limit"
     
    253212    }
    254213
    255     bool simple = false;
    256     {
    257         bool status = false;
    258         simple = psMetadataLookupBool(&status, config->args, "-simple");
    259         if (!status) {
    260             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    261             return false;
    262         }
    263     }
    264 
    265214    // negative simple so the default is true
    266215    if (!ippdbPrintMetadatas(stdout, output, "detPendingCorrectImfile", !simple)) {
     
    275224}
    276225
     226// NOTE : the command-line args are parsed by register_detrend_imfileMode
    277227bool addcorrectimfileMode(pxConfig *config)
    278228{
  • branches/eam_branch_20080706/ippTools/src/pxtools.h

    r18468 r18480  
    2222
    2323#include <stdio.h>
     24#include <string.h>   // for strcmp and strncmp
    2425#include <strings.h>  // for strcasecmp
    2526#include <unistd.h>   // for unlink
     27
     28// #include <stdlib.h>
     29// #include <stdint.h>
     30// #include <inttypes.h>
     31
    2632#include <pslib.h>
    2733#include <psmodules.h>
Note: See TracChangeset for help on using the changeset viewer.