6 Commits

Author SHA1 Message Date
858d8dbd45 New version 2013-09-25 09:02:41 +02:00
879ec1d657 FDA-27
added datafile and filename to script actions
2013-09-23 15:34:31 +02:00
3025f597c0 FDA-27
Have filename available for manipulations
2013-09-23 13:18:29 +02:00
73107a4799 Always ensure that filename and name of the file inside the xml are
consistent!
Issue FDA-35
2013-09-23 10:56:20 +02:00
a5da9a2527 Issue FDA-35
Now the (file)name inside the xml file is always the same as the
filename of the xml file
2013-09-23 10:49:09 +02:00
21d935e35e Issue FDA-79
Removed restriction for manipulation
2013-09-23 09:55:41 +02:00
10 changed files with 184 additions and 10 deletions

View File

@@ -28,6 +28,10 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ch.psi</groupId>
<artifactId>fda</artifactId>
<version>1.1.38</version>
<version>1.1.40</version>
<dependencies>
<dependency>

View File

@@ -510,6 +510,12 @@ public class Acquisition {
}
JythonManipulation manipulation = new JythonManipulation(sm.getId(), sm.getScript(), mapping, sm.isReturnArray());
if(configuration.getData()!=null){ // Safety
manipulation.setVariable("FILENAME", configuration.getData().getFileName());
manipulation.setVariable("DATAFILE", datafile.getAbsoluteFile());
}
this.manipulations.add(manipulation);
}
}
@@ -621,7 +627,9 @@ public class Acquisition {
}
else if(a instanceof ShellAction){
ShellAction sa = (ShellAction) a;
ch.psi.fda.core.actions.ShellAction action = new ch.psi.fda.core.actions.ShellAction(sa.getCommand());
String com = sa.getCommand().replaceAll("\\$\\{DATAFILE\\}", datafile.getAbsolutePath());
com = com.replaceAll("\\$\\{FILENAME\\}", datafile.getName().replaceAll("\\.\\w*$", ""));
ch.psi.fda.core.actions.ShellAction action = new ch.psi.fda.core.actions.ShellAction(com);
action.setCheckExitValue(sa.isCheckExitValue());
action.setExitValue(sa.getExitValue());
alist.add(action);
@@ -629,6 +637,9 @@ public class Acquisition {
else if(a instanceof ScriptAction){
ScriptAction sa = (ScriptAction) a;
// TODO set global variables DATAFILE and FILENAME
// TODO create Jython Action
List<JythonParameterMappingChannel> mapping = new ArrayList<JythonParameterMappingChannel>();
for(ChannelParameterMapping ma: sa.getMapping()){
@@ -645,7 +656,11 @@ public class Acquisition {
logger.warning("Channel type ["+ma.getType()+"] is not supported for mapping");
}
}
alist.add(new ch.psi.fda.core.actions.JythonAction(sa.getScript(), mapping));
ch.psi.fda.core.actions.JythonAction ja = new ch.psi.fda.core.actions.JythonAction(sa.getScript(), mapping);
ja.setVariable("FILENAME", datafile.getName().replaceAll("\\.\\w*$", ""));
ja.setVariable("DATAFILE", datafile.getAbsoluteFile());
alist.add(ja);
}
}
return(alist);

View File

@@ -21,7 +21,9 @@ package ch.psi.fda.core.actions;
import gov.aps.jca.CAException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -60,6 +62,8 @@ public class JythonAction implements Action {
* Jython entry call
*/
private String jythonCall;
private Map<String,Object> gvariables = new HashMap<String,Object>();
public JythonAction(String script, List<JythonParameterMappingChannel> mapping){
@@ -76,7 +80,12 @@ public class JythonAction implements Action {
String[] functionParameters = null;
if(matcher.find() && matcher.groupCount()==1){
logger.finest("Entry function '"+entryFunctionPattern+"' found - Identified parameters: "+matcher.group(1));
functionParameters = matcher.group(1).split(" *, *");
if(matcher.group(1).matches(" *")){
functionParameters = new String[0];
}
else{
functionParameters = matcher.group(1).split(" *, *");
}
}
else{
throw new IllegalArgumentException("Cannot determine entry function: "+entryFunctionPattern);
@@ -112,7 +121,7 @@ public class JythonAction implements Action {
StringBuffer buffer = new StringBuffer();
buffer.append(entryFunction);
buffer.append("(");
buffer.append("( "); // Need to have trailing space as otherwise there will be a problem if no paramters are specified
for(JythonParameterMappingChannel b: mapping){
// Create channel
@@ -142,6 +151,15 @@ public class JythonAction implements Action {
*/
@Override
public void execute() {
// Set global variables - WORKAROUND gvariables
// This block is not in initialization as we want to assure that all invocations
// of this manipulation will get the same value (i.e. to prevent inconsistent behaviour
// if variable was changed during an execution of the manipulation)
for(String k: gvariables.keySet()){
engine.put(k, gvariables.get(k));
}
try {
engine.eval(jythonCall);
} catch (ScriptException e) {
@@ -166,4 +184,13 @@ public class JythonAction implements Action {
// Nothing to be done
}
/**
* Workaround to put variables into the jython engine.
* @param name
* @param value
*/
public void setVariable(String name, Object value){
gvariables.put(name, value);
}
}

View File

@@ -21,7 +21,9 @@ package ch.psi.fda.core.manipulator;
import gov.aps.jca.CAException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
@@ -102,6 +104,10 @@ public class JythonManipulation implements Manipulation{
*/
private String jythonCall;
private Map<String,Object> gvariables = new HashMap<String,Object>();
public JythonManipulation(String id, String script, List<JythonParameterMapping> mapping){
this(id, script, mapping, false);
}
@@ -232,12 +238,19 @@ public class JythonManipulation implements Manipulation{
buffer.setCharAt(buffer.length()-1, ')');
jythonCall = buffer.toString();
}
@Override
public Object execute(DataMessage message){
// Set global variables - WORKAROUND gvariables
// This block is not in initialization as we want to assure that all invocations
// of this manipulation will get the same value (i.e. to prevent inconsistent behaviour
// if variable was changed during an execution of the manipulation)
for(String k: gvariables.keySet()){
engine.put(k, gvariables.get(k));
}
// Manipulate data
for(int i=0;i<parameterIndex.length;i++){
if(parameterIndex[i] != null){
@@ -261,7 +274,8 @@ public class JythonManipulation implements Manipulation{
return(((Integer)r).doubleValue());
}
else{
return Double.NaN;
// return Double.NaN;
return r;
}
}
} catch (ScriptException e) {
@@ -270,4 +284,13 @@ public class JythonManipulation implements Manipulation{
return Double.NaN;
}
}
/**
* Workaround to put variables into the jython engine.
* @param name
* @param value
*/
public void setVariable(String name, Object value){
gvariables.put(name, value);
}
}

View File

@@ -47,6 +47,7 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import ch.psi.fda.model.v1.Configuration;
import ch.psi.fda.model.v1.Data;
/**
* Manage the serialization and deserialization of the model
@@ -111,6 +112,15 @@ public class ModelManager {
try{
Configuration model = (Configuration) u.unmarshal(bsource, Configuration.class).getValue();
// Ensure that the filename inside the xml file is always the file name
Data d = model.getData();
if(d==null){
d = new Data();
model.setData(d);
}
d.setFileName(file.getName().replaceAll("\\.xml$", ""));
return (model);
}
catch(UnmarshalException e){
@@ -142,6 +152,15 @@ public class ModelManager {
try{
Configuration model = (Configuration) u.unmarshal(new StreamSource(file), Configuration.class).getValue();
// Ensure that the filename inside the xml file is always the file name
Data d = model.getData();
if(d==null){
d = new Data();
model.setData(d);
}
d.setFileName(file.getName().replaceAll("\\.xml$", ""));
return (model);
}
catch(UnmarshalException e){
@@ -173,6 +192,14 @@ public class ModelManager {
Schema schema = sf.newSchema(new Source[]{s}); // Use schema reference provided in XML
m.setSchema(schema);
// Set scan name equal to file name
Data d = model.getData();
if(d==null){
d = new Data();
model.setData(d);
}
d.setFileName(file.getName().replaceAll("\\.xml$", ""));
m.marshal( new JAXBElement<Configuration>(qname, Configuration.class, model ), file);
}
}

View File

@@ -141,7 +141,22 @@ public class Visualizer {
// XYSeriesP series = ((LinePlot) xyfilter.getPlot()).getData().getSeries(xyfilter.getCount()); // TODO Does not work with multiple series filter per plot !!!!
XYSeriesP series = xyfilter.getActualSeries(); // TODO Does not work with multiple series filter per plot !!!!
// series.add((Double) m.getData().get(xyfilter.getIndexX()), (Double) m.getData().get(xyfilter.getIndexY()));
series.add((Double) m.getData().get(xyfilter.getIndexX()), (Double) m.getData().get(xyfilter.getIndexY()), updateAtStreamElement);
// There might be other values than double in the data, therefore we have to check for it
Object dX = m.getData().get(xyfilter.getIndexX());
Object dY = m.getData().get(xyfilter.getIndexY());
Double dataX = Double.NaN;
Double dataY = Double.NaN;
if(dX instanceof Double){
dataX = (Double) dX;
}
if(dY instanceof Double){
dataY = (Double) dY;
}
// Add Data to the series
series.add(dataX , dataY, updateAtStreamElement);
}
if(filter instanceof XYSeriesArrayDataFilter){
final XYSeriesArrayDataFilter xyfilter = (XYSeriesArrayDataFilter) filter;

View File

@@ -75,6 +75,8 @@ public class ModelManagerTest {
URL url = this.getClass().getClassLoader().getResource("home/scans/templates/scan1d.xml");
Configuration c = ModelManager.unmarshall(new File(new URI(url.toString())));
logger.info(""+c.getData().getFormat());
logger.info("FILENAME: "+c.getData().getFileName());
}
/**
@@ -106,7 +108,7 @@ public class ModelManagerTest {
Scan s = new Scan();
c.setScan(s);
ModelManager.marshall(c, new File(tmpDirectory+"/scan.xml"));
ModelManager.marshall(c, new File(tmpDirectory+"/scan1234.xml"));
}

View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration numberOfExecution="0" xmlns="http://www.psi.ch/~ebner/models/scan/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.psi.ch/~ebner/models/scan/1.0 ../../src/model-v1.xsd">
<!--
1D Scan reading out scalar channels and the timestamp for each point
-->
<data format="txt"/>
<scan id="">
<preAction xsi:type="ShellAction" command="/bin/echo hello ${DATAFILE} ${FILENAME}"/>
<preAction xsi:type="ScriptAction">
<script>
def process( ):
print "filename __ %s" % FILENAME
print "data __ %s" % DATAFILE
</script>
</preAction>
</scan>
</configuration>

View File

@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration numberOfExecution="0" xmlns="http://www.psi.ch/~ebner/models/scan/1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.psi.ch/~ebner/models/scan/1.0 ../../src/model-v1.xsd">
<!--
1D Scan reading out scalar channels and the timestamp for each point
-->
<data format="txt"/>
<scan id="">
<dimension zigzag="true">
<positioner id="id0" name="MTEST-HW3:MOT1" settlingTime="0.1" xsi:type="LinearPositioner">
<start>0.0</start>
<end>8.0</end>
<stepSize>0.5</stepSize>
</positioner>
<detector id="idD0" xsi:type="ScalarDetector" name="MTEST-HW3:MOT1.RRBV"/>
<detector id="idD1" xsi:type="ScalarDetector" name="MTEST-HW3:MOT1.RBV"/>
<detector xsi:type="Timestamp" id="timestamp"/>
</dimension>
<manipulation id="man1" xsi:type="ScriptManipulation">
<mapping xsi:type="IDParameterMapping" variable="a" refid="idD1"/>
<script>
def process(a):
return [1,a]
</script>
</manipulation>
<manipulation id="man2" xsi:type="ScriptManipulation">
<mapping xsi:type="IDParameterMapping" variable="a" refid="man1"/>
<script>
def process(a):
print a[1]
print FILENAME
return 1.0
</script>
</manipulation>
</scan>
<visualization title="Line Plot One" xsi:type="LinePlot" x="id0" y="idD0"/>
<visualization title="Line Plot Two" xsi:type="LinePlot" x="id0" y="idD1"/>
<visualization title="Line Plot Two" xsi:type="LinePlot" x="id0" y="man1"/>
<visualization title="Line Plot Two" xsi:type="LinePlot" x="id0" y="man2"/>
<visualization xsi:type="LinePlot" x="id0" y="timestamp" title="Timestamp" />
</configuration>