IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 16, 2010, 9:26:43 AM (16 years ago)
Author:
Paul Price
Message:

Need to ensure output file exists.

File:
1 edited

Legend:

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

    r27112 r27298  
    11#!/usr/bin/env perl
    22# this program is used to run 'burntool' on images for a single chip
    3 # for all exposures for a given time period.   
    4 # USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD 
     3# for all exposures for a given time period.
     4# USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD
    55
    66# XXX todo:
    77# - add filters to processedimfile
    8 # 
     8#
    99
    1010use warnings;
     
    8282foreach my $cfg (@$recipeData) {
    8383    if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
    84         $burntoolStateGood = $cfg->{value};
     84        $burntoolStateGood = $cfg->{value};
    8585    }
    8686}
     
    100100$command .= " -dbname $dbname" if defined $dbname;
    101101
    102 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
     102( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    103103    run ( command => $command, verbose => $verbose);
    104104unless ($success) {
     
    114114    push @single, $value;
    115115    if ($value =~ /^\s*END\s*$/) {
    116         push @single, "\n";
    117        
    118         my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
    119         &my_die("Unable to parse output from regtool", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_PROG_ERROR) unless
    120             defined $list;
    121         push @{ $files }, @$list;
    122         @single = ();
     116        push @single, "\n";
     117
     118        my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     119        &my_die("Unable to parse output from regtool", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_PROG_ERROR) unless
     120            defined $list;
     121        push @{ $files }, @$list;
     122        @single = ();
    123123    }
    124124}
     
    142142    my $rawImfile = $file->{uri};
    143143    my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
    144    
     144
    145145    my $outTable  = $file->{uri};
    146146    $outTable  =~ s/fits$/burn.tbl/;
    147147    my $outTableReal = $ipprc->file_resolve($outTable, 1);
    148    
     148
    149149    my $process = 0;
    150150    my $previousTableStyle = 0;
    151151
    152152    if ($state == 0) {
    153         $process = 1;
     153        $process = 1;
    154154    }
    155155    elsif ($state == -1) {
    156         $process = 1;
     156        $process = 1;
    157157    }
    158158    elsif ($state == -3) {
    159         $process = 1;
     159        $process = 1;
    160160    }
    161161    elsif ($state == -2) {
    162         &my_die("Aborting as $rawImfile has modified pixel data!");
     162        &my_die("Aborting as $rawImfile has modified pixel data!");
    163163    }
    164164    elsif ($state == $burntoolStateGood) {
    165         $process = 0;
    166         $previousTableStyle = 1;
     165        $process = 0;
     166        $previousTableStyle = 1;
    167167    }
    168168    elsif ($state == -1 * $burntoolStateGood) {
    169         $process = 0;
    170 #       $previousTable = "in=$outTableReal";
    171         $previousTableStyle = -1;
     169        $process = 0;
     170#       $previousTable = "in=$outTableReal";
     171        $previousTableStyle = -1;
    172172    }
    173173    else {
    174         $process = 1;
     174        $process = 1;
    175175    }
    176176    if ($REALRUN == 0) {
    177         print "##Pretending to process as instructed!\n";
    178         $process = 1;
     177        print "##Pretending to process as instructed!\n";
     178        $process = 1;
    179179    }
    180180    if (($process == 1)||($processNext == 1)) {
    181         $processNext = 1;
    182         # Set state to processing
    183         my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
    184         if ($status) {
    185             &my_die("failed to update imfile");
    186         }
    187         $file->{burntool_state} = -1;
    188        
    189         my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
    190                                         DIR => '/tmp/',
    191                                         UNLINK => !$save_temps,
    192                                         SUFFIX => '.fits');
    193         my $tempPixels = $tempfile->filename;
    194        
    195         # Run burntool
    196         $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
    197         if ($status) {
    198             &my_die("failed on funpack",$exp_id,$class_id);
    199         }
    200         if ($previousTable ne '') {
    201             $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
    202         }
    203         else {
    204             $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
    205         }
    206         if ($status) {
    207             &my_die("failed on burntool",$exp_id,$class_id);
    208         }
    209        
    210         $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
    211         $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
    212         if ($status) {
    213             &my_die("failed to update imfile");
    214         }
    215 
    216         $previousTableStyle = -1;
    217        
    218         print "\n";
    219     }
    220    
     181        $processNext = 1;
     182        # Set state to processing
     183        my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
     184        if ($status) {
     185            &my_die("failed to update imfile");
     186        }
     187        $file->{burntool_state} = -1;
     188
     189        my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
     190                                        DIR => '/tmp/',
     191                                        UNLINK => !$save_temps,
     192                                        SUFFIX => '.fits');
     193        my $tempPixels = $tempfile->filename;
     194
     195        # Run burntool
     196        $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
     197        if ($status) {
     198            &my_die("failed on funpack",$exp_id,$class_id);
     199        }
     200        if ($previousTable ne '') {
     201            $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
     202        }
     203        else {
     204            $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
     205        }
     206        if ($status) {
     207            &my_die("failed on burntool",$exp_id,$class_id);
     208        }
     209        &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal);
     210
     211        $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
     212        $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
     213        if ($status) {
     214            &my_die("failed to update imfile");
     215        }
     216
     217        $previousTableStyle = -1;
     218
     219        print "\n";
     220    }
     221
    221222    if ($previousTableStyle == 1) {
    222         $previousTable = "infits=$rawImfileReal";
     223        $previousTable = "infits=$rawImfileReal";
    223224    }
    224225    elsif ($previousTableStyle == -1) {
    225         $previousTable = "in=$outTableReal";
     226        $previousTable = "in=$outTableReal";
    226227    }
    227228    else {
    228         die "previousTableStyle undefined!\n";
    229     }
    230    
    231 }
    232    
     229        die "previousTableStyle undefined!\n";
     230    }
     231
     232}
     233
    233234exit 0;
    234235
     
    238239
    239240    print "$command\n";
    240    
     241
    241242    my $status = 0;
    242243    if ($realrun) {
    243         $status = system ($command);
     244        $status = system ($command);
    244245    }
    245246
     
    250251    my $message = shift;
    251252    if ($#_ != -1) {
    252         my $exp_id = shift;
    253         my $class_id = shift;
    254         vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
     253        my $exp_id = shift;
     254        my $class_id = shift;
     255        vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
    255256    }
    256257    printf STDERR "$message\n";
Note: See TracChangeset for help on using the changeset viewer.