Class Emu

java.lang.Object
org.jlab.coda.emu.Emu
All Implemented Interfaces:
CODAComponent, StatedObject, CommandAcceptor

public class Emu extends Object implements CODAComponent
This is the main class of the EMU (Event Management Unit) program. It implements the CODAComponent interface which allows communication with Run Control and implements a state machine.
  • Constructor Details

    • Emu

      public Emu(String name, String type, boolean debugUI, boolean debug) throws EmuException
      Constructor.

      This class is not executable. To create and run an Emu, use the EmuFactory class.

      A thread is started to monitor the state. The emu loads local.xml which contains a specification of status parameters. The emu starts up a connection to the cMsg server. By the end of the constructor several threads have been started.
      Parameters:
      name - name of Emu
      type - CODA component type of Emu
      debugUI - start a debug GUI
      debug - turn on debug printout
      Throws:
      EmuException - if name is null, or cannot connect to rc server
  • Method Details

    • name

      public String name()
      Get the name of this CODA component.
      Specified by:
      name in interface CODAComponent
      Returns:
      the name of this CODA component
    • getCodaid

      public int getCodaid()
      Get the id of this CODA component.
      Specified by:
      getCodaid in interface CODAComponent
      Returns:
      the id of this CODA component.
    • setCodaid

      public void setCodaid(int codaid)
      Set the id of this CODA component.
      Specified by:
      setCodaid in interface CODAComponent
      Parameters:
      codaid - the coda id of this CODA component
      See Also:
    • getSession

      public String getSession()
      Get the session of this CODA component.
      Specified by:
      getSession in interface CODAComponent
      Returns:
      the session of this CODA component
    • getExpid

      public String getExpid()
      Get the experiment id (expid) of this CODA component.
      Specified by:
      getExpid in interface CODAComponent
      Returns:
      the experiment id (expid) of this CODA component
    • getHostName

      public String getHostName()
      Get the name of the host this CODA component is running on.
      Specified by:
      getHostName in interface CODAComponent
      Returns:
      the hostName of this CODAComponent object.
    • getCodaClass

      public CODAClass getCodaClass()
      Get the class of this CODA component (e.g. "EMU", "ROC", "ER").
      Specified by:
      getCodaClass in interface CODAComponent
      Returns:
      the class of this CODA component (e.g. "EMU", "ROC", "ER")
    • getRunNumber

      public int getRunNumber()
      Get the run number of this CODA component.
      Specified by:
      getRunNumber in interface CODAComponent
      Returns:
      the run number of this CODA component
    • getRunTypeId

      public int getRunTypeId()
      Get the numeric code representing the run type of this CODA component.
      Specified by:
      getRunTypeId in interface CODAComponent
      Returns:
      the numeric code representing the run type of this CODA component.
    • getRunType

      public String getRunType()
      Get the runType of this CODA component.
      Specified by:
      getRunType in interface CODAComponent
      Returns:
      the runType of this CODA component
    • getCmsgUDL

      public String getCmsgUDL()
      Get the UDL used to connect to the cMsg server by this CODA component.
      Specified by:
      getCmsgUDL in interface CODAComponent
      Returns:
      the UDL used to connect to the cMsg server by this CODA component
    • getPlatformIpAddresses

      public String[] getPlatformIpAddresses()
      Get the rc platform's IP addresses as dot-decimal strings.
      Returns:
      rc platform's IP addresses as dot-decimal strings, null if none.
    • getPlatformTcpPort

      public int getPlatformTcpPort()
      Get the platform's cMsg domain server's TCP port.
      Returns:
      platform's cMsg domain server's TCP port, 0 if none.
    • getBufferLevel

      public int getBufferLevel()
      Get the smallest number of evio-events/et-buffer that connected DC/PEB found. Meaningful only for a ROC.
      Returns:
      smallest number of evio-events/et-buffer that connected DC/PEB found.
    • setBufferLevel

      public void setBufferLevel(int bufferLevel)
      Set the smallest number of evio-events/et-buffer that connected DC/PEB found. Meaningful only for a ROC.
      Parameters:
      bufferLevel - smallest number of evio-events/et-buffer that connected DC/PEB found.
    • configuration

      public Document configuration()
      Get the configuration of this CODA component in the form of a parsed XML document object that is loaded from a file when the configure command is executed. It may change from run to run and tells the Emu which modules to load, which data transports to start and what data channels to open.
      Specified by:
      configuration in interface CODAComponent
      Returns:
      the CODA component configuration object as a parsed XML document
    • parameters

      public Document parameters()
      Get the configuration of this CODA component in the form of a parsed XML document object that is loaded when the configure command is executed. It contains all of the status variables that change from run to run.
      Specified by:
      parameters in interface CODAComponent
      Returns:
      the CODA component configuration object as a parsed XML document that contains all of the status variables that change from run to run
    • setRunNumber

      public void setRunNumber(int runNumber)
      Set the run number of this CODA component.
      Specified by:
      setRunNumber in interface CODAComponent
      Parameters:
      runNumber - the run number of this CODA component
      See Also:
    • setRunTypeId

      public void setRunTypeId(int runTypeId)
      Set the numeric code representing the run type of this CODA component.
      Specified by:
      setRunTypeId in interface CODAComponent
      Parameters:
      runTypeId - the numeric code representing the runType of this CODA component
      See Also:
    • setRunType

      public void setRunType(String runType)
      Set the runType of this CODA component.
      Specified by:
      setRunType in interface CODAComponent
      Parameters:
      runType - the runType of this CODA component
      See Also:
    • getCodaClassObject

      public CODAClass getCodaClassObject()
      Get the CODAClass of this emu.
      Returns:
      CODAClass of this emu.
    • setCodaClass

      public void setCodaClass(CODAClass codaClass)
      Method to set the CODAClass member.
      Parameters:
      codaClass - type of CODA component such as ROC, EMU, or ER.
    • isFileWritingOn

      public boolean isFileWritingOn()
      Set the flag to tell file output channel to actually write the file or not.
      Returns:
      true if file output channel will actually write the file, else false.
    • getFramework

      public DebugFrame getFramework()
      Get the debug GUI object.
      Returns:
      debug gui.
    • getThreadGroup

      public ThreadGroup getThreadGroup()
      Get the ThreadGroup this emu's threads are part of.
      Returns:
      ThreadGroup this emu's threads are part of.
    • getLogger

      public Logger getLogger()
      Get the Logger this emu uses.
      Returns:
      Logger this emu uses.
    • getCmsgPortal

      public CMSGPortal getCmsgPortal()
      Get the cmsgPortal object of this emu.
      Returns:
      cmsgPortal object of this emu.
    • getEndingTimeLimit

      public long getEndingTimeLimit()
      This method gets the amount of milliseconds to wait for an END command to succeed before going to an ERROR state.
      Returns:
      amount of milliseconds to wait for an END command to succeed before going to an ERROR state.
    • getInputChannelCount

      public int getInputChannelCount()
      Get out the number of input channels to the first module. This is determined when initially receiving the configure command.
      Returns:
      number of input channels to the first module.
    • getInChannels

      public List<DataChannel> getInChannels()
      Get list of input channels.
      Returns:
      list of input channels
    • getOutChannels

      public List<DataChannel> getOutChannels()
      Get list of output channels.
      Returns:
      list of output channels
    • getDataStreamId

      public int getDataStreamId()
      Get the id number of the data stream this emu is a part of. Only relevant if this emu is an EB which outputs to a single ER, or has an output file channel.
      Returns:
      data stream id.
    • getDataStreamCount

      public int getDataStreamCount()
      Get the total number of data streams in the configuration which contains this emu.
      Returns:
      total number of data streams in this configuration.
    • getFileOutputCount

      public int getFileOutputCount()
      Get the number of file output channels in this emu.
      Returns:
      number of file output channels in this emu.
    • theEndIsNigh

      public boolean theEndIsNigh()
      Get whether END button has been pushed. If true, someone hit the END button, but the END event has not necessarily come through yet and the END command may not have been received yet. This allows the file channel (in ER) to cleanup if disk is full and END button was pushed.

      Only to be used internally to the emu.

      Returns:
      true if someone hit the END button (until END transition finished).
    • previousState

      public CODAStateIF previousState()
      This method returns the previous state of the modules in this Emu. If the Emu has not undergone any transitions yet, it returns null.
      Returns:
      state before last transition
    • getError

      public String getError()
      Get any available error information.
      Specified by:
      getError in interface StatedObject
      Returns:
      any available error information; null if none
    • setState

      public void setState(CODAStateIF state)
      This method sets the state of this Emu, but not if emu is currently resetting in which case it immediately returns. Setting the state is synchronized on the emu object to ensure that the state does not change while it's being read.
      Parameters:
      state - desired state of this Emu.
    • getState

      public CODAState getState()
      This method gets the state of this Emu.
      Returns:
      state of this Emu.
    • setErrorState

      public void setErrorState(String errorCause)
      This method sets the state of this Emu to ERROR, but not if the emu is currently resetting in which case it immediately returns. It sends an error message to run control if not already done. Setting the state is synchronized on the emu object to ensure that the state does not change while it's being read.
      Parameters:
      errorCause - description of error's cause.
    • state

      public CODAStateIF state()
      Get the state of this object.
      Specified by:
      state in interface StatedObject
      Returns:
      the state of this object
    • sendRcInfoMessage

      public void sendRcInfoMessage(String msg)
      Send run control a informational message which gets displayed in its GUI.
      Parameters:
      msg - info message
    • sendRcWarningMessage

      public void sendRcWarningMessage(String msg)
      Send run control a warning message which gets displayed in its GUI.
      Parameters:
      msg - warning message
    • sendRcErrorMessage

      public void sendRcErrorMessage(String error)
      Send run control an error message which gets displayed in its GUI.
      Parameters:
      error - error message
    • sendRcSevereMessage

      public void sendRcSevereMessage(String error)
      Send run control a severe error message which gets displayed in its GUI.
      Parameters:
      error - severe message
    • addOutputDestination

      public int addOutputDestination(String outputDestination)
      Add a single output destination name, like a file or et system name, or a string like "cMsg", to the array of destinations names. Call this when setting a destination for the first time. Do NOT call this if resetting an existing output destination file name to the next split file name.
      Parameters:
      outputDestination - name of an output data destination of this emu
      Returns:
      number of already existing output destinations.
    • setOutputDestination

      public void setOutputDestination(int index, String outputDestination)
      Change an existing single output destination name in the array of names. Call this if resetting an existing output destination file name to the next split file name.
      Parameters:
      index - index in array of name to be changed.
      outputDestination - name of an output destination.
    • clearOutputDestinations

      public void clearOutputDestinations()
      Clear output destination names.
    • sendStatusMessage

      public void sendStatusMessage()
      Allow the "out-of-band" sending of a status message to run control.
    • getTime

      public long getTime()
      Get the time from System.currentTimeMillis(), but it's updated only every second or thereabouts.
      Returns:
      time from System.currentTimeMillis()
    • postCommand

      public void postCommand(Command cmd) throws InterruptedException
      This method puts a command object into a mailbox of a CODA component that is periodically checked by that component.
      Specified by:
      postCommand in interface CommandAcceptor
      Parameters:
      cmd - of type Command (eg. start transition, control run variables, control session)
      Throws:
      InterruptedException - if thread interrupted while in method.
    • reset

      public void reset()
      This method executes a RESET command. We don't queued it up and possibly have it wait like a transition command. RESET must always have top priority and is executed in the cMsg callback. Synchronized on emu.
      Specified by:
      reset in interface CODAComponent
    • execute

      public void execute(Command cmd)
      This method takes a Command object and attempts to execute it.
      Parameters:
      cmd - of type Command