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!");
}
}
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);
}
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);
}
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);
}
}
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;
}
Aggregations