IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 8, 2011, 2:44:12 PM (15 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20110906
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110906

  • branches/eam_branches/ipp-20110906/ippScripts/scripts/videophot_process.pl

    r32125 r32630  
    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
     
    2522use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    2623use Pod::Usage qw( pod2usage );
     24use File::Temp qw( tempfile );
     25use File::Basename qw( basename );
    2726
    2827# Look for programs we need
    2928my $missing_tools;
    3029my $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);
    3230my $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);
    3332my $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);
    3434if ($missing_tools) {
    3535    warn("Can't find required tools.");
    3636    exit($PS_EXIT_CONFIG_ERROR);
    3737}
    38 my ($vp_id, $exp_id, $camera, $outroot, $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);
    3940
    4041GetOptions(
    4142    'vp_id=s'           => \$vp_id,
    42     'exp_id=s'          => \$exp_id,
    4343    'camera=s'          => \$camera,
    4444    'outroot=s'         => \$outroot,
     45    'dest_id=s'         => \$dest_id,
     46    'product=s'         => \$product,
     47    'ds_dbname=s'       => \$ds_dbname,
     48    'ds_dbhost=s'       => \$ds_dbhost,
    4549    'dbname|d=s'        => \$dbname,
    4650    'verbose'           => \$verbose,
     51    'save-temps'        => \$save_temps,
    4752    'no-update'         => \$no_update, # Don't update the database?
    4853    'no-op'             => \$no_op,     # Don't do any operations?
     
    5257pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    5358pod2usage(
    54     -msg => "Required options: --vp_id --exp_id --outroot --camera",
     59    -msg => "Required options: --vp_id --outroot --camera",
    5560    -exitval => 3,
    5661          ) unless defined $vp_id
    57             and defined $exp_id
    5862            and defined $camera
    5963            and defined $outroot;
    6064
     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
    6170
    6271$no_update = 1 if $no_op;
    63 
    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
     72$vptool .= " -dbname $dbname" if $dbname;
     73
     74my $ipprc = PS::IPP::Config->new($camera) or my_die( "Unable to set up", $vp_id, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    6575
    6676my $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;
    68 
    69 my $source_id = $ipprc->source_id($dbname, $PS_TABLE_ID_DIFF);
    70 
    71 # Get list of components for subtraction
     77if ($redirect) {
     78    $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $vp_id, $PS_EXIT_SYS_ERROR );
     79
     80    print "\n\n";
     81    print "Starting script $0 on $host at $date\n\n";
     82}
     83
     84# Get list of chips with pending video cells
    7285my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    7386my $files;
    7487{
    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;
    79     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    80         run(command => $command, verbose => $verbose);
    81     unless ($success) {
    82         $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);
    84     }
    85 
    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);
    90 }
     88    my $command = "$vptool -pendingimfile -vp_id $vp_id";
     89    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     90        run(command => $command, verbose => $verbose);
     91    unless ($success) {
     92        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     93        &my_die("Unable to perform vptool -pendingimfile: $error_code", $vp_id, $error_code);
     94    }
     95
     96    my $output = join "", @$stdout_buf;
     97    if ($output) {
     98        my $metadata = $mdcParser->parse($output) or
     99            &my_die("Unable to parse metadata config doc", $vp_id, $PS_EXIT_PROG_ERROR);
     100        $files = parse_md_list($metadata) or
     101        &my_die("Unable to parse metadata list", $vp_id, $PS_EXIT_PROG_ERROR);
     102    }
     103}
     104
    91105
    92106foreach my $file (@$files) {
     
    95109
    96110    my $resolved = $ipprc->file_resolve($uri);
    97     &my_die("Unable to resolve $uri", $vp_id, $class_id, 'nocell', $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
     111    &my_die("Unable to resolve $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless $resolved;
    98112
    99113    my $command = "$listvideocells --file $resolved";
     
    102116    unless ($success) {
    103117        $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);
     118        &my_die("Unable to perform $command: $error_code", $vp_id, $error_code);
    106119    }
    107120
    108121    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;
     122    &my_die("No video cells found in $uri", $vp_id, $PS_EXIT_UNKNOWN_ERROR) unless scalar @video_cells;
    111123
    112124    foreach my $cell_id (@video_cells) {
    113         my $command = "$psvideophot $outroot";
     125        my $path_base =  "$outroot.$class_id.$cell_id";
     126        my $output = $ipprc->filename("PSVIDEOPHOT.OUTPUT", $path_base);
     127        my $command = "$psvideophot $output";
    114128        $command .= " -file $uri";
     129        $command .= " -class_id $class_id";
    115130        $command .= " -cell_id $cell_id";
    116         $command .= " -dbname $dbname" if defined $dbname;
     131        my $vpstart = DateTime->now->mjd;
    117132        unless ($no_op) {
    118133            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    120135            unless ($success) {
    121136                $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);
     137                &my_die("Unable to perform psvideophot: $error_code", $vp_id, $error_code);
    123138            }
    124 
    125             # check_output($outputStats, 1);
    126139        } else {
    127140            print "Not executing: $command\n";
    128141        }
     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
    129157        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;
     158            my $command = "$vptool -addprocessedcell -vp_id $vp_id -class_id $class_id -cell_id $cell_id";
     159            $command .= " -path_base $path_base";
     160            $command .= " -hostname $host";
     161            $command .= " -dtime_photom " . ((DateTime->now->mjd - $vpstart) * 86400);
    134162
    135163            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    138166                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    139167                my $err_message = "Unable to perform vptool -addvpcell";
    140                 &my_die("$err_message: $error_code", $vp_id, $class_id, $cell_id, $error_code);
     168                &my_die("$err_message: $error_code", $vp_id, $error_code);
    141169            }
    142170        }
     171    }
     172}
     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}
     221
     222unless ($no_update) {
     223    my $command = "$vptool -updaterun -vp_id $vp_id -set_state full";
     224    $command .= " -set_outroot $outroot";
     225    $command .= " -set_hostname $host";
     226    $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     227
     228    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     229        run(command => $command, verbose => $verbose);
     230    unless ($success) {
     231        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     232        my $err_message = "Unable to perform vptool -updaterun";
     233        &my_die("$err_message: $error_code", $vp_id, $error_code);
    143234    }
    144235}
     
    149240{
    150241    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
     242    my $vp_id = shift;          # vpRun id
    154243    my $exit_code = shift;      # Exit code to add
    155244
     
    157246
    158247    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;
     248    if (defined $vp_id and not $no_update) {
     249        my $command = "$vptool -vp_id $vp_id";
     250        $command .= " -updaterun";
     251        $command .= " -set_fault $exit_code";
     252        $command .= " -set_hostname $host" if defined $host;
     253        $command .= " -set_outroot $outroot" if defined $outroot;
     254        $command .= " -set_dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400);
     255
    166256        run(command => $command, verbose => $verbose);
    167257    }
     
    169259}
    170260
    171 END {
    172     my $exit = $?;
    173     system("sync") == 0 or die "failed to execute sync: $!";
    174     $? = $exit;
    175 }
    176 
    177261__END__
Note: See TracChangeset for help on using the changeset viewer.