Search in sources :

Example 6 with IMalcolmModel

use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.

the class ScanRequestFactory method prepareMalcolmAcquisitionEngine.

private void prepareMalcolmAcquisitionEngine(ScanRequest scanRequest, IRunnableDeviceService runnableDeviceService) throws ScanningException {
    final Map<String, IDetectorModel> ret = new HashMap<>();
    scanRequest.setDetectors(ret);
    String id = Optional.ofNullable(getAcquisitionEngine()).map(AcquisitionEngineReader::getId).orElseThrow(() -> new ScanningException("The AcquisitionEngine section does not contain the device id"));
    IRunnableDevice<IDetectorModel> detector = runnableDeviceService.getRunnableDevice(id);
    IDetectorModel imodel = Optional.ofNullable(detector.getModel()).orElseThrow(() -> new ScanningException(String.format("Could not get model for detector %s", detector.getName())));
    if (!(imodel instanceof IMalcolmModel))
        throw new ScanningException(String.format("Detector model is not an instance of of type %s", IMalcolmModel.class));
    final IMalcolmModel model = IMalcolmModel.class.cast(imodel);
    setDetectorsExposures(model);
    ret.put(detector.getName(), model);
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) HashMap(java.util.HashMap) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel)

Example 7 with IMalcolmModel

use of org.eclipse.scanning.api.device.models.IMalcolmModel 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)

Example 8 with IMalcolmModel

use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.

the class ProcessingSelectionWizardPage method getDetectorDatasetNameForMalcolm.

/**
 * Get the name of the dataset to use for the malcolm device with the given name. This is the
 * first dataset of type 'primary' in the {@link MalcolmTable} of the {@link MalcolmConstants#ATTRIBUTE_NAME_DATASETS}
 * attribute.
 * @param malcolmModel
 * @return
 */
private Optional<String> getDetectorDatasetNameForMalcolm(IMalcolmModel malcolmModel) {
    if (malcolmDetectorDatasetNames != null && malcolmDetectorDatasetNames.containsKey(malcolmModel.getName())) {
        return Optional.of(malcolmDetectorDatasetNames.get(malcolmModel.getName()));
    }
    Optional<String> datasetName = Optional.empty();
    try {
        final IRunnableDevice<IMalcolmModel> malcolmDevice = getRunnableDeviceService().getRunnableDevice(malcolmModel.getName());
        if (malcolmDevice.getDeviceState() != DeviceState.READY) {
            throw new ScanningException("The malcolm device is not ready. A scan may be running.");
        }
        try {
            // configure the malcolm device, puts it in 'Armed' state
            malcolmDevice.configure(malcolmModel);
            if (malcolmDevice instanceof IMalcolmDevice) {
                final MalcolmTable datasetsTable = ((IMalcolmDevice) malcolmDevice).getDatasets();
                if (datasetsTable != null) {
                    datasetName = getPrimaryDatasetNameForMalcolm(datasetsTable);
                }
            }
            if (datasetName.isPresent()) {
                // if we found the dataset name, cache it
                logger.debug("Got ''{}'' as dataset for processing for malcolm device ''{}''", datasetName.get(), malcolmModel.getName());
                if (malcolmDetectorDatasetNames == null) {
                    malcolmDetectorDatasetNames = new HashMap<>(4);
                }
                malcolmDetectorDatasetNames.put(malcolmModel.getName(), datasetName.get());
            } else {
                logger.error("Could not get primary dataset for malcolm device ''{}''. The dataset for the malcolm device may not be set correctly.", malcolmModel.getName());
            }
        } finally {
            // Reset the malcolm device back to the 'Ready' state
            malcolmDevice.reset();
        }
    } catch (Exception e) {
        logger.error("Could not get primary dataset for malcolm device: " + malcolmModel.getName(), e);
    }
    return datasetName;
}
Also used : MalcolmTable(org.eclipse.scanning.api.malcolm.MalcolmTable) ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) IMalcolmDevice(org.eclipse.scanning.api.malcolm.IMalcolmDevice) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) EventException(org.eclipse.scanning.api.event.EventException)

Example 9 with IMalcolmModel

