Index: trunk/dbconfig/det.md
===================================================================
--- trunk/dbconfig/det.md	(revision 14168)
+++ trunk/dbconfig/det.md	(revision 14231)
@@ -32,15 +32,15 @@
 
 detInputExp METADATA
-    det_id      S64         0       # Primary Key INDEX(det_id, exp_id) fkey (det_id) ref detRun(det_id)
-    iteration   S32         0       # Primary Key INDEX(det_id, iteration)
-    exp_id     S64         64       # Primary Key fkey (exp_id) ref rawExp(exp_id)
-    include     BOOL        f
+    det_id      S64         0       # Primary Key fkey(det_id) ref detRun(det_id)
+    iteration   S32         0       # Primary Key fkey(exp_id) ref rawExp(exp_id)
+    exp_id     S64         64       # Primary Key INDEX(det_id, exp_id)
+    include     BOOL        f       # INDEX(det_id, iteration)
 END
 
 detProcessedImfile METADATA
-    det_id      S64         0      # Primary Key fkey (det_id, exp_id) ref detInputExp(det_id, exp_id) 
-    exp_id     S64         64      # Primary Key fkey (exp_id, class_id) ref rawImfile(exp_id, class_id)
-    class_id    STR         64     # Primary Key INDEX(det_id, class_id)
-    uri         STR         255
+    det_id      S64         0       # Primary Key fkey(det_id, exp_id) ref detInputExp(det_id, exp_id) 
+    exp_id     S64         64       # Primary Key fkey(exp_id, class_id) ref rawImfile(exp_id, class_id)
+    class_id    STR         64      # Primary Key INDEX(det_id, class_id)
+    uri         STR         255     # INDEX(det_id, exp_id)
     recipe      STR         64
     bg          F64         0.0
@@ -61,24 +61,28 @@
 detProcessedExp METADATA
     det_id      S64         0       # Primary Key fkey(det_id, exp_id) ref detInputExp(det_id, exp_id)
-    exp_id     S64         64       # Primary Key
-    recipe      STR         64
-    bg          F64         0.0
-    bg_stdev    F64         0.0
-    bg_mean_stdev   F64     0.0
-    fringe_0    F64         0.0
-    fringe_1    F64         0.0
-    fringe_2    F64         0.0
-    user_1      F64         0.0
-    user_2      F64         0.0
-    user_3      F64         0.0
-    user_4      F64         0.0
-    user_5      F64         0.0
-    path_base   STR         255
-    fault       S16         0       # Key NOT NULL
-END
-
+    exp_id     S64         64       # Primary Key fkey(det_id, exp_id) ref detProcessedImfile(det_id, exp_id)
+    recipe      STR         64
+    bg          F64         0.0
+    bg_stdev    F64         0.0
+    bg_mean_stdev   F64     0.0
+    fringe_0    F64         0.0
+    fringe_1    F64         0.0
+    fringe_2    F64         0.0
+    user_1      F64         0.0
+    user_2      F64         0.0
+    user_3      F64         0.0
+    user_4      F64         0.0
+    user_5      F64         0.0
+    path_base   STR         255
+    fault       S16         0       # Key NOT NULL
+END
+
+#
+# detStackedImfile does not depend on detProcessedExp. detProcesedExp is purely
+# FYI values and can be calculated in parellel
+#
 detStackedImfile METADATA
     det_id      S64         0       # Primary Key fkey(det_id, iteration) ref detInputExp(det_id, iteration)
-    iteration   S32         0       # Primary Key fkey(det_id, class_id) ref  detProcessedImfile(det_id, class_id)
+    iteration   S32         0       # Primary Key fkey(det_id, class_id) ref detProcessedImfile(det_id, class_id)
     class_id    STR         64      # Primary Key
     uri         STR         255
@@ -96,6 +100,6 @@
 
 detNormalizedStatImfile METADATA
-    det_id      S64         0       # Primary Key fkey(det_id, iteration, class_id) ref detStackedImfile(det_id, iteration, class_id)
-    iteration   S32         0       # Primary Key
+    det_id      S64         0       # Primary Key fkey(det_id, iteration) ref detInputExp(det_id, iteration)
+    iteration   S32         0       # Primary Key fkey(det_id, iteration, class_id) ref detStackedImfile(det_id, iteration, class_id)
     class_id    STR         64      # Primary Key
     norm        F32         0.0
@@ -103,12 +107,8 @@
 END
 
-# we can not setup a fkey against detStackedImfile here as it would preference
-# detrend registration nor can we fkey iteration as a registered detrend image
-# will not have any entrires in detInputExp
-
 detNormalizedImfile METADATA
-    det_id      S64         0       # Primary Key INDEX(det_id, iteration) fkey(det_id) ref detInputExp(det_id)
-    iteration   S32         0       # Primary Key 
-    class_id    STR         64      # Primary Key
+    det_id      S64         0       # Primary Key fkey(det_id) ref detInputExp(det_id)
+    iteration   S32         0       # Primary Key fkey(det_id, iteration, class_id) ref detNormalizedStatImfile(det_id, iteration, class_id)
+    class_id    STR         64      # Primary Key INDEX(det_id, iteration)
     uri         STR         255
     bg          F64         0.0
@@ -125,6 +125,6 @@
 
 detNormalizedExp METADATA
-    det_id      S64         0       # Primary Key fkey(det_id, iteration) ref detNormalizedImfile(det_id, iteration)
-    iteration   S32         0       # Primary Key
+    det_id      S64         0       # Primary Key fkey(det_id, iteration) ref detInputExp(det_id, iteration)
+    iteration   S32         0       # Primary Key fkey(det_id, iteration) ref detNormalizedImfile(det_id, iteration)
     recipe      STR         64
     bg          F64         0.0
@@ -155,8 +155,8 @@
 
 detResidImfile METADATA
-    det_id      S64         0       # Primary Key
-    iteration   S32         0       # Primary Key
-    exp_id     S64         64      # Primary Key
-    class_id    STR         64      # Primary Key
+    det_id      S64         0       # Primary Key fkey(det_id, iteration, exp_id) ref detInputExp(det_id, iteration, exp_id)
+    iteration   S32         0       # Primary Key fkey(det_id, exp_id, class_id) ref detProcessedImfile(det_id, exp_id, class_id)
+    exp_id     S64         64       # Primary Key fkey(det_id, iteration) ref detNormalizedExp(det_id, iteration)
+    class_id    STR         64      # Primary Key INDEX(det_id, iteration, exp_id)
     uri         STR         255
     recipe      STR         64
@@ -178,7 +178,7 @@
 
 detResidExp METADATA
-    det_id      S64         0       # Primary Key
-    iteration   S32         0       # Primary Key
-    exp_id     S64         64      # Primary Key
+    det_id      S64         0       # Primary Key fkey(det_id, iteration, exp_id) ref detInputExp(det_id, iteration, exp_id)
+    iteration   S32         0       # Primary Key fkey(det_id, iteration, exp_id) ref detResidImfile(det_id, iteration, exp_id)
+    exp_id     S64         64       # Primary Key INDEX(det_id, iteration)
     recipe      STR         64
     bg          F64         0.0
@@ -201,5 +201,5 @@
 detRunSummary METADATA
     det_id      S64         0       # Primary Key fkey(det_id, iteration) ref detInputExp(det_id, iteration)
-    iteration   S32         0       # Primary Key
+    iteration   S32         0       # Primary Key fkey(det_id, iteration) ref detResidExp(det_id, iteration)
     bg          F64         0.0
     bg_stdev    F64         0.0
