IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 24, 2009, 12:00:25 PM (17 years ago)
Author:
Paul Price
Message:

Adding handling for missed exceptions, similar to register_imfile.pl --- the idea is to have exceptions trigger the my_die functions so that errors are recorded in the database, and don't go on forever.

File:
1 edited

Legend:

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

    r20661 r22430  
    2727use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2828use Pod::Usage qw( pod2usage );
     29
     30# Look for programs we need
     31my $missing_tools;
     32my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
     33my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
     34my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     35my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     36my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
     37my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
     38if ($missing_tools) {
     39    warn("Can't find required tools.");
     40    exit($PS_EXIT_CONFIG_ERROR);
     41}
    2942
    3043my ( $exp_tag, $cam_id, $camera, $outroot, $recipe, $dbname, $reduction, $dvodb, $verbose, $no_update,
     
    5770    defined $camera;
    5871
     72# Unhandled exceptions should be passed on to my_die so they get pushed into the database
     73$SIG{__DIE__} = sub { die @_ if $^S;
     74                      my_die( $_[0], $cam_id, $PS_EXIT_UNKNOWN_ERROR ); };
     75
    5976$ipprc->define_camera($camera);
    6077
     
    84101my $recipe_addstar = $ipprc->reduction($reduction, 'ADDSTAR'); # Recipe to use
    85102&my_die("Unrecognised ADDSTAR recipe", $cam_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe1;
    86 
    87 # Look for programs we need
    88 my $missing_tools;
    89 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
    90 my $ppImage = can_run('ppImage') or (warn "Can't find ppImage" and $missing_tools = 1);
    91 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    92 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
    93 
    94 # test for addstar and psastro:
    95 my $psastro = can_run('psastro') or (warn "Can't find psastro" and $missing_tools = 1);
    96 my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
    97 
    98 if ($missing_tools) {
    99     warn("Can't find required tools.");
    100     exit($PS_EXIT_CONFIG_ERROR);
    101 }
    102103
    103104my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    272273
    273274        if ($do_stats) {
    274             my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
    275             &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
    276 
    277             # parse stats from metadata
    278             $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
    279             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    280                 run(command => $command, verbose => $verbose);
    281             unless ($success) {
    282                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    283                 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
    284             }
    285             foreach my $line (@$stdout_buf) {
    286                 $cmdflags .= " $line";
    287             }
    288             chomp $cmdflags;
     275            my $fpaStatsReal = $ipprc->file_resolve($fpaStats);
     276            &my_die("Couldn't find expected output file: $fpaStats", $cam_id, $PS_EXIT_SYS_ERROR) unless -f $fpaStatsReal;
     277
     278            # parse stats from metadata
     279            $command = "$ppStatsFromMetadata $fpaStatsReal - CAMERA_EXP_FPA";
     280            ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     281                run(command => $command, verbose => $verbose);
     282            unless ($success) {
     283                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     284                &my_die("Unable to perform ppStatsFromMetadata: $error_code", $cam_id, $error_code);
     285            }
     286            foreach my $line (@$stdout_buf) {
     287                $cmdflags .= " $line";
     288            }
     289            chomp $cmdflags;
    289290        }
    290291
     
    323324            $command .= " $realFile";
    324325
    325             my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
     326            my $mjd_addstar_start = DateTime->now->mjd;   # MJD of starting script
    326327
    327328            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    331332                &my_die("Unable to perform addstar: $error_code", $cam_id, $error_code);
    332333            }
    333             $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
     334            $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);   # MJD of starting script
    334335        }
    335336    }
Note: See TracChangeset for help on using the changeset viewer.