Index: branches/eam_branches/ipp-20110906/ippTasks/Makefile.am
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/Makefile.am	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/Makefile.am	(revision 32630)
@@ -42,5 +42,6 @@
 	background.pro \
 	diffphot.pro \
-	lap.pro
+	lap.pro \
+	vp.pro
 
 other_files = \
Index: branches/eam_branches/ipp-20110906/ippTasks/destreak.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/destreak.pro	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/destreak.pro	(revision 32630)
@@ -206,5 +206,6 @@
     book getword magicToDS $pageName magicked -var MAGICKED
     book getword magicToDS $pageName dbname -var DBNAME
-
+    book getword magicToDS $pageName diff_tess_id -var DIFF_TESS_ID
+    book getword magicToDS $pageName mismatched_tess -var MISMATCHED_TESS
 
     substr $COMPONENT 0 3 COMP_HEAD
@@ -224,4 +225,8 @@
     $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --exp_id $EXP_ID --streaks_path_base $STREAKS_PATH_BASE --inv_streaks_path_base $INV_STREAKS_PATH_BASE --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $WORKDIR --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE --magicked $MAGICKED --run-state $RUN_STATE
 
+    if ($MISMATCHED_TESS) 
+        book getword magicToDS $pageName diff_tess_id -var DIFF_TESS_ID
+        $run = $run --mismatched_tess --diff_tess_id $DIFF_TESS_ID
+    end
     add_standard_args run
 
Index: branches/eam_branches/ipp-20110906/ippTasks/diskbalance.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/diskbalance.pro	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/diskbalance.pro	(revision 32630)
@@ -15,4 +15,8 @@
 book init balanceControl
 
+
+book init targetPending
+book init targetControl
+
 macro balance.reset
   book init balancePending
@@ -41,4 +45,30 @@
 end
 
+macro target.reset
+  book init targetPending
+end
+
+macro target.status
+  book listbook targetPending
+end
+
+macro target.on
+  task target.load
+    active true
+  end
+  task target.run
+    active true
+  end
+end
+
+macro target.off
+  task target.load
+    active false
+  end
+  task target.run
+    active false
+  end
+end
+ 
 macro set.host.for.balance
   if ($0 != 2)
@@ -71,4 +101,15 @@
   book setword balanceControl control mDestinations $2
 end
+
+macro set.balance.range
+  if ($0 != 3)
+    echo "USAGE: set.balance.range (SO_ID_START) (SO_ID_RANGE)"
+    break
+  end
+
+  $BALANCE_SO_ID_START = $1
+  $BALANCE_SO_ID_RANGE = $2
+end
+
 
 macro show.balance.numbers
@@ -90,4 +131,25 @@
  end
  $BALANCE_TARGET = $1
+end
+
+macro set.target.range
+  if ($0 != 3)
+    echo "USAGE: set.target.range (SO_ID_START) (SO_ID_RANGE)"
+    break
+  end
+
+  $TARGET_SO_ID_START = $1
+  $TARGET_SO_ID_RANGE = $2
+end
+
+
+macro show.target.numbers
+  echo "target so_ids: $TARGET_SO_ID_START $TARGET_SO_ID_RANGE"
+end
+
+macro show.targetPending
+  book npages targetPending -var N
+  echo "$N pages in book"
+  book listbook targetPending
 end
 
