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

    r11297 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
    1624
     
    4250my $missing_tools;
    4351my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    44 die "Can't find required tools.\n" if $missing_tools;
     52if ($missing_tools) {
     53    warn("Can't find required tools.");
     54    exit($PS_EXIT_CONFIG_ERROR);
     55}
     56
    4557my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    4658
     
    5264    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    5365        run(command => $command, verbose => 1);
    54     die "Unable to perform dettool -residexp: $error_code\n" if not $success;
    55     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    56         or die "unable to parse metadata config doc";
    57     $exposures = parse_md_list($metadata);
     66    unless ($success) {
     67        $error_code >> 8;
     68        &my_die("Unable to perform dettool -residexp: $error_code", $det_id, $iter, $error_code);
     69    }
     70
     71    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     72        &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     73    $exposures = parse_md_list($metadata) or
     74        &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
    5875}
    5976
     
    6683my @include;                    # Array of include flags
    6784foreach my $exposure (@$exposures) {
    68     die "Unable to find exposure id.\n" if not defined $exposure->{exp_tag};
    69     die "Unable to find mean.\n" if not defined $exposure->{bg};
    70     die "Unable to find stdev.\n" if not defined $exposure->{bg_stdev};
    71     die "Unable to find mean stdev.\n" if not defined $exposure->{bg_mean_stdev};
    72     die "Unable to find accept.\n" if not defined $exposure->{accept};
    73     die "Unable to find include.\n" if not defined $exposure->{include};
     85    &my_die("Unable to find exposure id.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{exp_tag};
     86    &my_die("Unable to find mean.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg};
     87    &my_die("Unable to find stdev.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg_stdev};
     88    &my_die("Unable to find mean stdev.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{bg_mean_stdev};
     89    &my_die("Unable to find accept.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{accept};
     90    &my_die("Unable to find include.\n", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $exposure->{include};
    7491    push @expTags, $exposure->{exp_tag};
    7592    push @means, $exposure->{bg};
     
    170187        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    171188            run(command => $command, verbose => 1);
    172         die "Unable to perform dettool -updateresidexp: $error_code\n" if not $success;
     189        unless ($success) {
     190            $error_code >> 8;
     191            &my_die("Unable to perform dettool -updateresidexp: $error_code", $det_id, $iter, $error_code);
     192        }
    173193    }
    174194}
     
    205225    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    206226        run(command => $command, verbose => 1);
    207     die "Unable to perform dettool -adddetrunsummary: $error_code\n" if not $success;
     227    unless ($success) {
     228        $error_code >> 8;
     229        warn("Unable to perform dettool -adddetrunsummary: $error_code");
     230        exit($error_code);
     231    }
    208232}
    209233
     
    221245    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    222246        run(command => $command, verbose => 1);
    223     die "Unable to perform dettool -updatedetrun: $error_code\n" if not $success;
     247    unless ($success) {
     248        $error_code >> 8;
     249        warn("Unable to perform dettool -updatedetrun: $error_code");
     250        exit($error_code);
     251    }
    224252}
    225253
     
    231259}
    232260
    233 # Retrieve the requested rejection limit, dying if not extant
     261
     262sub my_die
     263{
     264    my $msg = shift; # Warning message on die
     265    my $det_id = shift;         # Detrend identifier
     266    my $iter = shift;           # Iteration
     267    my $exit_code = shift; # Exit code to add
     268
     269    warn($msg);
     270    if ($det_id and $iter) {
     271        my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter -code $exit_code";
     272        $command .= " -dbname $dbname" if defined $dbname;
     273        system ($command);
     274    }
     275    exit $exit_code;
     276}
     277
     278
     279
     280# Retrieve the requested rejection limit, dying unless extant
    234281sub rejection_limit
    235282{
     
    240287    my $value = $ipprc->rejection( $name, $det_type, $filter );
    241288    if (not defined $value) {
    242         $filter = "(no filter)" if not defined $filter;
     289        $filter = "(no filter)" unless defined $filter;
    243290        die "Unable to determine $name rejection limit for $det_type with $filter.\n";
    244291    }
Note: See TracChangeset for help on using the changeset viewer.