IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25425 for trunk/tools


Ignore:
Timestamp:
Sep 16, 2009, 6:35:31 PM (17 years ago)
Author:
watersc1
Message:

changes to support new burntool_state

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/examine_burntool_pcontrol.pl

    r25300 r25425  
    22
    33# script to print out information about the current status of a burntool run.
    4 
    54use DBI;
    65use Getopt::Std;
     
    1514    print STDERR "         status of the processing.  On the OTA grid:\n";
    1615    print STDERR "                  _             Blank chip\n";
    17     print STDERR "                  N             Null value for user_1. No burntool attempted.\n";
    18     print STDERR "                  O             0.1 value for user_1. Burntool failed or is running.\n";
    19     print STDERR "                  B             1.0 value for user_1. Burntool succeeded.\n";
     16    print STDERR "                  N             Null/zero value for burntool_state. No burntool attempted.\n";
     17    print STDERR "                  O             -1 value for burntool_state. Burntool is running.\n";
     18    print STDERR "                  E             -2 value for burntool_state. Error!\n";
     19    print STDERR "                  B             Current version value for burntool_state. Burntool succeeded.\n";
     20    print STDERR "                  b             Old version value for burntool_state. Burntool needs to be rerun.\n";
    2021    exit(1);
    2122}
    22 
    23 # Read a class_id and user_1 pair, and set the correct cell of the (sorry, global) character array vector
     23$| = 1;
     24# Determine what the value of "BURNTOOL.STATE.GOOD" currently is:
     25$burntoolStateGood = 999;
     26open(LAZY,"ppConfigDump -camera GPC1 -dump-camera - |") || die "Can't run ppConfigDump\n";
     27while(<LAZY>) {
     28    chomp;
     29    if ($_ =~ /BURNTOOL.STATE.GOOD/) {
     30        @line = split /\s+/;
     31        $burntoolStateGood = $line[2];
     32    }
     33}
     34close(LAZY);
     35unless( $burntoolStateGood == 999) {
     36    print STDERR "GOOD == $burntoolStateGood\n";
     37}
     38
     39# Read a class_id and burntool_state pair, and set the correct cell of the (sorry, global) character array vector
    2440sub class_to_vector {
    2541    my $class = shift;
    26     my $user1 = shift;
     42    my $burntool_state = shift;
    2743    my $char = '_';
    28     if ($user1 == 1.0) {
    29         $char = '[32mB[m';
     44    if (abs($burntool_state) == $burntoolStateGood) {
     45        $char = '[32;01mB[m';
    3046        $burncount++;
    3147    }
    32     elsif ($user1 == 0.1) {
     48    elsif ($burntool_state == -1) {
     49        $char = '[01;33mP[m';
     50    }
     51    elsif ($burntool_state == 0) {
    3352        $char = '[31mO[m';
    3453    }
    35     elsif ($user1 == -1.0) {
    36         $char = '[34mN[m';
     54    elsif ($burntool_state == -2) {
     55        $char = '[35;01;44;05mE[m';
     56    }
     57    elsif ($burntool_state == -3) {
     58        $char = '[34mX[m';
     59    }
     60    else {
     61        $char = '[32mb[m';
    3762    }
    3863   
     
    4772# Engauge autoflush, in case the database server is acting up.
    4873$| = 1;
    49 
    5074
    5175# Load the pcontrol.pro file, and create arrays of the dates included
     
    96120    # Get the data.  The limit is there to keep the database happy.  I don't think you can observe that many
    97121    # images on a single night.
    98     $sth = "SELECT exp_id,exp_name,obs_mode,dateobs,class_id,user_1,comment FROM rawImfile WHERE dateobs >= '${dmin}' AND dateobs <= '${dmax}' order by dateobs limit 60000";
     122    $sth = "SELECT exp_id,exp_name,obs_mode,dateobs,class_id,burntool_state,comment FROM rawImfile WHERE dateobs >= '${dmin}' AND dateobs <= '${dmax}' order by dateobs limit 60000";
    99123    $data_ref = $db->selectall_arrayref( $sth );
    100124
     
    122146   
    123147    foreach $row_ref (@{ $data_ref }) {
    124         ($exp_id,$exp_name, $obs_mode,$dateobs,$class_id,$user_1,$comment) = @{ $row_ref };
     148        ($exp_id,$exp_name, $obs_mode,$dateobs,$class_id,$burntool_state,$comment) = @{ $row_ref };
     149
    125150        # Correct for nulls in the database.
    126151        if (!defined($obs_mode)) {
    127152            $obs_mode = 'NULL';
    128153        }
    129         if (!defined($user_1)) {
    130             $user_1 = -1;
     154        if (!defined($burntool_state)) {
     155            $burntool_state = 0;
    131156        }
    132157        if (!defined($comment)) {
    133158            $comment = ' ';
    134159        }
    135 
     160#       print "$exp_id $class_id $burntool_state\n";
    136161        # If we're still working on the same exp_id, update the chip we got
    137162        if ($exp_id == $cur_exp_id) {
    138             class_to_vector($class_id,$user_1);
     163            class_to_vector($class_id,$burntool_state);
    139164        }
    140165        else {
     
    156181            }
    157182            ($cur_exp_id,$cur_exp_name,$cur_obs_mode,$cur_dateobs,$cur_comment) = ($exp_id,$exp_name,$obs_mode,$dateobs,$comment);
    158             class_to_vector($class_id,$user_1);
     183            class_to_vector($class_id,$burntool_state);
    159184        }
    160185    }
     
    169194    if ($burncount != 60) {
    170195        for ($j = 0; $j < 64; $j++) {
    171             $vector[$j] =~ s/\[..m(.).*/$1/;
    172             if ($vector[$j] ne 'B') {
     196#           printf("%d %s %d\n",$j, $vector[$j], ($vector[$j] !~ /B/));
     197            if ($vector[$j] !~ /B/) {
    173198                if ($vector[$j] ne '_') {
    174199                    $id = sprintf("XY%d%d",int($j / 8),$j % 8);
  • trunk/tools/ipp_apply_burntool.pl

    r25412 r25425  
    1212use Carp;
    1313
    14 use IPC::Cmd 0.36 qw( can_run );
    15 use IPC::Run 0.36 qw( run );
     14use IPC::Cmd 0.36 qw( can_run run );
     15#use IPC::Run 0.36 qw( run );
    1616use PS::IPP::Metadata::List qw( parse_md_list );
    1717use PS::IPP::Config 1.01 qw( :standard );
     
    2020use Pod::Usage qw( pod2usage );
    2121
    22 my ( $class_id, $dateobs_begin, $dateobs_end, $skip_burned, $rerun_from_first, $dbname, $logfile, $verbose, $save_temps);
     22my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps);
    2323GetOptions(
    2424    'class_id=s'        => \$class_id, # chip identifier
    2525    'dateobs_begin=s'   => \$dateobs_begin, # exposure date/time range start
    2626    'dateobs_end=s'     => \$dateobs_end, # exposure date/time range stop
     27    'camera=s'          => \$camera,     # Camera
    2728    'dbname|d=s'        => \$dbname, # Database name
    2829    'logfile=s'         => \$logfile,
    29     'skip_burned'       => \$skip_burned,   # Print to stdout
    30     'rerun_from_first'  => \$rerun_from_first,   # Print to stdout
    3130    'verbose'           => \$verbose,   # Print to stdout
    3231    'save-temps'        => \$save_temps, # Save temporary files?
     32
    3333    ) or pod2usage( 2 );
    3434
     
    4343    defined $dbname;
    4444
    45 if ($skip_burned and $rerun_from_first) { &my_die("-rerun_from_first and -skip_burned are incompatible"); }
     45unless (defined $camera) {
     46    $camera = "GPC1";
     47#    warn("No camera defined. Defaulting to $camera and warning.");
     48}
    4649
    4750my $missing_tools;
     
    4952my $funpack  = can_run('funpack')  or (warn "Can't find funpack" and $missing_tools = 1);
    5053my $burntool = can_run('burntool') or (warn "Can't find burntool" and $missing_tools = 1);
    51 my $fpack    = can_run('fpack')    or (warn "Can't find fpack" and $missing_tools = 1);
     54my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     55#my $fpack    = can_run('fpack')    or (warn "Can't find fpack" and $missing_tools = 1);
    5256if ($missing_tools) {
    5357    warn("Can't find required tools.");
     
    5761my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    5862
     63# IPP configuration (including nebulous)
     64my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set up");
     65
     66$ipprc->redirect_output($logfile) if $logfile;
     67
     68# Determine the value of a "good" burntool run.
     69my $config_cmd = "$ppConfigDump -camera $camera -dump-camera - | grep BURNTOOL";
     70my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     71    run ( command => $config_cmd, verbose => $verbose);
     72unless ($success) {
     73    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     74    &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, $class_id, $PS_EXIT_SYS_ERROR);
     75}
     76
     77my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     78    &my_die("Unable to parse metadata config doc", 0, 0, $class_id, $PS_EXIT_SYS_ERROR);
     79
     80my $burntoolStateGood = 999;
     81foreach my $cfg (@$recipeData) {
     82    if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') {
     83        $burntoolStateGood = $cfg->{value};
     84    }
     85}
     86if ($burntoolStateGood == 999) {
     87    &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, $class_id, 0, $PS_EXIT_SYS_ERROR);
     88}
     89my $outState = -1 * abs($burntoolStateGood);
     90
     91print ">>$burntoolStateGood<<\n";
     92
     93# Define list of images to examine.
    5994my $command = "$regtool -processedimfile";
    6095$command .= " -class_id $class_id";
     
    6499$command .= " -dbname $dbname" if defined $dbname;
    65100
    66 my @command = split /\s+/, $command;
    67 my ( $stdin, $stdout, $stderr ); # Buffers for running program
    68 print "Running [$command]...\n" if $verbose;
    69 if (not run(\@command, \$stdin, \$stdout, \$stderr)) {
    70     &my_die("Unable to perform regtool -processedimfile");
    71 }
    72 print $stdout . "\n" if $verbose;
    73 
    74 my @files;
    75 my @whole = split /\n/, $stdout;
    76 my @single = ();
    77 while ( scalar @whole > 0 ) {
    78     my $value = shift @whole;
    79     push @single, $value;
    80     if ($value =~ /^\s*END\s*$/) {
    81         push @single, "\n";
    82 
    83         my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) );
    84         &my_die("Unable to parse output from regtool") unless defined $list;
    85         push @files, @$list;
    86         @single = ();
    87     }
    88 }
    89 
    90 # IPP configuration (including nebulous)
    91 my $ipprc = PS::IPP::Config->new() or my_die("Unable to set up");
    92 
    93 $ipprc->redirect_output($logfile) if $logfile;
    94 
    95 my $Nfiles = @files;
    96 print "files: $Nfiles\n";
     101( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     102    run ( command => $command, verbose => $verbose);
     103unless ($success) {
     104    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     105    &my_die("Unable to perform regtool: $error_code", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
     106}
     107
     108my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     109    &my_die("Unable to parse metadata", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
     110
     111my $files = parse_md_list($metadata) or
     112    &my_die("Unable to parse metadat list", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR);
    97113
    98114my $REALRUN = 1;
    99 my $RAWTABLES = 1;
    100 # XXX if we want to avoid using the raw tables in this script, we need to delay deletion of the tempfile until the next pass.
    101 
    102 # first pass: mark the db entries to catch failures
    103 # these will not be identified as burned by chip processing (user_1 > 0.5)
    104 if (! $skip_burned)  {
    105     foreach my $file (@files) {
     115
     116# Process each file in turn, checking to see if it needs processing, and doing it all in a single pass
     117my $processNext = 0;
     118my $previousTable = '';
     119
     120foreach my $file (@$files) {
     121    my $exp_id = $file->{exp_id};
     122    my $state = $file->{burntool_state};
     123
     124    my $rawImfile = $file->{uri};
     125    my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
     126   
     127    my $outTable  = $file->{uri};
     128    $outTable  =~ s/fits$/burn.tbl/;
     129    my $outTableReal = $ipprc->file_resolve($outTable, 1);
     130   
     131    my $process = 0;
     132
     133    if ($state == 0) {
     134        $process = 1;
     135    }
     136    elsif ($state == -1) {
     137        $process = 1;
     138    }
     139    elsif ($state == -3) {
     140        $process = 1;
     141    }
     142    elsif ($state == -2) {
     143        &my_die("Aborting as $rawImfile has modified pixel data!");
     144    }
     145    elsif ($state == $burntoolStateGood) {
     146        $process = 0;
     147        $previousTable = "infits=$rawImfileReal";
     148    }
     149    elsif ($state == -1 * $burntoolStateGood) {
     150        $process = 0;
     151        $previousTable = "in=$outTableReal";
     152    }
     153    else {
     154        $process = 1;
     155    }
     156
     157    if (($process == 1)||($processNext == 1)) {
     158        $processNext = 1;
     159        # Set state to processing
     160        my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
     161        if ($status) {
     162            &my_die("failed to update imfile");
     163        }
     164        $file->{burntool_state} = -1;
    106165       
    107         # rerun_from_first treats the first image as already burned (if it is already burned)
    108         # the artifact table from the first file is used for the rest of the sequence.
    109         if ($rerun_from_first) {
    110             $skip_burned = 1;
    111             $rerun_from_first = 0;
    112             next;
    113         }
    114         my $exp_id = $file->{exp_id};
    115 
    116         my $status;
    117         $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -user_1 0.1", 1);
     166        my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX",
     167                                        DIR => '/tmp/',
     168                                        UNLINK => !$save_temps,
     169                                        SUFFIX => '.fits');
     170        my $tempPixels = $tempfile->filename;
     171       
     172        # Run burntool
     173        $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
     174        if ($status) {
     175            &my_die("failed on funpack",$exp_id,$class_id);
     176        }
     177        if ($previousTable ne '') {
     178            $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN);
     179        }
     180        else {
     181            $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
     182        }
     183        if ($status) {
     184            &my_die("failed on burntool",$exp_id,$class_id);
     185        }
     186       
     187        $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN);
    118188        if ($status) {
    119189            &my_die("failed to update imfile");
    120190        }
    121         $file->{user_1} = 0.1;
    122     }
    123 }
    124 
    125 my $prevFileOpt = "";
    126 foreach my $file (@files) {
    127     my $exp_id = $file->{exp_id};
    128 
    129     my $rawImfile = $file->{uri};
    130     my $rawImfileReal;
    131     if ($REALRUN) {
    132         $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
    133     } else {
    134         ($rawImfileReal) = $rawImfile =~ m|^neb:/(.*)|;
    135     }
    136     print "rawImfile: $rawImfile -> $rawImfileReal\n";
    137 
    138     # mangle name, create tmp file (always a UNIX file)
    139     my $basename = `basename $rawImfile`; chomp $basename;
    140     my $tempfile = new File::Temp ( TEMPLATE => "$basename.XXXX",
    141                                     DIR => '/tmp',
    142                                     UNLINK => !$save_temps,
    143                                     SUFFIX => '.fits');
    144     my $tmpImfileReal = $tempfile->filename;
    145     # print "tmpImfile: $tmpImfile -> $tmpImfileReal\n";
    146    
    147     # destination for the burntool-applied image file (may be a NEB file)
    148     my $outImfile = $rawImfile;
    149     $outImfile =~ s/fits$/burn.fits/;
    150     my $outImfileReal = $ipprc->file_resolve($outImfile, 1);
    151     # print "outImfile: $outImfile -> $outImfileReal\n";
    152 
    153     # burntool now can write the artifacts to the fits file.
    154     # destination for the burntool artifacts.  use this if RAWTABLES is set.
    155     my $artImfile;
    156     my $artImfileReal;
    157     if ($RAWTABLES) {
    158         $artImfile = $rawImfile;
    159         $artImfile =~ s/fits$/burn.tbl/;
    160         $artImfileReal = $ipprc->file_resolve($artImfile, 1);
    161         # print "artImfile: $artImfile -> $artImfileReal\n";
    162     }
    163 
    164     print "$rawImfile : $skip_burned, $file->{user_1}\n";
    165 
    166     if (! ($skip_burned and ($file->{user_1} > 0.5))) {
    167         print "running on: $rawImfile\n";
    168         # uncompress the image (do we need to check if it is compressed?)
    169         my $status = vsystem ("$funpack -S $rawImfileReal > $tmpImfileReal", $REALRUN);
    170         if ($status) {
    171             &my_die("failed on funpack");
    172         }
    173 
    174         if ($RAWTABLES) {
    175             $status = vsystem ("$burntool $tmpImfileReal out=$artImfileReal $prevFileOpt persist=t", $REALRUN);
    176         } else {
    177             $status = vsystem ("$burntool $tmpImfileReal $prevFileOpt persist=t", $REALRUN);
    178         }
    179         if ($status) {
    180             &my_die("failed on burntool");
    181         }
    182 
    183         # compress the image (do we need to check if it is compressed?)
    184         $status = vsystem ("$fpack -S $tmpImfileReal > $outImfileReal", $REALRUN);
    185         if ($status) {
    186             &my_die("failed on fpack");
    187         }
    188 
    189         # set the user_1 value to a new result value for now
    190         $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -user_1 2.0", 1);
    191         if ($status) {
    192             &my_die("failed to update imfile");
    193         }
    194         print "\n";
    195     }
    196     # save the artifact file for the next image
    197     if ($RAWTABLES) {
    198         $prevFileOpt = "in=$artImfileReal";
    199     } else {
    200         $prevFileOpt = "infits=$artImfileReal";
    201     }
    202 }
    203 
     191
     192        $previousTable = "in=$outTableReal";
     193
     194        print "\n";
     195    }
     196}
     197   
    204198exit 0;
    205199
     
    220214sub my_die {
    221215    my $message = shift;
    222 
     216    if ($#_ != -1) {
     217        my $exp_id = shift;
     218        my $class_id = shift;
     219        vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1);
     220    }
    223221    printf STDERR "$message\n";
    224222    exit 1;
Note: See TracChangeset for help on using the changeset viewer.