Index: /trunk/dbconfig/changes.txt
===================================================================
--- /trunk/dbconfig/changes.txt	(revision 29494)
+++ /trunk/dbconfig/changes.txt	(revision 29495)
@@ -1946,4 +1946,6 @@
 ALTER TABLE stackSummary DROP PRIMARY KEY, ADD PRIMARY KEY (sass_id, projection_cell);
 
+ALTER TABLE stackSumSkyfile ADD COLUMN mjd_obs double AFTER good_frac;
+
 -- changes to support cleanup of the background preserved images
 ALTER TABLE chipBackgroundImfile ADD COLUMN data_state VARCHAR(64) AFTER path_base;
@@ -1952,3 +1954,8 @@
 ALTER TABLE warpBackgroundSkyfile  ADD KEY(data_state);
 
-ALTER TABLE stackSumSkyfile ADD COLUMN mjd_obs double AFTER good_frac;
+ALTER TABLE magicMask ADD COLUMN path_base VARCHAR(255) AFTER uri;
+
+-- diff_id was removed from magicInputSkyfile ages ago, but
+-- pxadmin_create_tables.sql still had it this command didn't work due to
+-- a mysql error.
+-- ALTER TABLE magicInputSkyfile DROP COLUMN diff_id;
Index: /trunk/dbconfig/magic.md
===================================================================
--- /trunk/dbconfig/magic.md	(revision 29494)
+++ /trunk/dbconfig/magic.md	(revision 29495)
@@ -42,4 +42,5 @@
     magic_id    S64         0       # Primary Key fkey(magic_id) ref magicRun(magic_id)
     uri         STR         255
+    path_base   STR         255
     streaks     S32         0
     fault       S16         0       # Key
Index: /trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- /trunk/ippScripts/scripts/magic_destreak.pl	(revision 29494)
+++ /trunk/ippScripts/scripts/magic_destreak.pl	(revision 29495)
@@ -42,4 +42,5 @@
 # Parse the command-line arguments
 my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base, $cam_reduction);
+my ($streaks_path_base, $inv_streaks_path_base);
 my ($outroot, $recoveryroot, $magicked);
 my ($replace, $release);
@@ -49,4 +50,7 @@
            'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
            'camera=s'       => \$camera,     # camera for evaluating file rules
+           'streaks_path_base=s'      => \$streaks_path_base,    # path_base for streaks data
+           'inv_streaks_path_base=s'  => \$inv_streaks_path_base, #path_base for streaks from inverse diff
+           'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
            'streaks=s'      => \$streaks,    # file containing the list of streaks
            'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
@@ -78,4 +82,5 @@
     defined $camera and
     defined $streaks and
+    defined $streaks_path_base and
     defined $stage and
     defined $stage_id and
@@ -108,4 +113,5 @@
     &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
 }
+$inv_streaks_path_base = undef if defined($inv_streaks_path_base) and ($inv_streaks_path_base eq "NULL");
 $inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL");
 
@@ -240,4 +246,20 @@
     my ($allstreaks_fh, $allstreaks_name);
 
+    # Set name of streaks files from their path_base. Note. ne 'NULL' test is for backward compatability
+    # with runs that don't have path_base set yet
+    if ($streaks_path_base ne 'NULL') {
+        $streaks = "$streaks_path_base.streaks";
+    }
+    if ($inv_streaks_path_base and ($inv_streaks_path_base ne 'NULL')) {
+        $inv_streaks = "$inv_streaks_path_base.streaks";
+    }
+
+    my $streaks_resolved = $ipprc->file_resolve($streaks) or &my_die("failed to resolve streaks file $streaks", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR);
+    my $inv_streaks_resolved;
+    if ($inv_streaks) {
+        $inv_streaks_resolved = $ipprc->file_resolve($inv_streaks) or &my_die("failed to resolve inverse streaks file $inv_streaks", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR);
+    }
+        
+
     if ($stage eq "raw") {
         $image = $uri;
@@ -301,5 +323,5 @@
         $sources    = $ipprc->filename("PPSUB.OUTPUT.SOURCES", $path_base);
 
-        if ($inv_streaks) {
+        if ($inv_streaks_resolved) {
             # create a temporary file containing the contents of the
             # two streaks files
@@ -307,13 +329,13 @@
                     UNLINK => !$save_temps);
 
-            combine_streaks($allstreaks_fh, $streaks, $inv_streaks);
+            combine_streaks($allstreaks_fh, $streaks_resolved, $inv_streaks_resolved);
 
             # apply the combined streaks to both the forward and inverse diffs
-            $streaks = $allstreaks_name;
+            $streaks_resolved = $allstreaks_name;
         }
     }
 
     {
-        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
+        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks_resolved -image $image";
 
         $command .= " -stats $statsFile";
@@ -340,5 +362,5 @@
         }
     }
