Search in sources :

Example 31 with ScanRequest

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

the class ScanRequestConverterTest method testDetectorIsExcludedCorrectly.

@Test
public void testDetectorIsExcludedCorrectly() throws Exception {
    // Arrange
    final String displayName = "Mandelbrot Detector";
    final IDetectorModel detModel = new MandelbrotModel();
    mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, false)));
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    assertThat(scanRequest.getDetectors().entrySet(), is(empty()));
    // Act again - merge the scan request back into the same mapping bean
    scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBean);
    // Assert again - check the mapping bean is the same as the original
    List<IScanModelWrapper<IDetectorModel>> newDetectorParams = mappingBean.getDetectorParameters();
    assertThat(newDetectorParams.size(), is(1));
    IScanModelWrapper<IDetectorModel> wrapper = newDetectorParams.get(0);
    assertThat(wrapper.getName(), is(equalTo(displayName)));
    // names must be same, i.e. mandlebrot
    assertThat(wrapper.getModel(), is(equalTo(detModel)));
    assertThat(wrapper.isIncludeInScan(), is(false));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 32 with ScanRequest

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

the class ScanRequestConverterTest method testDetectorIsIncludedCorrectly.

@Test
public void testDetectorIsIncludedCorrectly() throws Exception {
    // Arrange
    final String detName = "mandelbrot";
    final String displayName = "Mandelbrot Detector";
    final IDetectorModel detModel = new MandelbrotModel();
    detModel.setName(detName);
    mappingBean.setDetectorParameters(Arrays.asList(new DetectorModelWrapper(displayName, detModel, true)));
    // Act - convert mapping bean to scan request
    final ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    assertEquals(detModel, scanRequest.getDetectors().get(detName));
    // Act again - convert scan request back to mapping bean
    ((DetectorModelWrapper) mappingBean.getDetectorParameters().get(0)).setIncludeInScan(false);
    scanRequestConverter.mergeIntoMappingBean(scanRequest, mappingBean);
    // Assert - check the new mapping bean is the same as the original
    List<IScanModelWrapper<IDetectorModel>> newDetectorParams = mappingBean.getDetectorParameters();
    assertThat(newDetectorParams.size(), is(1));
    IScanModelWrapper<IDetectorModel> wrapper = newDetectorParams.get(0);
    assertThat(wrapper.getName(), is(equalTo(displayName)));
    assertThat(wrapper.getModel(), is(equalTo(detModel)));
    assertThat(wrapper.isIncludeInScan(), is(true));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) IDetectorModel(org.eclipse.scanning.api.device.models.IDetectorModel) IScanModelWrapper(uk.ac.diamond.daq.mapping.api.IScanModelWrapper) DetectorModelWrapper(uk.ac.diamond.daq.mapping.impl.DetectorModelWrapper) MandelbrotModel(org.eclipse.scanning.example.detector.MandelbrotModel) Test(org.junit.Test)

Example 33 with ScanRequest

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

the class ScanRequestConverterTest method testMonitorNameSetCorrectly.

@Test
public void testMonitorNameSetCorrectly() throws Exception {
    // Arrange
    final Set<String> perPointMonitorNames = mappingBean.getPerPointMonitorNames();
    final Set<String> perScanMonitorNames = mappingBean.getPerScanMonitorNames();
    // Act - convert mapping bean to scan request
    ScanRequest scanRequest = scanRequestConverter.convertToScanRequest(mappingBean);
    // Assert
    assertEquals(perPointMonitorNames, scanRequest.getMonitorNamesPerPoint());
    Set<String> expectedPerScanMonitorNames = new HashSet<>(perScanMonitorNames);
    expectedPerScanMonitorNames.add(BEAM_SIZE_NAME);
    assertEquals(expectedPerScanMonitorNames, scanRequest.getMonitorNamesPerScan());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with ScanRequest

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

the class ScanRequestFactoryTest method testNotEmptyTemplateFile.

@Test
public void testNotEmptyTemplateFile() throws Exception {
    IMalcolmModel model = Mockito.mock(IMalcolmModel.class);
    when(detectorModel.getModel()).thenReturn(model);
    ScanningAcquisition scanningAcquisition = loadScanningAcquisition();
    URL file1 = new URL("file:/lev1/lev2");
    URL file2 = new URL("file:/lev3/lev4");
    List<URL> paths = new ArrayList<>();
    paths.add(file1);
    paths.add(file2);
    ApplyNexusTemplatesRequest request = (new ApplyNexusTemplatesRequest.Builder()).withValue(paths).build();
    scanningAcquisition.getAcquisitionConfiguration().setProcessingRequest(new ArrayList<>());
    scanningAcquisition.getAcquisitionConfiguration().getProcessingRequest().add(request);
    ScanRequestFactory scanRequestFactory = new ScanRequestFactory(scanningAcquisition);
    ScanRequest scanRequest = scanRequestFactory.createScanRequest(runnableService);
    Assert.assertEquals(2, scanRequest.getTemplateFilePaths().size());
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ScanningAcquisition(uk.ac.diamond.daq.mapping.api.document.scanning.ScanningAcquisition) IMalcolmModel(org.eclipse.scanning.api.device.models.IMalcolmModel) ArrayList(java.util.ArrayList) ApplyNexusTemplatesRequest(uk.ac.gda.api.acquisition.configuration.processing.ApplyNexusTemplatesRequest) URL(java.net.URL) Test(org.junit.Test)

Example 35 with ScanRequest

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

the class ApplyNexusTemplateTest method testApplyNexusTemplateRequest.

@Test
public void testApplyNexusTemplateRequest() throws Exception {
    ProcessingRequestHandler handler = new ApplyNexusTemplateHandler();
    List<URL> paths = new ArrayList<>();
    paths.add(file1);
    paths.add(file2);
    ApplyNexusTemplatesRequest request = new ApplyNexusTemplatesRequest.Builder().withValue(paths).build();
    ScanRequest scanRequest = new ScanRequest();
    scanRequest.setProcessingRequest(new ProcessingRequest());
    scanRequest.getProcessingRequest().setRequest(new HashMap<>());
    handler.handle(request, scanRequest);
    Set<String> translated = scanRequest.getTemplateFilePaths();
    Assert.assertEquals(2, translated.size());
    Assert.assertTrue(translated.contains(file1.getPath()));
    Assert.assertTrue(translated.contains(file2.getPath()));
}
Also used : ScanRequest(org.eclipse.scanning.api.event.scan.ScanRequest) ArrayList(java.util.ArrayList) ProcessingRequest(org.eclipse.scanning.api.event.scan.ProcessingRequest) ApplyNexusTemplatesRequest(uk.ac.gda.api.acquisition.configuration.processing.ApplyNexusTemplatesRequest) URL(java.net.URL) 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