@@ -250,5 +312,155 @@
 
 
-
-    
-
+# This value will need to be incremented periodically.  It looks like we grow by about 5e7 so_ids per month.
+$TARGET_BIG_SO_ID   = 6e8
+$TARGET_SO_ID_START = int($TARGET_BIG_SO_ID * rnd(0)) 
+$TARGET_SO_ID_RANGE = 500000
+$TARGET_LIMIT       = 500
+$TARGET_OFFSET      = 0
+$TARGET_TARGET      = "SOURCE"
+# Select Nebulous objects which should be shuffled
+task           target.load
+  host         local
+
+  periods      -poll 60
+  periods      -exec 60
+  periods      -timeout 1500
+  npending     1
+
+  # logs
+  stdout NULL
+  stderr $LOGSUBDIR/target.log
+    
+  task.exec
+    book npages targetPending -var N
+    if ($N > 2000)
+      process_cleanup targetPending
+      break
+    end
+
+    command neb-admin --host $NEB_HOST --db $NEB_DB --user $NEB_USER --pass $NEB_PASS --pendingtarget --limit $TARGET_LIMIT --offset $TARGET_OFFSET --so_id_start $TARGET_SO_ID_START --so_id_range $TARGET_SO_ID_RANGE  
+  end
+
+   # success : 0 -- we did not hit the limit, advance so_id counter
+  task.exit 0
+    # advance the so_id counter
+    $TARGET_SO_ID_START = $TARGET_SO_ID_START + $TARGET_SO_ID_RANGE
+    $TARGET_OFFSET = 0
+    # convert 'stdout' to book format
+    ipptool2book stdout targetPending -key key -uniq -setword pantaskState INIT
+
+    if ($VERBOSE > 2)
+      book listbook targetPending
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup targetPending
+  end
+
+  # success : 1 -- we DID hit the limit, do NOT advance so_id counter 
+  task.exit 1
+    # convert 'stdout' to book format
+    ipptool2book stdout targetPending -key key -uniq -setword pantaskState INIT
+    $TARGET_OFFSET = $TARGET_OFFSET + $TARGET_LIMIT
+    if ($VERBOSE > 2)
+      book listbook targetPending
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup targetPending
+  end
+
+  # out of so_id range, reset
+  task.exit 10
+    # advance the so_id counter
+    $TARGET_SO_ID_START = 0
+  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 to execute shuffles
+task            target.run
+  periods       -poll 0.5
+  periods       -exec 5
+  periods       -timeout 5
+  npending      200 
+
+  task.exec
+    # if we are unable to run the 'exec', use a long retry time
+    periods -exec 5
+
+    book npages targetPending -var N
+    if ($NETWORK == 0) break
+    if ($N == 0) break
+
+    # look for new objects in targetPending
+    book getpage targetPending 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword targetPending $pageName pantaskState RUN
+
+    book getword targetPending $pageName key              -var KEY
+    book getword targetPending $pageName source_name      -var SOURCE
+    book getword targetPending $pageName source_host      -var SOURCE_HOST
+    book getword targetPending $pageName destination_name -var DESTINATION
+    book getword targetPending $pageName destination_host -var DEST_HOST
+    book getword targetPending $pageName destination_uri  -var DEST_URI
+    book getword targetPending $pageName ins_id           -var INS_ID
+
+    # Fix this with multihost restriction when possible.
+    if ("$TARGET_TARGET" == "DESTINATION")
+       set.host.for.target $DEST_HOST
+    else 
+       set.host.for.target $SOURCE_HOST
+    end
+    
+
+    stdout NULL
+    stderr $LOGSUBDIR/target.log
+
+    $run = neb-insedit --key $KEY --ins_id $INS_ID --uri $DEST_URI --volume $DESTINATION 
+    $run = $run --db $NEB_DB --host $NEB_HOST --user $NEB_USER --pass $NEB_PASS
+    $run = $run --neb_host http://ippc04/nebulous
+    
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+	echo command $run
+    end
+    periods -exec 0.05
+    command $run
+  end
+
+  # default exit status
+  task.exit     default
+    process_exit targetPending $options:0 $JOB_STATUS
+  end
+
+  task.exit    crash
+    showcommand crash
+    book setword targetPending $options:0 pantaskState CRASH
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword targetPending $options:0 pantaskState TIMEOUT
+  end
+end
+
+
Index: branches/eam_branches/ipp-20110906/ippTasks/ipphosts.mhpcc.config
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/ipphosts.mhpcc.config	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/ipphosts.mhpcc.config	(revision 32630)
@@ -95,6 +95,6 @@
   camera STR GPC1
 
-  XY01  STR  ipp005
-  XY02  STR  ipp005
+  XY01  STR  ipp010
+  XY02  STR  ipp011
   XY03  STR  ipp006
   XY04  STR  ipp006
@@ -128,13 +128,13 @@
   XY33  STR  ipp021
   XY34  STR  ipp023
-  XY35  STR  ipp023
+  XY35  STR  ipp013
 
   XY36  STR  ipp024
-  XY37  STR  ipp024
+  XY37  STR  ipp019
   XY40  STR  ipp025
-  XY41  STR  ipp025
-
-  XY42  STR  ipp026
-  XY43  STR  ipp026
+  XY41  STR  ipp018
+
+  XY42  STR  ipp017
+  XY43  STR  ipp015
   XY44  STR  ipp027
   XY45  STR  ipp028
