IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23438


Ignore:
Timestamp:
Mar 19, 2009, 2:54:59 PM (17 years ago)
Author:
bills
Message:

manage magicked status of diffSkyfiles made with magicked inputs

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/diff_skycell.pl

    r23435 r23438  
    9595my $tess_id;                    # Tesselation identifier
    9696my $camera;                     # Camera
     97my $magicked_0;
     98my $magicked_1;
    9799foreach my $file (@$files) {
    98100    if (defined $file->{template} and $file->{template}) {
     
    103105            $templateVariance = "PPSTACK.OUTPUT.VARIANCE";
    104106            $templateSources = "PSPHOT.OUT.CMF.MEF";  ## this must be consistent with the value in stack_skycell.pl:161
     107            # template is a stack so it doesn't need to be magicked
     108            $magicked_1 = 1;
    105109            ## use an explicit stack name for psphot output objects
    106110        } else {
     
    108112            $templateVariance = "PSWARP.OUTPUT.VARIANCE";
    109113            $templateSources = "PSWARP.OUTPUT.SOURCES";
     114            $magicked_1 = $file->{magicked};
    110115        }
    111116    } else {
    112117        $input = $file->{uri};
    113118        $inputPath = $file->{path_base};
     119        $magicked_0 = $file->{magicked};    # if input is a stack the output can't be "magicked"
    114120        if ($file->{warp_id} == 0) {
    115121            $inputMask = "PPSTACK.OUTPUT.MASK";
     
    146152&my_die("Unable to identify camera", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
    147153$ipprc->define_camera($camera);
     154
     155# Compute the magicked status of the output.
     156# The output file will be considered magicked if the input has been magicked and the
     157# template is either a stack or a warp that has been magicked.
     158# note that difftool -inputskyfile outputs the magicked boolean as an int not T or F
     159# because the output is constructed from a union of two selects
     160my $magicked = $magicked_0 && $magicked_1;
    148161
    149162# Recipes to use based on reduction class
     
    265278        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -uri $outputName -path_base $outroot";
    266279        $command .= " $cmdflags";
     280        $command .= " -magicked" if $magicked;
    267281        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    268282        $command .= " -hostname $host" if defined $host;
  • trunk/ippTools/share/difftool_completed_runs.sql

    r20973 r23438  
    11SELECT DISTINCT
    2     diff_id
     2    diff_id,
     3    all_magicked as magicked
    34FROM (
    45    SELECT
    56        COUNT(diffInputSkyfile.skycell_id), COUNT(diffSkyfile.skycell_id),
    6         diffSkyfile.*
     7        diffSkyfile.*,
     8        SUM(!diffSkyfile.magicked) = 0 as all_magicked
    79    FROM diffRun
    810    JOIN diffInputSkyfile USING(diff_id)
  • trunk/ippTools/src/difftool.c

    r23388 r23438  
    4848static bool importrunMode(pxConfig *config);
    4949
    50 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state);
     50static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, bool magicked);
    5151static bool diffRunComplete(pxConfig *config);
    5252
     
    169169    if (state) {
    170170        // set detRun.state to state
    171         return setdiffRunState(config, diff_id, state);
     171        return setdiffRunState(config, diff_id, state, false);
    172172    }
    173173
     
    283283
    284284    if (count == 2) {
    285         if (!setdiffRunState(config, diff_id, "new")) {
     285        if (!setdiffRunState(config, diff_id, "new", false)) {
    286286            if (!psDBRollback(config->dbh)) {
    287287                psError(PS_ERR_UNKNOWN, false, "database error");
     
    732732
    733733
    734 static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state)
     734static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, bool magicked)
    735735{
    736736    PS_ASSERT_PTR_NON_NULL(state, false);
     
    742742    }
    743743
    744     char *query = "UPDATE diffRun SET state = '%s' WHERE diff_id = %"PRId64;
    745     if (!p_psDBRunQueryF(config->dbh, query, state, diff_id)) {
     744    char *query = "UPDATE diffRun SET state = '%s', magicked = %d WHERE diff_id = %"PRId64;
     745
     746    if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
    746747        psError(PS_ERR_UNKNOWN, false,
    747748                "failed to change state for diff_id %"PRId64, diff_id);
     
    11691170        query = NULL;
    11701171
    1171         if (!setdiffRunState(config, run->diff_id, "new")) {
     1172        if (!setdiffRunState(config, run->diff_id, "new", false)) {
    11721173            psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64,
    11731174                run->diff_id);
     
    14321433
    14331434        psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id");
     1435        bool magicked = psMetadataLookupBool(NULL, row, "magicked");
    14341436
    14351437        // set diffRun.state to 'stop'
    1436         if (!setdiffRunState(config, diff_id, "full")) {
     1438        if (!setdiffRunState(config, diff_id, "full", magicked)) {
    14371439            psError(PS_ERR_UNKNOWN, false, "failed to change diffRun.state for diff_id: %" PRId64,
    14381440                diff_id);
  • trunk/ippTools/src/magicdstool.c

    r23389 r23438  
    4040
    4141static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
    42 static bool magicDSRunComplete(pxConfig *config);
     42static bool magicDSRunComplete(pxConfig *config, bool setmagicked);
    4343static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id);
    4444
     
    528528}
    529529
     530static bool
     531setRunMagicked(pxConfig *config, psS64 magic_ds_id)
     532{
     533    // first query the magicDSRun to find the stage and the stage_id
     534    psString query = "SELECT stage, stage_id from magicDSRun where magic_ds_id = %" PRId64;
     535
     536    if (!p_psDBRunQueryF(config->dbh, query, magic_ds_id)) {
     537        psError(PS_ERR_UNKNOWN, false, "database error");
     538        return false;
     539    }
     540
     541    psArray *output = p_psDBFetchResult(config->dbh);
     542    if (!output) {
     543        psError(PS_ERR_UNKNOWN, false, "database error");
     544        return false;
     545    }
     546    if (!psArrayLength(output)) {
     547        psError(PS_ERR_UNKNOWN, true, "magicDSRun not found for magic_ds_id %" PRId64, magic_ds_id);
     548        psFree(output);
     549        return false;
     550    }
     551    if (psArrayLength(output) > 1) {
     552        psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found %ld for magic_ds_id %" PRId64,
     553            psArrayLength(output), magic_ds_id);
     554        psFree(output);
     555        return false;
     556    }
     557    psMetadata *row = output->data[0];
     558
     559    psString stage = psMetadataLookupStr(NULL, row, "stage");
     560    psS64 stage_id = psMetadataLookupS64(NULL, row, "stage_id");
     561
     562
     563    // chose the appropriate query based on the stage
     564    if (!strcmp(stage, "raw")) {
     565        query = "UPDATE rawExp SET magicked = 1 where exp_id = %" PRId64;
     566    } else if (!strcmp(stage, "chip")) {
     567        query = "UPDATE chipRun SET magicked = 1 where chip_id = %" PRId64;
     568    } else if (!strcmp(stage, "warp")) {
     569        query = "UPDATE warpRun SET magicked = 1 where warp_id = %" PRId64;
     570    } else if (!strcmp(stage, "diff")) {
     571        query = "UPDATE diffRun SET magicked = 1 where diff_id = %" PRId64;
     572    } else {
     573        psError(PS_ERR_UNKNOWN, true, "unexpected value for stage: %s found", stage);
     574        psFree(output);
     575        return false;
     576    }
     577    if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
     578        psError(PS_ERR_UNKNOWN, false, "database error");
     579        return false;
     580    }
     581    psFree(output);
     582
     583    psU64 affected = psDBAffectedRows(config->dbh);
     584    if (affected != 1) {
     585        psError(PS_ERR_UNKNOWN, false, "should have affected 1 row");
     586        return false;
     587    }
     588
     589    return true;
     590}
     591
    530592static bool adddestreakedfileMode(pxConfig *config)
    531593{
     
    553615
    554616    if (setmagicked) {
     617        // set the image file's magicked flag
    555618        if (!setMagicked(config, magic_ds_id, component)) {
    556619            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
     620            if (!psDBRollback(config->dbh)) {
     621                psError(PS_ERR_UNKNOWN, false, "database error");
     622            }
    557623            return false;
    558624        }
     
    568634    }
    569635
    570     if (!magicDSRunComplete(config)) {
     636    if (!magicDSRunComplete(config, setmagicked)) {
    571637            // rollback
    572638        if (!psDBRollback(config->dbh)) {
     
    593659
    594660    if (!strcmp(stage, "diff")) {
    595         // don't need these ids for diff stage
     661        // don't need these ids for diff stage because diff_id is in the magicRun
    596662        *stage_id = 0;
    597663        *cam_id = 0;
     
    654720}
    655721
    656 static bool magicDSRunComplete(pxConfig *config)
     722static bool magicDSRunComplete(pxConfig *config, bool setmagicked)
    657723{
    658724    PS_ASSERT_PTR_NON_NULL(config, false);
     
    686752
    687753        psS64 magic_ds_id = psMetadataLookupS64(NULL, row, "magic_ds_id");
     754
     755        // if requested, set stageRun.magicked
     756        if (setmagicked && !setRunMagicked(config, magic_ds_id)) {
     757            psError(PS_ERR_UNKNOWN, false, "failed to change stageRun.magicked for magic_ds_id: %" PRId64,
     758                magic_ds_id);
     759            return false;
     760        }
    688761
    689762        // set magicDSRun.state to 'full'
Note: See TracChangeset for help on using the changeset viewer.