IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 38008


Ignore:
Timestamp:
Mar 25, 2015, 12:40:19 PM (11 years ago)
Author:
bills
Message:

Implement date cuttoff based on the "accessLevel" if a user. For now the
rules are hard coded

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstampparse.pl

    r37998 r38008  
    1818use POSIX;
    1919use Time::HiRes qw(gettimeofday);
     20use Time::Local;
    2021
    2122my $verbose;
     
    569570    $option_mask |= $PSTAMP_NO_WAIT_FOR_UPDATE if $no_updates_allowed;
    570571
     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);
     575
    571576    my $roi_string;
    572577
     
    612617
    613618    my $imagefile = $image->{image};
    614     if (($stage ne "stack") and ($need_magic and !$image->{magicked})) {
    615         # XXX: should we add a faulted job so the client can know what happened if no images come back?
    616         # The test for destreaked is made in locate_images now so this code never runs. This leads to no feedback
    617         # to users, but speeds up processing significantly
    618         print STDERR "skipping non-magicked image $imagefile\n" if $verbose;
    619 
    620         # for now assume yes.
    621 
    622         insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_DESTREAKED);
    623         return 1;
    624     } elsif ($stage eq "stack") {
     619
     620    if ($stage eq "stack") {
    625621        # unconvolved stack images weren't available prior to some point in time.
    626622        # XXX: handle this more correctly by examining the stack run's config dump file.
     
    633629            insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_AVAILABLE);
    634630            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            }
    635671        }
    636672    }
     
    863899    my $job_num = shift;
    864900    my $fault = shift;
     901    my $exp_id = shift;
    865902
    866903    my ($job_type, $rownum);
     
    885922    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $job_type"
    886923                        . " -rownum $rownum -state stop -fault $fault";
     924    $command .= " -exp_id $exp_id" if $exp_id and $exp_id ne 'NULL';
    887925
    888926    if (!$no_update) {
     
    11531191        # set the access rights based on the assigned label.
    11541192        if ($label eq 'IFA' or $label eq 'QUB' or $label =~ 'MOPS') {
    1155             $level = 2;
     1193            $level = 0;
    11561194        } else {
    11571195            # access rights PS1 data only
     
    11641202            $domain = lc($domain);
    11651203            if ($domain eq 'ifa.hawaii.edu' or $domain eq 'qub.ac.uk') {
    1166                 $level = 2;
     1204                $level = 0;
    11671205            } else {
    11681206                # XXX check for special users
     
    11781216}
    11791217
     1218
     1219# determine the latest exposure date that a user may have access to
     1220# based on the user's accessLevel.
     1221sub 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
     1240sub 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
    11801259sub my_die
    11811260{
Note: See TracChangeset for help on using the changeset viewer.