@@ -174,6 +174,6 @@
   camera STR gpc1
 
-  ota01  STR  ipp005
-  ota02  STR  ipp005
+  ota01  STR  ipp010
+  ota02  STR  ipp011
   ota03  STR  ipp006
   ota04  STR  ipp006
@@ -207,13 +207,13 @@
   ota33  STR  ipp021
   ota34  STR  ipp023
-  ota35  STR  ipp023
+  ota35  STR  ipp013
 	            
   ota36  STR  ipp024
-  ota37  STR  ipp024
+  ota37  STR  ipp019
   ota40  STR  ipp025
-  ota41  STR  ipp025
-	            
-  ota42  STR  ipp026
-  ota43  STR  ipp026
+  ota41  STR  ipp018
+	            
+  ota42  STR  ipp017
+  ota43  STR  ipp015
   ota44  STR  ipp027
   ota45  STR  ipp028
@@ -285,6 +285,6 @@
   count S32   60
 
-  XY01  STR  ipp005
-  XY02  STR  ipp005
+  XY01  STR  ipp010
+  XY02  STR  ipp011
   XY03  STR  ipp006
   XY04  STR  ipp006
@@ -318,13 +318,13 @@
   XY33  STR  ipp021
   XY34  STR  ipp023
-  XY35  STR  ipp023
+  XY35  STR  ipp013
 	           
   XY36  STR  ipp024
-  XY37  STR  ipp024
+  XY37  STR  ipp019
   XY40  STR  ipp025
-  XY41  STR  ipp025
-	           
-  XY42  STR  ipp026
-  XY43  STR  ipp026
+  XY41  STR  ipp018
+	           
+  XY42  STR  ipp017
+  XY43  STR  ipp015
   XY44  STR  ipp027
   XY45  STR  ipp028
@@ -441,2 +441,81 @@
   sky75 STR  ipp053
 END
+
+ipphosts METADATA
+  camera STR STARE
+
+  ota01  STR  ipp010
+  ota02  STR  ipp010
+  ota03  STR  ipp010
+  ota04  STR  ipp010
+	            
+  ota05  STR  ipp011
+  ota06  STR  ipp011
+  ota10  STR  ipp011
+  ota11  STR  ipp011
+	            
+  ota12  STR  ipp012
+  ota13  STR  ipp012
+  ota14  STR  ipp012
+  ota15  STR  ipp012
+	            
+  ota16  STR  ipp013
+  ota17  STR  ipp013
+  ota20  STR  ipp013
+  ota21  STR  ipp013
+	            
+  ota22  STR  ipp014
+  ota23  STR  ipp014
+  ota24  STR  ipp014
+  ota25  STR  ipp014
+	            
+  ota26  STR  ipp015
+  ota27  STR  ipp015
+  ota30  STR  ipp015
+  ota31  STR  ipp015
+	            
+  ota32  STR  ipp016
+  ota33  STR  ipp016
+  ota34  STR  ipp016
+  ota35  STR  ipp016
+	            
+  ota36  STR  ipp017
+  ota37  STR  ipp017
+  ota40  STR  ipp017
+  ota41  STR  ipp017
+	            
+  ota42  STR  ipp018
+  ota43  STR  ipp018
+  ota44  STR  ipp018
+  ota45  STR  ipp018
+	            
+  ota46  STR  ipp019
+  ota47  STR  ipp019
+  ota50  STR  ipp019
+  ota51  STR  ipp019
+	            
+  ota52  STR  ipp020
+  ota53  STR  ipp020
+  ota54  STR  ipp020
+  ota55  STR  ipp020
+	            
+  ota56  STR  ipp021
+  ota57  STR  ipp021
+  ota60  STR  ipp021
+  ota61  STR  ipp021
+	            
+  ota62  STR  ipp010
+  ota63  STR  ipp011
+  ota64  STR  ipp012
+  ota65  STR  ipp013
+	            
+  ota66  STR  ipp014
+  ota67  STR  ipp015
+  ota71  STR  ipp016
+  ota72  STR  ipp017
+	            
+  ota73  STR  ipp018
+  ota74  STR  ipp019
+  ota75  STR  ipp020
+  ota76  STR  ipp021
+END
Index: branches/eam_branches/ipp-20110906/ippTasks/lap.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/lap.pro	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/lap.pro	(revision 32630)
@@ -10,4 +10,6 @@
 $lap_RunPage = 0
 $lap_DonePage = 0
