IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 29, 2010, 3:55:49 PM (16 years ago)
Author:
eugene
Message:

update merges from trunk

Location:
branches/eam_branches/20100225
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20100225

  • branches/eam_branches/20100225/ippScripts/scripts/ipp_apply_burntool.pl

    r27038 r27517  
    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;
     
    2020use Pod::Usage qw( pod2usage );
    2121
    22 my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps);
     22my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps, $rerun);
    2323GetOptions(
    2424    'class_id=s'        => \$class_id, # chip identifier
     
    2828    'dbname|d=s'        => \$dbname, # Database name
    2929    'logfile=s'         => \$logfile,
     30    'rerun'             => \$rerun,
    3031    'verbose'           => \$verbose,   # Print to stdout
    3132    'save-temps'        => \$save_temps, # Save temporary files?
     
    8283foreach my $cfg (@$recipeData) {
    8384    if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
    84         $burntoolStateGood = $cfg->{value};
     85        $burntoolStateGood = $cfg->{value};
    8586    }
    8687}
     
    100101$command .= " -dbname $dbname" if defined $dbname;
    101102
    102 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 
     103( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    103104    run ( command => $command, verbose => $verbose);
    104105unless ($success) {
     
    107108}
    108109
    109 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    110     &my_die("Unable to parse metadata", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
    111 
    112 my $files = parse_md_list($metadata) or
    113     &my_die("Unable to parse metadata list", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
     110my @whole = split /\n/, (join "", @$stdout_buf);
     111my @single = ();
     112my $files;
     113while ( scalar @whole > 0 ) {
     114    my $value = shift @whole;
     115    push @single, $value;
     116    if ($value =~ /^\s*END\s*$/) {
     117        push @single, "\n";
     118
     119        my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
     120        &my_die("Unable to parse output from regtool", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_PROG_ERROR) unless
     121            defined $list;
     122        push @{ $files }, @$list;
     123        @single = ();
     124    }
     125}
     126
     127#my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     128#    &my_die("Unable to parse metadata", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
     129#
     130#my $files = parse_md_list($metadata) or
     131#    &my_die("Unable to parse metadata list", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
    114132
    115133my $REALRUN = 1;
     
    125143    my $rawImfile = $file->{uri};
    126144    my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
    127    
     145
    128146    my $outTable  = $file->{uri};
    129147    $outTable  =~ s/fits$/burn.tbl/;
    130148    my $outTableReal = $ipprc->file_resolve($outTable, 1);
    131    
     149
    132150    my $process = 0;
    133151    my $previousTableStyle = 0;
    134152
    135153    if ($state == 0) {
     154        $process = 1;
     155    }
     156    elsif ($state == -1) {
     157        $process = 1;
     158    }
     159    elsif ($state == -3) {
     160        $process = 1;
     161    }
     162    elsif ($state == -2) {
     163        &my_die("Aborting as $rawImfile has modified pixel data!");
     164    }
     165    elsif ($state == $burntoolStateGood) {
     166        $process = 0;
     167        $previousTableStyle = 1;
     168    }
     169    elsif ($state == -1 * $burntoolStateGood) {
     170        $process = 0;
     171#       $previousTable = "in=$outTableReal";
     172        $previousTableStyle = -1;
     173    }
     174    else {
     175        $process = 1;
     176    }
     177    if ($rerun) {
    136178        $process = 1;
    137179    }
    138     elsif ($state == -1) {
    139         $process = 1;
    140     }
    141     elsif ($state == -3) {
    142         $process = 1;
    143     }
    144     elsif ($state == -2) {
    145         &my_die("Aborting as $rawImfile has modified pixel data!");
    146     }
    147     elsif ($state == $burntoolStateGood) {
    148         $process = 0;
    149         $previousTableStyle = 1;
    150     }
    151     elsif ($state == -1 * $burntoolStateGood) {
    152         $process = 0;
    153 #       $previousTable = "in=$outTableReal";
    154         $previousTableStyle = -1;
     180    if ($REALRUN == 0) {
     181        print "##Pretending to process as instructed!\n";
     182        $process = 1;
     183    }
     184    if (($process == 1)||($processNext == 1)) {
     185        $processNext = 1;
     186        # Set state to processing
     187        my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
     188        if ($status) {
     189            &my_die("failed to update imfile");
     190        }
     191        $file->{burntool_state} = -1;
     192
     193        my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
     194                                        DIR => '/tmp/',
     195                                        UNLINK => !$save_temps,
     196                                        SUFFIX => '.fits');
     197        my $tempPixels = $tempfile->filename;
     198
     199        # Run burntool
     200        $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
     201        if ($status) {
     202            &my_die("failed on funpack",$exp_id,$class_id);
     203        }
     204        if ($previousTable ne '') {
     205            $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
     206        }
     207        else {
     208            $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
     209        }
     210        if ($status) {
     211            &my_die("failed on burntool",$exp_id,$class_id);
     212        }
     213        &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal);
     214
     215        $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
     216        $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
     217        if ($status) {
     218            &my_die("failed to update imfile");
     219        }
     220
     221        $previousTableStyle = -1;
     222
     223        print "\n";
     224    }
     225
     226    if ($previousTableStyle == 1) {
     227        $previousTable = "infits=$rawImfileReal";
     228    }
     229    elsif ($previousTableStyle == -1) {
     230        $previousTable = "in=$outTableReal";
    155231    }
    156232    else {
    157         $process = 1;
    158     }
    159     if ($REALRUN == 0) {
    160         print "##Pretending to process as instructed!\n";
    161         $process = 1;
    162     }
    163     if (($process == 1)||($processNext == 1)) {
    164         $processNext = 1;
    165         # Set state to processing
    166         my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
    167         if ($status) {
    168             &my_die("failed to update imfile");
    169         }
    170         $file->{burntool_state} = -1;
    171        
    172         my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
    173                                         DIR => '/tmp/',
    174                                         UNLINK => !$save_temps,
    175                                         SUFFIX => '.fits');
    176         my $tempPixels = $tempfile->filename;
    177        
    178         # Run burntool
    179         $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
    180         if ($status) {
    181             &my_die("failed on funpack",$exp_id,$class_id);
    182         }
    183         if ($previousTable ne '') {
    184             $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
    185         }
    186         else {
    187             $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
    188         }
    189         if ($status) {
    190             &my_die("failed on burntool",$exp_id,$class_id);
    191         }
    192        
    193         $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
    194         $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
    195         if ($status) {
    196             &my_die("failed to update imfile");
    197         }
    198 
    199         $previousTableStyle = -1;
    200        
    201         print "\n";
    202     }
    203    
    204     if ($previousTableStyle == 1) {
    205         $previousTable = "infits=$rawImfileReal";
    206     }
    207     elsif ($previousTableStyle == -1) {
    208         $previousTable = "in=$outTableReal";
    209     }
    210     else {
    211         die "previousTableStyle undefined!\n";
    212     }
    213    
    214 }
    215    
     233        die "previousTableStyle undefined!\n";
     234    }
     235
     236}
     237
    216238exit 0;
    217239
     
    221243
    222244    print "$command\n";
    223    
     245
    224246    my $status = 0;
    225247    if ($realrun) {
    226         $status = system ($command);
     248        $status = system ($command);
    227249    }
    228250
     
    233255    my $message = shift;
    234256    if ($#_ != -1) {
    235         my $exp_id = shift;
    236         my $class_id = shift;
    237         vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
     257        my $exp_id = shift;
     258        my $class_id = shift;
     259        vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
    238260    }
    239261    printf STDERR "$message\n";
Note: See TracChangeset for help on using the changeset viewer.