- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_job_run.pl (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/pstamp/scripts/pstamp_job_run.pl
r24963 r27840 11 11 use Sys::Hostname; 12 12 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 13 use Carp; 13 14 use File::Basename; 15 use File::Copy; 14 16 use Digest::MD5::File qw( file_md5_hex ); 15 17 use PS::IPP::PStamp::RequestFile qw( :standard ); 16 18 use IPC::Cmd 0.36 qw( can_run run ); 19 use POSIX; 17 20 18 21 use PS::IPP::Metadata::Config; 19 22 #use PS::IPP::Metadata::Stats; 20 #use PS::IPP::Metadata::List qw( parse_md_list );23 use PS::IPP::Metadata::List qw( parse_md_list ); 21 24 22 25 use PS::IPP::Config qw( :standard ); 23 26 24 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType );27 my ($job_id, $redirect_output, $outputBase, $rownum, $jobType, $options); 25 28 my ($verbose, $dbname, $dbserver, $no_update); 26 29 … … 30 33 'rownum=s' => \$rownum, 31 34 'output_base=s' => \$outputBase, 35 'options=s' => \$options, 32 36 'redirect-output' => \$redirect_output, 33 37 'dbname=s' => \$dbname, … … 49 53 my_die("rownum is required", $job_id, $PS_EXIT_PROG_ERROR) if !$rownum; 50 54 my_die("output_base is required", $job_id, $PS_EXIT_PROG_ERROR) if !$outputBase; 55 56 $options = 1 if !$options; 51 57 52 58 … … 92 98 run(command => $command, verbose => $verbose); 93 99 94 if ($success) { 100 my $exitStatus; 101 if (WIFEXITED($error_code)) { 102 $exitStatus = WEXITSTATUS($error_code); 103 } else { 104 print STDERR "ppstamp failed error_code: $error_code\n"; 105 $exitStatus = $PS_EXIT_SYS_ERROR; 106 } 107 108 if ($exitStatus == 0) { 95 109 my $dir = dirname($outputBase); 96 110 97 111 my $reglist = "$dir/reglist$job_id"; 98 112 99 open F, ">$reglist" or my_die( "can't open $reglist for output", $job_id, $PS_EXIT_UNKNOWN_ERROR); 113 my $F; 114 open $F, ">$reglist" or my_die( "can't open $reglist for output", $job_id, $PS_EXIT_UNKNOWN_ERROR); 100 115 101 116 # Figure out what output images were produced … … 106 121 $PSTAMP_SELECT_WEIGHT => "wt.fits"); 107 122 108 # we always create a stamp of the image 109 my $output_mask = $PSTAMP_SELECT_IMAGE; 110 111 # we search the argString for -mask and -variance. 112 # searching the arg string allows us to avoid adding a column in pstampJob 113 $output_mask |= $PSTAMP_SELECT_MASK if ($argString =~ /-mask/); 114 $output_mask |= $PSTAMP_SELECT_WEIGHT if ($argString =~ /-variance/); 123 my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_WEIGHT); 115 124 116 125 foreach my $key (keys (%extensions)) { … … 127 136 128 137 # XXX is pstamp always the right file type, if not where do we get the right one? 129 print F file_registration_line($filename, $path, "pstamp") . "\n"; 130 } 131 132 close F; 138 print $F file_registration_line($filename, $path, "pstamp") . "\n"; 139 } 140 141 get_other_outputs($F, $outputBase, $options); 142 143 close $F; 133 144 $jobStatus = $PS_EXIT_SUCCESS; 134 } else { 135 $jobStatus = $error_code >> 8; 136 my_die( "ppstamp failed with error code: $jobStatus", $job_id, $jobStatus); 145 } elsif ($exitStatus == $PSTAMP_NO_OVERLAP) { 146 $jobStatus = $PSTAMP_NO_OVERLAP; 147 } else { 148 my_die( "ppstamp failed with error code: $exitStatus", $job_id, $exitStatus); 137 149 } 138 150 } elsif ($jobType eq "get_image") { 139 my_die( "get_image jobs not working right now", $job_id, $PS_EXIT_CONFIG_ERROR);140 151 141 152 my $uri = ""; 142 my $command = "$pstamp_get_image_job --job_id $job_id -- uri $uri --out_dir$outputBase --rownum $rownum";153 my $command = "$pstamp_get_image_job --job_id $job_id --output_base $outputBase --rownum $rownum"; 143 154 $command .= " --dbname $dbname" if $dbname; 144 155 $command .= " --dbserver $dbserver" if $dbserver; 156 $command .= " --verbose" if $verbose; 145 157 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 146 158 run(command => $command, verbose => $verbose); … … 161 173 { 162 174 my $command = "$pstamptool -updatejob -job_id $job_id -state stop"; 175 $command .= " -fault $jobStatus" if $jobStatus; 163 176 $command .= " -dbname $dbname" if $dbname; 164 177 $command .= " -dbserver $dbserver" if $dbserver; … … 194 207 } 195 208 } 209 210 sub get_other_outputs { 211 my $f = shift; 212 my $output_base = shift; 213 my $options = shift; 214 215 if ($options & ( $PSTAMP_SELECT_CMF | $PSTAMP_SELECT_PSF | $PSTAMP_SELECT_BACKMDL)) { 216 my $comp = read_params_file($output_base); 217 218 my $stage = $comp->{stage}; 219 220 # raw files don't have any other data products 221 return 1 if $stage eq "raw"; 222 223 # add the other data products if they are selected and exist. 224 # silently skip them if they don't exist. Perhaps this should be 225 # detected in pstampparse so that the user can be notified with 226 # a message in parse_error.txt ("warp do not have a background model") 227 my $cmf_file = $comp->{cmf} if ($options & $PSTAMP_SELECT_CMF); 228 my $psf_file = $comp->{psf} if ($options & $PSTAMP_SELECT_PSF); 229 my $backmdl_file = $comp->{backmdl} if ($options & $PSTAMP_SELECT_BACKMDL); 230 my $pattern_file = $comp->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL); 231 232 my $outdir = dirname($output_base); 233 my $basename = basename($output_base); 234 my ($rownum, $jobnum, $therest) = split /_/, $basename; 235 &my_die("failed to split basename: $basename", $job_id, $PS_EXIT_CONFIG_ERROR) 236 if (!$therest or !$rownum or !$jobnum); 237 238 my $prefix = "${rownum}_${jobnum}_"; 239 240 if ($cmf_file) { 241 print "cmf file is $cmf_file\n"; 242 copy_and_register_file($f, $cmf_file, $outdir, $prefix); 243 } 244 if ($psf_file) { 245 print "psf_file is $psf_file\n"; 246 copy_and_register_file($f, $psf_file, $outdir, $prefix); 247 } 248 if ($backmdl_file) { 249 print "backmdl_file is $backmdl_file\n";; 250 copy_and_register_file($f, $backmdl_file, $outdir, $prefix); 251 } 252 if (0) { 253 # don't enable this yet 254 if ($pattern_file) { 255 print "pattern_file is $pattern_file\n";; 256 copy_and_register_file($f, $pattern_file, $outdir, $prefix); 257 } 258 } 259 } 260 } 261 262 sub read_params_file { 263 my $output_base = shift; 264 265 my $params_file = $output_base . ".mdc"; 266 open (IN, "<$params_file") 267 or my_die("failed to open params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR); 268 269 my $data = $mdcParser->parse(join "", (<IN>)) 270 or my_die("failed to parse params file: $params_file", $job_id, $PS_EXIT_UNKNOWN_ERROR); 271 272 my $components = parse_md_list($data); 273 274 my $n = scalar @$components; 275 if ($n != 1) { 276 my_die("params file $params_file contains unexpected number of components: $n", 277 $job_id, $PS_EXIT_PROG_ERROR); 278 } 279 return $components->[0]; 280 } 281 282 # copy_and_register_file ($f, $src, $destdir, $prefix); 283 sub copy_and_register_file { 284 my $F = shift; 285 my $src = shift; 286 my $destdir = shift; 287 my $prefix = shift; 288 289 my $fn = $prefix . basename($src); 290 my $dst = "$destdir/$fn"; 291 292 my $resolved = $ipprc->file_resolve($src); 293 294 my_die("failed to resolve $src", $job_id, $PS_EXIT_UNKNOWN_ERROR) if !$resolved; 295 296 if (!-e $resolved) { 297 print STDERR "$src does not exist, skipping\n"; 298 return; 299 } 300 301 302 copy($resolved, $dst) or my_die("failed to copy $resolved to $dst", $job_id, $PS_EXIT_UNKNOWN_ERROR); 303 304 print $F file_registration_line($fn, $dst, "fits") . "\n"; 305 } 196 306 197 307 sub my_die … … 201 311 my $exit_code = shift; # Exit code to add 202 312 203 $exit_code = $PS_EXIT_PROG_ERROR unless defined$exit_code;313 $exit_code = $PS_EXIT_PROG_ERROR unless $exit_code; 204 314 205 315 carp($msg); … … 208 318 $command .= " -job_id $job_id"; 209 319 $command .= " -fault $exit_code"; 320 # XXX: fix pstamptool to not require -state when -fault with nonzero value is provided 321 $command .= " -state run"; 210 322 $command .= " -dbname $dbname" if defined $dbname; 211 323 $command .= " -dbserver $dbserver" if defined $dbserver;
Note:
See TracChangeset
for help on using the changeset viewer.
