IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 11, 2012, 11:19:21 PM (15 years ago)
Author:
mhuber
Message:

merged latest r33093 trunk changes to meh_branches/ppsub_test

Location:
branches/meh_branches/ppsub_test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/meh_branches/ppsub_test

  • branches/meh_branches/ppsub_test/ippScripts/scripts/chip_imfile.pl

    r31941 r33098  
    3434my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    3535my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
     36my $nebrepair = can_run('neb-repair') or (warn "Can't find neb-repair" and $missing_tools = 1);
     37
    3638if ($missing_tools) {
    3739    warn("Can't find required tools.");
     
    4446my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose,
    4547     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned );
    46 
    47 my $zaplog = 0;
    4848
    4949GetOptions(
     
    6565    'no-op'             => \$no_op,     # Don't do any operations?
    6666    'redirect-output'   => \$redirect,
    67     'zaplog'            => \$zaplog,
    6867    'save-temps'        => \$save_temps, # Save temporary files?
    6968    ) or pod2usage( 2 );
     
    9291}
    9392
    94 my ($logDest, $traceDest);
     93my ($logRule, $traceDest);
    9594if ($run_state eq 'new') {
    96     $logDest = prepare_output("LOG.IMFILE", $outroot, $class_id, $zaplog);
     95    $logRule = "LOG.IMFILE";
    9796    $traceDest = prepare_output("TRACE.IMFILE",  $outroot, $class_id, 1);
    9897} else {
    99     $logDest = prepare_output("LOG.IMFILE.UPDATE", $outroot, $class_id, 1);
     98    $logRule = "LOG.IMFILE.UPDATE";
    10099    $traceDest = prepare_output("TRACE.IMFILE.UPDATE",  $outroot, $class_id, 1);
    101100}
    102101
    103102if ($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
    105107    print STDOUT "\n\n";
    106108    print STDOUT "Starting script $0 on $host\n\n";
     
    145147my $outputBin2;
    146148my $dump_config = 1;
     149my $do_stats = 1;
     150$outputStats   = prepare_output("PPIMAGE.STATS",         $outroot, $class_id, 1);
    147151my $do_binned_images = 1;
    148152if ($run_state eq 'new') {
    149153    # prepare the files that are only created for a new run
    150154    $configuration = prepare_output("PPIMAGE.CONFIG",        $outroot, $class_id, 1);
    151     $outputStats   = prepare_output("PPIMAGE.STATS",         $outroot, $class_id, 1);
    152155} else {
    153156    $configuration = $ipprc->filename('PPIMAGE.CONFIG', $outroot, $class_id)
     
    194197unless ($no_op) {
    195198    my $command;
    196     my $do_stats;
    197199
    198200    ## get the ppImage recipe for this camera and CHIP reduction
     
    266268        }
    267269
    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        ## }
    291294
    292295        if ($run_state eq 'new') {
     
    329332        # get the UNIX version of the (possible) neb: or path: filename
    330333        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           
    331344        &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
    332345
     
    335348        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
    336349        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) {
    337359            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    338360            &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     
    347369            $burntoolTable_uri =~ s/fits$/burn.tbl/;
    348370            $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            }
    349379            unless ($ipprc->file_exists($burntoolTable_uri)) {
     380                # Catch errors here
    350381                &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
    351382            }
     
    439470        $command .= " -Db PPIMAGE:PHOTOM FALSE";
    440471    }
    441     if ($run_state eq "new") {
     472    if ($run_state eq "new" or $do_stats) {
    442473        $command .= " -recipe PPSTATS CHIPSTATS";
    443474        $command .= " -stats $outputStats";
     
    450481    $command .= " -image_id $chip_imfile_id" if defined $chip_imfile_id;
    451482    $command .= " -source_id $source_id" if defined $source_id;
    452     $command .= " -tracedest $traceDest -log $logDest";
     483    $command .= " -tracedest $traceDest";
    453484    $command .= " -dbname $dbname" if defined $dbname;
    454485
     
    531562
    532563# 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";
     564my $tries = 0;
     565while (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    }
    543583}
    544584
     
    726766        &my_die("Couldn't find expected output file: $file",  $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
    727767    }
     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    #####
    728780
    729781    if ($replicate and $neb) {
Note: See TracChangeset for help on using the changeset viewer.