-    if (($stage eq "diff") and $inv_streaks) {
+    if (($stage eq "diff") and $inv_streaks_resolved) {
         $image   = $ipprc->filename("PPSUB.INVERSE", $path_base);
         $mask    = $ipprc->filename("PPSUB.INVERSE.MASK", $path_base);
@@ -349,5 +371,5 @@
         my $invStatsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.inv.stats";
 
-        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
+        my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks_resolved -image $image";
         $command .= " -stats $invStatsFile";
 
Index: /trunk/ippScripts/scripts/magic_process.pl
===================================================================
--- /trunk/ippScripts/scripts/magic_process.pl	(revision 29494)
+++ /trunk/ippScripts/scripts/magic_process.pl	(revision 29495)
@@ -325,6 +325,29 @@
 }
 
+### Input result into database
+{
+    my $command = "$magictool -addresult";
+    $command   .= " -magic_id $magic_id";
+    $command   .= " -node $node";
+    $command   .= " -path_base $outroot";
+    $command   .= " -dbname $dbname" if defined $dbname;
+
+    # Add the processed file to the database
+    unless ($no_update) {
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
+        }
+    } else {
+        print "Skipping command: $command\n";
+    }
+}
 
 if ($node eq "root") {
+    # XXXX: Since we just added the result above, all of these my_dies are going to fail
+    # with a duplicate row error.
+    # see more comments below
     my $streaks_file = "$outroot.streaks";
     my $resolved = $ipprc->file_resolve($streaks_file);
@@ -389,27 +412,4 @@
     }
 
-### Input result into database
-# XXXX: if this succeeds but addmask fails the magicRun is in a goofy state XXXX
-{
-    my $command = "$magictool -addresult";
-    $command   .= " -magic_id $magic_id";
-    $command   .= " -node $node";
-    $command   .= " -path_base $outroot";
-    $command   .= " -dbname $dbname" if defined $dbname;
-
-    # Add the processed file to the database
-    unless ($no_update) {
-        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-            run(command => $command, verbose => $verbose);
-        unless ($success) {
-            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-            &my_die("Unable to perform magictool -addresult: $error_code", $magic_id, $node, $error_code);
-        }
-    } else {
-        print "Skipping command: $command\n";
-    }
-}
-
-
     {
         my $command = "$magictool -addmask";
@@ -425,5 +425,9 @@
             unless ($success) {
                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-                # This isn't going to work because our result was already entered.
+                # XXX: This my_die isn't going to work because the result for the root node was already
+                # added to the database up above.
+                # There is a magicMask has a fault column. Maybe we should 
+                # use that and add a new revert mode that deletes the magicMask and the magicNodeResult
+                # for the root node.
                 &my_die("Unable to perform magictool -addmask: $error_code", $magic_id, $node, $error_code);
             }
@@ -433,4 +437,5 @@
     }
 }
+
 
 ### Pau.
Index: /trunk/ippTools/share/magicdstool_todestreak_camera.sql
===================================================================
--- /trunk/ippTools/share/magicdstool_todestreak_camera.sql	(revision 29494)
+++ /trunk/ippTools/share/magicdstool_todestreak_camera.sql	(revision 29495)
@@ -7,5 +7,7 @@
     camera,
     magicMask.uri AS streaks_uri,
+    magicMask.path_base AS streaks_path_base,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
+    CAST(NULL AS CHAR(255)) AS inv_streaks_path_base,
     stage,
     stage_id,
Index: /trunk/ippTools/share/magicdstool_todestreak_chip.sql
===================================================================
--- /trunk/ippTools/share/magicdstool_todestreak_chip.sql	(revision 29494)
+++ /trunk/ippTools/share/magicdstool_todestreak_chip.sql	(revision 29495)
@@ -7,5 +7,7 @@
     camera,
     magicMask.uri AS streaks_uri,
+    magicMask.path_base AS streaks_path_base,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
+    CAST(NULL AS CHAR(255)) AS inv_streaks_path_base,
     stage,
     stage_id,
