IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 10, 2010, 4:16:03 PM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091201/ippScripts/scripts/diff_skycell.pl

    r26753 r26873  
    3535}
    3636
    37 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $verbose, $no_update, $no_op, $redirect);
     37my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect);
    3838my ($skycell_id, $diff_skyfile_id);
    3939GetOptions(
     
    4343    'dbname|d=s'        => \$dbname, # Database name
    4444    'threads=s'         => \$threads,   # Number of threads to use
     45    'run-state=s'       => \$run_state,   # state for run: 'new' or 'update'
    4546    'outroot=s'         => \$outroot, # Output root name
    4647    'inverse'           => \$inverse, # Make inverse subtraction?
     
    5455pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5556pod2usage(
    56     -msg => "Required options: --diff_id --skycell_id --outroot --diff_skyfile_id",
     57    -msg => "Required options: --diff_id --skycell_id --outroot --run-state --diff_skyfile_id",
    5758    -exitval => 3,
    5859          ) unless defined $diff_id
    5960    and defined $skycell_id
    6061    and defined $diff_skyfile_id
     62    and defined $run_state
    6163    and defined $outroot;
    6264
     
    6668# my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    6769my $logDest = "$outroot.log";
     70$logDest .= ".update" if $run_state eq "update";
    6871$ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect;
    6972
     
    155158# The output file will be considered magicked if the input has been magicked and the
    156159# template is either a stack or a warp that has been magicked.
    157 # note that difftool -inputskyfile outputs the magicked boolean as an int not T or F
    158 # because the output is constructed from a union of two selects
    159 my $magicked = $inputMagic && $templateMagic;
     160my $magicked = $inputMagic && $templateMagic ? $inputMagic : 0;
    160161
    161162# Recipes to use based on reduction class
     
    216217my $traceDest = $ipprc->filename("TRACE.EXP", $outroot);
    217218
     219if ($run_state eq 'update') {
     220    $traceDest .= '.update';
     221    $outputStats .= '.update';
     222}
     223
    218224my ($inverseName, $inverseMask, $inverseVariance, $inverseSources);
    219225if ($inverse) {
     
    227233
    228234# Perform subtraction
    229 unless ($no_op) {
     235{
    230236    my $command = "$ppSub $outroot";
    231237    $command .= " -inimage $input";
     
    239245    $command .= " -stats $outputStats";
    240246    $command .= " -threads $threads" if defined $threads;
     247    if ($run_state eq "new") {
     248        $command .= " -dumpconfig $configuration";
     249    } else {
     250        my $configurationReal = $ipprc->file_resolve($configuration) or &my_die("Couldn't resolve configuration file: $configuration", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR);
     251        $command .= " -ipprc $configurationReal";
     252    }
    241253    $command .= " -recipe PPSUB $recipe_ppSub";
    242254    $command .= " -recipe PSPHOT $recipe_psphot";
     
    245257    $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF";
    246258    $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF";
    247     $command .= " -photometry";
     259    if ($run_state eq "new") {
     260        $command .= " -photometry";
     261    }
    248262    $command .= " -inverse" if $inverse;
    249263    $command .= " -tracedest $traceDest -log $logDest";
    250     $command .= " -dumpconfig $configuration";
    251264    $command .= " -dbname $dbname" if defined $dbname;
    252265    $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id;
    253266    $command .= " -source_id $source_id" if defined $source_id;
    254267
    255     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    256         run(command => $command, verbose => $verbose);
    257     unless ($success) {
    258         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    259         &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code);
    260     }
    261 
    262     my $outputStatsReal = $ipprc->file_resolve($outputStats);
    263     &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
    264 
    265     # measure chip stats
    266     $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
    267     ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    268         run(command => $command, verbose => $verbose);
    269     unless ($success) {
    270         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    271         &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code);
    272     }
    273     foreach my $line (@$stdout_buf) {
    274         $cmdflags .= " $line";
    275     }
    276     chomp $cmdflags;
    277 
    278     my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
    279 
    280     if (!$quality) {
    281         &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
    282         &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    283         &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
    284         &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    285         &my_die("Couldn't find expected output file: $jpeg1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name);
    286         &my_die("Couldn't find expected output file: $jpeg2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name);
    287         if ($inverse) {
    288             &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName);
    289             &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask);
    290             &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance);
    291             &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources);
    292         }
    293     }
    294 }
    295 
    296 unless ($no_update) {
    297 
    298     # Add the subtraction result
    299     {
    300         my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -path_base $outroot";
    301         $command .= " $cmdflags";
    302         $command .= " -magicked" if $magicked;
    303         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    304         $command .= " -hostname $host" if defined $host;
    305         $command .= " -dbname $dbname" if defined $dbname;
    306 
     268    unless ($no_op) {
    307269        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    308270            run(command => $command, verbose => $verbose);
    309271        unless ($success) {
    310272            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    311             &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $skycell_id, $error_code);
     273            &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code);
     274        }
     275
     276        my $outputStatsReal = $ipprc->file_resolve($outputStats);
     277        &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     278
     279        # measure chip stats
     280        $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL";
     281        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     282            run(command => $command, verbose => $verbose);
     283        unless ($success) {
     284            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     285            &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code);
     286        }
     287        foreach my $line (@$stdout_buf) {
     288            $cmdflags .= " $line";
     289        }
     290        chomp $cmdflags;
     291
     292        my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag
     293
     294        if (!$quality) {
     295            &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
     296            &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
     297            &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
     298            &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
     299            &my_die("Couldn't find expected output file: $jpeg1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name);
     300            &my_die("Couldn't find expected output file: $jpeg2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name);
     301            if ($inverse) {
     302                &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName);
     303                &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask);
     304                &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance);
     305                &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources);
     306            }
     307        }
     308    } else {
     309        print "Not executing: $command\n";
     310    }
     311}
     312
     313unless ($no_update) {
     314
     315    # Add the subtraction result
     316    {
     317        my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id";
     318        $command .= " -magicked $magicked" if $magicked;
     319        if ($run_state eq 'new') {
     320            $command .= " -adddiffskyfile -path_base $outroot";
     321            $command .= " $cmdflags";
     322            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     323            $command .= " -hostname $host" if defined $host;
     324        } else {
     325            $command .= " -tofullskyfile";
     326        }
     327        $command .= " -dbname $dbname" if defined $dbname;
     328
     329        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     330            run(command => $command, verbose => $verbose);
     331        unless ($success) {
     332            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     333            my $err_message = $run_state eq "update" ?
     334                "Unable to perform difftool -adddiffskyfile" :
     335                "Unable to perform difftool -tofullskyfile";
     336            &my_die("$err_message: $error_code", $diff_id, $skycell_id, $error_code);
    312337        }
    313338    }
     
    326351    warn($msg);
    327352    if (defined $diff_id and defined $skycell_id and not $no_update) {
    328         my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code";
    329         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    330         $command .= " -hostname $host" if defined $host;
    331         $command .= " -path_base $outroot" if defined $outroot;
    332         $command .= " -dbname $dbname" if defined $dbname;
     353        my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code";
     354        if ($run_state eq 'new') {
     355            $command .= " -adddiffskyfile";
     356            $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
     357            $command .= " -hostname $host" if defined $host;
     358            $command .= " -path_base $outroot" if defined $outroot;
     359            $command .= " -dbname $dbname" if defined $dbname;
     360        } else {
     361            $command .= " -updatediffskyfile";
     362        }
    333363        run(command => $command, verbose => $verbose);
    334364    }
Note: See TracChangeset for help on using the changeset viewer.