IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/tools/gpc1_find_images.pl

    r25853 r27838  
    33use DBI;
    44use Getopt::Std;
    5 getopts('hFARCPp:BMDWvx:n:c:w:O:S:',\%opt);
     5getopts('hEFARCPp:BLMDWIJVYTvx:n:c:w:s:d:e:O:S:N:',\%opt);
    66#getopt('xncwOS:hARCW',\%opt);
    77unless (exists($opt{O})) {
     
    3434}
    3535
     36# abcdefghijklmnopqrstuvwxyz
     37#used:
     38# ABCDEF     LMNOP RST  W Y
     39#   c    h     n    s  vwx 
    3640if (exists($opt{h})) {
    3741    print "USAGE find_images.pl ... \n";
    3842    print "          -h              This help\n";
    39     print "          -R              Return raw data.\n";
    40     print "          -C              Return chip stage data.\n";
    41     print "          -W              Return warp stage data.\n";
     43    print "          -R              Return Raw data.\n";
     44    print "          -C              Return Chip stage data.\n";
     45    print "          -E              Return camEra stage data.\n";
     46    print "          -W              Return Warp stage data.\n";
     47    print "          -T              Get the sTacks for a given input.\n";
     48    print "          -J              Get the dIff stage data (warps only for now).\n";
    4249    print "          -A              Return not just fits images.\n";
    4350    print "          -F              Convert to real filenames.\n";
     
    4552    print "          -B              Return burntool table.\n";
    4653    print "          -M              Include masks in results.\n";
     54    print "          -L              Return the log files from this stage.\n";
    4755    print "          -D              Return only pre-destreaked images.\n";
     56    print "          -Y              Yes, I want the raw, even if it's not been processed.\n";
     57    print "          -V              Return the cmf or smf files.\n";
    4858    print "          -v              Be verbose on output.\n";
    4959    print " \n";
    5060    print "          -x <exp_id>     Specify a exp_id.\n";
    5161    print "          -c <chip_id>    ...\n";
     62    print "          -e <cam_id>     ...\n";
    5263    print "          -w <warp_id>    ...\n";
     64    print "          -s <stack_id>   ...\n";
     65    print "          -d <diff_id>    ...\n";
    5366    print "          -n <exp_name>   ...\n";
    5467    print " \n";
     
    6376$dbname = 'gpc1';
    6477$dbserver = 'ippdb01';
    65 $dbuser = 'ipp';
    66 $dbpass = 'ipp';
     78$dbuser = 'ippuser';
     79$dbpass = 'ippuser';
    6780$db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
    6881                   "mysql_socket=" . DB_SOCKET(),
     
    7184                   ) or die "Unable to connect to database $DBI::errstr\n";
    7285
    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)";
     86if ($opt{Y}) {
     87    $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',camRun.cam_id,camRun.workdir,0,'nodiff' from warpRun RIGHT OUTER JOIN fakeRun USING(fake_id) RIGHT OUTER JOIN camRun USING(cam_id) RIGHT OUTER JOIN chipRun USING(chip_id) RIGHT OUTER JOIN rawExp USING (exp_id)";
     88}
     89else {
     90    $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',camRun.cam_id,camRun.workdir,0,'nodiff' from warpRun  JOIN fakeRun USING(fake_id)  JOIN camRun USING(cam_id)  JOIN chipRun USING(chip_id)  JOIN rawExp USING (exp_id)";
     91}
     92
    7493# What do we have?
    7594@sth_adds = ();
     
    86105if (exists($opt{w})) {
    87106    push @sth_adds, "warpRun.warp_id = $opt{w}";
     107}
     108if (exists($opt{e})) {
     109    push @sth_adds, "camRun.cam_id = $opt{e}";
     110}
     111if (exists($opt{s})||exists($opt{T})) {
     112#    print "$opt{s}!\n";
     113    if (exists($opt{s})&&($opt{s} != 0)) {
     114        push @sth_adds, "stackRun.stack_id = $opt{s}";
     115    }
     116    $sth_base =~ s/0,'nostack'/stack_id,stackSumSkyfile.uri/;
     117    if (exists($opt{T})) {
     118        $sth_base .= ' RIGHT OUTER ';
     119    }
     120    $sth_base .= ' JOIN stackInputSkyfile USING (warp_id) JOIN stackSumSkyfile USING (stack_id) JOIN stackRun USING (stack_id)';
     121#    print "$sth_base\n";
     122}
     123if (exists($opt{J})||(exists($opt{d}))) {
     124    if (exists($opt{d})&&($opt{d} != 0)) {
     125        push @sth_adds, "diffRun.diff_id = $opt{d}";
     126    }
     127    $sth_base =~ s/0,'nodiff'/diffRun.diff_id,diffSkyfile.path_base/;
     128    if (exists($opt{J})) {
     129#       $sth_base .= ' RIGHT OUTER ';
     130    }
     131    $sth_base .= ' JOIN diffInputSkyfile ON (warpRun.warp_id = diffInputSkyfile.warp1 OR warpRun.warp_id = diffInputSkyfile.warp2) JOIN diffRun USING (diff_id) JOIN diffSkyfile USING (diff_id)';
    88132}
    89133if ($#sth_adds != -1) {
     
    97141$dr = $db->selectall_arrayref( $sth );
    98142
     143
     144%uniq = ();
     145$found = 0;
    99146foreach $rr (@{ $dr }) {
    100147    ($warp_id, $warp_workdir, $chip_id, $chip_workdir,
    101      $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime) = @{ $rr };
    102 #    print (join "\t", @{ $rr }) . "\n";
    103     $exp_pontime = 0; # To stop warnings, but I want this around.
     148     $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime,
     149     $stack_id, $stack_sumfile_uri,
     150     $cam_id, $cam_workdir,
     151     $diff_id, $diff_workdir
     152    ) = @{ $rr };
     153    if ($stack_id == 0) {
     154        $stack_sumfile_uri = '';
     155    }
     156#    print (join "\t", @{ $rr }) . "\n" . "\n";
     157#    $exp_pontime = 0; # To stop warnings, but I want this around.
     158    if (exists($opt{I})) {
     159        $stack_id = 0; # Ditto.
     160        $cam_id = 0;
     161        $diff_id = 0;
     162    }
     163    if (exists($opt{N})) {
     164        if ($found > $opt{N}) {
     165            last;
     166        }
     167    }
    104168    if (exists($opt{P})) {
    105169        $sth_previous = "SELECT exp_name from rawExp where dateobs < '$exp_dateobs' order by dateobs desc limit 1";
     
    112176        if (exists($opt{B})) { $previous_cmd .= ' -B '; }
    113177        if (exists($opt{v})) { $previous_cmd .= ' -v '; }
     178        if (exists($opt{F})) { $previous_cmd .= ' -F '; }
    114179        if ($opt{A}) { $previous_cmd .= ' -A '; }
    115180        if ($opt{M}) { $previous_cmd .= ' -M '; }
     
    127192#       exit(0);
    128193    }
    129    
    130 
    131 
     194
     195    %mapping = ();
     196    unless (exists($opt{Y})) {
     197        if ((exists($opt{C})&&(exists($opt{S})))||
     198            (exists($opt{W})&&(exists($opt{O})))||
     199            exists($opt{I})) {
     200            $sth_mapping = "SELECT skycell_id,class_id from warpSkyCellMap WHERE warp_id = $warp_id";
     201            $mr = $db->selectall_arrayref( $sth_mapping );
     202            foreach $mrr (@{ $mr }) {
     203                my ($skycell,$class) = @{ $mrr };
     204                my $raw_class = $class;
     205                $raw_class =~ s/xy/ota/i;
     206                push @{ $mapping{$skycell} }, $class;
     207                push @{ $mapping{$skycell} }, $raw_class;
     208                push @{ $mapping{$class} }, $skycell;
     209                push @{ $mapping{$raw_class} }, $skycell;
     210#           print STDERR "$raw_class $class $skycell\n";
     211            }
     212        }
     213    }
     214   
     215    if (exists($opt{I})) {
     216        if ($warp_id eq '') {
     217            $warp_id = 'NULL';
     218        }
     219        if ($stack_id eq '') {
     220            $stack_id = 'NULL';
     221        }
     222        $line = "$exp_name $exp_id $exp_dateobs $exp_pontime $chip_id $warp_id\t";
     223        if (exists($opt{O})) {
     224            foreach $sky (@{ $mapping{$opt{O}} }) {
     225                $line .= "$sky\t";
     226            }
     227        }
     228        if (exists($opt{S})) {
     229            foreach $sky (@{ $mapping{$opt{S}} }) {
     230                $line .= "$sky\t";
     231            }
     232        }
     233        $line .= "\n";
     234        unless (exists($uniq{$line})) {
     235            print $line;
     236            $uniq{$line} = 1;
     237        }
     238        next;
     239    }
    132240    @scan = ();
    133241    if (exists($opt{R})||exists($opt{B})) {
     242#       print STDERR "$exp_workdir $exp_name\n";
    134243        open(NLS,"neb-ls $exp_workdir/${exp_name}/ |") || die "can't neb-ls";
    135244        while (<NLS>) {
    136245            chomp;
    137             if (($_ =~ /${opt{O}}/)&&((($opt{A})) || ($_ =~ /fits/))) {
    138                 if (exists($opt{B})) {
    139                     $_ =~ s/.fits$/.burn.tbl/;
    140                 }
     246            if (is_valid_raw($_)) {
    141247                push @scan, $_;
     248                $found++;
    142249            }
    143250        }
     
    148255        while (<NLS>) {
    149256            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                 }
     257            if (is_valid_chip($_)) {
    157258                push @scan, $_;
    158 
     259                $found++;
     260            }
     261        }
     262        close(NLS);
     263    }
     264    if (exists($opt{E})) {
     265        open(NLS,"neb-ls $cam_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls";
     266        while (<NLS>) {
     267            chomp;
     268            if (is_valid_cam($_)) {
     269                push @scan, $_;
     270                $found++;
    159271            }
    160272        }
     
    165277        while (<NLS>) {
    166278            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                 }
     279            if (is_valid_warp($_)) {
    174280                push @scan, $_;
    175             }
    176         }
    177     }
    178     %uniq = ();
     281                $found++;
     282            }
     283        }
     284    }
     285    if (exists($opt{J})) {
     286        @diff_tmp = split /\//, $diff_workdir;
     287        $diff_prefix = pop(@diff_tmp);
     288        $diff_true_dir = join '/',@diff_tmp;
     289
     290        open(NLS,"neb-ls $diff_true_dir |") || die "can't neb-ls";
     291        while (<NLS>) {
     292            chomp;
     293            if (is_valid_diff($_)) {
     294                push @scan, $_;
     295                $found++;
     296            }
     297        }
     298    }
     299    if (exists($opt{s})||exists($opt{T})) {
     300        if (defined($stack_sumfile_uri)) {
     301            push @scan, $stack_sumfile_uri;
     302            $found++;
     303        }
     304    }
     305
    179306    foreach $f (@scan) {
    180307        unless (exists($uniq{$f})) {
     
    190317    }
    191318}
     319
     320sub is_mapped {
     321    my ($key,$map_string) = @_;
     322   
     323    unless (exists($mapping{$map_string})) {
     324        return(0);
     325    }
     326   
     327    foreach $v (@{ $mapping{$map_string} }) {
     328        if ($key =~ /$v/) {
     329            return(1);
     330        }
     331    }
     332    return(0);
     333}
     334
     335sub is_valid_raw {
     336    my $key = shift;
     337
     338    if ($opt{A}) {
     339        return(1);
     340    }
     341    elsif ($opt{L}) {
     342        if ($key =~ /log/) {
     343            return(1);
     344        }
     345        else {
     346            return(0);
     347        }
     348    }
     349    elsif ($opt{B}) {
     350        if ($key =~ /burn.tbl/) {
     351            if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     352                return(0); # Not the requested OTA
     353            }
     354            if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     355                return(0); # Not the remapped skycell requested
     356            }
     357            return(1);
     358        }
     359        else {
     360            return(0);
     361        }
     362    }
     363    elsif ($key !~ /fits/) {
     364        return(0);
     365    }
     366    else {
     367        if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     368            return(0); # Not the requested OTA
     369        }
     370        if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     371            return(0); # Not the remapped skycell requested
     372        }
     373        if ($key =~ /burn.fits/) {
     374            return(0);
     375        }
     376        return(1);
     377    }
     378}
     379   
     380sub is_valid_chip {
     381    my $key = shift;
     382   
     383   
     384    if ($opt{D} && ($key !~ /SR/)) {
     385        return(0); # Not destreaked when required
     386    }
     387    elsif ($key !~ /${exp_id}.ch/) {
     388        return(0); # Not a chip from this exposure
     389    }
     390    elsif ($key !~ /${chip_id}/) {
     391        return(0); # Not from this chip_id
     392    }
     393
     394    if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     395        return(0); # Not the requested OTA
     396    }
     397    if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     398        return(0); # Not the remapped skycell requested
     399    }
     400           
     401    if ($opt{A}) {
     402        return(1); # You asked for all,
     403    }
     404    elsif ($opt{L}) {
     405        if ($key =~ /log/) {
     406            return(1);
     407        }
     408        else {
     409            return(0);
     410        }
     411    }
     412    elsif ($opt{V} && ($key =~ /cmf/)) {
     413        return(1);
     414    }
     415    elsif ($key !~ /fits/) {
     416        return(0); # Not a fits
     417    }
     418    elsif ($key =~ /wt.fits/) {
     419        return(0); # No handler for weight right now.
     420    }
     421    elsif ($key =~ /mk/) {
     422        if ($opt{M}) {
     423            return(1); # Requested mask
     424        }
     425        else {
     426            return(0);
     427        }
     428    }
     429    elsif ($key =~ /ch.fits/) {
     430        return(1); # Should be just the chip
     431    }
     432    return(0);
     433
     434}
     435
     436sub is_valid_cam {
     437    my $key = shift;
     438    if ($key =~ /\.cm\./) {
     439        if ($opt{A}) {
     440            return(1);
     441        }
     442        elsif ($opt{L} && ($key =~ /log/)) {
     443            return(1);
     444        }
     445        elsif ($opt{V} && ($key =~ /smf/)) {
     446            return(1);
     447        }
     448        elsif ($opt{M} && ($key =~ /mk.fits/)) {
     449            if (($opt{O} ne '')&&($key !~ /$opt{O}/)) {
     450                return(0); # Not the requested OTA
     451            }
     452            if (($opt{S} ne '')&& !(is_mapped($key,$opt{S}))) {
     453                return(0); # Not the remapped skycell requested
     454            }
     455            return(1);
     456        }           
     457
     458    }
     459    return(0);
     460}
     461
     462sub is_valid_diff {
     463    my $key = shift;
     464    if ($key =~ /$diff_prefix/) {
     465        if ($opt{D} && ($key !~ /SR/)) {
     466            return(0); # Not destreaked when required
     467        }
     468        if (($opt{S} ne '')&&($key !~ /$opt{S}/)) {
     469            return(0); # Not the requested skycell
     470        }
     471        if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) {
     472            return(0); # Not the remapped OTA requested
     473        }
     474       
     475        if ($opt{A}) {
     476            return(1); # You asked for all,
     477        }
     478        elsif ($opt{L}) {
     479            if ($key =~ /log/) {
     480                return(1);
     481            }
     482            else {
     483                return(0);
     484            }
     485        }
     486        elsif ($opt{V} && ($key =~ /cmf/)) {
     487            return(1);
     488        }
     489        elsif ($key !~ /fits/) {
     490            return(0); # Not a fits
     491        }
     492        elsif ($key =~ /refConv/) {
     493            return(0);
     494        }
     495        elsif ($key =~ /inConv/) {
     496            return(0);
     497        }
     498        elsif ($key =~ /inv/) {
     499            return(0);
     500        }
     501        elsif ($key =~ /wt.fits/) {
     502            return(0); # No handler for weight right now.
     503        }
     504
     505        elsif ($key =~ /mask/) {
     506            if ($opt{M}) {
     507                return(1); # Requested mask
     508            }
     509            else {
     510                return(0);
     511            }
     512        }
     513        else {
     514            return(1); # Should be just the warp.
     515        }
     516    }
     517   
     518    return(0);
     519}
     520sub is_valid_warp {
     521    my $key = shift;
     522   
     523    if ($opt{D} && ($key !~ /SR/)) {
     524        return(0); # Not destreaked when required
     525    }
     526    elsif ($key !~ /wrp.${warp_id}/) {
     527        return(0); # Not a warp from this warp_id
     528    }
     529    if (($opt{S} ne '')&&($key !~ /$opt{S}/)) {
     530        return(0); # Not the requested skycell
     531    }
     532    if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) {
     533        return(0); # Not the remapped OTA requested
     534    }
     535           
     536    if ($opt{A}) {
     537        return(1); # You asked for all,
     538    }
     539    elsif ($opt{L}) {
     540        if ($key =~ /log/) {
     541            return(1);
     542        }
     543        else {
     544            return(0);
     545        }
     546    }
     547    elsif ($opt{V} && ($key =~ /cmf/)) {
     548        return(1);
     549    }
     550    elsif ($key !~ /fits/) {
     551        return(0); # Not a fits
     552    }
     553    elsif ($key =~ /wt.fits/) {
     554        return(0); # No handler for weight right now.
     555    }
     556    elsif ($key =~ /mask/) {
     557        if ($opt{M}) {
     558            return(1); # Requested mask
     559        }
     560        else {
     561            return(0);
     562        }
     563    }
     564    else {
     565        return(1); # Should be just the warp.
     566    }
     567    return(0);
     568}
Note: See TracChangeset for help on using the changeset viewer.