Index: /trunk/ippTools/share/magicdstool_todestreak_diff.sql
===================================================================
--- /trunk/ippTools/share/magicdstool_todestreak_diff.sql	(revision 29494)
+++ /trunk/ippTools/share/magicdstool_todestreak_diff.sql	(revision 29495)
@@ -7,5 +7,7 @@
     rawExp.camera,
     magicMask.uri AS streaks_uri,
+    magicMask.path_base AS streaks_path_base,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
+    CAST(NULL AS CHAR(255)) AS inv_streaks_path_base,
     stage,
     magicRun.diff_id AS stage_id,
@@ -52,5 +54,7 @@
     rawExp.camera,
     magicMask.uri AS streaks_uri,
+    magicMask.path_base AS streaks_path_base,
     (SELECT uri from magicMask where magic_id = inv_magic_id) AS inv_streaks_uri,
+    (SELECT path_base from magicMask where magic_id = inv_magic_id) AS inv_streaks_path_base,
     stage,
     magicRun.diff_id AS stage_id,
Index: /trunk/ippTools/share/magicdstool_todestreak_raw.sql
===================================================================
--- /trunk/ippTools/share/magicdstool_todestreak_raw.sql	(revision 29494)
+++ /trunk/ippTools/share/magicdstool_todestreak_raw.sql	(revision 29495)
@@ -6,5 +6,7 @@
     rawExp.camera,
     magicMask.uri as streaks_uri,
+    magicMask.path_base as streaks_path_base,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
+    CAST(NULL AS CHAR(255)) AS inv_streaks_path_base,
     stage,
     stage_id,
Index: /trunk/ippTools/share/magicdstool_todestreak_warp.sql
===================================================================
--- /trunk/ippTools/share/magicdstool_todestreak_warp.sql	(revision 29494)
+++ /trunk/ippTools/share/magicdstool_todestreak_warp.sql	(revision 29495)
@@ -6,5 +6,7 @@
     camera,
     magicMask.uri as streaks_uri,
+    magicMask.path_base as streaks_path_base,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
+    CAST(NULL AS CHAR(255)) AS inv_streaks_path_base,
     stage,
     stage_id,
Index: /trunk/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- /trunk/ippTools/share/pxadmin_create_tables.sql	(revision 29494)
+++ /trunk/ippTools/share/pxadmin_create_tables.sql	(revision 29495)
@@ -1221,9 +1221,7 @@
 CREATE TABLE magicInputSkyfile (
         magic_id BIGINT,
-        diff_id BIGINT,
         node VARCHAR(64),
-        PRIMARY KEY(magic_id, diff_id, node),
-        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id),
-        FOREIGN KEY(diff_id) REFERENCES diffRun(diff_id)
+        PRIMARY KEY(magic_id, node),
+        FOREIGN KEY(magic_id) REFERENCES magicRun(magic_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
@@ -1253,4 +1251,5 @@
         magic_id BIGINT,
         uri VARCHAR(255),
+        path_base VARCHAR(255),
         streaks INT,
         fault SMALLINT,
Index: /trunk/ippTools/src/magictool.c
===================================================================
--- /trunk/ippTools/src/magictool.c	(revision 29494)
+++ /trunk/ippTools/src/magictool.c	(revision 29495)
@@ -1182,5 +1182,6 @@
 
     // optional
-    PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);
+//    PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);
+    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
     PXOPT_LOOKUP_S32(streaks, config->args, "-streaks", false, false);
 
@@ -1195,5 +1196,6 @@
     if (!magicMaskInsert(config->dbh,
                          magic_id,
-                         uri,
+                         NULL,
+                         path_base,
                          streaks,
                          fault
Index: /trunk/ippTools/src/magictoolConfig.c
===================================================================
--- /trunk/ippTools/src/magictoolConfig.c	(revision 29494)
+++ /trunk/ippTools/src/magictoolConfig.c	(revision 29495)
@@ -152,5 +152,5 @@
     psMetadata *addmaskArgs = psMetadataAlloc();
     psMetadataAddS64(addmaskArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID (required)", 0);
-    psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-uri", 0, "define URI", NULL);
+    psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-path_base", 0, "define path_base (required)", NULL);
     psMetadataAddS32(addmaskArgs, PS_LIST_TAIL, "-streaks", 0, "define number of streaks", 0);
     psMetadataAddS16(addmaskArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
