java.lang.Object
org.scictrl.mp.orbitcorrect.model.optics.DataBush

public class DataBush extends Object
DataBush holds together objects representation of physical view of Control System (CS for short). It provides organized access to all elements, manages their cooindependance and synchronization. DataBush also perform group operations and linear optics calculations.

DataBush keeps persistance of basic settings and event listeners while DataBush is initialized and cleared as many times as needed.
Author:
igor@scictrl.com
  • Field Details

    • debug

      public static boolean debug
      Enables/disables aditional debug output.
    • DEFAULT_POSITION_PRECISION

      public static final double DEFAULT_POSITION_PRECISION
      DataBush default value for position precision.
      See Also:
    • DEFAULT_CURRENT_PRECISION

      public static final double DEFAULT_CURRENT_PRECISION
      DataBush default value for PowerSupply's current precision.
      See Also:
    • DEFAULT_BPM_POSITION_PRECISION

      public static final double DEFAULT_BPM_POSITION_PRECISION
      DataBush default value for BPM's value precision.
      See Also:
    • DEFAULT_MIN_UPDATE_INTERVAL

      public static final long DEFAULT_MIN_UPDATE_INTERVAL
      DataBush default value for minimal interval between linear optics updates.
      See Also:
  • Constructor Details

    • DataBush

      public DataBush()
      Constructs empty instance of DataBush. Status of DataBush is set to DBConst.EMPTY. All lists are accessible, but none of DataBush elements, since they don't exsists.

      AbeanInitializer is initialized with DataBush. DataBush application by default does not need any aditional ABean initializations in order to work with Abeans.
      See Also:
  • Method Details

    • abort

      public void abort()
      This method sets aborted flag on own DataBushHandler to true.
    • addActionReportListener

      public void addActionReportListener(IActionReportListener listener)
      Adds listener for performed actions on DataBush or its elements.
      Parameters:
      listener - a IActionReportListener object
      See Also:
    • addConnectionListener

      public void addConnectionListener(IConnectionListener listener)
      Adds listener for connection events on DataBush elements.
      Parameters:
      listener - a IConnectionListener object
    • addDataBushListener

      public void addDataBushListener(IDataBushListener listener)
      Adds listener to DataBush.
      Parameters:
      listener - a IDataBushListener object
      See Also:
    • apply

      Sends values from all DataBush elements to the Control System. First are applied CalibratedMagnets to PoweSupplies, than currents on PowerSupplies to CS. Returns the code of element with best result returned. Apply is allways performed till last element, than all caught exceptions are thrown with one PackedDBException.
      Returns:
      a int the code of element with best result returned
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      DataBushPackedException - contains all exception thrown or caught during invoking apply on all elements
      InconsistentDataException - thrown before values are actully send to CS, if PowerSupply is assigned to more than one Magnet and diference betwean different desired current values is to high.
    • applyFast

      Perform fast apply for elements in list. Values are sent to CS one after another as fast as possible with asynchronus sets. If any exception was cought during proccess, it is rethrown with PackedDBException after all sets are finished. Returns the code of element with best result returned. NOTE! This method is not synchronized to synchronization lock.
      Parameters:
      cor - a ElementList object if any.
      Returns:
      a int the code of element with best result returned
      Throws:
      DataBushPackedException - contains all exception thrown or caught during invoking apply on specified elements
      DataBushPackedException - contains all exception thrown or caught during invoking apply on specified elements
      InconsistentDataException - thrown before values are actully send to CS, if PowerSupply is assigned to more than one Magnet and diference betwean different desired current values is to high.
      ControlSystemException - if any.
      IllegalStateException - if any.
    • clear

      public void clear()
      Clears all elements from DataBush. status of DataBush is set to DB_EMPTY. All listeners persist.
      See Also:
    • connect

      public int connect() throws IllegalStateException, DataBushPackedException
      Connects all connectable DataBush elements to appropriate Abean objects. Returns the code of element with best result returned.
      Returns:
      a int the code of element with best result returned
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      DataBushPackedException - contains all exception thrown or caught during invoking connect on all elements
      See Also:
    • disconnect

      public int disconnect() throws IllegalStateException, DataBushPackedException
      Disconnects all connectable DataBush elements. Returns the code of element with best result returned.
      Returns:
      a int the code of element with best result returned
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      DataBushPackedException - contains all exception thrown or caught during invoking disconnect on all elements
      See Also:
    • getAlpha

      public PositionedData getAlpha()
      Returns closed orbit solution for alpha-function. This is convenience method for getDataBushInfo().getAlpha().
      Returns:
      a PositionedData closed orbit solution for alpha-function
    • getAlphaList

      public PositionedDataList getAlphaList()
      Returns list with values of alpha funtion for all optical elements in DataBush.
      Returns:
      a PositionedDataList list with values of alpha funtion for all optical elements in DataBushect
    • getBeamSimulator

      public IBeamSimulator getBeamSimulator()
      This method return IBeamSimulator, which is used. If nobody, returns DefaultBeamSimulator
      Returns:
      IBeamSimulator
    • getBendings

      public BendingList getBendings()
      Returns list with all bending magnets in DataBush.
      Returns:
      a BendingList list with all bending magnets
    • getBeta

      public PositionedData getBeta()
      Returns closed orbit solution for beta-function. This is convenience method for getDataBushInfo().getBeta().
      Returns:
      a PositionedData closed orbit solution for beta-function
    • getBetaList

      public PositionedDataList getBetaList()
      Returns list with values of beta-funtion for all optical elements in DataBush.
      Returns:
      a PositionedDataList list with values of beta-funtion for all optical elements in DataBush
    • getBinded

      public BindedList getBinded()
      Returns list with all IBindedElement elements in DataBush.
      Returns:
      a BindedList list with all IBindedElement elements in DataBush
    • getBPMonitor

      public BPMonitor getBPMonitor(int index)
      Returns the BPMonitor at the specified index.
      Parameters:
      index - a int index of BPMmonitor to return.
      Returns:
      a BPMonitor the BPMonitor at the specified index
    • getBPMonitors

      public BPMonitorList getBPMonitors()
      Returns list with all BPMonitor elements in DataBush.
      Returns:
      a BPMonitorList list with all BPMonitor elements in DataBush
    • getBPMonitors

      public BPMonitor[] getBPMonitors(int[] pick)
      Returns array of BPMonitor elements at the specified indices.
      Parameters:
      pick - an array of
      invalid reference
      int
      indices of BPMonitor elements to return.
      Returns:
      an array of BPMonitor array of BPMonitor elements at the specified indices
    • getBPMPositionPrecision

      public double getBPMPositionPrecision()
      Returns precision of BPMonitor beam position value handling.
      Returns:
      a double precision of BPMonitor bean position value handling
      See Also:
    • getCalculatorModelFactory

      public ICalculatorModelFactory getCalculatorModelFactory()
      Returns factory for calibration calculators.
      Returns:
      a ICalculatorModelFactory factory for calibration calculators
      See Also:
    • getCalMagnets

      public CalMagnetList getCalMagnets()
      Returns list with all AbstractCalibratedMagnet elements in DataBush.
      Returns:
      a CalMagnetList list with all AbstractCalibratedMagnet elements in DataBush
    • getControlSystemEngine

      public IControlSystemEngine getControlSystemEngine()
      This method return IControlSystemEngine, that is used. If no IControlSystemEngine is in use, method return default IControlSystemEngine.
      Returns:
      IControlSystemEngine
      See Also:
    • getCorrector

      public AbstractCorrector getCorrector(int index)
      Returns the AbstractCorrector at the specified index.
      Parameters:
      index - a int index of AbstractCorrector to return.
      Returns:
      a AbstractCorrector the AbstractCorrector at the specified index
    • getCorrectors

      public CorrectorList getCorrectors()
      Returns list with all AbstractCorrector elements in DataBush.
      Returns:
      a CorrectorList list with all AbstractCorrector elements in DataBush
    • getCorrectors

      public AbstractCorrector[] getCorrectors(int[] pick)
      Returns array of AbstractCorrector elements at the specified indices.
      Parameters:
      pick - an array of
      invalid reference
      int
      indices of AbstractCorrector elements to return.
      Returns:
      an array of AbstractCorrector array of AbstractCorrector elements at the specified indices
    • getCurrentApplyModel

      public ICurrentApplyModel getCurrentApplyModel()
      Returns model for applying current.
      Returns:
      a ICurrentApplyModel model for applying current
    • getCurrentPrecision

      public double getCurrentPrecision()
      Returns the precision of PowerSupply electric current value handling.
      Returns:
      a double the precision of PowerSupply electric current value handling
      See Also:
    • getDataBushElement

      public AbstractDataBushElement getDataBushElement(String name)
      Returns AbstractDataBushElement with specified name. If not exsist, null is returned.
      Parameters:
      name - a String the name of element to return
      Returns:
      a AbstractDataBushElement AbstractDataBushElement with specified name
    • getDataBushInfo

      public DataBushInfo getDataBushInfo()
      Returns DataBushInfo element if present, otherwise null.
      Returns:
      a DataBushInfo e;ement
    • getDispersion

      public DispersionData getDispersion()
      Returns closed orbit solution for horizontal momentum dispersion function. This is convenience method for getDataBushInfo().getDispersion().
      Returns:
      a DispersionData closed orbit solution for horizontal momentum dispersion function
    • getDispersionList

      public DispersionDataList getDispersionList()
      Returns list with values of horizontal momentum dispersion function for all optical elements in DataBush.
      Returns:
      a DispersionDataList list with values of horizontal momentum dispersion function for all optical elements in DataBush
    • getElement

      public AbstractDataBushElement getElement(String name)
      Returns element with specified name, if contained in this DataBush. If not, null is reurned.
      Parameters:
      name - a String object
      Returns:
      element, if contained int this DataBush, null otherwise.
    • getLog

      public org.apache.logging.log4j.Logger getLog()

      getLog.

      Returns:
      a Logger object
    • getElementMatrix

      public TransferMatrix getElementMatrix(String name)
      Returns transfer matrix of AbstractTransferElement with specified name. If there is no such element, null pointer exception is thrown.
      Parameters:
      name - a String the name of element to return transfer matrix
      Returns:
      a TransferMatrix transfer matrix of AbstractTransferElement with specified name
    • getHorCorrectors

      public HorCorrectorList getHorCorrectors()
      Returns list with all HorCorrector elements in DataBush.
      Returns:
      a HorCorrectorList list with all HorCorrector elements in DataBush
    • getMachineFunctions

      public double[][] getMachineFunctions(double[][] dataArray, AbstractOpticalElement oe1, AbstractOpticalElement oe2, int count) throws IllegalStateException, IllegalArgumentException, InconsistentDataException
      Calculates machine functions on specified interval at count points. DataBush tries to spread the points as much equidistant as possible. It allways takes beginning and end position of each DataBush element in interval.

      Result is stored in dataArray matrix which should have dimension 9×count. Rows with values are accessed with DBConst constants: MF_POSITION, MF_Q_X, MF_Q_Z, MF_BETA_X MF_BETA_Z, MF_ALPHA_X, MF_ALPHA_Z, MF_D, MF_DP.
      Parameters:
      dataArray - an array of
      invalid reference
      double
      a 9×count matrix to recive the result
      oe1 - a AbstractOpticalElement the begining element of interval
      oe2 - a AbstractOpticalElement the ending element of interval
      count - a int number of points machine functions to be calculated
      Returns:
      dataArray parameter
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      IllegalArgumentException - thrown if dataArray does not mach specification or number of points is to low (at least one per optical element)
      InconsistentDataException - thrown if no closed orbit solutin exsists
      See Also:
    • getMachineFunctions

      public List<Double>[] getMachineFunctions(List<Double>[] dataVectors, AbstractOpticalElement oe1, AbstractOpticalElement oe2, int count) throws IllegalStateException, IllegalArgumentException, InconsistentDataException
      Calculates machine functions on specified interval at count points. DataBush tries to spread the points as much equidistant as possible. It allways takes beginning and end position of each DataBush element in interval.

      Result is stored in dataVectors. dataVectors must be array of 9 empty java.util.Vector objects. Vectors with machine function values are accessed with DBConst constants: MF_POSITION, MF_Q_X, MF_Q_Z, MF_BETA_X MF_BETA_Z, MF_ALPHA_X, MF_ALPHA_Z, MF_D, MF_DP.
      Parameters:
      dataVectors - an array of List array of 9 empty java.util.Vector objects
      oe1 - a AbstractOpticalElement the begining element of interval
      oe2 - a AbstractOpticalElement the ending element of interval
      count - a int number of points machine functions to be calculated
      Returns:
      dataVectors parameter
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      IllegalArgumentException - thrown if dataVectors does not mach specification or number of points is to low (at least one per optical element)
      InconsistentDataException - thrown if no closed orbit solutin exsists
      See Also:
    • getMagnets

      public MagnetList getMagnets()
      Returns list with all AbstractMagnetElement elements in DataBush.
      Returns:
      a MagnetList list with all AbstractMagnetElement elements in DataBush
    • getMinFreeOpticalLength

      public double getMinFreeOpticalLength() throws IllegalStateException
      Returns minimal optical path length. This is the shortest distance between any optical element beginning and end. For example shortest element length or shortest distance between two elements. Helps to determine minimum required number of points for machine function calculation.
      Returns:
      a double minimal optical path length
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      See Also:
    • getMinUpdateInterval

      public long getMinUpdateInterval()
      Returns the minimal allowed interval in milliseconds between two linear optic calculations.
      Returns:
      a long the minimal allowed interval in milliseconds between two linear optic calculations
    • getOptics

      public OpticsList getOptics()
      Returns list with all AbstractOpticalElement elements in DataBush.
      Returns:
      a OpticsList list with all AbstractOpticalElement elements in DataBush
    • getOpticsLength

      public double getOpticsLength()
      Returns length of orbit.
      Returns:
      a double length of orbit.
    • getPositionPrecision

      public double getPositionPrecision()
      Returns the precision of element's position handling.
      Returns:
      a double the precision of element's position handling
      See Also:
    • getPowerSupplies

      public PowerSupplyList getPowerSupplies()
      Returns list with all PowerSupply elements in DataBush.
      Returns:
      a PowerSupplyList list with all PowerSupply elements in DataBush
    • getQ

      public PositionedData getQ()
      Returns tune of closed orbit. This is convenience method for getDataBushInfo().getQ().
      Returns:
      a PositionedData tune of closed orbit
    • getQList

      public PositionedDataList getQList()
      Returns list with values of phase of beta-functions, divided by 2 pi, for all optical elements in DataBush.
      Returns:
      a PositionedDataList list with values of phase of beta-functions, divided by 2 pi, for all optical elements in DataBush
    • getRFGenerator

      public RFGenerator getRFGenerator()
      Returns RFGenerator element if present, otherwise null.
      Returns:
      a RFGenerator element
      See Also:
    • getStatus

      public int getStatus()
      Returns status of DataBush. Status has two possible values
      • DBConst.DB_EMPTY - when DataBush in not initialized and contains no elements.
      • DBConst.DB_OPERATIONAL - after successful initialization
      Returns:
      status of DataBush
      See Also:
    • isStatusEmpty

      public boolean isStatusEmpty()
      Returns true if status of DataBush is DBConst.DB_EMPTY - when DataBush in not initialized and contains no elements.
      Returns:
      true if status of DataBush is DBConst.DB_EMPTY
      See Also:
    • isStatusOperational

      public boolean isStatusOperational()
      Returns true if status of DataBush is DBConst.DB_OPERATIONAL - after successful initialization.
      Returns:
      true if status of DataBush is DBConst.DB_OPERATIONAL
      See Also:
    • getSynchronizationLock

      public Object getSynchronizationLock()
      Returns synchronization lock for DataBush. All DataBush updating, applying is locked inside this lock.
      Returns:
      synchronization lock for DataBush
    • getTransfers

      public TransferList getTransfers()
      Returns list with all AbstractTransferElement elements in DataBush.
      Returns:
      a TransferList list with all AbstractTransferElement elements in DataBush
      See Also:
    • getUpdateMode

      public int getUpdateMode()
      Returns update mode code. Update mode controls how DataBush is updated.
      Returns:
      a int update mode code
      See Also:
    • getVerCorrectors

      public VerCorrectorList getVerCorrectors()
      Returns list with all VerCorrector elements in DataBush.
      Returns:
      a VerCorrectorList list with all VerCorrector elements in DataBush
    • hasClosedOrbitSolution

      public boolean hasClosedOrbitSolution()
      Returns true if closed orbit solution was foud when last linear optics calculation was performed.
      Returns:
      true if closed orbit solution was foud when last linear optics
    • init

      Initialize DataBush with elements from list. If initialization sucseds, DataBush become operational (DB_OPERATIONAL).
      Parameters:
      l - a ElementList list of elements to put in DataBush
      Throws:
      IllegalStateException - thrown if DataBush allready operational.
      DataBushInitializationException - thrown, if DataBush was not able to initialize with given elements
    • isProperySetFiresEvent

      public boolean isProperySetFiresEvent()
      This method perform isSetFiresEvent() method on own DataBushHandler.
      Returns:
      boolean
      See Also:
    • removeActionReportListener

      public void removeActionReportListener(IActionReportListener listener)
      Removes listener for performed actions on DataBush or its elements.
      Parameters:
      listener - a IActionReportListener object
      See Also:
    • removeConnectionListener

      public void removeConnectionListener(IConnectionListener listener)
      Removes listener for connection events on DataBush elements.
      Parameters:
      listener - a IConnectionListener object
      See Also:
    • removeDataBushListener

      public void removeDataBushListener(IDataBushListener listener)
      Removes listener from DataBush.
      Parameters:
      listener - a IDataBushListener object
      See Also:
    • setBeamSimulator

      public void setBeamSimulator(IBeamSimulator newBeamSimulator)
      This method sets new IBeamSimulator
      Parameters:
      newBeamSimulator - IBeamSimulator
    • setBPMPositionPrecision

      public void setBPMPositionPrecision(double precision)
      Sets precision of BPMonitor beam position value handling. If in UPDATE_ON_EVENT update mode BPMonitor gets new value from CS, that is different from current less them precision, it is assumed as same and no event fires.

      This value is independent of DataBush status. Can be seted at any time.
      Parameters:
      precision - a double new precision
      See Also:
    • setCalculatorModelFactory

      public void setCalculatorModelFactory(ICalculatorModelFactory newValue) throws IllegalStateException
      Sets the factory for calibration calculators. If none is seted, defaul one is used. To use default one, set to DataBush input file location. It is needed by default factory.

      This property can be setted only vhen DataBush is empty, otherwise IllegalStateException is thrown.
      Parameters:
      newValue - a ICalculatorModelFactory new factory for calibration calculators
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_OPERATIONAL
      See Also:
    • setControlSystemEngine

      public void setControlSystemEngine(IControlSystemEngine newControlSystemEngine) throws IllegalStateException
      This method sets IControlSystemEngine.
      Parameters:
      newControlSystemEngine - a IControlSystemEngine object
      Throws:
      IllegalStateException - if any.
      See Also:
    • setCurrentApplyModel

      public void setCurrentApplyModel(ICurrentApplyModel newValue)
      Sets the model for applying current.

      This value is independent of DataBush status. Can be seted at any time.
      Parameters:
      newValue - a ICurrentApplyModel new model for applying current
      See Also:
    • setCurrentPrecision

      public void setCurrentPrecision(double newValue)
      Sets the precision of PowerSupply electric current value handling. If in UPDATE_ON_EVENT update mode PowerSupply gets new value from CS, that is different from current one less then precision, it is assumed as same and no event fires.

      This value is independent of DataBush status. Can be seted at any time.
      Parameters:
      newValue - a double new precision of PowerSupply current value handling
      See Also:
    • setMinUpdateInterval

      public void setMinUpdateInterval(long newValue)
      Sets the minimal allowed interval in milliseconds between two linear optic calculations. This value is used in UPDAT_ON_EVENT update mode.

      This value is independent of DataBush status. Can be seted at any time.
      Parameters:
      newValue - a long new minimal allowed interval in milliseconds
    • setPositionPrecision

      public void setPositionPrecision(double newValue)
      Sets the precision of element's position handling. This value is used when element positions are recalculated. If one element ends and other starts within position of this precision, then is assumed, that there is no gap in between.

      This value is independent of DataBush status. Can be seted at any time.
      Parameters:
      newValue - a double
      See Also:
    • setProperySetFiresEvent

      public void setProperySetFiresEvent(boolean newSetProperyFiresEvent)
      This method perform setSetFiresEvent() method on own DataBushHandler.
      Parameters:
      newSetProperyFiresEvent - a boolean
    • setUpdateMode

      public void setUpdateMode(int mode) throws IllegalStateException
      Sets update mode code. Update mode controls how DataBush is updated. There are two update modes:
      • DBConst.UPDATE_MANUAL - DataBush is updated, when update method is called. This is defualt mode.
      • DBConst.UPDATE_ON_EVENT - DataBush is updated upon monitor events from Abean family. Manual updating will thow an exception.


      This operation can be preformed only on operational DataBush. If DataBush is empty, When DataBush is cleared, update mode is reset to UPDATE_MANUAL. IllegalStateException will be thrown.
      Parameters:
      mode - a int update mode code
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      See Also:
    • simulateBPMs

      public void simulateBPMs() throws IllegalStateException
      Symulates BPM beam positions with closed orbit calculation. This operation can be preformed only on operational DataBush. If DataBush is empty, When DataBush is cleared, update mode is reset to UPDATE_MANUAL. IllegalStateException will be thrown.
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
    • testPowerSupplies

      public boolean testPowerSupplies(ElementList<AbstractDataBushElement> list) throws IllegalArgumentException, IllegalStateException
      Tests power supplies or magnets in lust if are usable.
      Parameters:
      list - a ElementList object
      Returns:
      if true if all powers supplies are usable, false otherwise
      Throws:
      IllegalArgumentException - thrown if lust contains element, which is not PowerSupply nor AbstractMagnetElement element
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
    • toString

      public String toString()
      Returns string representation of DataBush. First is returned string representation of DataBushInfo element, than all optical element in optical order and than power supplies. Returned string if formated and can be used as input for DefaultDBReader.
      Overrides:
      toString in class Object
    • transferMatrix

      This method returns first optical element to last.
      Parameters:
      first - a AbstractOpticalElement object
      last - a AbstractOpticalElement object
      Returns:
      TransferMatrix
      Throws:
      IllegalStateException - if any.
      InconsistentDataException - if any.
      See Also:
    • transferMatrix

      This method returns first optical element to last. Elements are represented by SimpleData
      Parameters:
      first - a SimpleData object
      last - a SimpleData object
      Returns:
      TransferMatrix
      Throws:
      IllegalStateException - if any.
      InconsistentDataException - if any.
      See Also:
    • update

      public int update() throws IllegalStateException, DataBushPackedException
      Reads values from Control System and updates DataBush elements. First are updated power supplies, BPM's nad DataBushInfo. Than magnets and linear optics data. Returns the code of element with best result returned. Update is allways performed till last element, than all caught exceptions are thrown with one PackedDBException.
      Returns:
      a int the code of element with best result returned
      Throws:
      IllegalStateException - thrown if status of DataBush equals DB_EMPTY
      DataBushPackedException - contains all exception thrown or caught during updating all elements