Package jisa.experiment
Class Measurement
- java.lang.Object
-
- jisa.experiment.Measurement
-
public abstract class Measurement extends java.lang.ObjectAbstract class for implementing measurement routines. Allows for procedures that can be easily and safely interrupted.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classMeasurement.BooleanParameterclassMeasurement.ChoiceParameterclassMeasurement.CustomParameter<T>classMeasurement.DecimalParameterclassMeasurement.DoubleParameterstatic interfaceMeasurement.Getter<T>classMeasurement.IntegerParameterclassMeasurement.Parameter<T>classMeasurement.RangeParameterstatic interfaceMeasurement.Reader<T>static interfaceMeasurement.Setter<T>classMeasurement.StringParameterclassMeasurement.TimeParameterstatic interfaceMeasurement.Writer<T>
-
Constructor Summary
Constructors Constructor Description Measurement()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Instrument>
Configuration<T>addInstrument(java.lang.String name, java.lang.Class<T> type)<T extends Instrument>
Configuration<T>addInstrument(Configuration<T> configuration)protected voidcheckPoint()Checks if the stop() method has been called.java.util.List<Action>getActions()abstract Column[]getColumns()This method should return an array of columns to be used when generating a new ResultTable for results storage.java.util.List<Configuration<? extends Instrument>>getInstruments()java.lang.StringgetLabel()Returns a user-given label for this measurement instance.abstract java.lang.StringgetName()Returns the name of this measurement.java.util.List<Measurement.Parameter<?>>getParameters()ResultTablegetResults()Returns the currently used ResultTable for results storagebooleanisRunning()Returns whether this measurement is currently running.ResultTablenewResults()Generates a new ResultTable for storing results, in memory.ResultTablenewResults(java.lang.String path)Generates a new ResultTable for storing results, directly to a file.protected abstract voidonError()This method is always called when a measurement ends in error (but not interrupt).protected abstract voidonFinish()This method is always called whenever a measurement has ended, regardless of if it was successful, ended in error or was interrupted.protected abstract voidonInterrupt()This method is always called whenever the measurement is ended prematurely by stop() (or other interrupt).protected abstract voidrun(ResultTable results)This method should perform the measurement itself and throw and exception if either something is wrong (ie missing instruments) or if something goes wrong during the measurement.voidsetLabel(java.lang.String value)Sets the user-given label for this measurement instance.voidsleep(int mSec)Makes the current thread wait for the given number of milliseconds with proper checks for any stop() calls.voidstart()Starts the measurement.voidstop()Stops the current execution of this measurement (if it is running at all).booleanwasStopped()Returns whether the last execution of this measurement was interrupted by stop().
-
-
-
Method Detail
-
addInstrument
public <T extends Instrument> Configuration<T> addInstrument(Configuration<T> configuration)
-
addInstrument
public <T extends Instrument> Configuration<T> addInstrument(java.lang.String name, java.lang.Class<T> type)
-
getName
public abstract java.lang.String getName()
Returns the name of this measurement.- Returns:
- Name of the measurement
-
getLabel
public java.lang.String getLabel()
Returns a user-given label for this measurement instance.- Returns:
- Label
-
setLabel
public void setLabel(java.lang.String value)
Sets the user-given label for this measurement instance.- Parameters:
value- Label to set
-
run
protected abstract void run(ResultTable results) throws java.lang.Exception
This method should perform the measurement itself and throw and exception if either something is wrong (ie missing instruments) or if something goes wrong during the measurement.- Parameters:
results- The ResultTable to be used for results storage.- Throws:
java.lang.Exception- Upon invalid configuration or measurement error
-
onInterrupt
protected abstract void onInterrupt() throws java.lang.ExceptionThis method is always called whenever the measurement is ended prematurely by stop() (or other interrupt). This method in most cases can be left empty, as it would only really serve a purpose for logging an interrupted measurement.- Throws:
java.lang.Exception- This method can throw exceptions
-
onError
protected abstract void onError() throws java.lang.ExceptionThis method is always called when a measurement ends in error (but not interrupt).- Throws:
java.lang.Exception- This method can throw exceptions
-
onFinish
protected abstract void onFinish() throws java.lang.ExceptionThis method is always called whenever a measurement has ended, regardless of if it was successful, ended in error or was interrupted. This method should therefore contain any clean-up code that should be run at the end of a measurement (for instance turning off any instruments etc).- Throws:
java.lang.Exception- This method can throw exceptions
-
getColumns
public abstract Column[] getColumns()
This method should return an array of columns to be used when generating a new ResultTable for results storage.- Returns:
- Array of columns
-
newResults
public ResultTable newResults()
Generates a new ResultTable for storing results, in memory.- Returns:
- Results storage
-
newResults
public ResultTable newResults(java.lang.String path) throws java.io.IOException
Generates a new ResultTable for storing results, directly to a file.- Parameters:
path- Path to file to write to- Returns:
- Results storage
- Throws:
java.io.IOException- Upon error opening file for writing
-
getResults
public ResultTable getResults()
Returns the currently used ResultTable for results storage- Returns:
- Results storage being used
-
start
public void start() throws java.lang.ExceptionStarts the measurement. Will run until completion if no errors are encountered. Will throw an InterruptedException if the measurement is stopped by calling stop(). Can throw any other type of exception if there is a measurement or instrumentation error.- Throws:
java.lang.Exception- Upon measurement error or interruption.
-
getParameters
public java.util.List<Measurement.Parameter<?>> getParameters()
-
getInstruments
public java.util.List<Configuration<? extends Instrument>> getInstruments()
-
isRunning
public boolean isRunning()
Returns whether this measurement is currently running.- Returns:
- Is it running?
-
wasStopped
public boolean wasStopped()
Returns whether the last execution of this measurement was interrupted by stop().- Returns:
- Was it stopped?
-
stop
public void stop()
Stops the current execution of this measurement (if it is running at all).
-
sleep
public void sleep(int mSec) throws java.lang.InterruptedExceptionMakes the current thread wait for the given number of milliseconds with proper checks for any stop() calls.- Parameters:
mSec- Time to wait for, in milliseconds- Throws:
java.lang.InterruptedException- If stop() is called (or other interrupt occurs) during sleep
-
checkPoint
protected void checkPoint() throws java.lang.InterruptedExceptionChecks if the stop() method has been called. To be called at safe points to stop a measurement during run(). Will throw an InterruptedException if stop() has indeed been called, causing run() to end early as it should.- Throws:
java.lang.InterruptedException- If stop() has indeed been called.
-
getActions
public java.util.List<Action> getActions()
-
-