Search in sources :

Example 11 with ScanRequest

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

the class ScanRequestConverterTest method testTemplateFilesAdded.

@Test
public void testTemplateFilesAdded() throws Exception {
    final String first = "first.yaml";
    final String second = "second.yaml";
    final String third = "third.yaml";
    final String fourth = "fourth.yaml";
    final TemplateFileWrapper firstWrapper = new TemplateFileWrapper(first, true);
    final TemplateFileWrapper secondWrapper = new TemplateFileWrapper(second, true);
    final TemplateFileWrapper thirdWrapper = new TemplateFileWrapper(third, false);
    final TemplateFileWrapper fourthWrapper = new TemplateFileWrapper(fourth, true);
    // Arrange
    final TemplateFileWrapper[] templateFiles = { firstWrapper, secondWrapper, thirdWrapper };
    mappingBean.setTemplateFiles(Arrays.asList(templateFiles));
    // Act
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert: only active files should be in scan request
    final Set<String> scanRequestTemplateFiles = scanRequest.getTemplateFilePaths();
    assertThat(scanRequestTemplateFiles, contains(first, second));
    // Arrange again - to convert back to mapping bean
    mappingBean.setTemplateFiles(Arrays.asList(secondWrapper, fourthWrapper));
    // Act
    scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBean);
    // Assert: the merge should add any files that were not already in the mapping bean and deactivate any that were
    // not in the scan request.
    final List<TemplateFileWrapper> mappingBeanTemplateFiles = mappingBean.getTemplateFiles();
    assertEquals(3, mappingBeanTemplateFiles.size());
    assertContainsWrapper(mappingBeanTemplateFiles, first, true);
    assertContainsWrapper(mappingBeanTemplateFiles, second, true);
    assertContainsWrapper(mappingBeanTemplateFiles, fourth, false);
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) TemplateFileWrapper(uk.ac.diamond.daq.mapping.api.TemplateFileWrapper) Test(org.junit.Test)

Example 12 with ScanRequest

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

the class ScanRequestConverterTest method testOuterScannableIsSet.

@Test
public void testOuterScannableIsSet() throws Exception {
    // Arrange
    final IScanPointGeneratorModel outerModel = new AxialStepModel(Z_AXIS_NAME, -3, 2, 0.5);
    final List<IScanModelWrapper<IScanPointGeneratorModel>> outerScannables = Arrays.asList(new ScanPathModelWrapper(Z_AXIS_NAME, outerModel, true));
    mappingBean.getScanDefinition().setOuterScannables(outerScannables);
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    // Check there are now 2 models the outer z AxialStepModel and the inner Grid model
    assertThat(scanRequest.getCompoundModel().getModels().size(), is(equalTo(2)));
    final AxialStepModel recoveredOuterModel = (AxialStepModel) scanRequest.getCompoundModel().getModels().get(0);
    // Check the outer scannable model is first in the list
    assertThat(recoveredOuterModel, is(outerModel));
    // Check it has the correct axis name
    assertThat(recoveredOuterModel.getName(), is(Z_AXIS_NAME));
    // setup the new mapping bean with an outer scannable for the same axis, but disabled
    // and with a different model, and another enabled and for a different axis
    newMappingBean.getScanDefinition().setOuterScannables(Arrays.asList(new ScanPathModelWrapper(Z_AXIS_NAME, new AxialStepModel(Z_AXIS_NAME, 0, 5, 0.25), false), new ScanPathModelWrapper("energy", new AxialStepModel("energy", 10000, 15000, 1000), true)));
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again - check the new mapping bean is the same as the old one
    List<IScanModelWrapper<IScanPointGeneratorModel>> newOuterScannables = newMappingBean.getScanDefinition().getOuterScannables();
    assertThat(newOuterScannables.size(), is(2));
    assertThat(newOuterScannables.get(0).getName(), is(equalTo(Z_AXIS_NAME)));
    assertThat(newOuterScannables.get(0).getModel(), is(equalTo(outerModel)));
    assertThat(newOuterScannables.get(0).isIncludeInScan(), is(true));
    assertThat(newOuterScannables.get(1).getName(), is(equalTo("energy")));
    assertThat(newOuterScannables.get(1).isIncludeInScan(), is(false));
}
Also used : ScanPathModelWrapper(uk.ac.diamond.daq.mapping.impl.ScanPathModelWrapper) ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) AxialStepModel(org.eclipse.scanning.api.points.models.AxialStepModel) IScanPointGeneratorModel(org.eclipse.scanning.api.points.models.IScanPointGeneratorModel) Test(org.junit.Test)

