IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32507


Ignore:
Timestamp:
Oct 6, 2011, 3:17:52 PM (15 years ago)
Author:
bills
Message:

use vptool

File:
1 edited

Legend:

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

    r32125 r32507  
    88my $host = hostname();
    99my $date = `date`;
    10 print "\n\n";
    11 print "Starting script $0 on $host at $date\n\n";
    12 
    1310use DateTime;
    1411my $mjd_start = DateTime->now->mjd;   # MJD of starting script
     
    2926my $missing_tools;
    3027my $vptool = can_run('vptool') or (warn "Can't find vptool" and $missing_tools = 1);
    31 my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    3228my $psvideophot = can_run('psvideophot') or (warn "Can't find psvideophot" and $missing_tools = 1);
    3329my $listvideocells = can_run('listvideocells.pl') or (warn "Can't find listvideocells.pl" and $missing_tools = 1);
     
    3632    exit($PS_EXIT_CONFIG_ERROR);
    3733}
    38 my ($vp_id, $exp_id, $camera, $outroot, $dbname, $verbose, $no_update, $no_op, $redirect);
     34my ($vp_id, $exp_tag, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect);
     35
     36my $dbserver = "ipp049";
    3937
    4038GetOptions(
    4139    'vp_id=s'           => \$vp_id,
    42     'exp_id=s'          => \$exp_id,
    4340    'camera=s'          => \$camera,
    4441    'outroot=s'         => \$outroot,
     42    'dest_id=s'         => \$dest_id,
    4543    'dbname|d=s'        => \$dbname,
    4644    'verbose'           => \$verbose,
     
    5250pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5351pod2usage(
    54     -msg => "Required options: --vp_id --exp_id --outroot --camera",
     52    -msg => "Required options: --vp_id --outroot --camera",
    5553    -exitval => 3,
    5654          ) unless defined $vp_id
    57             and defined $exp_id
    5855            and defined $camera
    5956            and defined $outroot;
     
    6259$no_update = 1 if $no_op;
    6360
    64 my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, 'nochip', 'nocell', $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     61my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    6562
    6663my $logDest = $ipprc->filename("LOG.EXP", $outroot);
    67 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $vp_id, 'nochip', 'nocell', $PS_EXIT_SYS_ERROR ) if $redirect;
     64if ($redirect) {
     65    $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $vp_id, $PS_EXIT_SYS_ERROR );
    6866
    69 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
     67    print "\n\n";
     68    print "Starting script $0 on $host at $date\n\n";
     69}
    7070
    71 # Get list of components for subtraction
     71$vptool .= " -dbname $dbname" if $dbname;
     72$vptool .= " -dbserver $dbserver" if $dbserver;
     73
     74# Get list of chips with pending video cells
    7275my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    7376my $files;
    7477{
    75 #    my $command = "$vptool -pendingimfile -vp_id $vp_id";
    76 #    $command .= " -dbname $dbname" if defined $dbname;
    77     my $command = "$regtool -processedimfile -video_cells -exp_id $exp_id";
    78     $command .= " -dbname $dbname" if defined $dbname;
     78    my $command = "$vptool -pendingimfile -vp_id $vp_id";
    7979    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8080        run(command => $command, verbose => $verbose);
    8181    unless ($success) {
    8282        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    83         &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, 'nochip', 'nocell', $error_code);
     83        &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code);
    8484    }
    8585
    86     my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    87         &my_die("Unable to parse metadata config doc", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR);
    88     $files = parse_md_list($metadata) or
    89         &my_die("Unable to parse metadata list", $vp_id, 'nochip', 'nocell', $PS_EXIT_PROG_ERROR);
     86    my $output = join "", @$stdout_buf;
     87    if ($output) {
     88        my $metadata = $mdcParser->parse($output) or
     89            &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR);
     90        $files = parse_md_list($metadata) or
     91        &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR);
     92    }
    9093}
    9194
     
    9598
    9699    my $resolved = $ipprc->file_resolve($uri);
    97     &my_die("Unable to resolve $uri", $vp_id, $class_id, 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
     100    &my_die("Unable to resolve $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
    98101
    99102    my $command = "$listvideocells --file $resolved";
     
    102105    unless ($success) {
    103106        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    104         &my_die("Unable to perform $command: $error_code", $vp_id, $class_id,
    105             'nocell', $error_code);
     107        &my_die("Unable to perform $command: $error_code", $vp_id, $error_code);
    106108    }
    107109
    108110    my @video_cells = split "\n", (join "", @$stdout_buf);
    109     &my_die("No video cells found in $uri", $vp_id, $class_id,
    110             'nocell', $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells;
     111    &my_die("No video cells found in $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells;
    111112
    112113    foreach my $cell_id (@video_cells) {
    113         my $command = "$psvideophot $outroot";
     114        my $path_base =  "$outroot.$class_id.$cell_id";
     115        my $command = "$psvideophot $path_base";
    114116        $command .= " -file $uri";
    115117        $command .= " -cell_id $cell_id";
    116         $command .= " -dbname $dbname" if defined $dbname;
     118        my $vpstart = DateTime->now->mjd;
    117119        unless ($no_op) {
    118120            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    120122            unless ($success) {
    121123                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    122                 &my_die("Unable to perform ppSub: $error_code", $vp_id, $class_id, $cell_id, $error_code);
     124                &my_die("Unable to perform ppSub: $error_code", $vp_id, $error_code);
    123125            }
    124126
     
    128130        }
    129131        unless ($no_update) {
    130             my $command = "$vptool -addvpcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
    131             $command .= " -path_base $outroot";
    132 
    133             $command .= " -dbname $dbname" if defined $dbname;
     132            my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
     133            $command .= " -path_base $path_base";
     134            $command .= " -hostname $host";
     135            $command .= " -dtime_photom " . ((DateTime->now->mjd - $vpstart) * 86400);
    134136
    135137            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    138140                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    139141                my $err_message = "Unable to perform vptool -addvpcell";
    140                 &my_die("$err_message: $error_code", $vp_id, $class_id, $cell_id, $error_code);
     142                &my_die("$err_message: $error_code", $vp_id, $error_code);
    141143            }
    142144        }
     145    }
     146}
     147# TODO: if dest_id build results fileset and post it in the given destination on the data store
     148
     149unless ($no_update) {
     150    my $command = "$vptool -updaterun -vp_id $vp_id -set_state full";
     151    $command .= " -set_outroot $outroot";
     152    $command .= " -set_hostname $host";
     153    $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     154
     155    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     156        run(command => $command, verbose => $verbose);
     157    unless ($success) {
     158        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     159        my $err_message = "Unable to perform vptool -updaterun";
     160        &my_die("$err_message: $error_code", $vp_id, $error_code);
    143161    }
    144162}
     
    149167{
    150168    my $msg = shift;            # Warning message on die
    151     my $vp_id = shift;
    152     my $class_id = shift;       # chip identifier
    153     my $cell_id = shift;       # chip identifier
     169    my $vp_id = shift;          # vpRun id
    154170    my $exit_code = shift;      # Exit code to add
    155171
     
    157173
    158174    warn($msg);
    159     if (defined $vp_id and defined $class_id and not $no_update) {
    160         my $command = "$vptool -vp_id $vp_id -class_id $class_id -cell_id -fault $exit_code";
    161         $command .= " -addvpcell";
    162         $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400));
    163         $command .= " -hostname $host" if defined $host;
    164         $command .= " -path_base $outroot" if defined $outroot;
    165         $command .= " -dbname $dbname" if defined $dbname;
     175    if (defined $vp_id and not $no_update) {
     176        my $command = "$vptool -vp_id $vp_id";
     177        $command .= " -updaterun";
     178        $command .= " -set_fault $exit_code";
     179        $command .= " -set_hostname $host" if defined $host;
     180        $command .= " -set_outroot $outroot" if defined $outroot;
     181        $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     182
    166183        run(command => $command, verbose => $verbose);
    167184    }
     
    169186}
    170187
    171 END {
    172     my $exit = $?;
    173     system("sync") == 0 or die "failed to execute sync: $!";
    174     $? = $exit;
    175 }
    176 
    177188__END__
Note: See TracChangeset for help on using the changeset viewer.