diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java index a682262..65885d9 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/aq/Acquisition.java @@ -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 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 sensor = new ChannelAccessSensor(lp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(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 sensor = new ChannelAccessSensor(lp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(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 sensor = new ChannelAccessSensor(ap.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(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 sensor = new ChannelAccessSensor(rp.getId(), createChannel(Double.class, name)); + ChannelAccessSensor sensor = new ChannelAccessSensor(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){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/EngineConfiguration.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/EngineConfiguration.java deleted file mode 100644 index 61391ad..0000000 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/EngineConfiguration.java +++ /dev/null @@ -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 . - * - */ - -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; - } - -} diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java index d08eca8..b8f44f9 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessFunctionActuator.java @@ -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 implements Actor { private Channel doneChannel = null; private final Function function; + private boolean checkActorSet = true; /** * Constructor - Initialize actor @@ -172,7 +172,7 @@ public class ChannelAccessFunctionActuator 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 ){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java index 7a572a5..bd244b4 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessLinearActuator.java @@ -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 implements Actor { @@ -82,6 +79,8 @@ public class ChannelAccessLinearActuator implements Actor { private final Channel channel; private final Channel doneChannel; + private boolean checkActorSet = true; + /** * Constructor * @param channel @@ -157,7 +156,7 @@ public class ChannelAccessLinearActuator 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 ){ diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java index 2d12d94..acef43b 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/actors/ChannelAccessTableActuator.java @@ -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 implements Actor { */ private Long timeout = null; + private boolean checkActorSet = true; /** * Constructor - Initialize actor @@ -161,7 +161,7 @@ public class ChannelAccessTableActuator 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"); } diff --git a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java index d3eaa75..e04a80f 100644 --- a/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java +++ b/ch.psi.fda/src/main/java/ch/psi/fda/core/sensors/ChannelAccessSensor.java @@ -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 implements Sensor { private Channel channel; private final String id; + private boolean failOnSensorError = true; public ChannelAccessSensor(String id, Channel channel){ this.id = id; this.channel = channel; } + public ChannelAccessSensor(String id, Channel 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 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;