cleanup ...
This commit is contained in:
@@ -42,7 +42,6 @@ import com.google.common.eventbus.EventBus;
|
||||
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Manipulation;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.actions.ChannelAccessCondition;
|
||||
@@ -154,6 +153,8 @@ public class Acquisition {
|
||||
private List<Object> templates = new ArrayList<>();
|
||||
|
||||
|
||||
private Configuration configModel;
|
||||
|
||||
public Acquisition(ChannelService cservice){
|
||||
this.cservice = cservice;
|
||||
this.configuration = AcquisitionConfiguration.getInstance();
|
||||
@@ -234,10 +235,6 @@ public class Acquisition {
|
||||
throw new RuntimeException("Unable to serialize scan",e);
|
||||
}
|
||||
|
||||
// Configure core engine
|
||||
EngineConfiguration.getInstance().setFailOnSensorError(smodel.isFailOnSensorError());
|
||||
|
||||
|
||||
logger.fine("Map Model to internal logic");
|
||||
|
||||
DataMessageMetadata metadata;
|
||||
@@ -421,6 +418,7 @@ public class Acquisition {
|
||||
* @param scan
|
||||
*/
|
||||
private void mapScan(Collector collector, Configuration configuration){
|
||||
this.configModel = configuration;
|
||||
Scan scan = configuration.getScan();
|
||||
|
||||
// Map continuous dimension
|
||||
@@ -713,7 +711,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name), configModel.isFailOnSensorError());
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof FunctionPositioner){
|
||||
@@ -746,7 +744,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name), configModel.isFailOnSensorError());
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof ArrayPositioner){
|
||||
@@ -779,7 +777,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = ap.getName();
|
||||
}
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(ap.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(ap.getId(), createChannel(Double.class, name), configModel.isFailOnSensorError());
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof RegionPositioner){
|
||||
@@ -866,7 +864,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = rp.getName();
|
||||
}
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(rp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(rp.getId(), createChannel(Double.class, name), configModel.isFailOnSensorError());
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof PseudoPositioner){
|
||||
@@ -961,10 +959,10 @@ public class Acquisition {
|
||||
// Add sensor
|
||||
Sensor sensor;
|
||||
if(sd.getType().equals("String")){
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(String.class,sd.getName()));
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(String.class,sd.getName()), configModel.isFailOnSensorError());
|
||||
}
|
||||
else{
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(Double.class,sd.getName()));
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(Double.class,sd.getName()), configModel.isFailOnSensorError());
|
||||
}
|
||||
|
||||
aLoop.getSensors().add(sensor);
|
||||
@@ -976,7 +974,7 @@ public class Acquisition {
|
||||
aLoop.getPreSensorActions().addAll(mapActions(ad.getPreAction()));
|
||||
|
||||
// Ad sensor
|
||||
Sensor sensor = new ChannelAccessSensor<>(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize()));
|
||||
Sensor sensor = new ChannelAccessSensor<>(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize()), configModel.isFailOnSensorError());
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (detector instanceof DetectorOfDetectors){
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core;
|
||||
|
||||
/**
|
||||
* Singleton object for holing the core engine configuration
|
||||
*/
|
||||
public class EngineConfiguration {
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the engine should fail if there is an error while reading out a sensor.
|
||||
*/
|
||||
private boolean failOnSensorError = true;
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the set value of the actor should be verified after the set operation.
|
||||
* Having this flag on true will enable detecting for example that a motor hit the end switch or
|
||||
* did not move correctly.
|
||||
*/
|
||||
private boolean checkActorSet = true;
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
private final static EngineConfiguration instance = new EngineConfiguration();
|
||||
|
||||
|
||||
|
||||
private EngineConfiguration(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Get singleton instance of this class
|
||||
* @return Engine configuration
|
||||
*/
|
||||
public static EngineConfiguration getInstance(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the failOnSensorError
|
||||
*/
|
||||
public boolean isFailOnSensorError() {
|
||||
return failOnSensorError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param failOnSensorError the failOnSensorError to set
|
||||
*/
|
||||
public void setFailOnSensorError(boolean failOnSensorError) {
|
||||
this.failOnSensorError = failOnSensorError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the checkActorSet
|
||||
*/
|
||||
public boolean isCheckActorSet() {
|
||||
return checkActorSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkActorSet the checkActorSet to set
|
||||
*/
|
||||
public void setCheckActorSet(boolean checkActorSet) {
|
||||
this.checkActorSet = checkActorSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
@@ -78,6 +77,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final Function function;
|
||||
private boolean checkActorSet = true;
|
||||
|
||||
/**
|
||||
* Constructor - Initialize actor
|
||||
@@ -172,7 +172,7 @@ public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
if(checkActorSet){
|
||||
double c = channel.getValue(true);
|
||||
double a = Math.abs( c - fvalue );
|
||||
if ( a > accuracy ){
|
||||
|
||||
@@ -25,14 +25,11 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel from a start to an end value by doing discrete steps.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
|
||||
@@ -82,6 +79,8 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
private final Channel<Double> channel;
|
||||
private final Channel<T> doneChannel;
|
||||
|
||||
private boolean checkActorSet = true;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channel
|
||||
@@ -157,7 +156,7 @@ public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
if(checkActorSet){
|
||||
double c = channel.getValue(true);
|
||||
double a = Math.abs( c - value );
|
||||
if ( a > accuracy ){
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
@@ -80,6 +79,7 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
*/
|
||||
private Long timeout = null;
|
||||
|
||||
private boolean checkActorSet = true;
|
||||
|
||||
/**
|
||||
* Constructor - Initialize actor
|
||||
@@ -161,7 +161,7 @@ public class ChannelAccessTableActuator<T> implements Actor {
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(doneChannel==null && !asynchronous && EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
if(doneChannel==null && !asynchronous && checkActorSet){
|
||||
if ( Math.abs( channel.getValue() - table[count] ) > accuracy ){
|
||||
throw new RuntimeException("Actor could not be set to the value "+table[count]+" The readback of the set value does not match the value that was set");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
@@ -37,12 +36,19 @@ public class ChannelAccessSensor<T> implements Sensor {
|
||||
|
||||
private Channel<T> channel;
|
||||
private final String id;
|
||||
private boolean failOnSensorError = true;
|
||||
|
||||
public ChannelAccessSensor(String id, Channel<T> channel){
|
||||
this.id = id;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
public ChannelAccessSensor(String id, Channel<T> channel, boolean failOnSensorError){
|
||||
this.id = id;
|
||||
this.channel = channel;
|
||||
this.failOnSensorError = failOnSensorError;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
@@ -51,7 +57,7 @@ public class ChannelAccessSensor<T> implements Sensor {
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
if(failOnSensorError){
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = null;
|
||||
|
||||
Reference in New Issue
Block a user