IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 20, 2010, 9:39:26 AM (16 years ago)
Author:
bills
Message:

changes to implment saving magic streaks file and verify outputs in nebulous and to add data_state to Background tables to support cleanup

File:
1 edited

Legend:

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

    r28137 r29493  
    1717use IPC::Cmd 0.36 qw( can_run run );
    1818use File::Temp qw( tempfile );
     19use File::Copy;
    1920use PS::IPP::Metadata::Config;
    2021use PS::IPP::Metadata::List qw( parse_md_list );
     
    4142
    4243# Parse the command-line arguments
    43 my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile);
     44my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile, $final_outroot);
    4445
    4546GetOptions(
     
    4950           'dbname=s'        => \$dbname,     # Database name
    5051           'baseroot=s'      => \$baseroot,   # Output root name
     52           'final-outroot=s' => \$final_outroot,   # location for final outputs
    5153           'save-temps'      => \$save_temps, # Save temporary files?
    5254           'verbose'         => \$verbose,    # Print stuff?
     
    8688
    8789my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     90
     91# list of VerifyStreaks input and output files to copy to nebulous
     92my @verify_outputs = qw(
     93clusterPos.txt
     94duplicate.png
     95mask.png
     96original.png
     97original.fits
     98residual.png
     99residual.fits
     100clusters.list
     101);
    88102
    89103### Get a list of inputs
     
    312326
    313327
    314 ### Input result into database
    315 {
    316     my $command = "$magictool -addresult";
    317     $command   .= " -magic_id $magic_id";
    318     $command   .= " -node $node";
    319     $command   .= " -path_base $outroot";
    320     $command   .= " -dbname $dbname" if defined $dbname;
    321 
    322     # Add the processed file to the database
    323     unless ($no_update) {
    324         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    325             run(command => $command, verbose => $verbose);
    326         unless ($success) {
    327             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    328             &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
    329         }
    330     } else {
    331         print "Skipping command: $command\n";
    332     }
    333 }
    334 
    335328if ($node eq "root") {
    336329    my $streaks_file = "$outroot.streaks";
     
    349342    }
    350343
    351     &run_verifystreaks($baseroot);
    352344
    353345    my $exp_id;                 # Exposure identifier
     
    366358    }
    367359
     360    &run_verifystreaks($baseroot, $exp_id);
     361
    368362    {
    369363        my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path); # Astrometry file
     
    383377    }
    384378
     379    my $output_streaks = $final_outroot . ".streaks";
     380    if ($output_streaks and ($output_streaks ne $streaks_file)) {
     381        copy_to_nebulous($ipprc, $streaks_file, $output_streaks, 1);
     382        foreach my $f (@verify_outputs) {
     383            my $src = "$baseroot.verify/${exp_id}_$f";
     384            my $dest = "$final_outroot.${f}";
     385            copy_to_nebulous($ipprc, $src, $dest, 1);
     386        }
     387    } else {
     388        $output_streaks = $streaks_file;
     389    }
     390
     391### Input result into database
     392# XXXX: if this succeeds but addmask fails the magicRun is in a goofy state XXXX
     393{
     394    my $command = "$magictool -addresult";
     395    $command   .= " -magic_id $magic_id";
     396    $command   .= " -node $node";
     397    $command   .= " -path_base $outroot";
     398    $command   .= " -dbname $dbname" if defined $dbname;
     399
     400    # Add the processed file to the database
     401    unless ($no_update) {
     402        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     403            run(command => $command, verbose => $verbose);
     404        unless ($success) {
     405            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     406            &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
     407        }
     408    } else {
     409        print "Skipping command: $command\n";
     410    }
     411}
     412
    385413
    386414    {
    387415        my $command = "$magictool -addmask";
    388416        $command   .= " -magic_id $magic_id";
    389         $command   .= " -uri $streaks_file";
     417        $command   .= " -uri $final_outroot";
    390418        $command   .= " -streaks $num_streaks";
    391419        $command   .= " -dbname $dbname" if defined $dbname;
     
    411439
    412440    my $baseroot = shift;
     441    my $exp_id = shift;
    413442
    414443    unless ($VerifyStreaks) {
     
    431460    my @files = <$baseroot.*.clusters>;
    432461
    433     unless (open ($FILE, ">$outdir/clusters.list")) {
    434         print "failed to create cluster file $outdir/clusters.list\n";
     462    my $clusters_list = "$outdir/${exp_id}_clusters.list";
     463    unless (open ($FILE, ">$clusters_list")) {
     464        print "failed to create cluster file $clusters_list\n";
    435465        return 1;
    436466    }
     
    441471    close ($FILE);
    442472    if ($status) {
    443         print "failed to create cluster file $outdir/clusters.list\n";
     473        print "failed to create cluster file $clusters_list\n";
    444474        return 1;
    445475    }
    446476
    447     my $command = "$VerifyStreaks --out $outdir --clusters $outdir/clusters.list $baseroot.root.streakMap";
     477    my $command = "$VerifyStreaks --out $outdir --clusters $clusters_list $baseroot.root.streakMap";
    448478
    449479    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    513543}
    514544
     545# Copy a file to nebulous and optionally replicate it
     546# We should consider making this an ipprc function. For now try it here so we can print
     547# the right error messages
     548sub copy_to_nebulous {
     549    my $ipprc = shift;
     550    my $src = shift;
     551    my $dest = shift;
     552    my $replicate = shift;
     553
     554    print "copying $src to $dest\n";
     555
     556    $ipprc->file_exists($src) or
     557        &my_die("expected output file does not exist: $src", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     558
     559    # copy the file to it's final destination - which is presumably in nebulous
     560    # we delete it so that all instances are deleted in case it has been replicated
     561    if ($ipprc->file_exists($dest)) {
     562        $ipprc->file_delete($dest) or
     563                &my_die("failed to delete existing file: $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     564    }
     565    my $dest_resolved = $ipprc->file_resolve($dest, 'create');
     566    &my_die("failed to resolve $dest", $PS_EXIT_UNKNOWN_ERROR) if !$dest_resolved;
     567
     568    copy ($src, $dest_resolved) or
     569        &my_die("failed to copy $src to $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     570
     571    if ($replicate and (file_scheme($dest) eq 'neb')) {
     572        my $neb = $ipprc->nebulous();
     573        $neb->setxattr($dest, 'user.copies', 2, 'create') or
     574            &my_die("failed to set user.copies for $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     575
     576        $neb->replicate($dest) or
     577            &my_die("failed to replicate $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     578    }
     579}
     580
    515581sub my_die
    516582{
Note: See TracChangeset for help on using the changeset viewer.