Search in sources :

Example 31 with ScanningException

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

the class ScanRequestFactory method createScanRequest.

public ScanRequest createScanRequest(IRunnableDeviceService runnableDeviceService) throws ScanningException {
    // Populate the {@link ScanRequest} with the assembled objects
    var scanRequest = new ScanRequest();
    scanRequest.setTemplateFilePaths(new HashSet<>());
    prepareScanRequestAccordingToScanType(scanRequest);
    Optional.ofNullable(getAcquisition().getAcquisitionLocation()).map(URL::getPath).ifPresent(scanRequest::setFilePath);
    try {
        scanRequest.setCompoundModel(createCompoundModel());
    } catch (GDAException e) {
        throw new ScanningException("Cannot create compound model", e);
    }
    parseAcquisitionEngine(scanRequest, runnableDeviceService);
    addPosition(createStartPosition(), scanRequest::setStartPosition);
    addPosition(createEndPosition(), scanRequest::setEnd);
    scanRequest.setMonitorNamesPerPoint(parseMonitorNamesPerPoint());
    scanRequest.setProcessingRequest(new ProcessingRequest());
    scanRequest.getProcessingRequest().setRequest(new HashMap<>());
    for (ProcessingRequestPair<?> request : getAcquisitionConfiguration().getProcessingRequest()) {
        getProcessingRequestHandlerService().handle(request, scanRequest);
    }
    return scanRequest;
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanningException(org.eclipse.scanning.api.scan.ScanningException) GDAException(uk.ac.gda.common.exception.GDAException) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest)

Example 32 with ScanningException

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

the class FrameCaptureRequestHandler method internalHandling.

private boolean internalHandling(FrameCaptureRequest frameCaptureRequest, ScanRequest scanRequest) {
    List<FrameRequestDocument> detectorDocuments = frameCaptureRequest.getValue();
    String monitorName = serverProperties.getProcessingRequests().getFrameCaptureDecorator();
    if (monitorName == null) {
        logger.error("Frame capture decorator not defined");
        return false;
    }
    try {
        FrameCollectingScannable scn = (FrameCollectingScannable) ScannableDeviceConnectorService.getInstance().getScannable(monitorName);
        scn.setFrameRequestDocument(detectorDocuments.iterator().next());
    } catch (ScanningException e) {
        logger.error("Error retrieving {} '{}'", FrameCollectingScannable.class.getName(), monitorName, e);
        return false;
    }
    List<String> monitors = new ArrayList<>(scanRequest.getMonitorNamesPerScan());
    monitors.add(monitorName);
    scanRequest.setMonitorNamesPerScan(monitors);
    var script = LocalProperties.get(CAMERA_STREAM_SCRIPT_PROPERTY);
    if (script != null) {
        var scriptRequest = new ScriptRequest(script);
        scanRequest.setAfterScript(scriptRequest);
    }
    return true;
}
Also used : ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) ScanningException(org.eclipse.scanning.api.scan.ScanningException) ArrayList(java.util.ArrayList) FrameRequestDocument(uk.ac.gda.api.acquisition.parameters.FrameRequestDocument) FrameCollectingScannable(uk.ac.diamond.daq.scanning.FrameCollectingScannable)

Example 33 with ScanningException

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

the class ScannableNexusWrapperScanTest method createGridScan.

