- Timestamp:
- Oct 21, 2010, 2:45:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/ippScripts/scripts/magic_process.pl
r28137 r29515 17 17 use IPC::Cmd 0.36 qw( can_run run ); 18 18 use File::Temp qw( tempfile ); 19 use File::Copy; 19 20 use PS::IPP::Metadata::Config; 20 21 use PS::IPP::Metadata::List qw( parse_md_list ); … … 41 42 42 43 # Parse the command-line arguments 43 my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile );44 my ($magic_id, $node, $camera, $dbname, $baseroot, $save_temps, $verbose, $no_update, $no_op, $logfile, $final_outroot); 44 45 45 46 GetOptions( … … 49 50 'dbname=s' => \$dbname, # Database name 50 51 'baseroot=s' => \$baseroot, # Output root name 52 'final-outroot=s' => \$final_outroot, # location for final outputs 51 53 'save-temps' => \$save_temps, # Save temporary files? 52 54 'verbose' => \$verbose, # Print stuff? … … 86 88 87 89 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 90 91 # list of VerifyStreaks input and output files to copy to nebulous 92 my @verify_outputs = qw( 93 clusterPos.txt 94 duplicate.png 95 mask.png 96 original.png 97 original.fits 98 residual.png 99 residual.fits 100 clusters.list 101 ); 88 102 89 103 ### Get a list of inputs … … 311 325 } 312 326 313 314 327 ### Input result into database 315 328 { … … 334 347 335 348 if ($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 336 352 my $streaks_file = "$outroot.streaks"; 337 353 my $resolved = $ipprc->file_resolve($streaks_file); … … 349 365 } 350 366 351 &run_verifystreaks($baseroot);352 367 353 368 my $exp_id; # Exposure identifier … … 366 381 } 367 382 383 &run_verifystreaks($baseroot, $exp_id); 384 368 385 { 369 386 my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path); # Astrometry file … … 383 400 } 384 401 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 } 385 413 386 414 { 387 415 my $command = "$magictool -addmask"; 388 416 $command .= " -magic_id $magic_id"; 389 $command .= " - uri $streaks_file";417 $command .= " -path_base $final_outroot"; 390 418 $command .= " -streaks $num_streaks"; 391 419 $command .= " -dbname $dbname" if defined $dbname; … … 397 425 unless ($success) { 398 426 $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. 400 432 &my_die("Unable to perform magictool -addmask: $error_code", $magic_id, $node, $error_code); 401 433 } … … 406 438 } 407 439 440 408 441 ### Pau. 409 442 … … 411 444 412 445 my $baseroot = shift; 446 my $exp_id = shift; 413 447 414 448 unless ($VerifyStreaks) { … … 431 465 my @files = <$baseroot.*.clusters>; 432 466 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"; 435 470 return 1; 436 471 } … … 441 476 close ($FILE); 442 477 if ($status) { 443 print "failed to create cluster file $ outdir/clusters.list\n";478 print "failed to create cluster file $clusters_list\n"; 444 479 return 1; 445 480 } 446 481 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"; 448 483 449 484 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 513 548 } 514 549 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 553 sub 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 515 586 sub my_die 516 587 {
Note:
See TracChangeset
for help on using the changeset viewer.
