IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36543 for trunk/ippTools/src


Ignore:
Timestamp:
Feb 20, 2014, 5:38:01 PM (12 years ago)
Author:
watersc1
Message:

Addition of a -show mode to detselect, which displays a catalog of detrends for a specified camera/telescope. The return catalog lists the constraints on the use of this detrend. It does not filter out superceded detrends, although they are sorted in descending order, so the first in the list that matches the image constraints is the one detselect -search would yield.

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

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

    r31058 r36543  
    2929static bool searchMode(pxConfig *config);
    3030static bool selectMode(pxConfig *config);
     31static bool showMode(pxConfig *config);
     32
    3133
    3234# define MODECASE(caseName, func) \
     
    5052        MODECASE(DETSELECT_MODE_SEARCH,        searchMode);
    5153        MODECASE(DETSELECT_MODE_SELECT,        selectMode);
     54        MODECASE(DETSELECT_MODE_SHOW,          showMode);
    5255        default:
    5356            psAbort("invalid option (this should not happen)");
     
    241244    return true;
    242245}
     246
     247static bool showMode(pxConfig *config)
     248{
     249    PS_ASSERT_PTR_NON_NULL(config, false);
     250
     251    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     252
     253    psMetadata *where = psMetadataAlloc();
     254
     255    PXOPT_COPY_STR(config->args, where, "-inst",      "camera", "==");
     256    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
     257    PXOPT_COPY_STR(config->args, where, "-det_type",  "det_type", "==");
     258    PXOPT_COPY_STR(config->args, where, "-type",      "det_type", "==");
     259
     260    psString query = pxDataGet("detselect_show.sql");
     261    if (!query) {
     262        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     263        return false;
     264    }
     265
     266    // use psDBGenerateWhereConditionalSQL with AND ... because the SQL ends in a WHERE
     267    if (where && psListLength(where->list)) {
     268        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     269        psStringAppend(&query, " AND %s", whereClause);
     270        psFree(whereClause);
     271    }
     272    psFree(where);
     273
     274    // we choose the single detrend image which matches all criteria and has
     275    // the latest insertion date
     276
     277    psStringAppend(&query, " ORDER BY registered DESC, iteration DESC, time_begin, time_end");
     278
     279    if (!p_psDBRunQuery(config->dbh, query)) {
     280        psError(PS_ERR_UNKNOWN, false, "database error");
     281        psFree(query);
     282        return false;
     283    }
     284    psFree(query);
     285
     286    psArray *output = p_psDBFetchResult(config->dbh);
     287    if (!output) {
     288        psError(PS_ERR_UNKNOWN, false, "database error");
     289        return false;
     290    }
     291    if (!psArrayLength(output)) {
     292        // XXX check psError here
     293        psError(PS_ERR_UNKNOWN, false, "no detRun rows found");
     294        psFree(output);
     295        return true;
     296    }
     297
     298    // negative simple so the default is true
     299    if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) {
     300        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     301        psFree(output);
     302        return false;
     303    }
     304
     305    psFree(output);
     306    return(true);
     307}
  • trunk/ippTools/src/detselect.h

    r18561 r36543  
    2727    DETSELECT_MODE_SEARCH,
    2828    DETSELECT_MODE_SELECT,
     29    DETSELECT_MODE_SHOW
    2930} detselectMode;
    3031
  • trunk/ippTools/src/detselectConfig.c

    r18561 r36543  
    6565    psMetadataAddStr(selectArgs, PS_LIST_TAIL, "-class_id", 0,                     "search by class ID", NULL);
    6666    psMetadataAddBool(selectArgs, PS_LIST_TAIL, "-simple",  0,                      "use the simple output format", false);
     67
     68    // -show
     69    psMetadata *showArgs = psMetadataAlloc();
     70    psMetadataAddStr(showArgs, PS_LIST_TAIL, "-inst",       0,       "search by camera", NULL);
     71    psMetadataAddStr(showArgs, PS_LIST_TAIL, "-telescope",  0,       "search by telescope", NULL);
     72    psMetadataAddStr(showArgs, PS_LIST_TAIL, "-det_type",   0,       "search by detrend type", NULL);
     73    psMetadataAddStr(showArgs, PS_LIST_TAIL, "-type",       0,       "search by detrend type (alias for -det_type)", NULL);
     74    psMetadataAddBool(showArgs, PS_LIST_TAIL, "-simple",     0,       "use the simple output format", false);
    6775   
    6876    psMetadata *argSets = psMetadataAlloc();
     
    7179    PXOPT_ADD_MODE("-search",  "search for an appropriate detrend", DETSELECT_MODE_SEARCH, searchArgs);
    7280    PXOPT_ADD_MODE("-select",  "retreive detrend information", DETSELECT_MODE_SELECT, selectArgs);
     81    PXOPT_ADD_MODE("-show",    "show all active detrends of this type with constraints", DETSELECT_MODE_SHOW, showArgs);
    7382
    7483    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Note: See TracChangeset for help on using the changeset viewer.