Package jisa.experiment
Class Measurement
- java.lang.Object
-
- jisa.experiment.Measurement
-
public abstract class Measurement extends java.lang.Object
Abstract 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 class
Measurement.BooleanParameter
class
Measurement.ChoiceParameter
class
Measurement.CustomParameter<T>
class
Measurement.DecimalParameter
class
Measurement.DoubleParameter
static interface
Measurement.Getter<T>
class
Measurement.IntegerParameter
class
Measurement.Parameter<T>
class
Measurement.RangeParameter
static interface
Measurement.Reader<T>
static interface
Measurement.Setter<T>
class
Measurement.StringParameter
class
Measurement.TimeParameter
static interface
Measurement.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 void
checkPoint()
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.String
getLabel()
Returns a user-given label for this measurement instance.abstract java.lang.String
getName()
Returns the name of this measurement.java.util.List<Measurement.Parameter<?>>
getParameters()
ResultTable
getResults()
Returns the currently used ResultTable for results storageboolean
isRunning()
Returns whether this measurement is currently running.ResultTable
newResults()
Generates a new ResultTable for storing results, in memory.ResultTable
newResults(java.lang.String path)
Generates a new ResultTable for storing results, directly to a file.protected abstract void
onError()
This method is always called when a measurement ends in error (but not interrupt).protected abstract void
onFinish()
This method is always called whenever a measurement has ended, regardless of if it was successful, ended in error or was interrupted.protected abstract void
onInterrupt()
This method is always called whenever the measurement is ended prematurely by stop() (or other interrupt).protected abstract void
run(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.void
setLabel(java.lang.String value)
Sets the user-given label for this measurement instance.void
sleep(int mSec)
Makes the current thread wait for the given number of milliseconds with proper checks for any stop() calls.void
start()
Starts the measurement.void
stop()
Stops the current execution of this measurement (if it is running at all).boolean
wasStopped()
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.Exception
This 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.Exception
This 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.Exception
This 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.Exception
Starts 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.InterruptedException
Makes 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.InterruptedException
Checks 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()
-
-