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_reject_imfile.pl

    r11298 r11316  
    1212use Statistics::Descriptive;
    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;
     
    5260my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    5361my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    54 die "Can't find required tools.\n" if $missing_tools;
     62if ($missing_tools) {
     63    warn("Can't find required tools.");
     64    exit($PS_EXIT_CONFIG_ERROR);
     65}
    5566
    5667my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    6374    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6475        run(command => $command, verbose => 1);
    65     die "Unable to perform dettool -residimfile: $error_code\n" if not $success;
    66     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    67         or die "unable to parse metadata config doc";
    68     $files = parse_md_list($metadata);
     76    unless ($success) {
     77        $error_code >> 8;
     78        warn("Unable to perform dettool -residimfile: $error_code\n");
     79        exit($error_code);
     80    }
     81
     82    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     83        &my_die("Unable to parse metadata config doc", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
     84    $files = parse_md_list($metadata) or
     85        &my_die("Unable to parse metadata list", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR);
    6986}
    7087
     
    107124    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    108125        run(command => $command, verbose => 1);
    109     die "Unable to find expected output file: $jpeg1Name\n" if not -f $jpeg1Name;
     126    unless ($success) {
     127        $error_code >> 8;
     128        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
     129    }
     130    &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg1Name;
    110131}
    111132
     
    115136    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    116137        run(command => $command, verbose => 1);
    117     die "Unable to find expected output file: $jpeg2Name\n" if not -f $jpeg2Name;
     138    unless ($success) {
     139        $error_code >> 8;
     140        &my_die("Unable to run ppImage: $error_code", $det_id, $iter, $exp_tag, $error_code);
     141    }
     142    &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg2Name;
    118143}
    119144
     
    131156# Reject based on the stats of the imfiles
    132157# it is VALID to reject on more than one criterion
    133 die "Number of means and number of variances differ!\n" if scalar @means != scalar @variances;
     158&my_die("Number of means and number of variances differ!", $det_id, $iter, $exp_tag, $PS_EXIT_PROG_ERROR) unless scalar @means == scalar @variances;
    134159for (my $i = 0; $i < scalar @means; $i++) {
    135160    my $mean = $means[$i];      # Mean for this imfile
     
    248273    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    249274        run(command => $command, verbose => 1);
    250     die "Unable to perform dettool -addresidexp: $error_code\n" if not $success;
     275    unless ($success) {
     276        $error_code >> 8;
     277        warn("Unable to perform dettool -addresidexp: $error_code\n");
     278        exit($error_code);
     279    }
    251280
    252281    unlink $list1Name;
     
    259288        or die "failed to execute sync: $!" ;
    260289    $? = $status;
     290}
     291
     292
     293sub my_die
     294{
     295    my $msg = shift; # Warning message on die
     296    my $det_id = shift;         # Detrend identifier
     297    my $iter = shift;           # Iteration
     298    my $exp_tag = shift; # Exposure tag
     299    my $exit_code = shift; # Exit code to add
     300
     301    warn($msg);
     302    if ($det_id and $iteration and $exp_tag) {
     303        my $command = "$dettool -addresidexp -det_id $det_id -iteration $iter -exp_tag $exp_tag -code $exit_code";
     304        $command .= " -dbname $dbname" if defined $dbname;
     305        system ($command);
     306    }
     307    exit $exit_code;
    261308}
    262309
Note: See TracChangeset for help on using the changeset viewer.