IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 9502


Ignore:
Timestamp:
Oct 11, 2006, 5:01:10 PM (20 years ago)
Author:
jhoblitt
Message:

add run() caching

File:
1 edited

Legend:

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

    r9446 r9502  
    44use strict;
    55
     6use Cache::File;
     7use Storable qw( freeze thaw );
     8use File::Basename qw( basename );
    69use IPC::Cmd qw( can_run run );
    710use PS::IPP::Metadata::Config;
    811use PS::IPP::Metadata::List qw( parse_md_list );
    912use Statistics::Descriptive;
    10 use Data::Dumper;
    1113
    1214use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    1315use Pod::Usage qw( pod2usage );
    1416
    15 my ($exptag, $no_update);
     17my ($cache, $exptag, $no_update);
    1618
    1719GetOptions(
    18     'exp_tag|e=s'    => \$exptag,
     20    'caches'        => \$cache,
     21    'exp_tag|e=s'   => \$exptag,
    1922    'no-update'     => \$no_update
    2023) or pod2usage( 2 );
     
    7073die "Can't find required tools.\n" if $missing_tools;
    7174
     75# setup cache interface
     76
     77my $c = Cache::File->new(
     78    cache_root => File::Spec->catdir($ENV{'HOME'}, '.', basename($0)),
     79    default_expires => '7200 sec',
     80);
     81
    7282my $mdcParser = PS::IPP::Metadata::Config->new;        # Parser for metadata config files
    7383
     
    7787    my $command = "$p0tool -rawimfile -exp_tag $exptag";
    7888    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    79         run(command => $command, verbose => 1);
     89        cache_run(command => $command, verbose => 1);
    8090    die "Unable to perform p0tool on exposure id $exptag: $error_code\n" if not $success;
    8191    my $metadata = $mdcParser->parse(join "", @$stdout_buf)
     
    159169 
    160170    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    161         run(command => \@command, verbose => 1);
     171        cache_run(command => \@command, verbose => 1);
    162172    die "Unable to run phase0 update for $exptag: $error_code\n" if not $success;
    163173}
     
    176186}
    177187
    178 END { system("sync") == 0 or die "failed to execute sync: $!" }
     188sub cache_run
     189{
     190    my %p = @_;
     191
     192    my $cmd_output = $c->get($p{command}) if $cache;
     193    if (defined $cmd_output) {
     194        return @{thaw $cmd_output};
     195    } else {
     196        my @output = run(%p);
     197        $c->set($p{command}, freeze \@output) if $cache;
     198        return @output;
     199    }
     200}
     201
     202END {
     203    my $exit = $?;
     204    system("sync") == 0 or die "failed to execute sync: $!";
     205    $? = $exit;
     206}
     207
Note: See TracChangeset for help on using the changeset viewer.