IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 13, 2009, 12:37:33 PM (17 years ago)
Author:
Paul Price
Message:

Merging branches/pap_magic@24173 into trunk. One conflict in dbconfig/changes.txt resolved easily.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/ippTools/src/difftool.c

    r24059 r24174  
    4040static bool revertdiffskyfileMode(pxConfig *config);
    4141static bool definepoprunMode(pxConfig *config);
    42 static bool definebyqueryMode(pxConfig *config);
     42static bool definewarpstackMode(pxConfig *config);
    4343static bool definewarpwarpMode(pxConfig *config);
    4444static bool pendingcleanuprunMode(pxConfig *config);
     
    7979        MODECASE(DIFFTOOL_MODE_REVERTDIFFSKYFILE,     revertdiffskyfileMode);
    8080        MODECASE(DIFFTOOL_MODE_DEFINEPOPRUN,          definepoprunMode);
    81         MODECASE(DIFFTOOL_MODE_DEFINEBYQUERY,         definebyqueryMode);
     81        MODECASE(DIFFTOOL_MODE_DEFINEWARPSTACK,         definewarpstackMode);
    8282        MODECASE(DIFFTOOL_MODE_DEFINEWARPWARP,        definewarpwarpMode);
    8383        MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
     
    116116    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
    117117    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
     118    PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false);
     119    PXOPT_LOOKUP_BOOL(exposure, config->args, "-exposure", false);
    118120    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    119121    PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
    120     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
    121122
    122123    // default
     
    133134            registered,
    134135            tess_id,
    135             exp_id,
     136            bothways,
     137            exposure,
    136138            false
    137139    );
     
    487489    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
    488490    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
    489     PXOPT_LOOKUP_STR(uri, config->args, "-uri", (fault == 0), false);
    490491    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", (fault == 0), false);
    491492
     
    521522                           diff_id,
    522523                           skycell_id,
    523                            uri,
    524524                           path_base,
    525525                           "full",
     
    771771                         psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none
    772772                         psS64 template_stack_id, // Stack identifier for template image, PS_MAX_S64 for none
    773                          psS64 exp_id, // exposure id for input_warp_id (if defined)
    774773                         pxConfig *config // Configuration
    775774                         )
     
    802801            registered,
    803802            tess_id,
    804             exp_id,
     803            false,
     804            false,
    805805            false       // magicked
    806806    );
     
    882882    PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false);
    883883    PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false);
    884     PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false);
    885884    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    886885
     
    902901        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    903902                "No input has been defined (-input_stack_id or -input_warp_id)");
    904         return false;
    905     }
    906     if (input_warp_id && !exp_id) {
    907         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    908                 "-exp_id is required with -input_warp_id.");
    909903        return false;
    910904    }
     
    917911                      template_warp_id ? template_warp_id : PS_MAX_S64,
    918912                      template_stack_id ? template_stack_id : PS_MAX_S64,
    919                       exp_id ? exp_id : PS_MAX_S64,
    920913                      config)) {
    921914        psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun");
     
    935928
    936929
    937 static bool definebyqueryMode(pxConfig *config)
     930static bool definewarpstackMode(pxConfig *config)
    938931{
    939932    PS_ASSERT_PTR_NON_NULL(config, false);
     
    960953    PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false);
    961954    PXOPT_LOOKUP_BOOL(available, config->args, "-available", false);
     955    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    962956
    963957    // find all things to queue
    964     psString query = pxDataGet("difftool_definebyquery_part1.sql");
     958    psString query = pxDataGet("difftool_definewarpstack_part1.sql");
    965959    if (!query) {
    966960        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    10571051    }
    10581052
     1053    if (pretend) {
     1054        // negative simple so the default is true
     1055        if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) {
     1056            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1057            psFree(output);
     1058            return false;
     1059        }
     1060        psFree(output);
     1061        return true;
     1062    }
     1063
    10591064    // create temporary table
    1060     query = pxDataGet("difftool_definebyquery_temp_create.sql");
     1065    query = pxDataGet("difftool_definewarpstack_temp_create.sql");
    10611066    if (!p_psDBRunQuery(config->dbh, query)) {
    10621067        psError(PS_ERR_UNKNOWN, false, "database error");
     
    10701075    query = NULL;
    10711076
    1072     psString skycell_query = pxDataGet("difftool_definebyquery_part2.sql");
     1077    psString skycell_query = pxDataGet("difftool_definewarpstack_part2.sql");
    10731078
    10741079    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
     
    11831188                registered,
    11841189                tess_id,
    1185                 exp_id,
     1190                true,
     1191                false,
    11861192                false       // magicked
    11871193        );
     
    12841290    // Haversine formula for great circle distance
    12851291    PXOPT_COPY_F32(config->args, selectWhere, "-distance",
    1286                    "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + COS(inputRawExp.decl)*COS(templateRawExp.decl)*POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<=");
     1292                   "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + "
     1293                   "COS(inputRawExp.decl)*COS(templateRawExp.decl)*"
     1294                   "POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<=");
    12871295
    12881296    PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false);
     
    13081316    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    13091317
     1318    if (!psDBTransaction(config->dbh)) {
     1319        psError(PS_ERR_UNKNOWN, false, "database error");
     1320        psFree(selectWhere);
     1321        psFree(insertWhere);
     1322        return false;
     1323    }
     1324
     1325    if (!rerun) {
     1326        // Need to build table of exposures with diffs
     1327        psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL
     1328        if (!tempCreate) {
     1329            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1330            psFree(selectWhere);
     1331            psFree(insertWhere);
     1332            if (!psDBRollback(config->dbh)) {
     1333                psError(PS_ERR_UNKNOWN, false, "database error");
     1334            }
     1335            return false;
     1336        }
     1337
     1338        if (!p_psDBRunQuery(config->dbh, tempCreate)) {
     1339            psError(PS_ERR_UNKNOWN, false, "Unable to create temp table: %s", tempCreate);
     1340            psFree(tempCreate);
     1341            psFree(selectWhere);
     1342            psFree(insertWhere);
     1343            if (!psDBRollback(config->dbh)) {
     1344                psError(PS_ERR_UNKNOWN, false, "database error");
     1345            }
     1346            return false;
     1347        }
     1348        psFree(tempCreate);
     1349
     1350        psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table
     1351        if (!tempInsert) {
     1352            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1353            psFree(selectWhere);
     1354            psFree(insertWhere);
     1355            if (!psDBRollback(config->dbh)) {
     1356                psError(PS_ERR_UNKNOWN, false, "database error");
     1357            }
     1358            return false;
     1359        }
     1360
     1361        psString where = psStringCopy(""); // WHERE for insertion
     1362        if (label) {
     1363            psStringAppend(&where, "\nAND diffRun.label = '%s'", label);
     1364        }
     1365
     1366        if (!p_psDBRunQueryF(config->dbh, tempInsert, where, where)) {
     1367            psError(PS_ERR_UNKNOWN, false, "Unable to insert into temp table: %s", tempInsert);
     1368            psFree(tempInsert);
     1369            psFree(where);
     1370            psFree(selectWhere);
     1371            psFree(insertWhere);
     1372            if (!psDBRollback(config->dbh)) {
     1373                psError(PS_ERR_UNKNOWN, false, "database error");
     1374            }
     1375            return false;
     1376        }
     1377        psFree(where);
     1378        psFree(tempInsert);
     1379    }
     1380
     1381    // Get list of warps to diff
    13101382    psString select = pxDataGet("difftool_definewarpwarp_select.sql");
    13111383    if (!select) {
    13121384        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1385        psFree(selectWhere);
     1386        psFree(insertWhere);
     1387        if (!psDBRollback(config->dbh)) {
     1388            psError(PS_ERR_UNKNOWN, false, "database error");
     1389        }
    13131390        return false;
    13141391    }
     
    13231400    psFree(selectWhere);
    13241401
    1325     if (!rerun) {
    1326         psStringAppend(&whereClause, "\n%s (diffRun.diff_id IS NULL", whereClause ? "AND" : "WHERE");
    1327         if (label) {
    1328             psStringAppend(&whereClause, " OR diffRun.label != '%s'", label);
    1329         }
    1330         psStringAppend(&whereClause, ")");
    1331     }
    1332 
    13331402    if (!available) {
    13341403        psStringAppend(&whereClause, "\n%s inputWarpRun.state = 'full'", whereClause ? "AND" : "WHERE");
    13351404    }
    13361405
    1337     if (!psDBTransaction(config->dbh)) {
    1338         psError(PS_ERR_UNKNOWN, false, "database error");
    1339         psFree(select);
    1340         psFree(whereClause);
    1341         psFree(insertWhere);
    1342         return false;
     1406    if (!rerun) {
     1407        psStringAppend(&whereClause, "\n%s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE");
    13431408    }
    13441409
    13451410    if (!p_psDBRunQueryF(config->dbh, select,
    1346                          !rerun ? "\n" : "", // Activate LEFT JOIN against diffRun?
     1411                         !rerun ? "\n" : "", // Activate LEFT JOIN against diffs?
    13471412                         whereClause)) {
    13481413        psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s [WITH] %s", select, whereClause);
     
    14141479        psMetadata *row = results->data[i]; // Result row from query
    14151480
    1416         psS64 exp_id = psMetadataLookupS64(NULL, row, "input_exp_id");
    14171481        psS64 input_id = psMetadataLookupS64(NULL, row, "input_warp_id");
    14181482        const char *template = psMetadataLookupStr(NULL, row, "template_warp_id");
    14191483        const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id");
    1420         if (!exp_id || !input_id || !template || !tess_id) {
     1484        if (!input_id || !template || !tess_id) {
    14211485            psError(PXTOOLS_ERR_PROG, false, "Identifiers not found");
    14221486            psFree(list);
     
    14301494
    14311495        diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered,
    1432                                           tess_id, exp_id, false); // Run to insert
     1496                                          tess_id, true, true, false); // Run to insert
    14331497        if (!diffRunInsertObject(config->dbh, run)) {
    14341498            psError(PS_ERR_UNKNOWN, false, "database error");
Note: See TracChangeset for help on using the changeset viewer.