1 Commits

Author SHA1 Message Date
ebner ed35d4c922 Some performance test changes 2014-03-18 13:56:47 +01:00
3 changed files with 85 additions and 42 deletions
@@ -96,22 +96,10 @@ public class Fdaq {
out.write(bytebuffer.array()); out.write(bytebuffer.array());
out.flush(); out.flush();
final List<Metadata> metadata = new ArrayList<>();
metadata.add(new Metadata("counter"));
metadata.add(new Metadata("ain1"));
metadata.add(new Metadata("ain2"));
metadata.add(new Metadata("ain3"));
metadata.add(new Metadata("ain4"));
metadata.add(new Metadata("enc1"));
int index=0;
for (int t = 0; t < numberOfElements; t++) { for (int t = 0; t < numberOfElements; t++) {
// struct fdaqbloc_out {int trigindex;int adc1reg;int // struct fdaqbloc_out {int trigindex;int adc1reg;int
// adc2reg;int encoder;}; // adc2reg;int encoder;};
ByteBuffer buffer = ByteBuffer.allocate(4 * 4); // 4 times ByteBuffer buffer = ByteBuffer.allocate(4 * 4); // 4 times Integers
// Integers
buffer.order(ByteOrder.LITTLE_ENDIAN);
int r = in.read(buffer.array()); int r = in.read(buffer.array());
if (r == -1) { if (r == -1) {
logger.info("End of Stream"); logger.info("End of Stream");
@@ -124,33 +112,8 @@ public class Fdaq {
// This is independent of the frequency // This is independent of the frequency
continue; continue;
} }
bus.post(buffer);
int a = buffer.getInt();
int b = buffer.getInt();
int b1 = b & 0xffff;
int b2 = (b >> 16) & 0xffff;
int c = buffer.getInt();
int c1 = c & 0xffff;
int c2 = (c >> 16) & 0xffff;
int d = buffer.getInt();
DataMessage message = new DataMessage(metadata);
message.getData().add(a);
message.getData().add(b1);
message.getData().add(b2);
message.getData().add(c1);
message.getData().add(c2);
message.getData().add(d);
bus.post(message);
if(t==0){
logger.info("index: "+a);
} }
index=a;
}
logger.info("Done ..."+index);
} catch (IOException e) { } catch (IOException e) {
// Ignore potential exceptions if stop was triggered before all messages were retrieved // Ignore potential exceptions if stop was triggered before all messages were retrieved
if (!stopAcquisition) { if (!stopAcquisition) {
@@ -168,7 +131,7 @@ public class Fdaq {
} }
bus.post(new EndOfStreamMessage()); // bus.post(new EndOfStreamMessage());
} }
/** /**
@@ -0,0 +1,74 @@
/**
*
* Copyright 2014 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.fdaq;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.List;
import ch.psi.fda.messages.DataMessage;
import ch.psi.fda.messages.Metadata;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
/**
* Does the bit shuffle required for fdaq.
*/
public class FdaqBitShuffle {
private final EventBus bus;
private final List<Metadata> metadata;
public FdaqBitShuffle(EventBus bus){
this.bus = bus;
metadata = new ArrayList<>();
metadata.add(new Metadata("counter"));
metadata.add(new Metadata("ain1"));
metadata.add(new Metadata("ain2"));
metadata.add(new Metadata("ain3"));
metadata.add(new Metadata("ain4"));
metadata.add(new Metadata("enc1"));
}
@Subscribe
public void shuffle(ByteBuffer buffer){
buffer.order(ByteOrder.LITTLE_ENDIAN);
int a = buffer.getInt();
int b = buffer.getInt();
int b1 = b & 0xffff;
int b2 = (b >> 16) & 0xffff;
int c = buffer.getInt();
int c1 = c & 0xffff;
int c2 = (c >> 16) & 0xffff;
int d = buffer.getInt();
DataMessage message = new DataMessage(metadata);
message.getData().add(a);
message.getData().add(b1);
message.getData().add(b2);
message.getData().add(c1);
message.getData().add(c2);
message.getData().add(d);
bus.post(message);
}
}
@@ -23,6 +23,7 @@ import java.util.concurrent.Executors;
import sun.misc.Signal; import sun.misc.Signal;
import sun.misc.SignalHandler; import sun.misc.SignalHandler;
import ch.psi.fda.messages.EndOfStreamMessage;
import ch.psi.fda.serializer.SerializerTXT; import ch.psi.fda.serializer.SerializerTXT;
import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.AsyncEventBus;
@@ -55,14 +56,19 @@ public class FdaqMain {
} }
EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor()); EventBus busA = new AsyncEventBus(Executors.newSingleThreadExecutor());
final Fdaq fdaq = new Fdaq(bus, configuration); final EventBus bus = new AsyncEventBus(Executors.newSingleThreadExecutor());
final Fdaq fdaq = new Fdaq(busA, configuration);
final FdaqBitShuffle bshuffle= new FdaqBitShuffle(bus);
busA.register(bshuffle);
Signal.handle(new Signal("INT"), new SignalHandler() { Signal.handle(new Signal("INT"), new SignalHandler() {
int count = 0; int count = 0;
public void handle(Signal sig) { public void handle(Signal sig) {
if(count < 1){ if(count < 1){
fdaq.stop(); fdaq.stop();
bus.post(new EndOfStreamMessage());
count++; count++;
return; return;
} }