- Timestamp:
- Mar 5, 2012, 5:19:48 PM (14 years ago)
- Location:
- branches/meh_branches/ppstack_test
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/chip_imfile.pl (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/meh_branches/ppstack_test
- Property svn:mergeinfo changed
-
branches/meh_branches/ppstack_test/ippScripts/scripts/chip_imfile.pl
r31941 r33415 34 34 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 35 35 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1); 36 my $nebrepair = can_run('neb-repair') or (warn "Can't find neb-repair" and $missing_tools = 1); 37 36 38 if ($missing_tools) { 37 39 warn("Can't find required tools."); … … 44 46 my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose, 45 47 $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned ); 46 47 my $zaplog = 0;48 48 49 49 GetOptions( … … 65 65 'no-op' => \$no_op, # Don't do any operations? 66 66 'redirect-output' => \$redirect, 67 'zaplog' => \$zaplog,68 67 'save-temps' => \$save_temps, # Save temporary files? 69 68 ) or pod2usage( 2 ); … … 92 91 } 93 92 94 my ($log Dest, $traceDest);93 my ($logRule, $traceDest); 95 94 if ($run_state eq 'new') { 96 $log Dest = prepare_output("LOG.IMFILE", $outroot, $class_id, $zaplog);95 $logRule = "LOG.IMFILE"; 97 96 $traceDest = prepare_output("TRACE.IMFILE", $outroot, $class_id, 1); 98 97 } else { 99 $log Dest = prepare_output("LOG.IMFILE.UPDATE", $outroot, $class_id, 1);98 $logRule = "LOG.IMFILE.UPDATE"; 100 99 $traceDest = prepare_output("TRACE.IMFILE.UPDATE", $outroot, $class_id, 1); 101 100 } 102 101 103 102 if ($redirect) { 104 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR ); 103 my $logDest = $ipprc->filename($logRule, $outroot, $class_id); 104 105 $ipprc->redirect_to_logfile($logDest) or my_die( "Unable to redirect output", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR ); 106 105 107 print STDOUT "\n\n"; 106 108 print STDOUT "Starting script $0 on $host\n\n"; … … 145 147 my $outputBin2; 146 148 my $dump_config = 1; 149 my $do_stats = 1; 150 $outputStats = prepare_output("PPIMAGE.STATS", $outroot, $class_id, 1); 147 151 my $do_binned_images = 1; 148 152 if ($run_state eq 'new') { 149 153 # prepare the files that are only created for a new run 150 154 $configuration = prepare_output("PPIMAGE.CONFIG", $outroot, $class_id, 1); 151 $outputStats = prepare_output("PPIMAGE.STATS", $outroot, $class_id, 1);152 155 } else { 153 156 $configuration = $ipprc->filename('PPIMAGE.CONFIG', $outroot, $class_id) … … 194 197 unless ($no_op) { 195 198 my $command; 196 my $do_stats;197 199 198 200 ## get the ppImage recipe for this camera and CHIP reduction … … 266 268 } 267 269 268 ## Read camera config to get the current good burntool state 269 ## this returns just the values of interest in a tiny mdc file 270 my $camera_config_cmd = "$ppConfigDump -camera $camera -get-key BURNTOOL.STATE.GOOD -get-key BURNTOOL.STATE.GOOD.UPDATE"; 271 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 272 run(command => $camera_config_cmd, verbose => 0); 273 unless ($success) { 274 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 275 &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 276 } 277 278 my $camData = $mdcParser->parse(join "", @$stdout_buf) or 279 &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 280 281 my $burntoolStateGood; 282 my $burntoolStateGoodUpdate; 283 foreach my $camEntry (@$camData) { 284 if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") { 285 $burntoolStateGood = $camEntry->{value}; 286 } 287 if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD.UPDATE") { 288 $burntoolStateGoodUpdate = $camEntry->{value}; 289 } 290 } 270 ## Read camera config to get the current good burntool state : 271 ## XXX This is extremely slow. Any better way to do this? 272 ## my $camera_config_cmd = "$ppConfigDump -camera $camera -dump-camera -"; 273 ## ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 274 ## run(command => $camera_config_cmd, verbose => 0); 275 ## unless ($success) { 276 ## $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 277 ## &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 278 ## } 279 ## 280 ## my $camData = $mdcParser->parse(join "", @$stdout_buf) or 281 ## &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 282 283 ## XXX short term hack until we have a C-based parser 284 my $burntoolStateGood = 14; 285 my $burntoolStateGoodUpdate = 13; 286 ## foreach my $camEntry (@$camData) { 287 ## if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") { 288 ## $burntoolStateGood = $camEntry->{value}; 289 ## } 290 ## if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD.UPDATE") { 291 ## $burntoolStateGoodUpdate = $camEntry->{value}; 292 ## } 293 ## } 291 294 292 295 if ($run_state eq 'new') { … … 329 332 # get the UNIX version of the (possible) neb: or path: filename 330 333 my $uriReal = $ipprc->file_resolve( $uri ); 334 # Catch errors here 335 if (!$uriReal) { 336 my $repair_cmd = "$nebrepair $uri"; 337 my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose); 338 unless ($repair_success) { 339 &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR); 340 } 341 $uriReal = $ipprc->file_resolve( $uri ); 342 } 343 331 344 &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal; 332 345 … … 335 348 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose); 336 349 unless ($success) { 350 # Catch errors here 351 my $repair_cmd = "$nebrepair $uri"; 352 my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose); 353 unless ($repair_success) { 354 &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR); 355 } 356 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose); 357 } 358 unless ($success) { 337 359 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 338 360 &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); … … 347 369 $burntoolTable_uri =~ s/fits$/burn.tbl/; 348 370 $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri ); 371 if ((!$burntoolTable_uriReal)||(!($ipprc->file_exists($burntoolTable_uri)))) { 372 my $repair_cmd = "$nebrepair $burntoolTable_uri"; 373 my ($repair_success, $repair_error_code, $repair_full_buf, $repair_stdout_buf, $repair_stderr_buf ) = run(command => $repair_cmd, verbose => $verbose); 374 unless ($repair_success) { 375 &my_die("Unable to attempt repair: $uri $repair_error_code", $exp_id,$chip_id, $class_id, $PS_EXIT_SYS_ERROR); 376 } 377 $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri ); 378 } 349 379 unless ($ipprc->file_exists($burntoolTable_uri)) { 380 # Catch errors here 350 381 &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR); 351 382 } … … 439 470 $command .= " -Db PPIMAGE:PHOTOM FALSE"; 440 471 } 441 if ($run_state eq "new" ) {472 if ($run_state eq "new" or $do_stats) { 442 473 $command .= " -recipe PPSTATS CHIPSTATS"; 443 474 $command .= " -stats $outputStats"; … … 450 481 $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id; 451 482 $command .= " -source_id $source_id" if defined $source_id; 452 $command .= " -tracedest $traceDest -log $logDest";483 $command .= " -tracedest $traceDest"; 453 484 $command .= " -dbname $dbname" if defined $dbname; 454 485 … … 531 562 532 563 # Add the processed file to the database 533 unless ($no_update) { 534 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 535 run(command => $command, verbose => $verbose); 536 unless ($success) { 537 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 538 warn("Unable to perform chiptool -addprocessedimfile: $error_code\n"); 539 exit($error_code); 540 } 541 } else { 542 print "skipping command: $command\n"; 564 my $tries = 0; 565 while (1) { 566 $tries++; 567 unless ($no_update) { 568 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 569 run(command => $command, verbose => $verbose); 570 unless ($success) { 571 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 572 warn("Unable to perform chiptool -addprocessedimfile: $error_code\n"); 573 exit($error_code) if $tries >= 3; 574 warn("Waiting 10 seconds to try again\n"); 575 sleep 10; 576 } else { 577 last; 578 } 579 } else { 580 print "skipping command: $command\n"; 581 last; 582 } 543 583 } 544 584 … … 726 766 &my_die("Couldn't find expected output file: $file", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 727 767 } 768 # Funpack to confirm we've really made things correctly 769 my $diskfile = $ipprc->file_resolve($file); 770 if ($diskfile =~ /fits/) { 771 my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 772 my $check_command = "$funpack -S $diskfile > /dev/null"; 773 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 774 run(command => $check_command, verbose => $verbose); 775 if (!$success) { 776 &my_die("Output file not a valid fits file: $file", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 777 } 778 } 779 ##### 728 780 729 781 if ($replicate and $neb) {
Note:
See TracChangeset
for help on using the changeset viewer.
