State transition flow controlStructure of the ProgramMajor classes and objectsInitialization flow control

Initialization flow control

To understand where to add code to modify the behavior of Readout you must understand how Readout initializes. The figure below is a flowchart of this initialization process.

Initialization flow chart

After command line switches are parsed and decoded, Experiment initialization takes place. This involves creating a CExperiment object and initializing its elements. All initialization of CExperiment are done in the context of the main thread.

Normally, CReadoutMain is subclassed, and you override two member functions to initialize the CExperiment object for your application.

These functions are:

void SetupReadout(CExperiment& rExperiment) SetupReadout invokes CExperiment::AddEventSegment to register segments of the application's readout with the experiment. When an event trigger is received, the trigger thread will iterate through the event segments, reading each out in the order it was registered.
void SetupScalers(CExperiment& rexperiment) SetupScalers invokes CExperiment::AddScalerModule to setup the desired scaler readout. When a scaler trigger is recieved, the Timer thread will iterate through the scaler modules that have been added and read each out in registration order.

Interpreter setup is slightly more complex because the interpreter runs in a separate thread. The Readout initialization software first checks for the presence of the --window switch. If present, a Tk interpreter is started off, if not, a Tcl interpreter.

Regardless of the interpreter started, it retains a object of CInterpreterCore. That object is responsible for registering all extensions to the command interpreter. After registering the standard extensions, in order it invokes three CReadoutMain member functions to allow the user to add any interpreter extensions requried by the application. These member functions are called in the context of the Interpreter thread. The CReadoutMain functinos called are virtual functions that can be overridden by the user to supply extensions without modifying the source of the framework.

The functions called are:

void AddUserCommands(CExperiment& rExperiment, CInterpreterStartup& rStartup, CInterpreterCore& rCore) AddUserCommands is expected to create and register any application specific commands that further extend the interpreter. Note that CInterpreterStartup::Interp() allows you to retrieve the interpreter object.
void SetupStateVariables(CExperiment& rExperiment, CInterpreterStartup& rStartup, CInterpreterCore& rCore) SetupStateVariables is expected to add any state variables your application wants to monitor.
void SetupRunVariables( CExperiment& rExperiment, CInterpreterStartup& rStartup, CInterpreterCore& rCore) SetupRunVariables is expected to add any run variables your application wants to maintain.

Once all extensions have been initialized, if the --port switch specified a TclServer port, Readout will initiate a thread to listen for TclServer client connections. This sequence of operations ensures that by the time the first TclServer connections are honored and the Tcl/Tk interpreter prompt is issued to stdin, all standard and application specific extensions have been initialized and installed in the interpreter.


Report documentation errors to Ron Fox (fox@nscl.msu.edu)or NSCL's Bugzilla page

State transition flow controlStructure of the ProgramMajor classes and objectsInitialization flow control