Search in sources :

Example 1 with IMarshallerService

use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.

the class ProcessingSection method configureProcessingModel.

private ConfigWrapper configureProcessingModel() {
    final List<IOperationSetupWizardPage> startPages = new ArrayList<>(2);
    final AcquireDataWizardPage acquirePage = new AcquireDataWizardPage(getEclipseContext());
    DawnConfigBean processingConfig = new DawnConfigBean();
    ConfigWrapper w = new ConfigWrapper();
    final ProcessingSelectionWizardPage selectionPage = new ProcessingSelectionWizardPage(getEclipseContext(), processingConfig, w, getMappingBean().getDetectorParameters());
    startPages.add(selectionPage);
    final Supplier<ProcessingSelectionWizardPage.ProcessingMode> selectedMode;
    selectedMode = selectionPage::selectedMode;
    startPages.add(acquirePage);
    try {
        IOperationModelWizard wizard = getEclipseContext().get(IOperationUIService.class).getWizard(null, startPages, (String) null, null);
        OperationModelWizardDialog dialog = new OperationModelWizardDialog(getShell(), wizard);
        dialog.setTitle("Setup Processing");
        if (dialog.open() == Window.OK) {
            if (ProcessingSelectionWizardPage.ProcessingMode.NEW_DAWN.equals(selectedMode.get())) {
                try {
                    final Path processingFilePath = Paths.get(processingConfig.getProcessingFile());
                    Files.createDirectories(processingFilePath.getParent());
                    wizard.saveOutputFile(processingFilePath.toString());
                } catch (Exception e) {
                    logger.error("Could not save template file!", e);
                }
            }
            if (!ProcessingSelectionWizardPage.ProcessingMode.OTHER.equals(selectedMode.get())) {
                IMarshallerService ms = getEclipseContext().get(IMarshallerService.class);
                String json = ms.marshal(processingConfig, false);
                try (BufferedWriter wr = new BufferedWriter(new FileWriter(w.getPathToConfig()))) {
                    wr.write(json);
                } catch (Exception e) {
                // TODO: dialog!
                }
            }
            return w;
        }
    } catch (Exception e) {
        logger.error("Could not open operation wizard", e);
    }
    return null;
}
Also used : Path(java.nio.file.Path) IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ConfigWrapper(uk.ac.diamond.daq.mapping.api.ConfigWrapper) OperationModelWizardDialog(org.dawnsci.processing.ui.model.OperationModelWizardDialog) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) IOperationSetupWizardPage(org.dawnsci.processing.ui.api.IOperationSetupWizardPage) IOperationModelWizard(org.dawnsci.processing.ui.api.IOperationModelWizard) IOperationUIService(org.dawnsci.processing.ui.api.IOperationUIService)

Example 2 with IMarshallerService

use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.

the class MappingXanesTemplateHandler method loadTemplate.

private void loadTemplate(String templatePath) {
    final IMappingExperimentBean template;
    try {
        final byte[] bytes = Files.readAllBytes(Paths.get(templatePath));
        final String json = new String(bytes, "UTF-8");
        final IMarshallerService marshaller = getService(IMarshallerService.class);
        template = marshaller.unmarshal(json, MappingExperimentBean.class);
    } catch (Exception e) {
        logger.error("Error loading template", e);
        MessageDialog.openError(Display.getCurrent().getActiveShell(), "Mapping template", "Could not load map template. Map parameters have not been changed.");
        return;
    }
    final IMappingExperimentBeanProvider beanProvider = getService(IMappingExperimentBeanProvider.class);
    final IMappingExperimentBean currentBean = beanProvider.getMappingExperimentBean();
    template.getScanDefinition().setMappingScanRegion(currentBean.getScanDefinition().getMappingScanRegion());
    beanProvider.setMappingExperimentBean(template);
    final MappingExperimentView view = (MappingExperimentView) getService(EPartService.class).findPart(MappingExperimentView.ID).getObject();
    view.updateControls();
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean) MappingExperimentBean(uk.ac.diamond.daq.mapping.impl.MappingExperimentBean) MappingExperimentView(uk.ac.diamond.daq.mapping.ui.experiment.MappingExperimentView) EPartService(org.eclipse.e4.ui.workbench.modeling.EPartService) IMappingExperimentBeanProvider(uk.ac.diamond.daq.mapping.api.IMappingExperimentBeanProvider) ExecutionException(org.eclipse.core.commands.ExecutionException) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 3 with IMarshallerService

