use of uk.ac.diamond.daq.mapping.impl.ScriptFiles in project gda-core by openGDA.
the class MappingUISerializationTest method testSerializeScriptFiles.
@Test
public void testSerializeScriptFiles() throws Exception {
ScriptFiles scriptFiles = new ScriptFiles();
scriptFiles.setBeforeScanScript("/path/to/before.py");
scriptFiles.setAfterScanScript("/path/to/after.py");
scriptFiles.setAlwaysRunAfterScript(true);
String json = service.marshal(scriptFiles);
ScriptFiles newScriptFiles = service.unmarshal(json, ScriptFiles.class);
assertEquals(scriptFiles, newScriptFiles);
}
use of uk.ac.diamond.daq.mapping.impl.ScriptFiles 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.ScriptFiles 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)));
}
use of uk.ac.diamond.daq.mapping.impl.ScriptFiles in project gda-core by openGDA.
the class ScanRequestConverter method mergeIntoMappingBean.
/**
* Merge a scan request into an existing mapping bean so that it can be viewed
* and possibly modified in the Mapping Experiment Setup view.
* The reason for merging into an existing mapping bean is so that we don't remove
* detectors and processing steps that we not selected when this scan was run -
* when creating the scan request from the mapping bean a detector is only added if
* {@link IScanModelWrapper#isIncludeInScan()} is true. The mapping bean reconstructed
* from the scan request still needs to include this detector.
*
* @param scanRequest the {@link ScanRequest}
* @param mappingBean the {@link IMappingExperimentBean} to merge into
*/
public void mergeIntoMappingBean(ScanRequest scanRequest, IMappingExperimentBean mappingBean) {
final CompoundModel compoundModel = scanRequest.getCompoundModel();
final Collection<ScanRegion> regions = compoundModel.getRegions();
if (regions.size() != 1) {
throw new IllegalArgumentException("The scan request must have exactly one region, has " + regions.size());
}
// Check that the scannable names in the scan region are the same as in the mapping stage
final IMapPathModel mapPath = checkMapModelAndUpdateMappingStage(compoundModel);
// recreate the outer scannable wrappers from the scan request
mergeOuterScannables(compoundModel, mappingBean);
// set the scan path to the last child model of the compound model
final IScanDefinition scanDefinition = mappingBean.getScanDefinition();
final IMappingScanRegion scanRegion = scanDefinition.getMappingScanRegion();
scanRegion.setScanPath(mapPath);
// convert the ROI to a mapping scan region shape
final ScanRegion region = regions.iterator().next();
final IMappingScanRegionShape shape = convertROItoRegionShape(region.getRoi());
scanRegion.setRegion(shape);
// recreate the beamline configuration from the scan start position
if (scanRequest.getStartPosition() != null) {
mappingBean.setBeamlineConfiguration(new LinkedHashMap<>(scanRequest.getStartPosition().getValues()));
}
// recreate the detector models and processing steps (included in the same map of detectors in the scan request)
mergeDetectorAndProcessing(scanRequest, mappingBean);
// recreate the scripts to run before and after the scan, if any
if (scanRequest.getBeforeScript() != null || scanRequest.getAfterScript() != null) {
ScriptFiles scriptFiles = new ScriptFiles();
if (scanRequest.getBeforeScript() != null) {
scriptFiles.setBeforeScanScript(scanRequest.getBeforeScript().getFile());
}
if (scanRequest.getAfterScript() != null) {
scriptFiles.setAfterScanScript(scanRequest.getAfterScript().getFile());
}
scriptFiles.setAlwaysRunAfterScript(scanRequest.isAlwaysRunAfterScript());
mappingBean.setScriptFiles(scriptFiles);
}
// recreate the sample metadata from the metadata in the scan request
mergeSampleMetadata(scanRequest, mappingBean);
mergeTemplateFiles(scanRequest, mappingBean);
mergeProcessingRequest(scanRequest, mappingBean);
}
Aggregations