5.2. Attaching to a ring buffer data source

This section provides guidance on how to attach SpecTcl to a RingDaq ring buffer data source. Each graphical user interface written for SpecTcl has its own methods for attaching to data sources. This makes it a bit tough to talk in generalities. What I will assume for this is the existence of a proc named attachOnline that receives as a parameter, the name of the host from which data will be taken.

For RingDaq, this proc must:

  1. Locate the ringselector executable. ringselector selects data from a ring and send it to stdout. It is the preferred SpecTcl pipe data source for RingDaq. See the comprehensive documentation http://docs.nscl.msu.edu/daq/ringbuffer for more information about this application.

  2. Construct the correct URL to use as a data source for the ringselector application and use it to construct the correct ringselector command.

  3. Issue the attach command for a pipe data source specifyig the -format ring option.

In the code for ringselector we are going to assume that the version for the ringbuffer data acquisition system is 10.0 or greater. To simplify the search we will assume there are not versions higher than 19.9 and that the 'point' releases are all single digits.

The following fragment of Tcl code locates the top level directory of the highest DAQ version greater than 10.0 at the NSCL:


set versions [glob /usr/opt/daq/1\[0-9\].\[0-9\]] (1)
set versions [lsort -decreasing $versions]        (2)
set highestVersion [lindex $versions 0]           (3)
                

(1)
versions is set to the list of matching top level daq directories. The glob pattern requires backslash substitutions to allow the range patterns ([0-9]) to not be interpreted as command substitutions.
(2)
The version directory names are then sorted in high to low order.
(3)
The highest version is then the first in the list.

Given a hostname, in the variable hostname a URL has to be constructed of the form: tcp://hostname/username in order to get data from the correct ring. The host localhost will get data from the local ring without making a proxy ring.

The Tcl fragment below will create that url:


global tcl_platform                   (1)
set url [join [list tcp: "" $hostname $tcl_platform(user)] /]  (2)
                

(1)
The built in global variable tcl_global is an array that contains among other things tcl_global(user) which is the logged in username. Since we are building the body of a proc, we need to declare it global to use it.
(2)
The join command createsa a single string by joining list elements together with the separator character provided (in this case / The empty list element "" in the list is a way to get the pair of slashes needed between the protocol (tcp:) and the hierarchical part.

Putting this all together gives us this:

Example 5-3. Proc to connect SpecTcl to a ring buffer data source


 proc attachOnline hostname {
    global tcl_platform

    set versions [glob /usr/opt/daq/1\[0-9\].\[0-9\]]
    set versions [lsort -decreasing $versions]
    set highestVersion [lindex $versions 0]
    set ringHelper [file join $highestVersion bin ringselector]  (1)

    set url [join [list tcp: "" $hostname $tcl_platform(user)] /]

    attach -format ring -pipe \
        $ringHelper --source=$url --sample=PHYSICS_EVENT    (2)
}                   
                
(1)
The file join command creates the path to the ringselector program. ringselector is the the bin subdirectory of the installation directory tree of the version of the RingDaq we found.
(2)
This command does the actual attach. The -format ring option tells attach that the data will come in ringbuffer format. You must also use this option when attaching to an event file produced by the RingDaq..

The second line of the command is the ringselector command used to send data to SpecTcl through a pipe. The --source option specifies where data comes from. The --sample option specifies that data of type PHYSICS_EVENT can be sampled. That is when ringselector is getting data from the ring it is allowed to skip physics events if SpecTcl is getting too far behind.

5.2.1. RingDaq event files

In order to read data from event files that are written by RingDaq you need only add -format pipe to your attach command e.g.:


set filename [format run-%04d-00.evt $runNumber]
attach -format -ring -file [file join ~ stagearea complete $filename]
                    

Where the fragment above assumes you are opening segment 0 of a run whose run number is in the Tcl variable runNumber