Class AbstractScannableNexusDevice<N extends NXobject>

java.lang.Object
gda.data.scan.nexus.device.AbstractNexusDeviceAdapter<N>
gda.data.scan.nexus.device.AbstractScannableNexusDevice<N>
Type Parameters:
N -
All Implemented Interfaces:
IGDAScannableNexusDevice<N>, INexusDevice<N>, IWritableNexusDevice<N>
Direct Known Subclasses:
ConfiguredScannableNexusDevice, DefaultScannableNexusDevice

public abstract class AbstractScannableNexusDevice<N extends NXobject> extends AbstractNexusDeviceAdapter<N>
An instance of this type adapts a Scannable to INexusDevice. There are two concrete subclasses:
  • Field Details

  • Constructor Details

    • AbstractScannableNexusDevice

      protected AbstractScannableNexusDevice(Scannable scannable)
  • Method Details

    • getScannable

      protected Scannable getScannable()
    • getPrimaryDataFieldIndex

      protected int getPrimaryDataFieldIndex()
    • getPrimaryDataFieldName

      protected String getPrimaryDataFieldName()
      Specified by:
      getPrimaryDataFieldName in class AbstractNexusDeviceAdapter<N extends NXobject>
    • getNexusCategory

      protected NexusBaseClass getNexusCategory() throws NexusException
      Throws:
      NexusException
    • getFieldDataNode

      public DataNode getFieldDataNode(String fieldName)
      Description copied from interface: IGDAScannableNexusDevice
      Returns the DataNode for the given field name, or null if there is not such field.
      Parameters:
      fieldName -
      Returns:
      the data node for the given field name
    • getNexusProvider

      public NexusObjectProvider<N> getNexusProvider(NexusScanInfo info) throws NexusException
      Description copied from interface: INexusDevice
      Returns the object provider required for writing correct NeXus files.

      In this method you should prepare the LazyDatasets the device will fill during the scan. You can also write out static device metadata, which will not change during the scan.

      Use the methods on NexusNodeFactory to create a NeXus object which matches the device e.g. a NXdetector. final NXdetector detector = NexusNodeFactory.createNXdetector();

      On the detector object you can create LazyDatasets and keep references which you can later use during the scan to write data. e.g. imageData = detector.initializeLazyDataset(NXdetector.NX_DATA, info.getRank() + 2, Double.class); You should also set chunking on the LazyDatasets you create e.g. imageData.setChunking(info.createChunk(detectorXSize, detectorYSize));.

      In this method you can also write static metadata such as the detector exposure e.g. detector.setField("exposure_time", model.getExposure());. Or static datasets such as the image axis data detector.setDataset("image_x_axis", DatasetFactory.createLinearSpace(DoubleDataset.class, minX, maxX, xPoints)); For fields that are defined in the NXDL base class definition for the returned nexus object, a setXXX or setXXXScalar method may be used as appropriate, e.g. detector.setLocalName(DatasetFactory.createFromObject("my detector")); or detector.setLocalNameScalar("my detector");

      If this device is a 'metadata scannable', then the device should write its data at this point directly into the returned nexus object. This can be done with the NXobject.setField(String, Object) method, or the setXXXScalar methods for fields defined in the appropriate NXDL base class definition.

      The default implementation of this method throws UnsupportedOperationException. One of either this method or INexusDevice.getNexusProviders(NexusScanInfo) must be overridden to create and return the nexus object(s) for this INexusDevice.

      Specified by:
      getNexusProvider in interface INexusDevice<N extends NXobject>
      Overrides:
      getNexusProvider in class AbstractNexusDeviceAdapter<N extends NXobject>
      Parameters:
      info - information about the scan which can be useful when creating datasets e.g. info.getRank()
      Returns:
      The NXobject created using the nodeFactory to represent this device
      Throws:
      NexusException - if the nexus object could not be created for any reason
    • addFields

      protected void addFields(String[] fieldNames, NXobject nexusObject)
    • createNexusObject

      protected N createNexusObject(NexusScanInfo info) throws NexusException
      Specified by:
      createNexusObject in class AbstractNexusDeviceAdapter<N extends NXobject>
      Throws:
      NexusException
    • setScanObject

      public void setScanObject(IScanObject scanObject)
      Set the IScanObject describing the movement of this scannable in the scan.
      Parameters:
      scanObject -
    • getNexusBaseClass

      protected NexusBaseClass getNexusBaseClass() throws NexusException
      Throws:
      NexusException
    • createDataNodes

      protected void createDataNodes(NexusScanInfo scanInfo) throws NexusException
      Creates the data fields for the nexus object. These are the DataNodes - and the datasets that they contain - for each of the fields returned by Scannable.getInputNames() and Scannable.getExtraNames(). If the wrapped scannable is a metadata scannable these datasets will be IDatasets containing a single scalar value from the position returned by Scannable.getPosition() (turned into an array by {#getPositionArray()}, otherwise they will be ILazyWriteableDatasets, which will be written into during each call to writePosition(Object, IPosition)} Create the DataNodes for the Scannable.
      Parameters:
      scanInfo -
      Throws:
      NexusException
    • getFieldUnits

      protected String getFieldUnits(int fieldIndex)
    • createLazyWritableDataset

      protected org.eclipse.january.dataset.ILazyWriteableDataset createLazyWritableDataset(String fieldName, Class<?> clazz, int rank, int[] chunking)
    • writeControllerRecordName

      protected void writeControllerRecordName(NXpositioner positioner)
    • writePosition

      public Object writePosition(Object demandPosition, IPosition scanPosition) throws Exception
      Throws:
      Exception
    • writePosition

      public void writePosition(Object position, org.eclipse.january.dataset.SliceND scanSlice) throws NexusException
      Write the given position at the given slice.
      Parameters:
      position - the position to write
      scanSlice - the scan slice, i.e. where to write in the datasets
      Throws:
      NexusException - if the position cannot be written for any reason
    • getFieldNames

      public String[] getFieldNames()
      Description copied from interface: IGDAScannableNexusDevice
      The names of the fields for this scannable. The resulting array may be empty, never null.
      Returns:
      field names
    • isNexusObjectCreated

      public boolean isNexusObjectCreated()
    • scanEnd

      public void scanEnd() throws NexusException
      Description copied from interface: IWritableNexusDevice
      Called at the end of a scan. The implementation should use this to clear up any state, such as closing any files and releasing any cached datasets so that this device can be used in subsequent scans.
      Specified by:
      scanEnd in interface IWritableNexusDevice<N extends NXobject>
      Overrides:
      scanEnd in class AbstractNexusDeviceAdapter<N extends NXobject>
      Throws:
      NexusException - if an error occurred for any reason
    • toString

      public String toString()
      Overrides:
      toString in class Object