private IRunnableDevice<ScanModel> createGridScan(final IRunnableDevice<? extends IDetectorModel> detector, String outerScannableName, int... size) throws Exception {
    // Create scan points for a grid and make a generator
    final TwoAxisGridPointsModel gridModel = new TwoAxisGridPointsModel();
    gridModel.setxAxisName("salong");
    gridModel.setxAxisPoints(size[size.length - 1]);
    gridModel.setyAxisName("saperp");
    gridModel.setyAxisPoints(size[size.length - 2]);
    gridModel.setBoundingBox(new BoundingBox(0, 0, 3, 3));
    final CompoundModel compoundModel = new CompoundModel();
    // We add the outer scans, if any
    if (outerScannableName != null) {
        for (int dim = 0; dim < size.length - 2; dim++) {
            if (size[dim] > 1) {
                // TODO outer scannable name(s)? could use cryostat temperature as an outer scan
                compoundModel.addModel(new AxialStepModel(outerScannableName, 10000, 20000, 9999.99d / (size[dim] - 1)));
            } else {
                // Will generate one value at 10
                compoundModel.addModel(new AxialStepModel(outerScannableName + (dim + 1), 10, 20, 30));
            }
        }
    }
    compoundModel.addModel(gridModel);
    final IPointGenerator<CompoundModel> pointGen = pointGenService.createCompoundGenerator(compoundModel);
    // Create the model for a scan
    final ScanModel scanModel = new ScanModel();
    scanModel.setPointGenerator(pointGen);
    scanModel.setScanPathModel(compoundModel);
    scanModel.setDetector(detector);
    final IScannable<?> attributeScannable = scannableDeviceService.getScannable("attributes");
    final IScannable<?> beamSizeScannable = scannableDeviceService.getScannable("beam");
    scanModel.setMonitorsPerScan(attributeScannable, beamSizeScannable);
    // Create a file to scan into
    final File output = File.createTempFile("test_legacy_nexus", ".nxs");
    output.deleteOnExit();
    scanModel.setFilePath(output.getAbsolutePath());
    System.out.println("File writing to " + scanModel.getFilePath());
    // Create a scan and run it without publishing events
    final IRunnableDevice<ScanModel> scanner = scanService.createScanDevice(scanModel);
    final IPointGenerator<?> fgen = pointGen;
    ((IRunnableEventDevice<ScanModel>) scanner).addRunListener(new IRunListener() {

        @Override
        public void runWillPerform(RunEvent evt) throws ScanningException {
            System.out.println("Running acquisition scan of size " + fgen.size());
        }
    });
    return scanner;
}
Also used : ScanModel(org.eclipse.scanning.api.scan.models.ScanModel) IRunListener(org.eclipse.scanning.api.scan.event.IRunListener) TwoAxisGridPointsModel(org.eclipse.scanning.api.points.models.TwoAxisGridPointsModel) IRunnableEventDevice(org.eclipse.scanning.api.device.IRunnableEventDevice) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) ScanningException(org.eclipse.scanning.api.scan.ScanningException) BoundingBox(org.eclipse.scanning.api.points.models.BoundingBox) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) NexusFile(org.eclipse.dawnsci.nexus.NexusFile) File(java.io.File) TreeFile(org.eclipse.dawnsci.analysis.api.tree.TreeFile) RunEvent(org.eclipse.scanning.api.scan.event.RunEvent)

Example 34 with ScanningException

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

the class DetectorsSection method updateMappingStage.

/**
 * Update the mapping stage scannable names based on the given detector.
 * This method will only make any changes if the given detector is a malcolm device,
 * and the value of the {@code axesToMove} attribute of that malcolm device is
 * a {@link StringArrayAttribute} with a length of 2 or greater.
 * In this case the fast and slow axes will be changed to the
 * first and second elements of that array, and if the array is of length 3 or greater,
 * the associated axis is set to the third element.
 *
 * @param wrapper detector model wrapper of the selected detector
 */
