Index: trunk/tools/gpc1_find_images.pl
===================================================================
--- trunk/tools/gpc1_find_images.pl	(revision 26561)
+++ trunk/tools/gpc1_find_images.pl	(revision 26563)
@@ -3,5 +3,5 @@
 use DBI;
 use Getopt::Std;
-getopts('hFARCPp:BLMDWIYTvx:n:c:w:s:O:S:N:',\%opt);
+getopts('hEFARCPp:BLMDWIJVYTvx:n:c:w:s:d:e:O:S:N:',\%opt);
 #getopt('xncwOS:hARCW',\%opt);
 unless (exists($opt{O})) {
@@ -34,10 +34,17 @@
 }
 
+# abcdefghijklmnopqrstuvwxyz
+#used:
+# ABCDEF     LMNOP RST  W Y
+#   c    h     n    s  vwx  
 if (exists($opt{h})) {
     print "USAGE find_images.pl ... \n";
     print "          -h              This help\n";
-    print "          -R              Return raw data.\n";
-    print "          -C              Return chip stage data.\n";
-    print "          -W              Return warp stage data.\n";
+    print "          -R              Return Raw data.\n";
+    print "          -C              Return Chip stage data.\n";
+    print "          -E              Return camEra stage data.\n";
+    print "          -W              Return Warp stage data.\n";
+    print "          -T              Get the sTacks for a given input.\n";
+    print "          -J              Get the dIff stage data (warps only for now).\n";
     print "          -A              Return not just fits images.\n";
     print "          -F              Convert to real filenames.\n";
@@ -45,13 +52,16 @@
     print "          -B              Return burntool table.\n";
     print "          -M              Include masks in results.\n";
+    print "          -L              Return the log files from this stage.\n";
     print "          -D              Return only pre-destreaked images.\n";
     print "          -Y              Yes, I want the raw, even if it's not been processed.\n";
-    print "          -T              Get the sTacks for a given input.\n";
+    print "          -V              Return the cmf or smf files.\n";
     print "          -v              Be verbose on output.\n";
     print " \n";
     print "          -x <exp_id>     Specify a exp_id.\n";
     print "          -c <chip_id>    ...\n";
+    print "          -e <cam_id>     ...\n";
     print "          -w <warp_id>    ...\n";
     print "          -s <stack_id>   ...\n";
+    print "          -d <diff_id>    ...\n";
     print "          -n <exp_name>   ...\n";
     print " \n";
@@ -66,6 +76,6 @@
 $dbname = 'gpc1';
 $dbserver = 'ippdb01';
-$dbuser = 'ipp';
-$dbpass = 'ipp';
+$dbuser = 'ippuser';
+$dbpass = 'ippuser';
 $db = DBI->connect("DBI:mysql:database=${dbname};host=${dbserver};" .
                    "mysql_socket=" . DB_SOCKET(),
@@ -75,8 +85,8 @@
 
 if ($opt{Y}) {
-    $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 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)";
+    $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)";
 }
 else {
-    $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)";
+    $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)";
 }
 
