14 Commits
1.0.0 ... zmq

Author SHA1 Message Date
5660fafe25 Fixed bug regarding the execution of manipulations 2013-10-04 13:03:34 +02:00
bf3535a9b5 optimized data flow for scans without manipulations 2013-10-04 11:27:40 +02:00
b9c15b0fc8 Added EventBus to collector 2013-10-04 11:16:08 +02:00
83dd7654ed small changes before messingup with guice 2013-10-03 16:19:09 +02:00
e723f66df3 More cleanup 2013-10-03 14:24:17 +02:00
1574dcc7bb Cleanup 2013-10-03 14:20:24 +02:00
1de3b6c14e Cleanup 2013-10-03 13:55:34 +02:00
2a6018c4f5 Fixed all compile problems and migrated all serializers and
deserializers to Guava EventBus.
2013-10-03 13:44:08 +02:00
c3238e4d22 Unfinished removal of the dispatcher class. tested the migration of the
serializer to EventBus.
Test is/was successfull but things now need to be cleaned up properly!
There are various compilation errors in the code
2013-10-03 10:57:20 +02:00
4045873135 Moved on to google guava EventBus for visualizer ... 2013-10-03 10:30:29 +02:00
3e38e4002d Experiment with zmq pub/sub for visualization.
- after the scan somehow the zmq library still takes 100% CPU time -
very strange
2013-10-03 09:30:36 +02:00
0958b76bb0 cleanup conversion class 2013-10-02 13:52:44 +02:00
eaffe7ff91 Fixed compiler warnings 2013-10-02 13:49:29 +02:00
70cb7a8939 removed obsolete functionality
upgraded to java 1.7 and set project encoding to UTF-8
2013-10-02 13:30:50 +02:00
55 changed files with 1416 additions and 2092 deletions

View File

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

View File

@@ -0,0 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/test/java=UTF-8

View File

@@ -1,5 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.6
org.eclipse.jdt.core.compiler.source=1.7

View File

@@ -6,6 +6,23 @@
<version>1.1.40</version>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>ch.psi</groupId>
<artifactId>jcae</artifactId>
@@ -73,8 +90,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- Generate Javadoc Jar -->

View File