Example 13 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest 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 14 with ScanRequest

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

the class ScanRequestConverterTest method testScriptFilesIncludedCorrectly.

@Test
public void testScriptFilesIncludedCorrectly() throws Exception {
    // Arrange
    final String beforeScanScript = "/path/to/before.py";
    final String afterScanScript = "/path/to/after.py";
    final IScriptFiles scriptFiles = new ScriptFiles();
    mappingBean.setScriptFiles(scriptFiles);
    scriptFiles.setBeforeScanScript(beforeScanScript);
    scriptFiles.setAfterScanScript(afterScanScript);
    scriptFiles.setAlwaysRunAfterScript(true);
    // Act - covert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    final ScriptRequest beforeScriptReq = scanRequest.getBeforeScript();
    assertThat(beforeScriptReq, is(notNullValue()));
    assertThat(beforeScriptReq.getLanguage(), is(SPEC_PASTICHE));
    assertThat(beforeScriptReq.getFile(), is(equalTo(beforeScanScript)));
    final ScriptRequest afterScriptReq = scanRequest.getAfterScript();
    assertThat(afterScriptReq, is(notNullValue()));
    assertThat(afterScriptReq.getLanguage(), is(SPEC_PASTICHE));
    assertThat(afterScriptReq.getFile(), is(equalTo(afterScanScript)));
    assertThat(scanRequest.isAlwaysRunAfterScript(), is(true));
    // Act again - convert the scan request back to a mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, newMappingBean);
    // Assert again
    final IScriptFiles newScriptFiles = newMappingBean.getScriptFiles();
    assertThat(newScriptFiles, is(notNullValue()));
    assertThat(newScriptFiles.getBeforeScanScript(), is(equalTo(beforeScanScript)));
    assertThat(newScriptFiles.getAfterScanScript(), is(equalTo(afterScanScript)));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScriptRequest(org.eclipse.scanning.api.script.ScriptRequest) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) ScriptFiles(uk.ac.diamond.daq.mapping.impl.ScriptFiles) IScriptFiles(uk.ac.diamond.daq.mapping.api.IScriptFiles) Test(org.junit.Test)

Example 15 with ScanRequest

use of org.eclipse.scanning.api.event.scan.ScanRequest 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)

Aggregations

ScanRequest (org.eclipse.scanning.api.event.scan.ScanRequest)42 Test (org.junit.Test)25 IDetectorModel (org.eclipse.scanning.api.device.models.IDetectorModel)8 ScanBean (org.eclipse.scanning.api.event.scan.ScanBean)8 CompoundModel (org.eclipse.scanning.api.points.models.CompoundModel)8 IScanPointGeneratorModel (org.eclipse.scanning.api.points.models.IScanPointGeneratorModel)8 ArrayList (java.util.ArrayList)7 ProcessingRequest (org.eclipse.scanning.api.event.scan.ProcessingRequest)7 IScanModelWrapper (uk.ac.diamond.daq.mapping.api.IScanModelWrapper)7 IMarshallerService (org.eclipse.dawnsci.analysis.api.persistence.IMarshallerService)5 ScanRegion (org.eclipse.scanning.api.points.models.ScanRegion)5 IScriptService (org.eclipse.scanning.api.script.IScriptService)5 IMappingExperimentBean (uk.ac.diamond.daq.mapping.api.IMappingExperimentBean)5 HashMap (java.util.HashMap)4 AxialStepModel (org.eclipse.scanning.api.points.models.AxialStepModel)4 IMappingScanRegion (uk.ac.diamond.daq.mapping.api.IMappingScanRegion)4 TemplateFileWrapper (uk.ac.diamond.daq.mapping.api.TemplateFileWrapper)4 DetectorModelWrapper (uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper)4 IMalcolmModel (org.eclipse.scanning.api.device.models.IMalcolmModel)3 IMapPathModel (org.eclipse.scanning.api.points.models.IMapPathModel)3