- Timestamp:
- May 3, 2010, 8:45:22 AM (16 years ago)
- Location:
- branches/simmosaic_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstamp/scripts/pstamp_finish.pl (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simmosaic_branches
- Property svn:mergeinfo changed
-
branches/simmosaic_branches/pstamp/scripts/pstamp_finish.pl
r24831 r27839 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; … … 47 48 48 49 my $ipprc = PS::IPP::Config->new(); # IPP Configuration 49 50 50 if ($redirect_output) { 51 51 my $logDest = "$out_dir/psfinish.$req_id.log"; … … 63 63 my $pstamp_results = can_run('pstamp_results_file.pl') 64 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); 65 66 if ($missing_tools) { 66 67 warn("Can't find required tools."); … … 68 69 } 69 70 71 if ($product eq "NULL") { 72 stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR); 73 } 70 74 71 75 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT'); … … 78 82 my $fileset = $req_name; 79 83 80 81 # Here we invoke the assumption that the output for the request is placed in the82 # fileset directory directly83 # my $out_dir = "$outputDataStoreRoot/$product/$fileset";84 85 # now we are assuming that the output directory is the dirname of the request file86 # XXX: put this in the database87 88 84 print STDERR "product: $product REQ_NAME: $req_name $out_dir\n" if $verbose; 89 85 … … 94 90 if (!mkdir $out_dir) { 95 91 print STDERR "cannot create output directory $out_dir"; 96 stop_request ($req_id, $PS_EXIT_UNKNOWN_ERROR);92 stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR); 97 93 } 98 94 … … 102 98 # request 103 99 print STDERR "output directory $out_dir exists but is not a directory"; 104 stop_request ($req_id, $PS_EXIT_UNKNOWN_ERROR);100 stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR); 105 101 } 106 102 107 103 if (! -e $req_file ) { 108 104 print STDERR "request file $req_file is missing\n"; 109 stop_request ($req_id, $PS_EXIT_CONFIG_ERROR);105 stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR); 110 106 } 111 107 … … 117 113 # point 118 114 print STDERR "failed to read request_file $req_file" ; 119 stop_request ($req_id, $PS_EXIT_CONFIG_ERROR);115 stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR); 120 116 } 121 117 … … 128 124 my ($rlf, $reglist_name) = tempfile ("$out_dir/reglist.XXXX", UNLINK => !$save_temps); 129 125 print $rlf "results.fits|||table|\n"; 126 print $rlf "results.mdc|||text|\n"; 130 127 131 128 my $err_file = "parse_error.txt"; … … 154 151 print STDERR "Request $req_id produced no jobs.\n" 155 152 } 156 # No Jobs. 157 # XXXX Ouch. We need results for each rownum (each request specification) in the request file 158 # including those that produced no jobs. 159 # for now add an entry for rownum 1 and a phony error code. 160 # we've included parse_error.txt to the fileset if it exists 161 # 162 my $rownum = 0; 163 my $fault = 42; # get a real error code 164 print $tdf "$rownum|$fault|0|0|"; 165 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); 166 155 } else { 167 156 my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc"); … … 173 162 } 174 163 164 my $exp_info; 165 my $last_exp_id = -1; 175 166 foreach my $job (@jobs) { 176 167 my $job_id = $job->{job_id}; … … 180 171 my $exp_id = $job->{exp_id}; 181 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 } 182 180 my ($row, $req_info, $project) = get_request_info($rows, $rownum); 183 my $proj_hash = resolve_project($ipprc, $project, $dbname); 181 182 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver); 184 183 my $image_db = $proj_hash->{dbname}; 185 186 # get the metadata for the exposure (if any i.e. stack) 187 # returns an appropriate string if !$exp_id 188 my $exp_info = get_exposure_info($image_db, $exp_id); 189 190 if (($job_type eq "stamp") || ($job_type eq "get_image")) { 184 if (!$image_db) { 185 carp("failed to find imagedb for project: $project"); 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') { 198 # get the metadata for the exposure (if any i.e. stack) 199 # returns an appropriate string if !$exp_id 200 $exp_info = get_exposure_info($image_db, $exp_id); 201 $last_exp_id = $exp_id; 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")) { 191 210 my $jreglist = "$out_dir/reglist$job_id"; 192 211 if (open JRL, "<$jreglist") {; … … 203 222 204 223 # ra_deg and dec_deg are the coordinates of center of the stamp 205 # XXX: parse the stamp header to find it 206 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|"; 207 234 208 235 print $tdf "$exp_info|"; … … 217 244 print $tdf "$exp_info|"; 218 245 print $tdf "$req_info|"; 246 print $tdf "\n"; 219 247 } 220 248 } else { … … 236 264 print STDERR "Unable to perform $command error code: $error_code\n"; 237 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 } 238 275 } 239 276 } … … 241 278 # register the fileset 242 279 my $command = "$dsreg --list $reglist_name --add $fileset --product $product --type PSRESULTS"; 243 $command .= " --link --datapath $out_dir ";280 $command .= " --link --datapath $out_dir --ps0 $req_id"; 244 281 $command .= " --dbname $dbname" if $dbname; 245 282 … … 267 304 } 268 305 269 sub stop_request {306 sub stop_request_and_exit { 270 307 my $req_id = shift; 271 308 my $fault = shift; … … 287 324 my $rownum = shift; 288 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 } 289 330 my $row = $rows->{$rownum}; 331 332 333 # these may be set to null during processing 334 my $component = $row->{COMPONENT}; 335 $component = "null" if !$component; 336 my $tess_id = $row->{TESS_ID}; 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; 290 346 291 347 # This is ugly, error prone and hard to change. 292 348 # Create a results file module and provide a list of the names (we have the data in the columns) 293 349 my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|"; 294 $rowinfo .= "$row->{ID}|$ row->{CLASS_ID}|$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}|"; 295 351 $rowinfo .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|"; 296 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}"; 352 $rowinfo .= "$row->{WIDTH}|$row->{HEIGHT}|"; 353 $rowinfo .= $comment; 297 354 298 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]; 299 384 } 300 385 … … 303 388 my $exp_id = shift; 304 389 305 if (!$exp_id ) {390 if (!$exp_id or !$image_db) { 306 391 # no exposure id just return zeros 307 392 # XXX: we could put a value in for filter, but we don't have a good place to find it … … 347 432 my $ra_deg = $exp->{ra} * RADIANS_TO_DEGREES; 348 433 my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES; 349 my $mjd_obs = dateobs_to_mjd($exp->{dateobs} , $exp->{exp_time});434 my $mjd_obs = dateobs_to_mjd($exp->{dateobs}); 350 435 351 436 my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}"; … … 356 441 sub dateobs_to_mjd { 357 442 my $dateobs = shift; 358 my $exp_time = shift;359 443 360 444 # dateobs is in format: 1970-01-01T00:00:00 … … 366 450 my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900); 367 451 368 $ticks += $exp_time / 2.0;369 370 452 return 40587.0 + ($ticks/86400.); 371 453 }
Note:
See TracChangeset
for help on using the changeset viewer.
