Chapter 4. More information

If you are preparing a system that will be used many times, you may want to automate the startup as well as run the Readout software under the control of a Readout Gui called ReadoutShell. Normally this automation is done by:

It is a good idea to get all of your software debugged first, as debugging programs run under desktop icons can be challenging.

4.1. Scripting and desktop icons

The trickiest issue for creating scripts that will become desktop icons is that the environment in which you are running your scripts and programs is not well known. You should ensure that each script sources appropriate login scripts and sets the working directory you want your application to run in. We will generate four scripts:

  1. A script to run SpecTcl

  2. A script to initialize SpecTcl, loading in our histogram definitions and connecting it to the appropriate online system.

  3. A script to run the ReadoutShell Readout GUI.

  4. A script that will be used by the ReadoutShell to start the readout program.

Once these scripts are written we will create desktop icons for the first two scripts so that you can start SpecTcl and Readout by clicking on the desktop.

4.1.1. Scripts and a desktop shortcut for SpecTcl

The following script will be used to start SpecTcl:

Example 4-1. SpecTcl startup script.


#!/bin/bash

. /etc/profile              # (1)
. ~/.bashrc

cd ~/experiment/spectcl     # (2)

./SpecTcl <setup.tcl        # (3)

                    

Refer to the numbers in the listing above when reading the annotations below:

(1)
Since icons may or may not source the various bash startup scripts we explicitly source the system wide and our login specific startup scripts.
(2)
We set the working directly explicitly to the directory in which we have installed our SpecTcl. This ensures that when SpecTcl is started, it will find its initialization scripts.
(3)
This starts SpecTcl, setting its standard input to the file setup.tcl located in ˜/experiment/spectcl, the working directory. This file will initialize SpecTcl, and will be written next.

In our startup script for SpecTcl we pointed the SpecTcl stdin at the file setup.tcl. This file will setup the initial spectrum definitions and attach SpecTcl to the online system.

The spectcl.tcl startup script is as shown below:

Example 4-2. The spectcl.tcl SpecTcl startup script


source myspectra.tcl;     # (1)
sbind -all;               # (2)

.gui.b update;            # (3)


if {[array names env DAQHOST] ne ""} {
    set daqsource $env(DAQHOST)
} else {;                  # (4)
    set daqsource "localhost"
}

set url "tcp://$daqsource:2602"; # (5)

attach -pipe /usr/opt/daq/current/bin/spectcldaq $url; # (6)
start;                                                 # (7)

                    

The numbers in the explanation below refer to the numbers in the example above.

(1)
This source command sources the spectrum definitions we created when we configured SpecTcl. SpecTcl GUI configuration files are just Tcl Scripts. Sourcing these scripts reproduces the definitions saved in them.
(2)
The sbind command here binds all of the spectra into the Xamine visualization program. SpecTcl spectra need not be visible to Xamine, this command ensures they will be.
(3)
Unless told to do so, the GUI's object browser will not reflect definitions that have been made outside the gui. This command tells the gui's object browser (widget .gui.b), to rebuild the object tree.
(4)
By convention, most experiments use the environment variable DAQHOST to store the name of the host on which Readout runs. This code sets daqsource to be the value of the DAQHOST environment variable if it is defined, or to localhost if it is not. This establishes the system from which data will be analyzed.
(5)
Connections are specified to remote data acquisition systems using URL notation. This command sets url to be the url corresponding to the spectrodaq server buffer request socket for the host daqsource.
(6)
The SpecTcl attach command specifies the data source from which SpecTcl will process buffers. In this case we specify that we will accpet buffers from a pipe to which the program spectcldaq in the data acqusition system will be attached. spectcldaq accepts data from the specified source, sampling event data, and dumps the data to its standard output (the other end of the pipe SpecTcl is taking buffers from.
(7)
Once SpecTcl is attached to a data source the start command starts processing data from that data source.