Search in sources :

Example 1 with ScanBean

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

the class MappingExperimentView method handleOpenRequest.

/**
 * @param openRequest
 */
private void handleOpenRequest(OpenRequest openRequest) {
    if (!isMappingScanBean(openRequest.getStatusBean())) {
        return;
    }
    ScanBean scanBean = (ScanBean) openRequest.getStatusBean();
    String scanName = scanBean.getName();
    logger.info("Open Request, Received an open request for ScanBean with the name: {}", scanName);
    // Confirm whether this scan should be opened as it will overwrite the contents of the view
    Shell shell = (Shell) injectionContext.get(IServiceConstants.ACTIVE_SHELL);
    boolean confirm = MessageDialog.openConfirm(shell, "Open Mapping Scan", MessageFormat.format("Do you want to open the scan ''{0}'' in the Mapping Experiment Setup view?\n" + "This will overwrite the current contents of this view.", scanName));
    if (!confirm) {
        return;
    }
    // If the scan bean contains a valid reference to a stored mapping bean, use this
    if (LocalProperties.isPersistenceServiceAvailable()) {
        final ScanManagementController smController = getEclipseContext().get(ScanManagementController.class);
        final java.util.Optional<IMappingExperimentBean> savedMappingBean = smController.loadScanMappingBean(scanBean.getMappingBeanId());
        if (savedMappingBean.isPresent()) {
            mappingBeanProvider.setMappingExperimentBean(savedMappingBean.get());
            updateControls();
            return;
        } else {
            logger.warn("No saved mapping bean found for scan id {}. Loading view from ScanRequest", scanBean.getMappingBeanId());
        }
    }
    // Otherwise, get the scan request and merge it into the mapping bean
    ScanRequest scanRequest = scanBean.getScanRequest();
    try {
        scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBeanProvider.getMappingExperimentBean());
        updateControls();
    } catch (Exception e) {
        logger.error("Error merging scan request into mapping bean.", e);
        final String errorMessage = MessageFormat.format("Could not open scan {0}. Could not recreate the mapping view from the queued scan. See the error log for more details.", scanName);
        MessageDialog.openError(shell, "Open Results", errorMessage);
    }
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) Shell(org.eclipse.swt.widgets.Shell) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IMappingExperimentBean(uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)

Example 2 with ScanBean

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

the class MScanSubmitterTest method willAllowStaticScanWithDefaultSizeAndNoDetectorParams.

@Test
public void willAllowStaticScanWithDefaultSizeAndNoDetectorParams() throws Exception {
    Object[] arr = { Scanpath.STATIC, detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScanpathElementProcessor(Scanpath.STATIC)), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    verify(submitter).blockingSubmit(beanCaptor.capture());
    verify(eventSubscriber).addListener(any(IScanListener.class));
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(new CompoundModel(new StaticModel()))));
    assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) CompoundModel(org.eclipse.scanning.api.points.models.CompoundModel) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) StaticModel(org.eclipse.scanning.api.points.models.StaticModel) Test(org.junit.Test)

Example 3 with ScanBean

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

the class MScanSubmitterTest method createsCorrectProcessorListForRectangularPointsScanWithAliasedSyntaxWithTuplesOrListsAndSubmits.