use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.

the class TomographyConfigurationDialog method saveCalibrationToFile.

/**
 * Save calibration data to a file, so that the Submit button can read it.
 */
private void saveCalibrationToFile() {
    CALIBRATION_DIRECTORY_PATH.toFile().mkdirs();
    final File outputFile = CALIBRATION_FILE_PATH.toFile();
    try (BufferedWriter outputWriter = Files.newBufferedWriter(CALIBRATION_FILE_PATH, CREATE)) {
        final IMarshallerService marshallerService = getService(IMarshallerService.class);
        final TomographyCalibrationData tomoCalibration = new TomographyCalibrationData(xCalibration, zCalibration);
        outputWriter.write(marshallerService.marshal(tomoCalibration));
        logger.debug("Calibration data written to {}", CALIBRATION_FILE_PATH);
        unsavedCalibration = false;
        setButtonStates();
    } catch (Exception e) {
        final String message = String.format(getClientMessage(TOMO_CALIBRATE_SAVE_FILE_ERROR), outputFile.getName());
        handleException(message, e);
    }
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) TomographyCalibrationData(uk.ac.diamond.daq.mapping.api.TomographyCalibrationData) File(java.io.File) DeviceException(gda.device.DeviceException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 4 with IMarshallerService

use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.

the class TomographySubmitScanSection method submitScan.

@Override
protected void submitScan() {
    // Read parameters from file
    try (BufferedReader reader = Files.newBufferedReader(CALIBRATION_FILE_PATH)) {
        final IScriptService scriptService = getService(IScriptService.class);
        final IMarshallerService marshallerService = getService(IMarshallerService.class);
        final IMappingExperimentBean mappingBean = getMappingBean();
        final TomographyCalibrationData calibrationParams = marshallerService.unmarshal(reader.readLine(), TomographyCalibrationData.class);
        final ScanRequest scanRequest = getScanRequest(mappingBean);
        final TomographyParams tomoParams = new TomographyParams();
        tomoParams.setTomographyCalibration(calibrationParams);
        tomoParams.setProcessingFiles(getProcessingFilesAs(mappingBean));
        tomoParams.setVisitId(InterfaceProvider.getBatonStateProvider().getBatonHolder().getVisitID());
        populateScriptService(scriptService, marshallerService, scanRequest, tomoParams);
    } catch (Exception e) {
        handleException(getClientMessage(TOMO_CALIBRATE_SUBMIT_ERROR), e);
        return;
    }
    Async.execute(() -> runScript(tomoScanScript, "tomography scanning script"));
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) TomographyCalibrationData(uk.ac.diamond.daq.mapping.api.TomographyCalibrationData) BufferedReader(java.io.BufferedReader) IScriptService(org.eclipse.scanning.api.script.IScriptService) TomographyParams(uk.ac.diamond.daq.mapping.api.TomographyParams) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 5 with IMarshallerService

use of org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService in project gda-core by openGDA.

the class XanesEdgeParametersSection method saveState.

@Override
public void saveState(Map<String, String> persistedState) {
    try {
        logger.debug("Saving XANES parameters");
        final IMarshallerService marshaller = getService(IMarshallerService.class);
        persistedState.put(XANES_SCAN_KEY, marshaller.marshal(scanParameters));
    } catch (Exception e) {
        logger.error("Error saving XANES scan parameters", e);
    }
}
Also used : IMarshallerService(org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService) NexusException(org.eclipse.dawnsci.nexus.NexusException) IOException(java.io.IOException)

Aggregations

IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)28 IOException (java.io.IOException)10 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)6 IScriptService (org.eclipse.scanning.api.script.IScriptService)6 XMLMarshallerService (org.eclipse.dawnsci.remotedataset.XMLMarshallerService)4 ScanningException (org.eclipse.scanning.api.scan.ScanningException)4 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)4 BufferedReader (java.io.BufferedReader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 PersistState (org.eclipse.e4.ui.di.PersistState)3 EventException (org.eclipse.scanning.api.event.EventException)3 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)3 DeviceException (gda.device.DeviceException)2 JythonServerFacade (gda.jython.JythonServerFacade)2 BufferedWriter (java.io.BufferedWriter)2 InputStreamReader (java.io.InputStreamReader)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2