- Timestamp:
- Mar 29, 2010, 3:55:49 PM (16 years ago)
- Location:
- branches/eam_branches/20100225
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/ipp_apply_burntool.pl (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20100225
- Property svn:mergeinfo changed
-
branches/eam_branches/20100225/ippScripts/scripts/ipp_apply_burntool.pl
r27038 r27517 1 1 #!/usr/bin/env perl 2 2 # 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 5 5 6 6 # XXX todo: 7 7 # - add filters to processedimfile 8 # 8 # 9 9 10 10 use warnings; … … 20 20 use Pod::Usage qw( pod2usage ); 21 21 22 my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps );22 my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps, $rerun); 23 23 GetOptions( 24 24 'class_id=s' => \$class_id, # chip identifier … … 28 28 'dbname|d=s' => \$dbname, # Database name 29 29 'logfile=s' => \$logfile, 30 'rerun' => \$rerun, 30 31 'verbose' => \$verbose, # Print to stdout 31 32 'save-temps' => \$save_temps, # Save temporary files? … … 82 83 foreach my $cfg (@$recipeData) { 83 84 if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') { 84 $burntoolStateGood = $cfg->{value};85 $burntoolStateGood = $cfg->{value}; 85 86 } 86 87 } … … 100 101 $command .= " -dbname $dbname" if defined $dbname; 101 102 102 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 103 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 103 104 run ( command => $command, verbose => $verbose); 104 105 unless ($success) { … … 107 108 } 108 109 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); 110 my @whole = split /\n/, (join "", @$stdout_buf); 111 my @single = (); 112 my $files; 113 while ( 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); 114 132 115 133 my $REALRUN = 1; … … 125 143 my $rawImfile = $file->{uri}; 126 144 my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0); 127 145 128 146 my $outTable = $file->{uri}; 129 147 $outTable =~ s/fits$/burn.tbl/; 130 148 my $outTableReal = $ipprc->file_resolve($outTable, 1); 131 149 132 150 my $process = 0; 133 151 my $previousTableStyle = 0; 134 152 135 153 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) { 136 178 $process = 1; 137 179 } 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"; 155 231 } 156 232 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 216 238 exit 0; 217 239 … … 221 243 222 244 print "$command\n"; 223 245 224 246 my $status = 0; 225 247 if ($realrun) { 226 $status = system ($command);248 $status = system ($command); 227 249 } 228 250 … … 233 255 my $message = shift; 234 256 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); 238 260 } 239 261 printf STDERR "$message\n";
Note:
See TracChangeset
for help on using the changeset viewer.