@Test
public void createsCorrectProcessorListForRectangularPointsScanWithAliasedSyntaxWithTuplesOrListsAndSubmits() throws Exception {
    // This is equivalent to typing:
    // mscan scannable, anotherScannable, rect ((2,3) [6,8]) line [20,10] detectorRunnableDevice
    PyTuple t1 = PyTuple.fromIterable(new PyList(Arrays.asList(rectangle.getPointX(), rectangle.getPointY())));
    PyList t2 = new PyList(Arrays.asList(rectangleX2, rectangleY2));
    PyTuple t3 = PyTuple.fromIterable(new PyList(Arrays.asList(t1, t2)));
    PyList t4 = new PyList(Arrays.asList(grid.getxAxisPoints(), grid.getyAxisPoints()));
    Object[] arr = { scannable, anotherScannable, RegionShape.RECTANGLE, t3, Scanpath.LINE_POINTS, t4, detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new ScannableElementProcessor(anotherScannable), new RegionShapeElementProcessor(RegionShape.RECTANGLE), new NumberElementProcessor(rectangle.getPointX()), new NumberElementProcessor(rectangle.getPointY()), new NumberElementProcessor(rectangleX2), new NumberElementProcessor(rectangleY2), new ScanpathElementProcessor(Scanpath.GRID_POINTS), new NumberElementProcessor(grid.getxAxisPoints()), new NumberElementProcessor(grid.getyAxisPoints())), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    List<IClauseElementProcessor> processors = captor.getValue();
    assertThat(processors.size(), is(11));
    assertThat(processors.get(0), instanceOf(ScannableElementProcessor.class));
    assertThat(processors.get(0).getElement(), is(scannable));
    assertThat(processors.get(1), instanceOf(ScannableElementProcessor.class));
    assertThat(processors.get(1).getElement(), is(anotherScannable));
    assertThat(processors.get(2), instanceOf(RegionShapeElementProcessor.class));
    assertThat(processors.get(2).getElement(), is(RegionShape.RECTANGLE));
    assertThat(processors.get(3), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(3).getElement(), is(rectangle.getPointX()));
    assertThat(processors.get(4), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(4).getElement(), is(rectangle.getPointY()));
    assertThat(processors.get(5), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(5).getElement(), is(rectangleX2));
    assertThat(processors.get(6), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(6).getElement(), is(rectangleY2));
    assertThat(processors.get(7), instanceOf(ScanpathElementProcessor.class));
    assertThat(processors.get(7).getElement(), is(Scanpath.GRID_POINTS));
    assertThat(processors.get(8), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(8).getElement(), is(grid.getxAxisPoints()));
    assertThat(processors.get(9), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(9).getElement(), is(grid.getyAxisPoints()));
    assertThat(processors.get(10), instanceOf(IRunnableDeviceDetectorElementProcessor.class));
    assertThat(processors.get(10).getElement(), is(detectorRunnableDevice));
    verify(eventSubscriber).addListener(any(IScanListener.class));
    verify(submitter).blockingSubmit(beanCaptor.capture());
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(getBoundedCompoundModel(grid, rectangle))));
    assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) IClauseElementProcessor(gda.mscan.processor.IClauseElementProcessor) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) PyList(org.python.core.PyList) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) PyTuple(org.python.core.PyTuple) RegionShapeElementProcessor(gda.mscan.processor.RegionShapeElementProcessor) Test(org.junit.Test)

Example 4 with ScanBean

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

the class MScanSubmitterTest method createsCorrectProcessorListForReRunFromFileAndSubmits.

@Test
public void createsCorrectProcessorListForReRunFromFileAndSubmits() throws Exception {
    Object[] arr = { Action.RERUN, TEST_FILE };
    doNothing().when(theFacadeInstance).runCommand(anyString());
    try (final MockedStatic<ScanRequestBuilder> scanBuilder = mockStatic(ScanRequestBuilder.class)) {
        ScanRequest request = new ScanRequest();
        request.setCompoundModel(getCompoundModel(grid, circle));
        scanBuilder.when(() -> ScanRequestBuilder.buildFromNexusFile(TEST_FILE)).thenReturn(Optional.of(request));
        builder.buildAndSubmitBlockingScanRequest(arr);
    }
    List<IClauseElementProcessor> processors = captor.getValue();
    assertThat(processors.size(), is(1));
    assertThat(processors.get(0), instanceOf(ReRunFromFileElementProcessor.class));
    assertThat(processors.get(0).getElement(), is(TEST_FILE));
    assertThat(processors.get(0).getElementValue(), is(TEST_FILE));
    verify(eventSubscriber).addListener(any(IScanListener.class));
    verify(submitter).blockingSubmit(beanCaptor.capture());
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(getBoundedCompoundModel(grid, circle))));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) IClauseElementProcessor(gda.mscan.processor.IClauseElementProcessor) ReRunFromFileElementProcessor(gda.mscan.processor.ReRunFromFileElementProcessor) ScanRequestBuilder(org.eclipse.scanning.sequencer.ScanRequestBuilder) Test(org.junit.Test)

Example 5 with ScanBean

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

the class MScanSubmitterTest method createsCorrectProcessorListForAxialArrayScanWithShorthandSyntaxAndSubmits.

