- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/chip_imfile.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippScripts/scripts/chip_imfile.pl
r24549 r27840 8 8 use Sys::Hostname; 9 9 my $host = hostname(); 10 my $date = `date`; 10 11 print "\n\n"; 11 print "Starting script $0 on $host \n\n";12 print "Starting script $0 on $host at $date\n\n"; 12 13 13 14 use DateTime; … … 19 20 use IPC::Cmd 0.36 qw( can_run run ); 20 21 use PS::IPP::Metadata::Config; 22 use PS::IPP::Metadata::List qw( parse_md_list ); 21 23 use PS::IPP::Config 1.01 qw( :standard ); 22 24 use File::Temp qw( tempfile ); … … 52 54 'reduction=s' => \$reduction, # Reduction class 53 55 'run-state=s' => \$run_state, # current state of the run (new, update) 54 'magicked '=> \$magicked, # magicked state of input file56 'magicked=s' => \$magicked, # magicked state of input file 55 57 'deburned=s' => \$deburned, # does deburned image exist? 56 58 'threads=s' => \$threads, # Number of threads to use for ppImage … … 133 135 $command = "$ppConfigDump -camera $camera -dump-recipe PPIMAGE -recipe PPIMAGE $recipe_ppImage -"; 134 136 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 135 run(command => $command, verbose => $verbose);137 run(command => $command, verbose => 0); 136 138 unless ($success) { 137 139 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); … … 143 145 ## XXX make the feature more general? 144 146 my $useDeburnedImage = metadataLookupBool($recipeData, 'USE.DEBURNED.IMAGE'); 145 if ($useDeburnedImage && $deburned) { 146 $uri =~ s/fits$/burn.fits/; 147 &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($uri); 147 148 if ($useDeburnedImage) { 149 my $useBestBurntool = metadataLookupBool($recipeData, 'USE.BEST.BURNTOOL'); 150 151 ## Check that we have required programs: 152 # print STDERR "Inside burntool loop!\n"; 153 my $regtool = can_run('regtool') or &my_die ("Can't find regtool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 154 my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 155 my $burntool = can_run('burntool') or &my_die ("Can't find burntool", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 156 157 ## Check the current burntool processing version: 158 my $regtool_state_cmd = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -limit 1"; 159 if (defined($dbname)) { 160 $regtool_state_cmd .= " -dbname $dbname"; 161 } 162 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 163 run(command => $regtool_state_cmd, verbose => $verbose); 164 165 unless ($success) { 166 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 167 &my_die("Unable to perform regtool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 168 } 169 170 my $regData = $mdcParser->parse(join "", @$stdout_buf) or 171 &my_die("Unable to parse regtool metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 172 my $regData2 = parse_md_list($regData); 173 174 my $burntoolState = 999; 175 foreach my $regEntry (@$regData2) { 176 print "$regEntry->{exp_id} $regEntry->{burntool_state}\n"; 177 178 if ($regEntry->{exp_id} == $exp_id) { 179 $burntoolState = $regEntry->{burntool_state}; 180 } 181 } 182 if ($burntoolState == 999) { 183 &my_die("Unable to find burntool_state in metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 184 } 185 if ($burntoolState == 32767) { 186 $burntoolState = 0; 187 } 188 189 ## Read camera config to get the current good burntool state : 190 ## XXX This is extremely slow. Any better way to do this? 191 my $camera_config_cmd = "$ppConfigDump -camera $camera -dump-camera -"; 192 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 193 run(command => $camera_config_cmd, verbose => 0); 194 unless ($success) { 195 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 196 &my_die("Unable to perform ppConfigDump: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 197 } 198 199 my $camData = $mdcParser->parse(join "", @$stdout_buf) or 200 &my_die("Unable to parse ppConfigDump metadata", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 201 202 my $burntoolStateGood; 203 foreach my $camEntry (@$camData) { 204 if ($camEntry->{name} eq "BURNTOOL.STATE.GOOD") { 205 $burntoolStateGood = $camEntry->{value}; 206 } 207 } 208 209 print "burntool state vs burntoolStateGood : $burntoolState vs $burntoolStateGood\n"; 210 if (abs($burntoolState) != $burntoolStateGood) { 211 if ($useBestBurntool) { 212 &my_die("Image burntool version does not match current accepted version.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 213 } 214 else { 215 warn ("Image burntool version does not match current accepted version. Continuing as requested."); 216 # Internally pretend that we're at a good version. 217 if ($burntoolState < -10) { 218 $burntoolState = -1 * $burntoolStateGood; 219 } 220 elsif ($burntoolState > 10) { 221 $burntoolState = $burntoolStateGood; 222 } 223 elsif ($burntoolState == 0) { 224 # You've told me to use a deburned image, and that you don't care if it's the most recent. The database has told me 225 # that burntool has never been run on this image. We'll hope the database is wrong, but I don't really trust that. 226 warn ("burntool_state suggests no table will be found. This will likely crash."); 227 $burntoolState = -1 * $burntoolStateGood; 228 } 229 else { 230 &my_die("No valid burntool table will be found.", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 231 } 232 } 233 } 234 235 ## We now know that we have an image that has been burntooled. 236 my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.deburned.XXXX", 237 UNLINK => !$save_temps, SUFFIX => '.fits' ); 238 239 # get the UNIX version of the (possible) neb: or path: filename 240 my $uriReal = $ipprc->file_resolve( $uri ); 241 242 # funpack into the temp file. 243 my $funpack_cmd = "$funpack -S $uriReal > $tempName"; 244 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $funpack_cmd, verbose => $verbose); 245 unless ($success) { 246 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 247 &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 248 } 249 250 ## Construct commands to apply the pre-calculated burntool trailfits to the pixel data. 251 my ($burntoolTable_uri, $burntoolTable_uriReal); 252 my $burntool_cmd = "$burntool "; 253 254 if ($burntoolState == -1 * $burntoolStateGood) { # Burntool information stored in an external table. 255 $burntoolTable_uri = $uri; 256 $burntoolTable_uri =~ s/fits$/burn.tbl/; 257 $burntoolTable_uriReal = $ipprc->file_resolve( $burntoolTable_uri ); 258 unless ($ipprc->file_exists($burntoolTable_uri)) { 259 &my_die("Couldn't find burntool table: $burntoolTable_uri",$exp_id,$chip_id,$class_id, $PS_EXIT_SYS_ERROR); 260 } 261 262 $burntool_cmd .= "$tempName in=${burntoolTable_uriReal} persist=t apply=t"; 263 } 264 elsif ($burntoolState == $burntoolStateGood) { # Burntool information stored in a header table. 265 $burntool_cmd .= "$tempName persist=t apply=t"; 266 } 267 else { 268 &my_die("Image data not properly burntooled, impossible state", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 269 } 270 271 ## Run burntool to change the pixels of tempfile, and repoint $uri to that file. 272 ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = 273 run(command => $burntool_cmd, verbose => $verbose); 274 unless ($success) { 275 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 276 &my_die("Unable to perform burntool: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 277 } 278 279 $uri = $tempName; 280 unless ($ipprc->file_exists($uri)) { 281 &my_die("Couldn't find deburned input file: $uri\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 282 } 283 284 # print STDERR "$uri $uriReal $tempName $burntoolTable_uri $burntoolTable_uriReal $burntool_cmd $save_temps\n"; 285 # exit(100); 148 286 } 149 287 … … 152 290 if ($tiltystreakApply) { 153 291 154 my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS');155 my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id");156 if ($tiltystreakClassApply) {157 158 my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id");159 if ($tiltystreakClassOptions eq "none") {160 $tiltystreakClassOptions = "";161 }162 163 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf);164 165 # XXX make these optional (must be built by psbuild as well...)166 my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);167 my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);168 169 # create an temporary output file:170 my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps );171 172 print "uri: $uri\n";173 174 # get the UNIX version of the (possible) neb: or path: filename175 my $uriReal = $ipprc->file_resolve( $uri );176 177 print "uriReal: $uriReal\n";178 179 # unpack the data (is a NOP if not compressed)180 $command = "$funpack -S $uriReal > $tempName";181 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);182 unless ($success) {183 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);184 &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);185 }186 187 # run tiltystreak188 $command = "$tiltystreak $tempName $tiltystreakClassOptions";189 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);190 unless ($success) {191 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);192 &my_die("Unable to perform tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR);193 }194 195 # supply the output file as the new input file196 $uri = $tempName;197 }292 my $tiltystreakByClass = metadataLookupMD($recipeData, 'TILTYSTREAK.BY.CLASS'); 293 my $tiltystreakClassApply = metadataLookupBool($tiltystreakByClass, "APPLY.$class_id"); 294 if ($tiltystreakClassApply) { 295 296 my $tiltystreakClassOptions = metadataLookupStr($tiltystreakByClass, "OPTIONS.$class_id"); 297 if ($tiltystreakClassOptions eq "none") { 298 $tiltystreakClassOptions = ""; 299 } 300 301 my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf); 302 303 # XXX make these optional (must be built by psbuild as well...) 304 my $funpack = can_run('funpack') or &my_die ("Can't find funpack", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 305 my $tiltystreak = can_run('tiltystreak') or &my_die ("Can't find tiltystreak", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 306 307 # create an temporary output file: 308 my ($tempFile, $tempName) = tempfile( "/tmp/chip.$exp_id.$class_id.tmp.XXXX", UNLINK => !$save_temps ); 309 310 print "uri: $uri\n"; 311 312 # get the UNIX version of the (possible) neb: or path: filename 313 my $uriReal = $ipprc->file_resolve( $uri ); 314 315 print "uriReal: $uriReal\n"; 316 317 # unpack the data (is a NOP if not compressed) 318 $command = "$funpack -S $uriReal > $tempName"; 319 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 320 unless ($success) { 321 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 322 &my_die("Unable to perform funpack: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 323 } 324 325 # run tiltystreak 326 $command = "$tiltystreak $tempName $tiltystreakClassOptions"; 327 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose); 328 unless ($success) { 329 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 330 &my_die("Unable to perform tiltystreak: $error_code", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR); 331 } 332 333 # supply the output file as the new input file 334 $uri = $tempName; 335 } 198 336 } 199 337 … … 239 377 if ($do_stats) { 240 378 my $outputStatsReal = $ipprc->file_resolve($outputStats); 241 &my_die("Couldn't find expected output file: $outputStats", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal;379 &my_die("Couldn't find expected output file: $outputStats", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal); 242 380 243 381 # measure chip stats … … 253 391 } 254 392 chomp $cmdflags; 255 if (($camera ne "GPC1") or ($class_id ne "XY27") or ($exp_id < 53171)) { 256 ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 257 } else { 258 # hack to kick ota 27 out of subsequent analysis by setting quality flag to a non-zero value 259 my ($before, $after) = split " -quality ", $cmdflags; 260 261 # get the current value 262 ($quality) = $after =~ /^(\d+)/; 263 $after = substr($after, length($quality)); 264 265 # replace it if it is zero 266 $quality = 42 if !$quality; 267 268 # rebuild the cmdflags 269 $cmdflags = $before . " -quality $quality"; 270 $cmdflags .= " $after" if $after; 271 } 393 ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 272 394 } 273 395 … … 278 400 &my_die("Couldn't find expected output file: $outputBin1\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin1); 279 401 &my_die("Couldn't find expected output file: $outputBin2\n", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputBin2); 402 if ($run_state eq 'new') { 403 &my_die("Couldn't find expected output file: $configuration", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration); 404 } 280 405 } 281 406 … … 291 416 $command .= " -uri $outputImage"; 292 417 $command .= " -path_base $outroot"; 293 $command .= " -magicked " if $magicked;418 $command .= " -magicked $magicked" if $magicked; 294 419 $command .= " -hostname $host" if defined $host; 295 420 $command .= " -dbname $dbname" if defined $dbname;
Note:
See TracChangeset
for help on using the changeset viewer.
