Changeset 25425 for trunk/tools
- Timestamp:
- Sep 16, 2009, 6:35:31 PM (17 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
-
examine_burntool_pcontrol.pl (modified) (7 diffs)
-
ipp_apply_burntool.pl (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/examine_burntool_pcontrol.pl
r25300 r25425 2 2 3 3 # script to print out information about the current status of a burntool run. 4 5 4 use DBI; 6 5 use Getopt::Std; … … 15 14 print STDERR " status of the processing. On the OTA grid:\n"; 16 15 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"; 20 21 exit(1); 21 22 } 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; 26 open(LAZY,"ppConfigDump -camera GPC1 -dump-camera - |") || die "Can't run ppConfigDump\n"; 27 while(<LAZY>) { 28 chomp; 29 if ($_ =~ /BURNTOOL.STATE.GOOD/) { 30 @line = split /\s+/; 31 $burntoolStateGood = $line[2]; 32 } 33 } 34 close(LAZY); 35 unless( $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 24 40 sub class_to_vector { 25 41 my $class = shift; 26 my $ user1= shift;42 my $burntool_state = shift; 27 43 my $char = '_'; 28 if ( $user1 == 1.0) {29 $char = '[32 mB[m';44 if (abs($burntool_state) == $burntoolStateGood) { 45 $char = '[32;01mB[m'; 30 46 $burncount++; 31 47 } 32 elsif ($user1 == 0.1) { 48 elsif ($burntool_state == -1) { 49 $char = '[01;33mP[m'; 50 } 51 elsif ($burntool_state == 0) { 33 52 $char = '[31mO[m'; 34 53 } 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'; 37 62 } 38 63 … … 47 72 # Engauge autoflush, in case the database server is acting up. 48 73 $| = 1; 49 50 74 51 75 # Load the pcontrol.pro file, and create arrays of the dates included … … 96 120 # Get the data. The limit is there to keep the database happy. I don't think you can observe that many 97 121 # 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"; 99 123 $data_ref = $db->selectall_arrayref( $sth ); 100 124 … … 122 146 123 147 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 125 150 # Correct for nulls in the database. 126 151 if (!defined($obs_mode)) { 127 152 $obs_mode = 'NULL'; 128 153 } 129 if (!defined($ user_1)) {130 $ user_1 = -1;154 if (!defined($burntool_state)) { 155 $burntool_state = 0; 131 156 } 132 157 if (!defined($comment)) { 133 158 $comment = ' '; 134 159 } 135 160 # print "$exp_id $class_id $burntool_state\n"; 136 161 # If we're still working on the same exp_id, update the chip we got 137 162 if ($exp_id == $cur_exp_id) { 138 class_to_vector($class_id,$ user_1);163 class_to_vector($class_id,$burntool_state); 139 164 } 140 165 else { … … 156 181 } 157 182 ($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); 159 184 } 160 185 } … … 169 194 if ($burncount != 60) { 170 195 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/) { 173 198 if ($vector[$j] ne '_') { 174 199 $id = sprintf("XY%d%d",int($j / 8),$j % 8); -
trunk/tools/ipp_apply_burntool.pl
r25412 r25425 12 12 use Carp; 13 13 14 use IPC::Cmd 0.36 qw( can_run );15 use IPC::Run 0.36 qw( run );14 use IPC::Cmd 0.36 qw( can_run run ); 15 #use IPC::Run 0.36 qw( run ); 16 16 use PS::IPP::Metadata::List qw( parse_md_list ); 17 17 use PS::IPP::Config 1.01 qw( :standard ); … … 20 20 use Pod::Usage qw( pod2usage ); 21 21 22 my ( $class_id, $dateobs_begin, $dateobs_end, $ skip_burned, $rerun_from_first, $dbname, $logfile, $verbose, $save_temps);22 my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps); 23 23 GetOptions( 24 24 'class_id=s' => \$class_id, # chip identifier 25 25 'dateobs_begin=s' => \$dateobs_begin, # exposure date/time range start 26 26 'dateobs_end=s' => \$dateobs_end, # exposure date/time range stop 27 'camera=s' => \$camera, # Camera 27 28 'dbname|d=s' => \$dbname, # Database name 28 29 'logfile=s' => \$logfile, 29 'skip_burned' => \$skip_burned, # Print to stdout30 'rerun_from_first' => \$rerun_from_first, # Print to stdout31 30 'verbose' => \$verbose, # Print to stdout 32 31 'save-temps' => \$save_temps, # Save temporary files? 32 33 33 ) or pod2usage( 2 ); 34 34 … … 43 43 defined $dbname; 44 44 45 if ($skip_burned and $rerun_from_first) { &my_die("-rerun_from_first and -skip_burned are incompatible"); } 45 unless (defined $camera) { 46 $camera = "GPC1"; 47 # warn("No camera defined. Defaulting to $camera and warning."); 48 } 46 49 47 50 my $missing_tools; … … 49 52 my $funpack = can_run('funpack') or (warn "Can't find funpack" and $missing_tools = 1); 50 53 my $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); 54 my $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); 52 56 if ($missing_tools) { 53 57 warn("Can't find required tools."); … … 57 61 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 58 62 63 # IPP configuration (including nebulous) 64 my $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. 69 my $config_cmd = "$ppConfigDump -camera $camera -dump-camera - | grep BURNTOOL"; 70 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 71 run ( command => $config_cmd, verbose => $verbose); 72 unless ($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 77 my $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 80 my $burntoolStateGood = 999; 81 foreach my $cfg (@$recipeData) { 82 if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') { 83 $burntoolStateGood = $cfg->{value}; 84 } 85 } 86 if ($burntoolStateGood == 999) { 87 &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, $class_id, 0, $PS_EXIT_SYS_ERROR); 88 } 89 my $outState = -1 * abs($burntoolStateGood); 90 91 print ">>$burntoolStateGood<<\n"; 92 93 # Define list of images to examine. 59 94 my $command = "$regtool -processedimfile"; 60 95 $command .= " -class_id $class_id"; … … 64 99 $command .= " -dbname $dbname" if defined $dbname; 65 100 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); 103 unless ($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 108 my $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 111 my $files = parse_md_list($metadata) or 112 &my_die("Unable to parse metadat list", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR); 97 113 98 114 my $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 117 my $processNext = 0; 118 my $previousTable = ''; 119 120 foreach 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; 106 165 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); 118 188 if ($status) { 119 189 &my_die("failed to update imfile"); 120 190 } 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 204 198 exit 0; 205 199 … … 220 214 sub my_die { 221 215 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 } 223 221 printf STDERR "$message\n"; 224 222 exit 1;
Note:
See TracChangeset
for help on using the changeset viewer.
