IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 21, 2010, 2:45:13 PM (16 years ago)
Author:
eugene
Message:

merge changes from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100823/ippScripts/scripts/magic_process.pl

    r28137 r29515  
    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
     
    311325}
    312326
    313 
    314327### Input result into database
    315328{
     
    334347
    335348if ($node eq "root") {
     349    # XXXX: Since we just added the result above, all of these my_dies are going to fail
     350    # with a duplicate row error.
     351    # see more comments below
    336352    my $streaks_file = "$outroot.streaks";
    337353    my $resolved = $ipprc->file_resolve($streaks_file);
     
    349365    }
    350366
    351     &run_verifystreaks($baseroot);
    352367
    353368    my $exp_id;                 # Exposure identifier
     
    366381    }
    367382
     383    &run_verifystreaks($baseroot, $exp_id);
     384
    368385    {
    369386        my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path); # Astrometry file
     
    383400    }
    384401
     402    my $output_streaks = $final_outroot . ".streaks";
     403    if ($output_streaks and ($output_streaks ne $streaks_file)) {
     404        copy_to_nebulous($ipprc, $streaks_file, $output_streaks, 1);
     405        foreach my $f (@verify_outputs) {
     406            my $src = "$baseroot.verify/${exp_id}_$f";
     407            my $dest = "$final_outroot.${f}";
     408            copy_to_nebulous($ipprc, $src, $dest, 1);
     409        }
     410    } else {
     411        $output_streaks = $streaks_file;
     412    }
    385413
    386414    {
    387415        my $command = "$magictool -addmask";
    388416        $command   .= " -magic_id $magic_id";
    389         $command   .= " -uri $streaks_file";
     417        $command   .= " -path_base $final_outroot";
    390418        $command   .= " -streaks $num_streaks";
    391419        $command   .= " -dbname $dbname" if defined $dbname;
     
    397425            unless ($success) {
    398426                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    399                 # This isn't going to work because our result was already entered.
     427                # XXX: This my_die isn't going to work because the result for the root node was already
     428                # added to the database up above.
     429                # There is a magicMask has a fault column. Maybe we should
     430                # use that and add a new revert mode that deletes the magicMask and the magicNodeResult
     431                # for the root node.
    400432                &my_die("Unable to perform magictool -addmask: $error_code", $magic_id, $node, $error_code);
    401433            }
     
    406438}
    407439
     440
    408441### Pau.
    409442
     
    411444
    412445    my $baseroot = shift;
     446    my $exp_id = shift;
    413447
    414448    unless ($VerifyStreaks) {
     
    431465    my @files = <$baseroot.*.clusters>;
    432466
    433     unless (open ($FILE, ">$outdir/clusters.list")) {
    434         print "failed to create cluster file $outdir/clusters.list\n";
     467    my $clusters_list = "$outdir/${exp_id}_clusters.list";
     468    unless (open ($FILE, ">$clusters_list")) {
     469        print "failed to create cluster file $clusters_list\n";
    435470        return 1;
    436471    }
     
    441476    close ($FILE);
    442477    if ($status) {
    443         print "failed to create cluster file $outdir/clusters.list\n";
     478        print "failed to create cluster file $clusters_list\n";
    444479        return 1;
    445480    }
    446481
    447     my $command = "$VerifyStreaks --out $outdir --clusters $outdir/clusters.list $baseroot.root.streakMap";
     482    my $command = "$VerifyStreaks --out $outdir --clusters $clusters_list $baseroot.root.streakMap";
    448483
    449484    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    513548}
    514549
     550# Copy a file to nebulous and optionally replicate it
     551# We should consider making this an ipprc function. For now try it here so we can print
     552# the right error messages
     553sub copy_to_nebulous {
     554    my $ipprc = shift;
     555    my $src = shift;
     556    my $dest = shift;
     557    my $replicate = shift;
     558
     559    print "copying $src to $dest\n";
     560
     561    $ipprc->file_exists($src) or
     562        &my_die("expected output file does not exist: $src", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     563
     564    # copy the file to it's final destination - which is presumably in nebulous
     565    # we delete it so that all instances are deleted in case it has been replicated
     566    if ($ipprc->file_exists($dest)) {
     567        $ipprc->file_delete($dest) or
     568                &my_die("failed to delete existing file: $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     569    }
     570    my $dest_resolved = $ipprc->file_resolve($dest, 'create');
     571    &my_die("failed to resolve $dest", $PS_EXIT_UNKNOWN_ERROR) if !$dest_resolved;
     572
     573    copy ($src, $dest_resolved) or
     574        &my_die("failed to copy $src to $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     575
     576    if ($replicate and (file_scheme($dest) eq 'neb')) {
     577        my $neb = $ipprc->nebulous();
     578        $neb->setxattr($dest, 'user.copies', 2, 'create') or
     579            &my_die("failed to set user.copies for $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     580
     581        $neb->replicate($dest) or
     582            &my_die("failed to replicate $dest", $magic_id, $node, $PS_EXIT_UNKNOWN_ERROR);
     583    }
     584}
     585
    515586sub my_die
    516587{
Note: See TracChangeset for help on using the changeset viewer.