Index: branches/czw_branch/20110406/ippTasks/lap.pro
===================================================================
--- branches/czw_branch/20110406/ippTasks/lap.pro	(revision 31385)
+++ branches/czw_branch/20110406/ippTasks/lap.pro	(revision 31417)
@@ -1,93 +1,49 @@
-## reprocessing.pro : -*- sh -*-
+## lap.pro : -*- sh -*-
 
 check.globals
 
-macro reprocessing.on
-  re.chip.on
-  re.diff.on
-  re.stack.on
-  re.magic.on
-  re.clean.on
-end
-
-macro reprocessing.off
-  re.chip.off
-  re.diff.off
-  re.stack.off
-  re.magic.off
-  re.clean.off
-end
-
-macro re.on
-  reprocessing.on
-end
-
-macro re.off
-  reprocessing.off
-end
-
-macro re.chip.on
-  task re.chip.load
-    active true
-  end
-end
-
-macro re.diff.on
-  task re.diff.load
-    active true
-  end
-end
-
-macro re.stack.on
-  task re.stack.load
-    active true
-  end
-end
-
-macro re.magic.on
-  task re.magic.load
-    active true
-  end
-end
-
-macro re.clean.on
-  task re.clean.load
-    active true
-  end
-end
-
-macro re.chip.off
-  task re.chip.load
-    active false
-  end
-end
-
-macro re.diff.off
-  task re.diff.load
-    active false
-  end
-end
-
-macro re.stack.off
-  task re.stack.load
-    active false
-  end
-end
-
-macro re.magic.off
-  task re.magic.load
-    active false
-  end
-end
-
-macro re.clean.off
-  task re.clean.load
-    active false
-  end
-end
-
-book init reData
-
-task           re.chip.load
+$lapSeq:n = 0
+
+book init lapRuns
+
+macro lap.add.sequence
+  if ($0 != 2) 
+    echo "USAGE: lap.add.sequence (seq_id)"
+    break
+  end
+  if ($?lapSeq:n == 0) 
+    list lapSeq -add $1
+    return
+  end
+
+  local found
+  $found = 0
+  for i 0 $lapSeq:n
+    if ($lapSeq:$i == $1)
+      $found = 1
+      echo "$lapSeq:$i set"
+      last
+    end
+  end
+
+  if ($found == 0)
+    list lapSeq -add $1
+  end
+end
+
+macro lap.del.sequence
+  if ($0 != 2)
+    echo "USAGE: lap.del.sequence (seq_id)"
+    break
+  end
+  if ($?lapSeq:n == 0)
+    return
+  end
+
+  list lapSeq -del $1
+end
+ 
+
+task           lap.initial.load
   host         local
   periods      -poll $LOADPOLL
@@ -98,33 +54,105 @@
   task.exec
     stdout NULL
-    stderr $LOGDEIR/re.chip.log
-
-    $run = echo no command yet
-    command $run
-  end
-  # success
-  task.exit  0
-    book delpage reData $options:0
-    ipptool2book stdout reData -uniq -key proj
-
-    if ($VERBOSE > 2)
-      book listbook reData
-    end
-  end
-  # locked list
-  task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-
-task           re.diff.load
+    stderr $LOGDIR/lap.load.log
+
+    $run = laptool -pendingrun -state new
+
+    if ($lapSeq:n == 0)
+      break
+    else 
+      option $lapSeq:$lap_N
+      $run = $run -seq_id $lapSeq:$lap_N
+      $lap_N ++
+      if ($lap_N >= $lapSeq:n) set lap_N = 0
+    end
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$lap_DB
+      $run = $run -dbname $DB:$lap_DB
+      $lap_DB ++
+      if ($lap_DB >= $DB:n) set lap_DB = 0
+    end
+
+    command $run
+  end
+  # success
+  task.exit  0
+    book delpage lapNewRuns $options:0
+    ipptool2book stdout lapNewRuns -uniq -key proj
+
+    if ($VERBOSE > 2)
+      book listbook lapNewRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           lap.initial.run
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 600
+# This can probably be increased and spread over hosts in the future.
+  npending     1            
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/lap.initial.log
+
+    book npages lapNewRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+
+    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword lapNewRuns $pageName pantaskState RUN
+    book getword lapNewRuns $pageName lap_id -var LAP_ID
+    book getword lapNewRuns $pageName dbname -var DBNAME
+
+    $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 proj
+
+    if ($VERBOSE > 2)
+      book listbook lapNewRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+
+
+task           lap.monitor.load
   host         local
   periods      -poll $LOADPOLL
@@ -135,32 +163,105 @@
   task.exec
     stdout NULL
