Index: trunk/ippScripts/scripts/warp_overlap.pl
===================================================================
--- trunk/ippScripts/scripts/warp_overlap.pl	(revision 17897)
+++ trunk/ippScripts/scripts/warp_overlap.pl	(revision 18055)
@@ -27,9 +27,9 @@
 my $ipprc = PS::IPP::Config->new(); # IPP configuration
 
-my ($warp_id, $camera, $tess_id, $dbname, $verbose, $no_update, $no_op, $save_temps);
+my ($warp_id, $camera, $tess_dir, $dbname, $verbose, $no_update, $no_op, $save_temps);
 GetOptions(
     'warp_id|i=s'       => \$warp_id, # Warp identifier
     'camera|c=s'        => \$camera, # Camera name
-    'tess_id=s'         => \$tess_id, # Tessellation identifier
+    'tess_dir=s'        => \$tess_dir, # Tessellation directory
     'dbname|d=s'        => \$dbname, # Database name
     'verbose'           => \$verbose,   # Print to stdout
@@ -41,9 +41,9 @@
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
 pod2usage(
-    -msg => "Required options: --warp_id --camera --tess_id",
+    -msg => "Required options: --warp_id --camera --tess_dir",
     -exitval => 3,
 ) unless defined $warp_id
     and defined $camera
-    and defined $tess_id;
+    and defined $tess_dir;
 
 $ipprc->define_camera($camera);
@@ -79,8 +79,7 @@
 }
 
-# Where do we get the astrometry source from?
-my $astromSource;               # The astrometry source
+# Where do we get the astrometry source from? 
+my $astromSource;               # The astrometry source filerule (eg, PSASTRO.OUTPUT, PSASTRO.OUTPUT.MEF)
 my $astromAccept;               # Accept the astrometry unconditionally?
-my $astromDepth;                # File level of the astrometry source (SPLIT or MEF)?
 {
     my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
@@ -95,8 +94,5 @@
     $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     $astromAccept = metadataLookupBool($metadata, 'ASTROM.ACCEPT');
-    $astromDepth  = metadataLookupStr($metadata, 'ASTROM.DEPTH');
-}
-
-
+}
 
 # Determine the imfile/skycell overlaps
@@ -105,43 +101,25 @@
     # Calculate the overlaps between imfiles and skycells
 
-    my $tess_dir = $ipprc->tessellation_catdir( $tess_id ); # Tessellation catdir for DVO
-    $tess_dir = $ipprc->convert_filename_absolute( $tess_dir );
+    # tess_dir is the DVO db holding the tessalations
+    # this may be an abstract name in site.config:TESSELLATIONS, a URI, or an absolute path.
+    # convert this to an absolute path
+    my $tess_dir_abs = $ipprc->tessellation_catdir( $tess_dir ); # Tessellation catdir for DVO
+    $tess_dir_abs = $ipprc->convert_filename_absolute( $tess_dir_abs );
 
     my %unique_skycells = (); # Identified skycells (all unique by virtue of hash property)
 
