IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 11316


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.

Location:
trunk/ippScripts/scripts
Files:
11 edited

Legend:

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

    r11298 r11316  
    88use Data::Dumper;
    99
    10 use PS::IPP::Config;
     10use PS::IPP::Config qw(
     11    $PS_EXIT_SUCCESS
     12    $PS_EXIT_UNKNOWN_ERROR
     13    $PS_EXIT_SYS_ERROR
     14    $PS_EXIT_CONFIG_ERROR
     15    $PS_EXIT_PROG_ERROR
     16    $PS_EXIT_DATA_ERROR
     17    $PS_EXIT_TIMEOUT_ERROR
     18    );
    1119my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1220use 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;
     70
     71if ($missing_tools) {
     72    warn("Can't find required tools.");
     73    exit($PS_EXIT_CONFIG_ERROR);
     74}
    6375
    6476unless (defined $workdir) {
     
    8597    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8698        run(command => $command, verbose => 1);
    87     die "Unable to perform ppImage: $error_code\n" if not $success;
    88     die "Can't find expected output file: $output\n" if not -e $output;
    89     die "Can't find expected output file: $b1name\n" if not -e $b1name;
    90     die "Can't find expected output file: $b2name\n" if not -e $b2name;
    91     die "Can't find expected output file: $statsName\n" if not -e $statsName;
     99    unless ($success) {
     100        $error_code >> 8;
     101        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $class_id, $error_code);
     102    }
     103    &my_die("Can't find expected output file: $output", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $output;
     104    &my_die("Can't find expected output file: $b1name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b2name;
     105    &my_die("Can't find expected output file: $b2name", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $b1name;
     106    &my_die("Can't find expected output file: $statsName", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -e $statsName;
    92107}
    93108
     
    96111{
    97112    my $statsFile;              # File handle
    98     open $statsFile, $statsName or die "Can't open statistics file $statsName: $!\n";
     113    open $statsFile, $statsName or &my_die("Can't open statistics file $statsName: $!\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    99114    my @contents = <$statsFile>; # Contents of file
    100115    close $statsFile;
    101116    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    102117    my $metadata = $mdcParser->parse(join "", @contents)
    103         or die "unable to parse metadata config";
     118        or &my_die("Unable to parse metadata config", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    104119    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    105     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     120    $stats->parse($metadata) or &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    106121}
    107122
     
    127142    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128143        run(command => $command, verbose => 1);
    129     die "Unable to perform dettool -addnormalizedimfile: $error_code\n"
    130         if not $success;
     144    unless ($success) {
     145        $error_code >> 8;
     146        warn("Unable to perform dettool -addnormalizedimfile: $error_code\n");
     147        exit($error_code);
     148    }
    131149
    132150    unlink $statsName;
    133151}
     152
     153sub my_die
     154{
     155    my $msg = shift;            # Warning message on die
     156    my $det_id = shift;         # Detrend identifier
     157    my $iter = shift;           # Iteration
     158    my $class_id = shift;       # Class identifier
     159    my $exit_code = shift;      # Exit code to add
     160
     161    warn($msg);
     162    if ($det_id and $iter and $class_id) {
     163        my $command = "$dettool -addnormalizedimfile -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code";
     164        $command .= " -dbname $dbname" if defined $dbname;
     165        system ($command);
     166    }
     167    exit $exit_code;
     168}
     169
    134170
    135171END {
     
    139175    $? = $status;
    140176}
     177
     178__END__
  • trunk/ippScripts/scripts/detrend_norm_calc.pl

    r11298 r11316  
    99use PS::IPP::Metadata::List qw( parse_md_list );
    1010use Data::Dumper;
     11
     12use PS::IPP::Config qw(
     13    $PS_EXIT_SUCCESS
     14    $PS_EXIT_UNKNOWN_ERROR
     15    $PS_EXIT_SYS_ERROR
     16    $PS_EXIT_CONFIG_ERROR
     17    $PS_EXIT_PROG_ERROR
     18    $PS_EXIT_DATA_ERROR
     19    $PS_EXIT_TIMEOUT_ERROR
     20    );
    1121
    1222use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    5464my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    5565my $ppNormCalc = can_run('ppNormCalc') or (warn "Can't find ppNormCalc" and $missing_tools = 1);
    56 die "Can't find required tools.\n" if $missing_tools;
    57 
    58 die "Unrecognised detrend type: $detType\n" unless exists NORMALIZE()->{lc($detType)};
    59 
     66if ($missing_tools) {
     67    warn("Can't find required tools.");
     68    exit($PS_EXIT_CONFIG_ERROR);
     69}
     70
     71unless (exists NORMALIZE()->{lc($detType)}) {
     72    warn("Unrecognised detrend type: $detType");
     73    exit($PS_EXIT_CONFIG_ERROR);
     74}
    6075
    6176my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    6984    my ( $stdin, $stdout, $stderr ); # Buffers for running program
    7085    print "Running [$command]...\n";
    71     run \@command, \$stdin, \$stdout, \$stderr or
    72         die "Unable to perform dettool -processedimfile on detrend $detId/$iter: $?";
     86    if (not run(\@command, \$stdin, \$stdout, \$stderr)) {
     87        warn("Unable to perform dettool -processedimfile on detrend $detId/$iter: $?");
     88        exit($PS_EXIT_SYS_ERROR);
     89    }
    7390#    print $stdout . "\n";
    7491   
     
    8299            push @single, "\n";
    83100
    84             my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) ) or
    85                 die "Unable to parse output from dettool.\n";
     101            my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     102            unless (defined $list) {
     103                warn("Unable to parse output from dettool.");
     104                exit($PS_EXIT_PROG_ERROR);
     105            }
    86106            push @files, @$list;
    87107            @single = ();
     
    119139        my @command = split /\s+/, $ppNormCalc;
    120140        print "Running [$ppNormCalc]...\n";
    121         run \@command, \$normData, \$stdout, \$stderr or
    122             die "Unable to perform ppNormCalc: $?";
     141        if (not run(\@command, \$normData, \$stdout, \$stderr)) {
     142            warn("Unable to perform ppNormCalc: $?");
     143            exit($PS_EXIT_SYS_ERROR);
     144        }
    123145        print $stdout . "\n";
    124146       
    125147        # Parse the output
    126         $norms = $mdcParser->parse($stdout)
    127             or die "unable to parse metadata config doc";
     148        $norms = $mdcParser->parse($stdout);
     149        unless ($norms) {
     150            warn("Unable to parse metadata config doc");
     151            exit($PS_EXIT_PROG_ERROR);
     152        }
    128153    }
    129154
     
    158183        my ( $stdin, $stdout, $stderr ); # Buffers for running program
    159184        print "Running [$command]...\n";
    160         run \@command, \$stdin, \$stdout, \$stderr or
    161             die "Unable to perform dettool -addnormstat for $className: $?";
     185        if (not run \@command, \$stdin, \$stdout, \$stderr) {
     186            warn("Unable to perform dettool -addnormstat for $className: $?");
     187            exit($PS_EXIT_SYS_ERROR);
     188        }
    162189        print $stdout . "\n";
    163190    }
     
    170197    $? = $status;
    171198}
     199
     200__END__
  • trunk/ippScripts/scripts/detrend_norm_exp.pl

    r11298 r11316  
    88
    99use IPC::Cmd qw( can_run run );
    10 use PS::IPP::Metadata::Config;
     10use PS::IPP::Metadata::Config qw(
     11    $PS_EXIT_SUCCESS
     12    $PS_EXIT_UNKNOWN_ERROR
     13    $PS_EXIT_SYS_ERROR
     14    $PS_EXIT_CONFIG_ERROR
     15    $PS_EXIT_PROG_ERROR
     16    $PS_EXIT_DATA_ERROR
     17    $PS_EXIT_TIMEOUT_ERROR
     18    );
    1119use PS::IPP::Metadata::List qw( parse_md_list );
    1220use Statistics::Descriptive;
     
    4957my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    5058my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    51 die "Can't find required tools.\n" if $missing_tools;
     59if ($missing_tools) {
     60    warn("Can't find required tools.");
     61    exit($PS_EXIT_CONFIG_ERROR);
     62}
    5263
    5364my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    6071    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    6172        run(command => $command, verbose => 1);
    62     die "Unable to perform dettool -normalizedimfile: $error_code\n" if not $success;
    63     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    64         or die "unable to parse metadata config doc";
    65     $files = parse_md_list($metadata);
     73    unless ($success) {
     74        $error_code >> 8;
     75        &my_die("Unable to perform ppImage: $error_code", $det_id, $iter, $error_code);
     76    }
     77    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     78        &my_die("Unable to parse metadata config doc", $det_id, $iter, $PS_EXIT_PROG_ERROR);
     79    $files = parse_md_list($metadata) or
     80        &my_die("Unable to parse metadata list", $det_id, $iter, $PS_EXIT_PROG_ERROR);
    6681}
    6782
     
    7287    my @variances;    # Array of variances for each component
    7388    foreach my $file (@$files) {
    74         die "Unable to find class id\n" unless defined $file->{class_id};
     89        &my_die("Unable to find class id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id};
    7590        my $class_id = $file->{class_id};
    76         die "Unable to find bg for class_id=$class_id\n" unless defined $file->{bg};
    77         die "Unable to find bg_mean_stdev for class_id=$class_id\n" unless defined $file->{bg_mean_stdev};
     91        &my_die("Unable to find bg for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
     92        &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
    7893        push @backgrounds, $file->{bg};
    7994        push @variances, $file->{bg_stdev}**2;
     
    127142    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    128143        run(command => $command, verbose => 1);
    129     die "Unable to find expected output file: $jpeg1Name\n" if not -f $jpeg1Name;
     144    &my_die("Unable to find expected output file: $jpeg1Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg1Name;
    130145}
    131146
     
    135150    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    136151        run(command => $command, verbose => 1);
    137     die "Unable to find expected output file: $jpeg2Name\n" if not -f $jpeg2Name;
     152    &my_die("Unable to find expected output file: $jpeg2Name", $det_id, $iter, $PS_EXIT_SYS_ERROR) unless -f $jpeg2Name;
    138153}
    139154
     
    148163    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    149164        run(command => $command, verbose => 1);
    150     die "Unable to perform dettool -addnormalizedexp: $error_code\n" if not $success;
     165    unless ($success) {
     166        $error_code >> 8;
     167        &my_die("Unable to perform dettool -addnormalizedexp: $error_code", $det_id, $iter, $error_code);
     168    }
    151169
    152170    unlink $list1Name;
    153171    unlink $list2Name;
     172}
     173
     174
     175sub my_die
     176{
     177    my $msg = shift; # Warning message on die
     178    my $det_id = shift;         # Detrend identifier
     179    my $iter = shift;           # Iteration
     180    my $exit_code = shift; # Exit code to add
     181
     182    warn($msg);
     183    if ($det_id and $iter) {
     184        my $command = "$dettool -addprocessedimfile -det_id $det_id -iter $iter -code $exit_code";
     185        $command .= " -dbname $dbname" if defined $dbname;
     186        system ($command);
     187    }
     188    exit $exit_code;
    154189}
    155190
  • 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
  • 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
  • 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    }
  • 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
  • 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
  • trunk/ippScripts/scripts/detrend_stack.pl

    r11298 r11316  
    1212use PS::IPP::Metadata::Stats;
    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;
     
    5260    };
    5361
    54 my $recipe = RECIPES()->{lc($det_type)}; # Recipe to use in stacking
    55 die "Unrecognised detrend type: $det_type\n" if not defined $recipe;
    56 
    5762# Look for programs we need
    5863my $missing_tools;
    5964my $dettool = can_run('dettool') or (warn "Can't find dettool" and $missing_tools = 1);
    6065my $ppMerge = can_run('ppMerge') or (warn "Can't find ppMerge" and $missing_tools = 1);
    61 die "Can't find required tools.\n" if $missing_tools;
     66if ($missing_tools) {
     67    warn("Can't find required tools.");
     68    exit($PS_EXIT_CONFIG_ERROR);
     69}
     70
     71my $recipe = RECIPES()->{lc($det_type)}; # Recipe to use in stacking
     72&my_die("Unrecognised detrend type: $det_type", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR) unless defined $recipe;
    6273
    6374my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    7081    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    7182        run(command => $command, verbose => 1);
    72     die "Unable to perform dettool -processedimfile: $error_code\n" if not $success;
    73     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    74         or die "unable to parse metadata config doc";
    75     $files = parse_md_list($metadata);
     83    unless ($success) {
     84        $error_code >> 8;
     85        &my_die("Unable to perform dettool -processedimfile: $error_code", $det_id, $iter, $class_id, $error_code);
     86    }
     87    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     88        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
     89    $files = parse_md_list($metadata) or
     90        &my_die("Unable to parse metadata list", $det_id, $iter, $class_id, $PS_EXIT_PROG_ERROR);
    7691}
    7792
     
    101116    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    102117        run(command => $command, verbose => 1);
    103     die "Unable to perform ppMerge: $error_code\n" if not $success;
    104     die "Unable to find expected output file: $outputStack\n" if not -f $outputStack;
    105     die "Unable to find expected output file: $outputStats\n" if not -f $outputStats;
     118    unless ($success) {
     119        $error_code >> 8;
     120        &my_die("Unable to perform ppMerge: $error_code", $det_id, $iter, $class_id, $error_code);
     121    }
     122    &my_die("Unable to find expected output file: $outputStack\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStack;
     123    &my_die("Unable to find expected output file: $outputStats\n", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    106124}
    107125
     
    109127my $stats;                      # Statistics from ppImage
    110128{
    111     open(my $statsFile, "$outputStats")
    112         or die "Can't open statistics file $outputStats: $!\n";
     129    open(my $statsFile, "$outputStats") or
     130        &my_die("Can't open statistics file $outputStats: $!", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    113131    my $contents = do { local $/; <$statsFile> }; # Contents of file
    114132    close($statsFile);
    115133
    116134    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    117     my $metadata = $mdcParser->parse($contents)
    118         or die "unable to parse metadata config doc";
     135    my $metadata = $mdcParser->parse($contents) or
     136        &my_die("Unable to parse metadata config doc", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    119137    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    120     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     138    $stats->parse($metadata)  or
     139        &my_die("Unable to find all values in statistics output.", $det_id, $iter, $class_id, $PS_EXIT_SYS_ERROR);
    121140}
    122141
     
    137156    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    138157        run(command => $command, verbose => 1);
    139     die "Unable to perform dettool -addstacked: $error_code\n" if not $success;
     158    unless ($success) {
     159        $error_code >> 8;
     160        warn("Unable to perform dettool -addstacked: $error_code\n");
     161        exit($error_code);
     162    }
    140163
    141164    unlink $outputStats;
     165}
     166
     167
     168sub my_die
     169{
     170    my $msg = shift; # Warning message on die
     171    my $det_id = shift;         # Detrend identifier
     172    my $iter = shift;           # Iteration
     173    my $class_id = shift; # Class identifier
     174    my $exit_code = shift; # Exit code to add
     175
     176    warn($msg);
     177    if ($det_id and $iter and $class_id) {
     178        my $command = "$dettool -addstacked -det_id $det_id -iteration $iter -class_id $class_id -code $exit_code";
     179        $command .= " -dbname $dbname" if defined $dbname;
     180        system ($command);
     181    }
     182    exit $exit_code;
    142183}
    143184
  • trunk/ippScripts/scripts/phase2.pl

    r11298 r11316  
    88use PS::IPP::Metadata::Stats;
    99use Data::Dumper;
    10 use PS::IPP::Config;
     10use PS::IPP::Config qw(
     11    $PS_EXIT_SUCCESS
     12    $PS_EXIT_UNKNOWN_ERROR
     13    $PS_EXIT_SYS_ERROR
     14    $PS_EXIT_CONFIG_ERROR
     15    $PS_EXIT_PROG_ERROR
     16    $PS_EXIT_DATA_ERROR
     17    $PS_EXIT_TIMEOUT_ERROR
     18    );
    1119my $ipprc = PS::IPP::Config->new(); # IPP configuration
    1220use File::Spec;
     
    5159my $p2tool = can_run('p2tool') or (warn "Can't find p2tool" and $missing_tools = 1);
    5260my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    53 die "Can't find required tools.\n" if $missing_tools;
     61if ($missing_tools) {
     62    warn("Can't find required tools.");
     63    exit($PS_EXIT_CONFIG_ERROR);
     64}
    5465
    5566unless (defined $workdir) {
     
    7990    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8091        run(command => $command, verbose => 1);
    81     die "Unable to perform ppImage on $input: $error_code\n" if not $success;
    82     die "Couldn't find expected output file: $outputImage\n" if not -f $outputImage;
    83     die "Couldn't find expected output file: $outputBin1\n" if not -f $outputBin1;
    84     die "Couldn't find expected output file: $outputBin2\n" if not -f $outputBin2;
    85     die "Couldn't find expected output file: $outputStats\n" if not -f $outputStats;
     92    unless ($success) {
     93        $error_code >> 8;
     94        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $class_id, $error_code);
     95    }
     96    &my_die("Couldn't find expected output file: $outputImage\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputImage;
     97    &my_die("Couldn't find expected output file: $outputBin1\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin1;
     98    &my_die("Couldn't find expected output file: $outputBin2\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputBin2;
     99    &my_die("Couldn't find expected output file: $outputStats\n", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStats;
    86100}
    87101
     
    90104{
    91105    my $statsFile;              # File handle
    92     open $statsFile, $outputStats or die "Can't open statistics file $outputStats: $!\n";
     106    open $statsFile, $outputStats or &my_die("Can't open statistics file $outputStats: $!", $exp_tag, $class_id, $PS_EXIT_SYS_ERROR);
    93107    my @contents = <$statsFile>; # Contents of file
    94108    close $statsFile;
    95109    my $mdcParser = PS::IPP::Metadata::Config->new;     # Parser for metadata config files
    96     my $metadata = $mdcParser->parse(join "", @contents)
    97             or die "unable to parse metadata config doc";
     110    my $metadata = $mdcParser->parse(join "", @contents) or
     111        &my_die("Unable to parse metadata config doc", $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    98112    $stats = PS::IPP::Metadata::Stats->new(); # Stats parser
    99     $stats->parse($metadata) or die "Unable to find all values in statistics output.\n";
     113    $stats->parse($metadata) or
     114        &my_die("Unable to find all values in statistics output.\n", $exp_tag, $class_id, $PS_EXIT_PROG_ERROR);
    100115}
    101116
     
    120135    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    121136        run(command => $command, verbose => 1);
    122     die "Unable to perform p2tool -addprocessedimfile for $expTag/$classId: $error_code\n"
    123         if not $success;
     137    unless ($success) {
     138        $error_code >> 8;
     139        warn("Unable to perform p2tool -addprocessedimfile: $error_code\n");
     140        exit($error_code);
     141    }
    124142
    125143    unlink $outputStats;
     144}
     145
     146
     147sub my_die
     148{
     149    my $msg = shift; # Warning message on die
     150    my $exp_tag = shift; # Exposure tag
     151    my $class_id = shift; # Class identifier
     152    my $exit_code = shift; # Exit code to add
     153
     154    warn($msg);
     155    if ($exp_tag and $class_id) {
     156        my $command = "$dettool -addprocessedimfile -exp_tag $exp_tag -class_id $class_id -code $exit_code";
     157        $command .= " -dbname $dbname" if defined $dbname;
     158        system ($command);
     159    }
     160    exit $exit_code;
    126161}
    127162
  • trunk/ippScripts/scripts/phase3.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;
     
    4553my $p3tool = can_run('p3tool') or (warn "Can't find p3tool" and $missing_tools = 1);
    4654my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    47 die "Can't find required tools.\n" if $missing_tools;
     55if ($missing_tools) {
     56    warn("Can't find required tools.");
     57    exit($PS_EXIT_CONFIG_ERROR);
     58}
    4859
    4960my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    5667    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    5768        run(command => $command, verbose => 1);
    58     die "Unable to perform p3tool -pendingimfile: $error_code\n" if not $success;
    59     my $metadata = $mdcParser->parse(join "", @$stdout_buf)
    60         or die "unable to parse metadata config doc";
    61     $files = parse_md_list($metadata);
     69    unless ($success) {
     70        $error_code >> 8;
     71        &my_die("Unable to perform p3tool: $error_code", $exp_tag, $error_code);
     72    }
     73    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     74        &my_die("Unable to parse metadata config doc", $exp_tag, $PS_EXIT_PROG_ERROR);
     75    $files = parse_md_list($metadata) or
     76        &my_die("Unable to parse metadata list", $exp_tag, $PS_EXIT_PROG_ERROR);
    6277}
    6378
     
    7489#    my @zp;                    # Array of photometric zero points
    7590    foreach my $file (@$files) {
    76         die "Unable to find class id\n" unless defined $file->{class_id};
     91        &my_die("Unable to find class id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{class_id};
    7792        my $class_id = $file->{class_id};
    78         die "Unable to find bg for class_id=$class_id\n" unless defined $file->{bg};
    79         die "Unable to find bg_mean_stdev for class_id=$class_id\n" unless defined $file->{bg_mean_stdev};
    80 #       die "Unable to find sigma_ra for class_id=$class_id\n" unless defined $file->{sigma_ra};
    81 #       die "Unable to find sigma_dec for class_id=$class_id\n" unless defined $file->{sigma_dec};
    82 #       die "Unable to find zp for class_id=$class_id\n" unless defined $file->{zp};
     93        &my_die("Unable to find bg for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg};
     94        &my_die("Unable to find bg_mean_stdev for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{bg_mean_stdev};
     95#       &my_die("Unable to find sigma_ra for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_ra};
     96#       &my_die("Unable to find sigma_dec for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{sigma_dec};
     97#       &my_die("Unable to find zp for class_id=$class_id", $exp_tag, $PS_EXIT_SYS_ERROR) unless defined $file->{zp};
    8398        push @backgrounds, $file->{bg};
    8499        push @variances, $file->{bg_stdev}**2;
     
    132147    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    133148        run(command => $command, verbose => 1);
    134     die "Unable to find expected output file: $jpeg1\n" if not -f $jpeg1;
     149    unless ($success) {
     150        $error_code >> 8;
     151        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $error_code);
     152    }
     153    &my_die("Unable to find expected output file: $jpeg1", $exp_tag, $PS_EXIT_PROG_ERROR) unless -f $jpeg1;
    135154}
    136155
     
    140159    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    141160        run(command => $command, verbose => 1);
    142     die "Unable to find expected output file: $jpeg2\n" if not -f $jpeg2;
     161    unless ($success) {
     162        $error_code >> 8;
     163        &my_die("Unable to perform ppImage: $error_code", $exp_tag, $error_code);
     164    }
     165    &my_die("Unable to find expected output file: $jpeg2", $exp_tag, $PS_EXIT_PROG_ERROR) unless -f $jpeg2;
    143166}
    144167
     
    156179    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    157180        run(command => $command, verbose => 1);
    158     die "Unable to perform p3tool -addprocessedexp: $error_code\n" if not $success;
     181    unless ($success) {
     182        $error_code >> 8;
     183        warn("Unable to perform dettool -addprocessedexp: $error_code\n");
     184        exit($error_code);
     185    }
    159186
    160187    unlink $list1Name;
    161188    unlink $list2Name;
    162189}
     190
     191
     192sub my_die
     193{
     194    my $msg = shift; # Warning message on die
     195    my $exp_tag = shift; # Exposure tag
     196    my $exit_code = shift; # Exit code to add
     197
     198    warn($msg);
     199    if ($exp_tag) {
     200        my $command = "$dettool -addprocessedexp -exp_tag $exp_tag -code $exit_code";
     201        $command .= " -dbname $dbname" if defined $dbname;
     202        system ($command);
     203    }
     204    exit $exit_code;
     205}
     206
    163207
    164208END {
Note: See TracChangeset for help on using the changeset viewer.