Search in sources :

Example 6 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class AreaDetectorRunnableDevice method firstFrame.

private void firstFrame() throws ScanningException {
    DataType imageDataType;
    try {
        // Get the data size so we know how big to write in the file and cache it here so we don't
        // need to go to EPICS all the time
        imageDimensions[0] = adDetector.getNdArray().getPluginBase().getArraySize1_RBV();
        imageDimensions[1] = adDetector.getNdArray().getPluginBase().getArraySize0_RBV();
        imageDataType = adDetector.getNdArray().getDataType();
    } catch (Exception e) {
        throw new ScanningException("Getting the image diamensions and data type from the detector failed", e);
    }
    if (imageDimensions[0] == 0 || imageDimensions[1] == 0) {
        // this unlikely to occur as the 1st frame already collected, unless EPICS Array plugin is disabled after IOC restarts.
        throw new ScanningException("Detector array plugin is not initialised! Please initialise it by collecting one dummy frame in EPICS.");
    }
    if (dataDimensions[0] != imageDimensions[0] || dataDimensions[1] != imageDimensions[1]) {
        // This is possible if EPICS roi plugin is used to set region of interest in AD pipeline
        logger.info("Detector diamensions {} are different from Array diamensions {}", dataDimensions, imageDimensions);
    }
    if (imageDataType != dataType) {
        // This is possible if EPICS proc plugin is used to process image data in AD pipeline
        logger.error("Image data type {} is different from Detector source data type {}", dataType, imageDataType);
        throw new ScanningException("Image data type changed in EPICS at 1st Frame. Please re-run your command or data collection again!");
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) DataType(gda.device.detector.areadetector.v17.NDPluginBase.DataType) DeviceException(gda.device.DeviceException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 7 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class AreaDetectorRunnableDeviceProxy method configure.

// AbstractRunnableDevice<AreaDetectorRunnableDeviceModel>
@Override
public void configure(AreaDetectorRunnableDeviceModel model) throws ScanningException {
    logger.trace("configure({}) on {}", model, getName());
    setDeviceState(DeviceState.CONFIGURING);
    // Get the detector by name defined in the model
    detector = Finder.find(model.getName());
    if (detector == null)
        throw new ScanningException("Could not find detector for " + model.getName());
    if (delegate == null)
        throw new ScanningException("No delegate defined for " + model.getName());
    try {
        delegate.configure(model);
    } catch (Exception e) {
        setDeviceState(DeviceState.FAULT);
        throw new ScanningException("Failed configuring detector " + model.getName(), e);
    }
    setDeviceState(DeviceState.ARMED);
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) NexusException(org.eclipse.dawnsci.nexus.NexusException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 8 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class AreaDetectorRunnableDeviceWaitForArray method run.

@Override
public void run(IPosition position) throws ScanningException, InterruptedException {
    try {
        arrayCounter = getArrayCounter();
        logger.trace("run(): arrayCounter = {}", arrayCounter);
    } catch (Exception e) {
        final String message = "Error getting array counter";
        logger.error(message, e);
        throw new ScanningException(message, e);
    }
    super.run(position);
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) ScanningException(org.eclipse.scanning.api.scan.ScanningException)

Example 9 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class AreaDetectorWritingFilesRunnableDevice method configureFileWriting.

private void configureFileWriting() throws ScanningException {
    try {
        // Setup the file writing
        final NDFile ndFile = adDetector.getNdFile();
        // Enable the HDF plugin
        ndFile.getPluginBase().enableCallbacks();
        // TODO this is a bit unsafe just cast it. Maybe ADDetector should hold a NdFileHDF5 itself?
        final NDFileHDF5 ndFileHDF5 = ((MultipleImagesPerHDF5FileWriter) adDetector.getFileWriter()).getNdFileHDF5();
        // Setup the HDF plugin
        // File template just merge path and file name (ignore file numbering in area detector)
        final String filetemplate = "%s%s";
        ndFileHDF5.setFileTemplate(filetemplate);
        // Just use a File object for nice methods
        final File scanFile = new File(information.getFilePath());
        // Set path
        ndFileHDF5.setFilePath(scanFile.getParent());
        // For the name remove the .nxs and add the detector name and file extension
        fileName = scanFile.getName().replace(".nxs", "") + "-" + getName() + DETECTOR_FILE_EXTENSION;
        ndFileHDF5.setFileName(fileName);
        // Store attributes allows stats output to be written to file
        ndFileHDF5.setStoreAttr(1);
        ndFileHDF5.setStoreAttributesByDimension(true);
        // Lazy open must be true so that the file doesn't exist when the link is made
        // Also it allows the first frame received to be used to setup the dimensions
        ndFileHDF5.setLazyOpen(true);
        ndFile.setFileWriteMode(FileWriteMode.STREAM);
        // FIXME This only handles non-alternating scans in a line square or cube.
        // Think the solution is to use the POS plugin to tell AD in advance where the frames are going
        final int[] scanShape = information.getShape();
        switch(information.getRank()) {
            case // 1D Scan
            1:
                // 1D scan so no extra dims
                ndFileHDF5.setNumExtraDims(0);
                ndFileHDF5.setNumCapture(scanShape[0]);
                break;
            case // 2D Scan (like a map)
            2:
                ndFileHDF5.setNumExtraDims(1);
                ndFileHDF5.setExtraDimSizeN(scanShape[1]);
                ndFileHDF5.setExtraDimSizeX(scanShape[0]);
                break;
            case // 3D Scan (like a map at multiple temperatures)
            3:
                ndFileHDF5.setNumExtraDims(2);
                ndFileHDF5.setExtraDimSizeN(scanShape[2]);
                ndFileHDF5.setExtraDimSizeX(scanShape[1]);
                ndFileHDF5.setExtraDimSizeY(scanShape[0]);
                break;
            default:
                throw new DeviceException("Area Detector can't handle file writing when scan is >3D. Scan dimensions = " + scanShape.length);
        }
        // Start capture and check it worked.
        ndFile.startCapture();
        // Give a chance for it to happen!
        Thread.sleep(100);
        if (ndFile.getCapture_RBV() != 1) {
            throw new DeviceException("Capture not ready!");
        }
    } catch (Exception e) {
        final String message = "Error configuring file writing";
        logger.error(message, e);
        throw new ScanningException(message, e);
    }
}
Also used : MultipleImagesPerHDF5FileWriter(gda.device.detector.addetector.filewriter.MultipleImagesPerHDF5FileWriter) ScanningException(org.eclipse.scanning.api.scan.ScanningException) NDFileHDF5(gda.device.detector.areadetector.v17.NDFileHDF5) NDFile(gda.device.detector.areadetector.v17.NDFile) NDFile(gda.device.detector.areadetector.v17.NDFile) File(java.io.File) DeviceException(gda.device.DeviceException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) DeviceException(gda.device.DeviceException)

Example 10 with ScanningException

use of org.eclipse.scanning.api.scan.ScanningException in project gda-core by openGDA.

the class ZebraRunnableDevice method write.

@Override
public boolean write(IPosition position) throws ScanningException {
    try {
        final double data1 = EPICS_CONTROLLER.cagetDouble(div1LastChannel);
        final double data2 = EPICS_CONTROLLER.cagetDouble(div2LastChannel);
        final double data3 = EPICS_CONTROLLER.cagetDouble(div3LastChannel);
        final double data4 = EPICS_CONTROLLER.cagetDouble(div4LastChannel);
        final IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(position);
        // We assume that all datasets have the same shape
        final SliceND slice = new SliceND(dataset1.getShape(), dataset1.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
        final Dataset ds1 = DatasetFactory.createFromObject(data1);
        final Dataset ds2 = DatasetFactory.createFromObject(data2);
        final Dataset ds3 = DatasetFactory.createFromObject(data3);
        final Dataset ds4 = DatasetFactory.createFromObject(data4);
        dataset1.setSlice(null, ds1, slice);
        dataset2.setSlice(null, ds2, slice);
        dataset3.setSlice(null, ds3, slice);
        dataset4.setSlice(null, ds4, slice);
    } catch (TimeoutException | CAException | InterruptedException | DatasetException e) {
        final String message = "Error writing data";
        logger.error(message, e);
        throw new ScanningException(message, e);
    }
    setDeviceState(DeviceState.ARMED);
    return true;
}
Also used : CAException(gov.aps.jca.CAException) ILazyWriteableDataset(org.eclipse.january.dataset.ILazyWriteableDataset) Dataset(org.eclipse.january.dataset.Dataset) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IScanSlice(org.eclipse.scanning.api.scan.rank.IScanSlice) SliceND(org.eclipse.january.dataset.SliceND) TimeoutException(gov.aps.jca.TimeoutException) DatasetException(org.eclipse.january.DatasetException)

Aggregations

ScanningException (org.eclipse.scanning.api.scan.ScanningException)41 DeviceException (gda.device.DeviceException)13 NexusException (org.eclipse.dawnsci.nexus.NexusException)7 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)4 EventException (org.eclipse.scanning.api.event.EventException)4 Scannable (gda.device.Scannable)3 CAException (gov.aps.jca.CAException)3 TimeoutException (gov.aps.jca.TimeoutException)3 DatasetException (org.eclipse.january.DatasetException)3 Dataset (org.eclipse.january.dataset.Dataset)3 ILazyWriteableDataset (org.eclipse.january.dataset.ILazyWriteableDataset)3 SliceND (org.eclipse.january.dataset.SliceND)3 IScanSlice (org.eclipse.scanning.api.scan.rank.IScanSlice)3 Composite (org.eclipse.swt.widgets.Composite)3 File (java.io.File)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AbstractScannable (org.eclipse.scanning.api.AbstractScannable)2