- 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_finish.pl (modified) (21 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/pstamp/scripts/pstamp_finish.pl
r25053 r27840 8 8 use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt ); 9 9 use Pod::Usage qw( pod2usage ); 10 use Carp; 10 11 11 12 use Time::Local; … … 62 63 my $pstamp_results = can_run('pstamp_results_file.pl') 63 64 or (warn "Can't find pstamp_results_file.pl" and $missing_tools = 1); 65 my $pstampdump = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1); 64 66 if ($missing_tools) { 65 67 warn("Can't find required tools."); … … 67 69 } 68 70 71 if ($product eq "NULL") { 72 stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR); 73 } 69 74 70 75 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT'); … … 77 82 my $fileset = $req_name; 78 83 79 80 # Here we invoke the assumption that the output for the request is placed in the81 # fileset directory directly82 # my $out_dir = "$outputDataStoreRoot/$product/$fileset";83 84 # now we are assuming that the output directory is the dirname of the request file85 # XXX: put this in the database86 87 84 print STDERR "product: $product REQ_NAME: $req_name $out_dir\n" if $verbose; 88 85 … … 93 90 if (!mkdir $out_dir) { 94 91 print STDERR "cannot create output directory $out_dir"; 95 stop_request ($req_id, $PS_EXIT_UNKNOWN_ERROR);92 stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR); 96 93 } 97 94 … … 101 98 # request 102 99 print STDERR "output directory $out_dir exists but is not a directory"; 103 stop_request ($req_id, $PS_EXIT_UNKNOWN_ERROR);100 stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR); 104 101 } 105 102 106 103 if (! -e $req_file ) { 107 104 print STDERR "request file $req_file is missing\n"; 108 stop_request ($req_id, $PS_EXIT_CONFIG_ERROR);105 stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR); 109 106 } 110 107 … … 116 113 # point 117 114 print STDERR "failed to read request_file $req_file" ; 118 stop_request ($req_id, $PS_EXIT_CONFIG_ERROR);115 stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR); 119 116 } 120 117 … … 127 124 my ($rlf, $reglist_name) = tempfile ("$out_dir/reglist.XXXX", UNLINK => !$save_temps); 128 125 print $rlf "results.fits|||table|\n"; 126 print $rlf "results.mdc|||text|\n"; 129 127 130 128 my $err_file = "parse_error.txt"; … … 153 151 print STDERR "Request $req_id produced no jobs.\n" 154 152 } 155 # No Jobs. 156 # XXXX Ouch. We need results for each rownum (each request specification) in the request file 157 # including those that produced no jobs. 158 # for now add an entry for rownum 1 and a phony error code. 159 # we've included parse_error.txt to the fileset if it exists 160 # 161 my $rownum = 0; 162 my $fault = 42; # get a real error code 163 print $tdf "$rownum|$fault|0|0|"; 164 print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n"; 153 # This should not happen. A fake job should be queued 154 stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR); 165 155 } else { 166 156 my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc"); … … 181 171 my $exp_id = $job->{exp_id}; 182 172 173 174 if (($fault eq $PSTAMP_DUP_REQUEST) and ($req_name eq "NULL")) { 175 # this request had a duplicate request name. We can't put the results 176 # on the data store since the product name is already used 177 # maybe we could be more clever about this and choose a fileset name 178 stop_request_and_exit($req_id, $fault); 179 } 183 180 my ($row, $req_info, $project) = get_request_info($rows, $rownum); 184 181 … … 187 184 if (!$image_db) { 188 185 carp("failed to find imagedb for project: $project"); 189 stop_request($req_id, $PS_EXIT_CONFIG_ERROR); 190 } 191 192 if ($exp_id ne $last_exp_id) { 186 if (!$fault) { 187 stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR); 188 } 189 } 190 191 my $job_params = get_job_parameters($job); 192 my $stage = ""; 193 if ($job_params) { 194 $stage = $job_params->{stage}; 195 } 196 197 if ($stage ne 'stack') { 193 198 # get the metadata for the exposure (if any i.e. stack) 194 199 # returns an appropriate string if !$exp_id 195 200 $exp_info = get_exposure_info($image_db, $exp_id); 196 201 $last_exp_id = $exp_id; 197 } 198 199 if (($job_type eq "stamp") || ($job_type eq "get_image")) { 202 } else { 203 my $filter = $job_params->{filter}; 204 $filter = "0" if !$filter; 205 $exp_info = "0|0|0|$filter|0|0"; 206 $last_exp_id = -1; 207 } 208 209 if (($job_type eq "stamp") || ($job_type eq "get_image") || ($job_type eq "none")) { 200 210 my $jreglist = "$out_dir/reglist$job_id"; 201 211 if (open JRL, "<$jreglist") {; … … 212 222 213 223 # ra_deg and dec_deg are the coordinates of center of the stamp 214 # XXX: parse the stamp header to find it 215 print $tdf "0.0|0.0|"; 224 # first assume that the image is compressed and check the first extension. 225 # If not found check the PHU. If that doesn't work just set them to zero. 226 # XXX do this more cleanly 227 my (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields -x 0 RA_DEG DEC_DEG`; 228 if (!defined $ra_deg) { 229 (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields RA_DEG DEC_DEG`; 230 } 231 $ra_deg = 0.0 if (!$ra_deg); 232 $dec_deg = 0.0 if (!$dec_deg); 233 print $tdf "$ra_deg|$dec_deg|"; 216 234 217 235 print $tdf "$exp_info|"; … … 246 264 print STDERR "Unable to perform $command error code: $error_code\n"; 247 265 $request_fault = $error_code >> 8; 266 } else { 267 # dump a textual representation 268 my $command = "$pstampdump $out_dir/results.fits > $out_dir/results.mdc"; 269 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 270 run(command => $command, verbose => $verbose); 271 unless ($success) { 272 print STDERR "Unable to perform $command error code: $error_code\n"; 273 $request_fault = $error_code >> 8; 274 } 248 275 } 249 276 } … … 251 278 # register the fileset 252 279 my $command = "$dsreg --list $reglist_name --add $fileset --product $product --type PSRESULTS"; 253 $command .= " --link --datapath $out_dir ";280 $command .= " --link --datapath $out_dir --ps0 $req_id"; 254 281 $command .= " --dbname $dbname" if $dbname; 255 282 … … 277 304 } 278 305 279 sub stop_request {306 sub stop_request_and_exit { 280 307 my $req_id = shift; 281 308 my $fault = shift; … … 297 324 my $rownum = shift; 298 325 326 if ($rownum eq 0) { 327 my $dummy_rowinfo = "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|"; 328 return (undef, $dummy_rowinfo, "none"); 329 } 299 330 my $row = $rows->{$rownum}; 331 300 332 301 333 # these may be set to null during processing … … 304 336 my $tess_id = $row->{TESS_ID}; 305 337 $tess_id = "null" if !$tess_id; 338 my $comment = $row->{COMMENT}; 339 $comment = "null" if !$comment; 340 my $data_group = $row->{DATA_GROUP}; 341 if (!defined $data_group) { 342 # XXX: backwards compatibility hook. Remove "soon". 343 $data_group = $row->{LABEL}; 344 } 345 $data_group = "null" if !$data_group; 306 346 307 347 # This is ugly, error prone and hard to change. 308 348 # Create a results file module and provide a list of the names (we have the data in the columns) 309 349 my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|"; 310 $rowinfo .= "$row->{ID}|$tess_id|$component|$ row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";350 $rowinfo .= "$row->{ID}|$tess_id|$component|$data_group|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|"; 311 351 $rowinfo .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|"; 312 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}"; 352 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}|"; 353 $rowinfo .= $comment; 313 354 314 355 return ($row, $rowinfo, $row->{PROJECT}); 356 } 357 358 sub get_job_parameters { 359 my $job = shift; 360 if (!$job->{outputBase}) { 361 print "get_job_parameters: $job->{job_id} has no outputBase\n"; 362 return undef; 363 } 364 my $params_file = $job->{outputBase} . '.mdc'; 365 if (! -e $params_file ) { 366 print "get_job_parameters: $job->{job_id} has no parameters file\n"; 367 return undef; 368 } 369 open IN, "<$params_file" or die "unable to open $params_file"; 370 my $data = join "", (<IN>); 371 close IN; 372 if (! $data ) { 373 print "get_job_parameters: parameters file is empty\n"; 374 return undef; 375 } 376 my $metadata = $mdcParser->parse($data) or die("Unable to parse metdata config doc"); 377 378 my $results = parse_md_list($metadata); 379 if (scalar @$results != 1) { 380 print STDERR "get_job_params: failed to parse_md_list\n"; 381 return undef; 382 } 383 return $results->[0]; 315 384 } 316 385 … … 319 388 my $exp_id = shift; 320 389 321 if (!$exp_id ) {390 if (!$exp_id or !$image_db) { 322 391 # no exposure id just return zeros 323 392 # XXX: we could put a value in for filter, but we don't have a good place to find it … … 363 432 my $ra_deg = $exp->{ra} * RADIANS_TO_DEGREES; 364 433 my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES; 365 my $mjd_obs = dateobs_to_mjd($exp->{dateobs} , $exp->{exp_time});434 my $mjd_obs = dateobs_to_mjd($exp->{dateobs}); 366 435 367 436 my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}"; … … 372 441 sub dateobs_to_mjd { 373 442 my $dateobs = shift; 374 my $exp_time = shift;375 443 376 444 # dateobs is in format: 1970-01-01T00:00:00 … … 382 450 my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900); 383 451 384 $ticks += $exp_time / 2.0;385 386 452 return 40587.0 + ($ticks/86400.); 387 453 }
Note:
See TracChangeset
for help on using the changeset viewer.
