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/detrend_correct_imfile.pl

    r20378 r22430  
    2424use Pod::Usage qw( pod2usage );
    2525
     26# Look for programs we need
     27my $missing_tools;
     28my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
     29my $dvoApplyCorr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1);
     30if ($missing_tools) {
     31    warn("Can't find required tools.");
     32    exit($PS_EXIT_CONFIG_ERROR);
     33}
     34
    2635my ( $det_id, $class_id, $det_type, $input_uri, $camera, $dbname,
    2736     $verbose, $no_update, $no_op, $outroot, $redirect, $corr_uri );
     
    4352pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    4453pod2usage( -msg => "Required options: --det_id --class_id --det_type --input_uri --camera --outroot",
    45            -exitval => 3)
     54           -exitval => 3)
    4655    unless defined $det_id
    4756    and defined $class_id
     
    5059    and defined $outroot
    5160    and defined $camera;
     61
     62# Unhandled exceptions should be passed on to my_die so they get pushed into the database
     63$SIG{__DIE__} = sub { die @_ if $^S;
     64                      my_die( $_[0], $det_id, $class_id, $PS_EXIT_UNKNOWN_ERROR ); };
    5265
    5366# XXX this exits with status = 0 on failure
     
    6073}
    6174
    62 # Recipes to use as a function of detrend type 
    63 # XXX there are no recipe options for dvoApplyCorr... 
     75# Recipes to use as a function of detrend type
     76# XXX there are no recipe options for dvoApplyCorr...
    6477# XXX in the future, we may define corrections other than the flat-field correction
    6578# $reduction = "DETREND" unless defined $reduction;
     
    6982# det_type is type of the CORRECTED (output) file
    7083if ($det_type ne "FLAT") { warn ("unexpected input detrend type: correcting data of type $det_type"); }
    71 
    72 # Look for programs we need
    73 my $missing_tools;
    74 my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    75 my $dvoApplyCorr = can_run('dvoApplyCorr') or (warn "Can't find dvoApplyCorr" and $missing_tools = 1);
    76 if ($missing_tools) {
    77     warn("Can't find required tools.");
    78     exit($PS_EXIT_CONFIG_ERROR);
    79 }
    8084
    8185&my_die("Couldn't find input file: $input_uri\n", $det_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($input_uri);
     
    9195
    9296    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    93         run(command => $command, verbose => $verbose);
     97        run(command => $command, verbose => $verbose);
    9498    unless ($success) {
    95         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    96         &my_die("Unable to perform ppImage: $error_code", $det_id, $class_id, $error_code);
     99        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     100        &my_die("Unable to perform ppImage: $error_code", $det_id, $class_id, $error_code);
    97101    }
    98102
     
    111115unless ($no_update) {
    112116    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    113         run(command => $command, verbose => $verbose);
     117        run(command => $command, verbose => $verbose);
    114118    unless ($success) {
    115         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    116         warn("Unable to perform dettool -addcorrectimfile: $error_code\n");
    117         exit($error_code);
     119        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     120        warn("Unable to perform dettool -addcorrectimfile: $error_code\n");
     121        exit($error_code);
    118122    }
    119123} else {
     
    124128{
    125129    my $msg = shift; # Warning message on die
    126     my $det_id = shift;         # Detrend identifier
     130    my $det_id = shift;         # Detrend identifier
    127131    my $class_id = shift; # Class identifier
    128132    my $exit_code = shift; # Exit code to add
     
    130134    carp($msg);
    131135    if (defined $det_id and defined $class_id and not $no_update) {
    132         my $command = "$dettool -addcorrectimfile";
    133         $command .= " -det_id $det_id";
    134         $command .= " -class_id $class_id";
    135         $command .= " -path_base $outroot";
    136         $command .= " -code $exit_code";
    137         $command .= " -dbname $dbname" if defined $dbname;
     136        my $command = "$dettool -addcorrectimfile";
     137        $command .= " -det_id $det_id";
     138        $command .= " -class_id $class_id";
     139        $command .= " -path_base $outroot";
     140        $command .= " -code $exit_code";
     141        $command .= " -dbname $dbname" if defined $dbname;
    138142        system ($command);
    139143    }
Note: See TracChangeset for help on using the changeset viewer.