Changeset 29493 for trunk/ippScripts/scripts/magic_process.pl
- Timestamp:
- Oct 20, 2010, 9:39:26 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippScripts/scripts/magic_process.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippScripts/scripts/magic_process.pl
r28137 r29493 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 … … 312 326 313 327 314 ### Input result into database315 {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 database323 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 335 328 if ($node eq "root") { 336 329 my $streaks_file = "$outroot.streaks"; … … 349 342 } 350 343 351 &run_verifystreaks($baseroot);352 344 353 345 my $exp_id; # Exposure identifier … … 366 358 } 367 359 360 &run_verifystreaks($baseroot, $exp_id); 361 368 362 { 369 363 my $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path); # Astrometry file … … 383 377 } 384 378 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 385 413 386 414 { 387 415 my $command = "$magictool -addmask"; 388 416 $command .= " -magic_id $magic_id"; 389 $command .= " -uri $ streaks_file";417 $command .= " -uri $final_outroot"; 390 418 $command .= " -streaks $num_streaks"; 391 419 $command .= " -dbname $dbname" if defined $dbname; … … 411 439 412 440 my $baseroot = shift; 441 my $exp_id = shift; 413 442 414 443 unless ($VerifyStreaks) { … … 431 460 my @files = <$baseroot.*.clusters>; 432 461 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"; 435 465 return 1; 436 466 } … … 441 471 close ($FILE); 442 472 if ($status) { 443 print "failed to create cluster file $ outdir/clusters.list\n";473 print "failed to create cluster file $clusters_list\n"; 444 474 return 1; 445 475 } 446 476 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"; 448 478 449 479 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 513 543 } 514 544 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 548 sub 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 515 581 sub my_die 516 582 {
Note:
See TracChangeset
for help on using the changeset viewer.
