IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 25, 2007, 7:10:31 PM (19 years ago)
Author:
Paul Price
Message:

Adding error handling; not yet tested --- there may be compilation errors.

File:
1 edited

Legend:

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

    r11298 r11316  
    1212use Data::Dumper;
    1313
    14 use PS::IPP::Config;
     14use PS::IPP::Config qw(
     15    $PS_EXIT_SUCCESS
     16    $PS_EXIT_UNKNOWN_ERROR
     17    $PS_EXIT_SYS_ERROR
     18    $PS_EXIT_CONFIG_ERROR
     19    $PS_EXIT_PROG_ERROR
     20    $PS_EXIT_DATA_ERROR
     21    $PS_EXIT_TIMEOUT_ERROR
     22    );
    1523my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1624use File::Spec;
     
    92100my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    93101my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    94 die "Can't find required tools.\n" if $missing_tools;
     102if ($missing_tools) {
     103    warn("Can't find required tools.");
     104    exit($PS_EXIT_CONFIG_ERROR);
     105}
    95106
    96107# Recipe to use in processing
    97 die "Unrecognised mode: $mode\n" if not defined RECIPES->{$mode};
     108&my_die("Unrecognised mode: $mode", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR) unless defined RECIPES->{$mode};
    98109my $recipe = RECIPES->{$mode}->{lc($det_type)};
    99 die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
     110&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR) unless defined $recipe;
    100111
    101112### Output file names --- must match camera configuration!
     
    124135    if (lc($mode) ne 'verify') {
    125136        my $detFlag = DETRENDS->{lc($det_type)};
    126         die "Unrecognised detrend type: $det_type\n" if not defined $detFlag;
     137        &my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR) unless defined $detFlag;
    127138        $command .= "$detFlag $detrend";
    128139    }
     
    130141    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    131142        run(command => $command, verbose => 1);
    132     die "Unable to perform ppImage on $input_uri: $error_code\n" if not $success;
    133     die "Couldn't find expected output file: $outputName\n" if not -f $outputName;
    134     die "Couldn't find expected output file: $outputStats\n" if not -f $outputStats;
    135     die "Couldn't find expected output file: $bin1Name\n" if not -f $bin1Name;
    136     die "Couldn't find expected output file: $bin2Name\n" if not -f $bin2Name;
     143    unless ($success) {
     144        $error_code >> 8;
     145        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $exp_tag, $class_id, $error_code);
     146    }
     147    &my_die("Couldn't find expected output file: $outputName", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputName;
     148    &my_die("Couldn't find expected output file: $outputStats", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     149    &my_die("Couldn't find expected output file: $bin1Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin1Name;
     150    &my_die("Couldn't find expected output file: $bin2Name", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $bin2Name;
    137151}
    138152
     
    141155{
    142156    my $statsFile;              # File handle
    143     open $statsFile, $outputStats or die "Can't open statistics file $outputStats: $!\n";
     157    open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
    144158    my @contents = <$statsFile>; # Contents of file
    145159    close $statsFile;
    146160    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    147     my $metadata = $mdcParser->parse(join "", @contents)
    148         or die "unable to parse metadata config doc";
     161    my $metadata = $mdcParser->parse(join "", @contents) or
     162        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    149163    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    150     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     164    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    151165}
    152166
     
    173187    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    174188        run(command => $command, verbose => 1);
    175     die "Unable to perform dettool -addprocessed for $det_id/$exp_tag/$class_id: $error_code\n"
    176         if not $success;
     189    unless ($success) {
     190        $error_code >> 8;
     191        warn("Unable to perform dettool -addresidimfile: $error_code\n");
     192        exit($error_code);
     193    }
    177194
    178195    unlink $outputStats;   
     196}
     197
     198
     199
     200sub my_die
     201{
     202    my $msg = shift; # Warning message on die
     203    my $det_id = shift;         # Detrend identifier
     204    my $iter = shift;           # Iteration
     205    my $exp_tag = shift; # Exposure tag
     206    my $class_id = shift; # Class identifier
     207    my $exit_code = shift; # Exit code to add
     208
     209    warn($msg);
     210    if ($det_id and $iter and $exp_tag) {
     211        my $command = "$dettool -addresidimfile -det_id $det_id -iteration $iter -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     212        $command .= " -dbname $dbname" if defined $dbname;
     213        system ($command);
     214    }
     215    exit $exit_code;
    179216}
    180217
Note: See TracChangeset for help on using the changeset viewer.