Batching Tasks
Ferdi Franceschini
2006-08-17 16:31
Usage
The SICS batch manager reads commands from a Tcl script and executes them, you can use
Tcl loops and logical constructs in the batch file, see the Tcl command reference. The batch manager
command is exe. Refer to the command reference section below for
syntax and usage.
Following is an example of an advanced batch file which runs some twotheta scans and
omega scans several times each. The batch execution has been made dynamically
configurable by using two tcl arrays, "scan()" and "batch()", to hold parameters for the
scan commands and the loops. This means that the user can change the number of points
per scan or the number of iterations in the loops from the command line before executing
the batchfile. The 'if' statements at the start of the file initialise the arrays if
they don't already exist.
Batch file example
# This is an example of a dynamically configurable batch file.
# Set default values for the batch and scan parameters.
if { [info exists scan(np)] == 0 } { set scan(np) 5 }
if { [info exists scan(mode)] == 0 } { set scan(mode) timer }
if { [info exists scan(preset)] == 0 } { set scan(preset) 1.0 }
if { [info exists batch(repeatnum)] == 0 } { set batch(repeatnum) 3 }
clientput "Starting batch of twotheta scans"
MyScan add twotheta 50 0.01
for {set i 0} {$i < $batch(repeatnum)} {incr i} {
clientput "twotheta scan: $i"
MyScan run $scan(np) $scan(mode) $scan(preset)
}
MyScan clear
clientput "Starting batch of omega scans"
MyScan add omega 50 0.01
for {set i 0} {$i < $batch(repeatnum)} {incr i} {
clientput "omega scan: $i"
MyScan run $scan(np) $scan(mode) $scan(preset)
}
Assuming that the file is called batch.tcl, the user could execute it as follows
set scan(np) 100
exe batch.tcl
Warning about the run command
The run command does not wait for a move to complete before it
returns, this means that the batch manager will execute any following commands
straight away. If you want move an axis and then perform some action after the move
is completed you should use the drive command instead of
run. The following batch file will print the message after
the move is complete.
drive omega 5
clientput "omega is has reached five degrees"
Commands
The batch buffer manager handles the execution of batch files.
It can execute batch files directly. Additionally, batch files can be added into a queue
for later processing. The batch buffer manager supports the following commands described
below. The command for controlling the batch manager is called exe
exe append
'tcl commands'
don't know the syntax. nha
Append some tcl commands.
exe
buffername
directly load the buffer stored in the file
buffername and execute it. The file is searched
in the batch buffer search path.
exe batchpath
newpath
Without an argument, this command lists the directories which are searched
for batch files.
newpath sets a new search path. It is possible
to specify multiple directories by separating them with colons.
exe clear
Clears the queue of batch buffers. For safety, use in conjuction with
exe clearupload
exe clearupload
Clears partially uploaded batch buffers.
exe enqueue
buffername
Appends buffername to the queue of batch
buffers to execute.
exe forcesave
filename
Will overwrite an existing batch file without warning.
exe info
prints the name of the currently executing batch buffer
exe info stack
prints the stack of nested batch files (i.e. batch files calling each
other).
exe info range
name
Without an argument prints the range of code currently being executed.
name prints the range of code executing in
named buffer within the stack of nested buffers. The reply looks like:
number of start character = number of end character = line
number
exe info text
name
Without an argument prints the code text currently being executed.
name prints the range of code text executing
in the named buffer within the stack of nested buffers.
exe interest
Switches on automatic notification about starting batch files, executing a
new bit of code or for finishing a batch file. This is most useful for SICS
clients watching the progress of the experiment.
exe print
buffername
Prints the content of the batch buffer
buffername to the screen.
exe queue
Prints the content of the batch buffer queue.
exe run
Starts executing the batch buffers in the queue.
exe save
filename
Save the commands to a batch file. Returns an error if you try to
overwrite an existing batch file
exe syspath
newpath
Without an argument, this command lists the system directories which are
searched for batch files.
newpath sets a new system search path. It is
possible to specify multiple directories by separating them with colons.
exe upload
Prepare the batch manager to upload a new set of commands from the
client