+
+$LAP_QUEUE = NULL
 
 book init lapNewRuns
@@ -135,4 +137,8 @@
  
 
+macro lap.define.queue
+  $LAP_QUEUE = $1
+end
+
 task           lap.initial.load
   host         local
@@ -388,5 +394,5 @@
     stderr $LOGDIR/lap.load.log
 
-    $run = laptool -pendingrun -state done
+    $run = laptool -pendingrun -state full
 
     if ($lapSeq:n != 0)
@@ -463,4 +469,8 @@
     option $LAP_ID
     $run = lap_science.pl --cleanup_mode --dbname $DBNAME --lap_id $LAP_ID
+    if ("$LAP_QUEUE" != "NULL") 
+      $run = $run --queue_list $LAP_QUEUE
+    end
+    
 
     command $run
Index: branches/eam_branches/ipp-20110906/ippTasks/nightly_science.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/nightly_science.pro	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/nightly_science.pro	(revision 32630)
@@ -178,5 +178,5 @@
   periods         -poll $LOADPOLL
   periods         -exec $LOADEXEC
-  periods         -timeout 30
+  periods         -timeout 300
   trange          0:00:00 1:00:00 -nmax 1
   npending        1
@@ -260,5 +260,5 @@
   periods         -poll 3600
   periods         -exec $LOADEXEC
-  periods         -timeout 30
+  periods         -timeout 300
   trange          22:00:00 23:59:59
   trange          00:00:00 10:00:00
Index: branches/eam_branches/ipp-20110906/ippTasks/summit.copy.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/summit.copy.pro	(revision 32363)
+++ branches/eam_branches/ipp-20110906/ippTasks/summit.copy.pro	(revision 32630)
@@ -442,5 +442,12 @@
         # this function uses workdir_template, default_host, volume_template, volume_default,
         # it sets workdir and volume
-       	set.workdir.by.camera $CAMERA $CLASS_ID $workdir_template $default_host workdir_base
+
+        # Look to see if we have a stare type observation, and redirect it to an appropriate host
+	substr $EXP_NAME 10 1 EXPTYPE_KEY
+	if ("$EXPTYPE_KEY" == "a") 
+	  set.workdir.by.camera STARE $CLASS_ID $workdir_template $default_host workdir_base
+        else 
+          set.workdir.by.camera $CAMERA $CLASS_ID $workdir_template $default_host workdir_base
+        end
 
         # figure out filename