-    stderr $LOGDEIR/re.diff.log
-
-    $run = echo no command yet
-    command $run
-  end
-  # success
-  task.exit  0
-    book delpage reData $options:0
-    ipptool2book stdout reData -uniq -key proj
-
-    if ($VERBOSE > 2)
-      book listbook reData
-    end
-  end
-  # locked list
-  task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-task           re.magic.load
+    stderr $LOGDIR/lap.load.log
+
+    $run = laptool -pendingrun -state run
+
+    if ($lapSeq:n != 0)
+      option $lapSeq:$lap_N
+      $run = $run -seq_id $lapSeq:$lap_N
+      $lap_N ++
+      if ($lap_N >= $lapSeq:n) set lap_N = 0
+    end
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$lap_DB
+      $run = $run -dbname $DB:$lap_DB
+      $lap_DB ++
+      if ($lap_DB >= $DB:n) set lap_DB = 0
+    end
+
+    add_poll_labels run
+
+    command $run
+  end
+  # success
+  task.exit  0
+    book delpage lapRuRuns $options:0
+    ipptool2book stdout lapRunRuns -uniq -key lap_id
+
+    if ($VERBOSE > 2)
+      book listbook lapRunRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           lap.monitor.run
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 600
+# This can probably be increased and spread over hosts in the future.
+  npending     1            
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/lap.initial.log
+
+    book npages lapRunRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+
+    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword lapNewRuns $pageName pantaskState RUN
+    book getword lapNewRuns $pageName lap_id -var LAP_ID
+    book getword lapNewRuns $pageName dbname -var DBNAME
+
+    $run = lap_science.pl --monitor_mode --dbname $DBNAME --lap_id $LAP_ID
+
+    command $run
+
+  end
+
+  # success
+  task.exit  0
+    book delpage lapRunRuns $options:0
+    ipptool2book stdout lapRunRuns -uniq -key proj
+
+    if ($VERBOSE > 2)
+      book listbook lapRunRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+
+
+task           lap.cleanup.load
   host         local
   periods      -poll $LOADPOLL
@@ -171,100 +272,99 @@
   task.exec
     stdout NULL
-    stderr $LOGDEIR/re.magic.log
-
-    $run = echo no command yet
-    command $run
-  end
-  # success
-  task.exit  0
-    book delpage reData $options:0
-    ipptool2book stdout reData -uniq -key proj
-
-    if ($VERBOSE > 2)
-      book listbook reData
-    end
-  end
-  # locked list
-  task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-task           re.stack.load
-  host         local
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC
-  periods      -timeout 30
-  npending     1
-
-  task.exec
-    stdout NULL
-    stderr $LOGDEIR/re.stack.log
-
-    $run = echo no command yet
-    command $run
-  end
-  # success
-  task.exit  0
-    book delpage reData $options:0
-    ipptool2book stdout reData -uniq -key proj
-
-    if ($VERBOSE > 2)
-      book listbook reData
-    end
-  end
-  # locked list
-  task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
-
-task           re.clean.load
-  host         local
-  periods      -poll $LOADPOLL
-  periods      -exec $LOADEXEC
-  periods      -timeout 30
-  npending     1
-
-  task.exec
-    stdout NULL
-    stderr $LOGDEIR/re.clean.log
-
-    $run = echo no command yet
-    command $run
-  end
-  # success
-  task.exit  0
-    book delpage reData $options:0
-    ipptool2book stdout reData -uniq -key proj
-
-    if ($VERBOSE > 2)
-      book listbook reData
-    end
-  end
-  # locked list
-  task.exit    default
-    showcommand failure
-  end
-  task.exit    crash
-    showcommand crash
-  end
-  #operation times out?
-  task.exit    timeout
-    showcommand timeout
-  end
-end
+    stderr $LOGDIR/lap.load.log
+
+    $run = laptool -pendingrun -state done
+
+    if ($lapSeq:n != 0)
+      option $lapSeq:$lap_N
+      $run = $run -seq_id $lapSeq:$lap_N
+      $lap_N ++
+      if ($lap_N >= $lapSeq:n) set lap_N = 0
+    end
+
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      option $DB:$lap_DB
+      $run = $run -dbname $DB:$lap_DB
+      $lap_DB ++
+      if ($lap_DB >= $DB:n) set lap_DB = 0
+    end
+
+    add_poll_labels run
+
+    command $run
+  end
+  # success
+  task.exit  0
+    book delpage lapDoneRuns $options:0
+    ipptool2book stdout lapDoneRuns -uniq -key lap_id
+
+    if ($VERBOSE > 2)
+      book listbook lapRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
+
+task           lap.cleanup.run
+  host         local
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 600
+# This can probably be increased and spread over hosts in the future.
+  npending     1            
+
+  task.exec
+    stdout NULL
+    stderr $LOGDIR/lap.cleanup.log
+
+    book npages lapNewRuns -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+
+
+    book getpage lapNewRuns 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword lapDoneRuns $pageName pantaskState RUN
+    book getword lapDoneRuns $pageName lap_id -var LAP_ID
+    book getword lapDoneRuns $pageName dbname -var DBNAME
+
+    $run = lap_science.pl --cleanup_mode --dbname $DBNAME --lap_id $LAP_ID
+
+    command $run
+
+  end
+
+  # success
+  task.exit  0
+    book delpage lapDoneRuns $options:0
+    ipptool2book stdout lapDoneRuns -uniq -key proj
+
+    if ($VERBOSE > 2)
+      book listbook lapDoneRuns
+    end
+  end
+  # locked list
+  task.exit    default
+    showcommand failure
+  end
+  task.exit    crash
+    showcommand crash
+  end
+  #operation times out?
+  task.exit    timeout
+    showcommand timeout
+  end
+end
