IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 4, 2008, 1:44:33 PM (18 years ago)
Author:
bills
Message:

on branch. Reorganizing the diff stage to consist of a collection of
skyfiles

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/bills_081204/ippTools/src/difftool.c

    r20719 r20903  
    4747
    4848static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state);
     49static bool diffRunComplete(pxConfig *config);
    4950
    5051# define MODECASE(caseName, func) \
     
    108109    // required options
    109110    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
    110     PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
    111111    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
    112112    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    113113    PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
     114    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
    114115
    115116    // default
     
    125126            NULL,       // dvodb
    126127            registered,
    127             skycell_id,
     128            exp_id,
    128129            tess_id
    129130    );
     
    178179
    179180    // optional
    180     PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false);
    181     PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", false, false);
    182     PXOPT_LOOKUP_STR(kind, config->args, "-kind", false, false);
    183 
    184     // defaults to false
    185     PXOPT_LOOKUP_BOOL(template, config->args, "-template", false);
    186 
    187     // must provide either stack_id or warp_id but not BOTH
    188     if (!(stack_id || warp_id)) {
    189         psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified");
    190         return false;
    191     }
    192     if (stack_id && warp_id) {
    193         psError(PS_ERR_UNKNOWN, true, "either -stack_id or -warp_id must be specified");
    194         return false;
    195     }
    196 
    197     // if a warp_id was provided we need to lookup the skycell_id and tess_id
    198     // from the warpRun
    199     psString skycell_id = NULL;
     181    PXOPT_LOOKUP_S64(stack1, config->args, "-stack1", false, false);
     182    PXOPT_LOOKUP_S64(stack2, config->args, "-stack2", false, false);
     183    PXOPT_LOOKUP_S64(warp1, config->args, "-warp1", false, false);
     184    PXOPT_LOOKUP_S64(warp2, config->args, "-warp2", false, false);
     185    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
     186
     187    // must provide either stack1 or warp1 but not BOTH
     188    if (!(stack1 || warp1)) {
     189        psError(PS_ERR_UNKNOWN, true, "either -stack1 or -warp1 must be specified");
     190        return false;
     191    }
     192    if (stack1 && warp1) {
     193        psError(PS_ERR_UNKNOWN, true, "either -stack1 or -warp1 must be specified");
     194        return false;
     195    }
     196    // must provide either stack2 or warp2 but not BOTH
     197    if (!(stack2 || warp2)) {
     198        psError(PS_ERR_UNKNOWN, true, "either -stack2 or -warp2 must be specified");
     199        return false;
     200    }
     201    if (stack2 && warp2) {
     202        psError(PS_ERR_UNKNOWN, true, "either -stack2 or -warp2 must be specified");
     203        return false;
     204    }
     205
     206    // if a warp1 was provided we need to lookup the and tess_id from the diffRun
    200207    psString tess_id = NULL;
    201     if (warp_id) {
     208    if (warp1) {
    202209        if (!p_psDBRunQuery(config->dbh, "SELECT * from diffRun WHERE diff_id = %" PRId64, diff_id)) {
    203210            psError(PS_ERR_UNKNOWN, false, "database error");
     
    217224
    218225        diffRunRow *run = diffRunObjectFromMetadata(output->data[0]);
    219         skycell_id = run->skycell_id;
    220226        tess_id = run->tess_id;
    221227    }
     
    228234    if (!diffInputSkyfileInsert(config->dbh,
    229235            diff_id,
    230             template,
    231             stack_id ? stack_id : PS_MAX_S64, // defined or NULL
    232             warp_id ? warp_id : PS_MAX_S64, // defined or NULL
     236            warp1 ? warp1 : PS_MAX_S64, // defined or NULL
     237            warp2 ? warp2 : PS_MAX_S64, // defined or NULL
     238            stack1 ? stack1 : PS_MAX_S64, // defined or NULL
     239            stack2 ? stack2 : PS_MAX_S64, // defined or NULL
    233240            skycell_id,
    234             tess_id,
    235             kind
     241            tess_id
    236242        )) {
    237243        if (!psDBRollback(config->dbh)) {
     
    300306    PXOPT_COPY_STR(config->args, where, "-skycell_id", "skycell_id", "==");
    301307    PXOPT_COPY_STR(config->args, where,  "-tess_id", "tess_id", "==");
    302     PXOPT_COPY_STR(config->args, where,  "-kind", "kind", "==");
    303308
    304309    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     
    349354    }
    350355
    351     if (!p_psDBRunQuery(config->dbh, query, whereClause, whereClause)) {
     356    if (!p_psDBRunQuery(config->dbh, query, whereClause, whereClause, whereClause, whereClause)) {
    352357        psError(PS_ERR_UNKNOWN, false, "database error");
    353358        psFree(whereClause);
     
    471476
    472477    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false); // required
     478    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
    473479    PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);
    474480    PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false);
     
    503509    if (!diffSkyfileInsert(config->dbh,
    504510                           diff_id,
     511                           skycell_id,
    505512                           uri,
    506513                           path_base,
     
    533540    }
    534541
    535     if (!setdiffRunState(config, diff_id, "full")) {
     542    if (!diffRunComplete(config)) {
    536543        if (!psDBRollback(config->dbh)) {
    537544            psError(PS_ERR_UNKNOWN, false, "database error");
     
    546553        return false;
    547554    }
     555
    548556
    549557    return true;
     
    762770                         psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none
    763771                         psS64 template_stack_id, // Stack identifier for template image, PS_MAX_S64 for none
     772                         psS64 exp_id, // exposure id for input_warp_id (if defined)
    764773                         pxConfig *config // Configuration
    765774                         )
     
    791800            NULL,       // dvodb
    792801            registered,
    793             skycell_id,
     802            exp_id,
    794803            tess_id
    795804    );
     
    817826    if (!diffInputSkyfileInsert(config->dbh,
    818827            run->diff_id,
    819             true,
     828            input_warp_id,
     829            template_warp_id,
     830            input_stack_id,
    820831            template_stack_id,
    821             template_warp_id,
    822832            skycell_id,
    823             tess_id,
    824             NULL    // kind
    825         )) {
    826         if (!psDBRollback(config->dbh)) {
    827             psError(PS_ERR_UNKNOWN, false, "database error");
    828         }
    829         psError(PS_ERR_UNKNOWN, false, "database error");
    830         return false;
    831     }
    832 
    833     // Input
    834     if (!diffInputSkyfileInsert(config->dbh,
    835             run->diff_id,
    836             false,
    837             input_stack_id,
    838             input_warp_id,
    839             skycell_id,
    840             tess_id,
    841             NULL    // kind
     833            tess_id
    842834        )) {
    843835        if (!psDBRollback(config->dbh)) {
     
    887879    PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false);
    888880    PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false);
     881    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
    889882    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    890883
     
    906899        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    907900                "No input has been defined (-input_stack_id or -input_warp_id)");
     901        return false;
     902    }
     903    if (input_warp_id && !exp_id) {
     904        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     905                "-exp_id is required with -input_warp_id.");
    908906        return false;
    909907    }
     
    916914                      template_warp_id ? template_warp_id : PS_MAX_S64,
    917915                      template_stack_id ? template_stack_id : PS_MAX_S64,
     916                      exp_id,
    918917                      config)) {
    919918        psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun");
     
    945944    PXOPT_COPY_STR(config->args, warpWhere, "-filter", "rawExp.filter", "==");
    946945    PXOPT_COPY_STR(config->args, warpWhere, "-warp_label", "warpRun.label", "==");
    947     PXOPT_COPY_STR(config->args, warpWhere,  "-kind", "warpsToDiff.kind", "==");
    948946    PXOPT_COPY_F32(config->args, warpWhere,  "-good_frac", "warpSkyfile.good_frac", ">=");
    949947    PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "==");
     
    10481046            continue;
    10491047        }
     1048        psS64 exp_id = psMetadataLookupS64(&mdok, row, "exp_id");
     1049        if (!mdok) {
     1050            psWarning("exp_id not found --- ignoring row %ld", i);
     1051            continue;
     1052        }
    10501053
    10511054        if (!populatedrun(list, workdir, skycell_id, tess_id, label, reduction, warp_id,
    1052                           PS_MAX_S64, PS_MAX_S64, stack_id, config)) {
     1055                          PS_MAX_S64, PS_MAX_S64, stack_id, exp_id, config)) {
    10531056            psWarning("Unable to add run for %s,%s,%" PRId64 ",%" PRId64, skycell_id, tess_id,
    10541057                      warp_id, stack_id);
     
    12741277}
    12751278
     1279static bool diffRunComplete(pxConfig *config)
     1280{
     1281    PS_ASSERT_PTR_NON_NULL(config, false);
     1282
     1283    // look for completed diffRuns
     1284    psString query = pxDataGet("difftool_completed_runs.sql");
     1285    if (!query) {
     1286        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1287        return false;
     1288    }
     1289
     1290    if (!p_psDBRunQuery(config->dbh, query)) {
     1291        psError(PS_ERR_UNKNOWN, false, "database error");
     1292        psFree(query);
     1293        return false;
     1294    }
     1295    psFree(query);
     1296
     1297    psArray *output = p_psDBFetchResult(config->dbh);
     1298    if (!output) {
     1299        psError(PS_ERR_UNKNOWN, false, "database error");
     1300        return false;
     1301    }
     1302    if (!psArrayLength(output)) {
     1303        psTrace("difftool", PS_LOG_INFO, "no rows found");
     1304        psFree(output);
     1305        return true;
     1306    }
     1307    for (long i = 0; i < psArrayLength(output); i++) {
     1308        psMetadata *row = output->data[i];
     1309
     1310        psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id");
     1311
     1312        // set diffRun.state to 'stop'
     1313        if (!setdiffRunState(config, diff_id, "full")) {
     1314            psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64,
     1315                diff_id);
     1316            psFree(output);
     1317            return false;
     1318        }
     1319    }
     1320
     1321    return true;
     1322}
     1323
Note: See TracChangeset for help on using the changeset viewer.