Class Scenario

java.lang.Object
xal.sim.scenario.Scenario

public class Scenario extends Object

Packages an on-line model scenario, including accelerator node proxy manager, lattice, probe, and synchronization manager.

It is not necessary for the Scenario object to maintain a back reference to the original AcceleratorSeq object that it models. In fact it is undesirable since this represents a dependency of the online model with the SMF hardware representation component of Open XAL. Its current uses here are not so requirements, typically used to lookup hardware nodes from their IDs. This can be done directly on the hardware sequence itself without using this class as a proxy.

Author:
Craig McChesney, Christopher K. Allen
  • Field Details

    • SYNC_MODE_LIVE

      public static final String SYNC_MODE_LIVE
      Synchronization manager constant for live machine synchronization
      See Also:
    • SYNC_MODE_DESIGN

      public static final String SYNC_MODE_DESIGN
      Synchronization manager constant for design parameter synchronization
      See Also:
    • SYNC_MODE_RF_DESIGN

      public static final String SYNC_MODE_RF_DESIGN
      Synchronization manager constant for synchronization only to live magnet values
      See Also:
  • Constructor Details

  • Method Details

    • newScenarioFor

      public static Scenario newScenarioFor(AcceleratorSeq smfSeq) throws ModelException
      Creates a new Scenario for the supplied accelerator sequence.
      Parameters:
      smfSeq - the accelerator sequence to build a scenario for
      Returns:
      a new Scenario for the supplied accelerator sequence
      Throws:
      ModelException - error building Scenario
    • newScenarioFor

      public static Scenario newScenarioFor(AcceleratorSeq smfSeq, ElementMapping mapNodeToElem) throws ModelException
      Creates a new Scenario for the supplied accelerator sequence and element mapping.
      Parameters:
      smfSeq - the accelerator sequence to build a scenario for
      mapNodeToElem - the element mapping to build a scenario with
      Returns:
      a new model Scenario for the supplied accelerator sequence
      Throws:
      ModelException - general error building model lattice
    • newScenarioFor

      public static Scenario newScenarioFor(Ring smfRing) throws ModelException
      Creates a new Scenario object for the explicit case where the AcceleratorSeq object is of type xal.smf.Ring.
      Parameters:
      smfRing - target hardware (SMF) ring object
      Returns:
      Scenario object encapsulating ring
      Throws:
      ModelException - unable to build modeling scenario
    • setSynchronizationMode

      public void setSynchronizationMode(String newMode)
      Sets the synchronization mode for the sync manager to a known sync mode, such as SynchronizationManager.SYNC_MODE_LIVE or SYNC_MODE_DESIGN.
      Parameters:
      newMode - String specifying mode to set to
      Throws:
      IllegalArgumentException - if the specified mode is unknown
    • getSynchronizationMode

      public String getSynchronizationMode()
      get the synchronization mode
    • resync

      public void resync() throws SynchronizationException
      Synchronizes each lattice element to the appropriate data source.
      Throws:
      SynchronizationException - if an error is encountered reading a data source
    • resyncFromCache

      public void resyncFromCache() throws SynchronizationException
      Synchronizes each lattice element from the cache and applies the whatif model inputs.
      Throws:
      SynchronizationException - if an error is encountered reading a data source
    • setStartNode

      public void setStartNode(String nodeId) throws ModelException
      Sets the model to start propagation from the AcceleratorNode with the specified id. First get the AcceleratorNode for the id, find the first element mapped to it, and then set it as the starting element in the lattice.
      Parameters:
      nodeId - ID of AcceleratorNode to start from
      Throws:
      ModelException - if the node is not found, or no elements are mapped to it
    • setStopNode

      public void setStopNode(String nodeId) throws ModelException
      Sets the model to stop propagation the AcceleratorNode with the specified id. By default the model will stop propagation AFTER this node. This behavior can be changed in the Tracker ( see setStopNodeInclusive(boolean) method.
      Parameters:
      nodeId - ID of the AcceleratorNode to stop after
      Throws:
      ModelException - if the node is not found, or no elements are mapped to it
    • setStartComponent

      public void setStartComponent(IComponent start)
      Sets the model to start propagation from the specified IComponent. If you don't have a reference to a component but do have an AcceleratorNode, use setStartNode(String).
      Parameters:
      start - Component to start propagation from
    • setStopComponent

      public void setStopComponent(IComponent stop)
      Sets the model to stop propagation (by default) after the specified IComponent. If you don't have a reference to a component but do have an AcceleratorNode, use setStopNode(String). This "stop after" behavior can be changed in the Tracker ( see setStopNodeInclusive(boolean) method.
      Parameters:
      stop - Component to stop propagation after
    • setIncludeStopElement

      public void setIncludeStopElement(boolean bolInclStopElem)
      Sets the flag that determines whether or not the propagation stops at the entrance of the stop element (if set), or at the exit of the stop node. The later case is the default.
      Parameters:
      bolInclStopElem - propagation stops after stop element if true, before the stop element if false
      Since:
      Oct 20, 2014
    • getPositionRelativeToStart

      public double getPositionRelativeToStart(double positionInSequence)
      Convert the position of a location in the sequence to a position in a trajectory due to a start element offset specified in the scenario.
      Parameters:
      positionInSequence - The position of a location in this scenario's sequence
      Returns:
      the corresponding position relative to this scenario's starting element
    • run

      public void run() throws ModelException
      Runs the model (propagate probe through lattice).
      Throws:
      ModelException - if there is an error propagating the probe
      IllegalStateException - if the lattice or probe is not properly initialized
    • getLattice

      public Lattice getLattice()
      Returns the lattice. NOTE: I (Craig M) don't like this here. I only added it so that I could keep ModelProxy working as it presently does. Let's figure out a way to change it. It seems that the only thing that gets the Lattice from ModelProxy is OrbitDisplay2. If it were changed to use Scenario, then this method could be removed!
      Returns:
      the Lattice
    • setLattice

      public void setLattice(Lattice aLattice)
    • getTrajectory

      public <S extends ProbeState<S>> Trajectory<S> getTrajectory()

      NOTE

      Returns the trajectory obtained by running the model. · The type of the object returned is actually Trajectory<?> since the actual type of the trajectory is not known. Any type of probe may be used to run the scenario.

      · This is simply a convenient way to avoid the clumsy Java type casting, however, it is essentially the same thing.

      · A runtime cast exception will be thrown if the trajectory does not match the probe type currently run.

      Returns:
      the Trajectory obtained by running the model
      Throws:
      IllegalStateException - if the probe or trajectory is null
    • propertiesForNode

      public Map<String,Double> propertiesForNode(AcceleratorNode aNode)
      Returns a map of property values (key = String property name, value = double property value) for the supplied node.
      Parameters:
      aNode - AcceleratorNode whose properties to get
      Returns:
      a Map of property values for the supplied node
      Throws:
      IllegalArgumentException - if aNode is null
    • nodeWithId

      public AcceleratorNode nodeWithId(String id)
      Returns the accelerator node with the specified id, or null if there is none.
      Parameters:
      id - String id of the node to return
      Returns:
      AcceleratorNode with specified id
    • componentsMappedTo

      public List<IComponent> componentsMappedTo(AcceleratorNode aNode)
      Returns a List of components mapped to the specified node.
      Parameters:
      aNode - node to get components mapped to
      Returns:
      a List of Components mapped to the specified node
    • trajectoryStatesForElement

      public List<? extends ProbeState<?>> trajectoryStatesForElement(String id) throws ModelException
      Returns an array of the trajectory states for the specified element id.
      Parameters:
      id - element id to find states for
      Returns:
      array of trajectory states for specified element id
      Throws:
      ModelException - if the probe is not yet propagated
    • getStartElementId

      public String getStartElementId()
      Return the string identifier of the modeling element where propagation starts.
      Returns:
      modeling element string identifier
    • setStartElementId

      public void setStartElementId(String elemId)
      Set the "start" element by String id
      Parameters:
      elemId - Start element Id
    • getStopElementId

      public String getStopElementId()
      Return the string identifier of the modeling element where propagation stops.
      Returns:
      modeling element string identifier
    • setStopElementId

      public void setStopElementId(String elemId)
      Set the "stop" element by String id
      Parameters:
      elemId - Stop element Id
    • setModelInput

      public ModelInput setModelInput(AcceleratorNode aNode, String propName, double val)
      Sets the specified node's property to the specified value. Replaces the existing value if there is one.
      Parameters:
      aNode - node whose property to set
      propName - name of property to set
      val - double value for property
    • getModelInput

      public ModelInput getModelInput(AcceleratorNode aNode, String propName)
      Returns the ModelInput for the specified node's property.
      Parameters:
      aNode - node whose property to get a ModelInput for
      propName - name of property to get a ModelInput for
    • removeModelInput

      public void removeModelInput(AcceleratorNode aNode, String property)
      Removes the model input for the specified property on the specified node, if there is one.
      Parameters:
      aNode - node whose input to remove
      property - name of property whose input to remove
    • setProbe

      public void setProbe(Probe<?> aProbe)
      Sets the supplied probe for this scenario.
      Parameters:
      aProbe - the probe to be used by the scenario
    • getProbe

      public Probe<?> getProbe()
      Returns the scenario's current probe, or null if there is none.
      Returns:
      the scenario's current probe or null
    • resetProbe

      public void resetProbe()
      Resets the probe to its initial state - before propagation (e.g., the state specified in the probe xml file).
    • checkSynchronization

      public boolean checkSynchronization(AcceleratorNode aNode, Map<String,Double> values) throws SynchronizationException
      Testing Support
      Throws:
      SynchronizationException
    • unsetStartNode

      public void unsetStartNode()
      remove previously set Start point
    • unsetStopNode

      public void unsetStopNode()
      remove previously set Stop point
    • getSequence

      public AcceleratorSeq getSequence()