Index: trunk/ippTasks/addstar.pro
===================================================================
--- trunk/ippTasks/addstar.pro	(revision 30327)
+++ trunk/ippTasks/addstar.pro	(revision 31376)
@@ -17,5 +17,11 @@
 
 macro addstar.on
-  task addstar.exp.load
+  task addstar.exp.load.stack
+    active true
+  end
+  task addstar.exp.load.cam
+    active true
+  end
+  task addstar.exp.load.staticsky
     active true
   end
@@ -26,5 +32,11 @@
 
 macro addstar.off
-  task addstar.exp.load
+  task addstar.exp.load.stack
+    active false
+  end
+  task addstar.exp.load.cam
+    active false
+  end
+  task addstar.exp.load.staticsky
     active false
   end
@@ -54,5 +66,5 @@
 # new entries are added to addPendingExp
 # skip already-present entries
-task	       addstar.exp.load
+task	       addstar.exp.load.stack
   host         local
 
@@ -67,5 +79,5 @@
   task.exec
    # if ($LABEL:n == 0) break
-    $run = addtool -pendingexp
+    $run = addtool -pendingexp -stage stack
     if ($DB:n == 0)
       option DEFAULT
@@ -109,4 +121,112 @@
 end
 
+task	       addstar.exp.load.cam
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/addstar.exp.log
+
+  task.exec
+   # if ($LABEL:n == 0) break
+    $run = addtool -pendingexp -stage cam
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$addstar_DB
+      $run = $run -dbname $DB:$addstar_DB
+      $addstar_DB ++
+      if ($addstar_DB >= $DB:n) set addstar_DB = 0
+    end
+    add_poll_args run
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout addPendingExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook addPendingExp
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup addPendingExp
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+task	       addstar.exp.load.staticsky
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGDIR/addstar.exp.log
+
+  task.exec
+   # if ($LABEL:n == 0) break
+    $run = addtool -pendingexp -stage staticsky
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$addstar_DB
+      $run = $run -dbname $DB:$addstar_DB
+      $addstar_DB ++
+      if ($addstar_DB >= $DB:n) set addstar_DB = 0
+    end
+    add_poll_args run
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit    0
+    # convert 'stdout' to book format
+    ipptool2book stdout addPendingExp -key add_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook addPendingExp
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup addPendingExp
+  end
+
+  # default exit status
+  task.exit    default
+    showcommand failure
+  end
+
+  task.exit    crash
+    showcommand crash
+  end
+
+  # operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
 # run the addstar script on pending exposures
 task	       addstar.exp.run
@@ -132,5 +252,6 @@
     book getword addPendingExp $pageName exp_tag -var EXP_TAG
     book getword addPendingExp $pageName add_id -var ADD_ID
-    book getword addPendingExp $pageName camroot -var CAMROOT
+    book getword addPendingExp $pageName stageroot -var STAGEROOT
+    book getword addPendingExp $pageName stage -var STAGE  
     book getword addPendingExp $pageName workdir -var WORKDIR_TEMPLATE
     book getword addPendingExp $pageName reduction -var REDUCTION
@@ -157,10 +278,20 @@
 
     ## generate outroot specific to this exposure (& chip)
-    sprintf outroot "%s/%s/%s.add.%s" $WORKDIR $EXP_TAG $EXP_TAG $ADD_ID
+
+    if ("$STAGE" == "cam")
+	sprintf outroot "%s/%s/%s.add.%s" $WORKDIR $EXP_TAG $EXP_TAG $ADD_ID
+    end
+    if ("$STAGE" == "staticsky")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+    if ("$STAGE" == "stack")
+	sprintf outroot "%s.add.%s" $STAGEROOT $ADD_ID
+    end
+  
 
     stdout $LOGDIR/addstar.exp.log
     stderr $LOGDIR/addstar.exp.log
 
-    $run = addstar_run.pl --exp_tag $EXP_TAG --add_id $ADD_ID --camera $CAMERA --dvodb $DVODB --camroot $CAMROOT --outroot $outroot --redirect-output
+    $run = addstar_run.pl --add_id $ADD_ID --camera $CAMERA --dvodb $DVODB --stage $STAGE --stageroot $STAGEROOT --outroot $outroot --redirect-output
     if ("$REDUCTION" != "NULL")
       $run = $run --reduction $REDUCTION
