IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32556 for trunk/ippScripts


Ignore:
Timestamp:
Oct 14, 2011, 4:41:16 PM (15 years ago)
Author:
bills
Message:

Post the results to the data store. Make programs work with outputs in nebulous

File:
1 edited

Legend:

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

    r32546 r32556  
    2222use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2323use Pod::Usage qw( pod2usage );
     24use File::Temp qw( tempfile );
     25use File::Basename qw( basename );
    2426
    2527# Look for programs we need
     
    2729my $vptool = can_run('vptool') or (warn "Can't find vptool" and $missing_tools = 1);
    2830my $psvideophot = can_run('psvideophot') or (warn "Can't find psvideophot" and $missing_tools = 1);
     31my $dumpvideo = can_run('dumpvideo') or (warn "Can't find dumpvideo" and $missing_tools = 1);
    2932my $listvideocells = can_run('listvideocells.pl') or (warn "Can't find listvideocells.pl" and $missing_tools = 1);
     33my $dsreg = can_run('dsreg') or (warn "Can't find dsreg" and $missing_tools = 1);
    3034if ($missing_tools) {
    3135    warn("Can't find required tools.");
    3236    exit($PS_EXIT_CONFIG_ERROR);
    3337}
    34 my ($vp_id, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect);
     38my ($vp_id, $camera, $outroot, $dest_id, $dbname, $verbose, $no_update, $no_op, $redirect, $save_temps);
     39my ($product, $ds_dbname, $ds_dbhost);
    3540
    3641GetOptions(
     
    3944    'outroot=s'         => \$outroot,
    4045    'dest_id=s'         => \$dest_id,
     46    'product=s'         => \$product,
     47    'ds_dbname=s'       => \$ds_dbname,
     48    'ds_dbhost=s'       => \$ds_dbhost,
    4149    'dbname|d=s'        => \$dbname,
    4250    'verbose'           => \$verbose,
     51    'save-temps'        => \$save_temps,
    4352    'no-update'         => \$no_update, # Don't update the database?
    4453    'no-op'             => \$no_op,     # Don't do any operations?
     
    5463            and defined $outroot;
    5564
     65pod2usage(
     66    -msg => " --product -ds_dbname and --dsdbhost are required if --dest_id",
     67    -exitval => 3,
     68          ) if ($dest_id and !( defined $product and defined $ds_dbname and defined $ds_dbhost));
     69
    5670
    5771$no_update = 1 if $no_op;
     72$vptool .= " -dbname $dbname" if $dbname;
    5873
    5974my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
     
    6681    print "Starting script $0 on $host at $date\n\n";
    6782}
    68 
    69 $vptool .= " -dbname $dbname" if $dbname;
    7083
    7184# Get list of chips with pending video cells
     
    90103}
    91104
     105
    92106foreach my $file (@$files) {
    93107    my $class_id = $file->{class_id};
     
    110124    foreach my $cell_id (@video_cells) {
    111125        my $path_base =  "$outroot.$class_id.$cell_id";
    112         my $command = "$psvideophot $path_base";
     126        my $output = $ipprc->filename("PSVIDEOPHOT.OUTPUT", $path_base);
     127        my $command = "$psvideophot $output";
    113128        $command .= " -file $uri";
     129        $command .= " -class_id $class_id";
    114130        $command .= " -cell_id $cell_id";
    115131        my $vpstart = DateTime->now->mjd;
     
    119135            unless ($success) {
    120136                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    121                 &my_die("Unable to perform ppSub: $error_code", $vp_id, $error_code);
     137                &my_die("Unable to perform psvideophot: $error_code", $vp_id, $error_code);
    122138            }
    123 
    124             # check_output($outputStats, 1);
    125139        } else {
    126140            print "Not executing: $command\n";
    127141        }
     142        # dump the video cell and the video table to a file
     143        unless ($no_op) {
     144            my $output = $path_base . ".fits";
     145            my $extname = "$cell_id";
     146            my $command = "$dumpvideo $uri $extname $output -includetable";
     147            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     148                run(command => $command, verbose => $verbose);
     149            unless ($success) {
     150                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     151                &my_die("Unable to perform dumpvideo: $error_code", $vp_id, $error_code);
     152            }
     153        } else {
     154            print "Not executing: $command\n";
     155        }
     156
    128157        unless ($no_update) {
    129158            my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
     
    142171    }
    143172}
    144 # TODO: if dest_id build results fileset and post it in the given destination on the data store
     173if ($dest_id) {
     174    my $command = "$vptool -processedcell -vp_id $vp_id";
     175    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     176        run(command => $command, verbose => $verbose);
     177    unless ($success) {
     178        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     179        &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code);
     180    }
     181
     182    my $output = join "", @$stdout_buf;
     183    my $cells;
     184    if ($output) {
     185        my $metadata = $mdcParser->parse($output) or
     186            &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR);
     187        $cells = parse_md_list($metadata) or
     188            &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR);
     189    }
     190    my ($reglist, $reglistName) = tempfile("/tmp/filelist.$vp_id.XXXX", UNLINK => !$save_temps);
     191
     192    if ($redirect) {
     193        print $reglist "$logDest|||text|\n";
     194    }
     195    my @exts = qw( vpt fits );
     196    my @types = qw( table fits );
     197    foreach my $cell (@$cells) {
     198        my $path_base = $cell->{path_base};
     199        for (my $i = 0; $i < scalar @exts; $i++) {
     200            my $file = "$path_base.$exts[$i]";
     201            my $type = $types[$i];
     202
     203            print $reglist "$file|||$type|\n";
     204        }
     205           
     206    }
     207    close $reglist or &my_die("failed to close $reglistName", $vp_id, $PS_EXIT_UNKNOWN_ERROR);
     208    unless ($no_update or $no_op) {
     209        my $fileset = basename($outroot);
     210        my $command = "$dsreg --add $fileset --product $product --type dump --list $reglistName";
     211        $command .= " --abspath --link";
     212        $command .= " --dbname $ds_dbname --dbhost $ds_dbhost";
     213        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     214            run(command => $command, verbose => $verbose);
     215        unless ($success) {
     216            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     217             &my_die("Unable to perform $command error_code: $error_code", $vp_id, $error_code);
     218        }
     219    }
     220}
    145221
    146222unless ($no_update) {
Note: See TracChangeset for help on using the changeset viewer.