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:
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.
Construct the correct URL to use as a data source for the ringselector application and use it to construct the correct ringselector command.
                        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\]]set versions [lsort -decreasing $versions]
set highestVersion [lindex $versions 0]


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.
                    

                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:

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.
                    
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]   set url [join [list tcp: "" $hostname $tcl_platform(user)] /]
    attach -format ring -pipe \
        $ringHelper --source=$url --sample=PHYSICS_EVENT
    set url [join [list tcp: "" $hostname $tcl_platform(user)] /]
    attach -format ring -pipe \
        $ringHelper --source=$url --sample=PHYSICS_EVENT     }
}                   
                

-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.
                    
                    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