Class 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.
    • Constructor Detail

      • Measurement

        public Measurement()
    • Method Detail

      • addInstrument

        public <T extends InstrumentConfiguration<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.
      • 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()