use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.
the class ScanRequestConverterTest method setUp.
@Before
public void setUp() throws Exception {
// We wire things together without OSGi here
// DO NOT COPY THIS IN NON-TEST CODE!
mappingStageInfo = new MappingStageInfo();
mappingStageInfo.setPlotXAxisName(X_AXIS_NAME);
mappingStageInfo.setPlotYAxisName(Y_AXIS_NAME);
mappingStageInfo.setBeamSize(BEAM_SIZE_NAME);
// Prepare the Finder
Factory testFactory = mock(Factory.class);
ScannableMotionUnits xAxis = mock(ScannableMotionUnits.class);
when(xAxis.getHardwareUnitString()).thenReturn(X_AXIS_UNITS);
ScannableMotionUnits yAxis = mock(ScannableMotionUnits.class);
when(yAxis.getHardwareUnitString()).thenReturn(Y_AXIS_UNITS);
when(testFactory.getFindable(X_AXIS_NAME)).thenReturn(xAxis);
when(testFactory.getFindable(Y_AXIS_NAME)).thenReturn(yAxis);
Finder.addFactory(testFactory);
scanRequestConverter = new ScanRequestConverter();
scanRequestConverter.setMappingStageInfo(mappingStageInfo);
// Set up the experiment bean with some sensible defaults
mappingBean = new MappingExperimentBean();
scanPath = new TwoAxisGridPointsModel();
scanPath.setContinuous(true);
mappingBean.getScanDefinition().getMappingScanRegion().setScanPath(scanPath);
final RectangularMappingRegion scanRegion = new RectangularMappingRegion();
scanRegion.setxStart(X_START);
scanRegion.setxStop(X_START + X_LENGTH);
scanRegion.setyStart(Y_START);
scanRegion.setyStop(Y_START + Y_LENGTH);
mappingBean.getScanDefinition().getMappingScanRegion().setRegion(scanRegion);
mappingBean.setDetectorParameters(Collections.emptyList());
mappingBean.setPerScanMonitorNames(new HashSet<>(Arrays.asList("perScan1", "perScan2")));
mappingBean.setPerPointMonitorNames(new HashSet<>(Arrays.asList("perPoint1", "perPoint2", "perPoint3")));
newMappingBean = new MappingExperimentBean();
}
use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.
the class MappingUISerializationTest method testSerializeMappingExperimentBean.
@Test
public void testSerializeMappingExperimentBean() throws Exception {
ScriptFiles scriptFiles = new ScriptFiles();
scriptFiles.setBeforeScanScript("/path/to/before.py");
scriptFiles.setAfterScanScript("/path/to/after.py");
Map<String, Object> beamlineConfiguration = new HashMap<>();
beamlineConfiguration.put("D7A", "Gap");
beamlineConfiguration.put("D7B", "gap");
beamlineConfiguration.put("kb_vfm_x", "7.0");
MandelbrotModel model = createMandelbrotModel();
DetectorModelWrapper mandelbrotWrapper = new DetectorModelWrapper("Mandelbrot Detector", model, true);
SimpleSampleMetadata sampleMetadata = new SimpleSampleMetadata();
sampleMetadata.setSampleName("SampleName");
sampleMetadata.setDescription("Description of sample");
IScanDefinition scanDefinition = createScanDefinition();
MappingExperimentBean mappingBean = new MappingExperimentBean();
mappingBean.setScriptFiles(scriptFiles);
mappingBean.setBeamlineConfiguration(beamlineConfiguration);
mappingBean.setDetectorParameters(Arrays.asList(mandelbrotWrapper));
mappingBean.setSampleMetadata(sampleMetadata);
mappingBean.setScanDefinition(scanDefinition);
ConfigWrapper w = new ConfigWrapper();
w.setAppName("dawn");
w.setPathToConfig("/path/to/config.json");
mappingBean.addProcessingRequest(w);
String json = service.marshal(mappingBean);
MappingExperimentBean newMappingBean = service.unmarshal(json, MappingExperimentBean.class);
assertEquals(mappingBean, newMappingBean);
}
use of uk.ac.diamond.daq.mapping.impl.MappingExperimentBean in project gda-core by openGDA.
the class ScanManagementController method loadScanMappingBean.
/**
* Loads the file specified by the supplied fully quAlified filename into a mapping bean which is then returned
* within and {@link Optional}. An error dialog is displayed if the file could not be successfully loaded.
*
* @param filename
* The fully qualified name of the required file
* @return An {@link Optional} of a mapping bean constructed from the contents of the file
*/
public Optional<IMappingExperimentBean> loadScanMappingBean(final String filename) {
checkInitialised();
Optional<IMappingExperimentBean> result = Optional.empty();
if (filename != null) {
try {
byte[] bytes = Files.readAllBytes(Paths.get(filename));
final String json = new String(bytes, "UTF-8");
final IMarshallerService marshaller = getService(IMarshallerService.class);
MappingExperimentBean mappingBean = marshaller.unmarshal(json, MappingExperimentBean.class);
stage.merge((MappingStageInfo) mappingBean.getStageInfoSnapshot());
result = Optional.of(mappingBean);
} catch (Exception e) {
final String errorMessage = "Could not load a mapping scan from file: " + filename;
logger.error(errorMessage, e);
ErrorDialog.openError(Display.getCurrent().getActiveShell(), "Load Scan", errorMessage, new Status(IStatus.ERROR, MappingUIConstants.PLUGIN_ID, errorMessage, e));
}
}
return result;
}
Aggregations