IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 23, 2013, 2:32:53 PM (13 years ago)
Author:
bills
Message:

refinements to fullForce tables. Full force run is now for a
a collection of warps with the same skycell and filter.
warp_id is removed from fullForceRun and is now contained in table
fullForceInput. The final results of the run will be stored in the
new table fullForceSummary which is also added. Run will transition
from new to full when all inputs have been processed and the summary
object is inserted.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/bills_branches/bills_201312/ippTools/src/fftool.c

    r36392 r36409  
    4040static bool updateresultMode(pxConfig *config);
    4141
    42 static bool setfullForceRunState(pxConfig *config, psS64 sky_id, const char *state);
     42// static bool setfullForceRunState(pxConfig *config, psS64 sky_id, const char *state);
    4343
    4444# define MODECASE(caseName, func) \
     
    103103    PXOPT_LOOKUP_STR(sources_path_base,   config->args, "-set_sources_path_base", false, false);
    104104
    105     psMetadata *whereMD = psMetadataAlloc();
    106     pxAddLabelSearchArgs(config, whereMD, "-select_warp_label",     "warpRun.label",           "LIKE");
    107     pxAddLabelSearchArgs(config, whereMD, "-select_warp_data_group","warpRun.data_group",      "LIKE");
    108     PXOPT_COPY_S64(config->args, whereMD, "-select_warp_id",        "warpRun.warp_id",         "==");
    109 
    110     pxAddLabelSearchArgs(config, whereMD, "-select_skycal_label",   "skycalRun.label",         "LIKE");
    111     pxAddLabelSearchArgs(config, whereMD, "-select_skycal_data_group", "skycalRun.data_group", "LIKE");
    112     PXOPT_COPY_S64(config->args, whereMD, "-select_skycal_id",      "skycalRun.skycal_id",     "==");
    113 
    114     // XXX: REQUIRE at least one of the stack selectors and one of the warp selectors are supplied
    115 
    116     PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id",    "stackRun.skycell_id",      "LIKE");
    117     PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id",       "stackRun.tess_id",         "==");
    118     pxAddLabelSearchArgs(config, whereMD, "-select_filter",        "stackRun.filter",          "LIKE");
    119 
    120     if (!pxskycellAddWhere(config, whereMD)) {
     105    psMetadata *skycalWhereMD = psMetadataAlloc();
     106    pxAddLabelSearchArgs(config, skycalWhereMD, "-select_skycal_label",   "skycalRun.label",         "LIKE");
     107    pxAddLabelSearchArgs(config, skycalWhereMD, "-select_skycal_data_group", "skycalRun.data_group", "LIKE");
     108    PXOPT_COPY_S64(config->args, skycalWhereMD, "-select_skycal_id",      "skycalRun.skycal_id",     "==");
     109
     110    if (!psListLength(skycalWhereMD->list)) {
     111        psError(PXTOOLS_ERR_CONFIG, false, "skycal search parameters are required");
     112        psFree(skycalWhereMD);
     113        return false;
     114    }
     115
     116    PXOPT_COPY_STR(config->args, skycalWhereMD, "-select_skycell_id",    "stackRun.skycell_id",      "LIKE");
     117    PXOPT_COPY_STR(config->args, skycalWhereMD, "-select_tess_id",       "stackRun.tess_id",         "==");
     118    pxAddLabelSearchArgs(config, skycalWhereMD, "-select_filter",        "stackRun.filter",          "LIKE");
     119    if (!pxskycellAddWhere(config, skycalWhereMD)) {
    121120        psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
    122         return false;
    123     }
     121        psFree(skycalWhereMD);
     122        return false;
     123    }
     124
     125    psMetadata *warpWhereMD = psMetadataAlloc();
     126    pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_label",     "warpRun.label",           "LIKE");
     127    pxAddLabelSearchArgs(config, warpWhereMD, "-select_warp_data_group","warpRun.data_group",      "LIKE");
     128    PXOPT_COPY_S64(config->args, warpWhereMD, "-select_warp_id",        "warpRun.warp_id",         "==");
     129    if (!psListLength(warpWhereMD->list)) {
     130        psError(PXTOOLS_ERR_CONFIG, false, "warp search parameters are required");
     131        psFree(warpWhereMD);
     132        psFree(skycalWhereMD);
     133        return false;
     134    }
     135    if (!psListLength(warpWhereMD->list)) {
     136        psError(PXTOOLS_ERR_CONFIG, false, "skycal search parameters are required");
     137        psFree(skycalWhereMD);
     138        psFree(warpWhereMD);
     139        return false;
     140    }
     141
     142    PXOPT_COPY_STR(config->args, warpWhereMD, "-select_tess_id",       "warpRun.tess_id",         "==");
     143    pxAddLabelSearchArgs(config, warpWhereMD, "-select_filter",        "warpRun.filter",          "LIKE");
     144    if (!pxskycellAddWhere(config, warpWhereMD)) {
     145        psError(PXTOOLS_ERR_CONFIG, false, "failed to add skycell search arguments");
     146        psFree(skycalWhereMD);
     147        psFree(warpWhereMD);
     148        return false;
     149    }
     150
    124151
    125152    PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
     
    130157    if (!select) {
    131158        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    132         psFree(whereMD);
    133         return false;
    134     }
    135 
    136     if (!psListLength(whereMD->list)) {
    137         psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    138         psFree(whereMD);
     159        psFree(skycalWhereMD);
     160        psFree(warpWhereMD);
    139161        return false;
    140162    }
    141163
    142164    psString where = NULL;
    143     psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL);
     165    psString whereClause = psDBGenerateWhereConditionSQL(skycalWhereMD, NULL);
    144166    psStringAppend(&where, "\nAND %s", whereClause);
    145167    psStringAppend(&select, where);
    146168    psFree(whereClause);
    147     psFree(whereMD);
     169    psFree(skycalWhereMD);
    148170
    149171    psString joinHook = NULL;
    150172    if (!rerun) {
     173        psStringAppend(&joinHook, "\nLEFT JOIN fullForceRun ON fullForceRun.skycal_id = fullForceRun.skycal_id");
    151174        psStringAppend(&joinHook, "\n %s\nAND fullForceRun.label = '%s'", where, label);
    152175        psStringAppend(&select, "\nAND ff_id IS NULL");
     
    181204        return true;
    182205    }
     206
    183207    if (pretend) {
    184208        // negative simple so the default is true
    185         if (!ippdbPrintMetadatas(stdout, output, "staticskyInput", !simple)) {
     209        if (!ippdbPrintMetadatas(stdout, output, "toFullForce", !simple)) {
    186210            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    187211            psFree(output);
     
    193217        return true;
    194218    }
     219
     220    psString warpQueryTemplate = pxDataGet("fftool_definebyquery_select_warps.sql");
     221
     222    whereClause = psDBGenerateWhereConditionSQL(warpWhereMD, NULL);
     223    psStringAppend(&warpQueryTemplate, "\nAND %s", whereClause);
    195224
    196225    for (long i = 0; i < output->n; i++) {
     
    204233        }
    205234
    206         psS64 warp_id = psMetadataLookupS64(&status, row, "warp_id");
     235        // psS64 warp_id = psMetadataLookupS64(&status, row, "warp_id");
    207236        psS64 skycal_id = psMetadataLookupS64(&status, row, "skycal_id");
    208237
     
    216245
    217246        psString skycal_data_group = psMetadataLookupStr(&status, row, "data_group");
     247        psString tess_id = psMetadataLookupStr(&status, row, "tess_id");
     248        psString skycell_id = psMetadataLookupStr(&status, row, "skycell_id");
     249        psString filter = psMetadataLookupStr(&status, row, "filter");
     250
     251        psString query = NULL;
     252        psStringAppend(&query, warpQueryTemplate, tess_id, skycell_id, filter);
     253
     254        if (!p_psDBRunQuery(config->dbh, query)) {
     255            psError(PS_ERR_UNKNOWN, false, "database error");
     256            psFree(query);
     257            return false;
     258        }
     259        psFree(query);
     260
     261        // Find the warps for this skycell and filter combination
     262        psArray *warpOutput = p_psDBFetchResult(config->dbh);
     263        if (!warpOutput) {
     264            psErrorCode err = psErrorCodeLast();
     265            switch (err) {
     266                case PS_ERR_DB_CLIENT:
     267                    psError(PXTOOLS_ERR_SYS, false, "database error");
     268                case PS_ERR_DB_SERVER:
     269                    psError(PXTOOLS_ERR_PROG, false, "database error");
     270                default:
     271                    psError(PXTOOLS_ERR_PROG, false, "unknown error");
     272            }
     273            return false;
     274        }
     275        if (!psArrayLength(warpOutput)) {
     276            // no warps for this skycal. Suprise?
     277            psFree(warpOutput);
     278            psFree(query);
     279            continue;
     280        }
    218281
    219282        // create a staticskyRun
    220283        if (!fullForceRunInsert(config->dbh,
    221284                                0x0,         // ff_id
    222                                 warp_id,
    223285                                skycal_id,
    224286                                path_base,
     
    241303        }
    242304
     305        psS64 ff_id = psDBLastInsertID(config->dbh);
     306
     307        for (int j = 0; j < warpOutput->n; j++) {
     308            psMetadata *warpRow = warpOutput->data[j];
     309            psS64 warp_id = psMetadataLookupS64(&status, warpRow, "warp_id");
     310
     311            if (!fullForceInputInsert(config->dbh,
     312                                ff_id,
     313                                warp_id)
     314               ) {
     315                if (!psDBRollback(config->dbh)) {
     316                    psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");
     317                }
     318                psError(PS_ERR_UNKNOWN, false, "database error");
     319                psFree(warpOutput);
     320                psFree(output);
     321                return false;
     322            }
     323        }
     324
    243325        if (!psDBCommit(config->dbh)) {
    244326            psError(PS_ERR_UNKNOWN, false, "database error");
     327                psFree(warpOutput);
    245328            psFree(output);
    246329            return false;
    247330        }
     331        psFree(warpOutput);
    248332    }
    249333    psFree(output);
     
    365449    // required
    366450    PXOPT_LOOKUP_S64(ff_id, config->args, "-ff_id", true, false);
     451    PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
    367452
    368453    // optional
     
    384469    if (!fullForceResultInsert(config->dbh,
    385470                               ff_id,
     471                               warp_id,
    386472                               path_base,
    387473                               dtime_script,
     
    398484    }
    399485
     486#ifdef notdef
    400487    if (!fault) {
    401488        if (!setfullForceRunState(config, ff_id, "full")) {
     
    407494        }
    408495    }
     496#endif
    409497
    410498    // point of no return
     
    557645    psMetadata *where = psMetadataAlloc();
    558646    PXOPT_COPY_S64(config->args, where, "-ff_id",   "ff_id",   "==");
     647    PXOPT_COPY_S64(config->args, where, "-warp_id",   "ff_id",   "==");
    559648
    560649
     
    567656    return true;
    568657}
    569 
     658#ifdef notyet
    570659static bool setfullForceRunState(pxConfig *config, psS64 ff_id, const char *state)
    571660{
     
    578667    return true;
    579668}
    580 
     669#endif
     670
Note: See TracChangeset for help on using the changeset viewer.