@@ -95,4 +105,7 @@
 if (exists($opt{w})) {
     push @sth_adds, "warpRun.warp_id = $opt{w}";
+}
+if (exists($opt{e})) {
+    push @sth_adds, "camRun.cam_id = $opt{e}";
 }
 if (exists($opt{s})||exists($opt{T})) {
@@ -107,4 +120,14 @@
     $sth_base .= ' JOIN stackInputSkyfile USING (warp_id) JOIN stackSumSkyfile USING (stack_id) JOIN stackRun USING (stack_id)';
 #    print "$sth_base\n";
+}
+if (exists($opt{J})||(exists($opt{d}))) {
+    if (exists($opt{d})&&($opt{d} != 0)) {
+	push @sth_adds, "diffRun.diff_id = $opt{d}";
+    }
+    $sth_base =~ s/0,'nodiff'/diffRun.diff_id,diffSkyfile.path_base/;
+    if (exists($opt{J})) {
+#	$sth_base .= ' RIGHT OUTER ';
+    }
+    $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)';
 }
 if ($#sth_adds != -1) {
@@ -124,5 +147,8 @@
     ($warp_id, $warp_workdir, $chip_id, $chip_workdir, 
      $exp_name, $exp_id, $exp_workdir, $exp_dateobs, $exp_pontime,
-     $stack_id, $stack_sumfile_uri) = @{ $rr };
+     $stack_id, $stack_sumfile_uri,
+     $cam_id, $cam_workdir,
+     $diff_id, $diff_workdir
+    ) = @{ $rr };
     if ($stack_id == 0) {
 	$stack_sumfile_uri = '';
@@ -132,4 +158,6 @@
     if (exists($opt{I})) {
 	$stack_id = 0; # Ditto.
+	$cam_id = 0;
+	$diff_id = 0;
     }
     if (exists($opt{N})) {
@@ -231,4 +259,15 @@
 	close(NLS);
     }
+    if (exists($opt{E})) {
+	open(NLS,"neb-ls $cam_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls";
+	while (<NLS>) {
+	    chomp;
+	    if (is_valid_cam($_)) {
+		push @scan, $_;
+		$found++;
+	    }
+	}
+	close(NLS);
+    }
     if (exists($opt{W})) {
 	open(NLS,"neb-ls $warp_workdir/${exp_name}.${exp_id}/ |") || die "can't neb-ls";
@@ -241,4 +280,18 @@
 	}
     }
+    if (exists($opt{J})) {
+	@diff_tmp = split /\//, $diff_workdir;
+	$diff_prefix = pop(@diff_tmp);
+	$diff_true_dir = join '/',@diff_tmp;
+
+	open(NLS,"neb-ls $diff_true_dir |") || die "can't neb-ls";
+	while (<NLS>) {
+	    chomp;
+	    if (is_valid_diff($_)) {
+		push @scan, $_;
+		$found++;
+	    }
+	}
+    }
     if (exists($opt{s})||exists($opt{T})) {
 	if (defined($stack_sumfile_uri)) {
@@ -354,4 +407,7 @@
 	}
     }
+    elsif ($opt{V} && ($key =~ /cmf/)) {
+	return(1);
+    }
     elsif ($key !~ /fits/) {
 	return(0); # Not a fits
@@ -375,4 +431,68 @@
 }
 
+sub is_valid_cam {
+    my $key = shift;
+    if ($key =~ /\.cm\./) {
+	if ($opt{A}) {
+	    return(1);
+	}
+	elsif ($opt{L} && ($key =~ /log/)) {
+	    return(1);
+	}
+	elsif ($opt{V} && ($key =~ /smf/)) {
+	    return(1);
+	}
+    }
+    return(0);
+}
+
+sub is_valid_diff {
+    my $key = shift;
+    if ($key =~ /$diff_prefix/) {
+	if ($opt{D} && ($key !~ /SR/)) {
+	    return(0); # Not destreaked when required
+	}
+	if (($opt{S} ne '')&&($key !~ /$opt{S}/)) {
+	    return(0); # Not the requested skycell
+	}
+	if (($opt{O} ne '')&& !(is_mapped($key,$opt{O}))) {
+	    return(0); # Not the remapped OTA requested
+	}
+	
+	if ($opt{A}) {
+	    return(1); # You asked for all, 
+	}
+	elsif ($opt{L}) {
+	    if ($key =~ /log/) {
+		return(1);
+	    }
+	    else {
+		return(0);
+	    }
+	}
+	elsif ($opt{V} && ($key =~ /cmf/)) {
+	    return(1);
+	}
+	elsif ($key !~ /fits/) {
+	    return(0); # Not a fits
+	}
+	elsif ($key =~ /wt.fits/) {
+	    return(0); # No handler for weight right now.
+	}
+	elsif ($key =~ /mask/) {
+	    if ($opt{M}) {
+		return(1); # Requested mask
+	    }
+	    else {
+		return(0);
+	    }
+	}
+	else {
+	    return(1); # Should be just the warp.
+	}
+    }
+    
+    return(0);
+}
 sub is_valid_warp {
     my $key = shift;
@@ -402,4 +522,7 @@
 	}
     }
+    elsif ($opt{V} && ($key =~ /cmf/)) {
+	return(1);
+    }
     elsif ($key !~ /fits/) {
 	return(0); # Not a fits
@@ -421,7 +544,2 @@
     return(0);
 }
-	
-
-
-    
-    
