From 3dc2d4c7daee763155597953d07137ff8b424f41 Mon Sep 17 00:00:00 2001 From: Simon Ebner Date: Tue, 16 Apr 2013 09:24:48 +0200 Subject: [PATCH] minor changes --- .../java/ch/psi/fdaq/FdaqConfiguration.java | 31 +++++++----- .../main/java/ch/psi/fdaq/FdaqService.java | 50 ++++++++++++------- .../java/ch/psi/fdaq/SocketClientStop.java | 2 +- 3 files changed, 51 insertions(+), 32 deletions(-) diff --git a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqConfiguration.java b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqConfiguration.java index ad0802f..f7c2569 100644 --- a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqConfiguration.java +++ b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqConfiguration.java @@ -19,6 +19,7 @@ package ch.psi.fdaq; +import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; @@ -38,7 +39,7 @@ public class FdaqConfiguration { private String hostname = "mchip015.psi.ch"; private int port = 2233; private int killPort = 2234; - private int nelements = Integer.MAX_VALUE; + private int nelements = Integer.MAX_VALUE/2; private String filePrefix = "${yyyy_MM}/${yyyyMMdd}/${yyyyMMddHHmmss}_${name}/${yyyyMMddHHmm}_"; private String dataDirectory; @@ -57,19 +58,23 @@ public class FdaqConfiguration { throw new RuntimeException("No configuration file specified via -D"+FdaqService.APP_HOME+"=..."); } - Properties properties = new Properties(); - try { - properties.load(new FileReader(config+"/config/fdaq.properties")); - } catch (FileNotFoundException e) { - throw new RuntimeException("Configuration file "+config+" not found", e); - } catch (IOException e) { - throw new RuntimeException("Cannot read configuration file "+config, e); + File cfile = new File(config+"/config/fdaq.properties"); + if(cfile.exists()){ + Properties properties = new Properties(); + try { + properties.load(new FileReader(cfile)); + } catch (FileNotFoundException e) { + throw new RuntimeException("Configuration file "+config+" not found", e); + + } catch (IOException e) { + throw new RuntimeException("Cannot read configuration file "+config, e); + } + + hostname = properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".hostname", "mchip015.psi.ch"); + port = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".port", "2233")); + killPort = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".killPort", "2234")); + dataDirectory = config+"/data"; } - - hostname = properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".hostname", "mchip015.psi.ch"); - port = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".port", "2233")); - killPort = Integer.parseInt(properties.getProperty(FdaqConfiguration.class.getPackage().getName()+".killPort", "2234")); - dataDirectory = config+"/data"; } public String getHostname() { diff --git a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqService.java b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqService.java index e33ad57..86750bb 100644 --- a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqService.java +++ b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/FdaqService.java @@ -76,6 +76,7 @@ public class FdaqService { // open file and write + logger.info("Open file: "+file.getAbsolutePath()); writer = new PrintWriter(new BufferedWriter(new FileWriter(file))); writer.println("# a" + "\t" + "b1" + "\t" + "b2" + "\t" + "c1" + "\t" + "c2" + "\t" + "d"); @@ -100,8 +101,12 @@ public class FdaqService { int c2 = (c >> 16) & 0xffff; int d = buffer.getInt(); -// System.out.println(a + " " + b1 + " " + b2 + " " + c1 + " " + c2 + " " + d); + logger.info(a + " " + b1 + " " + b2 + " " + c1 + " " + c2 + " " + d); writer.println(a + "\t" + b1 + "\t" + b2 + "\t" + c1 + "\t" + c2 + "\t" + d); + + if(t%100==0){ // flush at least every hundered messages + writer.flush(); + } } writer.close(); @@ -128,25 +133,34 @@ public class FdaqService { t.start(); } - public void stopAcquistion() { - try { - stopAcquisition=true; - FdaqConfiguration c = FdaqConfiguration.getInstance(); - Socket echoSocket = new Socket(c.getHostname(), c.getKillPort()); - DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream()); + public void stopAcquisition() { + Thread t = new Thread(new Runnable() { - ByteBuffer bytebuffer = ByteBuffer.allocate(1 * 4); // 2 times - // Integers - bytebuffer.order(ByteOrder.LITTLE_ENDIAN); - bytebuffer.putInt(666); - out.write(bytebuffer.array()); - out.flush(); + @Override + public void run() { + try { + stopAcquisition = true; + FdaqConfiguration c = FdaqConfiguration.getInstance(); + Socket echoSocket = new Socket(c.getHostname(), c.getKillPort()); + DataOutputStream out = new DataOutputStream(echoSocket.getOutputStream()); - out.close(); - echoSocket.close(); - } catch (IOException e) { - logger.log(Level.SEVERE, "", e); - } + ByteBuffer bytebuffer = ByteBuffer.allocate(1 * 4); // 2 + // times + // Integers + bytebuffer.order(ByteOrder.LITTLE_ENDIAN); + bytebuffer.putInt(666); + out.write(bytebuffer.array()); + out.flush(); + + out.close(); + echoSocket.close(); + } catch (IOException e) { + logger.log(Level.SEVERE, "", e); + } + } + }); + t.start(); } + } diff --git a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/SocketClientStop.java b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/SocketClientStop.java index 46045f5..b9fe059 100644 --- a/ch.psi.fdaq/src/main/java/ch/psi/fdaq/SocketClientStop.java +++ b/ch.psi.fdaq/src/main/java/ch/psi/fdaq/SocketClientStop.java @@ -33,7 +33,7 @@ public class SocketClientStop { /** * Requires connection to: - * ssh -L9999:mchip015:2234 x10da-gw + * ssh -L9998:mchip015:2234 x10da-gw * * @param args * @throws IOException