IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 7, 2009, 4:08:25 PM (17 years ago)
Author:
Paul Price
Message:

Merging trunk (r25026) to get up-to-date on old branch.

Location:
branches/pap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippTools/src

    • Property svn:ignore
      •  

        old new  
        3434disttool
        3535receivetool
         36
         37pubtool
  • branches/pap/ippTools/src/difftool.c

    r23940 r25027  
    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);
     
    4949static bool importrunMode(pxConfig *config);
    5050
    51 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, bool magicked);
     51static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked);
    5252static bool diffRunComplete(pxConfig *config);
    5353
     
    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    );
    138140    if (!run) {
    139141        psError(PS_ERR_UNKNOWN, false, "failed to alloc diffRun object");
    140         return true;
     142        return false;
    141143    }
    142144    if (!diffRunInsertObject(config->dbh, run)) {
    143145        psError(PS_ERR_UNKNOWN, false, "database error");
    144146        psFree(run);
    145         return true;
     147        return false;
    146148    }
    147149
     
    150152
    151153    if (!diffRunPrintObject(stdout, run, !simple)) {
    152             psError(PS_ERR_UNKNOWN, false, "failed to print object");
    153             psFree(run);
    154             return false;
     154        psError(PS_ERR_UNKNOWN, false, "failed to print object");
     155        psFree(run);
     156        return false;
    155157    }
    156158
     
    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
     
    511512    PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
    512513    PXOPT_LOOKUP_F32(good_frac, config->args, "-good_frac", false, false);
    513     PXOPT_LOOKUP_BOOL(magicked, config->args, "-magicked", false);
     514    PXOPT_LOOKUP_S64(magicked, config->args, "-magicked", false, false);
    514515
    515516    if (!psDBTransaction(config->dbh)) {
     
    521522                           diff_id,
    522523                           skycell_id,
    523                            uri,
    524524                           path_base,
    525525                           "full",
     
    582582    PXOPT_COPY_STR(config->args, where, "-skycell_id", "diffInputSkyfile.skycell_id", "==");
    583583    PXOPT_COPY_S64(config->args, where,  "-diff_skyfile_id", "diffInputSkyfile.diff_skyfile_id", "==");
    584     PXOPT_COPY_STR(config->args, where, "-tess_id", "diffSkyfile.tess_id", "==");
     584    PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "==");
    585585    PXOPT_COPY_S16(config->args, where, "-fault", "diffSkyfile.fault", "==");
    586586    PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "==");
     
    662662    PXOPT_COPY_S16(config->args, where, "-fault",     "fault", "==");
    663663
     664    if (!psListLength(where->list) && !psMetadataLookupBool(NULL, config->args, "-all")) {
     665        psFree(where);
     666        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     667        return false;
     668    }
     669
    664670    if (!psDBTransaction(config->dbh)) {
    665671        psError(PS_ERR_UNKNOWN, false, "database error");
     
    695701        psFree(query);
    696702
    697         psLogMsg("diftool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh));
     703        psLogMsg("difftool", PS_LOG_INFO, "Updated %" PRIu64 " rows", psDBAffectedRows(config->dbh));
    698704    }
    699705
     
    739745
    740746
    741 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, bool magicked)
     747static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked)
    742748{
    743749    PS_ASSERT_PTR_NON_NULL(state, false);
     
    749755    }
    750756
    751     char *query = "UPDATE diffRun SET state = '%s', magicked = %d WHERE diff_id = %"PRId64;
     757    char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
    752758
    753759    if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
     
    771777                         psS64 template_warp_id, // Warp identifier for template image, PS_MAX_S64 for none
    772778                         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)
    774779                         pxConfig *config // Configuration
    775780                         )
     
    802807            registered,
    803808            tess_id,
    804             exp_id,
    805             false       // magicked
     809            false,
     810            false,
     811            0       // magicked
    806812    );
    807813
     
    882888    PXOPT_LOOKUP_S64(input_warp_id, config->args, "-input_warp_id", false, false);
    883889    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);
    885890    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    886891
     
    902907        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    903908                "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.");
    909909        return false;
    910910    }
     
    917917                      template_warp_id ? template_warp_id : PS_MAX_S64,
    918918                      template_stack_id ? template_stack_id : PS_MAX_S64,
    919                       exp_id ? exp_id : PS_MAX_S64,
    920919                      config)) {
    921920        psError(PS_ERR_UNKNOWN, false, "failed to create populated diffRun");
     
    935934
    936935
    937 static bool definebyqueryMode(pxConfig *config)
     936static bool definewarpstackMode(pxConfig *config)
    938937{
    939938    PS_ASSERT_PTR_NON_NULL(config, false);
     
    944943
    945944    PXOPT_COPY_S64(config->args, expWhere, "-exp_id", "exp_id", "==");
     945    PXOPT_COPY_STR(config->args, expWhere, "-filter", "filter", "==");
    946946    PXOPT_COPY_S64(config->args, warpWhere, "-warp_id", "warpRun.warp_id", "==");
    947947    PXOPT_COPY_STR(config->args, warpWhere, "-skycell_id", "warpSkyfile.skycell_id", "==");
    948948    PXOPT_COPY_STR(config->args, warpWhere, "-tess_id", "warpRun.tess_id", "==");
    949     PXOPT_COPY_STR(config->args, warpWhere, "-filter", "rawExp.filter", "==");
    950949    PXOPT_COPY_STR(config->args, warpWhere, "-warp_label", "warpRun.label", "==");
    951950    PXOPT_COPY_F32(config->args, warpWhere,  "-good_frac", "warpSkyfile.good_frac", ">=");
     
    960959    PXOPT_LOOKUP_BOOL(reRun, config->args, "-rerun", false);
    961960    PXOPT_LOOKUP_BOOL(available, config->args, "-available", false);
     961    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    962962
    963963    // find all things to queue
    964     psString query = pxDataGet("difftool_definebyquery_part1.sql");
     964    psString query = pxDataGet("difftool_definewarpstack_part1.sql");
    965965    if (!query) {
    966966        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     
    10571057    }
    10581058
     1059    if (pretend) {
     1060        // negative simple so the default is true
     1061        if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) {
     1062            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1063            psFree(output);
     1064            return false;
     1065        }
     1066        psFree(output);
     1067        return true;
     1068    }
     1069
    10591070    // create temporary table
    1060     query = pxDataGet("difftool_definebyquery_temp_create.sql");
     1071    query = pxDataGet("difftool_definewarpstack_temp_create.sql");
    10611072    if (!p_psDBRunQuery(config->dbh, query)) {
    10621073        psError(PS_ERR_UNKNOWN, false, "database error");
     
    10701081    query = NULL;
    10711082
    1072     psString skycell_query = pxDataGet("difftool_definebyquery_part2.sql");
     1083    psString skycell_query = pxDataGet("difftool_definewarpstack_part2.sql");
    10731084
    10741085    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
     
    11831194                registered,
    11841195                tess_id,
    1185                 exp_id,
    1186                 false       // magicked
     1196                false,                  // bothways
     1197                true,                   // exposure
     1198                0       // magicked
    11871199        );
    11881200
     
    12821294                   "ABS(TIME_TO_SEC(TIMEDIFF(inputRawExp.dateobs, templateRawExp.dateobs)))", "<=");
    12831295
     1296    // other where restrictions:
     1297    PXOPT_COPY_TIME(config->args,  selectWhere, "-dateobs_begin",      "inputRawExp.dateobs",        ">=");
     1298    PXOPT_COPY_TIME(config->args,  selectWhere, "-dateobs_end",        "inputRawExp.dateobs",        "<=");
     1299    PXOPT_COPY_RADEC(config->args, selectWhere, "-ra_min",             "inputRawExp.ra",             ">=");
     1300    PXOPT_COPY_RADEC(config->args, selectWhere, "-ra_max",             "inputRawExp.ra",             "<");
     1301    PXOPT_COPY_RADEC(config->args, selectWhere, "-decl_min",           "inputRawExp.decl",           ">=");
     1302    PXOPT_COPY_RADEC(config->args, selectWhere, "-decl_max",           "inputRawExp.decl",           "<");
     1303    PXOPT_COPY_F32(config->args,   selectWhere, "-sat_pixel_frac_min", "inputRawExp.sat_pixel_frac", ">=");
     1304    PXOPT_COPY_F32(config->args,   selectWhere, "-sat_pixel_frac_max", "inputRawExp.sat_pixel_frac", "<");
     1305    PXOPT_COPY_F64(config->args,   selectWhere, "-airmass_min",        "inputRawExp.airmass",        ">=");
     1306    PXOPT_COPY_F64(config->args,   selectWhere, "-airmass_max",        "inputRawExp.airmass",        "<");
     1307    PXOPT_COPY_F32(config->args,   selectWhere, "-exp_time_min",       "inputRawExp.exp_time",       ">=");
     1308    PXOPT_COPY_F32(config->args,   selectWhere, "-exp_time_max",       "inputRawExp.exp_time",       "<");
     1309    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_min",             "inputRawExp.bg",             ">=");
     1310    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_max",             "inputRawExp.bg",             "<");
     1311    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_stdev_min",       "inputRawExp.bg_stdev",       ">=");
     1312    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_stdev_max",       "inputRawExp.bg_stdev",       "<");
     1313    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_mean_stdev_min",  "inputRawExp.bg_mean_stdev",  ">=");
     1314    PXOPT_COPY_F64(config->args,   selectWhere, "-bg_mean_stdev_max",  "inputRawExp.bg_mean_stdev",  "<");
     1315    PXOPT_COPY_F64(config->args,   selectWhere, "-alt_min",            "inputRawExp.alt",            ">=");
     1316    PXOPT_COPY_F64(config->args,   selectWhere, "-alt_max",            "inputRawExp.alt",            "<");
     1317    PXOPT_COPY_F64(config->args,   selectWhere, "-az_min",             "inputRawExp.az",             ">=");
     1318    PXOPT_COPY_F64(config->args,   selectWhere, "-az_max",             "inputRawExp.az",             "<");
     1319    PXOPT_COPY_F32(config->args,   selectWhere, "-ccd_temp_min",       "inputRawExp.ccd_temp",       ">=");
     1320    PXOPT_COPY_F32(config->args,   selectWhere, "-ccd_temp_max",       "inputRawExp.ccd_temp",       "<");
     1321    PXOPT_COPY_F64(config->args,   selectWhere, "-posang_min",         "inputRawExp.posang",         ">=");
     1322    PXOPT_COPY_F64(config->args,   selectWhere, "-posang_max",         "inputRawExp.posang",         "<");
     1323    PXOPT_COPY_F32(config->args,   selectWhere, "-sun_angle_min",      "inputRawExp.sun_angle",      ">=");
     1324    PXOPT_COPY_F32(config->args,   selectWhere, "-sun_angle_max",      "inputRawExp.sun_angle",      "<");
     1325    PXOPT_COPY_STR(config->args,   selectWhere, "-comment",            "inputRawExp.comment",        "LIKE");
     1326
    12841327    // Haversine formula for great circle distance
    12851328    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))))", "<=");
     1329                   "DEGREES(2*ASIN(SQRT(POW(SIN(inputRawExp.decl - templateRawExp.decl),2) + "
     1330                   "COS(inputRawExp.decl)*COS(templateRawExp.decl)*"
     1331                   "POW(SIN(inputRawExp.ra - templateRawExp.ra),2))))", "<=");
    12871332
    12881333    PXOPT_LOOKUP_BOOL(backwards, config->args, "-backwards", false);
     
    13081353    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    13091354
     1355    if (!psDBTransaction(config->dbh)) {
     1356        psError(PS_ERR_UNKNOWN, false, "database error");
     1357        psFree(selectWhere);
     1358        psFree(insertWhere);
     1359        return false;
     1360    }
     1361
     1362    if (!rerun) {
     1363        // Need to build table of exposures with diffs
     1364        psString tempCreate = pxDataGet("difftool_definewarpwarp_temp_create.sql"); // Create temp table SQL
     1365        if (!tempCreate) {
     1366            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1367            psFree(selectWhere);
     1368            psFree(insertWhere);
     1369            if (!psDBRollback(config->dbh)) {
     1370                psError(PS_ERR_UNKNOWN, false, "database error");
     1371            }
     1372            return false;
     1373        }
     1374
     1375        if (!p_psDBRunQuery(config->dbh, tempCreate)) {
     1376            psError(PS_ERR_UNKNOWN, false, "Unable to create temp table: %s", tempCreate);
     1377            psFree(tempCreate);
     1378            psFree(selectWhere);
     1379            psFree(insertWhere);
     1380            if (!psDBRollback(config->dbh)) {
     1381                psError(PS_ERR_UNKNOWN, false, "database error");
     1382            }
     1383            return false;
     1384        }
     1385        psFree(tempCreate);
     1386
     1387        psString tempInsert = pxDataGet("difftool_definewarpwarp_temp_insert.sql"); // Insert to temp table
     1388        if (!tempInsert) {
     1389            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1390            psFree(selectWhere);
     1391            psFree(insertWhere);
     1392            if (!psDBRollback(config->dbh)) {
     1393                psError(PS_ERR_UNKNOWN, false, "database error");
     1394            }
     1395            return false;
     1396        }
     1397
     1398        psString where = psStringCopy(""); // WHERE for insertion
     1399        if (label) {
     1400            psStringAppend(&where, "\nAND diffRun.label = '%s'", label);
     1401        }
     1402
     1403        if (!p_psDBRunQueryF(config->dbh, tempInsert, where, where)) {
     1404            psError(PS_ERR_UNKNOWN, false, "Unable to insert into temp table: %s", tempInsert);
     1405            psFree(tempInsert);
     1406            psFree(where);
     1407            psFree(selectWhere);
     1408            psFree(insertWhere);
     1409            if (!psDBRollback(config->dbh)) {
     1410                psError(PS_ERR_UNKNOWN, false, "database error");
     1411            }
     1412            return false;
     1413        }
     1414        psFree(where);
     1415        psFree(tempInsert);
     1416    }
     1417
     1418    // Get list of warps to diff
    13101419    psString select = pxDataGet("difftool_definewarpwarp_select.sql");
    13111420    if (!select) {
    13121421        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     1422        psFree(selectWhere);
     1423        psFree(insertWhere);
     1424        if (!psDBRollback(config->dbh)) {
     1425            psError(PS_ERR_UNKNOWN, false, "database error");
     1426        }
    13131427        return false;
    13141428    }
     
    13231437    psFree(selectWhere);
    13241438
     1439    if (!available) {
     1440        psStringAppend(&whereClause,
     1441                       "\n%s inputWarpRun.state = 'full'"
     1442                       "AND templateWarpRun.state = 'full'",
     1443                       whereClause ? "AND" : "WHERE");
     1444    }
     1445
    13251446    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 
    1333     if (!available) {
    1334         psStringAppend(&whereClause, "\n%s inputWarpRun.state = 'full'", whereClause ? "AND" : "WHERE");
    1335     }
    1336 
    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;
     1447        psStringAppend(&whereClause, "\n%s diffs.diff_id IS NULL", whereClause ? "AND" : "WHERE");
    13431448    }
    13441449
    13451450    if (!p_psDBRunQueryF(config->dbh, select,
    1346                          !rerun ? "\n" : "", // Activate LEFT JOIN against diffRun?
     1451                         !rerun ? "\n" : "", // Activate LEFT JOIN against diffs?
    13471452                         whereClause)) {
    13481453        psError(PS_ERR_UNKNOWN, false, "Unable to run query: %s [WITH] %s", select, whereClause);
     
    14141519        psMetadata *row = results->data[i]; // Result row from query
    14151520
    1416         psS64 exp_id = psMetadataLookupS64(NULL, row, "input_exp_id");
    14171521        psS64 input_id = psMetadataLookupS64(NULL, row, "input_warp_id");
    14181522        const char *template = psMetadataLookupStr(NULL, row, "template_warp_id");
    14191523        const char *tess_id = psMetadataLookupStr(NULL, row, "tess_id");
    1420         if (!exp_id || !input_id || !template || !tess_id) {
     1524        if (!input_id || !template || !tess_id) {
    14211525            psError(PXTOOLS_ERR_PROG, false, "Identifiers not found");
    14221526            psFree(list);
     
    14301534
    14311535        diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered,
    1432                                           tess_id, exp_id, false); // Run to insert
     1536                                          tess_id, true, true, false); // Run to insert
    14331537        if (!diffRunInsertObject(config->dbh, run)) {
    14341538            psError(PS_ERR_UNKNOWN, false, "database error");
     
    15111615
    15121616    psMetadata *where = psMetadataAlloc();
    1513     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     1617    pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "==");
    15141618
    15151619    psString query = pxDataGet("difftool_pendingcleanuprun.sql");
     
    15761680        PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
    15771681    }
    1578     pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     1682    pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "==");
    15791683
    15801684    psString query = pxDataGet("difftool_pendingcleanupskyfile.sql");
     
    17381842
    17391843        psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id");
    1740         bool magicked = psMetadataLookupBool(NULL, row, "magicked");
     1844        psS64 magicked = psMetadataLookupS64(NULL, row, "magicked");
    17411845
    17421846        // set diffRun.state to 'stop'
Note: See TracChangeset for help on using the changeset viewer.