- Timestamp:
- Mar 28, 2015, 8:28:32 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20150112/pstamp/scripts/pstampparse.pl
r37838 r38052 18 18 use POSIX; 19 19 use Time::HiRes qw(gettimeofday); 20 use Time::Local; 20 21 21 22 my $verbose; … … 117 118 my_die("REQ_NAME not found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if (!$req_name); 118 119 my_die("wrong EXTVER $extver found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2"); 120 121 if ($extver eq "1") { 122 print STDERR "WARNING WARNING WARNING\n"; 123 print STDERR "Very soon version 1 postage stamp requests will be rejected. Please update your request tables to version 2 format.\n"; 124 print STDERR "Note that EMAIL will not be optional\n"; 125 126 } elsif (!$email) { 127 my_die("ERROR: Required parameter EMAIL not found in request file header.\n", $PSTAMP_INVALID_REQUEST) 128 } 129 119 130 120 131 if ($extver >= 2) { … … 260 271 my $num_jobs = 0; 261 272 273 my $accessLevel = getUsersAccessLevel($email, $label); 274 if ($accessLevel < 0) { 275 print STDERR "Data access forbidden.\n"; 276 insertFakeJobForRow(undef, 0, $PSTAMP_NOT_AUTHORIZED); 277 exit 0; 278 } 279 262 280 foreach my $row (@$rows) { 263 281 … … 271 289 $row->{job_num} = 0; 272 290 $row->{error_code} = 0; 291 $row->{accessLevel} = $accessLevel; 273 292 274 293 $num_jobs += processRow($action, $row); … … 537 556 } 538 557 539 sub processRows {540 my $action = shift;541 my $rowList = shift;542 my $num_jobs = 0;543 544 if ($action eq 'LIST') {545 # LIST is not allowed by caller. Can't get here.546 return list_targets($rowList);547 }548 549 # all rows in the list are compatible550 my $row = $rowList->[0];551 552 my $project = $row->{PROJECT};553 554 # note: resolve_project avoids running pstamptool every time by remembering the555 # last project resolved556 my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);557 if (!$proj_hash) {558 foreach my $r (@$rowList) {559 insertFakeJobForRow($r, 1, $PSTAMP_UNKNOWN_PRODUCT);560 $num_jobs++;561 }562 return $num_jobs;563 }564 my $req_type = $row->{REQ_TYPE};565 my $stage = $row->{IMG_TYPE};566 my $id = $row->{ID};567 my $component = $row->{COMPONENT};568 my $tess_id = $row->{TESS_ID};569 570 my $filter = $row->{REQFILT};571 my $mjd_min = $row->{MJD_MIN};572 my $mjd_max = $row->{MJD_MAX};573 my $data_group = $row->{DATA_GROUP};574 575 my $rownum = $row->{ROWNUM};576 my $job_type = $row->{JOB_TYPE};577 my $option_mask= $row->{OPTION_MASK};578 579 my $image_db = $proj_hash->{dbname};580 my $camera = $proj_hash->{camera};581 my $need_magic = $proj_hash->{need_magic};582 # Since user can get unmagicked data "by coordinate" requests can go back in time583 # to dredge unusable data from the "dark days"...584 if ($req_type eq 'bycoord' and $mjd_min eq 0) {585 # ... so unless the user sets mjd_min clamp it to 2009-04-01586 # XXX: This value should live in the pstampProject table not be hardcoded here587 $mjd_min = 54922;588 }589 590 $need_magic = 0 if $stage eq 'stack';591 592 # XXX: magic is dead593 $need_magic = 0;594 595 my $numRows = scalar @$rowList;596 597 if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) {598 # avoid error from print below if $id isn't needed599 $id = "" if !$id;600 }601 print "Collected $numRows rows beginning with row $rownum. $req_type $stage $id $tess_id $component\n";602 603 # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this604 # request specification. An array reference is returned.605 my $start_locate = gettimeofday();606 607 # XXX: perhaps we should get rid of most of this argument list.608 # Now that we are passing down compatible rows all of the609 # information required is contained there610 611 my $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,612 $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);613 614 my $dtime_locate = gettimeofday() - $start_locate;615 print "Time to locate_images for row $rownum $dtime_locate\n";616 617 # handle this618 # XXX: what did I mean by that comment?619 $row->{need_magic} = $need_magic;620 621 $num_jobs += queueJobs($action, $rowList, $imageList);622 623 # if a row slipped through with no jobs add a faulted one624 foreach my $row (@$rowList) {625 if ($row->{job_num} == 0) {626 print "row $row->{ROWNUM} produced no jobs\n";627 print STDERR "row $row->{ROWNUM} produced no jobs\n";628 my $error_code = $row->{error_code};629 $error_code = $PSTAMP_NO_IMAGE_MATCH if !$error_code;630 insertFakeJobForRow($row, ++$row->{job_num}, $error_code);631 }632 }633 634 return $num_jobs;635 }636 637 558 sub queueJobForImage 638 559 { … … 648 569 649 570 $option_mask |= $PSTAMP_NO_WAIT_FOR_UPDATE if $no_updates_allowed; 571 572 # determine if there is a cut off date for data access for this user 573 my $mjd_max; 574 my $adjustedDateCuts = adjustDateCuts($row, \$mjd_max); 650 575 651 576 my $roi_string; … … 692 617 693 618 my $imagefile = $image->{image}; 694 if (($stage ne "stack") and ($need_magic and !$image->{magicked})) { 695 # XXX: should we add a faulted job so the client can know what happened if no images come back? 696 # The test for destreaked is made in locate_images now so this code never runs. This leads to no feedback 697 # to users, but speeds up processing significantly 698 print STDERR "skipping non-magicked image $imagefile\n" if $verbose; 699 700 # for now assume yes. 701 702 insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_DESTREAKED); 703 return 1; 704 } elsif ($stage eq "stack") { 619 620 if ($stage eq "stack") { 705 621 # unconvolved stack images weren't available prior to some point in time. 706 622 # XXX: handle this more correctly by examining the stack run's config dump file. … … 713 629 insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_AVAILABLE); 714 630 return 1; 631 } 632 } else { 633 if ($need_magic and !$image->{magicked}) { 634 # XXX: should we add a faulted job so the client can know what happened if no images come back? 635 # The test for destreaked is made in locate_images now so this code never runs. This leads to no feedback 636 # to users, but speeds up processing significantly 637 print STDERR "skipping non-magicked image $imagefile\n" if $verbose; 638 639 # for now assume yes. 640 641 insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_DESTREAKED); 642 return 1; 643 } 644 645 if ($adjustedDateCuts) { 646 my $mjd = 0; 647 my $exp_id; 648 if ($stage eq 'diff') { 649 # diff stage doesn't have a dateobs so we need to hack it. 650 # Extract dateobs from the exp_name_1 651 if ($row->{PROJECT} eq 'gpc1') { 652 my $exp_name = $image->{exp_name_1}; 653 if ($exp_name ne 'NULL') { 654 $mjd = 50000 + (substr($exp_name, 1, 4)); 655 $exp_id = $image->{exp_id_1}; 656 } else { 657 # it's stack-stack diff just let it go with mjd = 0 658 # XXX: deal with this 659 } 660 } 661 } else { 662 $exp_id = $image->{exp_id}; 663 $mjd = dateobsToMJD($image->{dateobs}); 664 } 665 666 if ($mjd > $mjd_max) { 667 print STDERR "User is not authorized for stamps from this exposure.\n"; 668 insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_AUTHORIZED, $exp_id); 669 return 1; 670 } 715 671 } 716 672 } … … 943 899 my $job_num = shift; 944 900 my $fault = shift; 901 my $exp_id = shift; 945 902 946 903 my ($job_type, $rownum); … … 965 922 my $command = "$pstamptool -addjob -req_id $req_id -job_type $job_type" 966 923 . " -rownum $rownum -state stop -fault $fault"; 924 $command .= " -exp_id $exp_id" if $exp_id and $exp_id ne 'NULL'; 967 925 968 926 if (!$no_update) { … … 1220 1178 } 1221 1179 1180 # Prototype function for setting access level. 1181 # XXX: Implement something more flexible using the database. 1182 sub getUsersAccessLevel { 1183 my $email = shift; 1184 my $label = shift; 1185 1186 my $level = -1; 1187 1188 if (!$email) { 1189 # No email provided. Eventually this will be forbidden. 1190 # For now in order to temporarily continue to support the version 1 request format 1191 # set the access rights based on the assigned label. 1192 if ($label eq 'IFA' or $label eq 'QUB' or $label =~ 'MOPS') { 1193 $level = 0; 1194 } else { 1195 # access rights PS1 data only 1196 $level = 1; 1197 } 1198 } else { 1199 # we've got an email check the domain 1200 my ($user, $domain) = split '@', $email; 1201 if ($domain) { 1202 $domain = lc($domain); 1203 if ($domain eq 'ifa.hawaii.edu' or $domain eq 'qub.ac.uk') { 1204 $level = 0; 1205 } else { 1206 # XXX check for special users 1207 # access rights PS1 data only 1208 $level = 1; 1209 } 1210 } else { 1211 print STDERR "Error: $email is not a valid email address\n"; 1212 } 1213 } 1214 1215 return $level; 1216 } 1217 1218 1219 # determine the latest exposure date that a user may have access to 1220 # based on the user's accessLevel. 1221 sub adjustDateCuts { 1222 my $row = shift; 1223 my $r_mjd_max = shift; 1224 my $adjusted = 0; 1225 1226 my $MJD_PS1_BEGIN = 54922; # 2009-04-01 1227 my $MJD_PS1_END = 56838; # 2014-06-30 XXX get the actual date 1228 1229 if ($row->{accessLevel} == 1) { 1230 # User has access to PS1 data only 1231 my $mjd_max_user = $row->{MJD_MAX}; 1232 if (!$mjd_max_user or $mjd_max_user > $MJD_PS1_END) { 1233 $$r_mjd_max = $MJD_PS1_END; 1234 $adjusted = 1; 1235 } 1236 } 1237 return $adjusted; 1238 } 1239 1240 sub dateobsToMJD { 1241 my $dateobs = shift; 1242 1243 my ($date, $time) = split "T", $dateobs; 1244 1245 my ($year, $mon, $day) = split "-", $date; 1246 1247 my ($hr, $min, $sec) = split ":", $time; 1248 my $fraction = $sec - int($sec); 1249 $sec = int($sec); 1250 1251 my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900); 1252 $ticks += $fraction; 1253 1254 # I'm not allowing for leap seconds here but for our purposes here that is ok 1255 my $mjd = 40587.0 + ($ticks / 86400.); 1256 return $mjd; 1257 } 1258 1222 1259 sub my_die 1223 1260 {
Note:
See TracChangeset
for help on using the changeset viewer.
