IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 8, 2009, 5:21:35 PM (17 years ago)
Author:
Paul Price
Message:

Branching for magic development (make it work with warpwarp diffs).

Location:
branches/pap_magic
Files:
1 edited
1 copied

Legend:

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

    r24059 r24120  
    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    );
     
    771773                         psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none
    772774                         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)
    774775                         pxConfig *config // Configuration
    775776                         )
     
    802803            registered,
    803804            tess_id,
    804             exp_id,
     805            false,
     806            false,
    805807            false       // magicked
    806808    );
     
    882884    PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false);
    883885    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);
    885886    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    886887
     
    902903        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    903904                "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.");
    909905        return false;
    910906    }
     
    917913                      template_warp_id ? template_warp_id : PS_MAX_S64,
    918914                      template_stack_id ? template_stack_id : PS_MAX_S64,
    919                       exp_id ? exp_id : PS_MAX_S64,
    920915                      config)) {
    921916        psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun");
     
    935930
    936931
    937 static bool definebyqueryMode(pxConfig *config)
     932static bool definewarpstackMode(pxConfig *config)
    938933{
    939934    PS_ASSERT_PTR_NON_NULL(config, false);
     
    962957
    963958    // find all things to queue
    964     psString query = pxDataGet("difftool_definebyquery_part1.sql");
     959    psString query = pxDataGet("difftool_definewarpstack_part1.sql");
    965960    if (!query) {
    966961        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    10581053
    10591054    // create temporary table
    1060     query = pxDataGet("difftool_definebyquery_temp_create.sql");
     1055    query = pxDataGet("difftool_definewarpstack_temp_create.sql");
    10611056    if (!p_psDBRunQuery(config->dbh, query)) {
    10621057        psError(PS_ERR_UNKNOWN, false, "database error");
     
    10701065    query = NULL;
    10711066
    1072     psString skycell_query = pxDataGet("difftool_definebyquery_part2.sql");
     1067    psString skycell_query = pxDataGet("difftool_definewarpstack_part2.sql");
    10731068
    10741069    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
     
    11831178                registered,
    11841179                tess_id,
    1185                 exp_id,
     1180                true,
     1181                false,
    11861182                false       // magicked
    11871183        );
     
    12841280    // Haversine formula for great circle distance
    12851281    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))))", "<=");
     1282                   "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + "
     1283                   "COS(inputRawExp.decl)*COS(templateRawExp.decl)*"
     1284                   "POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<=");
    12871285
    12881286    PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false);
     
    13081306    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    13091307
     1308    if (!psDBTransaction(config->dbh)) {
     1309        psError(PS_ERR_UNKNOWN, false, "database error");
     1310        psFree(selectWhere);
     1311        psFree(insertWhere);
     1312        return false;
     1313    }
     1314
     1315    if (!rerun) {
     1316        // Need to build table of exposures with diffs
     1317        psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL
     1318        if (!tempCreate) {
     1319            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1320            psFree(selectWhere);
     1321            psFree(insertWhere);
     1322            if (!psDBRollback(config->dbh)) {
     1323                psError(PS_ERR_UNKNOWN, false, "database error");
     1324            }
     1325            return false;
     1326        }
     1327
     1328        if (!p_psDBRunQuery(config->dbh, tempCreate)) {
     1329            psError(PS_ERR_UNKNOWN, false, "Unable to create temp table: %s", tempCreate);
     1330            psFree(tempCreate);
     1331            psFree(selectWhere);
     1332            psFree(insertWhere);
     1333            if (!psDBRollback(config->dbh)) {
     1334                psError(PS_ERR_UNKNOWN, false, "database error");
     1335            }
     1336            return false;
     1337        }
     1338        psFree(tempCreate);
     1339
     1340        psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table
     1341        if (!tempInsert) {
     1342            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1343            psFree(selectWhere);
     1344            psFree(insertWhere);
     1345            if (!psDBRollback(config->dbh)) {
     1346                psError(PS_ERR_UNKNOWN, false, "database error");
     1347            }
     1348            return false;
     1349        }
     1350
     1351        psString where = psStringCopy(""); // WHERE for insertion
     1352        if (label) {
     1353            psStringAppend(&where, "\nAND diffRun.label = '%s'", label);
     1354        }
     1355
     1356        if (!p_psDBRunQueryF(config->dbh, tempInsert, where, where)) {
     1357            psError(PS_ERR_UNKNOWN, false, "Unable to insert into temp table: %s", tempInsert);
     1358            psFree(tempInsert);
     1359            psFree(where);
     1360            psFree(selectWhere);
     1361            psFree(insertWhere);
     1362            if (!psDBRollback(config->dbh)) {
     1363                psError(PS_ERR_UNKNOWN, false, "database error");
     1364            }
     1365            return false;
     1366        }
     1367        psFree(where);
     1368        psFree(tempInsert);
     1369    }
     1370
     1371    // Get list of warps to diff
    13101372    psString select = pxDataGet("difftool_definewarpwarp_select.sql");
    13111373    if (!select) {
    13121374        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1375        psFree(selectWhere);
     1376        psFree(insertWhere);
     1377        if (!psDBRollback(config->dbh)) {
     1378            psError(PS_ERR_UNKNOWN, false, "database error");
     1379        }
    13131380        return false;
    13141381    }
     
    13231390    psFree(selectWhere);
    13241391
    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 
    13331392    if (!available) {
    13341393        psStringAppend(&whereClause, "\n%s inputWarpRun.state = 'full'", whereClause ? "AND" : "WHERE");
    13351394    }
    13361395
    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;
     1396    if (!rerun) {
     1397        psStringAppend(&whereClause, "\n%s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE");
    13431398    }
    13441399
    13451400    if (!p_psDBRunQueryF(config->dbh, select,
    1346                          !rerun ? "\n" : "", // Activate LEFT JOIN against diffRun?
     1401                         !rerun ? "\n" : "", // Activate LEFT JOIN against diffs?
    13471402                         whereClause)) {
    13481403        psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s [WITH] %s", select, whereClause);
     
    14141469        psMetadata *row = results->data[i]; // Result row from query
    14151470
    1416         psS64 exp_id = psMetadataLookupS64(NULL, row, "input_exp_id");
    14171471        psS64 input_id = psMetadataLookupS64(NULL, row, "input_warp_id");
    14181472        const char *template = psMetadataLookupStr(NULL, row, "template_warp_id");
    14191473        const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id");
    1420         if (!exp_id || !input_id || !template || !tess_id) {
     1474        if (!input_id || !template || !tess_id) {
    14211475            psError(PXTOOLS_ERR_PROG, false, "Identifiers not found");
    14221476            psFree(list);
     
    14301484
    14311485        diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered,
    1432                                           tess_id, exp_id, false); // Run to insert
     1486                                          tess_id, true, true, false); // Run to insert
    14331487        if (!diffRunInsertObject(config->dbh, run)) {
    14341488            psError(PS_ERR_UNKNOWN, false, "database error");
Note: See TracChangeset for help on using the changeset viewer.