@Test
public void createsCorrectProcessorListForAxialArrayScanWithShorthandSyntaxAndSubmits() throws Exception {
    Object[] arr = { scannable, RegionShape.AXIAL, Scanpath.AXIS_ARRAY, positions[0], positions[1], positions[2], positions[3], detectorRunnableDevice };
    when(resolver.resolveScanClauses()).thenReturn(Arrays.asList(Arrays.asList(new ScannableElementProcessor(scannable), new RegionShapeElementProcessor(RegionShape.AXIAL), new NumberElementProcessor(positions[2]), new NumberElementProcessor(positions[1]), new ScanpathElementProcessor(Scanpath.AXIS_ARRAY), new NumberElementProcessor(positions[0]), new NumberElementProcessor(positions[1]), new NumberElementProcessor(positions[2]), new NumberElementProcessor(positions[3])), Arrays.asList(new IRunnableDeviceDetectorElementProcessor(detectorRunnableDevice))));
    builder.buildAndSubmitBlockingScanRequest(arr);
    List<IClauseElementProcessor> processors = captor.getValue();
    assertThat(processors.size(), is(10));
    assertThat(processors.get(0), instanceOf(ScannableElementProcessor.class));
    assertThat(processors.get(0).getElement(), is(scannable));
    assertThat(processors.get(1), instanceOf(RegionShapeElementProcessor.class));
    assertThat(processors.get(1).getElement(), is(RegionShape.AXIAL));
    assertThat(processors.get(2), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(2).getElement(), is(positions[2]));
    assertThat(processors.get(3), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(3).getElement(), is(positions[1]));
    assertThat(processors.get(4), instanceOf(ScanpathElementProcessor.class));
    assertThat(processors.get(4).getElement(), is(Scanpath.AXIS_ARRAY));
    assertThat(processors.get(5), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(5).getElement(), is(positions[0]));
    assertThat(processors.get(6), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(6).getElement(), is(positions[1]));
    assertThat(processors.get(7), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(7).getElement(), is(positions[2]));
    assertThat(processors.get(8), instanceOf(NumberElementProcessor.class));
    assertThat(processors.get(8).getElement(), is(positions[3]));
    assertThat(processors.get(9), instanceOf(IRunnableDeviceDetectorElementProcessor.class));
    assertThat(processors.get(9).getElement(), is(detectorRunnableDevice));
    verify(eventSubscriber).addListener(any(IScanListener.class));
    verify(submitter).blockingSubmit(beanCaptor.capture());
    ScanBean bean = beanCaptor.getValue();
    assertThat(bean.getScanRequest().getCompoundModel(), is(equalTo(getCompoundModel(axArray, line))));
    assertThat(bean.getScanRequest().getDetectors().values(), contains(detectorRunnableDevice.getModel()));
}
Also used : IScanListener(org.eclipse.scanning.api.event.scan.IScanListener) ScanBean(org.eclipse.scanning.api.event.scan.ScanBean) NumberElementProcessor(gda.mscan.processor.NumberElementProcessor) ScanpathElementProcessor(gda.mscan.processor.ScanpathElementProcessor) IClauseElementProcessor(gda.mscan.processor.IClauseElementProcessor) ScannableElementProcessor(gda.mscan.processor.ScannableElementProcessor) IRunnableDeviceDetectorElementProcessor(gda.mscan.processor.IRunnableDeviceDetectorElementProcessor) RegionShapeElementProcessor(gda.mscan.processor.RegionShapeElementProcessor) Test(org.junit.Test)

Aggregations

ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)35 Test (org.junit.Test)23 IScanListener (org.eclipse.scanning.api.event.scan.IScanListener)20 ScanpathElementProcessor (gda.mscan.processor.ScanpathElementProcessor)18 IRunnableDeviceDetectorElementProcessor (gda.mscan.processor.IRunnableDeviceDetectorElementProcessor)16 NumberElementProcessor (gda.mscan.processor.NumberElementProcessor)15 IClauseElementProcessor (gda.mscan.processor.IClauseElementProcessor)13 RegionShapeElementProcessor (gda.mscan.processor.RegionShapeElementProcessor)12 ScannableElementProcessor (gda.mscan.processor.ScannableElementProcessor)12 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)8 ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)7 StaticModel (org.eclipse.scanning.api.points.models.StaticModel)7 EventException (org.eclipse.scanning.api.event.EventException)4 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)3 ScannableDetectorElementProcessor (gda.mscan.processor.ScannableDetectorElementProcessor)2 URISyntaxException (java.net.URISyntaxException)2 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)2 ReRunFromFileElementProcessor (gda.mscan.processor.ReRunFromFileElementProcessor)1 ScanDataConsumerElementProcessor (gda.mscan.processor.ScanDataConsumerElementProcessor)1 ScannableMonitorElementProcessor (gda.mscan.processor.ScannableMonitorElementProcessor)1