- Timestamp:
- May 26, 2009, 1:59:32 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/dist_component.pl (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090301/ippScripts/scripts/dist_component.pl
r23594 r24244 27 27 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 28 28 use Pod::Usage qw( pod2usage ); 29 30 # filerules that are not included in 'cleaned' distribution bundles 31 # I could simplify the function below by using a two level hash but 32 # that would be less clear I think 33 my %chip_cleaned = ( 'PPIMAGE.CHIP' => 'image', 34 'PPIMAGE.CHIP.MASK' => 'mask', 35 'PPIMAGE.CHIP.VARIANCE' => 'variance' ); 36 my %camera_cleaned = ( 'PSASTRO.OUTPUT.MASK' => 'mask' ); 37 my %fake_cleaned; 38 my %warp_cleaned = ( 'PSWARP.OUTPUT' => 'image', 39 'PSWARP.OUTPUT.MASK' => 'mask', 40 'PSWARP.OUTPUT.VARIANCE' => 'variance' ); 41 my %diff_cleaned = ( 'PPSUB.OUTPUT' => 'image', 42 'PPSUB.OUTPUT.MASK' => 'mask', 43 'PPSUB.OUTPUT.VARIANCE' => 'variance' ); 44 my %stack_cleaned = ( 'PPSTACK.OUTPUT' => 'image', 45 'PPSTACK.OUTPUT.MASK' => 'mask', 46 'PPSTACK.OUTPUT.VARIANCE' => 'variance' ); 47 29 48 30 49 # Look for programs we need … … 39 58 # Parse the command-line arguments 40 59 my ($dist_id, $camera, $stage, $stage_id, $component, $path_base, $chip_path_base, $clean); 41 my ($out root, $run_state, $data_state, $magicked);60 my ($outdir, $run_state, $data_state, $magicked, $no_magic, $poor_quality); 42 61 my ($dbname, $save_temps, $verbose, $no_update, $logfile); 43 62 … … 52 71 'state=s' => \$run_state, # state of the run 53 72 'data_state=s' => \$data_state, # data_state for this component 73 'poor_quality' => \$poor_quality, # the processing for this component did not produced images 74 'no_magic' => \$no_magic, # magic is not required for this distribution run 54 75 'magicked' => \$magicked, # magicked state for this component 55 'out root=s' => \$outroot,# "directory" for outputs76 'outdir=s' => \$outdir, # "directory" for outputs 56 77 'clean' => \$clean, # create clean distribution 57 78 'save-temps' => \$save_temps, # Save temporary files? … … 63 84 64 85 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 65 pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --out root",86 pod2usage( -msg => "Required options: --dist_id --camera --stage --stage_id --component --path_base --outdir", 66 87 -exitval => 3) unless 67 88 defined $dist_id and … … 71 92 defined $component and 72 93 defined $path_base and 73 defined $out root;94 defined $outdir; 74 95 75 96 $ipprc->redirect_output($logfile) if $logfile; 76 97 77 if (($stage eq 'raw') and ! defined $chip_path_base) {98 if (($stage eq 'raw') and !$clean and !defined $chip_path_base) { 78 99 pod2usage( -msg => "Required options: --chip_path_base for raw stage", -exitval => 3); 79 100 } … … 83 104 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 84 105 85 my $basename = basename($path_base);86 87 106 # making a clean bundle of raw images doesn't make sense 88 if (($stage eq "raw") and $clean) {89 # well I suppose we could ship the log file....90 &my_die("cannot create clean run at raw stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR);91 }92 107 93 108 # create the output directories if it is not a nebulous path and it doesn't exist 94 if (index($out root, "neb://") != 0) {95 if (! -e $out root) {96 my $code = system "mkdir -p $out root";97 &my_die("cannot create output directory $out root", $dist_id, $component,109 if (index($outdir, "neb://") != 0) { 110 if (! -e $outdir ) { 111 my $code = system "mkdir -p $outdir"; 112 &my_die("cannot create output directory $outdir", $dist_id, $component, 98 113 $code >> 8) if $code; 99 114 } 100 115 } 101 116 102 my $file_list = get_file_list($clean, $stage, $path_base); 103 104 &my_die("failed to compute product list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if !$file_list; 105 106 &my_die("empty file list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if !scalar @$file_list; 107 117 # Get the list of data products for this component 118 # note: We my_die in get_file_list if something goes wrong. 119 120 my $file_list = get_file_list($stage, $component, $path_base, $clean); 121 122 if (($stage ne 'raw') and ($stage ne 'fake')) { 123 # If the file list is empty it is an error because we should at least get a config dump file 124 # except for fake stage which doesn't do anything yet 125 &my_die("empty file list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if (!scalar @$file_list); 126 } 108 127 109 128 # set up directory for temporary files 110 129 111 my $tmpdir = "$out root/tmpdir.$dist_id.$component.$$";130 my $tmpdir = "$outdir/tmpdir.$dist_id.$component"; 112 131 if (-e $tmpdir) { 113 132 if (-d $tmpdir) { … … 121 140 $PS_EXIT_UNKNOWN_ERROR); 122 141 123 my @base_list; 142 # 143 # we need to run set masked pixels to NAN in the image and variance images 144 # unless 145 # 1. we are building a clean distribution bundle 146 # 2. magic is not required for this distRun 147 # 3. the processing for the component produced no images (warp or diff with bad quality for example) 148 my $nan_masked_pixels = ! ($clean || (($stage eq "camera") || ($stage eq 'fake') || ($stage eq 'stack')) || $no_magic || $poor_quality); 149 150 my ($image, $mask, $variance); 151 152 # foreach my $file_rule (keys %$file_list) { 153 my $num_files = 0; 124 154 foreach my $file (@$file_list) { 125 my $base = basename($file); 126 my $path = $ipprc->file_resolve($file); 127 # if file is not found, just skip it. 128 # This is not always the right thing to do. 129 # For example if warpSkyfile is ignored, there won't be many of the data products 130 # the new config dump will only list the files actually produced. 131 next if !$path; 132 133 push @base_list, $base; 134 symlink $path, "$tmpdir/$base"; 135 } 136 137 if (!$clean) { 138 139 # Here is where we determine whether or not a GPC1 image can be released. 140 141 if ($camera eq "GPC1" and !$magicked) { 155 # check whether this file rule refers to an image, mask, or variance fits image 156 my $file_rule = $file->{file_rule}; 157 my $image_type = get_image_type($stage, $file_rule); 158 159 # if we are building a clean bundle skip this rule 160 next if $clean && $image_type; 161 162 # if magic is required, don't ship jpegs or binned fits images 163 next if !$no_magic && (($file_rule =~ /.BIN1/) or ($file_rule =~ /.BIN2/) or ($file_rule =~ /.JPEG1/) 164 or ($file_rule =~ /.JPEG2/)); 165 166 my $file_name = $file->{name}; 167 my $base = basename($file_name); 168 my $path = $ipprc->file_resolve($file_name); 169 170 if (!$path) { 171 # skip this file if $poor_quality 172 # this is for compatability with older runs which don't have the files list in the 173 # config dump. 174 # Once we give up on supporting that we can remove the next line. (If the file is in the list 175 # it must exist) 176 next if $poor_quality; 177 178 &my_die("failed to resolve $file_name", $dist_id, $component, $PS_EXIT_DATA_ERROR); 179 } 180 181 # open the file to make sure it exists (and to work around the failed mount phenomena) 182 my $fh = open_with_retries($path); 183 close $fh; 184 185 # we need to pre-process the image before adding to the bundle. Save the path names. 186 # the images will be created below 187 $num_files++; 188 if ($image_type && $nan_masked_pixels) { 189 # save the 190 if ($image_type eq 'image') { 191 $image = $path 192 } elsif ($image_type eq 'mask') { 193 $mask = $path; 194 } elsif ($image_type eq 'variance') { 195 $variance = $path; 196 } else { 197 &my_die("invalid image type found: $image_type", $dist_id, $component, 198 $PS_EXIT_PROG_ERROR); 199 } 200 } else { 201 # create a symbolic link from the file in the nebulous repository 202 # in the temporary directory 203 symlink $path, "$tmpdir/$base"; 204 } 205 } 206 207 if ($nan_masked_pixels) { 208 # One last check as to whether magic has been applied to the inputs 209 210 # Note: the sql for disttool -pendingcomponent won't select a component that 211 # requires magic and hasn't been magicked, but we check again here 212 213 if (!($magicked or $no_magic)) { 142 214 &my_die("cannot create distribution bundle ${stage}_id $stage_id because the data has not been magic desreaked", $dist_id, $component, $PS_EXIT_DATA_ERROR); 143 215 } 144 216 217 &my_die("no image found in file list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if !$image; 218 &my_die("no mask image found in file list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if !$mask; 219 &my_die("no variance image found in file list", $dist_id, $component, $PS_EXIT_CONFIG_ERROR) if !$variance; 220 221 my $class_id; 145 222 # run streaksrelease to set masked pixels to NAN 146 my ($image, $mask, $variance, $class_id);147 223 if ($stage eq "raw") { 148 224 $class_id = $component; 149 $image = $path_base; 150 $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $chip_path_base, $class_id); 225 # we can use the chip mask because disttool demands that magic have been run 226 # and so the camera mask and the chip mask are the same 227 $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $chip_path_base, $component); 228 my $fh = open_with_retries($mask); 229 close $fh; 151 230 } elsif ($stage eq "chip") { 152 231 $class_id = $component; 153 $image = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id); 154 $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 155 $variance = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id); 156 } elsif ($stage eq "warp") { 157 $mask = $ipprc->filename("PSWARP.OUTPUT.MASK", $path_base); 158 $variance = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $path_base); 159 } elsif ($stage eq "diff") { 160 $mask = $ipprc->filename("PPSUB.OUTPUT.MASK", $path_base); 161 $variance = $ipprc->filename("PPSUB.OUTPUT.VARIANCE", $path_base); 162 } else { 163 &my_die("not ready for stage: $stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR); 164 } 165 166 push @base_list, $image; 167 push @base_list, $mask if $mask; 168 push @base_list, $variance if $variance; 232 } 169 233 170 234 my $command = "$streaksrelease -stage $stage -image $image -outroot $tmpdir"; … … 185 249 my $bytes; 186 250 my $md5sum; 187 # create the tarfile 188 { 251 252 if ($num_files) { 253 # create the tarfile 189 254 # XXX TODO: create a file rule for the tar file name 190 255 my $tbase = basename($path_base); 191 256 $tbase .= ".$component" if $component; 192 257 $file_name = "$tbase.tgz"; 193 my $tarfile = "$out root/$file_name";194 195 my $command = "tar -C $tmpdir - czhf $tarfile .";258 my $tarfile = "$outdir/$file_name"; 259 260 my $command = "tar -C $tmpdir --owner=ipp --group=users -czhf $tarfile ."; 196 261 197 262 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = … … 207 272 &my_die("unable to compute md5sum for $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !$md5sum; 208 273 209 my @finfo = stat($tarfile); 210 &my_die("unable to stat $tarfile", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !@finfo; 211 $bytes = $finfo[7]; 274 $bytes = -s $tarfile; 212 275 213 276 delete_tmpdir($tmpdir); 277 } else { 278 # no files for this component 279 $file_name = "none"; 280 $bytes = 0; 281 $md5sum = "0"; 214 282 } 215 283 { … … 234 302 ### Pau. 235 303 304 # return the image type (image, mask, or variance) if this file rule refers to 305 # one of the big fits files that are not included in a clean distribution 306 sub get_image_type { 307 my $stage = shift; 308 my $rule = shift; 309 my $type; 310 311 if ($stage eq "raw") { 312 if ($rule eq "RAW.IMAGE") { 313 $type = 'image'; 314 } 315 } elsif ($stage eq "chip") { 316 $type = $chip_cleaned{$rule}; 317 } elsif ($stage eq "camera") { 318 $type = $camera_cleaned{$rule}; 319 } elsif ($stage eq "fake") { 320 $type = $fake_cleaned{$rule}; 321 } elsif ($stage eq "warp") { 322 $type = $warp_cleaned{$rule}; 323 } elsif ($stage eq "diff") { 324 $type = $diff_cleaned{$rule}; 325 } elsif ($stage eq "stack") { 326 $type = $stack_cleaned{$rule}; 327 } else { 328 &my_die("$stage is not a valid stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR); 329 } 330 return $type; 331 } 332 333 sub open_with_retries { 334 my $name = shift; 335 336 my $tries = 1; 337 my $max_tries = 5; 338 my $opened = 0; 339 while (!$opened && ($tries <= $max_tries)) { 340 $opened = open(IN, "<$name"); 341 if (!$opened) { 342 print STDERR "WARNING failed to open $name re-try $tries\n"; 343 $tries++; 344 sleep 5; 345 } 346 } 347 348 &my_die("failed to open $name after $max_tries tries\n", $dist_id, $component, 349 $PS_EXIT_DATA_ERROR) if (!$opened); 350 351 return *IN; 352 } 236 353 237 354 sub get_file_list { 355 my $stage = shift; 356 my $component = shift; 357 my $path_base = shift; 238 358 my $clean = shift; 239 my $stage = shift;240 my $path_base = shift;241 359 242 360 my @file_list; 243 361 if ($stage eq "raw") { 244 push @file_list, $path_base; 245 } else { 246 # TODO: these data will eventually come from the CONFIG dump 247 248 my $clean_mdc = get_legacy_file_mdc(); 249 250 my $mdlist = $mdcParser->parse($clean_mdc) or 251 &my_die("failed to parse clean.mdc", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR); 252 253 my $product_lists = parse_md_list($mdlist) or 254 &my_die("failed to parse metadata list", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR); 255 256 257 my $product_list; 258 foreach my $list (@$product_lists) { 259 260 my $list_name = $list->{STAGE}; 261 if (lc ($list_name) eq lc($stage) ) { 262 $product_list = $list; 263 } 264 } 265 &my_die("failed to parse find product list for stage $stage", $dist_id, $component, $PS_EXIT_UNKNOWN_ERROR) if !$product_list; 266 267 # resolve each file rule and add it to the file_list 268 foreach my $rule (keys %$product_list) { 269 next if $rule eq "STAGE"; 270 my $keep_on_clean = $product_list->{$rule}; 271 my $fn = $ipprc->filename($rule, $path_base, $component) or 272 &my_die("Missing entry from camera config: $rule", $dist_id, $component, 362 # XXX: TODO for now disttool sets path_base is set to the uri of the file 363 # eventually rawImfile will have a path_base that we'll need to add '.fits' 364 # XXX do we want to distribute the registration log files? 365 if (!$clean) { 366 my %file; 367 $file{file_rule} = "RAW.IMAGE"; 368 $file{name} = $path_base; 369 push @file_list, \%file; 370 } 371 return \@file_list; 372 } 373 374 # we get the list of output data products for this run from the config dump file that 375 # is created when the run is done 376 my $config_file_rule; 377 if ($stage eq "chip") { 378 $config_file_rule = "PPIMAGE.CONFIG"; 379 } elsif ($stage eq "camera") { 380 $config_file_rule = "PSASTRO.CONFIG"; 381 } elsif ($stage eq 'fake') { 382 # XXX: fake is a no op now return an emtpy list 383 return \@file_list; 384 } elsif ($stage eq "warp") { 385 $config_file_rule = "PSWARP.CONFIG"; 386 } elsif ($stage eq "diff") { 387 $config_file_rule = "PPSUB.CONFIG"; 388 } elsif ($stage eq "stack") { 389 $config_file_rule = "PPSTACK.CONFIG"; 390 } else { 391 &my_die("$stage is not a valid stage", $dist_id, $component, $PS_EXIT_CONFIG_ERROR); 392 } 393 my $config_file = $ipprc->filename($config_file_rule, $path_base, $component) or 394 &my_die("can't get filename for config dump file: $config_file_rule", $dist_id, $component, 273 395 $PS_EXIT_CONFIG_ERROR); 274 # printf "%-16.16s\t%s\t%s\n", $rule, $clean, $fn; 275 if (!$clean or $keep_on_clean) { 276 push @file_list, $fn; 277 } 278 } 279 } 396 397 my %config_file_hash; 398 399 # add the configuration file to the list 400 $config_file_hash{file_rule} = $config_file_rule; 401 $config_file_hash{name} = $config_file; 402 push @file_list, \%config_file_hash; 403 404 my $resolved = $ipprc->file_resolve($config_file); 405 406 &my_die("failed to resolve name of config dump file: $config_file_rule", $dist_id, $component, 407 $PS_EXIT_CONFIG_ERROR) if (!$resolved); 408 409 # we don't use the mdc parser because the perl parser is way is too slow for complicated config 410 # files like this 411 my $in = open_with_retries($resolved); 412 413 my $line; 414 while ($line = <$in>) { 415 if ($line =~ /FILES.OUTPUT/) { 416 # print "found FILES.OUTPUT\n"; 417 last; 418 } 419 } 420 &my_die("config dump file does not contain FILES.OUTPUT: $config_file", $dist_id, $component, 421 $PS_EXIT_CONFIG_ERROR) if (!$line); 422 423 while ($line = <$in>) { 424 chomp $line; 425 my ($key, $type, $val) = split " ", $line; 426 # skip blank lines 427 next if !$key; 428 # we're done when we find END 429 last if $key eq "END"; 430 # skip multi and other lines 431 next if ($type ne "STR"); 432 433 # printf "%-32.32s %s\n", $key, $val; 434 435 &my_die("no value found for file rule $key in $resolved", $dist_id, $component, 436 $PS_EXIT_CONFIG_ERROR) if (!$val); 437 438 my %file; 439 $file{file_rule} = $key; 440 $file{name} = $val; 441 push @file_list, \%file; 442 } 443 close $in; 280 444 281 445 return \@file_list; … … 304 468 $command .= " -dist_id $dist_id"; 305 469 $command .= " -component $component"; 306 $command .= " - code$exit_code";470 $command .= " -fault $exit_code"; 307 471 $command .= " -dbname $dbname" if defined $dbname; 308 472 … … 326 490 sub delete_tmpdir 327 491 { 328 if (!$save_temps ) {492 if (!$save_temps and $tmpdir and -e $tmpdir) { 329 493 system "rm -r $tmpdir"; 330 494 } 331 495 } 332 496 333 # list of output data products for runs that were made before the configuration re-work334 sub get_legacy_file_mdc335 {336 my $list =337 "338 #339 # interesting things we might want to save in this file340 # 1. whether file is to be distributed in 'clean' mode341 # 2. whether file is to be cleaned (this should be the same thing)342 # 3. type of file 'no, not our business, precious'343 344 # this data should probably be computed by the relevant program and saved as part345 # of the configuration dump that is output.346 347 348 PROD_LIST MULTI349 350 PROD_LIST METADATA351 STAGE STR RAW352 # there is isn't really a file rule for raw images353 DUMMY BOOL F354 END355 356 # list of data products for a gpc1 chipProcessedImfile (made by ppImage)357 PROD_LIST METADATA358 STAGE STR CHIP359 PPIMAGE.CONFIG BOOL T360 # PPIMAGE.CHIP BOOL F361 # PPIMAGE.CHIP.MASK BOOL F362 # PPIMAGE.CHIP.VARIANCE BOOL F363 PPIMAGE.BIN1 BOOL T364 PPIMAGE.BIN2 BOOL T365 PSPHOT.OUT.CMF.SPL BOOL T366 PSPHOT.BACKMDL BOOL T367 PPIMAGE.STATS BOOL T368 LOG.IMFILE BOOL T369 TRACE.IMFILE BOOL T370 # where do we put exposure level data such as LOG.EXP ?371 END372 # exposure level output products from camera processing made by psastro and ppImage (jpegs)373 PROD_LIST METADATA374 STAGE STR CAM375 PSASTRO.CONFIG BOOL T376 PSASTRO.OUTPUT BOOL T377 PSASTRO.STATS BOOL T378 PPIMAGE.JPEG1 BOOL T379 PPIMAGE.JPEG2 BOOL T380 LOG.EXP BOOL T381 TRACE.EXP BOOL T382 END383 # chip lelel output products from camera processing made by psastro384 PROD_LIST METADATA385 STAGE STR CAM_CHIP386 # PSASTRO.OUTPUT.MASK BOOL F387 END388 PROD_LIST METADATA389 STAGE STR FAKE390 # PPSIM.OUTPUT BOOL F391 END392 # list of data products for a gpc1 warpSkyfile (pswarp)393 PROD_LIST METADATA394 STAGE STR WARP395 PSWARP.CONFIG BOOL T396 # PSWARP.OUTPUT BOOL F397 # PSWARP.OUTPUT.MASK BOOL F398 # PSWARP.OUTPUT.VARIANCE BOOL F399 PSWARP.OUTPUT.SOURCES BOOL T400 PSPHOT.BACKMDL.MEF BOOL T401 PSPHOT.PSF.SKY.SAVE BOOL T402 SKYCELL.STATS BOOL T403 SKYCELL.TEMPLATE BOOL T404 LOG.EXP BOOL T405 TRACE.EXP BOOL T406 END407 # outputs from diffRun (ppSub)408 PROD_LIST METADATA409 STAGE STR DIFF410 PPSUB.CONFIG BOOL T411 # PPSUB.OUTPUT BOOL F412 # PPSUB.OUTPUT.MASK BOOL F413 # PPSUB.OUTPUT.VARIANCE BOOL F414 PPSUB.OUTPUT.KERNELS BOOL T415 PPSUB.OUTPUT.JPEG1 BOOL T416 PPSUB.OUTPUT.JPEG2 BOOL T417 PSPHOT.OUT.CMF.MEF BOOL T418 PSPHOT.BACKMDL.MEF BOOL T419 SKYCELL.STATS BOOL T420 LOG.EXP BOOL T421 TRACE.EXP BOOL T422 END423 PROD_LIST METADATA424 STAGE STR STACK425 PPSTACK.CONFIG BOOL T426 # PPSTACK.OUTPUT BOOL F427 # PPSTACK.OUTPUT.MASK BOOL F428 # PPSTACK.OUTPUT.VARIANCE BOOL F429 PPSTACK.TARGET.PSF BOOL T430 PSPHOT.OUT.CMF.MEF BOOL T431 PSPHOT.BACKMDL.MEF BOOL T432 SKYCELL.STATS BOOL T433 PPSTACK.OUTPUT.JPEG1 BOOL T434 PPSTACK.OUTPUT.JPEG2 BOOL T435 LOG.EXP BOOL T436 TRACE.EXP BOOL T437 END438 ";439 return $list;440 }441 442 443 497 __END__
Note:
See TracChangeset
for help on using the changeset viewer.