private void updateMappingStage(IScanModelWrapper<IDetectorModel> wrapper) {
    final String deviceName = wrapper.getModel().getName();
    try {
        // get the axesToMove from the malcolm device
        final MappingStageInfo stageInfo = getEclipseContext().get(MappingStageInfo.class);
        final List<String> malcolmAxes = getMalcolmDevice(deviceName).getAvailableAxes();
        // only update the mapping stage if the malcolm device is configured to move at least two axes.
        if (malcolmAxes.size() < 2)
            return;
        // if the current fast and slow axes are contained in the malcolm axes, then the mapping stage
        // is already set correctly for the malcolm device, no update is required
        // note if new (2018) malcolm, malcolmAxes will contain all
        boolean updatedFastAndSlowAxes = false;
        if (!malcolmAxes.contains(stageInfo.getPlotXAxisName()) || !malcolmAxes.contains(stageInfo.getPlotYAxisName())) {
            // we assume the order is fast-axis, slow-axes. Malcolm devices must be configured to have this order
            stageInfo.setPlotXAxisName(malcolmAxes.get(0));
            stageInfo.setPlotYAxisName(malcolmAxes.get(1));
            updatedFastAndSlowAxes = true;
        }
        boolean updatedAssociatedAxes = false;
        if (malcolmAxes.size() > 2 && !malcolmAxes.contains(stageInfo.getAssociatedAxis())) {
            // for a 3+ dimension malcolm device, we can set the z-axis as well
            stageInfo.setAssociatedAxis(malcolmAxes.get(2));
            updatedAssociatedAxes = true;
        }
        if (updatedFastAndSlowAxes || updatedAssociatedAxes) {
            // show a dialog to inform the user of the change (unless overridden in the preferences)
            final IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
            if (prefs.getBoolean(PREFERENCE_KEY_SHOW_MAPPING_STAGE_CHANGED_DIALOG, true)) {
                String message = "";
                if (updatedFastAndSlowAxes) {
                    message += MessageFormat.format("The active fast scan axis for mapping scans has been updated to ''{0}'' and the active slow scan axis to ''{1}''.", stageInfo.getPlotXAxisName(), stageInfo.getPlotYAxisName());
                }
                if (updatedAssociatedAxes) {
                    message += MessageFormat.format(" The associated axis has been updated to ''{0}''.", stageInfo.getAssociatedAxis());
                } else {
                    message += MessageFormat.format(" The associated axis is ''{0}'' and has not been changed.", stageInfo.getAssociatedAxis());
                }
                final MessageDialogWithToggle dialog = MessageDialogWithToggle.openInformation(getShell(), "Mapping Stage", message, "Don't show this dialog again", false, null, null);
                prefs.putBoolean(PREFERENCE_KEY_SHOW_MAPPING_STAGE_CHANGED_DIALOG, !dialog.getToggleState());
            }
            // Region and path composites need updating to reflect this change.
            getMappingView().redrawRegionAndPathComposites();
        }
    } catch (ScanningException e) {
        logger.error("Could not get axes of malcolm device: {}", deviceName, e);
    }
}
Also used : IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) ScanningException(org.eclipse.scanning.api.scan.ScanningException) MappingStageInfo(uk.ac.diamond.daq.mapping.impl.MappingStageInfo) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle)

Example 35 with ScanningException

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

the class DetectorsSection method editDetectorParameters.

private void editDetectorParameters(final IScanModelWrapper<IDetectorModel> detectorParameters) {
    try {
        if (detectorParameters.getModel() instanceof IMalcolmModel && getRunnableDeviceService().getRunnableDevice(detectorParameters.getModel().getName()).getDeviceState() == DeviceState.OFFLINE) {
            MessageDialog.openError(getShell(), "Malcolm Device " + detectorParameters.getModel().getName(), "Cannot edit malcolm device " + detectorParameters.getModel().getName() + " as it is offline.");
            return;
        }
    } catch (ScanningException e) {
        logger.error("Cannot get malcolm device", e);
    }
    final Dialog editModelDialog = new EditDetectorModelDialog(getShell(), getRunnableDeviceService(), detectorParameters.getModel(), detectorParameters.getName());
    editModelDialog.create();
    if (editModelDialog.open() == Window.OK) {
        dataBindingContext.updateTargets();
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) EditDetectorModelDialog(org.eclipse.scanning.device.ui.device.EditDetectorModelDialog) Dialog(org.eclipse.jface.dialogs.Dialog) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) EditDetectorModelDialog(org.eclipse.scanning.device.ui.device.EditDetectorModelDialog)

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