Index: branches/eam_branches/ipp-20110505/ippTasks/lap.pro
===================================================================
--- branches/eam_branches/ipp-20110505/ippTasks/lap.pro	(revision 31458)
+++ branches/eam_branches/ipp-20110505/ippTasks/lap.pro	(revision 31587)
@@ -17,8 +17,19 @@
 
 macro lap.show.books
+    echo "lapNewRuns"
     book listbook lapNewRuns
+    echo "lapRunRuns"
     book listbook lapRunRuns
+    echo "lapDoneRuns"
     book listbook lapDoneRuns
+    echo "lapFullRuns"
     book listbook lapFullRuns
+end
+
+macro lap.clear.books
+    book init lapNewRuns
+    book init lapRunRuns
+    book init lapFullRuns
+    book init lapDoneRuns
 end
 
@@ -36,10 +47,4 @@
       active true
     end
-    task lap.cleanup.load
-      active true
-    end
-    task lap.cleanup.run
-      active true
-    end
 end
 
@@ -57,8 +62,17 @@
       active false
     end
-    task lap.cleanup.load
-      active false
-    end
-    task lap.cleanup.run
+end
+
+macro lap.debug.mode
+    task lap.initial.load
+      active true
+    end
+    task lap.initial.run
+      active false
+    end
+    task lap.monitor.load
+      active true
+    end
+    task lap.monitor.run
       active false
     end
@@ -156,7 +170,8 @@
   # success
   task.exit  0
-#    book delpage lapNewRuns $options:0
     ipptool2book stdout lapNewRuns -uniq -key lap_id -setword dbname $options:0 -setword pantaskState INIT
 
+    process_cleanup lapNewRuns
+
     if ($VERBOSE > 2)
       book listbook lapNewRuns
@@ -181,4 +196,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 600
+  active       false
 # This can probably be increased and spread over hosts in the future.
   npending     1            
@@ -193,11 +209,12 @@
 
 
-    book getpage lapNewRuns $lap_NewPage -var lapNewPageName 
+    book getpage lapNewRuns 0 -var lapNewPageName -key pantaskState INIT
 
     $lap_NewPage ++
     if ($lap_NewPage >= $N) set lap_NewPage = 0
 
-
     if ("$lapNewPageName" == "NULL") break
+
+
 
     book setword lapNewRuns $lapNewPageName pantaskState RUN
@@ -205,15 +222,15 @@
     book getword lapNewRuns $lapNewPageName dbname -var DBNAME
 
+    option $LAP_ID
+
     $run = lap_science.pl --chip_mode --dbname $DBNAME --lap_id $LAP_ID
-
-    command $run
-
-  end
-
-  # success
-  task.exit  0
-#    book delpage lapNewRuns $options:0
-#    ipptool2book stdout lapNewRuns -uniq -key lap_id
-
+    
+    command $run
+
+  end
+
+  # success
+  task.exit  0
+    process_exit lapNewRuns $options:0 0
     if ($VERBOSE > 2)
       book listbook lapNewRuns
@@ -222,11 +239,14 @@
   # locked list
   task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
+    process_exit lapNewRuns $options:0 0
+    showcommand failure
+  end
+  task.exit    crash
+    process_exit lapNewRuns $options:0 0
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    process_exit lapNewRuns $options:0 0
     showcommand timeout
   end
@@ -267,11 +287,11 @@
 
     add_poll_labels run
-#    echo $run
-    command $run
-  end
-  # success
-  task.exit  0
-#    book delpage lapRunRuns $options:0
+    command $run
+  end
+  # success
+  task.exit  0
     ipptool2book stdout lapRunRuns -uniq -key lap_id -setword dbname $options:0 -setword pantaskState INIT
+    
+    process_cleanup lapRunRuns
 
     if ($VERBOSE > 2)
@@ -297,4 +317,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 600
+  active       false
 # This can probably be increased and spread over hosts in the future.
   npending     1            
@@ -306,15 +327,13 @@
     book npages lapRunRuns -var N
 
-#    echo $N $NETWORK
     if ($N == 0) break
     if ($NETWORK == 0) break
 
 
-    book getpage lapRunRuns $lap_RunPage -var lapRunPageName
+    book getpage lapRunRuns 0 -var lapRunPageName -key pantaskState INIT
 
     $lap_RunPage ++
     if ($lap_RunPage >= $N) set lap_RunPage = 0
 
-#    echo $lapRunPageName
     if ("$lapRunPageName" == "NULL") break
 
@@ -323,4 +342,6 @@
     book getword lapRunRuns $lapRunPageName dbname -var DBNAME
 
+    option $LAP_ID
+
     $run = lap_science.pl --monitor_mode --dbname $DBNAME --lap_id $LAP_ID
 
@@ -331,8 +352,7 @@
   # success
   task.exit  0
-#    book delpage lapRunRuns $options:0
-#    ipptool2book stdout lapRunRuns -uniq -key lap_id
-
-    if ($VERBOSE > 2)
+    process_exit lapRunRuns $options:0 0
+    if ($VERBOSE > 2)
+
       book listbook lapRunRuns
     end
@@ -340,11 +360,14 @@
   # locked list
   task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
+    process_exit lapRunRuns $options:0 0
+    showcommand failure
+  end
+  task.exit    crash
+    process_exit lapRunRuns $options:0 0
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    process_exit lapRunRuns $options:0 0
     showcommand timeout
   end
@@ -358,4 +381,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 30
+  active       false
   npending     1
 
@@ -390,4 +414,5 @@
     ipptool2book stdout lapDoneRuns -uniq -key lap_id  -setword dbname $options:0 -setword pantaskState INIT
 
+    process_cleanup lapDoneRuns
     if ($VERBOSE > 2)
       book listbook lapRuns
@@ -412,4 +437,5 @@
   periods      -exec $LOADEXEC
   periods      -timeout 600
+  active       false
 # This can probably be increased and spread over hosts in the future.
   npending     1            
@@ -424,5 +450,5 @@
 
 
-    book getpage lapDoneRuns $lap_DonePage -var lapDonePageName 
+    book getpage lapDoneRuns 0 -var lapDonePageName -key pantaskState INIT
 
     $lap_DonePage ++
@@ -435,4 +461,5 @@
     book getword lapDoneRuns $lapDonePageName dbname -var DBNAME
 
+    option $LAP_ID
     $run = lap_science.pl --cleanup_mode --dbname $DBNAME --lap_id $LAP_ID
 
@@ -443,6 +470,5 @@
   # success
   task.exit  0
-#    ipptool2book stdout lapDoneRuns -uniq -key lap_id
-
+    process_exit lapDoneRuns $options:0 0
     if ($VERBOSE > 2)
       book listbook lapDoneRuns
@@ -451,12 +477,15 @@
   # locked list
   task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
+    process_exit lapDoneRuns $options:0 0
+    showcommand failure
+  end
+  task.exit    crash
+    process_exit lapDoneRuns $options:0 0
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    process_exit lapDoneRuns $options:0 0
+    showcommand timeout
+  end
+end
