- Timestamp:
- Apr 21, 2014, 5:42:34 AM (12 years ago)
- Location:
- branches/eam_branches/ps2-tc3-20130727
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
pstamp/scripts (modified) (1 prop)
-
pstamp/scripts/pstampparse.pl (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ps2-tc3-20130727
- Property svn:mergeinfo changed
-
branches/eam_branches/ps2-tc3-20130727/pstamp/scripts
- Property svn:mergeinfo deleted
-
branches/eam_branches/ps2-tc3-20130727/pstamp/scripts/pstampparse.pl
r35828 r36680 31 31 my $no_update; 32 32 my $dest_requires_magic; 33 my $dump_params = 0; 33 34 34 35 # set this to true to disable update processing … … 48 49 'save-temps'=> \$save_temps, 49 50 'no-update' => \$no_update, 51 'dump-params' => \$dump_params, 50 52 ); 51 53 52 54 die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "queue_job"); 53 die "--file is required" if !defined($request_file_name);55 die "--file is required" unless defined($request_file_name); 54 56 55 57 if ($mode ne "list_uri") { 56 die "req_id is required" if !$req_id;58 die "req_id is required" if !$req_id; 57 59 die "outdir is required" if !$outdir; 58 die "product is required" if !$product;60 die "product is required" if !$product; 59 61 } else { 60 $req_id = 0; 61 $outdir = "nowhere"; 62 # mode eq 'list_uri' (used for parser testing) 63 # these values won't be used for anything but should be defined to avoid errors 64 $req_id = 0; 65 $outdir = "nowhere"; 62 66 $product = "dummy"; 63 67 } … … 76 80 my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools = 1); 77 81 my $pstampdump = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1); 78 my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);82 my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1); 79 83 80 84 if ($missing_tools) { … … 116 120 if ($extver >= 2) { 117 121 # 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; 122 my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) 123 unless defined $action; 124 125 my_die("invalid action: $action supplied in version $extver request file $request_file_name\n", 126 $PSTAMP_INVALID_REQUEST) 127 unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW'); 128 129 my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) 130 unless $email; 131 123 132 # XXX check for "valid" $email 124 133 } else { 125 134 # for version 1 file the action is process and email is not used 126 135 $action = 'PROCESS'; 127 $email = 'null';136 $email = 'null'; 128 137 } 129 138 … … 175 184 176 185 177 if ($req_id and !$no_update){186 { 178 187 # update the database with the request name. This will be used as the 179 # the output data store's product name188 # the fileset name in the output data store 180 189 my $command = "$pstamptool -updatereq -req_id $req_id -set_name $req_name"; 181 190 $command .= " -set_username $email" if $email ne 'null'; 182 191 $command .= " -set_outProduct $product"; 183 192 $command .= " -set_label $label" if $label_changed; 184 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 185 run(command => $command, verbose => $verbose); 186 unless ($success) { 187 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 188 } 189 } 193 unless ($no_update) { 194 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 195 run(command => $command, verbose => $verbose); 196 unless ($success) { 197 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 198 } 199 } else { 200 print "skipping $command\n"; 201 } 202 } 203 190 204 if ($duplicate_req_name) { 191 205 exit 0; … … 212 226 } 213 227 214 my $nRows = scalar @$rows;228 my $nRows = $rows ? scalar @$rows : 0; 215 229 print "\n$nRows rows read from request file\n"; 216 230 231 unless ($nRows) { 232 # pstamp_job_run was invoked so the request file must have contained a valid header 233 # a request file with no rows is invalid. 234 # The print above will let the log file know a bit more. 235 # Insert a faulted fake job and exit this program successfully. 236 print STDERR "Invalid request file.\n"; 237 insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST); 238 exit 0; 239 } 240 241 242 # if label is for one of the high priority channels, watch for big requests 243 my $watch_for_big_requests = (!($label =~ /BIG/) and ($label =~ /PSI/ or $label =~ /WEB/)); 244 245 # XXX: these should be in a configuration file somewhere not hard coded 246 my $big_limit = 100; 247 my $job_big_limit = 400; 248 249 if ($watch_for_big_requests and $nRows > $big_limit) { 250 $label = change_to_lower_priority_label($label); 251 $watch_for_big_requests = 0; 252 } 217 253 218 254 my $num_jobs = 0; 219 my $imageList; 220 my $stage; 255 221 256 foreach my $row (@$rows) { 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 assigned225 # change it to the generic one that has lower with lower priority226 $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 257 237 258 # validate the paramaters … … 246 267 247 268 $num_jobs += processRow($action, $row); 269 270 # see whether number of jobs limit for high priority request was exceeded 271 if ($watch_for_big_requests and $num_jobs > $job_big_limit) { 272 $label = change_to_lower_priority_label($label); 273 $watch_for_big_requests = 0; 274 } 248 275 } 249 276 250 277 if (($action eq 'LIST' or $mode eq "queue_job") and ($num_jobs eq 0)) { 251 print STDERR "no jobs created for $req_name\n" if $verbose; 252 insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST); 278 # this should not happen. The function above is required to insert a fake job for any 279 # rows that did not yield any jobs. 280 print STDERR "ERROR: zero jobs created for $req_name\n"; 281 insertFakeJobForRow(undef, 0, $PS_EXIT_PROG_ERROR); 253 282 } 254 283 255 284 exit 0; 285 286 # end of main function 287 288 sub change_to_lower_priority_label { 289 my $label = shift; 290 my $old_label = $label; 291 $label = ($label =~ /WEB/) ? 'WEB.BIG' : 'PSI.BIG'; 292 print "\nChanging label for big $old_label request to $label\n"; 293 294 my $command = "$pstamptool -updatereq -req_id $req_id -set_label $label"; 295 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 296 run(command => $command, verbose => $verbose); 297 unless ($success) { 298 my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR); 299 } 300 return $label; 301 } 256 302 257 303 sub checkRow { … … 267 313 my $rownum = $row->{ROWNUM}; 268 314 if (!validID($rownum)) { 315 $rownum = 'NULL' if !defined $rownum; 269 316 print STDERR "$rownum is not a valid ROWNUM\n"; 270 317 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); … … 272 319 } 273 320 my $job_type = $row->{JOB_TYPE}; 274 if (($job_type ne "stamp") and ($job_type ne "get_image")) { 321 if (!defined $job_type || (($job_type ne "stamp") and ($job_type ne "get_image"))) { 322 $job_type = 'NULL' if !defined $job_type; 275 323 print STDERR "$job_type is not a valid JOB_TYPE\n"; 276 324 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); … … 281 329 if (($req_type ne "byid") and ($req_type ne "bycoord") and ($req_type ne "byexp") and 282 330 ($req_type ne "byskycell") and ($req_type ne "bydiff")) { 331 $req_type = 'NULL' if !defined $req_type; 283 332 print STDERR "$req_type is not a valid REQ_TYPE\n"; 284 333 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); … … 286 335 } 287 336 if ($job_type eq 'get_image') { 288 unless ($req_type eq 'byid' or $req_type eq 'byexp' or ($req_type eq 'byskycell' and $stage eq 'stack')) { 289 print STDERR "REQ_TYPE must be 'byid' or 'byexp' or byskcyell for stacks for JOB_TYPE 'get_image'\n"; 337 # get_image jobs are quite expensive in terms of space so we are currently restricting them 338 unless ($req_type eq 'byid' or $req_type eq 'byexp' 339 or ($req_type eq 'byskycell' and $stage eq 'stack') 340 or ($stage eq 'stack_summary')) { 341 print STDERR "REQ_TYPE must be 'byid' or 'byexp' JOB_TYPE 'get_image' for IMG_TYPE $stage\n"; 290 342 insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST); 291 343 return 0; … … 295 347 my $component = $row->{COMPONENT}; 296 348 if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) { 297 if ($job_type eq 'get_image' ) {349 if ($job_type eq 'get_image' and ! ($stage eq 'stack' or $stage eq 'stack_summary')) { 298 350 $row->{COMPONENT} = 'all'; 299 351 } else { … … 384 436 } 385 437 386 if (($req_type eq "byexp") and ($stage eq "stack" )) {387 print STDERR "byexp not implemented for stackstage. row: $rownum\n";438 if (($req_type eq "byexp") and ($stage eq "stack" or $stage eq 'stack_summary')) { 439 print STDERR "byexp not implemented for $stage stage. row: $rownum\n"; 388 440 insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED); 389 441 return 0; … … 457 509 my $start_locate = gettimeofday(); 458 510 459 print "\nCalling new_locate_imagesfor row: $rownum\n";460 461 $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);511 print "\nCalling locate_images_for_row for row: $rownum\n"; 512 513 my $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose); 462 514 463 515 my $dtime_locate = gettimeofday() - $start_locate; … … 521 573 my $image_db = $proj_hash->{dbname}; 522 574 my $camera = $proj_hash->{camera}; 523 my $need_magic = $proj_hash->{need_magic};575 my $need_magic = $proj_hash->{need_magic}; 524 576 # Since user can get unmagicked data "by coordinate" requests can go back in time 525 577 # to dredge unusable data from the "dark days"... … … 532 584 $need_magic = 0 if $stage eq 'stack'; 533 585 534 if ($need_magic) { 535 536 # this project requires that postage stamps be extracted from destreaked images 537 538 if ($option_mask & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED)) { 539 # The user has requested uncensored stamps 540 541 if (!$dest_requires_magic) { 542 # and this user's data store destination is allowed uncensored stamps, so accept the request 543 $need_magic = 0; 544 } else { 545 print STDERR "Error row $rownum: User not authorized to to request uncensored stamps.\n"; 546 if ($option_mask & $PSTAMP_REQUIRE_UNCENSORED) { 547 # user required uncensored stamps. Can't do it so fail. 548 foreach my $r (@$rowList) { 549 insertFakeJobForRow($r, 1, $PSTAMP_NOT_AUTHORIZED); 550 $num_jobs++; 551 } 552 return $num_jobs; 553 } 554 555 # user will accept censored stamps. alter OPTION_MASK and continue 556 557 print STDERR " Will attempt to make destreaked stamps\n"; 558 # zap the offending bit in the option mask 559 $option_mask = $option_mask ^ ($PSTAMP_REQUEST_UNCENSORED); 560 foreach my $r (@$rowList) { 561 $r->{OPTION_MASK} = $option_mask; 562 } 563 } 564 } 565 } 566 586 # XXX: magic is dead 587 $need_magic = 0; 588 567 589 my $numRows = scalar @$rowList; 568 590 … … 581 603 # information required is contained there 582 604 583 $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,605 my $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component, 584 606 $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose); 585 607 … … 701 723 } 702 724 $base =~ s/.fits$//; 725 726 my $filter = $image->{filter}; 727 if (!$filter) { 728 if ($stage eq 'diff') { 729 $filter = $image->{filter_1}; 730 } 731 if (!$filter) { 732 # XXX: perhaps this should be a programming error... 733 print STDERR "missing filter using 'X'\n"; 734 $filter = 'X'; 735 } 736 } 737 # use first character of filter 738 $filter = substr($filter, 0, 1); 703 739 704 my $output_base = "$outdir/${rownum}_${job_num}_${ base}";740 my $output_base = "$outdir/${rownum}_${job_num}_${filter}_${base}"; 705 741 write_params($output_base, $image); 706 742 … … 758 794 print "$image->{image}\n"; 759 795 ++$firstRow->{job_num}; 796 if ($dump_params) { 797 my $rownum = $firstRow->{ROWNUM}; 798 my $jobnum = $firstRow->{job_num}; 799 my $filter = substr $image->{filter}, 0, 1; 800 my $output_base = "${rownum}_${jobnum}_${filter}"; 801 write_params($output_base, $image); 802 } 760 803 } 761 804 } elsif ($job_type eq "get_image") { … … 1163 1206 } 1164 1207 if (($img_type eq "raw") or ($img_type eq "chip") or ($img_type eq "warp") or 1165 ($img_type eq "stack") or ($img_type eq "diff")) {1208 ($img_type eq "stack") or ($img_type eq 'stack_summary') or ($img_type eq "diff")) { 1166 1209 return 1; 1167 1210 } else {
Note:
See TracChangeset
for help on using the changeset viewer.