-    # XXX this is a bit too hard wired: the concept is that astrometry comes from the MOSAIC vs CHIP output
-    # XXX we have moved the astrometry analysis to the camera stage only: we should always have the source be MEF
-    if ($astromSource eq 'PSASTRO.OUTPUT.MEF') {
-        # We have a MEF astrometry file from psastro
-        my $imfile = $imfiles->[0];
-        my $camRoot = $imfile->{cam_path_base};
-        my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file
-
-        my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
-        if (! @matchlist) {
-            &my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR);
-        }
-        # Match each of the imfiles to this list
-        foreach my $imfile (@$imfiles) {
-            extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
-        }
-    } else {
-        # We have per-imfile astrometry
-        foreach my $imfile (@$imfiles) {
-            my $astromFile;
-            if ($astromSource eq 'PSASTRO.OUTPUT') {
-                my $chipRoot = $imfile->{chip_path_base};
-                my $classID = $imfile->{class_id};
-                $astromFile = $ipprc->filename($astromSource, $chipRoot, $classID); # Astrometry file
-            } else {
-                $astromFile = $imfile->{chip_uri}; # Astrometry file
-            }
-            my @matchlist = get_overlaps($astromFile, $tess_dir, $astromAccept); # List of overlaps
-            if (! @matchlist and $verbose) {
-                print "skipping $astromFile\n";
-            }
-
-            extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_id, \@overlaps, \%unique_skycells);
-        }
+    # astrometry is always determined at the camera stage; we have a MEF astrometry file from psastro
+    my $imfile = $imfiles->[0];
+    my $camRoot = $imfile->{cam_path_base};
+    my $astromFile = $ipprc->filename($astromSource, $camRoot); # Astrometry file
+
+    my @matchlist = get_overlaps($astromFile, $tess_dir_abs, $astromAccept); # List of overlaps
+    if (! @matchlist) {
+	&my_die("Unable to perform dvoImageOverlaps: missing astrometry", $warp_id, $PS_EXIT_DATA_ERROR);
+    }
+    # Match each of the imfiles to this list (the input images may be split, but the astrometry is not)
+    # tess_dir (not tess_dir_abs) is supplied here so it may be written to the db
+    foreach my $imfile (@$imfiles) {
+	extract_overlaps(\@matchlist, $imfile, $astromFile, $tess_dir, \@overlaps, \%unique_skycells);
     }
 } else {
@@ -150,5 +128,5 @@
         my %overlap = ();
         $overlap{skycell_id} = 'default';
-        $overlap{tess_id}    = 'default';
+        $overlap{tess_dir}   = 'default';
         $overlap{cam_id}     = $imfile->{cam_id};
         $overlap{class_id}   = $imfile->{class_id};
@@ -170,5 +148,6 @@
     print $overlapFile "  warp_id        S32    $warp_id\n";
     print $overlapFile "  skycell_id     STR    $overlap->{skycell_id}\n";
-    print $overlapFile "  tess_id        STR    $overlap->{tess_id}\n";
+    # XXX convert tess_id here to tess_dir when db scheme is updated
+    print $overlapFile "  tess_id        STR    $overlap->{tess_dir}\n"; 
     print $overlapFile "  cam_id         S32    $overlap->{cam_id}\n";
     print $overlapFile "  class_id       STR    $overlap->{class_id}\n";
@@ -215,8 +194,8 @@
 {
     my $filename = shift;       # Filename on which to run dvoImageOverlaps
-    my $tess_dir = shift;       # Tessellation directory
+    my $tess_dir_abs = shift;       # Tessellation directory
     my $accept = shift;         # Do we use the -accept-astrom flag?
 
-    my $command = "$dvoImageOverlaps -D CATDIR $tess_dir " . $ipprc->file_resolve($filename);
+    my $command = "$dvoImageOverlaps -D CATDIR $tess_dir_abs " . $ipprc->file_resolve($filename);
     $command .= ' -accept-astrom' if $accept;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -248,5 +227,5 @@
     my $imfile = shift;         # Imfile information
     my $filename = shift;       # Filename used with dvoImageOverlaps
-    my $tess_id = shift;        # Tessellation identifier
+    my $tess_dir = shift;        # Tessellation identifier
     my $overlaps = shift;       # Reference to list of overlaps
     my $unique_skycells = shift; # Reference to hash of found skycells
@@ -259,9 +238,8 @@
     my $fileLevel = $imfile->{filelevel};
     my $entry;  # How to identify this imfile in the dvoImageOverlaps output
-    if ((lc($fileLevel) eq "chip") && (lc($astromDepth) eq "mef")) {
+    if (lc($fileLevel) eq "chip") {
         my $class_id = $imfile->{class_id};
         my $chipRoot = $ipprc->file_resolve( $imfile->{chip_path_base} );
         my $extname = $ipprc->extname_rule("CMF.HEAD", $class_id); # MEF psastro output
-
 
         $entry = $filename . '\[' . $extname . '\]';
@@ -278,5 +256,5 @@
         my %overlap = ();       # Overlap information for warptool
         $overlap{skycell_id} = $skycell;
-        $overlap{tess_id}    = $tess_id;
+        $overlap{tess_dir}   = $tess_dir;
         $overlap{cam_id}     = $imfile->{cam_id};
         $overlap{class_id}   = $imfile->{class_id};