use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.

the class ProcessingSelectionWizardPage method finishPage.

@Override
public void finishPage() {
    if (ProcessingMode.OTHER.equals(mode)) {
        String path = existingConfigText.getText();
        configWrapper.setAppName(appText.getText());
        configWrapper.setName(new File(path).getName());
        configWrapper.setPathToConfig(path);
        return;
    }
    final IDetectorModel detectorModel = getSelectedDetector().getModel();
    final Optional<String> malcolmDetectorDatasetName = detectorModel instanceof IMalcolmModel ? getDetectorDatasetNameForMalcolm((IMalcolmModel) detectorModel) : Optional.empty();
    configureProcessingModel(detectorModel, malcolmDetectorDatasetName);
    if (!ProcessingMode.NEW_DAWN.equals(selectedMode())) {
        return;
    }
    // Clone the detector model - we don't want to change the one in the mapping bean
    IDetectorModel detectorModelCopy = null;
    try {
        detectorModelCopy = (IDetectorModel) BeanUtils.cloneBean(detectorModel);
    } catch (Exception e) {
        logger.error("Could not make a copy of the detector model: " + detectorModel.getName(), e);
        return;
    }
    // setup the acquire page with the detector model for the appropriate detector and
    // the name of the detector group (may be different if the detector is a malcolm detector).
    AcquireDataWizardPage acquirePage = (AcquireDataWizardPage) getNextPage();
    acquirePage.setAcquireDetectorModel(detectorModelCopy);
    acquirePage.setDetectorDataGroupName(malcolmDetectorDatasetName.orElse(detectorModel.getName()));
    // set template file on wizard, so that other pages can be created appropriately
    final String templateFile = getSelectedTemplateFile().getPath();
    try {
        ((IOperationModelWizard) getWizard()).setTemplateFile(templateFile);
    } catch (Exception e) {
        final String exceptionMessage = "Error setting template file on wizard. Could not create operations pages.";
        final String userMessage = "Could not open template file, please contact beamline representative";
        logger.error(exceptionMessage, e);
        final MessageBox messageBox = new MessageBox(getShell(), SWT.ERROR);
        messageBox.setMessage(userMessage);
        messageBox.open();
        throw new RuntimeException(exceptionMessage, e);
    }
}
Also used : IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IOperationModelWizard(org.dawnsci.processing.ui.api.IOperationModelWizard) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) File(java.io.File) URISyntaxException(java.net.URISyntaxException) ScanningException(org.eclipse.scanning.api.scan.ScanningException) EventException(org.eclipse.scanning.api.event.EventException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 10 with IMalcolmModel

use of org.eclipse.scanning.api.device.models.IMalcolmModel in project gda-core by openGDA.

the class TimeSeriesScanView method createMalcolmModelEditor.

private MalcolmModelEditor createMalcolmModelEditor(Composite parent, String malcolmDeviceName) {
    try {
        final IRunnableDevice<?> malcolmDevice = getRunnableDeviceService().getRunnableDevice(malcolmDeviceName);
        final IMalcolmModel malcolmModel = (IMalcolmModel) malcolmDevice.getModel();
        final MalcolmModelEditor editor = new MalcolmModelEditor(getRunnableDeviceService(), malcolmModel);
        editor.createEditorPart(parent);
        return editor;
    } catch (ScanningException e) {
        logger.error("Could not get malcolm device: ", malcolmDeviceName, e);
        return null;
    }
}
Also used : ScanningException(org.eclipse.scanning.api.scan.ScanningException) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) MalcolmModelEditor(org.eclipse.scanning.device.ui.device.MalcolmModelEditor)

Aggregations

IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)10 ScanningException (org.eclipse.scanning.api.scan.ScanningException)6 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)4 URISyntaxException (java.net.URISyntaxException)3 EventException (org.eclipse.scanning.api.event.EventException)3 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)3 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)2 File (java.io.File)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 IOperationModelWizard (org.dawnsci.processing.ui.api.IOperationModelWizard)1 Dialog (org.eclipse.jface.dialogs.Dialog)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 ValidationException (org.eclipse.scanning.api.ValidationException)1