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

    r11298 r11316  
    1111use PS::IPP::Metadata::Stats;
    1212
    13 use PS::IPP::Config;
     13use PS::IPP::Config qw(
     14    $PS_EXIT_SUCCESS
     15    $PS_EXIT_UNKNOWN_ERROR
     16    $PS_EXIT_SYS_ERROR
     17    $PS_EXIT_CONFIG_ERROR
     18    $PS_EXIT_PROG_ERROR
     19    $PS_EXIT_DATA_ERROR
     20    $PS_EXIT_TIMEOUT_ERROR
     21    );
    1422my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1523use File::Spec;
     
    6068my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    6169my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    62 die "Can't find required tools.\n" if $missing_tools;
     70if ($missing_tools) {
     71    warn("Can't find required tools.");
     72    exit($PS_EXIT_CONFIG_ERROR);
     73}
    6374
    6475# Recipe to use in processing
    6576my $recipe = RECIPES->{lc($det_type)};
    66 die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
     77unless (defined $recipe) {
     78    warn("Unrecognised detrend type: $det_type");
     79    exit($PS_EXIT_CONFIG_ERROR);
     80}
    6781
    6882### Output file name
     
    88102    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    89103        run(command => $command, verbose => 1);
    90     die "Unable to perform ppImage on $input_uri: $error_code\n" if not $success;
    91     die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
    92     die "Couldn't find expected output file: $outputStats\n" if not -f $outputStats;
    93     die "Couldn't find expected output file: $outputBin1\n" if not -f $outputBin1;
    94     die "Couldn't find expected output file: $outputBin2\n" if not -f $outputBin2;
     104    unless ($success) {
     105        $error_code >> 8;
     106        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $class_id, $error_code);
     107    }
     108    &my_die("Couldn't find expected output file: $outputImage", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
     109    &my_die("Couldn't find expected output file: $outputStats", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
     110    &my_die("Couldn't find expected output file: $outputBin1", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
     111    &my_die("Couldn't find expected output file: $outputBin2", $det_id, $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
    95112}
    96113
     
    104121    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    105122    my $metadata = $mdcParser->parse(join "", @contents)
    106         or die "unable to parse metadata config";
     123        or &my_die("Unable to parse metadata config", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    107124    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    108     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     125    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    109126}
    110127
     
    131148    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    132149        run(command => $command, verbose => 1);
    133     die "Unable to perform dettool -addprocessedimfile for $det_id/$exp_tag/$class_id: $error_code\n"
    134         if not $success;
     150    unless ($success) {
     151        $error_code >> 8;
     152        warn("Unable to perform dettool -addprocessedimfile: $error_code\n");
     153        exit($error_code);
     154    }
    135155
    136156    unlink $outputStats;
     157}
     158
     159sub my_die
     160{
     161    my $msg = shift; # Warning message on die
     162    my $det_id = shift;         # Detrend identifier
     163    my $exp_tag = shift; # Exposure tag
     164    my $class_id = shift; # Class identifier
     165    my $exit_code = shift; # Exit code to add
     166
     167    warn($msg);
     168    if ($det_id and $exp_tag and $class_id) {
     169        my $command = "$dettool -addprocessedimfile -det_id $det_id -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     170        $command .= " -dbname $dbname" if defined $dbname;
     171        system ($command);
     172    }
     173    exit $exit_code;
    137174}
    138175
Note: See TracChangeset for help on using the changeset viewer.