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_exp.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;
     
    4755my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    4856my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    49 die "Can't find required tools.\n" if $missing_tools;
     57if ($missing_tools) {
     58    warn("Can't find required tools.");
     59    exit($PS_EXIT_CONFIG_ERROR);
     60}
    5061
    5162my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    5869    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    5970        run(command => $command, verbose => 1);
    60     die "Unable to perform dettool -processedimfile: $error_code\n" if not $success;
    61     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    62         or die "unable to parse metadata config doc";
    63     $files = parse_md_list($metadata);
     71    unless ($success) {
     72        $error_code >> 8;
     73        &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $exp_tag, $error_code);
     74    }
     75    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     76        &my_die("Unable to parse metadata config doc", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR);
     77    $files = parse_md_list($metadata) or
     78        &my_die("Unable to parse metadata list", $det_id, $exp_tag, $PS_EXIT_PROG_ERROR);
    6479}
    6580
     
    7085    my @variances;    # Array of variances for each component
    7186    foreach my $file (@$files) {
    72         die "Unable to find class id\n" unless defined $file->{class_id};
     87        &my_die("Unable to find class id", $det_id, $exp_tag, $PS_EXIT_SYS_ERRROR) unless defined $file->{class_id};
    7388        my $class_id = $file->{class_id};
    74         die "Unable to find bg for class_id=$class_id\n" unless defined $file->{bg};
    75         die "Unable to find bg_mean_stdev for class_id=$class_id\n" unless defined $file->{bg_mean_stdev};
     89        &my_die("Unable to find bg for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
     90        &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
    7691        push @backgrounds, $file->{bg};
    7792        push @variances, $file->{bg_stdev}**2;
     
    125140    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    126141        run(command => $command, verbose => 1);
    127     die "Unable to find expected output file: $jpeg1\n" if not -f $jpeg1;
     142    unless ($success) {
     143        $error_code >> 8;
     144        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
     145    }
     146    &my_die("Unable to find expected output file: $jpeg1", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg1;
    128147}
    129148
     
    133152    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    134153        run(command => $command, verbose => 1);
    135     die "Unable to find expected output file: $jpeg2\n" if not -f $jpeg2;
     154    unless ($success) {
     155        $error_code >> 8;
     156        &my_die("Unable to perform ppImage: $error_code", $det_id, $exp_tag, $error_code);
     157    }
     158    &my_die("Unable to find expected output file: $jpeg2", $det_id, $exp_tag, $PS_EXIT_SYS_ERROR) unless -f $jpeg2;
    136159}
    137160
     
    148171    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    149172        run(command => $command, verbose => 1);
    150     die "Unable to perform dettool -addprocessedexp: $error_code\n" if not $success;
     173    unless ($success) {
     174        $error_code >> 8;
     175        warn("Unable to perform dettool -addprocessedexp: $error_code");
     176        exit($error_code);
     177    }
    151178
    152179    unlink $list1Name;
    153180    unlink $list2Name;
     181}
     182
     183
     184sub my_die
     185{
     186    my $msg = shift; # Warning message on die
     187    my $det_id = shift;         # Detrend identifier
     188    my $exp_tag = shift; # Exposure tag
     189    my $exit_code = shift; # Exit code to add
     190
     191    warn($msg);
     192    if ($det_id && $exp_tag) {
     193        my $command = "$dettool -addprocessedexp -det_id $det_id -exp_tag $exp_tag -code $exit_code";
     194        $command .= " -dbname $dbname" if defined $dbname;
     195        system ($command);
     196    }
     197    exit $exit_code;
    154198}
    155199
Note: See TracChangeset for help on using the changeset viewer.