Index: trunk/ippTasks/lap.pro
===================================================================
--- trunk/ippTasks/lap.pro	(revision 31435)
+++ trunk/ippTasks/lap.pro	(revision 31435)
@@ -0,0 +1,370 @@
+## lap.pro : -*- sh -*-
+
+check.globals
+
+$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
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  task.exec
+    stdout NULL
+    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
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  task.exec
+    stdout NULL
+    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
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  task.exec
+    stdout NULL
+    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
