Class AbstractNexusDeviceAdapter<N extends NXobject>

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

public abstract class AbstractNexusDeviceAdapter<N extends NXobject> extends Object implements IWritableNexusDevice<N>, IGDAScannableNexusDevice<N>
Abstract superclass of classes that adapt Scannables (including Detectors) to INexusDevice, so that they can be used by the NexusScanFileService.
  • Field Details

    • DOUBLE_DATA_BYTE_SIZE

      protected static final int DOUBLE_DATA_BYTE_SIZE
      See Also:
  • Constructor Details

    • AbstractNexusDeviceAdapter

      protected AbstractNexusDeviceAdapter(Scannable device)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: INexusDevice
      Returns the name of this nexus device.
      Specified by:
      getName in interface INexusDevice<N extends NXobject>
      Returns:
      name of nexus device
    • getDevice

      protected Scannable getDevice()
    • registerAttributes

      protected void registerAttributes(NXobject nexusObject) throws NexusException
      Add the attributes for the given attribute container into the given nexus object. TODO: consider removing this and providing an easier mechanism. see DAQ-3186.
      Throws:
      NexusException - if the attributes could not be added for any reason
    • addAttributesToDataNode

      protected void addAttributesToDataNode(String inputFieldName, int numDecimals, String unitsStr, DataNode dataNode)
    • 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>
      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
    • createNexusObject

      protected abstract N createNexusObject(NexusScanInfo info) throws NexusException
      Throws:
      NexusException
    • createNexusProvider

      protected NexusObjectProvider<N> createNexusProvider(N nexusObject, NexusScanInfo info) throws NexusException
      Throws:
      NexusException
    • configureNexusWrapper

      protected void configureNexusWrapper(NexusObjectWrapper<N> nexusWrapper, NexusScanInfo info) throws NexusException
      Configure the nexus wrapper, an object that contains the nexus object and contains additional information describing how the nexus object should be added to the nexus tree - in particular to NXdata groups.
      Parameters:
      nexusWrapper -
      info -
      Throws:
      NexusException
    • getPrimaryDataFieldName

      protected abstract String getPrimaryDataFieldName()
    • getFillValue

      protected static Object getFillValue(Class<?> clazz)
    • 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>
      Throws:
      NexusException - if an error occurred for any reason