- Timestamp:
- Apr 19, 2013, 3:39:39 PM (13 years ago)
- Location:
- branches/eam_branches/ipp-20130307/pstamp/scripts
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
pstampparse.pl (modified) (34 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20130307/pstamp/scripts
- Property svn:mergeinfo changed
/trunk/pstamp/scripts merged: 35353-35354,35356,35362-35364,35366,35380,35384,35388,35396,35398,35409
- Property svn:mergeinfo changed
-
branches/eam_branches/ipp-20130307/pstamp/scripts/pstampparse.pl
r34447 r35412 27 27 my $outdir; 28 28 my $product; 29 my $label ;29 my $label = ""; 30 30 my $save_temps; 31 31 my $no_update; … … 57 57 die "outdir is required" if !$outdir; 58 58 die "product is required" if !$product; 59 } else { 60 $req_id = 0; 61 $outdir = "nowhere"; 62 $product = "dummy"; 59 63 } 60 64 … … 83 87 $pstamptool .= " -dbserver $dbserver" if $dbserver; 84 88 85 # list_job is a deugging mode 86 $no_update = 1 if $mode eq "list_job"; 89 # If $mode is not queue_job we are using a debugging mode 90 # do not update the database 91 $no_update = 1 if $mode ne "queue_job"; 87 92 88 93 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 89 94 90 95 # 91 # get the datafrom the extension header96 # Read the keywords from the extension header 92 97 # 93 98 my $fields_output; 94 99 { 95 my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION USEREMAIL";100 my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION EMAIL"; 96 101 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 97 102 run(command => $command, verbose => $verbose); 98 # fields doesn't return zero when it succeeds 99 #unless ($success) { 100 # print STDERR @$stderr_buf; 101 #} 103 104 # note fields doesn't return zero when it succeeds. 102 105 $fields_output = join "", @$stdout_buf; 103 106 } 104 my (undef, $extname, $extver, $req_name, $action, $ username, $email) = split " ", $fields_output;107 my (undef, $extname, $extver, $req_name, $action, $email) = split " ", $fields_output; 105 108 106 109 # make sure the file contains what we are expecting 107 # This program shouldn't have been run if the request file is bogus. 108 # No need to notify the client 109 my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST"; 110 my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR) if (!$req_name); 111 my_die("wrong EXTVER $extver found in $request_file_name", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2"); 112 110 # pstamp_parser_run.pl would not have run this program unless the request file was ok 111 my_die("$request_file_name does not contain EXTNAME\n", $PS_EXIT_PROG_ERROR) if !$extname; 112 my_die("$request_file_name is not a PS1_PS_REQUEST\n", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST"; 113 my_die("REQ_NAME not found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if (!$req_name); 114 my_die("wrong EXTVER $extver found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2"); 115 116 if ($extver >= 2) { 117 # We have a version 2 file. Require that the new keywords be supplied. 118 my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless defined $action; 119 120 my_die("invalid action: $action supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW'); 121 122 my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless $email; 123 # XXX check for "valid" $email 124 } else { 125 # for version 1 file the action is process and email is not used 126 $action = 'PROCESS'; 127 $email = 'null'; 128 } 129 130 print "Request Header Keywords EXTVER: $extver REQ_NAME: $req_name ACTION: $action EMAIL: $email\n"; 113 131 114 132 # check for duplicate request name … … 161 179 # the output data store's product name 162 180 my $command = "$pstamptool -updatereq -req_id $req_id -set_name $req_name"; 181 $command .= " -set_username $email" if $email ne 'null'; 163 182 $command .= " -set_outProduct $product"; 164 183 $command .= " -set_label $label" if $label_changed; … … 174 193 175 194 # 176 # now convert the request table to an array of metadata config docs195 # now convert the request table to an array of metadatas 177 196 # 178 197 … … 191 210 my $dtime_request_file = gettimeofday() - $start_request_file; 192 211 print "Time to read and parse request file: $dtime_request_file\n"; 193 194 } 195 196 # 197 # Loop over rows in the request file collecting consecutive rows that have the "same images of interest" 198 # in the sense that their selection parameters will yield the same "Runs". 199 # Process the groups of rows together to reduce lookup time and to potentially make multiple 200 # stamps from the same ppstamp process. 201 # 202 my @rowList; 212 } 213 214 my $nRows = scalar @$rows; 215 print "\n$nRows rows read from request file\n"; 216 217 203 218 my $num_jobs = 0; 204 219 my $imageList; 205 220 my $stage; 206 my $need_magic;207 221 foreach my $row (@$rows) { 208 # santiy check the paramaters 222 223 if ($label eq 'WEB.UP' and ($nRows > 500 or $num_jobs > 500) and $req_id and !$no_update) { 224 # this is a big request and it came from the upload page and doesn't have a specific label assigned 225 # change it to the generic one that has lower with lower priority 226 $label = 'WEB.BIG'; 227 print "\nChanging label for big WEB.UP request to $label\n"; 228 229 my $command = "$pstamptool -updatereq -req_id $req_id -set_label $label"; 230 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 231 run(command => $command, verbose => $verbose); 232 unless ($success) { 233 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 234 } 235 } 236 237 # validate the paramaters 209 238 if (!checkRow($row)) { 210 239 # when it enconters an error checkRow adds a fake job with an appropriate error code to the database … … 216 245 $row->{error_code} = 0; 217 246 218 if (scalar @rowList == 0) { 219 push @rowList, $row; 220 next; 221 } 222 223 my $firstRow = $rowList[0]; 224 if (same_images_of_interest($firstRow, $row)) { 225 # add this row to the list and move on 226 push @rowList, $row; 227 next; 228 } 229 230 # the images of interest for this new row doesn't match the list. 231 # process the list ... 232 $num_jobs += processRows($action, \@rowList); 233 234 # and reset the list to contain just the new row 235 @rowList = ($row); 236 } 237 238 # out of rows process the list 239 if (scalar @rowList > 0) { 240 $num_jobs += processRows($action, \@rowList); 247 $num_jobs += processRow($action, $row); 241 248 } 242 249 … … 252 259 my $row = shift; 253 260 261 # check validity of the paramters in a request specification 254 262 # If we encounter an error for a particular row add a job with the proper fault code. 263 # also adjust some paramterers like filter and set defaults for some others 255 264 256 265 my $stage = $row->{IMG_TYPE}; … … 284 293 } 285 294 286 287 295 my $component = $row->{COMPONENT}; 288 296 if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) { … … 314 322 return 0; 315 323 } 324 325 my $fwhm_min = $row->{FWHM_MIN}; 326 if (!defined $fwhm_min) { 327 $row->{FWHM_MIN} = 0; 328 } elsif (!validNumber($fwhm_min)) { 329 print STDERR "$fwhm_min is not a valid FWHM_MIN\n"; 330 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); 331 return 0; 332 } 333 my $fwhm_max = $row->{FWHM_MAX}; 334 if (!defined $fwhm_max) { 335 $row->{FWHM_MAX} = 0; 336 } elsif (!validNumber($fwhm_max)) { 337 print STDERR "$fwhm_max is not a valid FWHM_MAX\n"; 338 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); 339 return 0; 340 } 341 316 342 my $data_group = $row->{DATA_GROUP}; 317 343 if (!defined $data_group) { … … 363 389 } 364 390 365 # $mode list_uri is a debugging mode (it may used by the http interface)366 # if this happens just croak367 # 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");368 369 370 391 if ($req_type eq "bycoord") { 371 392 if (!$skycenter) { … … 384 405 } 385 406 407 386 408 return 1; 387 409 } … … 392 414 393 415 $num_jobs = 1; 416 return $num_jobs; 417 } 418 419 sub processRow { 420 my $action = shift; 421 my $row = shift; 422 423 my $num_jobs = 0; 424 425 my $project = $row->{PROJECT}; 426 427 # note: resolve_project avoids running pstamptool every time by remembering the 428 # last project resolved 429 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver); 430 if (!$proj_hash) { 431 insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PROJECT); 432 $num_jobs++; 433 return $num_jobs; 434 } 435 my $image_db = $proj_hash->{dbname}; 436 my $camera = $proj_hash->{camera}; 437 438 my $req_type = $row->{REQ_TYPE}; 439 my $rownum = $row->{ROWNUM}; 440 441 # Since user can get unmagicked data "by coordinate" requests can go back in time 442 # to dredge unusable data from the "dark days"... 443 if ($req_type eq 'bycoord' and $row->{IMG_TYPE} ne 'stack' and $row->{MJD_MIN} == 0) { 444 # ... so unless the user sets mjd_min clamp it to 2009-04-01 445 # XXX: This value should live in the pstampProject table not be hardcoded here 446 $row->{MJD_MIN} = 54922; 447 } 448 449 if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) { 450 # avoid error from print below if $id isn't needed 451 $row->{ID} = "" if !$row->{ID}; 452 } 453 454 # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this 455 # request specification. An array reference is returned. 456 my $start_locate = gettimeofday(); 457 458 print "\nCalling new_locate_images for row: $rownum\n"; 459 460 $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose); 461 462 my $dtime_locate = gettimeofday() - $start_locate; 463 print "Time to locate_images for row $rownum $dtime_locate\n"; 464 465 my @rowList = ($row); 466 $num_jobs += queueJobs($action, \@rowList, $imageList); 467 468 # if this row slipped through without a job being added add one. 469 if ($row->{job_num} == 0) { 470 print "row $row->{ROWNUM} produced no jobs\n"; 471 print STDERR "row $row->{ROWNUM} produced no jobs\n"; 472 my $error_code = $row->{error_code}; 473 $error_code = $PSTAMP_NO_IMAGE_MATCH if !$error_code; 474 insertFakeJobForRow($row, ++$row->{job_num}, $error_code); 475 } 476 394 477 return $num_jobs; 395 478 } … … 401 484 402 485 if ($action eq 'LIST') { 486 # LIST is not allowed by caller. Can't get here. 403 487 return list_targets($rowList); 404 488 } … … 420 504 } 421 505 my $req_type = $row->{REQ_TYPE}; 422 $stage= $row->{IMG_TYPE};506 my $stage = $row->{IMG_TYPE}; 423 507 my $id = $row->{ID}; 424 508 my $component = $row->{COMPONENT}; … … 436 520 my $image_db = $proj_hash->{dbname}; 437 521 my $camera = $proj_hash->{camera}; 438 $need_magic = $proj_hash->{need_magic};522 my $need_magic = $proj_hash->{need_magic}; 439 523 # Since user can get unmagicked data "by coordinate" requests can go back in time 440 524 # to dredge unusable data from the "dark days"... … … 496 580 # information required is contained there 497 581 498 $imageList = locate_images($ipprc, $image_db, \@rowList, $req_type, $stage, $id, $tess_id, $component,582 $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component, 499 583 $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose); 500 584 … … 506 590 $row->{need_magic} = $need_magic; 507 591 508 $num_jobs += queueJobs($ mode, \@rowList, $imageList);592 $num_jobs += queueJobs($action, $rowList, $imageList); 509 593 510 594 # if a row slipped through with no jobs add a faulted one 511 foreach my $row (@ rowList) {595 foreach my $row (@$rowList) { 512 596 if ($row->{job_num} == 0) { 513 597 print "row $row->{ROWNUM} produced no jobs\n"; … … 528 612 my $image = shift; 529 613 my $need_magic = shift; 530 my $ mode= shift;614 my $action = shift; 531 615 532 616 my $rownum = $row->{ROWNUM}; … … 611 695 write_params($output_base, $image); 612 696 613 my $newState = "run";697 my $newState = $action eq 'PROCESS' ? "run" : "parsed"; 614 698 my $fault = 0; 615 699 my $dep_id; 616 700 617 queueUpdatesIfNeeded($ stage, $image, $option_mask, \$newState, \$fault, \$dep_id);701 queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id); 618 702 619 703 my $command = "$pstamptool -addjob -req_id $req_id -job_type $row->{JOB_TYPE}" … … 644 728 sub queueJobs 645 729 { 646 my $ mode= shift;730 my $action = shift; 647 731 my $rowList = shift; 648 732 my $imageList = shift; 649 733 650 my $firstRow = $rowList [0];734 my $firstRow = $rowList->[0]; 651 735 my $stage = $firstRow->{IMG_TYPE}; 652 736 my $job_type = $firstRow->{JOB_TYPE}; … … 656 740 657 741 if ($mode eq "list_uri") { 742 $num_jobs = $imageList ? scalar @$imageList : 0; 743 print "List of $num_jobs Images selected for row: $firstRow->{ROWNUM}\n"; 658 744 foreach my $image (@$imageList) { 659 745 print "$image->{image}\n"; 746 ++$firstRow->{job_num}; 660 747 } 661 748 } elsif ($job_type eq "get_image") { … … 664 751 my_die( "error: unexpected number of rows for get_image request: $n", $PS_EXIT_PROG_ERROR) if $n != 1; 665 752 666 $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $ mode);753 $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $action); 667 754 668 755 } else { … … 692 779 my $row = $rowList->[$i]; 693 780 694 $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $ mode);781 $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $action); 695 782 } 696 783 } … … 706 793 my $stage = shift; 707 794 my $need_magic = shift; 708 my $ mode= shift;795 my $action = shift; 709 796 710 797 my $num_jobs = 0; … … 753 840 write_params($output_base, $image); 754 841 755 my $newState = "run";842 my $newState = $action eq 'PROCESS' ? "run" : "parsed"; 756 843 my $fault = 0; 757 844 my $dep_id; 758 845 759 queueUpdatesIfNeeded($ stage, $image, $option_mask, \$newState, \$fault, \$dep_id);846 queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id); 760 847 761 848 $num_jobs++; … … 899 986 sub get_dependent 900 987 { 901 my ($ r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;988 my ($action, $r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_; 902 989 903 990 # chipRun's can be in full state if destreaking is necessary … … 918 1005 my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component -outdir $outdir"; 919 1006 $command .= " -need_magic" if $need_magic; 920 921 # compute rlabel for the run. 922 # XXX: This bit of policy shouldn't be buried so deeply in the code 923 # For now use one that implies 'postage stamp server' 'update' 'request_label" 924 my $rlabel = "ps_ud_" . $label if $label; 925 $command .= " -rlabel $rlabel" if $rlabel; 1007 $command .= ' -hold' if $action eq 'PREVIEW'; 1008 1009 if ($label) { 1010 # compute rlabel for the run. 1011 # XXX: This bit of policy shouldn't be buried so deeply in the code 1012 # For now use one that implies 'postage stamp server' 'update' 'request_label" 1013 my $rlabel = "ps_ud_" . $label; 1014 $command .= " -rlabel $rlabel"; 1015 } 926 1016 927 1017 if (!$no_update) { … … 931 1021 my $fault = $error_code >> 8; 932 1022 print STDERR "$command failed with fault $fault\n"; 933 if ($fault < 10) {1023 if ($fault < $PSTAMP_FIRST_ERROR_CODE) { 934 1024 # pstamptool returns an error if an existing depenent is faulted 935 # Set the object to not available even if the fault < 101025 # Set the object to not available even if the fault < $PSTAMP_FIRST_ERROR_CODE 936 1026 # which is nominally a recoverable error in order to keep 937 1027 # the request from faulting (which can be very expensive if … … 939 1029 $fault = $PSTAMP_NOT_AVAILABLE 940 1030 } 941 if ($fault >= 10) {1031 if ($fault >= $PSTAMP_FIRST_ERROR_CODE) { 942 1032 $$r_dep_id = 0; 943 1033 $$r_fault = $fault; … … 967 1057 968 1058 sub queueUpdatesIfNeeded { 1059 my $action = shift; 969 1060 my $stage = shift; 970 1061 my $image = shift; … … 973 1064 my $r_fault = shift; 974 1065 my $r_dep_id = shift; 1066 1067 my $need_magic = 0; 975 1068 976 1069 if ($stage ne 'raw') { … … 1016 1109 # set up to queue an update run 1017 1110 my $require_magic = ($need_magic or $image->{magicked}); 1018 get_dependent( \$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb},1111 get_dependent($action, \$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb}, 1019 1112 $run_state, $stage, $image->{stage_id}, $image->{component}, $require_magic ); 1020 1113 } … … 1070 1163 my $fault = shift; 1071 1164 1072 carp$msg;1165 print STDERR $msg; 1073 1166 1074 1167 # we don't fault the request here pstamp_parser_run.pl handles that if necessary
Note:
See TracChangeset
for help on using the changeset viewer.
