use of org.eclipse.january.DatasetException in project gda-core by openGDA.
the class ZebraRunnableDevice method write.
@Override
public boolean write(IPosition position) throws ScanningException {
try {
final double data1 = EPICS_CONTROLLER.cagetDouble(div1LastChannel);
final double data2 = EPICS_CONTROLLER.cagetDouble(div2LastChannel);
final double data3 = EPICS_CONTROLLER.cagetDouble(div3LastChannel);
final double data4 = EPICS_CONTROLLER.cagetDouble(div4LastChannel);
final IScanSlice scanSlice = IScanRankService.getScanRankService().createScanSlice(position);
// We assume that all datasets have the same shape
final SliceND slice = new SliceND(dataset1.getShape(), dataset1.getMaxShape(), scanSlice.getStart(), scanSlice.getStop(), scanSlice.getStep());
final Dataset ds1 = DatasetFactory.createFromObject(data1);
final Dataset ds2 = DatasetFactory.createFromObject(data2);
final Dataset ds3 = DatasetFactory.createFromObject(data3);
final Dataset ds4 = DatasetFactory.createFromObject(data4);
dataset1.setSlice(null, ds1, slice);
dataset2.setSlice(null, ds2, slice);
dataset3.setSlice(null, ds3, slice);
dataset4.setSlice(null, ds4, slice);
} catch (TimeoutException | CAException | InterruptedException | DatasetException e) {
final String message = "Error writing data";
logger.error(message, e);
throw new ScanningException(message, e);
}
setDeviceState(DeviceState.ARMED);
return true;
}
use of org.eclipse.january.DatasetException in project gda-core by openGDA.
the class NexusSlitsWrapper method setPosition.
@Override
public DeviceValueMultiPosition setPosition(DeviceValueMultiPosition value, IPosition position) throws ScanningException {
logger.debug("setPosition({}, {}) called on {}", value, position, getName());
if (value != null) {
logger.warn("non null setPosition() not expected on {}, ignoring...", getName());
}
if (position != null) {
try {
DeviceValueMultiPosition currentLocation = getPosition();
write(value, currentLocation, position);
return currentLocation;
} catch (DatasetException e) {
throw new ScanningException("Could not set position of scannable: " + getName(), e);
}
}
return null;
}
use of org.eclipse.january.DatasetException in project gda-core by openGDA.
the class MeanProc method processFrame.
@Override
public void processFrame(Dataset data, SliceFromSeriesMetadata metaSlice) {
logger.debug("Start of processFrame");
Object mean = data.mean();
Dataset s = DatasetFactory.createFromObject(mean);
SliceND sl = new SliceND(meanDataset.getShape(), meanDataset.getMaxShape(), metaSlice.getSliceFromInput());
try {
meanDataset.setSlice(null, s, sl);
} catch (DatasetException e) {
logger.error("Error setting slice", e);
}
logger.debug("End of processFrame");
}
use of org.eclipse.january.DatasetException in project gda-core by openGDA.
the class SumProc method processFrame.
@Override
public void processFrame(Dataset data, SliceFromSeriesMetadata metaSlice) {
logger.debug("Start of processFrame");
Object sum = data.sum();
Dataset s = DatasetFactory.createFromObject(sum);
SliceND sl = new SliceND(sumDataset.getShape(), sumDataset.getMaxShape(), metaSlice.getSliceFromInput());
try {
sumDataset.setSlice(null, s, sl);
} catch (DatasetException e) {
logger.error("Error setting slice", e);
}
logger.debug("End of processFrame");
}
use of org.eclipse.january.DatasetException in project gda-core by openGDA.
the class SwmrMalcolmProcessingReader method runOptimisedLoop.
/**
* Loop to run if there is up to a max of two processors, typically one ROI and one plot.
* This only updates the plotting periodically rather than every frame which allows for
* the lazy dataset to be actually read in the ROI processor (for the region only) rather
* than reading the full frame here every time.
*/
private void runOptimisedLoop(SimpleDynamicSliceViewIterator it) {
Optional<RoiProc> roi = procs.stream().filter(RoiProc.class::isInstance).map(RoiProc.class::cast).findFirst();
Optional<PlotProc> plot = procs.stream().filter(PlotProc.class::isInstance).map(PlotProc.class::cast).findFirst();
// Last time the plot was updated
long plotLastUpdate = System.currentTimeMillis();
// Time last of last frame from iterator
long iterTime;
while (it.hasNext()) {
ILazyDataset next = it.next();
iterTime = System.currentTimeMillis();
SliceFromSeriesMetadata md = next.getFirstMetadata(SliceFromSeriesMetadata.class);
logger.debug("Ready for slice {}", Slice.createString(md.getSliceFromInput()));
next.clearMetadata(null);
// We read the full dataset and send to plot and roi only once per second
if (plot.isPresent() && (iterTime - plotLastUpdate > 1000)) {
try {
Dataset dataset = DatasetUtils.convertToDataset(next.getSlice());
plot.get().processFrame(dataset, md);
plotLastUpdate = iterTime;
roi.ifPresent(r -> r.processFrame(dataset, md));
sendUpdateMessage();
} catch (DatasetException e) {
logger.error("Error obtaining slice, meta: {}", md, e);
return;
}
} else if (roi.isPresent()) {
// Otherwise we pass the LazyDataset to the ROI without reading the full frame
long roiTStart = System.currentTimeMillis();
roi.get().processFrame(next, md);
logger.debug("Roi proc took {} millis", System.currentTimeMillis() - roiTStart);
}
logger.debug("Complete for slice {}, total time {} millis", Slice.createString(md.getSliceFromInput()), System.currentTimeMillis() - iterTime);
}
}
Aggregations