FDA-27
Have filename available for manipulations
This commit is contained in:
@@ -510,6 +510,11 @@ 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());
|
||||
}
|
||||
|
||||
this.manipulations.add(manipulation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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){
|
||||
@@ -271,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);
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ def process(a):
|
||||
<script>
|
||||
def process(a):
|
||||
print a[1]
|
||||
print FILENAME
|
||||
return 1.0
|
||||
</script>
|
||||
</manipulation>
|
||||
|
||||
Reference in New Issue
Block a user