Changeset 25058
- Timestamp:
- Aug 12, 2009, 3:08:50 PM (17 years ago)
- Location:
- trunk/pstamp/scripts
- Files:
-
- 2 edited
-
pstamp_parser_run.pl (modified) (1 diff)
-
pstampparse.pl (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/scripts/pstamp_parser_run.pl
r24961 r25058 200 200 unlink $error_file_name if (-e $error_file_name); 201 201 202 # Run the parser 203 202 204 my $command = "$parse_cmd"; 203 205 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = -
trunk/pstamp/scripts/pstampparse.pl
r25052 r25058 91 91 # make sure the file contains what we are expecting 92 92 93 die "$request_file_name is not a PS1_PS_REQEST" if $extname ne "PS1_PS_REQUEST"; 94 die "REQ_NAME not found in $request_file_name" if (!$req_name); 95 die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1"); 93 # we shouldn't get here if this is the case so just die. No need to notify the client 94 my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST"; 95 my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR) if (!$req_name); 96 my_die("wrong EXTVER $extver found in $request_file_name", $PS_EXIT_PROG_ERROR) if ($extver ne "1"); 96 97 97 98 if ($req_id and !$no_update) { 99 # update the database with the request name. This will be used as the 100 # the output data store's product name 98 101 my $command = "$pstamptool -updatereq -req_id $req_id -name $req_name"; 99 102 $command .= " -outProduct $product"; … … 103 106 run(command => $command, verbose => $verbose); 104 107 unless ($success) { 105 die "$command failed";108 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 106 109 } 107 110 } … … 120 123 } 121 124 my $table = $mdcParser->parse(join "", @$stdout_buf) or 122 die("Unable to parse metdata config doc");125 my_die("Unable to parse metdata config doc", $PS_EXIT_UNKNOWN_ERROR); 123 126 124 127 $rows = parse_md_list($table); … … 154 157 my $option_mask= $row->{OPTION_MASK}; 155 158 156 die "valid region of interest is required to make postage stamps"157 if (($job_type eq "stamp") and ! validROI($row));158 159 159 my $skycenter = $row->{skycenter} = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS); 160 $component = "" if (defined($component) and ($component eq "null" or $component eq "all")); 160 161 my $search_component = (!defined($component) or ($component eq "null")) ? "" : $component; 161 162 162 die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri"); 163 if (!$skycenter and !$search_component) { 164 print STDERR "COMPONENT must be specified for pixel coordinate ROI\n" if $verbose; 165 insertFakeJobForRow($row, 1, 45); 166 $num_jobs++; 167 next; 168 } 169 170 $search_component = "" if $search_component eq "all"; 171 172 if (($job_type eq "stamp") and ! validROI($row)) { 173 print STDERR "invalid ROI for row $rownum\n" if $verbose; 174 insertFakeJobForRow($row, 1, 46); 175 $num_jobs++; 176 next; 177 } 178 179 180 # $mode list_uri is a debugging mode (it may used by the http interface) 181 # if this happens just croak 182 my_die("job_type is list_uri but mode is $mode", $PS_EXIT_PROG_ERROR) if ($job_type eq "list_uri") and ($mode ne "list_uri"); 163 183 164 184 # note: resolve_project avoids running pstamptool every time by remembering the 165 185 # last project resolved 166 186 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver); 167 die "project $project not found\n" unless $proj_hash; 187 if (!$proj_hash) { 188 print STDERR "project $project not found\n" if $verbose; 189 insertFakeJobForRow($row, 1, 46); 190 $num_jobs++; 191 next; 192 } 168 193 169 194 my $image_db = $proj_hash->{dbname}; … … 175 200 if (@rowList) { 176 201 my $firstRow = $rowList[0]; 177 # XXX: the collecting might work with !$skycenter but I need to think about it 178 if ( $skycenter andsame_images_of_interest($row, $firstRow)) {202 # if ($skycenter and same_images_of_interest($row, $firstRow)) { 203 if (same_images_of_interest($row, $firstRow)) { 179 204 push @rowList, $row; 180 205 # On to the next row … … 188 213 189 214 if ($req_type eq "bycoord") { 190 die "center must be specified in sky coordintes for bycoord" if ( ! $skycenter); 191 die "lookup bycoord is not yet implemented"; 215 if (!$skycenter) { 216 print STDERR "center must be specified in sky coordintes for bycoord" if $verbose; 217 insertFakeJobForRow($row, 1, 46); 218 $num_jobs++; 219 next; 220 } 221 print STDERR "lookup bycoord is not yet implemented" if $verbose; 222 insertFakeJobForRow($row, 1, 47); 223 $num_jobs++; 224 next; 192 225 } else { 193 194 # Call PS::IPP::PStamp::Job's locate_images routine to get the parameters for this 195 # request specification. An array reference is returned 196 my ($x, $y); 197 $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $component, $skycenter, 198 $x, $y, $mjd_min, $mjd_max, $filter, $verbose); 199 } 200 201 if (!$imageList or !@$imageList) { 202 print STDERR "no matching images found for row $rownum\n"; 203 } 204 $row->{need_magic} = $need_magic; 205 push @rowList, $row; 206 } 207 208 if (@rowList) { 209 $num_jobs += queueJobs($mode, \@rowList, $imageList); 210 } 211 212 if ($mode eq "queue_jobs") { 213 if ($num_jobs) { 214 exit 0; 215 } else { 216 # no jobs queued return error to get the request stopped 217 # TODO: need to define meaningful error codes 218 exit $PS_EXIT_UNKNOWN_ERROR; 219 } 220 } else { 221 exit 0; 222 } 226 # Call PS::IPP::PStamp::Job's locate_images subroutine to get the parameters for this 227 # request specification. An array reference is returned. 228 my ($x, $y); 229 $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $search_component, 230 $skycenter, $x, $y, $mjd_min, $mjd_max, $filter, $verbose); 231 } 232 233 if (!$imageList or !@$imageList) { 234 print STDERR "no matching images found for row $rownum\n" if $verbose; 235 # note in this case queueJobs inserts the fake job for these rows 236 } 237 $row->{need_magic} = $need_magic; 238 push @rowList, $row; 239 } 240 241 if (@rowList) { 242 $num_jobs += queueJobs($mode, \@rowList, $imageList); 243 } 244 245 if (($mode eq "queue_jobs") and ($num_jobs eq 0)) { 246 print STDERR "no jobs created for $req_name\n" if $verbose; 247 insertFakeJobForRow(undef, 1, 41); 248 } 249 exit 0; 223 250 224 251 … … 230 257 my $have_skycells = shift; 231 258 my $need_magic = shift; 259 260 my $rownum = $row->{ROWNUM}; 261 262 my $components = $row->{components}; 263 my $numComponents = scalar keys %$components; 264 if ( $numComponents == 0 ) { 265 print STDERR "no jobs for row $rownum\n" if $verbose; 266 insertFakeJobForRow($row, 1, 44); 267 return 1; 268 } 269 270 my $roi_string; 271 272 # note values were insured to be numbers in validROI() 273 my $x = $row->{CENTER_X}; 274 my $y = $row->{CENTER_Y}; 275 my $w = $row->{WIDTH}; 276 my $h = $row->{HEIGHT}; 277 my $coord_mask = $row->{COORD_MASK}; 278 if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) { 279 if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) { 280 $roi_string = "-pixcenter $x $y"; 281 } else { 282 $roi_string = "-skycenter $x $y"; 283 } 284 if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) { 285 $roi_string .= " -pixrange $w $h"; 286 } else { 287 $roi_string .= " -arcrange $w $h"; 288 } 289 } 232 290 233 291 # loop over images … … 242 300 243 301 # skip this component if it is not in the list for this row 244 next if !$row->{components}->{$component}; 245 246 my $rownum = $row->{ROWNUM}; 247 248 my $roi_string; 249 250 # note values were insured to be numbers in validROI() 251 my $x = $row->{CENTER_X}; 252 my $y = $row->{CENTER_Y}; 253 my $w = $row->{WIDTH}; 254 my $h = $row->{HEIGHT}; 255 my $coord_mask = $row->{COORD_MASK}; 256 if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) { 257 if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) { 258 $roi_string = "-pixcenter $x $y"; 259 } else { 260 $roi_string = "-skycenter $x $y"; 261 } 262 if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) { 263 $roi_string .= " -pixrange $w $h"; 264 } else { 265 $roi_string .= " -arcrange $w $h"; 266 } 267 } 302 next if ! $components->{$component}; 268 303 269 304 $job_num++; … … 271 306 my $imagefile = $image->{image}; 272 307 if (($stage ne "stack") and ($need_magic and !$image->{magicked})) { 273 # XXX: should we add a faulted job so the client can know what happened? 274 # print STDERR "skippping non-magicked image $imagefile\n" if $verbose; 308 # XXX: should we add a faulted job so the client can know what happened if no images come back? 309 print STDERR "skippping non-magicked image $imagefile\n" if $verbose; 310 311 # for now assume yes. 275 312 276 313 insertFakeJobForRow($row, $job_num, 43); … … 303 340 304 341 # copy the argument list to a file 305 open ARGSLIST, ">$argslist" or die "failed to open $argslist";342 open ARGSLIST, ">$argslist" or my_die("failed to open $argslist", $PS_EXIT_UNKNOWN_ERROR); 306 343 print ARGSLIST "$args\n"; 307 close ARGSLIST or die "failed to close $argslist"; 308 309 # XXX: TODO: here is where we need to check whether or not the source inputs still exist 310 # and if not, queue an update job and set the job state appropriately. 344 close ARGSLIST or my_die("failed to close $argslist", $PS_EXIT_UNKNOWN_ERROR); 311 345 312 346 my $newState = "run"; 347 my $fault = 0; 348 if ($image->{data_state} ne "full") { 349 # XXX here is where we need to queue an update job 350 # for now just say that the image is not available 351 $newState = 'stop'; 352 $fault = 49; 353 } 313 354 314 355 $num_jobs++; 315 356 my $command = "$pstamptool -addjob -req_id $req_id -job_type $row->{JOB_TYPE}" 316 357 . " -outputBase $output_base -rownum $rownum -state $newState"; 358 $command .= " -fault $fault" if $fault; 317 359 $command .= " -exp_id $exp_id" if $exp_id; 318 360 $command .= " -dbname $dbname" if $dbname; … … 332 374 # should we keep going for other uris? If so how do we report that some 333 375 # of the work that the request wanted isn't going to get done 334 die "failed to queue job for request $req_id";376 my_die("failed to queue job for request $req_id", $PS_EXIT_UNKNOWN_ERROR); 335 377 } 336 378 } else { … … 341 383 } 342 384 385 # queue jobs for a collection of request specifications that have the same Images of Interest 343 386 sub queueJobs 344 387 { … … 359 402 } 360 403 } elsif ($job_type eq "get_image") { 361 die "get_image jobs not implemented yet"; 404 print STDERR "get_image jobs not implemented yet" if $verbose; 405 foreach my $row (@$rowList) { 406 insertFakeJobForRow($row, 1, 47); 407 $num_jobs++; 408 } 362 409 } else { 363 410 if (!$imageList or (scalar @$imageList eq 0)) { … … 370 417 return $num_jobs; 371 418 } 372 my $thisRun;373 374 my ($pointsList, $pointsListName) = tempfile ("/tmp/pointsList.XXXX", UNLINK => !$save_temps);375 foreach my $row (@$rowList) {376 print $pointsList "$row->{ROWNUM} $row->{CENTER_X} $row->{CENTER_Y}\n";377 $row->{components} = {};378 }379 close $pointsList;380 419 381 420 my $have_skycells; … … 386 425 } 387 426 427 my $thisRun; 428 429 my ($pointsList, $pointsListName) = tempfile ("/tmp/pointsList.XXXX", UNLINK => !$save_temps); 430 my $npoints = 0; 431 foreach my $row (@$rowList) { 432 $row->{components} = {}; 433 if ($row->{skycenter}) { 434 print $pointsList "$row->{ROWNUM} $row->{CENTER_X} $row->{CENTER_Y}\n"; 435 $npoints++; 436 } else { 437 # this row's center is in pixel coordinates add all images to the component list for this row 438 foreach my $i (@$imageList) { 439 my $component = $have_skycells ? $i->{skycell_id} : $i->{class_id}; 440 my_die( "image found with no value for component", $PS_EXIT_UNKNOWN_ERROR) if !$component; 441 $row->{components}->{$component} = 1; 442 } 443 } 444 } 445 close $pointsList; 446 388 447 my $tess_dir_abs; 389 448 my $last_tess_id = ""; 390 449 while ($thisRun = getOneRun($stage, $imageList)) { 391 { 450 if ($npoints) { 451 # we collected a set of sky coordintates above filter the images so that only 452 # those tat contain the centers are processed 392 453 my $command = "$dvoImagesAtCoords $pointsListName"; 393 454 if ($have_skycells) { … … 401 462 } else { 402 463 my $astrom = $thisRun->[0]->{astrom}; 403 die "no astrometry file found"if !$astrom;464 my_die( "no astrometry file found", $PS_EXIT_UNKNOWN_ERROR) if !$astrom; 404 465 my $astrom_resolved = $ipprc->file_resolve($astrom); 405 466 $command .= " -astrom $astrom_resolved"; … … 410 471 print STDERR @$stderr_buf; 411 472 my $rc = $error_code >> 8; 412 die "dvoImagesAtCoords failed: $rc";473 my_die( "dvoImagesAtCoords failed: $rc", $PS_EXIT_UNKNOWN_ERROR); 413 474 } 414 475 # now we have a list of row numbers and components … … 457 518 # should we keep going for other uris? If so how do we report that some 458 519 # of the work that the request wanted isn't going to get done 459 die "failed to queue job for request $req_id";520 my_die("failed to queue job for request $req_id", $PS_EXIT_UNKNOWN_ERROR); 460 521 } 461 522 } else { … … 480 541 return $image->{diff_id}; 481 542 } else { 482 die "unenexpected stage: $stage found";543 my_die("unenexpected stage: $stage found", $PS_EXIT_PROG_ERROR); 483 544 } 484 545 } … … 554 615 return undef; 555 616 } 617 618 sub my_die 619 { 620 my $msg = shift; 621 my $fault = shift; 622 623 carp $msg; 624 625 # we don't fault the request here pstamp_parser_run.pl handles that if necessary 626 627 return $fault; 628 }
Note:
See TracChangeset
for help on using the changeset viewer.