Index: branches/eam_branches/ipp-20110906/ippTasks/vp.pro
===================================================================
--- branches/eam_branches/ipp-20110906/ippTasks/vp.pro	(revision 32630)
+++ branches/eam_branches/ipp-20110906/ippTasks/vp.pro	(revision 32630)
@@ -0,0 +1,243 @@
+## vp.pro : tasks for video photometry : -*- sh -*-
+
+# test for required global variables
+check.globals
+
+$LOGSUBDIR = $LOGDIR/vp
+mkdir $LOGSUBDIR
+
+### Initialise the books containing the tasks to do
+book init vpPendingRun
+
+### Database lists
+$vp_DB = 0
+$vp_revert_DB = 0
+
+### Check status of vping tasks
+macro vp.status
+  book listbook vpPendingRun
+end
+
+### Reset vping tasks
+macro vp.reset
+  book init vpPendingRun
+end
+
+### Turn vp tasks on
+macro vp.on
+  task vp.load
+    active true
+  end
+  task vp.run
+    active true
+  end
+  task vp.revert
+    active true
+  end
+end
+
+### Turn vp tasks off
+macro vp.off
+  task vp.load
+    active false
+  end
+  task vp.run
+    active false
+  end
+  task vp.revert
+    active false
+  end
+end
+
+macro vp.revert.on
+  task vp.revert
+    active true
+  end
+end
+
+macro vp.revert.off
+  task vp.revert
+    active false
+  end
+end
+
+
+### Load tasks for doing video photometry
+### Tasks are loaded into vpPendingRun.
+task	       vp.load
+  host         local
+
+  periods      -poll $LOADPOLL
+  periods      -exec $LOADEXEC
+  periods      -timeout 30
+  npending     1
+
+  stdout NULL
+  stderr $LOGSUBDIR/vp.load.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    $run = vptool -pendingrun
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$vp_DB
+      $run = $run -dbname $DB:$vp_DB
+      $vp_DB ++
+      if ($vp_DB >= $DB:n) set vp_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 vpPendingRun -key vp_id -uniq -setword dbname $options:0 -setword pantaskState INIT
+    if ($VERBOSE > 2)
+      book listbook vpPendingRun
+    end
+
+    # delete existing entries in the appropriate pantaskStates
+    process_cleanup vpPendingRun
+  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
+
+
+
+
+### Run video photometery tasks
+### Tasks are taken from vpPendingRun.
+task	       vp.run
+  periods      -poll $RUNPOLL
+  periods      -exec $RUNEXEC
+  periods      -timeout 300
+
+  task.exec
+    book npages vpPendingRun -var N
+    if ($N == 0) break
+    if ($NETWORK == 0) break
+    if ($BURNTOOLING == 1) break
+
+    # look for new runs in vpPendingRun (pantaskState == INIT)
+    book getpage vpPendingRun 0 -var pageName -key pantaskState INIT
+    if ("$pageName" == "NULL") break
+
+    book setword vpPendingRun $pageName pantaskState RUN
+    book getword vpPendingRun $pageName vp_id -var VP_ID
+    book getword vpPendingRun $pageName camera -var CAMERA
+    book getword vpPendingRun $pageName exp_tag -var EXP_TAG
+    book getword vpPendingRun $pageName workdir -var WORKDIR
+    book getword vpPendingRun $pageName dest_id -var DEST_ID
+    book getword vpPendingRun $pageName dest_name -var DEST_NAME
+    book getword vpPendingRun $pageName ds_dbname -var DS_DBNAME
+    book getword vpPendingRun $pageName ds_dbhost -var DS_DBHOST
+    book getword vpPendingRun $pageName dbname -var DBNAME
+
+    # set the host and workdir based on the skycell hash
+#    set.host.for.skycell $SKYCELL_ID
+#    set.workdir.by.skycell $SKYCELL_ID $WORKDIR_TEMPLATE $default_host WORKDIR
+
+    sprintf outroot "%s/%s.vp.%d" $WORKDIR $EXP_TAG $VP_ID
+
+    stdout $LOGSUBDIR/vp.log
+    stderr $LOGSUBDIR/vp.log
+
+    $run = videophot_process.pl --vp_id $VP_ID --outroot $outroot --redirect-output --camera $CAMERA 
+    if ($DEST_ID) 
+     $run = $run --dest_id $DEST_ID --product $DEST_NAME --ds_dbname $DS_DBNAME --ds_dbhost $DS_DBHOST
+    end
+    add_standard_args run
+
+    # save the pageName for future reference below
+    options $pageName
+
+    # create the command line
+    if ($VERBOSE > 1)
+      echo command $run
+    end
+    command $run
+  end
+
+  # default exit status
+  task.exit    default
+    process_exit vpPendingRun $options:0 $JOB_STATUS
+  end
+
+  # locked list
+  task.exit    crash
+    showcommand crash
+    echo "hostname: $JOB_HOSTNAME"
+    book setword vpPendingRun $options:0 pantaskState CRASH
+  end
+
+  # operation timed out?
+  task.exit    timeout
+    showcommand timeout
+    book setword vpPendingRun $options:0 pantaskState TIMEOUT
+  end
+end
+
+
+task vp.revert
+  host         local
+
+  periods      -poll 5
+  periods      -exec 600
+  periods      -exec 30
+  periods      -timeout 120
+  npending     1
+  
+  stdout NULL
+  stderr $LOGSUBDIR/vp.revert.log
+
+  task.exec
+    if ($LABEL:n == 0) break
+    $run = vptool -revertrun
+    if ($DB:n == 0)
+      option DEFAULT
+    else
+      # save the DB name for the exit tasks
+      option $DB:$vp_revert_DB
+      $run = $run -dbname $DB:$vp_revert_DB
+      $vp_revert_DB ++
+      if ($vp_revert_DB >= $DB:n) set vp_revert_DB = 0
+    end
+    add_poll_labels run
+    command $run
+  end
+
+  # success
+  task.exit    0
+  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