@@ -17,7 +17,7 @@
*
*/
package ch.psi.fda.aq;
package ch.psi.fda;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
@@ -27,6 +27,7 @@ import java.awt.event.WindowEvent;
import java.io.File;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -47,10 +48,13 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import sun.misc.Signal;
import sun.misc.SignalHandler;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.aq.Acquisition;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.gui.ProgressPanel;
import ch.psi.fda.gui.ScrollableFlowPanel;
import ch.psi.fda.install.ApplicationConfigurator;
@@ -60,10 +64,9 @@ import ch.psi.fda.model.v1.Data;
import ch.psi.fda.visualizer.Visualizer;
/**
* Main class for data acquisition
* @author ebner
*
* Entry class for command line based data acquisition
*/
@SuppressWarnings("restriction")
public class AcquisitionMain {
@@ -216,13 +219,7 @@ public class AcquisitionMain {
Configuration c;
try {
if(file.getName().endsWith(".xsl")){
c = ModelManager.unmarshall(file, variables);
}
else{
c = ModelManager.unmarshall(file);
}
c = ModelManager.unmarshall(file);
} catch (Exception e) {
throw new RuntimeException("Unable to deserialize configuration: "+e.getMessage(), e);
}
@@ -264,12 +261,17 @@ public class AcquisitionMain {
vis=true;
}
DataQueue vdq = acquisition.initalize(c, vis);
EventBus b = new AsyncEventBus(Executors.newSingleThreadExecutor());
DataMessageMetadata dmeta = acquisition.initalize(b, c, vis);
Visualizer visualizer = null;
// Only register data visualization task/processor if there are visualizations
if(vis){
visualizer = new Visualizer(vdq, c.getVisualization());
visualizer = new Visualizer(dmeta, c.getVisualization());
b.register(visualizer);
// If there is a continous dimension only update plot at the end of a line
if(c.getScan() != null && c.getScan().getCdimension()!=null){
visualizer.setUpdateAtStreamElement(false);
@@ -403,15 +405,15 @@ public class AcquisitionMain {
try {
if(visualizer != null){
// Start visualization
visualizer.startVisualization();
visualizer.configure();
}
acquisition.execute();
if(visualizer != null){
// Stop visualization
visualizer.stopVisualization();
}
// if(visualizer != null){
// // Stop visualization
// visualizer.stopVisualization();
// }
} catch (InterruptedException e1) {
throw new RuntimeException("Acquisition was interrupted",e1);

View File

@@ -17,7 +17,7 @@
*
*/
package ch.psi.fda.co;
package ch.psi.fda;
import java.io.File;
import java.io.PrintWriter;
@@ -33,6 +33,8 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.deserializer.DataDeserializer;
import ch.psi.fda.deserializer.DataDeserializerMDA;
import ch.psi.fda.deserializer.DataDeserializerTXT;
@@ -46,24 +48,17 @@ import ch.psi.fda.serializer.DataSerializerTXT2D;
import ch.psi.fda.serializer.DataSerializerTXTSplit;
/**
* Visualize data according to the scan description
*
* Converter to convert the format of datafiles
* @author ebner
*
*/
public class ConversionEngine {
public class ConversionMain {
// Get Logger
private static Logger logger = Logger.getLogger(ConversionEngine.class.getName());
private static Logger logger = Logger.getLogger(ConversionMain.class.getName());
public enum Writer {TXT, TXT_2D, TXT_SPLIT, MAT, MAT_2D, MDA, MAT_2D_Z};
public enum Reader {TXT, MDA};
/**
* Default constructor
*/
public ConversionEngine(){
}
/**
* Visualize data
@@ -89,14 +84,17 @@ public class ConversionEngine {
else if(output.exists()){
throw new IllegalArgumentException("Output file ["+output.getAbsolutePath()+"] already exists");
}
EventBus bus = new EventBus();
// Create deserializer
DataDeserializer deserializer;
if(reader.equals(Reader.TXT)){
deserializer = new DataDeserializerTXT(input);
deserializer = new DataDeserializerTXT(bus, input);
}
else if(reader.equals(Reader.MDA)){
deserializer = new DataDeserializerMDA(input);
deserializer = new DataDeserializerMDA(bus, input);
}
else{
throw new IllegalArgumentException("Reader of type "+reader+" not supported.");
@@ -104,39 +102,33 @@ public class ConversionEngine {
DataSerializer serializer;
if(writer.equals(Writer.MAT)){
serializer = new DataSerializerMAT(deserializer.getQueue(), output);
serializer = new DataSerializerMAT(deserializer.getMetadata(), output);
}
else if(writer.equals(Writer.MAT_2D)){
serializer = new DataSerializerMAT2D(deserializer.getQueue(), output);
serializer = new DataSerializerMAT2D(deserializer.getMetadata(), output);
}
else if(writer.equals(Writer.TXT)){
serializer = new DataSerializerTXT(deserializer.getQueue(), output, false);
serializer = new DataSerializerTXT(deserializer.getMetadata(), output, false);
}
else if(writer.equals(Writer.TXT_2D)){
serializer = new DataSerializerTXT2D(deserializer.getQueue(), output);
serializer = new DataSerializerTXT2D(deserializer.getMetadata(), output);
}
else if(writer.equals(Writer.TXT_SPLIT)){
serializer = new DataSerializerTXTSplit(deserializer.getQueue(), output);
serializer = new DataSerializerTXTSplit(deserializer.getMetadata(), output);
}
else if(writer.equals(Writer.MDA)){
serializer = new DataSerializerMDA(deserializer.getQueue(), output);
serializer = new DataSerializerMDA(deserializer.getMetadata(), output);
}
else if(writer.equals(Writer.MAT_2D_Z)){
serializer = new DataSerializerMAT2DZigZag(deserializer.getQueue(), output);
serializer = new DataSerializerMAT2DZigZag(deserializer.getMetadata(), output);
}
else{
throw new IllegalArgumentException("Writer of type "+writer+" not supported.");
}
// Start deserializer and serializer
Thread td = new Thread(deserializer);
Thread ts = new Thread(serializer);
td.start();
ts.start();
td.join();
ts.join();
// Start conversion
bus.register(serializer);
deserializer.read();
}
/**
@@ -243,7 +235,7 @@ public class ConversionEngine {
System.exit(-1);
}
ConversionEngine e = new ConversionEngine();
ConversionMain e = new ConversionMain();
try{
e.convert(infile, outfile, reader, writer);
}

View File

@@ -17,13 +17,14 @@
*
*/
package ch.psi.fda.vis;
package ch.psi.fda;
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.PrintWriter;
import java.util.concurrent.Executors;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -44,6 +45,9 @@ import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.xml.sax.SAXException;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.deserializer.DataDeserializer;
import ch.psi.fda.deserializer.DataDeserializerTXT;
import ch.psi.fda.gui.ScrollableFlowPanel;
@@ -57,15 +61,15 @@ import ch.psi.fda.visualizer.Visualizer;
* @author ebner
*
*/
public class VisualizationEngine {
public class VisualizationMain {
// Get Logger
private static Logger logger = Logger.getLogger(VisualizationEngine.class.getName());
private static Logger logger = Logger.getLogger(VisualizationMain.class.getName());
/**
* Default constructor
*/
public VisualizationEngine(){
public VisualizationMain(){
}
/**
@@ -112,13 +116,14 @@ public class VisualizationEngine {
throw new IllegalArgumentException("Data file ["+data.getAbsolutePath()+"] does not exist");
}
EventBus bus = new AsyncEventBus(Executors.newCachedThreadPool());
// Create deserializer
DataDeserializer deserializer = new DataDeserializerTXT(data);
DataDeserializer deserializer = new DataDeserializerTXT(bus, data);
// Create Visualizer
Visualizer visualizer = new Visualizer(deserializer.getQueue(), configuration.getVisualization());
Visualizer visualizer = new Visualizer(deserializer.getMetadata(), configuration.getVisualization());
visualizer.setTerminateAtEOS(true);
// visualizer.setTerminateAtEOS(true);
// Adapt default visualizer behavior to optimize performance for visualization
visualizer.setUpdateAtStreamElement(false);
visualizer.setUpdateAtStreamDelimiter(false);
@@ -155,12 +160,10 @@ public class VisualizationEngine {
// Start deserializer and visualizer
Thread td = new Thread(deserializer);
bus.register(visualizer);
visualizer.configure();
deserializer.read();
td.start();
visualizer.startVisualization();
td.join();
logger.info("Deserializer finished");
// visualizer.stopVisualization();
}
@@ -215,7 +218,7 @@ public class VisualizationEngine {
System.exit(-1);
}
VisualizationEngine e = new VisualizationEngine();
VisualizationMain e = new VisualizationMain();
try{
e.visualize(cfile, dfile);
}

View File

@@ -30,13 +30,16 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Executors;
import java.util.logging.FileHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import com.google.common.eventbus.AsyncEventBus;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.core.ActionLoop;
import ch.psi.fda.core.Actor;
import ch.psi.fda.core.EngineConfiguration;
@@ -54,8 +57,6 @@ import ch.psi.fda.core.actors.ComplexActuator;
import ch.psi.fda.core.actors.JythonFunction;
import ch.psi.fda.core.actors.OTFActuator;
import ch.psi.fda.core.actors.PseudoActuatorSensor;
import ch.psi.fda.core.collector.Collector;
import ch.psi.fda.core.collector.DataDispatcher;
import ch.psi.fda.core.guard.ChannelAccessGuard;
import ch.psi.fda.core.guard.ChannelAccessGuardCondition;
import ch.psi.fda.core.loops.ActorSensorLoop;
@@ -66,8 +67,7 @@ import ch.psi.fda.core.loops.cr.ScrlogicLoop;
import ch.psi.fda.core.manipulator.JythonManipulation;
import ch.psi.fda.core.manipulator.Manipulation;
import ch.psi.fda.core.manipulator.Manipulator;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.scripting.JythonGlobalVariable;
import ch.psi.fda.core.scripting.JythonGlobalVariableDictionary;
import ch.psi.fda.core.scripting.JythonParameterMapping;
@@ -128,14 +128,11 @@ import ch.psi.jcae.ChannelBeanFactory;
*/
public class Acquisition {
// Get Logger
private static Logger logger = Logger.getLogger(Acquisition.class.getName());
private AcquisitionEngineConfiguration configuration;
private AcquisitionConfiguration configuration;
private ActionLoop actionLoop;
private Collector collector;
private DataDispatcher dispatcher;
private Manipulator manipulator;
private DataSerializerTXT serializer;
@@ -146,19 +143,17 @@ public class Acquisition {
private Handler logHandler = null;
private Collector col;
/**
* Name of the datafile
*/
private File datafile;
// private Thread acquisitionThread = null;
public Acquisition(){
configuration = AcquisitionEngineConfiguration.getInstance();
configuration = AcquisitionConfiguration.getInstance();
actionLoop = null;
collector = new Collector();
manipulations = new ArrayList<Manipulation>();
}
@@ -180,7 +175,7 @@ public class Acquisition {
* @param getQueue Flag whether to return a queue or not. If false the return value of the function will be null.
* @throws InterruptedException
*/
public DataQueue initalize(Configuration smodel, boolean getQueue) {
public DataMessageMetadata initalize(EventBus bus, Configuration smodel, boolean getQueue) {
// Create notification agent with globally configured recipients
notificationAgent = new NotificationAgent(configuration.getSmptServer(), "fda.notification@psi.ch");
@@ -240,37 +235,42 @@ public class Acquisition {
logger.fine("Map Model to internal logic");
// Map scan to base model
// After this call actionLoop and collector will be initialized
mapScan(smodel);
logger.fine("ActionLoop and Collector initialized");
// TODO Remove this workaround
Collections.reverse(collector.getQueues());
// Add manipulator into processing chain
this.manipulator = new Manipulator(collector.getOutQueue(), this.manipulations);
// // Insert dispatcher into processing chain
this.dispatcher = new DataDispatcher(manipulator.getOutQueue());
DataQueue dq = new DataQueue(new LinkedBlockingQueue<Message>(1000), manipulator.getOutQueue().getDataMessageMetadata()); // Create bounded queue to
// prevent running out of
// memory ...
this.serializer = new DataSerializerTXT(dq, datafile, true);
DataQueue vdq = null;
if (getQueue) {
vdq = new DataQueue(new LinkedBlockingQueue<Message>(1000), manipulator.getOutQueue().getDataMessageMetadata()); // Create bounded queue to prevent
// running out of memory ...
dispatcher.getOutQueues().add(vdq);
DataMessageMetadata metadata;
if(smodel.getScan().getManipulation()!= null && smodel.getScan().getManipulation().size()>0){
// Setup optimized with manipulations
EventBus b = new AsyncEventBus(Executors.newCachedThreadPool());
// Map scan to base model
// After this call actionLoop and collector will be initialized
Collector collector = new Collector(b);
mapScan(collector, smodel);
col = collector;
logger.fine("ActionLoop and Collector initialized");
// Add manipulator into processing chain
this.manipulator = new Manipulator(bus, collector.getMetadata(), this.manipulations);
b.register(this.manipulator);
metadata = manipulator.getMetadata();
this.serializer = new DataSerializerTXT(metadata, datafile, true);
bus.register(serializer);
}
// Add queue for serializer to dispatcher
dispatcher.getOutQueues().add(dq);
return (vdq);
else{
// Setup optimized without manipulations
Collector collector = new Collector(bus);
mapScan(collector, smodel);
col = collector;
metadata = collector.getMetadata();
this.serializer = new DataSerializerTXT(metadata, datafile, true);
bus.register(serializer);
}
return (metadata);
}
/**
@@ -284,18 +284,9 @@ public class Acquisition {
try{
active = true;
Thread tc = new Thread(collector);
Thread tc = new Thread(col);
tc.start();
Thread tm = new Thread(manipulator);
tm.start();
Thread td = new Thread(dispatcher);
td.start();
Thread t = new Thread(serializer);
t.start();
actionLoop.prepare();
actionLoop.execute();
actionLoop.cleanup();
@@ -305,9 +296,6 @@ public class Acquisition {
// Give the threads 1 minute to catch up
tc.join(60000);
tm.join(60000);
td.join(60000);
t.join(60000);
// Send notifications out to all recipients that want to have success notifications
try {
@@ -316,8 +304,6 @@ public class Acquisition {
} catch (UnknownHostException e1) {
logger.log(Level.WARNING, "Unable to send notification", e1);
}
// active = false;
}
catch(RuntimeException e){
logger.log(Level.WARNING, "Execution failed: ", e);
@@ -426,7 +412,7 @@ public class Acquisition {
* Map scan to base model
* @param scan
*/
private void mapScan(Configuration configuration){
private void mapScan(Collector collector, Configuration configuration){
Scan scan = configuration.getScan();
// Map continuous dimension
@@ -519,6 +505,10 @@ public class Acquisition {
this.manipulations.add(manipulation);
}
}
// TODO Remove this workaround
// Revert queues to match sequence
Collections.reverse(collector.getQueues());
}
/**
@@ -582,7 +572,7 @@ public class Acquisition {
timeout = Math.round(ca.getTimeout()*1000);
}
if(type.equals("String")){
alist.add(new ChannelAccessConditionRegex<String>(ca.getChannel(), ca.getValue(), timeout));
alist.add(new ChannelAccessConditionRegex(ca.getChannel(), ca.getValue(), timeout));
}
else{
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
@@ -595,7 +585,7 @@ public class Acquisition {
}
if(type.equals("Integer")){
alist.add(new ChannelAccessConditionOr<Integer>(ca.getChannel(), new Integer(ca.getValue()), timeout));
alist.add(new ChannelAccessConditionOr(ca.getChannel(), new Integer(ca.getValue()), timeout));
}
else{
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
@@ -607,7 +597,7 @@ public class Acquisition {
timeout = Math.round(ca.getTimeout()*1000);
}
if(type.equals("Integer")){
alist.add(new ChannelAccessConditionAnd<Integer>(ca.getChannel(), new Integer(ca.getValue()), timeout));
alist.add(new ChannelAccessConditionAnd(ca.getChannel(), new Integer(ca.getValue()), timeout));
}
else {
logger.warning("Operation "+operation+" wity type "+type+" for action is not supported");
@@ -679,7 +669,7 @@ public class Acquisition {
// Mapping dimension pre-actions
aLoop.getPreActions().addAll(mapActions(dimension.getPreAction()));
Long moveTimeout = AcquisitionEngineConfiguration.getInstance().getActorMoveTimeout();
Long moveTimeout = AcquisitionConfiguration.getInstance().getActorMoveTimeout();
// Mapping positioners
Double stime = 0d;

View File

@@ -35,11 +35,11 @@ import ch.psi.fda.install.ApplicationConfigurator;
* @author ebner
*
*/
public class AcquisitionEngineConfiguration {
public class AcquisitionConfiguration {
private static final Logger logger = Logger.getLogger(AcquisitionEngineConfiguration.class.getName());
private static final AcquisitionEngineConfiguration instance = new AcquisitionEngineConfiguration();
private static final Logger logger = Logger.getLogger(AcquisitionConfiguration.class.getName());
private static final AcquisitionConfiguration instance = new AcquisitionConfiguration();
private String otfChannelPrefix;
private String otfNfsServer;
@@ -74,7 +74,7 @@ public class AcquisitionEngineConfiguration {
* Default Constructor
* The constructor will read the configuration from the /fda.properties file (resource) located in the classpath.
*/
private AcquisitionEngineConfiguration(){
private AcquisitionConfiguration(){
loadConfiguration();
}
@@ -82,7 +82,7 @@ public class AcquisitionEngineConfiguration {
* Get instance of this configuration
* @return configuration
*/
public static AcquisitionEngineConfiguration getInstance(){
public static AcquisitionConfiguration getInstance(){
return(instance);
}
@@ -108,14 +108,14 @@ public class AcquisitionEngineConfiguration {
}
// The defaults are set here
otfChannelPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.channelPrefix", "");
otfScalerPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.scalerPrefix", "");
otfNfsServer = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.nfsServer", "");
otfNfsShare = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.nfsShare", "");
otfSmbShare = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.smbShare", "");
otfUseCrlogic = new Boolean(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.useCrlogic", "false"));
otfCrlogicPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.crlogicPrefix", "");
otfCrlogicKeepTmpFiles = new Boolean(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.crlogicKeepTmpFiles", "false"));
otfChannelPrefix = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.channelPrefix", "");
otfScalerPrefix = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.scalerPrefix", "");
otfNfsServer = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.nfsServer", "");
otfNfsShare = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.nfsShare", "");
otfSmbShare = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.smbShare", "");
otfUseCrlogic = new Boolean(properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.useCrlogic", "false"));
otfCrlogicPrefix = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.crlogicPrefix", "");
otfCrlogicKeepTmpFiles = new Boolean(properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".otf.crlogicKeepTmpFiles", "false"));
// Workaround
// dataBaseDirectory = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".data.baseDirectory", ".");
@@ -126,11 +126,11 @@ public class AcquisitionEngineConfiguration {
dataBaseDirectory = "./data";
}
dataFilePrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".data.filePrefix","");
dataFilePrefix = properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".data.filePrefix","");
actorMoveTimeout = new Long(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".actorMoveTimeout","600000"));
actorMoveTimeout = new Long(properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".actorMoveTimeout","600000"));
smptServer= properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".notification.host","mail.psi.ch");
smptServer= properties.getProperty(AcquisitionConfiguration.class.getPackage().getName()+".notification.host","mail.psi.ch");
}

View File

@@ -0,0 +1,18 @@
package ch.psi.fda.aq;
import gov.aps.jca.CAException;
import ch.psi.jcae.ChannelBeanFactory;
import com.google.inject.AbstractModule;
public class AcquisitionModule extends AbstractModule {
@Override
protected void configure() {
try {
bind(ChannelBeanFactory.class).toInstance(ChannelBeanFactory.getFactory());
} catch (CAException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -17,14 +17,15 @@
*
*/
package ch.psi.fda.core.collector;
package ch.psi.fda.aq;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
@@ -53,14 +54,14 @@ public class Collector implements Runnable{
/**
* Outgoing queue of this collector
*/
private BlockingQueue<Message> outQueue;
private EventBus bus;
/**
* Constructor
*/
public Collector(){
public Collector(EventBus b){
queues = new ArrayList<DataQueue>();
outQueue = new LinkedBlockingQueue<Message>(1000); // Create bounded queue to prevent running out of memory ...
this.bus = b;
}
/* (non-Javadoc)
@@ -81,14 +82,8 @@ public class Collector implements Runnable{
// No queue registered for reading
}
try {
bus.post(new EndOfStreamMessage());
outQueue.put(new EndOfStreamMessage());
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Unable to terminate stream with and End of Stream Message",e);
}
logger.info("END");
@@ -115,7 +110,7 @@ public class Collector implements Runnable{
}
else{
// Write message to outgoing queue
outQueue.put(dm);
bus.post(dm);
}
// Read next message
@@ -126,7 +121,7 @@ public class Collector implements Runnable{
// Translate EndOfStream to StreamDelimiter message
StreamDelimiterMessage ddm = new StreamDelimiterMessage(queues.size()-1-index, ((EndOfStreamMessage)message).isIflag());
// Write message to outgoing queue
outQueue.put(ddm);
bus.post(ddm);
}
}
@@ -140,14 +135,10 @@ public class Collector implements Runnable{
/**
* Get the outgoing data queue.
* Attention, only call this method after all ingoing queues were registered! Otherwise the data returned
* by this method is not accurate.
* @return output queue of collector
* Get the outgoing data metadata
*/
public DataQueue getOutQueue(){
public DataMessageMetadata getMetadata(){
DataMessageMetadata dataMessageMetadata = new DataMessageMetadata();
dataMessageMetadata.getComponents();
// Generate new combined metadata and add dimension information to the components
int nq = queues.size();
@@ -158,8 +149,7 @@ public class Collector implements Runnable{
dataMessageMetadata.getComponents().add(new ComponentMetadata(cm.getId(), nq-i-1));
}
}
return(new DataQueue(outQueue, dataMessageMetadata));
return(dataMessageMetadata);
}
}

View File

@@ -28,12 +28,13 @@ import ch.psi.jcae.ChannelBean;
import ch.psi.jcae.ChannelBeanFactory;
/**
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
* asynchronously.
* Condition a channnel needs to match
* Only accepts channels of type Integer
*
* @author ebner
*
*/
public class ChannelAccessConditionAnd<E extends Integer> implements Action {
public class ChannelAccessConditionAnd implements Action {
// Get Logger
private static Logger logger = Logger.getLogger(ChannelAccessConditionAnd.class.getName());
@@ -41,11 +42,11 @@ public class ChannelAccessConditionAnd<E extends Integer> implements Action {
/**
* Channel to set
*/
private final ChannelBean<E> channel;
private final ChannelBean<Integer> channel;
/**
* Value to wait for
*/
private final E expectedValue;
private final Integer expectedValue;
private final Long timeout;
@@ -62,14 +63,14 @@ public class ChannelAccessConditionAnd<E extends Integer> implements Action {
* Timeout specified is not >=0
*/
@SuppressWarnings("unchecked")
public ChannelAccessConditionAnd(String channelName, E expectedValue, Long timeout){
public ChannelAccessConditionAnd(String channelName, Integer expectedValue, Long timeout){
if(timeout !=null && timeout<=0){
throw new IllegalArgumentException("Timeout must be > 0");
}
try {
this.channel = (ChannelBean<E>) ChannelBeanFactory.getFactory().createChannelBean( (Class<E>) expectedValue.getClass(), channelName, false);
this.channel = (ChannelBean<Integer>) ChannelBeanFactory.getFactory().createChannelBean( (Class<Integer>) expectedValue.getClass(), channelName, false);
} catch (CAException e) {
// Convert Exception into unchecked RuntimeException
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
@@ -101,10 +102,10 @@ public class ChannelAccessConditionAnd<E extends Integer> implements Action {
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
try{
waitT = Thread.currentThread();
channel.waitForValue(expectedValue, new Comparator<E>() {
channel.waitForValue(expectedValue, new Comparator<Integer>() {
@Override
public int compare(E o1, E o2) {
public int compare(Integer o1, Integer o2) {
int one = o1;
int two = o2;
if((one & two) != 0){

View File

@@ -28,12 +28,13 @@ import ch.psi.jcae.ChannelBean;
import ch.psi.jcae.ChannelBeanFactory;
/**
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
* asynchronously.
* Or condition of a channel
* Only supports Integer values and channel
*
* @author ebner
*
*/
public class ChannelAccessConditionOr<E extends Integer> implements Action {
public class ChannelAccessConditionOr implements Action {
// Get Logger
private static Logger logger = Logger.getLogger(ChannelAccessConditionOr.class.getName());
@@ -41,11 +42,11 @@ public class ChannelAccessConditionOr<E extends Integer> implements Action {
/**
* Channel to set
*/
private final ChannelBean<E> channel;
private final ChannelBean<Integer> channel;
/**
* Value to wait for
*/
private final E expectedValue;
private final Integer expectedValue;
private final Long timeout;
@@ -62,14 +63,14 @@ public class ChannelAccessConditionOr<E extends Integer> implements Action {
* Timeout specified is not >=0
*/
@SuppressWarnings("unchecked")
public ChannelAccessConditionOr(String channelName, E expectedValue, Long timeout){
public ChannelAccessConditionOr(String channelName, Integer expectedValue, Long timeout){
if(timeout !=null && timeout<=0){
throw new IllegalArgumentException("Timeout must be > 0");
}
try {
this.channel = (ChannelBean<E>) ChannelBeanFactory.getFactory().createChannelBean( (Class<E>) expectedValue.getClass(), channelName, false);
this.channel = (ChannelBean<Integer>) ChannelBeanFactory.getFactory().createChannelBean( (Class<Integer>) expectedValue.getClass(), channelName, false);
} catch (CAException e) {
// Convert Exception into unchecked RuntimeException
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
@@ -101,10 +102,10 @@ public class ChannelAccessConditionOr<E extends Integer> implements Action {
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
try{
waitT = Thread.currentThread();
channel.waitForValue(expectedValue, new Comparator<E>() {
channel.waitForValue(expectedValue, new Comparator<Integer>() {
@Override
public int compare(E o1, E o2) {
public int compare(Integer o1, Integer o2) {
int one = o1;
int two = o2;
if((one | two) != 0){

View File

@@ -28,12 +28,12 @@ import ch.psi.jcae.ChannelBean;
import ch.psi.jcae.ChannelBeanFactory;
/**
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
* asynchronously.
* Regex condition
* Only supports String value/channel.
* @author ebner
*
*/
public class ChannelAccessConditionRegex<E extends String> implements Action {
public class ChannelAccessConditionRegex implements Action {
// Get Logger
private static Logger logger = Logger.getLogger(ChannelAccessConditionRegex.class.getName());
@@ -41,11 +41,11 @@ public class ChannelAccessConditionRegex<E extends String> implements Action {
/**
* Channel to set
*/
private final ChannelBean<E> channel;
private final ChannelBean<String> channel;
/**
* Value to wait for
*/
private final E expectedValue;
private final String expectedValue;
private final Long timeout;
@@ -62,14 +62,14 @@ public class ChannelAccessConditionRegex<E extends String> implements Action {
* Timeout specified is not >=0
*/
@SuppressWarnings("unchecked")
public ChannelAccessConditionRegex(String channelName, E expectedValue, Long timeout){
public ChannelAccessConditionRegex(String channelName, String expectedValue, Long timeout){
if(timeout !=null && timeout<=0){
throw new IllegalArgumentException("Timeout must be > 0");
}
try {
this.channel = (ChannelBean<E>) ChannelBeanFactory.getFactory().createChannelBean( (Class<E>) expectedValue.getClass(), channelName, false);
this.channel = (ChannelBean<String>) ChannelBeanFactory.getFactory().createChannelBean( (Class<String>) expectedValue.getClass(), channelName, false);
} catch (CAException e) {
// Convert Exception into unchecked RuntimeException
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
@@ -101,10 +101,10 @@ public class ChannelAccessConditionRegex<E extends String> implements Action {
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
try{
waitT = Thread.currentThread();
channel.waitForValue(expectedValue, new Comparator<E>() {
channel.waitForValue(expectedValue, new Comparator<String>() {
@Override
public int compare(E o1, E o2) {
public int compare(String o1, String o2) {
return o1.matches(o2) ? 0:1;
}
}, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value

View File

@@ -28,14 +28,10 @@ import ch.psi.fda.core.Action;
*/
public class Delay implements Action {
/**
* Time to wait
*/
private final long time;
/**
* Constructor
* @param time Time to wait (in milliseconds)
* @param time Time to wait in milliseconds
*/
public Delay(long time){
@@ -47,28 +43,17 @@ public class Delay implements Action {
this.time = time;
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#execute()
*/
@Override
public void execute() throws InterruptedException {
Thread.sleep(time);
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#abort()
*/
@Override
public void abort() {
// Not implemented because not needed
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#destroy()
*/
@Override
public void destroy() {
// Nothing to be done
}
}

View File

@@ -44,7 +44,6 @@ import ch.psi.jcae.ChannelBeanFactory;
*/
public class JythonAction implements Action {
// Get Logger
private static Logger logger = Logger.getLogger(JythonAction.class.getName());
/**
@@ -167,21 +166,13 @@ public class JythonAction implements Action {
}
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#abort()
*/
@Override
public void abort() {
// TODO need to find a way to abort script execution
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#destroy()
*/
@Override
public void destroy() {
// Nothing to be done
}
/**

View File

@@ -121,9 +121,6 @@ public class ShellAction implements Action{
}
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#abort()
*/
@Override
public void abort() {
abort=true;
@@ -134,14 +131,8 @@ public class ShellAction implements Action{
}
}
/* (non-Javadoc)
* @see ch.psi.fda.core.Action#destroy()
*/
@Override
public void destroy() {
// Nothing to be done
}
/**

View File

@@ -1,88 +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.collector;
import java.util.ArrayList;
import java.util.List;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
* Serialize data received by a DataQueue
* @author ebner
*
*/
public class DataDispatcher implements Runnable{
private DataQueue queue;
private List<DataQueue> outQueues;
public DataDispatcher(DataQueue queue){
this.queue = queue;
this.outQueues = new ArrayList<DataQueue>();
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try{
// TODO Need to synchronize message metadata
// for(DataQueue q: outQueues){
// }
// Dispatch Messages
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
// Clone message ...
for(DataQueue q: outQueues){
q.getQueue().put(message);
}
// Read next message
message = queue.getQueue().take();
}
// Write end of stream message
for(DataQueue q: outQueues){
q.getQueue().put(message);
}
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
}
}
/**
* @return the outQueues
*/
public List<DataQueue> getOutQueues() {
return outQueues;
}
}

View File

@@ -20,104 +20,55 @@
package ch.psi.fda.core.manipulator;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
* @author ebner
*
* Applies manipulations to the data stream
*/
public class Manipulator implements Runnable{
public class Manipulator {
/**
* Outgoing data queue
*/
private final DataQueue outQueue;
private EventBus bus;
private DataMessageMetadata metadata;
/**
* Incomming data queue
*/
private final DataQueue queue;
/**
* List of manipulations
*/
private final List<Manipulation> manipulations;
/**
* Constructor
* @param queue
* @param manipulations
*/
// TODO need to support multiple (a list of) manipulation(s)
public Manipulator(DataQueue queue, List<Manipulation> manipulations){
public Manipulator(EventBus b, DataMessageMetadata meta, List<Manipulation> manipulations){
this.bus = b;
this.manipulations = manipulations;
// Create outgoing data metadata
DataMessageMetadata dmetadata = queue.getDataMessageMetadata().clone();
this.metadata = meta.clone();
// Initialize manipulations and create outgoing metadata
for(Manipulation manipulation: this.manipulations){
// Initialize manipulation
// manipulation.initialize(queue.getDataMessageMetadata());
manipulation.initialize(dmetadata);
manipulation.initialize(this.metadata);
// Add manipulation id to metadata
dmetadata.getComponents().add(new ComponentMetadata(manipulation.getId(),0)); // Calculated component always belongs to lowes dimension
this.metadata.getComponents().add(new ComponentMetadata(manipulation.getId(),0)); // Calculated component always belongs to lowes dimension
}
this.queue = queue;
this.outQueue = new DataQueue(new LinkedBlockingQueue<Message>(1000) , dmetadata ); // Create bounded queue to prevent running out of memory ...
}
/**
* @return the outQueue
*/
public DataQueue getOutQueue() {
return outQueue;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try{
@Subscribe
public void onMessage(Message message){
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
// Dispatch Messages
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
for(Manipulation manipulation: manipulations){
dm.getData().add(manipulation.execute(dm));
}
}
// Put message to outgoing queue ...
outQueue.getQueue().put(message);
// Read next message
message = queue.getQueue().take();
for(Manipulation manipulation: manipulations){
dm.getData().add(manipulation.execute(dm));
}
// Write end of stream message
outQueue.getQueue().put(message);
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data manipulator was interrupted while writing data to file",e);
}
bus.post(message);
}
public DataMessageMetadata getMetadata() {
return metadata;
}
}

View File

@@ -19,6 +19,8 @@
package ch.psi.fda.core.messages;
import java.io.Serializable;
/**
* Metadata of a component of a message. Each component has a global id.
* Optionally the component can also belong to a dimension. However, depending on the
@@ -28,7 +30,10 @@ package ch.psi.fda.core.messages;
* @author ebner
*
*/
public class ComponentMetadata {
public class ComponentMetadata implements Serializable{
private static final long serialVersionUID = 1L;
/**
* Global id of the component
*/

View File

@@ -19,11 +19,13 @@
package ch.psi.fda.core.messages;
/**
* A control message that is not holding any data but
* control information (like end of loop, etc.)
* @author ebner
*
*/
public abstract class ControlMessage extends Message {
public abstract class ControlMessage extends Message{
private static final long serialVersionUID = 1L;
}

View File

@@ -27,7 +27,9 @@ import java.util.List;
* @author ebner
*
*/
public class DataMessage extends Message {
public class DataMessage extends Message{
private static final long serialVersionUID = 1L;
/**
* Data payload of the message

View File

@@ -19,6 +19,7 @@
package ch.psi.fda.core.messages;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@@ -27,8 +28,9 @@ import java.util.List;
* @author ebner
*
*/
public class DataMessageMetadata {
public class DataMessageMetadata implements Serializable {
private static final long serialVersionUID = 1L;
/**
* List of the metadata of the message components
*/

View File

@@ -25,8 +25,9 @@ package ch.psi.fda.core.messages;
* @author ebner
*
*/
public class EndOfStreamMessage extends ControlMessage{
public class EndOfStreamMessage extends ControlMessage {
private static final long serialVersionUID = 1L;
/**
* Intersect flag - flag to indicate that stream should be intersected

View File

@@ -19,10 +19,13 @@
package ch.psi.fda.core.messages;
import java.io.Serializable;
/**
* Message that can be put to the data queue
* @author ebner
*
*/
public abstract class Message {
public abstract class Message implements Serializable{
private static final long serialVersionUID = 1L;
}

View File

@@ -25,7 +25,7 @@ package ch.psi.fda.core.messages;
*
*/
public class StreamDelimiterMessage extends ControlMessage{
private static final long serialVersionUID = 1L;
/**
* Number of the dimension this delimiter belongs to.
*/

View File

@@ -19,18 +19,20 @@
package ch.psi.fda.deserializer;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
/**
* Data deserializer
* @author ebner
*
*/
public interface DataDeserializer extends Runnable {
public interface DataDeserializer {
/**
* Get data queue of deserializer
* @return data queue of deserializer
* Get message metadata
* @return metadata/information of the message format
*/
public DataQueue getQueue();
public DataMessageMetadata getMetadata();
public void read();
}

View File

@@ -9,45 +9,45 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
/**
* TODO Need to be optimized as currently the while file is read into memory when creating this object.
* @author ebner
*
*/
public class DataDeserializerMDA implements DataDeserializer {
private static Logger logger = Logger.getLogger(DataDeserializerMDA.class.getName());
private DataQueue queue;
private EventBus bus;
private DataMessageMetadata metadata;
private RecursiveReturnContainer c;
public DataDeserializerMDA(File file){
public DataDeserializerMDA(EventBus b, File file){
this.bus = b;
try {
RecursiveReturnContainer c = read(new FileInputStream(file));
this.queue = new DataQueue(new LinkedBlockingQueue<Message>(), c.getMetadata());
// Add data to queue
for(Message m: c.getMessage()){
queue.getQueue().put(m);
}
queue.getQueue().put(new EndOfStreamMessage());
try{
c = read(new FileInputStream(file));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
this.metadata = c.getMetadata();
}
public RecursiveReturnContainer read(InputStream in) throws IOException {
private RecursiveReturnContainer read(InputStream in) throws IOException {
logger.fine("Read MDA input stream");
XDRInputStream x = new XDRInputStream(in);
@@ -443,21 +443,18 @@ public class DataDeserializerMDA implements DataDeserializer {
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
// TODO Auto-generated method stub
public void read() {
// Add data to queue
for(Message m: c.getMessage()){
bus.post(m);
}
bus.post(new EndOfStreamMessage());
}
/* (non-Javadoc)
* @see ch.psi.fda.deserializer.DataDeserializer#getQueue()
*/
@Override
public DataQueue getQueue() {
return queue;
public DataMessageMetadata getMetadata() {
return metadata;
}
}

View File

@@ -25,16 +25,15 @@ import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
* Deserialize file data and put it into the DataQueue
@@ -43,10 +42,10 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataDeserializerTXT implements DataDeserializer {
// Get Logger
private static Logger logger = Logger.getLogger(DataDeserializerTXT.class.getName());
private DataQueue queue;
private EventBus bus;
private DataMessageMetadata metadata;
private File file;
private List<Integer> dindex;
@@ -56,12 +55,12 @@ public class DataDeserializerTXT implements DataDeserializer {
* Default Constructor
* @param file
*/
public DataDeserializerTXT(File file){
public DataDeserializerTXT(EventBus b, File file){
this.bus = b;
this.file = file;
this.dindex = new ArrayList<Integer>();
this.iindex = new ArrayList<Integer>();
DataMessageMetadata metadata;
try{
// Read metadata
// Open file
@@ -103,23 +102,15 @@ public class DataDeserializerTXT implements DataDeserializer {
catch(Exception e){
throw new RuntimeException("Unable to read file metadata and initialize data queue",e);
}
this.queue = new DataQueue(new LinkedBlockingQueue<Message>(10000000), metadata);
}
/* (non-Javadoc)
* @see ch.psi.fda.deserializer.DataDeserializer#getQueue()
*/
@Override
public DataQueue getQueue(){
return(queue);
public DataMessageMetadata getMetadata(){
return(metadata);
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
public void read() {
try{
List<Double> checklist = new ArrayList<Double>(dindex.size());
@@ -195,14 +186,14 @@ public class DataDeserializerTXT implements DataDeserializer {
// }
if(checklist.get(i)!=null &&!checklist.get(i).equals(d)){
// If value changes issue a dimension delimiter message
queue.getQueue().put(new StreamDelimiterMessage(dindex.get(t)-1));
bus.post(new StreamDelimiterMessage(dindex.get(t)-1));
}
checklist.set(i, d);
}
}
// Put message to queue
queue.getQueue().put(message);
bus.post(message);
// TODO Need to detect dimension boundaries
@@ -210,20 +201,17 @@ public class DataDeserializerTXT implements DataDeserializer {
// Add delimiter for all the dimensions
for(int i=dindex.size()-1;i>=0;i--){
queue.getQueue().put(new StreamDelimiterMessage(dindex.get(i)));
bus.post(new StreamDelimiterMessage(dindex.get(i)));
}
// queue.getQueue().put(new DimensionDelimiterMessage(dindex.get(0)-1));
// queue.getQueue().put(new DimensionDelimiterMessage(dindex.get(0)));
// Place end of stream message
queue.getQueue().put(new EndOfStreamMessage());
bus.post(new EndOfStreamMessage());
// Close file
reader.close();
} catch (InterruptedException e) {
throw new RuntimeException("Data deserializer was interrupted while reading the datafile",e);
} catch (IOException e) {
throw new RuntimeException("Data deserializer had a problem reading the specified datafile",e);
}

View File

@@ -19,11 +19,7 @@
package ch.psi.fda.model;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
@@ -32,13 +28,7 @@ import javax.xml.bind.Marshaller;
import javax.xml.bind.UnmarshalException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
@@ -47,95 +37,18 @@ 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
* Manage the serialization and deserialization of the FDA data model
* @author ebner
*
*/
public class ModelManager {
/**
* Deserialize an instance of a data model of the type Configuration
* Before creating the object model variables will be replaced
* De-serialize an instance of the FDA data model
*
* @param file Scan file
* @param variables Scan variables
* @throws JAXBException Something went wrong while unmarshalling
* @throws SAXException Cannot read model schema file
* @throws ParserConfigurationException
* @throws IOException
* @throws TransformerFactoryConfigurationError
* @throws TransformerException
*/
public static Configuration unmarshall(File file, HashMap<String, String> variables) throws JAXBException, SAXException, IOException,
ParserConfigurationException, TransformerFactoryConfigurationError, TransformerException {
// Load template file
Transformer xformer = TransformerFactory.newInstance().newTransformer(new StreamSource(file));
// Overwrite parameters
for(String key: variables.keySet()){
xformer.setParameter(key, variables.get(key));
}
// Workaround for complex parameters (parameter including xml fragments)
// How the workaround works:
// Because we want to set complex parameters we first have to apply the xslt transformation to the input
// stream and create an other output stream. In the template file the complex parameter must be referenced as follows
// <xsl:value-of select="$var.regions" disable-output-escaping="yes" />
// If it is not done this way the < and > of the tags will be replaced by &lt; and &gt;
// Also if we directly transform to a DOMResult the dom tree would not include the
// nodes added by the parameter but just a text object. Therefor we do the workaround via the StreamResult ...
ByteArrayOutputStream bstream = new ByteArrayOutputStream();
StreamResult sresult = new StreamResult(bstream);
// Perform transformation (using template file also as input source)
xformer.transform(new StreamSource(file), sresult );
// Workaround for complex parameters
ByteArrayInputStream bistream = new ByteArrayInputStream(bstream.toByteArray());
StreamSource bsource = new StreamSource(bistream);
JAXBContext context = JAXBContext.newInstance(Configuration.class);
Unmarshaller u = context.createUnmarshaller();
// Validation
SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
Source s = new StreamSource(Configuration.class.getResourceAsStream("/model-v1.xsd"));
Schema schema = sf.newSchema(new Source[]{s}); // Use schema reference provided in XML
u.setSchema(schema);
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){
// Check
if(e.getLinkedException() instanceof SAXParseException){
throw new RuntimeException("Configuration file does not comply to required model specification\nCause: "+e.getLinkedException().getMessage(), e);
}
throw e;
}
}
/**
* Deserialize an instance of a data model of the type Configuration
* @param file
* @param file File to deserialize
* @throws JAXBException Something went wrong while unmarshalling
* @throws SAXException Cannot read model schema file
*/
@@ -152,15 +65,6 @@ 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,7 +77,8 @@ public class ModelManager {
}
/**
* Serialize an instance of a data model of the type Configuration
* Serialize an instance of the FDA data model
*
* @param model Model datastructure
* @param file File to write the model data into
* @throws JAXBException Something went wrong while marshalling model
@@ -192,14 +97,6 @@ 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

@@ -32,8 +32,7 @@ import javax.mail.internet.MimeMessage;
import ch.psi.fda.model.v1.Recipient;
/**
* This is a copy of the NotificationAgent class that should go into the foundation classes
* This actually should be extracted to an own project
* Agent to send out notifications to specified recipients.
* @author ebner
*/
public class NotificationAgent {

View File

@@ -20,9 +20,7 @@
package ch.psi.fda.serializer;
/**
* Data Serializer
* @author ebner
*
* Data Serializer marker interface
*/
public interface DataSerializer extends Runnable {
public interface DataSerializer {
}

View File

@@ -24,13 +24,14 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.common.eventbus.Subscribe;
import com.jmatio.io.MatFileWriter;
import com.jmatio.types.MLArray;
import com.jmatio.types.MLDouble;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
@@ -41,120 +42,109 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataSerializerMAT implements DataSerializer{
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
private boolean appendSuffix = false;
private boolean first = true;
/**
* Construtor
* @param queue Data queue holding the data to serialize
* @param file Name of the Matlab file to serialize the data to
*/
public DataSerializerMAT(DataQueue queue, File file){
this.queue = queue;
public DataSerializerMAT(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try{
// WORKAROUND BEGIN
File outfile;
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
fname = fname.replaceAll("\\."+extension+"$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
}
}
else{
outfile = this.file;
}
// WORKAROUND END
File outfile;
List<List<Object>> dlist;
List<Class<?>> clist;
boolean firstF;
@Subscribe
public void onMessage(Message message) {
try {
// Transposed data list
List<List<Object>> dlist = new ArrayList<List<Object>>();
List<Class<?>> clist = new ArrayList<Class<?>>();
boolean firstF = true;
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage m = (DataMessage) message;
// Initialize list
if(firstF){
for(Object o: m.getData()){
dlist.add(new ArrayList<Object>());
clist.add(o.getClass());
}
firstF=false;
if (first) {
first = false;
// WORKAROUND BEGIN
if (appendSuffix) {
// Append a count suffix to the file. If there is already a
// file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine
// file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine
// extension
fname = fname.replaceAll("\\." + extension + "$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while (outfile.exists()) {
cnt++;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
}
// Put data into data list
for(int i=0;i< m.getData().size();i++){
Object object = m.getData().get(i);
dlist.get(i).add(object);
} else {
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
dlist = new ArrayList<List<Object>>();
clist = new ArrayList<Class<?>>();
firstF = true;
}
if (message instanceof DataMessage) {
DataMessage m = (DataMessage) message;
// Initialize list
if (firstF) {
for (Object o : m.getData()) {
dlist.add(new ArrayList<Object>());
clist.add(o.getClass());
}
firstF = false;
}
// Read next message
message = queue.getQueue().take();
// Put data into data list
for (int i = 0; i < m.getData().size(); i++) {
Object object = m.getData().get(i);
dlist.get(i).add(object);
}
} else if (message instanceof EndOfStreamMessage) {
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
for (int t = 0; t < dlist.size(); t++) {
// Get component metadata
ComponentMetadata c = metadata.getComponents().get(t);
c.getId();
List<Object> list = dlist.get(t);
if (clist.get(t).isArray()) {
// Array Handling
} else if (clist.get(t).equals(Double.class)) {
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()), (Double[]) list.toArray(new Double[list.size()]), 1);
matlablist.add(darray);
}
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
}
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = queue.getDataMessageMetadata().getComponents().get(t);
c.getId();
List<Object> list = dlist.get(t);
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()),(Double[])list.toArray(new Double[list.size()]),1);
matlablist.add(darray);
}
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
throw new RuntimeException("Data serializer had a problem writing to the specified file", e);
}
}
/**

View File

@@ -25,13 +25,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import com.google.common.eventbus.Subscribe;
import com.jmatio.io.MatFileWriter;
import com.jmatio.types.MLArray;
import com.jmatio.types.MLDouble;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
@@ -43,25 +44,34 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataSerializerMAT2D implements DataSerializer{
// Get Logger
private static final Logger logger = Logger.getLogger(DataSerializerMAT2D.class.getName());
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
private boolean appendSuffix = false;
private boolean first = true;
private List<List<List<Object>>> dlist;
private List<Class<?>> clist;
private int dsize;
private int dcount;
private Integer mindsize;
private boolean firstF;
private File outfile;
/**
* Construtor
* @param queue Data queue holding the data to serialize
* @param file Name of the Matlab file to serialize the data to
*/
public DataSerializerMAT2D(DataQueue queue, File file){
this.queue = queue;
public DataSerializerMAT2D(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
// Check if input queue does only hold 2D data
int maxdim=0;
for(ComponentMetadata m: queue.getDataMessageMetadata().getComponents()){
for(ComponentMetadata m: metadata.getComponents()){
if(m.getDimension()>maxdim){
maxdim=m.getDimension();
}
@@ -76,49 +86,42 @@ public class DataSerializerMAT2D implements DataSerializer{
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
@Subscribe
public void onMessage(Message message) {
try{
// WORKAROUND BEGIN
File outfile;
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
fname = fname.replaceAll("\\."+extension+"$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
if(first){
first=false;
// WORKAROUND BEGIN
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
fname = fname.replaceAll("\\."+extension+"$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
}
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
dlist = new ArrayList<List<List<Object>>>();
clist = new ArrayList<Class<?>>();
dsize = 0; // Size of the dimension
dcount = 0;
mindsize = null;
firstF = true;
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
List<List<List<Object>>> dlist = new ArrayList<List<List<Object>>>();
List<Class<?>> clist = new ArrayList<Class<?>>();
int dsize = 0; // Size of the dimension
int dcount = 0;
Integer mindsize = null;
boolean firstF = true;
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage m = (DataMessage) message;
@@ -170,62 +173,55 @@ public class DataSerializerMAT2D implements DataSerializer{
}
}
// Read next message
message = queue.getQueue().take();
}
logger.info("dsize: "+dsize + " mindsize:"+mindsize);
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
logger.info("dlist size: "+dlist.size());
for(int t=0; t<dlist.size(); t++ ){
else if(message instanceof EndOfStreamMessage){
logger.info("dsize: "+dsize + " mindsize:"+mindsize);
// Get component metadata
ComponentMetadata c = queue.getDataMessageMetadata().getComponents().get(t);
// Combine all lists to one big list (pad if there are data points missing)
List<Object> list = new ArrayList<Object>();
List<List<Object>> ol = dlist.get(t);
// Remove last array list as it is empty
ol.remove(ol.size()-1);
for(List<Object> li: ol){
list.addAll(li);
// Pad list if there are missing data points for some lines
for(int i=li.size();i<dsize;i++){
logger.info("Pad data point: "+i);
list.add(Double.NaN);
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
logger.info("dlist size: "+dlist.size());
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = metadata.getComponents().get(t);
// Combine all lists to one big list (pad if there are data points missing)
List<Object> list = new ArrayList<Object>();
List<List<Object>> ol = dlist.get(t);
// Remove last array list as it is empty
ol.remove(ol.size()-1);
for(List<Object> li: ol){
list.addAll(li);
// Pad list if there are missing data points for some lines
for(int i=li.size();i<dsize;i++){
logger.info("Pad data point: "+i);
list.add(Double.NaN);
}
}
// List<Object> list = dlist.get(t);
logger.info("List: "+list.size());
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()),(Double[])list.toArray(new Double[list.size()]), dsize);
matlablist.add(darray);
}
}
// List<Object> list = dlist.get(t);
logger.info("List: "+list.size());
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()),(Double[])list.toArray(new Double[list.size()]), dsize);
matlablist.add(darray);
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}

View File

@@ -26,13 +26,14 @@ import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import com.google.common.eventbus.Subscribe;
import com.jmatio.io.MatFileWriter;
import com.jmatio.types.MLArray;
import com.jmatio.types.MLDouble;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
@@ -47,22 +48,35 @@ public class DataSerializerMAT2DZigZag implements DataSerializer{
// Get Logger
private static final Logger logger = Logger.getLogger(DataSerializerMAT2DZigZag.class.getName());
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
private boolean appendSuffix = false;
private boolean first = true;
private File outfile;
private List<List<Object>> dlist;
private List<List<Object>> dlistTmp;
private List<Class<?>> clist;
private int dsize; // Size of the dimension
private int dcount;
private int delimiterCount;
private boolean firstF;
private boolean firstC;
/**
* Construtor
* @param queue Data queue holding the data to serialize
* @param file Name of the Matlab file to serialize the data to
*/
public DataSerializerMAT2DZigZag(DataQueue queue, File file){
this.queue = queue;
public DataSerializerMAT2DZigZag(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
// Check if input queue does only hold 2D data
int maxdim=0;
for(ComponentMetadata m: queue.getDataMessageMetadata().getComponents()){
for(ComponentMetadata m: metadata.getComponents()){
if(m.getDimension()>maxdim){
maxdim=m.getDimension();
}
@@ -77,52 +91,49 @@ public class DataSerializerMAT2DZigZag implements DataSerializer{
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
@Subscribe
public void onMessage(Message message) {
try{
// WORKAROUND BEGIN
File outfile;
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
fname = fname.replaceAll("\\."+extension+"$", "");
if(first){
first=false;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
// WORKAROUND BEGIN
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
fname = fname.replaceAll("\\."+extension+"$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
}
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
dlist = new ArrayList<List<Object>>();
dlistTmp = new ArrayList<List<Object>>();
clist = new ArrayList<Class<?>>();
dsize = 0; // Size of the dimension
dcount = 0;
delimiterCount = 0;
firstF = true;
firstC = true;
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
List<List<Object>> dlist = new ArrayList<List<Object>>();
List<List<Object>> dlistTmp = new ArrayList<List<Object>>();
List<Class<?>> clist = new ArrayList<Class<?>>();
int dsize = 0; // Size of the dimension
int dcount = 0;
int delimiterCount = 0;
boolean firstF = true;
boolean firstC = true;
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage m = (DataMessage) message;
@@ -172,41 +183,35 @@ public class DataSerializerMAT2DZigZag implements DataSerializer{
delimiterCount++;
}
}
// Read next message
message = queue.getQueue().take();
}
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
logger.info("dlist size: "+dlist.size());
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = queue.getDataMessageMetadata().getComponents().get(t);
List<Object> list = dlist.get(t);
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()),(Double[])list.toArray(new Double[list.size()]), dsize);
matlablist.add(darray);
else if(message instanceof EndOfStreamMessage){
// Create Matlab vectors
ArrayList<MLArray> matlablist = new ArrayList<MLArray>();
logger.info("dlist size: "+dlist.size());
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = metadata.getComponents().get(t);
List<Object> list = dlist.get(t);
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
MLDouble darray = new MLDouble(escapeString(c.getId()),(Double[])list.toArray(new Double[list.size()]), dsize);
matlablist.add(darray);
}
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
}
// Write Matlab file
MatFileWriter writerr = new MatFileWriter();
writerr.write(outfile, matlablist);
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}

View File

@@ -30,9 +30,11 @@ import java.util.HashMap;
import java.util.List;
import java.util.logging.Logger;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
@@ -47,81 +49,75 @@ import ch.psi.fda.core.messages.StreamDelimiterMessage;
*/
public class DataSerializerMDA implements DataSerializer{
// Get Logger
private static final Logger logger = Logger.getLogger(DataSerializerMDA.class.getName());
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
public DataSerializerMDA(DataQueue queue, File file){
this.queue = queue;
private boolean first = true;
private List<Boolean> firstL;
private List<Boolean> takeData;
private List<Integer> dcountL;
private List<List<List<List<Double>>>> dimensionList;
private HashMap<Integer,List<Integer>> dMap;
private HashMap<Integer,List<String>> idMap;
private int numberOfDimensions;
public DataSerializerMDA(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try{
// Analyze header
// Map holding all indexes for a given dimension
HashMap<Integer,List<Integer>> dMap = new HashMap<Integer, List<Integer>>();
// Map holding all ids for a given dimension
HashMap<Integer,List<String>> idMap = new HashMap<Integer, List<String>>();
List<ComponentMetadata> mlist = queue.getDataMessageMetadata().getComponents();
for(int index=0;index<mlist.size();index++){
ComponentMetadata m = mlist.get(index);
if(!dMap.containsKey(m.getDimension())){
dMap.put(m.getDimension(), new ArrayList<Integer>());
@Subscribe
public void onMessage(Message message) {
if(first){
first = false;
// Analyze header
// Map holding all indexes for a given dimension
dMap = new HashMap<Integer, List<Integer>>();
// Map holding all ids for a given dimension
idMap = new HashMap<Integer, List<String>>();
List<ComponentMetadata> mlist = metadata.getComponents();
for(int index=0;index<mlist.size();index++){
ComponentMetadata m = mlist.get(index);
if(!dMap.containsKey(m.getDimension())){
dMap.put(m.getDimension(), new ArrayList<Integer>());
}
if(!idMap.containsKey(m.getDimension())){
idMap.put(m.getDimension(), new ArrayList<String>());
}
dMap.get(m.getDimension()).add(index);
idMap.get(m.getDimension()).add(m.getId());
}
if(!idMap.containsKey(m.getDimension())){
idMap.put(m.getDimension(), new ArrayList<String>());
//dimensions/dimension/dimensioncomponents/component/componentvalue
dimensionList = new ArrayList<List<List<List<Double>>>>();
numberOfDimensions = dMap.size();
logger.info("Number of dimensions: "+numberOfDimensions);
for(int i=0;i<numberOfDimensions; i++){
// For each dimension add an list
dimensionList.add(new ArrayList<List<List<Double>>>());
}
firstL = new ArrayList<Boolean>();
takeData = new ArrayList<Boolean>(); // Flag whether to take data for this dimension
dcountL = new ArrayList<Integer>(); // How many times this dimension is there
for(int i=0;i<numberOfDimensions;i++){
firstL.add(true);
takeData.add(true);
dcountL.add(0);
}
dMap.get(m.getDimension()).add(index);
idMap.get(m.getDimension()).add(m.getId());
}
//dimensions/dimension/dimensioncomponents/component/componentvalue
List<List<List<List<Double>>>> dimensionList = new ArrayList<List<List<List<Double>>>>();
int numberOfDimensions = dMap.size();
logger.info("Number of dimensions: "+numberOfDimensions);
for(int i=0;i<numberOfDimensions; i++){
// For each dimension add an list
dimensionList.add(new ArrayList<List<List<Double>>>());
}
// // Transposed data list
// List<List<Double>> dlist = new ArrayList<List<Double>>();
//// List<Class<?>> clist = new ArrayList<Class<?>>();
// int dsize = 0; // Size of the dimension
// int dcount = 0;
// boolean firstF = true;
List<Boolean> firstL = new ArrayList<Boolean>();
List<Boolean> takeData = new ArrayList<Boolean>(); // Flag whether to take data for this dimension
List<Integer> dcountL = new ArrayList<Integer>(); // How many times this dimension is there
for(int i=0;i<numberOfDimensions;i++){
firstL.add(true);
takeData.add(true);
dcountL.add(0);
}
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage m = (DataMessage) message;
@@ -172,63 +168,53 @@ public class DataSerializerMDA implements DataSerializer{
}
}
// Read next message
message = queue.getQueue().take();
}
// Write MDA file
logger.info("Write MDA data file");
try {
if(file.exists()){
file.delete();
}
// XDROutputStream x = new XDROutputStream(new FileOutputStream(file));
XDRRandomAccessFile x = new XDRRandomAccessFile(file, "rw");
else if(message instanceof EndOfStreamMessage){
// Write MDA file
logger.info("Write MDA data file");
/**
* Read file header
*/
x.writeFloat(0f); // Version
x.writeInt(0); // Scan number
x.writeInt(numberOfDimensions); // Rank/Number of dimensions
for(int i=numberOfDimensions-1;i>=0; i--){
int s = dimensionList.get(i).get(0).get(0).size();
x.writeInt(s); // Dimension size
logger.info("Size: "+i+" - "+s+" ");
}
x.writeInt(1); // Is Regular (true=1, false=0)
x.writeInt(0); // Number of extra pvs
// Write data
HashMap<Integer,Integer> indexCount = new HashMap<Integer,Integer>();
for(int i=0;i<dimensionList.size();i++){
indexCount.put(i, 0);
}
// The highest dimension only consist of one data list
int dnum = dimensionList.size()-1;
writeDimension(x, dimensionList, indexCount, idMap, dnum);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
// } catch (IOException e) {
// throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}
try {
if(file.exists()){
file.delete();
}
// XDROutputStream x = new XDROutputStream(new FileOutputStream(file));
XDRRandomAccessFile x = new XDRRandomAccessFile(file, "rw");
/**
* Read file header
*/
x.writeFloat(0f); // Version
x.writeInt(0); // Scan number
x.writeInt(numberOfDimensions); // Rank/Number of dimensions
for(int i=numberOfDimensions-1;i>=0; i--){
int s = dimensionList.get(i).get(0).get(0).size();
x.writeInt(s); // Dimension size
logger.info("Size: "+i+" - "+s+" ");
}
x.writeInt(1); // Is Regular (true=1, false=0)
x.writeInt(0); // Number of extra pvs
// Write data
HashMap<Integer,Integer> indexCount = new HashMap<Integer,Integer>();
for(int i=0;i<dimensionList.size();i++){
indexCount.put(i, 0);
}
// The highest dimension only consist of one data list
int dnum = dimensionList.size()-1;
writeDimension(x, dimensionList, indexCount, idMap, dnum);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private long writeDimension(XDRRandomAccessFile x, List<List<List<List<Double>>>> dimensionList, HashMap<Integer,Integer> icount, HashMap<Integer,List<String>> idMap, int dnum) throws IOException{

View File

@@ -25,9 +25,11 @@ import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Logger;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
@@ -39,197 +41,160 @@ import ch.psi.fda.core.messages.StreamDelimiterMessage;
*/
public class DataSerializerTXT implements DataSerializer{
// Get Logger
private static final Logger logger = Logger.getLogger(DataSerializerTXT.class.getName());
private DataQueue queue;
private File file;
private boolean appendSuffix = true;
private boolean first = true;
private File outfile;
private DataMessageMetadata meta;
private int icount;
private String basename;
private String extension;
private boolean newfile;
private boolean dataInBetween;
private BufferedWriter writer;
private StringBuffer b;
private StringBuffer b1;
/**
*
* @param queue
* @param metadata
* @param file
* @param appendSuffix Flag whether to append a _0000 suffix after the original file name
*/
public DataSerializerTXT(DataQueue queue, File file, boolean appendSuffix){
this.queue = queue;
public DataSerializerTXT(DataMessageMetadata meta, File file, boolean appendSuffix){
this.meta = meta;
this.file = file;
this.appendSuffix = appendSuffix;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
@Subscribe
public void onMessage(Message message){
try{
// WORKAROUND BEGIN
File outfile;
// if(appendSuffix){
// // Append a count suffix to the file. If there is already a file with
// // this suffix increase the counter for the suffix
// int cnt = 0;
// String fname = this.file.getAbsolutePath(); // Determine file name
// String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
// fname = fname.replaceAll("\\."+extension+"$", "");
//
// outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
//
// while(outfile.exists()){
// cnt++;
// outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
// }
// }
// else{
// outfile = this.file;
// }
// WORKAROUND END
if(first){
first=false;
// Write header
StringBuffer b = new StringBuffer();
StringBuffer b1 = new StringBuffer();
b.append("#");
b1.append("#");
for(ComponentMetadata c: queue.getDataMessageMetadata().getComponents()){
b = new StringBuffer();
b1 = new StringBuffer();
b.append("#");
b1.append("#");
for(ComponentMetadata c: meta.getComponents()){
b.append(c.getId());
b.append("\t");
b1.append(c.getDimension());
b1.append("\t");
}
b.setCharAt(b.length()-1, '\n');
b1.setCharAt(b1.length()-1, '\n');
int icount = 0;
boolean newfile = true;
boolean dataInBetween = false;
BufferedWriter writer = null;
// Get basename of the file
String basename = this.file.getAbsolutePath(); // Determine file name
String extension = basename.replaceAll("^.*\\.", ""); // Determine extension
basename = basename.replaceAll("\\."+extension+"$", "");
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
dataInBetween = true;
if(newfile){
// Open new file and write header
// Construct file name
if(appendSuffix){
outfile = new File(String.format("%s_%04d.%s", basename, icount, extension));
}
else{
outfile = new File(String.format("%s.%s", basename, extension));
b.append(c.getId());
b.append("\t");
b1.append(c.getDimension());
b1.append("\t");
}
b.setCharAt(b.length()-1, '\n');
b1.setCharAt(b1.length()-1, '\n');
// Open file
logger.fine("Open new data file: "+outfile.getAbsolutePath());
writer = new BufferedWriter(new FileWriter(outfile));
// Write header
writer.write(b.toString());
writer.write(b1.toString());
newfile=false;
}
// Write message to file - each message will result in one line
DataMessage m = (DataMessage) message;
StringBuffer buffer = new StringBuffer();
for(Object o: m.getData()){
if(o.getClass().isArray()){
// If the array object is of type double[] display its content
if(o instanceof double[]){
double[] oa = (double[]) o;
for(double o1 : oa){
buffer.append(o1);
buffer.append(" "); // Use space instead of tab
}
buffer.replace(buffer.length()-1,buffer.length()-1 , "\t"); // Replace last space with tab
}
else if(o instanceof Object[]){
// TODO need to be recursive ...
Object[] oa = (Object[])o;
for(Object o1 : oa){
buffer.append(o1);
buffer.append(" "); // Use space instead of tab
}
buffer.replace(buffer.length()-1,buffer.length()-1 , "\t"); // Replace last space with tab
}
else{
buffer.append("-"); // Not supported
}
}
else{
buffer.append(o);
buffer.append("\t");
}
}
if(buffer.length()>0){
buffer.deleteCharAt(buffer.length()-1); // Remove last character (i.e. \t)
buffer.append("\n"); // Append newline
}
writer.write(buffer.toString());
}
else if(message instanceof StreamDelimiterMessage){
StreamDelimiterMessage m = (StreamDelimiterMessage) message;
logger.info("Delimiter - number: "+m.getNumber()+" iflag: "+m.isIflag());
if(m.isIflag() && appendSuffix){
// Only increase iflag counter if there was data in between
// subsequent StreamDelimiterMessages.
if(dataInBetween){
icount++;
}
dataInBetween = false;
// Set flag to open new file
icount = 0;
newfile = true;
dataInBetween = false;
writer = null;
// Close file
writer.close();
}
// Get basename of the file
basename = this.file.getAbsolutePath(); // Determine file name
extension = basename.replaceAll("^.*\\.", ""); // Determine extension
basename = basename.replaceAll("\\."+extension+"$", "");
}
if(message instanceof DataMessage){
dataInBetween = true;
if(newfile){
// Open new file and write header
// Construct file name
if(appendSuffix){
outfile = new File(String.format("%s_%04d.%s", basename, icount, extension));
}
else{
outfile = new File(String.format("%s.%s", basename, extension));
}
// Read next message
message = queue.getQueue().take();
// Open file
logger.fine("Open new data file: "+outfile.getAbsolutePath());
writer = new BufferedWriter(new FileWriter(outfile));
// Write header
writer.write(b.toString());
writer.write(b1.toString());
newfile=false;
}
// Write message to file - each message will result in one line
DataMessage m = (DataMessage) message;
StringBuffer buffer = new StringBuffer();
for(Object o: m.getData()){
if(o.getClass().isArray()){
// If the array object is of type double[] display its content
if(o instanceof double[]){
double[] oa = (double[]) o;
for(double o1 : oa){
buffer.append(o1);
buffer.append(" "); // Use space instead of tab
}
buffer.replace(buffer.length()-1,buffer.length()-1 , "\t"); // Replace last space with tab
}
else if(o instanceof Object[]){
// TODO need to be recursive ...
Object[] oa = (Object[])o;
for(Object o1 : oa){
buffer.append(o1);
buffer.append(" "); // Use space instead of tab
}
buffer.replace(buffer.length()-1,buffer.length()-1 , "\t"); // Replace last space with tab
}
else{
buffer.append("-"); // Not supported
}
}
else{
buffer.append(o);
buffer.append("\t");
}
}
if(buffer.length()>0){
buffer.deleteCharAt(buffer.length()-1); // Remove last character (i.e. \t)
buffer.append("\n"); // Append newline
}
writer.write(buffer.toString());
}
else if(message instanceof StreamDelimiterMessage){
StreamDelimiterMessage m = (StreamDelimiterMessage) message;
logger.info("Delimiter - number: "+m.getNumber()+" iflag: "+m.isIflag());
if(m.isIflag() && appendSuffix){
// Only increase iflag counter if there was data in between
// subsequent StreamDelimiterMessages.
if(dataInBetween){
icount++;
}
dataInBetween = false;
// Set flag to open new file
newfile = true;
// Close file
writer.close();
}
}
else if (message instanceof EndOfStreamMessage){
if(writer!=null){
// Close file
writer.close(); //If the stream was closed previously this has no effect
}
// Writer can be null if a scan is defined without a dimension
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
}
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}
}
// /**
// * Enable/disable the generation of the _0000 suffix in front of the extension of the out file
// * @param appendSuffix the appendSuffix to set
// */
// public void setAppendSuffix(boolean appendSuffix) {
// this.appendSuffix = appendSuffix;
// }
}

View File

@@ -26,9 +26,11 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
@@ -40,22 +42,31 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataSerializerTXT2D implements DataSerializer{
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
private boolean appendSuffix = false;
private boolean first = true;
File outfile;
List<List<Object>> dlist;
List<Class<?>> clist;
int dsize;
int dcount;
boolean firstF;
/**
* Construtor
* @param queue Data queue holding the data to serialize
* @param file Name of the Matlab file to serialize the data to
*/
public DataSerializerTXT2D(DataQueue queue, File file){
this.queue = queue;
public DataSerializerTXT2D(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
// Check if input queue does only hold 2D data
int maxdim=0;
for(ComponentMetadata m: queue.getDataMessageMetadata().getComponents()){
for(ComponentMetadata m: metadata.getComponents()){
if(m.getDimension()>maxdim){
maxdim=m.getDimension();
}
@@ -70,49 +81,46 @@ public class DataSerializerTXT2D implements DataSerializer{
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
@Subscribe
public void onMessage(Message message) {
try{
// WORKAROUND BEGIN
File outfile;
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
// fname = fname.replaceAll("(_[0-9]+)?\\."+extension+"$", "");
fname = fname.replaceAll("\\."+extension+"$", "");
if(first){
first = false;
// WORKAROUND BEGIN
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
if(appendSuffix){
// Append a count suffix to the file. If there is already a file with
// this suffix increase the counter for the suffix
int cnt = 0;
String fname = this.file.getAbsolutePath(); // Determine file name
String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
// fname = fname.replaceAll("(_[0-9]+)?\\."+extension+"$", "");
fname = fname.replaceAll("\\."+extension+"$", "");
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
while(outfile.exists()){
cnt++;
outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
}
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
dlist = new ArrayList<List<Object>>();
clist = new ArrayList<Class<?>>();
dsize = 0; // Size of the dimension
dcount = 0;
firstF = true;
}
else{
outfile = this.file;
}
// WORKAROUND END
// Transposed data list
List<List<Object>> dlist = new ArrayList<List<Object>>();
List<Class<?>> clist = new ArrayList<Class<?>>();
int dsize = 0; // Size of the dimension
int dcount = 0;
boolean firstF = true;
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
DataMessage m = (DataMessage) message;
@@ -143,59 +151,53 @@ public class DataSerializerTXT2D implements DataSerializer{
}
}
// Read next message
message = queue.getQueue().take();
}
// Open file
BufferedWriter writer = new BufferedWriter(new FileWriter(outfile));
// Create text images
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = queue.getDataMessageMetadata().getComponents().get(t);
else if(message instanceof EndOfStreamMessage){
// Open file
BufferedWriter writer = new BufferedWriter(new FileWriter(outfile));
writer.write(c.getId()+"\n");
List<Object> list = dlist.get(t);
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
// Create text images
for(int t=0; t<dlist.size(); t++ ){
// Get component metadata
ComponentMetadata c = metadata.getComponents().get(t);
StringBuffer b = new StringBuffer();
int counter = 0;
for(Object o: list){
b.append(o);
counter++;
if(counter==dsize){
b.append("\n");
counter=0;
}
else{
b.append(" ");
writer.write(c.getId()+"\n");
List<Object> list = dlist.get(t);
if(clist.get(t).isArray()){
// Array Handling
}
else if(clist.get(t).equals(Double.class)){
// Data is of type Double
StringBuffer b = new StringBuffer();
int counter = 0;
for(Object o: list){
b.append(o);
counter++;
if(counter==dsize){
b.append("\n");
counter=0;
}
else{
b.append(" ");
}
}
writer.write(b.toString());
}
writer.write(b.toString());
writer.write("\n");
}
writer.write("\n");
// Close file
writer.close();
}
// Close file
writer.close();
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}

View File

@@ -26,11 +26,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
@@ -40,20 +41,23 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataSerializerTXTSplit implements DataSerializer{
private DataQueue queue;
private DataMessageMetadata metadata;
private File file;
private int maxdim = 0;
// private boolean appendSuffix = false;
private boolean first = true;
private List<String> header;
private List<String> data;
public DataSerializerTXTSplit(DataQueue queue, File file){
this.queue = queue;
public DataSerializerTXTSplit(DataMessageMetadata metadata, File file){
this.metadata = metadata;
this.file = file;
// Determine maximum dimension
for(ComponentMetadata m: queue.getDataMessageMetadata().getComponents()){
for(ComponentMetadata m: metadata.getComponents()){
if(m.getDimension()>maxdim){
maxdim=m.getDimension();
}
@@ -64,62 +68,42 @@ public class DataSerializerTXTSplit implements DataSerializer{
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
@Subscribe
public void onMessage(Message message) {
try{
// WORKAROUND BEGIN
// File outfile;
// if(appendSuffix){
// // Append a count suffix to the file. If there is already a file with
// // this suffix increase the counter for the suffix
// int cnt = 0;
// String fname = this.file.getAbsolutePath(); // Determine file name
// String extension = fname.replaceAll("^.*\\.", ""); // Determine extension
// fname = fname.replaceAll("\\."+extension+"$", "");
//
// outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
//
// while(outfile.exists()){
// cnt++;
// outfile = new File(String.format("%s_%04d.%s", fname, cnt, extension));
// }
// }
// else{
// outfile = this.file;
// }
// WORKAROUND END
List<String> header = new ArrayList<String>();
// Write header
StringBuffer b = new StringBuffer();
StringBuffer b1 = new StringBuffer();
b.append("#");
b1.append("#");
for(ComponentMetadata c: queue.getDataMessageMetadata().getComponents()){
b.append(c.getId());
b.append("\t");
if(first){
first=false;
header = new ArrayList<String>();
data = new ArrayList<String>();
// Write header
StringBuffer b = new StringBuffer();
StringBuffer b1 = new StringBuffer();
b.append("#");
b1.append("#");
for(ComponentMetadata c: metadata.getComponents()){
b.append(c.getId());
b.append("\t");
b1.append(c.getDimension());
b1.append("\t");
}
b.setCharAt(b.length()-1, '\n');
b1.setCharAt(b1.length()-1, '\n');
header.add(b.toString());
header.add(b1.toString());
b1.append(c.getDimension());
b1.append("\t");
}
b.setCharAt(b.length()-1, '\n');
b1.setCharAt(b1.length()-1, '\n');
header.add(b.toString());
header.add(b1.toString());
List<String> data = new ArrayList<String>();
// Write data
// Read Message
Message message = queue.getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
if(message instanceof DataMessage){
// Write message to file - each message will result in one line
@@ -168,19 +152,6 @@ public class DataSerializerTXTSplit implements DataSerializer{
}
}
// Read next message
message = queue.getQueue().take();
}
// // Open file
// BufferedWriter writer = new BufferedWriter(new FileWriter(outfile));
//
// // Close file
// writer.close();
} catch (InterruptedException e) {
// TODO Stop loop and exit logic instead of throwing an Exception
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
} catch (IOException e) {
throw new RuntimeException("Data serializer had a problem writing to the specified file",e);
}

View File

@@ -1,74 +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.visualizer;
import java.util.ArrayList;
import java.util.List;
import ch.psi.fda.core.messages.DataQueue;
/**
* @author ebner
*
*/
public class FilterSet {
private DataQueue queue;
private List<SeriesDataFilter> filters = new ArrayList<SeriesDataFilter>();
private String name;
public FilterSet(DataQueue queue){
this("", queue);
}
public FilterSet(String name, DataQueue queue){
this.queue = queue;
}
/**
* @return the queue
*/
public DataQueue getQueue() {
return queue;
}
/**
* @return the filters
*/
public List<SeriesDataFilter> getFilters() {
return filters;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
}

View File

@@ -19,10 +19,5 @@
package ch.psi.fda.visualizer;
/**
* @author ebner
*
*/
public interface SeriesDataFilter {
}

View File

@@ -27,13 +27,12 @@ import java.util.logging.Logger;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
//import org.jfree.data.xy.XYSeries;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.model.v1.ArrayDetector;
import ch.psi.fda.model.v1.ContinuousPositioner;
import ch.psi.fda.model.v1.Detector;
@@ -45,294 +44,204 @@ import ch.psi.plot.Plot;
import ch.psi.plot.xy.LinePlot;
import ch.psi.plot.xy.XYSeriesCollectionP;
import ch.psi.plot.xy.XYSeriesP;
//import ch.psi.plot.xyz.JFreeMatrixPlot;
//import ch.psi.plot.xyz.JFreeMatrixPlotData;
//import ch.psi.plot.xyz.JFreeMatrixPlotMetadata;
import ch.psi.plot.xyz.MatrixPlot;
import ch.psi.plot.xyz.MatrixPlotData;
/**
* Serialize data received by a DataQueue
* Visualizer for visualizing data
* @author ebner
*
*/
public class Visualizer {
// Logger
private static Logger logger = Logger.getLogger(Visualizer.class.getName());
private FilterSet filterSet = null;
private List<Plot> plots = new ArrayList<Plot>();
private Thread visualizationThread = null;
/**
* Terminate at end of stream
*/
private boolean terminateAtEOS = false;
private volatile boolean terminate = false;
private boolean updateAtStreamElement = true;
private boolean updateAtStreamDelimiter = true;
private boolean updateAtEndOfStream = false;
public Visualizer(DataQueue queue, List<Visualization> vl){
addFilterSet(queue, vl);
private int ecount;
private boolean clearPlot;
private List<SeriesDataFilter> filters;
public Visualizer(DataMessageMetadata meta, List<Visualization> vl){
filters = mapVisualizations(meta, vl);
}
private void addFilterSet(DataQueue queue, List<Visualization> vl){
filterSet = mapVisualizations(queue, vl);
}
/**
* Visualize data
* Method blocks until visualization is done
*/
public void visualize() {
if(filterSet != null ){
DataQueue queue = filterSet.getQueue();
List<SeriesDataFilter> filters = filterSet.getFilters();
int ecount = 0;
boolean clearPlot = false;
terminate = false;
// Read Messages
Message message = null;
try {
message = queue.getQueue().take();
} catch (InterruptedException e) {
terminate = true;
// Reset interrupted status
Thread.currentThread().interrupt();
@Subscribe
public void onDataMessage(final DataMessage message){
// Clear is here as the plot should not be cleared after the last point is plotted
// but just before the first point of the next plot (cycle)
if (clearPlot) {
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlotData) ((MatrixPlot)plot).getData()).clear();
}
}
clearPlot = false;
}
while ( (!Thread.currentThread().isInterrupted()) && (!terminate) ) {
if (message instanceof DataMessage) {
final DataMessage m = (DataMessage) message;
for(SeriesDataFilter filter: filters){
if(filter instanceof XYSeriesDataFilter){
XYSeriesDataFilter xyfilter = (XYSeriesDataFilter) filter;
// Clear is here as the plot should not be cleared after the last point is plotted
// but just before the first point of the next plot (cycle)
if (clearPlot) {
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlotData) ((MatrixPlot)plot).getData()).clear();
}
}
clearPlot = false;
}
for(SeriesDataFilter filter: filters){
if(filter instanceof XYSeriesDataFilter){
XYSeriesDataFilter xyfilter = (XYSeriesDataFilter) filter;
if(xyfilter.getActualSeries()==null || xyfilter.isNewseries()){
// First series that is filled by this filter!
XYSeriesP s = new XYSeriesP(xyfilter.getSeriesName() + " " + ecount + "-" + xyfilter.getCount());
((LinePlot)xyfilter.getPlot()).getData().addSeries(s);
xyfilter.setActualSeries(s);
xyfilter.setNewseries(false);
}
// 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()));
// 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;
// Ensure that there is no concurrent modification exception or synchronization problems with the
// Swing update task
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
XYSeriesP series = new XYSeriesP(xyfilter.getSeriesName() + "-" + xyfilter.getCount()); // Series name must be unique
xyfilter.incrementCount();
// ((LinePlot)xyfilter.getPlot()).getData().removeAllSeries(); // Remove all series from the data
// If we can agree only to display one series at a time also a clear() on the actual series is better
XYSeriesCollectionP sc = ((LinePlot)xyfilter.getPlot()).getData();
sc.addSeries(series);
// Remove outdated series
if(sc.getSeriesCount()>xyfilter.getMaxSeries()){
// Remove oldest series
sc.removeSeries(0);
}
double[] data = (double[]) m.getData().get(xyfilter.getIndexY());
// Copy data starting from offset to size
int size = data.length;
int offset = xyfilter.getOffset();
if(xyfilter.getSize()>0 && offset+xyfilter.getSize()<data.length){
size = offset + xyfilter.getSize();
}
for(int i=offset;i<size;i++){
series.add(i,data[i], false); // Do not fire change event - this would degrade performance drastically
}
series.fireSeriesChanged();
}
});
}
else if(filter instanceof XYZSeriesDataFilter){
XYZSeriesDataFilter xyzfilter = (XYZSeriesDataFilter) filter;
try{
((MatrixPlot)xyzfilter.getPlot()).getData().addData((Double) m.getData().get(xyzfilter.getIndexX()),(Double) m.getData().get(xyzfilter.getIndexY()), (Double) m.getData().get(xyzfilter.getIndexZ()));
}
catch (Exception e) {
// Ignore if something goes wrong while adding a datapoint
logger.log(Level.WARNING, "Unable to plot datapoint in matrix plot", e);
}
}
else if(filter instanceof XYZSeriesArrayDataFilter){
XYZSeriesArrayDataFilter xyzfilter = (XYZSeriesArrayDataFilter) filter;
try{
double[] data = (double[]) m.getData().get(xyzfilter.getIndexZ());
double y = (Double) m.getData().get(xyzfilter.getIndexY());
int offset = xyzfilter.getOffset();
int size = xyzfilter.getSize();
for(int i=offset;i<offset+size; i++){
((MatrixPlot)xyzfilter.getPlot()).getData().addData(i, y, data[i]);
}
// Update data if update by point is enabled
if(updateAtStreamElement){
xyzfilter.getPlot().update();
}
}
catch (Exception e) {
// Ignore if something goes wrong while adding a datapoint
logger.log(Level.WARNING, "Unable to plot datapoint in matrix plot", e);
}
}
if(xyfilter.getActualSeries()==null || xyfilter.isNewseries()){
// First series that is filled by this filter!
XYSeriesP s = new XYSeriesP(xyfilter.getSeriesName() + " " + ecount + "-" + xyfilter.getCount());
((LinePlot)xyfilter.getPlot()).getData().addSeries(s);
xyfilter.setActualSeries(s);
xyfilter.setNewseries(false);
}
} else if (message instanceof StreamDelimiterMessage) {
StreamDelimiterMessage ddm = (StreamDelimiterMessage) message;
for(SeriesDataFilter filter: filters){
if(filter instanceof XYSeriesDataFilter){
// Create new series
XYSeriesDataFilter xyfilter = (XYSeriesDataFilter) filter;
if (ddm.getNumber() == xyfilter.getDimensionX()) {
// Indicate to create new series at the next message
xyfilter.setCount(xyfilter.getCount()+1); // Increment count of the filter
xyfilter.setNewseries(true);
}
}
XYSeriesP series = xyfilter.getActualSeries(); // TODO Does not work with multiple series filter per plot !!!!
// There might be other values than double in the data, therefore we have to check for it
Object dX = message.getData().get(xyfilter.getIndexX());
Object dY = message.getData().get(xyfilter.getIndexY());
Double dataX = Double.NaN;
Double dataY = Double.NaN;
if(dX instanceof Double){
dataX = (Double) dX;
}
// Update matrix plot at the end of each line
if(updateAtStreamDelimiter){
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlot)plot).update();
}
else if(plot instanceof LinePlot){
((LinePlot) plot).update();
}
}
}
// Clear matrix plot if iflag is encountered
// TODO: One need to check whether the iflag belongs to a delimiter
// of a higher dimension than the highest dimension (axis) that
// is involved in the plot
if (ddm.isIflag()) {
clearPlot = true;
}
} else if (message instanceof EndOfStreamMessage) {
ecount++;
if(terminateAtEOS){
terminate = true;
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;
// Update plots if updateAtEndOfStream flag is set
if(updateAtEndOfStream){
// Update matrix plots
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlot)plot).update();
((MatrixPlot)plot).adaptColorMapScale(); // Update color scale at the end
// Ensure that there is no concurrent modification exception or synchronization problems with the
// Swing update task
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
XYSeriesP series = new XYSeriesP(xyfilter.getSeriesName() + "-" + xyfilter.getCount()); // Series name must be unique
xyfilter.incrementCount();
// ((LinePlot)xyfilter.getPlot()).getData().removeAllSeries(); // Remove all series from the data
// If we can agree only to display one series at a time also a clear() on the actual series is better
XYSeriesCollectionP sc = ((LinePlot)xyfilter.getPlot()).getData();
sc.addSeries(series);
// Remove outdated series
if(sc.getSeriesCount()>xyfilter.getMaxSeries()){
// Remove oldest series
sc.removeSeries(0);
}
else if(plot instanceof LinePlot){
((LinePlot) plot).update();
double[] data = (double[]) message.getData().get(xyfilter.getIndexY());
// Copy data starting from offset to size
int size = data.length;
int offset = xyfilter.getOffset();
if(xyfilter.getSize()>0 && offset+xyfilter.getSize()<data.length){
size = offset + xyfilter.getSize();
}
for(int i=offset;i<size;i++){
series.add(i,data[i], false); // Do not fire change event - this would degrade performance drastically
}
series.fireSeriesChanged();
}
});
}
else if(filter instanceof XYZSeriesDataFilter){
XYZSeriesDataFilter xyzfilter = (XYZSeriesDataFilter) filter;
try{
((MatrixPlot)xyzfilter.getPlot()).getData().addData((Double) message.getData().get(xyzfilter.getIndexX()),(Double) message.getData().get(xyzfilter.getIndexY()), (Double) message.getData().get(xyzfilter.getIndexZ()));
}
catch (Exception e) {
// Ignore if something goes wrong while adding a datapoint
logger.log(Level.WARNING, "Unable to plot datapoint in matrix plot", e);
}
}
// End loop if terminate flag is true
if(terminate){
break;
else if(filter instanceof XYZSeriesArrayDataFilter){
XYZSeriesArrayDataFilter xyzfilter = (XYZSeriesArrayDataFilter) filter;
try{
double[] data = (double[]) message.getData().get(xyzfilter.getIndexZ());
double y = (Double) message.getData().get(xyzfilter.getIndexY());
int offset = xyzfilter.getOffset();
int size = xyzfilter.getSize();
for(int i=offset;i<offset+size; i++){
((MatrixPlot)xyzfilter.getPlot()).getData().addData(i, y, data[i]);
}
// Update data if update by point is enabled
if(updateAtStreamElement){
xyzfilter.getPlot().update();
}
}
catch (Exception e) {
// Ignore if something goes wrong while adding a datapoint
logger.log(Level.WARNING, "Unable to plot datapoint in matrix plot", e);
}
}
// Read next message
try {
message = queue.getQueue().take();
} catch (InterruptedException e) {
terminate = true;
// Reset interrupted status
Thread.currentThread().interrupt();
}
}
@Subscribe
public void onStreamDelimiterMessage(StreamDelimiterMessage message){
for(SeriesDataFilter filter: filters){
if(filter instanceof XYSeriesDataFilter){
// Create new series
XYSeriesDataFilter xyfilter = (XYSeriesDataFilter) filter;
if (message.getNumber() == xyfilter.getDimensionX()) {
// Indicate to create new series at the next message
xyfilter.setCount(xyfilter.getCount()+1); // Increment count of the filter
xyfilter.setNewseries(true);
}
}
}
// Update matrix plot at the end of each line
if(updateAtStreamDelimiter){
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlot)plot).update();
}
else if(plot instanceof LinePlot){
((LinePlot) plot).update();
}
}
}
// Clear matrix plot if iflag is encountered
// TODO: One need to check whether the iflag belongs to a delimiter
// of a higher dimension than the highest dimension (axis) that
// is involved in the plot
if (message.isIflag()) {
clearPlot = true;
}
}
@Subscribe
public void onEndOfStreamMessage(EndOfStreamMessage message){
ecount++;
// Update plots if updateAtEndOfStream flag is set
if(updateAtEndOfStream){
// Update matrix plots
for (Plot plot: plots) {
if(plot instanceof MatrixPlot){
((MatrixPlot)plot).update();
((MatrixPlot)plot).adaptColorMapScale(); // Update color scale at the end
}
else if(plot instanceof LinePlot){
((LinePlot) plot).update();
}
}
}
logger.info("End visualization");
}
/**
* Starts a visualization thread for this visualizer
*/
public void startVisualization(){
// Throw an exception if visualization is already running
if(visualizationThread!=null){
throw new IllegalStateException("Visualization already running");
}
visualizationThread = new Thread(new Runnable() {
@Override
public void run() {
visualize();
}
});
// Start thread
visualizationThread.start();
}
/**
* Stop visualization thread of this visualizer
* Waits until the visualiztion thread is stopped
* @throws InterruptedException
*/
public void stopVisualization() throws InterruptedException{
// Wait until visualiztion thread is stopped
visualizationThread.interrupt();
visualizationThread.join(10000); // Wait 10 seconds to have the visualization Thread to come to an end
visualizationThread = null;
public void configure(){
ecount = 0;
clearPlot = false;
}
@@ -368,9 +277,8 @@ public class Visualizer {
* @param vl List of configured visualizations
* @return List of visualization configuration
*/
private FilterSet mapVisualizations(DataQueue queue, List<Visualization> vl){
FilterSet fset = new FilterSet(queue);
List<SeriesDataFilter> filters = fset.getFilters();
private List<SeriesDataFilter> mapVisualizations(DataMessageMetadata meta, List<Visualization> vl){
List<SeriesDataFilter> filters = new ArrayList<SeriesDataFilter>();
for(Visualization v: vl){
if(v instanceof ch.psi.fda.model.v1.LinePlot){
@@ -382,14 +290,14 @@ public class Visualizer {
// Create data filter for visualization
String idX = getId(lp.getX());
int indexX = queue.getDataMessageMetadata().getIndex(idX);
int dimX = queue.getDataMessageMetadata().getComponents().get(indexX).getDimension();
int indexX = meta.getIndex(idX);
int dimX = meta.getComponents().get(indexX).getDimension();
List<Object> l = lp.getY();
for(Object o: l){
String idY = getId(o);
int indexY = queue.getDataMessageMetadata().getIndex(idY);
int dimY = queue.getDataMessageMetadata().getComponents().get(indexY).getDimension();
int indexY = meta.getIndex(idY);
int dimY = meta.getComponents().get(indexY).getDimension();
XYSeriesDataFilter filter = new XYSeriesDataFilter(idX, idY, indexX, indexY, plot);
filter.setDimensionX(dimX);
@@ -410,8 +318,8 @@ public class Visualizer {
List<Object> l = lp.getY();
for(Object o: l){
String idY = getId(o);
int indexY = queue.getDataMessageMetadata().getIndex(idY);
int dimY = queue.getDataMessageMetadata().getComponents().get(indexY).getDimension();
int indexY = meta.getIndex(idY);
int dimY = meta.getComponents().get(indexY).getDimension();
XYSeriesArrayDataFilter filter = new XYSeriesArrayDataFilter(idY, indexY, plot);
filter.setDimensionY(dimY);
@@ -496,13 +404,13 @@ public class Visualizer {
plots.add(plot);
// Create data filter for visualization
int indexX = queue.getDataMessageMetadata().getIndex(idX);
int indexY = queue.getDataMessageMetadata().getIndex(idY);
int indexZ = queue.getDataMessageMetadata().getIndex(idZ);
int indexX = meta.getIndex(idX);
int indexY = meta.getIndex(idY);
int indexZ = meta.getIndex(idZ);
int dimX = queue.getDataMessageMetadata().getComponents().get(indexX).getDimension();
int dimY = queue.getDataMessageMetadata().getComponents().get(indexY).getDimension();
int dimZ = queue.getDataMessageMetadata().getComponents().get(indexZ).getDimension();
int dimX = meta.getComponents().get(indexX).getDimension();
int dimY = meta.getComponents().get(indexY).getDimension();
int dimZ = meta.getComponents().get(indexZ).getDimension();
XYZSeriesDataFilter filter = new XYZSeriesDataFilter(idX, idY, idZ, indexX, indexY, indexZ, plot);
filter.setDimensionX(dimX);
@@ -585,11 +493,11 @@ public class Visualizer {
plots.add(plot);
// Create data filter for visualization
int indexY = queue.getDataMessageMetadata().getIndex(idY);
int indexZ = queue.getDataMessageMetadata().getIndex(idZ);
int indexY = meta.getIndex(idY);
int indexZ = meta.getIndex(idZ);
int dimY = queue.getDataMessageMetadata().getComponents().get(indexY).getDimension();
int dimZ = queue.getDataMessageMetadata().getComponents().get(indexZ).getDimension();
int dimY = meta.getComponents().get(indexY).getDimension();
int dimZ = meta.getComponents().get(indexZ).getDimension();
XYZSeriesArrayDataFilter filter = new XYZSeriesArrayDataFilter(idY, idZ, indexY, indexZ, offset, size, plot);
filter.setDimensionY(dimY);
@@ -601,7 +509,7 @@ public class Visualizer {
throw new RuntimeException(v.getClass().getName()+" is not supported as visualization type");
}
}
return fset;
return filters;
}
/**
@@ -617,20 +525,6 @@ public class Visualizer {
return panels;
}
/**
* @param terminateAtEOS the terminateAtEOS to set
*/
public void setTerminateAtEOS(boolean terminateAtEOS) {
this.terminateAtEOS = terminateAtEOS;
}
/**
* @return the terminateAtEOS
*/
public boolean isTerminateAtEOS() {
return terminateAtEOS;
}
/**
* @return the updateAtStreamElement
*/

View File

@@ -16,13 +16,15 @@
* along with this code. If not, see <http://www.gnu.org/licenses/>.
*
*/
package ch.psi.fda.aq;
package ch.psi.fda;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ch.psi.fda.AcquisitionMain;
/**
* @author ebner
*
@@ -44,7 +46,7 @@ public class AcquisitionMainTest {
}
/**
* Test method for {@link ch.psi.fda.aq.AcquisitionMain#main(java.lang.String[])}.
* Test method for {@link ch.psi.fda.AcquisitionMain#main(java.lang.String[])}.
*/
@Ignore
@Test

View File

@@ -17,7 +17,7 @@
*
*/
package ch.psi.fda.vis;
package ch.psi.fda;
import java.io.File;
import java.net.URI;
@@ -27,20 +27,19 @@ import javax.xml.bind.JAXBException;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.xml.sax.SAXException;
import ch.psi.fda.vis.VisualizationEngine;
import ch.psi.fda.VisualizationMain;
/**
* Testcase for visualization engine
* @author ebner
*
*/
public class VisualizationEngineTest {
public class VisualizationMainTest {
private VisualizationEngine engine;
private VisualizationMain engine;
private String configurationFile;
private String dataFile;
@@ -55,7 +54,7 @@ public class VisualizationEngineTest {
url = this.getClass().getClassLoader().getResource("testdata/scan/scan1d_0000.txt");
dataFile = new File(new URI(url.toString())).getAbsolutePath();
engine = new VisualizationEngine();
engine = new VisualizationMain();
}
/**
@@ -66,7 +65,7 @@ public class VisualizationEngineTest {
}
/**
* Test method for {@link ch.psi.fda.vis.VisualizationEngine#visualize(java.io.File, java.io.File)}.
* Test method for {@link ch.psi.fda.VisualizationMain#visualize(java.io.File, java.io.File)}.
* Test whether a null data parameter is handled correctly
* @throws InterruptedException
* @throws SAXException
@@ -78,7 +77,7 @@ public class VisualizationEngineTest {
}
/**
* Test method for {@link ch.psi.fda.vis.VisualizationEngine#visualize(java.io.File, java.io.File)}.
* Test method for {@link ch.psi.fda.VisualizationMain#visualize(java.io.File, java.io.File)}.
* Test whether a non existing data file is handled correctly
* @throws InterruptedException
* @throws SAXException
@@ -90,7 +89,7 @@ public class VisualizationEngineTest {
}
/**
* Test method for {@link ch.psi.fda.vis.VisualizationEngine#visualize(java.io.File, java.io.File)}.
* Test method for {@link ch.psi.fda.VisualizationMain#visualize(java.io.File, java.io.File)}.
* Check whether null configuration file is handled correctly
* @throws InterruptedException
* @throws SAXException
@@ -102,7 +101,7 @@ public class VisualizationEngineTest {
}
/**
* Test method for {@link ch.psi.fda.vis.VisualizationEngine#visualize(java.io.File, java.io.File)}.
* Test method for {@link ch.psi.fda.VisualizationMain#visualize(java.io.File, java.io.File)}.
* Test correct visualization
* @throws InterruptedException
* @throws SAXException
@@ -115,11 +114,11 @@ public class VisualizationEngineTest {
/**
* Test whether main can automatically determine the configuration file for a given data file
* Test method for {@link ch.psi.fda.vis.VisualizationEngine#main(String[])}
* Test method for {@link ch.psi.fda.VisualizationMain#main(String[])}
*/
@Test
public void testMain(){
// ATTENTION - This test will never fail because possible exceptions are caught in the main method !!!!
VisualizationEngine.main(new String[]{dataFile});
VisualizationMain.main(new String[]{dataFile});
}
}

View File

@@ -30,16 +30,16 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import ch.psi.fda.aq.AcquisitionEngineConfiguration;
import ch.psi.fda.aq.AcquisitionConfiguration;
/**
* @author ebner
*
*/
public class AcquisitionEngineConfigurationTest {
public class AcquisitionConfigurationTest {
// Get Logger
private static Logger logger = Logger.getLogger(AcquisitionEngineConfigurationTest.class.getName());
private static Logger logger = Logger.getLogger(AcquisitionConfigurationTest.class.getName());
/**
* @throws java.lang.Exception
@@ -59,12 +59,12 @@ public class AcquisitionEngineConfigurationTest {
/**
* Test method for {@link ch.psi.fda.aq.AcquisitionEngineConfiguration#getDataFilePrefix()}.
* Test method for {@link ch.psi.fda.aq.AcquisitionConfiguration#getDataFilePrefix()}.
* Test whether the supported date macros in the file prefix are resolved
*/
@Test
public void testGetConfiguration() {
AcquisitionEngineConfiguration configuration = AcquisitionEngineConfiguration.getInstance();
AcquisitionConfiguration configuration = AcquisitionConfiguration.getInstance();
String s = configuration.getDataFilePrefix();
if(s==null){
Assert.fail("No configuration returned for data file prefix");

View File

@@ -17,20 +17,22 @@
*
*/
package ch.psi.fda.core.collector;
package ch.psi.fda.aq;
import static org.junit.Assert.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import ch.psi.fda.core.collector.Collector;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.aq.Collector;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.ControlMessage;
import ch.psi.fda.core.messages.DataMessage;
@@ -39,43 +41,10 @@ import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
* @author ebner
*
*/
public class CollectorTest {
// Get Logger
private static Logger logger = Logger.getLogger(CollectorTest.class.getName());
class TestCollector implements Runnable{
private final DataQueue queue;
public TestCollector(DataQueue queue){
this.queue = queue;
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
try {
while(true){
Message m = queue.getQueue().take();
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.fine( x.toString() );
}
else if(m instanceof ControlMessage){
logger.fine("---- "+m.toString()+" ----");
}
}
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "An Exception occured while reading data from the data queue", e);
}
}
}
private EventBus bus;
private BlockingQueue<Message> q1;
private BlockingQueue<Message> q2;
@@ -85,11 +54,12 @@ public class CollectorTest {
private DataMessageMetadata m2;
private DataMessageMetadata m3;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
bus = new EventBus();
// Create blocking queues
q1 = new LinkedBlockingQueue<Message>();
q2 = new LinkedBlockingQueue<Message>();
@@ -190,30 +160,24 @@ public class CollectorTest {
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/**
* Test method for {@link ch.psi.fda.core.collector.Collector#run()}.
* Test method for {@link ch.psi.fda.aq.Collector#run()}.
* @throws InterruptedException
*/
@Test
public void testRun() throws InterruptedException {
Collector collector = new Collector();
Collector collector = new Collector(bus);
collector.getQueues().add(new DataQueue(q1, m1));
collector.getQueues().add(new DataQueue(q2, m2));
collector.getQueues().add(new DataQueue(q3, m3));
Thread t = new Thread(new TestCollector(collector.getOutQueue()));
t.start();
// Check component metadata of output queue
int c=2;
for(ComponentMetadata cm: collector.getOutQueue().getDataMessageMetadata().getComponents()){
for(ComponentMetadata cm: collector.getMetadata().getComponents()){
logger.info(cm.toString());
if(cm.getDimension() != c){
fail("Dimension number does not match required dimension number");
@@ -224,13 +188,22 @@ public class CollectorTest {
c--;
}
collector.run();
// Wait some time to ensure that collector was able to finish processing
Thread.sleep(2000);
// Execute collector via the ExecutorService framework
// ExecutorService executor = Executors.newCachedThreadPool();
// executor.execute(collector);
// check wether messages arrive
bus.register(new Object(){
@Subscribe
public void onMessage(Message m){
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.info( x.toString() );
}
else if(m instanceof ControlMessage){
logger.info("---- "+m.toString()+" ----");
}
}
});
collector.run();
}
}

View File

@@ -74,7 +74,7 @@ public class ChannelAccessConditionTest {
public void testChannelAccessStringConditionRegex() throws InterruptedException, CAException {
final ChannelBean<String> channel = ChannelBeanFactory.getFactory().createChannelBean(String.class, TestChannels.STRING_OUT, false);
channel.setValue("SomeValue");
ChannelAccessConditionRegex<String> c = new ChannelAccessConditionRegex<String>(TestChannels.STRING_OUT, "Some.*", 1000l);
ChannelAccessConditionRegex c = new ChannelAccessConditionRegex(TestChannels.STRING_OUT, "Some.*", 1000l);
c.execute();
}

View File

@@ -18,12 +18,12 @@
*/
package ch.psi.fda.core.loops;
import java.util.logging.Logger;
//import java.util.logging.Logger;
import jcifs.smb.SmbFile;
import org.junit.Ignore;
import org.junit.Test;
//import jcifs.smb.SmbFile;
//
//import org.junit.Ignore;
//import org.junit.Test;
/**
* @author ebner
@@ -31,36 +31,36 @@ import org.junit.Test;
*/
public class SambaTest {
private static final Logger logger = Logger.getLogger(SambaTest.class.getName());
// private static final Logger logger = Logger.getLogger(SambaTest.class.getName());
@Test
public void testSamba() throws Exception{
// System.setProperty("jcifs.smb.client.dfs.disabled", "true");
// System.setProperty("jcifs.smb.client.ssnLimit", "1");
// System.setProperty("jcifs.smb.client.domain", "x05la.psi.ch");
// System.setProperty("jcifs.smb.client.username", "x05laop");
// System.setProperty("jcifs.smb.client.password", "mXAS");
// @Test
// public void testSamba() throws Exception{
//// System.setProperty("jcifs.smb.client.dfs.disabled", "true");
//// System.setProperty("jcifs.smb.client.ssnLimit", "1");
//
// System.setProperty("jcifs.util.loglevel", "6");
// System.setProperty("jcifs.smb.lmCompatibility", "0");
// jcifs.smb.client.{domain,username,password
String smbShare = "";
// smbShare = "smb://x05laop:mXAS@x05la/x05laop/Data1/otfTmp/";
// smbShare = "smb://x05la.psi.ch/x05laop/Data1/otfTmp/";
// smbShare = "smb://x05laop:mXAS@x05la/x05laop/Data1/otfTmp/000000.txt.lock";
smbShare = "smb://:@yoke.psi.ch/nfs/";
// NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("x05laop:mXAS");
// SmbFile tmpDir = new SmbFile(smbShare,auth);
// SmbFile tmpDir = new SmbFile(smbShare);
// tmpDir.createNewFile();
// logger.info(""+tmpDir.exists());
// logger.info(""+tmpDir.isDirectory());
// SmbFile tmpFile = new SmbFile(tmpDir, "000000.txt.lock");
// tmpFile.exists();
}
//// System.setProperty("jcifs.smb.client.domain", "x05la.psi.ch");
//// System.setProperty("jcifs.smb.client.username", "x05laop");
//// System.setProperty("jcifs.smb.client.password", "mXAS");
////
//// System.setProperty("jcifs.util.loglevel", "6");
//
//// System.setProperty("jcifs.smb.lmCompatibility", "0");
//
//// jcifs.smb.client.{domain,username,password
//
// String smbShare = "";
//// smbShare = "smb://x05laop:mXAS@x05la/x05laop/Data1/otfTmp/";
//// smbShare = "smb://x05la.psi.ch/x05laop/Data1/otfTmp/";
//// smbShare = "smb://x05laop:mXAS@x05la/x05laop/Data1/otfTmp/000000.txt.lock";
// smbShare = "smb://:@yoke.psi.ch/nfs/";
//// NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("x05laop:mXAS");
//// SmbFile tmpDir = new SmbFile(smbShare,auth);
//// SmbFile tmpDir = new SmbFile(smbShare);
//
//// tmpDir.createNewFile();
//// logger.info(""+tmpDir.exists());
//// logger.info(""+tmpDir.isDirectory());
//// SmbFile tmpFile = new SmbFile(tmpDir, "000000.txt.lock");
//// tmpFile.exists();
// }
}

View File

@@ -29,7 +29,6 @@ import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import ch.psi.fda.TestConfiguration;

View File

@@ -20,12 +20,10 @@
package ch.psi.fda.core.manipulator;
import static org.junit.Assert.*;
import gov.aps.jca.CAException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import org.junit.After;
@@ -33,6 +31,9 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.TestChannels;
import ch.psi.fda.core.manipulator.JythonManipulation;
import ch.psi.fda.core.manipulator.Manipulation;
@@ -40,7 +41,6 @@ import ch.psi.fda.core.manipulator.Manipulator;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.core.scripting.JythonParameterMapping;
@@ -49,21 +49,18 @@ import ch.psi.fda.core.scripting.JythonParameterMappingID;
import ch.psi.jcae.ChannelBean;
import ch.psi.jcae.ChannelBeanFactory;
/**
* @author ebner
*
*/
public class ManipulatorTest {
// Get Logger
private static Logger logger = Logger.getLogger(ManipulatorTest.class.getName());
private EventBus bus;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
bus = new EventBus();
}
/**
@@ -79,7 +76,6 @@ public class ManipulatorTest {
@Test(expected=IllegalArgumentException.class)
public void testConstructor() {
DataMessageMetadata dmm = new DataMessageMetadata();
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
String id="computedId";
String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)";
@@ -91,21 +87,14 @@ public class ManipulatorTest {
// id "myid" which is expected in the mapping
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
new Manipulator(inQueue, manipulations);
new Manipulator(bus, dmm, manipulations);
}
@Test
public void testConstructorNoMappingNoParam() {
DataMessageMetadata dmm = new DataMessageMetadata();
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process():\n return 0.0";
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
@@ -114,7 +103,7 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
new Manipulator(inQueue, manipulations);
new Manipulator(bus, dmm, manipulations);
// Expect IllegalArgument Exception as there is no mapping for the parameter c
}
@@ -123,14 +112,7 @@ public class ManipulatorTest {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
dmm.getComponents().add(new ComponentMetadata("myid2"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process():\n return 0.0";
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
@@ -139,7 +121,7 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
new Manipulator(inQueue, manipulations);
new Manipulator(bus, dmm, manipulations);
// Expect IllegalArgument Exception as there is no mapping for the parameter c
}
@@ -151,14 +133,7 @@ public class ManipulatorTest {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
dmm.getComponents().add(new ComponentMetadata("myid2"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process(o ,c):\n return math.cos(c) + math.sin(o)";
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
@@ -167,7 +142,7 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
new Manipulator(inQueue, manipulations);
new Manipulator(bus, dmm, manipulations);
// Expect IllegalArgument Exception as there is no mapping for the parameter c
}
@@ -179,13 +154,7 @@ public class ManipulatorTest {
public void testRun() throws InterruptedException {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)";
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
@@ -194,10 +163,10 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
Manipulator manipulator = new Manipulator(inQueue, manipulations);
Manipulator manipulator = new Manipulator(bus, dmm, manipulations);
// Check whether output queue message structur complies to expected one
DataMessageMetadata outMeta = manipulator.getOutQueue().getDataMessageMetadata();
DataMessageMetadata outMeta = manipulator.getMetadata();
// Test whether only the expected components are within the outgoing queue
if(outMeta.getComponents().size()!=2){
@@ -214,25 +183,29 @@ public class ManipulatorTest {
fail("Id of the second component does not match the expected id 'cid'");
}
manipulator.run();
Message message = manipulator.getOutQueue().getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(1)) - (Math.cos(10.0)+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
bus.register(new Object(){
@Subscribe
public void onMessage(Message message){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(1)) - (Math.cos(10.0)+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
}
}
}
message = manipulator.getOutQueue().getQueue().take();
}
});
EventBus b = new EventBus();
b.register(manipulator);
DataMessage m = new DataMessage();
m.getData().add(10d);
b.post(m);
b.post(new EndOfStreamMessage());
logger.info(""+(Math.cos(10.0)+Math.sin(10)));
}
@@ -245,12 +218,7 @@ public class ManipulatorTest {
public void testRunIntegerReturn() throws InterruptedException {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process(o):\n return 1";
@@ -260,10 +228,10 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
Manipulator manipulator = new Manipulator(inQueue, manipulations);
Manipulator manipulator = new Manipulator(bus, dmm, manipulations);
// Check whether output queue message structur complies to expected one
DataMessageMetadata outMeta = manipulator.getOutQueue().getDataMessageMetadata();
DataMessageMetadata outMeta = manipulator.getMetadata();
// Test whether only the expected components are within the outgoing queue
if(outMeta.getComponents().size()!=2){
@@ -280,21 +248,25 @@ public class ManipulatorTest {
fail("Id of the second component does not match the expected id 'cid'");
}
manipulator.run();
Message message = manipulator.getOutQueue().getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
bus.register(new Object(){
@Subscribe
public void onMessage(Message message){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
}
}
message = manipulator.getOutQueue().getQueue().take();
}
});
EventBus b = new EventBus();
b.register(manipulator);
DataMessage m = new DataMessage();
m.getData().add(10d);
b.post(m);
b.post(new EndOfStreamMessage());
}
/**
@@ -306,30 +278,6 @@ public class ManipulatorTest {
public void testRunLongTimeTest() throws InterruptedException {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
final DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(1000), dmm);
Thread tf = new Thread(new Runnable() {
@Override
public void run() {
try{
for(Double i=0d;i<1000000;i++){
DataMessage m = new DataMessage();
m.getData().add(i);
inQueue.getQueue().put(m);
// try {
// Thread.sleep(1);
// } catch (InterruptedException e) {
// }
}
inQueue.getQueue().put(new EndOfStreamMessage());
}
catch(InterruptedException e){
e.printStackTrace();
}
}
});
String id="cid";
String script = "import math\ndef process(o):\n return math.cos(10.0) + math.sin(o)";
@@ -339,44 +287,29 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
Manipulator manipulator = new Manipulator(inQueue, manipulations);
Manipulator manipulator = new Manipulator(bus, dmm, manipulations);
Thread t = new Thread(manipulator);
final DataQueue outQueue = manipulator.getOutQueue();
Thread tp = new Thread(new Runnable() {
@Override
public void run() {
try{
int count=0;
Message message;
while((message = outQueue.getQueue().take()) != null){
if(!(message instanceof EndOfStreamMessage)){
logger.info(count+" - "+message.toString());
}
else{
break;
}
count++;
}
}
catch (Exception e) {
e.printStackTrace();
bus.register(new Object(){
int count=0;
@Subscribe
public void onMessage(Message message){
if(!(message instanceof EndOfStreamMessage)){
logger.info(count+" - "+message.toString());
count++;
}
}
});
tf.start();
t.start();
tp.start();
tf.join();
t.join();
tp.join();
EventBus b = new EventBus();
b.register(manipulator);
for(Double i=0d;i<1000000;i++){
DataMessage m = new DataMessage();
m.getData().add(i);
b.post(m);
}
b.post(new EndOfStreamMessage());
}
/**
@@ -388,13 +321,7 @@ public class ManipulatorTest {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
dmm.getComponents().add(new ComponentMetadata("myid2"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process(o ,c):\n return math.cos(c) + math.sin(o)";
@@ -405,10 +332,10 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
Manipulator manipulator = new Manipulator(inQueue, manipulations);
Manipulator manipulator = new Manipulator(bus, dmm, manipulations);
// Check whether output queue message structur complies to expected one
DataMessageMetadata outMeta = manipulator.getOutQueue().getDataMessageMetadata();
DataMessageMetadata outMeta = manipulator.getMetadata();
// Test whether only the expected components are within the outgoing queue
if(outMeta.getComponents().size()!=3){
@@ -429,26 +356,31 @@ public class ManipulatorTest {
fail("Id of the second component does not match the expected id 'cid'");
}
manipulator.run();
Message message = manipulator.getOutQueue().getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(2)) - (Math.cos(((Double)dm.getData().get(1)))+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
bus.register(new Object(){
@Subscribe
public void onMessage(Message message){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(2)) - (Math.cos(((Double)dm.getData().get(1)))+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
}
}
}
message = manipulator.getOutQueue().getQueue().take();
}
});
EventBus b = new EventBus();
b.register(manipulator);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
b.post(m);
b.post(new EndOfStreamMessage());
logger.info(""+(Math.cos(0.2)+Math.sin(10)));
@@ -470,16 +402,9 @@ public class ManipulatorTest {
DataMessageMetadata dmm = new DataMessageMetadata();
dmm.getComponents().add(new ComponentMetadata("myid"));
dmm.getComponents().add(new ComponentMetadata("myid2"));
DataQueue inQueue = new DataQueue(new LinkedBlockingQueue<Message>(), dmm);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
inQueue.getQueue().add(m);
inQueue.getQueue().add(new EndOfStreamMessage());
String id="cid";
String script = "import math\ndef process(o ,c,d):\n d.setValue("+setValue+")\n print d.getValue()\n return math.cos(c) + math.sin(o)";
String script = "import math\ndef process(o ,c,d):\n d.setValue("+setValue+")\n return math.cos(c) + math.sin(o)";
List<JythonParameterMapping> mapping = new ArrayList<JythonParameterMapping>();
mapping.add(new JythonParameterMappingID("o", "myid"));
mapping.add(new JythonParameterMappingID("c", "myid2"));
@@ -488,10 +413,10 @@ public class ManipulatorTest {
List<Manipulation> manipulations = new ArrayList<Manipulation>();
manipulations.add(manipulation);
Manipulator manipulator = new Manipulator(inQueue, manipulations);
Manipulator manipulator = new Manipulator(bus, dmm, manipulations);
// Check whether output queue message structur complies to expected one
DataMessageMetadata outMeta = manipulator.getOutQueue().getDataMessageMetadata();
DataMessageMetadata outMeta = manipulator.getMetadata();
// Test whether only the expected components are within the outgoing queue
if(outMeta.getComponents().size()!=3){
@@ -515,25 +440,30 @@ public class ManipulatorTest {
// Change something different on the channel than the value that will be set in the manipulator script
cbean.setValue(setValue+1);
manipulator.run();
Message message = manipulator.getOutQueue().getQueue().take();
while(!(message instanceof EndOfStreamMessage)){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(2)) - (Math.cos(((Double)dm.getData().get(1)))+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
bus.register(new Object(){
@Subscribe
public void onMessage(Message message){
logger.info(message.toString());
if(message instanceof DataMessage){
DataMessage dm = (DataMessage) message;
dm.getData().get(0);
double res = ((Double)dm.getData().get(2)) - (Math.cos(((Double)dm.getData().get(1)))+Math.sin(((Double)dm.getData().get(0))));
if( Math.abs(res) > 0.000000001){
fail("Calculation failed");
}
}
}
message = manipulator.getOutQueue().getQueue().take();
}
});
EventBus b = new EventBus();
b.register(manipulator);
DataMessage m = new DataMessage();
m.getData().add(10d);
m.getData().add(0.2d);
b.post(m);
b.post(new EndOfStreamMessage());
logger.info(""+(Math.cos(0.2)+Math.sin(10)));

View File

@@ -22,18 +22,18 @@ package ch.psi.fda.deserializer;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.ControlMessage;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
/**
@@ -44,84 +44,59 @@ import ch.psi.fda.core.messages.Message;
*/
public class DataDeserializerMDATest {
// Get Logger
private static Logger logger = Logger.getLogger(DataDeserializerMDATest.class.getName());
private EventBus bus;
private DataDeserializerMDA deserializer;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
bus = new EventBus();
URL url = this.getClass().getClassLoader().getResource("testdata/mda/mdadata7.mda");
deserializer = new DataDeserializerMDA(new File(new URI(url.toString())));
deserializer = new DataDeserializerMDA(bus, new File(new URI(url.toString())));
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
/**
* Test method for {@link ch.psi.fda.deserializer.DataDeserializerTXT#run()}.
* @throws InterruptedException
*/
@Test
public void testRun() throws InterruptedException {
public void testRead() throws InterruptedException {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
BlockingQueue<Message> q = deserializer.getQueue().getQueue();
while(true){
Message m = q.take();
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.info( x.toString() );
}
else if(m instanceof ControlMessage){
if(m instanceof EndOfStreamMessage){
break;
}
logger.info("---- "+m.toString()+" ----");
}
}
StringBuilder b = new StringBuilder();
b.append("[");
StringBuilder b1 = new StringBuilder();
b1.append("[");
for(ComponentMetadata cm : deserializer.getQueue().getDataMessageMetadata().getComponents()){
b.append(" ");
b.append(cm.getId());
b1.append(" ");
b1.append(cm.getDimension());
}
b.append(" ]");
b1.append(" ]");
logger.info("Metadata "+b.toString());
logger.info("Metadata "+b1.toString());
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "An Exception occured while reading data from the data queue", e);
// Visualize metadata
StringBuilder b = new StringBuilder();
b.append("[");
StringBuilder b1 = new StringBuilder();
b1.append("[");
for(ComponentMetadata cm : deserializer.getMetadata().getComponents()){
b.append(" ");
b.append(cm.getId());
b1.append(" ");
b1.append(cm.getDimension());
}
b.append(" ]");
b1.append(" ]");
logger.info("Metadata "+b.toString());
logger.info("Metadata "+b1.toString());
// Do "read" data
bus.register(new Object(){
@Subscribe
public void onMessage(Message m){
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.info( x.toString() );
}
else if(m instanceof ControlMessage){
logger.info("---- "+m.toString()+" ----");
}
}
});
deserializer.read();
Thread tt = new Thread(deserializer);
tt.start();
t.start();
tt.join();
t.join();
}
}

View File

@@ -22,38 +22,36 @@ package ch.psi.fda.deserializer;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import ch.psi.fda.core.messages.ControlMessage;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.deserializer.DataDeserializer;
import ch.psi.fda.deserializer.DataDeserializerTXT;
/**
* @author ebner
*
*/
public class DataDeserializerTest {
// Get Logger
private static Logger logger = Logger.getLogger(DataDeserializerTest.class.getName());
private DataDeserializer deserializer;
private EventBus bus;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
bus = new EventBus();
URL url = this.getClass().getClassLoader().getResource("testdata/text/textdata2.txt");
deserializer = new DataDeserializerTXT(new File(new URI(url.toString())));
deserializer = new DataDeserializerTXT(bus, new File(new URI(url.toString())));
}
/**
@@ -70,38 +68,18 @@ public class DataDeserializerTest {
@Test
public void testRun() throws InterruptedException {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
while(true){
Message m = deserializer.getQueue().getQueue().take();
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.info( x.toString() );
}
else if(m instanceof ControlMessage){
if(m instanceof EndOfStreamMessage){
break;
}
logger.info("---- "+m.toString()+" ----");
}
}
} catch (InterruptedException e) {
logger.log(Level.SEVERE, "An Exception occured while reading data from the data queue", e);
bus.register(new Object(){
@Subscribe
public void onMessage(Message m){
if(m instanceof DataMessage){
DataMessage x = (DataMessage) m;
logger.info( x.toString() );
}
else if(m instanceof ControlMessage){
logger.info("---- "+m.toString()+" ----");
}
}
});
Thread tt = new Thread(deserializer);
tt.start();
t.start();
tt.join();
t.join();
deserializer.read();
}
}

View File

@@ -20,20 +20,18 @@
package ch.psi.fda.serializer;
import java.io.File;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.google.common.eventbus.EventBus;
import ch.psi.fda.core.messages.ComponentMetadata;
import ch.psi.fda.core.messages.DataMessage;
import ch.psi.fda.core.messages.DataMessageMetadata;
import ch.psi.fda.core.messages.DataQueue;
import ch.psi.fda.core.messages.StreamDelimiterMessage;
import ch.psi.fda.core.messages.EndOfStreamMessage;
import ch.psi.fda.core.messages.Message;
import ch.psi.fda.serializer.DataSerializer;
import ch.psi.fda.serializer.DataSerializerMAT;
import ch.psi.fda.serializer.DataSerializerMAT2D;
@@ -41,16 +39,13 @@ import ch.psi.fda.serializer.DataSerializerTXT;
import ch.psi.fda.serializer.DataSerializerTXT2D;
import ch.psi.fda.serializer.DataSerializerTXTSplit;
/**
* @author ebner
*
*/
public class DataSerializerTest {
private static final String tmpDirectory = "target/tmp";
private DataQueue queue;
private DataMessageMetadata metadata;
private EventBus bus;
/**
* @throws java.lang.Exception
@@ -58,11 +53,8 @@ public class DataSerializerTest {
@Before
public void setUp() throws Exception {
new File(tmpDirectory).mkdirs();
BlockingQueue<Message> q3 = new LinkedBlockingQueue<Message>();
DataMessageMetadata m3 = new DataMessageMetadata();
this.queue = new DataQueue(q3, m3);
metadata = new DataMessageMetadata();
bus = new EventBus();
}
/**
@@ -71,23 +63,23 @@ public class DataSerializerTest {
*/
private void generate1DData() throws InterruptedException{
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id0", 0));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id1", 0));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id2", 0));
metadata.getComponents().add(new ComponentMetadata("id0", 0));
metadata.getComponents().add(new ComponentMetadata("id1", 0));
metadata.getComponents().add(new ComponentMetadata("id2", 0));
// Dimension
DataMessage m = new DataMessage();
m.getData().add(0.000000000000000001);
m.getData().add(0.1);
m.getData().add(1d); // have this value as double
queue.getQueue().put(m);
bus.post(m);
m = new DataMessage();
m.getData().add(0.02);
m.getData().add(0.2);
m.getData().add(2d); // have this value as double
queue.getQueue().put(m);
queue.getQueue().put(new EndOfStreamMessage());
bus.post(m);
bus.post(new EndOfStreamMessage());
}
/**
@@ -96,9 +88,9 @@ public class DataSerializerTest {
*/
private void generate2DData() throws InterruptedException{
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id0", 1));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id1", 0));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id2", 0));
metadata.getComponents().add(new ComponentMetadata("id0", 1));
metadata.getComponents().add(new ComponentMetadata("id1", 0));
metadata.getComponents().add(new ComponentMetadata("id2", 0));
for(double i=0;i<5;i++){
for(double t=0.1; t<10; t=t+0.1){
@@ -107,14 +99,14 @@ public class DataSerializerTest {
m.getData().add(i);
m.getData().add(t);
m.getData().add(Math.log(t)); // have this value as double
queue.getQueue().put(m);
bus.post(m);
}
queue.getQueue().put(new StreamDelimiterMessage(0));
bus.post(new StreamDelimiterMessage(0));
}
queue.getQueue().put(new StreamDelimiterMessage(1));
bus.post(new StreamDelimiterMessage(1));
queue.getQueue().put(new EndOfStreamMessage());
bus.post(new EndOfStreamMessage());
}
/**
@@ -123,10 +115,10 @@ public class DataSerializerTest {
*/
private void generate3DData() throws InterruptedException{
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id0", 2));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id1", 1));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id2", 0));
queue.getDataMessageMetadata().getComponents().add(new ComponentMetadata("id3", 0));
metadata.getComponents().add(new ComponentMetadata("id0", 2));
metadata.getComponents().add(new ComponentMetadata("id1", 1));
metadata.getComponents().add(new ComponentMetadata("id2", 0));
metadata.getComponents().add(new ComponentMetadata("id3", 0));
for(double z=30;z<36;z++){
for(double i=0;i<6;i++){
@@ -137,16 +129,15 @@ public class DataSerializerTest {
m.getData().add(i);
m.getData().add(t);
m.getData().add(Math.log(t)); // have this value as double
queue.getQueue().put(m);
bus.post(m);
}
queue.getQueue().put(new StreamDelimiterMessage(0));
bus.post(new StreamDelimiterMessage(0));
}
queue.getQueue().put(new StreamDelimiterMessage(1));
bus.post(new StreamDelimiterMessage(1));
}
queue.getQueue().put(new StreamDelimiterMessage(2));
bus.post(new StreamDelimiterMessage(2));
queue.getQueue().put(new EndOfStreamMessage());
bus.post(new EndOfStreamMessage());
}
/**
@@ -162,9 +153,9 @@ public class DataSerializerTest {
*/
@Test
public void testRunTXT() throws InterruptedException {
DataSerializer serializer = new DataSerializerTXT(metadata, new File(tmpDirectory+"/test.txt"), true);
bus.register(serializer);
generate1DData();
DataSerializer serializer = new DataSerializerTXT(queue, new File(tmpDirectory+"/test.txt"), true);
serializer.run();
}
/**
@@ -173,9 +164,10 @@ public class DataSerializerTest {
*/
@Test
public void testRunMAT() throws InterruptedException {
DataSerializer serializer = new DataSerializerMAT(metadata, new File(tmpDirectory+"/test.mat"));
bus.register(serializer);
generate1DData();
DataSerializer serializer = new DataSerializerMAT(queue, new File(tmpDirectory+"/test.mat"));
serializer.run();
}
/**
@@ -184,9 +176,9 @@ public class DataSerializerTest {
*/
@Test
public void testRunMAT2D() throws InterruptedException {
DataSerializer serializer = new DataSerializerMAT2D(metadata, new File(tmpDirectory+"/test-2d.mat"));
bus.register(serializer);
generate2DData();
DataSerializer serializer = new DataSerializerMAT2D(queue, new File(tmpDirectory+"/test-2d.mat"));
serializer.run();
}
/**
@@ -195,9 +187,9 @@ public class DataSerializerTest {
*/
@Test
public void testRunTXT2D() throws InterruptedException {
DataSerializer serializer = new DataSerializerTXT2D(metadata, new File(tmpDirectory+"/test-2d.txt"));
bus.register(serializer);
generate2DData();
DataSerializer serializer = new DataSerializerTXT2D(queue, new File(tmpDirectory+"/test-2d.txt"));
serializer.run();
}
/**
@@ -206,9 +198,9 @@ public class DataSerializerTest {
*/
@Test
public void testRunSplitTXT() throws InterruptedException {
DataSerializer serializer = new DataSerializerTXTSplit(metadata, new File(tmpDirectory+"/test-2d-split.txt"));
bus.register(serializer);
generate2DData();
DataSerializer serializer = new DataSerializerTXTSplit(queue, new File(tmpDirectory+"/test-2d-split.txt"));
serializer.run();
}
/**
@@ -217,9 +209,9 @@ public class DataSerializerTest {
*/
@Test
public void testRun2D() throws InterruptedException {
DataSerializer serializer = new DataSerializerMDA(metadata, new File(tmpDirectory+"/test-2d.mda"));
bus.register(serializer);
generate2DData();
DataSerializer serializer = new DataSerializerMDA(queue, new File(tmpDirectory+"/test-2d.mda"));
serializer.run();
}
/**
@@ -228,8 +220,8 @@ public class DataSerializerTest {
*/
@Test
public void testRun3D() throws InterruptedException {
DataSerializer serializer = new DataSerializerMDA(metadata, new File(tmpDirectory+"/test-3d.mda"));
bus.register(serializer);
generate3DData();
DataSerializer serializer = new DataSerializerMDA(queue, new File(tmpDirectory+"/test-3d.mda"));
serializer.run();
}
}

View File

@@ -93,7 +93,7 @@ public class DataVisualizerTest {
vlist.add(p);
// Create visualizer
Visualizer visualizer = new Visualizer(queue, vlist);
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -136,7 +136,7 @@ public class DataVisualizerTest {
t.start();
visualizer.visualize();
// visualizer.visualize();
t.join();
@@ -159,7 +159,7 @@ public class DataVisualizerTest {
vlist.add(p);
// Create visualizer
Visualizer visualizer = new Visualizer(queue, vlist);
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -205,7 +205,7 @@ public class DataVisualizerTest {
t.start();
visualizer.visualize();
// visualizer.visualize();
t.join();
@@ -249,7 +249,7 @@ public class DataVisualizerTest {
vlist.add(mp);
// Create visualizer
Visualizer visualizer = new Visualizer(queue, vlist);
Visualizer visualizer = new Visualizer(queue.getDataMessageMetadata(), vlist);
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@@ -293,7 +293,7 @@ public class DataVisualizerTest {
t.start();
visualizer.visualize();
// visualizer.visualize();
t.join();

View File

@@ -0,0 +1,2 @@
/data
/logs