Index: trunk/ippTasks/detrend.process.pro
===================================================================
--- trunk/ippTasks/detrend.process.pro	(revision 11210)
+++ trunk/ippTasks/detrend.process.pro	(revision 11323)
@@ -27,4 +27,8 @@
   book listbook detPendingProcessedExp
 end
+
+# these variables will cycle through the known database names
+$detPendingProcessedImfile_DB = 0
+$detPendingProcessedExp_DB = 0
 
 # select images ready for copy 
@@ -42,5 +46,14 @@
 
   task.exec
-    command dettool -toprocessedimfile -limit 20
+    if ($DB:n == 0)
+      option DEFAULT
+      command dettool -toprocessedimfile -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingProcessedImfile_DB
+      command dettool -toprocessedimfile -limit 20 -dbname $DB:$detPendingProcessedImfile_DB
+      $detPendingProcessedImfile_DB ++
+      if ($detPendingProcessedImfile_DB >= $DB:n) set detPendingProcessedImfile_DB = 0
+    end
   end
 
@@ -48,5 +61,5 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingProcessedImfile -key det_id:exp_tag:class_id -uniq
+    ipptool2book stdout detPendingProcessedImfile -key det_id:exp_tag:class_id -uniq -setword dbname $options:0
     if ($VERBOSE > 2)
       book listbook detPendingProcessedImfile
@@ -55,4 +68,5 @@
     # delete existing entries which are DONE
     book delpage detPendingProcessedImfile -key state DONE
+    book delpage detPendingProcessedImfile -key state DATA_ERR
   end
 
@@ -91,4 +105,7 @@
     book getword detPendingProcessedImfile $pageName uri      -var URI      
     book getword detPendingProcessedImfile $pageName camera   -var CAMERA   
+    book getword detPendingProcessedImfile $pageName workdir  -var WORKDIR
+    book getword detPendingProcessedImfile $pageName dbname   -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -100,12 +117,9 @@
 
     ## generate output log based on filerule
-    ## XXX use OUTPATH from db to set output path
-    ## XXX use ipp_filename.pl DETPROC.LOG $outroot $CLASS_ID`
-    $word = `basename $EXP_TAG | tr '.' ' '`
-    list word -split $word
-    $base = $word:0
-    stdout $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
-    stderr $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.$CLASS_ID.log
-    exec mkdir -p $LOGSUBDIR/$base
+    $outroot = $WORKDIR/$EXP_TAG
+    $logfile = `ipp_filename.pl DETPROC.LOG $outroot $CLASS_ID`
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $WORKDIR
 
     # save the pageName for future reference below
@@ -114,7 +128,7 @@
     # create example job options as a demonstration
     if ($VERBOSE > 1)
-      echo command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA
-    end
-    command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA
+      echo command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA $ARGS
+    end
+    command detrend_process_imfile.pl --det_id $DET_ID --det_type $DET_TYPE --exp_tag $EXP_TAG --class $CLASS --class_id $CLASS_ID --input_uri $URI --camera $CAMERA $ARGS
   end
 
@@ -145,5 +159,13 @@
 
   task.exec
-    command dettool -toprocessedexp -limit 20
+    if ($DB:n == 0)
+      command dettool -toprocessedexp -limit 20
+    else
+      # save the DB name for the exit tasks
+      option $DB:$detPendingProcessedExp_DB
+      command dettool -toprocessedexp -limit 20 -dbname $DB:$detPendingProcessedExp_DB
+      $detPendingProcessedExp_DB ++
+      if ($detPendingProcessedExp_DB >= $DB:n) set detPendingProcessedExp_DB = 0
+    end
   end
 
@@ -151,5 +173,9 @@
   task.exit    0
     # convert 'stdout' to book format
-    ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq
+    if ($options:n == 0)
+      ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq
+    else
+      ipptool2book stdout detPendingProcessedExp -key det_id:iteration:exp_tag -uniq -setword DBNAME $options:0
+    end
     if ($VERBOSE > 2)
       book listbook detPendingProcessedExp
@@ -158,4 +184,5 @@
     # delete existing entries which are DONE
     book delpage detPendingProcessedExp -key state DONE
+    book delpage detPendingProcessedExp -key state DATA_ERR
   end
 
@@ -192,4 +219,7 @@
     book getword detPendingProcessedExp $pageName exp_tag   -var EXP_TAG
     book getword detPendingProcessedExp $pageName camera    -var CAMERA  
+    book getword detPendingProcessedExp $pageName workdir   -var WORKDIR
+    book getword detPendingProcessedExp $pageName dbname    -var DBNAME
+    set_standard_args
 
     # specify choice of remote host:
@@ -200,11 +230,10 @@
     end
 
-    # XXX this is still a lame rule
-    $word = `basename $EXP_TAG | tr '.' ' '`
-    list word -split $word
-    $base = $word:0
-    stdout $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.log
-    stderr $LOGSUBDIR/$base/$EXP_TAG.detproc.$DET_ID.log
-    exec mkdir -p $LOGSUBDIR/$base
+    # XXX push this into the filerules?
+    $outroot = $WORKDIR/$EXP_TAG
+    $logfile = $outroot/$EXP_TAG.detproc.$DET_ID.log
+    stdout $logfile
+    stderr $logfile
+    exec mkdir -p $outroot
 
     # save the pageName for future reference below
@@ -213,7 +242,7 @@
     # create example job options as a demonstration
     if ($VERBOSE > 1)
-      echo command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA
-    end
-    command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA
+      echo command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA $ARGS
+    end
+    command detrend_process_exp.pl --det_id $DET_ID --exp_tag $EXP_TAG --camera $CAMERA $ARGS
   end
 
