Skip to content
This repository was archived by the owner on Mar 27, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ public void pause() throws ScanningException {
}

@Override
public void seek(int stepNumber) throws ScanningException {
public void seek(int stepNumber) throws ScanningException, InterruptedException {
// Do nothing
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public interface IDeviceController {
* Make a seek
* @param id
*/
void seek(String id, int step)throws ScanningException;
void seek(String id, int step)throws ScanningException, InterruptedException;

/**
* Make an abort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface IPausableDevice<T> extends IRunnableDevice<T> {
* Seek to/from a point number (absolute) in the scan.
* @param amount
*/
void seek(int stepNumber) throws ScanningException;
void seek(int stepNumber) throws ScanningException, InterruptedException;

/**
* Allowed when the device is in Paused state. Will block until the device is unpaused.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,5 +205,16 @@ public interface IRunnableDeviceService extends IPositionerService {
*/
Collection<DeviceInformation<?>> getDeviceInformationIncludingNonAlive() throws ScanningException;


/**
* This is a convenience method for getting the currently active scanner.
* It is useful if the scan is paused and it is required to seek the scan
* to a new location from Jython. The returned scanner will be null unless
* a scan is currently running, therefore it is of limited usage normally.
*
* @return current actively scanning device.
*/
default <T> IRunnableDevice<T> getActiveScanner() {
throw new IllegalArgumentException("The get active scanner method is not availble!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ public String toString() {
buf.append(get(name));
if (it.hasNext()) buf.append(", ");
}
buf.append(", step=");
buf.append(getStepIndex());

buf.append("]");
return buf.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
package org.eclipse.scanning.api.points;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,29 @@ public interface IPositionListenable {
*/
void removePositionListener(IPositionListener listener);

/**
* If there is a current IPositioner available, this is returned.
* Often an IPositionListenable will not implement getPositioner() or
* may not be back by an object directly moving position.
* <p><b>Use with Caution!</b>
*
* @return
*/
default IPositioner getPositioner() {
return null;
}

/**
* If there is a current IPositioner available, this is returned.
* Often an IPositionListenable will not implement getPositioner() or
* may not be back by an object directly moving position.
* <p><b>Use with Caution!</b>
*
* @return
* @throws IllegalArgumentException if there is no positioner
*/
default void setPositioner(IPositioner positioner) {
throw new IllegalArgumentException("The positioner of "+getClass().getSimpleName()+" may not be set");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public List<IPosition> createPoints() throws GeneratorException {

List<IPosition> points = new ArrayList<>(size());
createPoints(0, points, null);
for (int i = 0; i < points.size(); i++) points.get(i).setStepIndex(i);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR At most one statement is allowed per line, but 2 statements were found on this line. rule

return points;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ public class CompoundIterator implements Iterator<IPosition> {
private CompoundGenerator gen;
private IPosition pos;
private Iterator<? extends IPosition>[] iterators;
private int index;

public CompoundIterator(CompoundGenerator gen) throws GeneratorException {
this.gen = gen;
this.iterators = initIterators();
this.pos = createFirstPosition();
this.index = -1;
}

private IPosition createFirstPosition() throws GeneratorException {
Expand All @@ -57,6 +59,9 @@ private IPosition createFirstPosition() throws GeneratorException {
@Override
public boolean hasNext() {
next = getNext();
index++;
if (next!=null) next.setStepIndex(index);
Copy link
Copy Markdown
Contributor Author

@gerring gerring Feb 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR At most one statement is allowed per line, but 2 statements were found on this line. rule


justDidNext = true;
return next!=null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class CompoundSpgIterator extends AbstractScanPointIterator {

public SerializableIterator<IPosition> pyIterator;
private IPosition currentPoint;
private int index = -1;

public CompoundSpgIterator(CompoundGenerator gen) throws GeneratorException {
this.gen = gen;
Expand All @@ -75,7 +76,9 @@ public CompoundSpgIterator(CompoundGenerator gen) throws GeneratorException {
@SuppressWarnings("unchecked")
SerializableIterator<IPosition> iterator = (SerializableIterator<IPosition>) compoundGeneratorFactory.createObject(
iterators, excluders, mutators);
pyIterator = iterator;

index = -1;
pyIterator = iterator;
}

private IPosition createFirstPosition() throws GeneratorException {
Expand Down Expand Up @@ -106,6 +109,8 @@ public boolean hasNext() {
//
// if (gen.containsPoint(x, y)) {
currentPoint = point;
index++;
if (currentPoint!=null) currentPoint.setStepIndex(index);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR At most one statement is allowed per line, but 2 statements were found on this line. rule

return true;
// }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
* @author Matthew Gerring
*/
final class AcquisitionDevice extends AbstractRunnableDevice<ScanModel> implements IPositionListener {

// Scanning stuff
private IPositioner positioner;
private LevelRunner<IRunnableDevice<?>> runners;
Expand Down Expand Up @@ -199,6 +199,7 @@ public void configure(ScanModel model) throws ScanningException {
@Override
public void run(IPosition parent) throws ScanningException, InterruptedException {


if (getDeviceState()!=DeviceState.READY) throw new ScanningException("The device '"+getName()+"' is not ready. It is in state "+getDeviceState());

ScanModel model = getModel();
Expand All @@ -215,6 +216,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException
boolean errorFound = false;
IPosition pos = null;
try {
RunnableDeviceServiceImpl.setCurrentScanningDevice(this);
if (latch!=null) latch.countDown();
this.latch = new CountDownLatch(1);
// TODO Should we validate the position iterator that all
Expand Down Expand Up @@ -256,7 +258,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException

// Check if we are paused, blocks until we are not
boolean continueRunning = checkPaused();
if (!continueRunning) return; // finally block performed
if (!continueRunning) return; // finally block performed

// Run to the position
manager.invoke(PointStart.class, pos);
Expand All @@ -265,14 +267,13 @@ public void run(IPosition parent) throws ScanningException, InterruptedException
IPosition written = writers.await(); // Wait for the previous write out to return, if any
if (written!=null) manager.invoke(WriteComplete.class, written);

nexusScanFileManager.flushNexusFile(); // flush the nexus file
runners.run(pos); // GDA8: collectData() / GDA9: run() for Malcolm
runners.run(pos); // GDA8: collectData() / GDA9: run() for Malcolm
writers.run(pos, false); // Do not block on the readout, move to the next position immediately.

// Send an event about where we are in the scan
manager.invoke(PointEnd.class, pos);
positionComplete(pos, count, size);
++count;
count+=Math.max(innerSize, 1);
}

// On the last iteration we must wait for the final readout.
Expand All @@ -292,6 +293,7 @@ public void run(IPosition parent) throws ScanningException, InterruptedException

} finally {
close(errorFound, pos);
RunnableDeviceServiceImpl.setCurrentScanningDevice(null);
}
}

Expand Down Expand Up @@ -561,13 +563,33 @@ public void pause() throws ScanningException {
}

@Override
public void seek(int stepNumber) throws ScanningException {
// TODO FIXME The positioner should seek back to the previous position!!
public void seek(int stepNumber) throws ScanningException, InterruptedException {
// This is the values of all motors at this global (including malcolm) scan
// position. Therefore we do not need a subscan moderator but can run the iterator
// to the point
IPosition pos = positionForStep(stepNumber);
if (pos == null) throw new ScanningException("Seek position is invalid "+stepNumber);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR At most one statement is allowed per line, but 2 statements were found on this line. rule


positioner.setPosition(pos);
if (getModel().getDetectors()!=null) for (IRunnableDevice<?> device : getModel().getDetectors()) {
if (device instanceof IPausableDevice) ((IPausableDevice)device).seek(stepNumber);
}
}

private IPosition positionForStep(int stepNumber) {
/*
* IMPORTANT We do not keep the positions in memory because there can be millions.
* Running over them is fast however.
*/
int count=0;
for (IPosition pos : model.getPositionIterable()) {
pos.setStepIndex(count);
if (count == stepNumber) return pos;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR At most one statement is allowed per line, but 2 statements were found on this line. rule

count++;
}
return null;
}

@Override
public void resume() throws ScanningException {

Expand Down Expand Up @@ -690,4 +712,9 @@ private int getScanRank(Iterable<IPosition> gen) {
return scanRank;
}

@Override
public IPositioner getPositioner() {
return positioner;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public final class RunnableDeviceServiceImpl implements IRunnableDeviceService,
*/
private static final Map<String, IRunnableDevice> namedDevices;


// This field is used to provide the getActiveScanner() method on the service.
// It should not be accessed from elsewhere.
private static IRunnableDevice<?> currentScanningDevice;


// Use a factory pattern to register the types.
// This pattern can always be extended by extension points
// to allow point generators to be dynamically registered.
Expand Down Expand Up @@ -421,4 +427,19 @@ public void removeScanParticipant(Object device) {
public Collection<Object> getScanParticipants() {
return participants; // May be null
}

@SuppressWarnings("unchecked")
@Override
public <T> IRunnableDevice<T> getActiveScanner() {
return (IRunnableDevice<T>)RunnableDeviceServiceImpl.currentScanningDevice; // Package private method. Do not use globally!
}

/**
* Package private, think before stopping this.
* @param currentScanningDevice
*/
static void setCurrentScanningDevice(IRunnableDevice<?> currentScanningDevice) {
RunnableDeviceServiceImpl.currentScanningDevice = currentScanningDevice;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public IPosition getPosition() throws ScanningException {
throw new ScanningException("Cannout read value of "+name, ne);
}
}
ret.setStepIndex(position.getStepIndex());
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void pause(String id, DeviceWatchdogModel model) throws ScanningException
logger.debug("Controller pausing on "+getName()+" because of id "+id);
device.pause();
}
public void seek(String id, int stepNumber) throws ScanningException {
public void seek(String id, int stepNumber) throws ScanningException, InterruptedException {

// If any of the others think it should be paused, we do not resume
Map<String, DeviceState> copy = new HashMap<>(states);
Expand Down
Loading