IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 24, 2009, 12:00:25 PM (17 years ago)
Author:
Paul Price
Message:

Adding handling for missed exceptions, similar to register_imfile.pl --- the idea is to have exceptions trigger the my_die functions so that errors are recorded in the database, and don't go on forever.

File:
1 edited

Legend:

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

    r21395 r22430  
    2727use Pod::Usage qw( pod2usage );
    2828
     29# Look for programs we need
     30my $missing_tools;
     31my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
     32my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
     33my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     34if ($missing_tools) {
     35    warn("Can't find required tools.");
     36    exit($PS_EXIT_CONFIG_ERROR);
     37}
     38
    2939my ($diff_id, $dbname, $threads, $outroot, $reduction, $verbose, $no_update, $no_op, $redirect);
    3040my ($skycell_id, $diff_skyfile_id);
    3141GetOptions(
    3242    'diff_id=s'         => \$diff_id, # Diff identifier
    33     'skycell_id=s'      => \$skycell_id, # Diff identifier
     43    'skycell_id=s'      => \$skycell_id, # Skycell identifier
    3444    'diff_skyfile_id=s' => \$diff_skyfile_id, # Diff identifier
    3545    'dbname|d=s'        => \$dbname, # Database name
     
    5262    and defined $outroot;
    5363
     64# Unhandled exceptions should be passed on to my_die so they get pushed into the database
     65$SIG{__DIE__} = sub { die @_ if $^S;
     66                      my_die( $_[0], $diff_id, $skycell_id, $PS_EXIT_UNKNOWN_ERROR ); };
     67
    5468# XXX camera is not known here; cannot use filerules...
    5569# my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    56 
    5770my $logDest = "$outroot.log";
    5871$ipprc->redirect_output($logDest) if $redirect;
    5972
    6073my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
    61 
    62 # Look for programs we need
    63 my $missing_tools;
    64 my $difftool = can_run('difftool') or (warn "Can't find difftool" and $missing_tools = 1);
    65 my $ppSub = can_run('ppSub') or (warn "Can't find ppSub" and $missing_tools = 1);
    66 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    67 if ($missing_tools) {
    68     warn("Can't find required tools.");
    69     exit($PS_EXIT_CONFIG_ERROR);
    70 }
    7174
    7275# Get list of components for subtraction
     
    8083    unless ($success) {
    8184        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    82         &my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $error_code);
     85        &my_die("Unable to perform difftool -inputskyfile: $error_code", $diff_id, $skycell_id, $error_code);
    8386    }
    8487
    8588    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    86         &my_die("Unable to parse metadata config doc", $diff_id, $PS_EXIT_PROG_ERROR);
     89        &my_die("Unable to parse metadata config doc", $diff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
    8790    $files = parse_md_list($metadata) or
    88         &my_die("Unable to parse metadata list", $diff_id, $PS_EXIT_PROG_ERROR);
    89 }
    90 
    91 &my_die("Subtraction list does not contain exactly two elements", $diff_id, $PS_EXIT_SYS_ERROR) unless
    92     scalar @$files == 2;
     91        &my_die("Unable to parse metadata list", $diff_id, $skycell_id, $PS_EXIT_PROG_ERROR);
     92}
     93
     94&my_die("Subtraction list does not contain exactly two elements", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless scalar @$files == 2;
    9395
    9496# Identify the input and the template
     
    123125    }
    124126    if (defined $tess_id) {
    125         &my_die("Tesselation identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
     127        &my_die("Tesselation identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless
    126128            $file->{tess_id} eq $tess_id;
    127129    } else {
     
    129131    }
    130132    if (defined $skycell_id) {
    131         &my_die("Skycell identifiers don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless
     133        &my_die("Skycell identifiers don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless
    132134            $file->{skycell_id} eq $skycell_id;
    133135    } else {
     
    135137    }
    136138    if (defined $camera) {
    137         &my_die("Cameras don't match", $diff_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
     139        &my_die("Cameras don't match", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $file->{camera} eq $camera;
    138140    } else {
    139141        $camera = $file->{camera};
     
    142144}
    143145
    144 &my_die("Unable to identify template", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $template;
    145 &my_die("Unable to identify input", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $input;
    146 &my_die("Unable to identify camera", $diff_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
     146&my_die("Unable to identify template", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $template;
     147&my_die("Unable to identify input", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $input;
     148&my_die("Unable to identify camera", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless defined $camera;
    147149$ipprc->define_camera($camera);
    148150
     
    152154my $recipe_psphot  = $ipprc->reduction($reduction, 'DIFF_PSPHOT'); # Recipe to use for psphot
    153155unless ($recipe_ppSub and $recipe_psphot) {
    154     &my_die("Couldn't find selected reduction for DIFF_PPSUB and DIFF_PSPHOT: $reduction\n", $diff_id, $PS_EXIT_CONFIG_ERROR);
     156    &my_die("Couldn't find selected reduction for DIFF_PPSUB and DIFF_PSPHOT: $reduction\n", $diff_id, $skycell_id, $PS_EXIT_CONFIG_ERROR);
    155157}
    156158
     
    177179print "templateSources: $templateSources\n";
    178180
    179 &my_die("Couldn't find input: $template", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($template);
    180 &my_die("Couldn't find input: $templateMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateMask);
    181 &my_die("Couldn't find input: $templateVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateVariance);
    182 &my_die("Couldn't find input: $input", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
    183 &my_die("Couldn't find input: $inputMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
    184 &my_die("Couldn't find input: $inputVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
    185 &my_die("Couldn't find input: $templateSources", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
     181&my_die("Couldn't find input: $template", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($template);
     182&my_die("Couldn't find input: $templateMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateMask);
     183&my_die("Couldn't find input: $templateVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateVariance);
     184&my_die("Couldn't find input: $input", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input);
     185&my_die("Couldn't find input: $inputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputMask);
     186&my_die("Couldn't find input: $inputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inputVariance);
     187&my_die("Couldn't find input: $templateSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($templateSources);
    186188
    187189# Get the output filenames
     
    223225    unless ($success) {
    224226        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    225         &my_die("Unable to perform ppSub: $error_code", $diff_id, $error_code);
    226     }
    227     &my_die("Couldn't find expected output file: $outputName", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
    228     &my_die("Couldn't find expected output file: $outputMask", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    229     &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
    230 #    &my_die("Couldn't find expected output file: $outputSources", $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    231 #    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
    232 #    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
     227        &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code);
     228    }
     229    &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName);
     230    &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
     231    &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance);
     232#    &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
     233#    &my_die("Couldn't find expected output file: $bin1Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin1Name);
     234#    &my_die("Couldn't find expected output file: $bin2Name",    $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($bin2Name);
    233235
    234236    my $outputStatsReal = $ipprc->file_resolve($outputStats);
    235     &my_die("Couldn't find expected output file: $outputStats", $diff_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
     237    &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;
    236238
    237239    # measure chip stats
     
    241243    unless ($success) {
    242244        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    243         &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $error_code);
     245        &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code);
    244246    }
    245247    foreach my $line (@$stdout_buf) {
     
    263265        unless ($success) {
    264266            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    265             &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $error_code);
     267            &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $skycell_id, $error_code);
    266268        }
    267269    }
     
    273275    my $msg = shift;            # Warning message on die
    274276    my $diff_id = shift;        # Diff identifier
     277    my $skycell_id = shift;     # Skycell identifier
    275278    my $exit_code = shift;      # Exit code to add
    276279
    277280    warn($msg);
    278     if (defined $diff_id and not $no_update) {
     281    if (defined $diff_id and defined $skycell_id and not $no_update) {
    279282        my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -code $exit_code";
    280283        $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
Note: See TracChangeset for help on using the changeset viewer.