IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 18, 2009, 10:29:30 AM (17 years ago)
Author:
watersc1
Message:

Modified chip_imfile.pl to accept burntool tables and apply corrections on-the-fly. Fixed bugs in ipp_cleanup.pl. Incremented BURNTOOL.STATE.GOOD to match updated upstream code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/chip_imfile.pl

    r24549 r25442  
    1919use IPC::Cmd 0.36 qw( can_run run );
    2020use PS::IPP::Metadata::Config;
     21use PS::IPP::Metadata::List qw( parse_md_list );
    2122use PS::IPP::Config 1.01 qw( :standard );
    2223use File::Temp qw( tempfile );
     
    143144    ## XXX make the feature more general?
    144145    my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE');
    145     if ($useDeburnedImage && $deburned) {
    146         $uri =~ s/fits$/burn.fits/;
    147         &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri);
     146    if ($useDeburnedImage) {
     147        ## Check that we have required programs:
     148#       print STDERR "Inside burntool loop!\n";
     149        my $regtool  = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     150        my $funpack  = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     151        my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     152       
     153        ## Check the current burntool processing version:
     154        my $regtool_state_cmd = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -limit 1";
     155        if (defined($dbname)) {
     156            $regtool_state_cmd .= " -dbname $dbname";
     157        }
     158        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     159            run(command => $regtool_state_cmd, verbose => $verbose);
     160
     161        unless ($success) {
     162            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     163            &my_die("Unable to perform regtool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     164        }
     165
     166        my $regData = $mdcParser->parse(join "", @$stdout_buf) or
     167            &my_die("Unable to parse regtool metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     168        my $regData2 = parse_md_list($regData);
     169
     170        my $burntoolState = 999;
     171        foreach my $regEntry (@$regData2) {
     172#           print "$regEntry->{exp_id} $regEntry->{burntool_state}\n";
     173
     174            if ($regEntry->{exp_id} == $exp_id) {
     175                $burntoolState = $regEntry->{burntool_state};
     176            }
     177        }
     178        if ($burntoolState == 999) {
     179            &my_die("Unable to find burntool_state in metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     180        }
     181
     182        ## Read camera config to get the current good burntool state :
     183        ## XXX This is extremely slow. Any better way to do this?
     184        my $camera_config_cmd = "$ppConfigDump -camera $camera -dump-camera -";
     185        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     186            run(command => $camera_config_cmd, verbose => $verbose);
     187        unless ($success) {
     188            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     189            &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     190        }
     191
     192        my $camData = $mdcParser->parse(join "", @$stdout_buf) or
     193            &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     194
     195        my $burntoolStateGood;
     196        foreach my $camEntry (@$camData) {
     197            if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") {
     198                $burntoolStateGood = $camEntry->{value};
     199            }
     200        }
     201
     202        if (abs($burntoolState) != $burntoolStateGood) {
     203            &my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     204        }
     205
     206        ## We now know that we have an image that has been burntooled. 
     207        my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX",
     208                                              UNLINK => !$save_temps, SUFFIX => '.fits' );
     209       
     210        # get the UNIX version of the (possible) neb: or path: filename
     211        my $uriReal = $ipprc->file_resolve( $uri );
     212
     213        # funpack into the temp file.
     214        my $funpack_cmd = "$funpack -S $uriReal > $tempName";
     215        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose);
     216        unless ($success) {
     217            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     218            &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     219        }
     220       
     221        ## Construct commands to apply the pre-calculated burntool trailfits to the pixel data.
     222        my ($burntoolTable_uri, $burntoolTable_uriReal);
     223        my $burntool_cmd = "$burntool ";
     224
     225        if ($burntoolState == -1 * $burntoolStateGood) {   # Burntool information stored in an external table.
     226            $burntoolTable_uri = $uri;
     227            $burntoolTable_uri =~ s/fits$/burn.tbl/;
     228            $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri );
     229            unless ($ipprc->file_exists($burntoolTable_uri)) {
     230                &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR);
     231            }
     232
     233            $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} apply=t";
     234        }
     235        elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table.
     236            $burntool_cmd .= "$tempName apply=t";
     237        }
     238        else {
     239            &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     240        }
     241
     242        ## Run burntool to change the pixels of tempfile, and repoint $uri to that file.
     243        ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
     244            run(command => $burntool_cmd, verbose => $verbose);
     245        unless ($success) {
     246            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     247            &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     248        }
     249
     250        $uri = $tempName;
     251        unless ($ipprc->file_exists($uri)) {
     252            &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);
     253        }       
     254
     255#       print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n";
     256#       exit(100);     
    148257    }
    149258
Note: See TracChangeset for help on using the changeset viewer.