IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 21, 2008, 4:51:55 PM (18 years ago)
Author:
eugene
Message:

add definebyquery mode to warptool

File:
1 edited

Legend:

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

    r19101 r19160  
    3333
    3434static psS64 definerunMode(pxConfig *config);
     35static bool definebyqueryMode(pxConfig *config);
    3536static bool updaterunMode(pxConfig *config);
    3637static bool expMode(pxConfig *config);
     
    7374    switch (config->mode) {
    7475        MODECASE(WARPTOOL_MODE_DEFINERUN,          definerunMode);
     76        MODECASE(WARPTOOL_MODE_DEFINEBYQUERY,      definebyqueryMode);
    7577        MODECASE(WARPTOOL_MODE_UPDATERUN,          updaterunMode);
    7678        MODECASE(WARPTOOL_MODE_EXP,                expMode);
     
    172174}
    173175
     176
     177static bool definebyqueryMode(pxConfig *config)
     178{
     179    PS_ASSERT_PTR_NON_NULL(config, NULL);
     180
     181    psMetadata *where = psMetadataAlloc();
     182    PXOPT_COPY_S64(config->args, where, "-fake_id", "fakeRun.fake_id", "==");
     183    PXOPT_COPY_S64(config->args, where, "-cam_id", "camRun.cam_id", "==");
     184    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     185    PXOPT_COPY_S64(config->args, where, "-exp_id", "newExp.exp_id", "==");
     186    PXOPT_COPY_STR(config->args, where, "-exp_name", "exp_name", "==");
     187    PXOPT_COPY_STR(config->args, where, "-inst", "camera", "==");
     188    PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "==");
     189    PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">=");
     190    PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<=");
     191    PXOPT_COPY_STR(config->args, where, "-exp_tag", "exp_tag", "==");
     192    PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "==");
     193    PXOPT_COPY_STR(config->args, where, "-filelevel", "filelevel", "==");
     194    PXOPT_COPY_STR(config->args, where, "-reduction", "reduction", "==");
     195    PXOPT_COPY_STR(config->args, where, "-filter", "filter", "==");
     196    PXOPT_COPY_F64(config->args, where, "-airmass_min", "airmass", ">=");
     197    PXOPT_COPY_F64(config->args, where, "-airmass_max", "airmass", "<");
     198    PXOPT_COPY_F64(config->args, where, "-ra_min", "ra", ">=");
     199    PXOPT_COPY_F64(config->args, where, "-ra_max", "ra", "<");
     200    PXOPT_COPY_F64(config->args, where, "-decl_min", "decl", ">=");
     201    PXOPT_COPY_F64(config->args, where, "-decl_max", "decl", "<");
     202    PXOPT_COPY_F32(config->args, where, "-exp_time_min", "exp_time", ">=");
     203    PXOPT_COPY_F32(config->args, where, "-exp_time_max", "exp_time", "<");
     204    PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_min", "sat_pixel_frac", ">=");
     205    PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_max", "sat_pixel_frac", "<");
     206    PXOPT_COPY_F64(config->args, where, "-bg_min", "bt", ">=");
     207    PXOPT_COPY_F64(config->args, where, "-bg_max", "bt", "<");
     208    PXOPT_COPY_F64(config->args, where, "-bg_stdev_min", "bg_stdev", ">=");
     209    PXOPT_COPY_F64(config->args, where, "-bg_stdev_max", "bg_stdev", "<");
     210    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_min", "bg_mean_stdev", ">=");
     211    PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_max", "bg_mean_stdev", "<");
     212    PXOPT_COPY_F64(config->args, where, "-alt_min", "alt", ">=");
     213    PXOPT_COPY_F64(config->args, where, "-alt_max", "alt", "<");
     214    PXOPT_COPY_F64(config->args, where, "-az_min", "az", ">=");
     215    PXOPT_COPY_F64(config->args, where, "-az_max", "az", "<");
     216    PXOPT_COPY_F32(config->args, where, "-ccd_temp_min", "ccd_temp", ">=");
     217    PXOPT_COPY_F32(config->args, where, "-ccd_temp_max", "ccd_temp", "<");
     218    PXOPT_COPY_F64(config->args, where, "-posang_min", "posang", ">=");
     219    PXOPT_COPY_F64(config->args, where, "-posang_max", "posang", "<");
     220    PXOPT_COPY_STR(config->args, where, "-object", "object", "==");
     221    PXOPT_COPY_F32(config->args, where, "-solang_min", "solang", ">=");
     222    PXOPT_COPY_F32(config->args, where, "-solang_max", "solang", "<");
     223
     224    if (!psListLength(where->list) &&
     225        !psMetadataLookupBool(NULL, config->args, "-all")) {
     226        psFree(where);
     227        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     228        return false;
     229    }
     230
     231    PXOPT_LOOKUP_STR(mode, config->args, "-set_mode", true, false); // required
     232    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", false, false);
     233    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     234    PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false);
     235    PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false);
     236    PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false);
     237
     238    PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     239    PXOPT_LOOKUP_BOOL(magiced, config->args, "-magiced", false);
     240    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     241
     242    // check mode
     243    if (mode && !isValidMode(config, mode)) {
     244        psError(PS_ERR_UNKNOWN, false, "invalid mode");
     245        return false;
     246    }
     247
     248    // find the exp_id of all the exposures that we want to queue up.
     249    psString query = pxDataGet("warptool_definebyquery.sql");
     250    if (!query) {
     251        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     252        psFree(where);
     253        return false;
     254    }
     255
     256    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     257    if (where && psListLength(where->list)) {
     258        psString whereClause = psDBGenerateWhereSQL(where, NULL);
     259        psStringAppend(&query, "%s", whereClause);
     260        psFree(whereClause);
     261    }
     262    psFree(where);
     263
     264    if (!p_psDBRunQuery(config->dbh, query)) {
     265        psError(PS_ERR_UNKNOWN, false, "database error");
     266        psFree(query);
     267        return false;
     268    }
     269    psFree(query);
     270
     271    psArray *output = p_psDBFetchResult(config->dbh);
     272    if (!output) {
     273        psError(PS_ERR_UNKNOWN, false, "database error");
     274        return false;
     275    }
     276    if (!psArrayLength(output)) {
     277        psTrace("warptool", PS_LOG_INFO, "no rows found");
     278        psFree(output);
     279        return true;
     280    }
     281
     282    // would could do this "all in the database" if we didn't want the option
     283    // of changing the label/reduction/expgroup/dvodb/etc.  So we're pulling the
     284    // data out so we have the option of changing these values or leaving the
     285    // old values in place (i.e., passing the values through).
     286
     287    // loop over our list of fakeRun rows
     288    for (long i = 0; i < psArrayLength(output); i++) {
     289        psMetadata *md = output->data[i];
     290
     291        fakeRunRow *row = fakeRunObjectFromMetadata(md);
     292        if (!row) {
     293            psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into fakeRun");
     294            psFree(output);
     295            return false;
     296        }
     297
     298        // queue the exp
     299        if (!pxwarpQueueByFakeID(config,
     300                    row->fake_id,
     301                    workdir     ? workdir   : row->workdir,
     302                    label       ? label     : row->label,
     303                    dvodb       ? dvodb     : row->dvodb,
     304                    tess_id     ? tess_id   : row->tess_id,
     305                    end_stage   ? end_stage : row->end_stage))
     306          {
     307            psError(PS_ERR_UNKNOWN, false, "failed to trying to queue fake_id: %" PRId64, row->fake_id);
     308            psFree(row);
     309            psFree(output);
     310            return false;
     311        }
     312        psFree(row);
     313    }
     314    psFree(output);
     315
     316    if (!psDBCommit(config->dbh)) {
     317        psError(PS_ERR_UNKNOWN, false, "database error");
     318        return false;
     319    }
     320
     321    return true;
     322}
    174323
    175324static bool updaterunMode(pxConfig *config)
Note: See TracChangeset for help on using the changeset viewer.