Package gda.device.scannable
Class ScannableUtils
java.lang.Object
gda.device.scannable.ScannableUtils
A collection of tools for Scannables and packages which use them
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown when a call to ScannableBase.validate() fails. -
Method Summary
Modifier and TypeMethodDescriptionstatic ObjectcalculateNextPoint(Object previousPoint, Object step) Given a current position and an incremental move, calculates the target position.static ObjectconvertToJava(Object object) static ObjectconvertToJava(org.python.core.PyObject object) Converts a Jython PyObject into its Java equivalent if that is possible.static ScannableSnapshotdeserializeScannableSnapshot(String serialized) Deserializes a Base64 encoded ScannableSnapshotstatic StringformatScannableWithChildren(Scannable parent, Collection<Scannable> children, boolean includeParentPosition) Formats a scannable which contains child scannables, such as ScannableGroup invalid input: '&' CoupledScannable.static double[]getCurrentPositionArray(Scannable scannable) Returns the current position of the given Scannable as an array of doublesstatic double[]getCurrentPositionArray_InputsOnly(Scannable scannable) Returns an array which is the current position, but with the 'extra' fields removedgetDetectorFieldNames(Detector detector) getDetectorFieldNames(List<Detector> detectors) static String[]getExtraNamesFormats(Scannable scannable) Returns an array of strings describing the formatting information for the output names of this scannable.static StringgetFormattedCurrentPosition(Scannable scannable) Returns the current position of the Scannable as a string.static StringgetFormattedCurrentPosition(ScannableMotion scannable) static StringgetFormattedCurrentPosition(ScannableMotionUnits scannable) static StringgetFormattedCurrentPosition(Scannable scannable, String[] unitStringArray, Double[] offsetArray) Returns the current position of the Scannable as a string including units.static String[]getFormattedCurrentPositionArray(Scannable scannable) Returns the current position of the Scannable as a formatted array of Strings.static String[]getFormattedCurrentPositionArray(Scannable scannable, Object position) static String[]getFormattedCurrentPositionArray(Object positionObject, int numberOfParts, String[] formats) Breaks currentPositionObj into the required number of parts.static StringgetFormattedPosition(Object position, Scannable scannable, String[] unitStringArray, Double[] offsetArray) Returns the current position of the Scannable as a string including units.static StringgetHTMLFormattedCurrentPosition(Scannable scannable) Returns the current position of the Scannable as an HTML string.static intgetNumberSteps(Scannable theScannable, Object start, Object stop, Object step) Assuming the objects can be converted into doubles, this calculates the number of steps for the given Scannables based on the given start, stop and step values.static intgetNumberSteps(Double startValue, Double stopValue, Double stepValue) static intgetNumDecimals(String outputFormat) Returns the number of decimals specified in the given output formatstatic int[]getNumDecimalsArray(Scannable scannable) Returns the number of decimal places for each field of the scannable, as an arraygetScannableExtraFieldNames(List<Scannable> scannables) getScannableFieldNames(Scannable scannable) getScannableFieldNames(List<Scannable> scannables) getScannableInputFieldNames(List<Scannable> scannables) getScannableNames(List<? extends Scannable> scannables) static StringgetScannablePosition(String name) Call to get the position with unit as a string.static StringNOTE: Instead of giving an exception of the EpicsMonitor is not in a valid state, this methods returns the message from the exception.static StringgetScannableUnits(Scannable scannable) Check to see if scannable has any units to return.static String[]getScannableUnitsArray(Scannable... scannables) Return an array of scannable units which map on to the scannable field names.static StringSerializes and encodes into Base64 a snapshot of a scannablestatic booleanisScannableBusy(String scannableName) Returns of the scannable is busy if it can.static Double[]objectToArray(Object position) Converts an object to an array of Doubles.static DoubleobjectToDouble(Object value) Convert an object to a Double Number 🡆 Result of doubleValue() String 🡆 Try parsing as either double or quantity Quantity 🡆 Value component - no unit conversions are made PyObject 🡆 Attempt conversion to number or string and try again Object 🡆 Call toString and try to parse the result null 🡆 null If no conversion is possible return null to differentiate the case where "NaN" orDouble.NaNis passed in.static double[]positionToArray(Object currentPositionObj, Scannable scannable) Returns the current position of the given Scannable as an array of doubles.static StringprettyPrintScannable(Scannable theScannable) static StringprettyPrintScannable(Scannable obj, int paddingSize) static Stringstatic Object[]toObjectArray(Object object) Converts an object to an array of Objects.static voidPerforms some basic validation of the given Scannable to check for internal consistency.
-
Method Details
-
getHTMLFormattedCurrentPosition
Returns the current position of the Scannable as an HTML string. This is mainly used in gda.gui.utils.WatchPanel.Use this for pretty-printing Scannables.
- Parameters:
scannable-- Returns:
- string pretty representation of this scannable's position
- Throws:
DeviceException
-
getFormattedCurrentPosition
Returns the current position of the Scannable as a string.Use this for pretty-printing Scannables.
- Parameters:
scannable-- Returns:
- string representation of this Scannable
- Throws:
DeviceException
-
getFormattedCurrentPosition
- Throws:
DeviceException
-
getFormattedCurrentPosition
public static String getFormattedCurrentPosition(ScannableMotionUnits scannable) throws DeviceException - Throws:
DeviceException
-
getFormattedCurrentPosition
public static String getFormattedCurrentPosition(Scannable scannable, String[] unitStringArray, Double[] offsetArray) throws DeviceException Returns the current position of the Scannable as a string including units.Use this for pretty-printing Scannables.
- Parameters:
scannable-unitStringArray- may be null otherwise must match length of input and extra fields- Returns:
- string representation of this Scannable
- Throws:
DeviceException
-
getFormattedPosition
public static String getFormattedPosition(Object position, Scannable scannable, String[] unitStringArray, Double[] offsetArray) throws DeviceException Returns the current position of the Scannable as a string including units.Use this for pretty-printing Scannables.
- Parameters:
position-scannable-unitStringArray- may be null otherwise must match length of input and extra fieldsoffsetArray-- Returns:
- string representation of this Scannable
- Throws:
DeviceException
-
getNumDecimalsArray
Returns the number of decimal places for each field of the scannable, as an array- Parameters:
scannable- the scannable- Returns:
- number of decimal places for each field
-
getNumDecimals
Returns the number of decimals specified in the given output format- Parameters:
outputFormat-- Returns:
- number of decimals
-
getFormattedCurrentPositionArray
public static String[] getFormattedCurrentPositionArray(Object positionObject, int numberOfParts, String[] formats) throws DeviceException Breaks currentPositionObj into the required number of parts. For each part if formatString given return String.format(formatString, part) else if String return as as else return toString value- Parameters:
positionObject-numberOfParts-formats-- Returns:
- array of position values taken from the currentPosition object
- Throws:
DeviceException
-
getFormattedCurrentPositionArray
public static String[] getFormattedCurrentPositionArray(Scannable scannable, Object position) throws DeviceException - Throws:
DeviceException
-
getFormattedCurrentPositionArray
Returns the current position of the Scannable as a formatted array of Strings.Use this for pretty-printing Scannables.
- Parameters:
scannable-- Returns:
- formatted array of Strings
- Throws:
DeviceException
-
formatScannableWithChildren
public static String formatScannableWithChildren(Scannable parent, Collection<Scannable> children, boolean includeParentPosition) Formats a scannable which contains child scannables, such as ScannableGroup invalid input: '&' CoupledScannable.- Parameters:
parent- Overall scannablechildren- Collection of child scannablesincludeParentPosition- Controls whether position of parent scannable should be included in output- Returns:
- Name and position of parent and child scannables indented for terminal output.
-
getCurrentPositionArray
Returns the current position of the given Scannable as an array of doubles- Parameters:
scannable-- Returns:
- the position as an array of doubles
- Throws:
DeviceException
-
positionToArray
public static double[] positionToArray(Object currentPositionObj, Scannable scannable) throws DeviceException Returns the current position of the given Scannable as an array of doubles. This will not call the scannable's getPosition() method.- Parameters:
currentPositionObj-scannable-- Returns:
- the position as an array of doubles
- Throws:
DeviceException
-
getCurrentPositionArray_InputsOnly
Returns an array which is the current position, but with the 'extra' fields removed- Parameters:
scannable-- Returns:
- the position as an array of doubles
- Throws:
Exception
-
calculateNextPoint
Given a current position and an incremental move, calculates the target position.This assumes that both objects are of the same type and are one of: number, Java array of numbers, Jython array of numbers
- Parameters:
previousPoint-step-- Returns:
- the target position of the relative move
-
getNumberSteps
public static int getNumberSteps(Scannable theScannable, Object start, Object stop, Object step) throws Exception Assuming the objects can be converted into doubles, this calculates the number of steps for the given Scannables based on the given start, stop and step values.- Parameters:
theScannable- Scannablestart- Objectstop- Objectstep- Object- Returns:
- int
- Throws:
Exception
-
getNumberSteps
-
validate
public static void validate(Scannable theScannable) throws ScannableUtils.ScannableValidationException Performs some basic validation of the given Scannable to check for internal consistency. This should be called at the end of every Scannable's constructor.If the validation fails then an exception with an explanatory message is thrown.
- Parameters:
theScannable-- Throws:
ScannableUtils.ScannableValidationException
-
objectToDouble
Convert an object to a Double- Number
- 🡆 Result of doubleValue()
- String
- 🡆 Try parsing as either double or quantity
- Quantity
- 🡆 Value component - no unit conversions are made
- PyObject
- 🡆 Attempt conversion to number or string and try again
- Object
- 🡆 Call toString and try to parse the result
- null
- 🡆 null
-
If no conversion is possible return null to differentiate the case where
"NaN" or
Double.NaNis passed in.- Parameters:
value- Anything that might be useful as a number- Returns:
- Some kind of double value - null if no conversion is possible
-
objectToArray
Converts an object to an array of Doubles.
If it is an array or list, each value is converted according toobjectToDouble(Object)and returned in an array. Otherwise, attempt to convert the object to a single double and return an array of a single value.- Parameters:
position- Any object representing a double or sequence of doubles- Returns:
- array of Doubles
-
toObjectArray
Converts an object to an array of Objects.
If it is an array, or iterable (including PySequence), it is returned as an array. Otherwise, an array is returned with a single value. UnlikeobjectToArray(Object), this method does not attempt to convert objects to double values, but it does convert Jython objects to their Java equivalents.- Parameters:
object- any object to convert- Returns:
- the object as an array of Java objects
-
convertToJava
- Parameters:
object-- Returns:
- null
- See Also:
-
convertToJava
Converts a Jython PyObject into its Java equivalent if that is possible. This only works on the sorts of objects dealt with in the Jython environment i.e. Strings, integers, floats (doubles) and arrays of these.If this fails or cannot work for any reason then null is returned.
- Parameters:
object-- Returns:
- Java equivalent object
-
getScannableNames
- Parameters:
scannables-- Returns:
- list of Names from the provided list of scannables/detectors
-
getScannableInputFieldNames
- Parameters:
scannables-- Returns:
- list of InputNames from the provided list of scannables
-
getScannableExtraFieldNames
- Parameters:
scannables-- Returns:
- list of extraNames from the provided list of scannables
-
getScannableFieldNames
- Parameters:
scannables-- Returns:
- list of input and extraNames from the provided list of scannables
-
getScannableFieldNames
-
getDetectorFieldNames
- Parameters:
detectors-- Returns:
- list of names (extra names in case of CounterTimer) from the provided list of detectors
-
getDetectorFieldNames
- Parameters:
detector-- Returns:
- list of names for the detector (extra names in case of CounterTimer, otherwise just the detector name)
-
getScannablePosition
Call to get the position with unit as a string. The units, if any, will be added on without a space.- Parameters:
name-- Returns:
- String position
- Throws:
DeviceException
-
isScannableBusy
Returns of the scannable is busy if it can. Otherwise returns false without an exception being thrown.- Parameters:
scannableName-- Returns:
- true if busy
-
getScannablePositionNoException
NOTE: Instead of giving an exception of the EpicsMonitor is not in a valid state, this methods returns the message from the exception.- Parameters:
name-- Returns:
- value or exception message or null.
-
getExtraNamesFormats
Returns an array of strings describing the formatting information for the output names of this scannable. I.e. it strips off the formatting strings for the input names.This is useful for adding detector data formatting information into the ScanDataPoint
- Parameters:
scannable-- Returns:
- String[]
-
prettyPrintScannable
-
prettyPrintScannable
-
prettyPrintScannableGroup
-
getSerializedScannableSnapshot
Serializes and encodes into Base64 a snapshot of a scannable- Parameters:
scn-- Returns:
- Base64 encoded ScannableSnapshot
- Throws:
Exception
-
deserializeScannableSnapshot
Deserializes a Base64 encoded ScannableSnapshot- Parameters:
serialized-- Returns:
- Deserialized snapshot
- Throws:
Exception
-
getScannableUnits
Check to see if scannable has any units to return. If not, return null. Does not work with IScannableGroup because it returns an array of strings where as this only returns a single string UsegetScannableUnitsArray(Scannable...)instead.- Parameters:
scannable-- Returns:
- units
-
getScannableUnitsArray
Return an array of scannable units which map on to the scannable field names.- Parameters:
scannables-- Returns:
- units
- Throws:
DeviceException
-