IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 26098


Ignore:
Timestamp:
Nov 11, 2009, 7:49:02 PM (16 years ago)
Author:
watersc1
Message:

Updated version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/gpc1_find_images.pl

    r25853 r26098  
    33use DBI;
    44use Getopt::Std;
    5 getopts('hFARCPp:BMDWvx:n:c:w:O:S:',\%opt);
     5getopts('hFARCPp:BLMDWIvx:n:c:w:s:O:S:N:',\%opt);
    66#getopt('xncwOS:hARCW',\%opt);
    77unless (exists($opt{O})) {
     
    5151    print "          -c <chip_id>    ...\n";
    5252    print "          -w <warp_id>    ...\n";
     53    print "          -s <stack_id>   ...\n";
    5354    print "          -n <exp_name>   ...\n";
    5455    print " \n";
     
    7172                   ) or die "Unable to connect to database $DBI::errstr\n";
    7273
    73 $sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING (exp_id)";
     74$sth_base = "SELECT warp_id,warpRun.workdir,chipRun.chip_id,chipRun.workdir,rawExp.exp_name,rawExp.exp_id,rawExp.workdir,rawExp.dateobs,rawExp.pon_time,0,'nostack' from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING (exp_id)";
     75
    7476# What do we have?
    7577@sth_adds = ();
     
    8688if (exists($opt{w})) {
    8789    push @sth_adds, "warpRun.warp_id = $opt{w}";
     90}
     91if (exists($opt{s})) {
     92    if ($opt{s} != 0) {
     93        push @sth_adds, "stackRun.stack_id = $opt{s}";
     94    }
     95    $sth_base =~ s/0,"nostack"/stack_id,stackSumSkyfile.uri/;
     96    $sth_base .= ' JOIN stackInputSkyfile USING (warp_id) JOIN stackSumSkyfile USING (stack_id) JOIN stackRun USING (stack_id)';
    8897}
    8998if ($#sth_adds != -1) {
     
    97106$dr = $db->selectall_arrayref( $sth );
    98107
     108
     109%uniq = ();
     110$found = 0;
    99111foreach $rr (@{ $dr }) {
    100112    ($warp_id, $warp_workdir, $chip_id, $chip_workdir,
    101      $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime) = @{ $rr };
     113     $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime,
     114     $stack_id, $stack_sumfile_uri) = @{ $rr };
     115    if ($stack_id == 0) {
     116        $stack_sumfile_uri = '';
     117    }
    102118#    print (join "\t", @{ $rr }) . "\n";
    103     $exp_pontime = 0; # To stop warnings, but I want this around.
     119#    $exp_pontime = 0; # To stop warnings, but I want this around.
     120    if (exists($opt{I})) {
     121        $stack_id = 0; # Ditto.
     122    }
     123    if (exists($opt{N})) {
     124        if ($found > $opt{N}) {
     125            last;
     126        }
     127    }
    104128    if (exists($opt{P})) {
    105129        $sth_previous = "SELECT exp_name from rawExp where dateobs < '$exp_dateobs' order by dateobs desc limit 1";
     
    127151#       exit(0);
    128152    }
    129    
    130 
    131 
     153
     154    %mapping = ();
     155    if ((exists($opt{C})&&(exists($opt{S})))||
     156        (exists($opt{W})&&(exists($opt{O})))||
     157        exists($opt{I})) {
     158        $sth_mapping = "SELECT skycell_id,class_id from warpSkyCellMap WHERE warp_id = $warp_id";
     159        $mr = $db->selectall_arrayref( $sth_mapping );
     160        foreach $mrr (@{ $mr }) {
     161            my ($skycell,$class) = @{ $mrr };
     162            my $raw_class = $class;
     163            $raw_class =~ s/xy/ota/i;
     164            push @{ $mapping{$skycell} }, $class;
     165            push @{ $mapping{$skycell} }, $raw_class;
     166            push @{ $mapping{$class} }, $skycell;
     167            push @{ $mapping{$raw_class} }, $skycell;
     168        }
     169    }
     170   
     171    if (exists($opt{I})) {
     172        if ($warp_id eq '') {
     173            $warp_id = 'NULL';
     174        }
     175        if ($stack_id eq '') {
     176            $stack_id = 'NULL';
     177        }
     178        $line = "$exp_name $exp_id $exp_dateobs $exp_pontime $chip_id $warp_id\t";
     179        if (exists($opt{O})) {
     180            foreach $sky (@{ $mapping{$opt{O}} }) {
     181                $line .= "$sky\t";
     182            }
     183        }
     184        if (exists($opt{S})) {
     185            foreach $sky (@{ $mapping{$opt{S}} }) {
     186                $line .= "$sky\t";
     187            }
     188        }
     189        $line .= "\n";
     190        unless (exists($uniq{$line})) {
     191            print $line;
     192            $uniq{$line} = 1;
     193        }
     194        next;
     195    }
    132196    @scan = ();
    133197    if (exists($opt{R})||exists($opt{B})) {
     
    135199        while (<NLS>) {
    136200            chomp;
    137             if (($_ =~ /${opt{O}}/)&&((($opt{A})) || ($_ =~ /fits/))) {
    138                 if (exists($opt{B})) {
    139                     $_ =~ s/.fits$/.burn.tbl/;
    140                 }
     201            if (is_valid_raw($_)) {
    141202                push @scan, $_;
     203                $found++;
    142204            }
    143205        }
     
    148210        while (<NLS>) {
    149211            chomp;
    150             if (($_ =~ /${exp_id}.ch/)&&($_ =~ /$chip_id/)&&($_ =~ /$opt{O}/)&&
    151                 ((($opt{A})) || (($_ =~ /fits/) &&
    152                                  ($opt{M} || ($_ !~ /mk.fits/)) &&
    153                                  ($_ !~ /wt.fits/)))) {
    154                 if ($opt{D} && ($_ !~ /SR/)) {
    155                     next;
    156                 }
     212            if (is_valid_chip($_)) {
    157213                push @scan, $_;
    158 
     214                $found++;
    159215            }
    160216        }
     
    165221        while (<NLS>) {
    166222            chomp;
    167 #           print "$_\n";
    168             if (($_ =~ /wrp.${warp_id}.$opt{S}/) && ((($opt{A})) || (($_ =~ /fits/) &&
    169                                                                      ($opt{M} || ($_ !~ /mask/)) &&
    170                                                                      ($_ !~ /wt/)))) {
    171                 if ($opt{D} && ($_ !~ /SR/)) {
    172                     next;
    173                 }
     223            if (is_valid_warp($_)) {
    174224                push @scan, $_;
    175             }
    176         }
    177     }
    178     %uniq = ();
     225                $found++;
     226            }
     227        }
     228    }
     229    if (exists($opt{s})) {
     230        push @scan, $stack_sumfile_uri;
     231        $found++;
     232    }
     233
    179234    foreach $f (@scan) {
    180235        unless (exists($uniq{$f})) {
     
    190245    }
    191246}
     247
     248sub is_mapped {
     249    my ($key,$map_string) = @_;
     250   
     251    unless (exists($mapping{$map_string})) {
     252        return(0);
     253    }
     254   
     255    foreach $v (@{ $mapping{$map_string} }) {
     256        if ($key =~ /$v/) {
     257            return(1);
     258        }
     259    }
     260    return(0);
     261}
     262
     263sub is_valid_raw {
     264    my $key = shift;
     265
     266    if ($opt{A}) {
     267        return(1);
     268    }
     269    elsif ($opt{L}) {
     270        if ($key =~ /log/) {
     271            return(1);
     272        }
     273        else {
     274            return(0);
     275        }
     276    }
     277    elsif ($opt{B}) {
     278        if ($key =~ /burn.tbl/) {
     279            return(1);
     280        }
     281        else {
     282            return(0);
     283        }
     284    }
     285    elsif ($key !~ /fits/) {
     286        return(0);
     287    }
     288    else {
     289        if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     290            return(0); # Not the requested OTA
     291        }
     292        if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     293            return(0); # Not the remapped skycell requested
     294        }
     295        if ($key =~ /burn.fits/) {
     296            return(0);
     297        }
     298        return(1);
     299    }
     300}
     301   
     302sub is_valid_chip {
     303    my $key = shift;
     304   
     305   
     306    if ($opt{D} && ($key !~ /SR/)) {
     307        return(0); # Not destreaked when required
     308    }
     309    elsif ($key !~ /${exp_id}.ch/) {
     310        return(0); # Not a chip from this exposure
     311    }
     312    elsif ($key !~ /${chip_id}/) {
     313        return(0); # Not from this chip_id
     314    }
     315
     316    if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     317        return(0); # Not the requested OTA
     318    }
     319    if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     320        return(0); # Not the remapped skycell requested
     321    }
     322           
     323    if ($opt{A}) {
     324        return(1); # You asked for all,
     325    }
     326    elsif ($opt{L}) {
     327        if ($key =~ /log/) {
     328            return(1);
     329        }
     330        else {
     331            return(0);
     332        }
     333    }
     334    elsif ($key !~ /fits/) {
     335        return(0); # Not a fits
     336    }
     337    elsif ($key =~ /wt.fits/) {
     338        return(0); # No handler for weight right now.
     339    }
     340    elsif ($key =~ /mk/) {
     341        if ($opt{M}) {
     342            return(1); # Requested mask
     343        }
     344        else {
     345            return(0);
     346        }
     347    }
     348    elsif ($key =~ /ch.fits/) {
     349        return(1); # Should be just the chip
     350    }
     351    return(0);
     352
     353}
     354
     355sub is_valid_warp {
     356    my $key = shift;
     357   
     358    if ($opt{D} && ($key !~ /SR/)) {
     359        return(0); # Not destreaked when required
     360    }
     361    elsif ($key !~ /wrp.${warp_id}/) {
     362        return(0); # Not a warp from this warp_id
     363    }
     364    if (($opt{S} ne '')&&($key !~ /$opt{S}/)) {
     365        return(0); # Not the requested skycell
     366    }
     367    if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) {
     368        return(0); # Not the remapped OTA requested
     369    }
     370           
     371    if ($opt{A}) {
     372        return(1); # You asked for all,
     373    }
     374    elsif ($opt{L}) {
     375        if ($key =~ /log/) {
     376            return(1);
     377        }
     378        else {
     379            return(0);
     380        }
     381    }
     382    elsif ($key !~ /fits/) {
     383        return(0); # Not a fits
     384    }
     385    elsif ($key =~ /wt.fits/) {
     386        return(0); # No handler for weight right now.
     387    }
     388    elsif ($key =~ /mask/) {
     389        if ($opt{M}) {
     390            return(1); # Requested mask
     391        }
     392        else {
     393            return(0);
     394        }
     395    }
     396    else {
     397        return(1); # Should be just the warp.
     398    }
     399    return(0);
     400}
     401       
     402
     403
     404   
     405   
Note: See TracChangeset for help on using the changeset viewer.