diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java index f617b419..51311e3f 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -16,7 +16,6 @@ package inr.numass.storage; import hep.dataforge.context.Global; -import hep.dataforge.data.binary.Binary; import hep.dataforge.exceptions.StorageException; import hep.dataforge.io.ColumnedDataReader; import hep.dataforge.io.envelopes.Envelope; @@ -29,7 +28,6 @@ import hep.dataforge.storage.loaders.AbstractLoader; import hep.dataforge.tables.Table; import hep.dataforge.values.Value; import org.apache.commons.vfs2.FileObject; -import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.VFS; import org.slf4j.LoggerFactory; @@ -38,6 +36,7 @@ import java.io.IOException; import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.nio.channels.ReadableByteChannel; import java.text.ParseException; import java.time.Instant; import java.util.*; @@ -55,7 +54,6 @@ import static org.apache.commons.vfs2.FileType.FOLDER; * @author darksnake */ public class NumassDataLoader extends AbstractLoader implements ObjectLoader, NumassData { - //FIXME administer resource release /** * The name of informational meta file in numass data directory @@ -118,11 +116,10 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader> items = new LinkedHashMap<>(); - FileObject dir = null; - try { - dir = VFS.getManager().resolveFile(url.toString()); + try (FileObject dir = VFS.getManager().resolveFile(url.toString())) { for (FileObject it : dir.getChildren()) { items.put(it.getName().getBaseName(), () -> readFile(it)); @@ -132,22 +129,13 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader events = new ArrayList<>(); - ByteBuffer buffer; - try { - buffer = Binary.readToBuffer(envelope.getData()); - } catch (IOException ex) { + + double timeCoef = envelope.meta().getDouble("time_coeff", 50); + try (ReadableByteChannel inChannel = envelope.getData().getChannel()) { + ByteBuffer buffer = ByteBuffer.allocate(7*1000); // one event is 7b + buffer.order(ByteOrder.LITTLE_ENDIAN); + while (inChannel.read(buffer) > 0) { + buffer.flip(); + while (buffer.hasRemaining()) { + short channel = (short) Short.toUnsignedInt(buffer.getShort()); + long time = Integer.toUnsignedLong(buffer.getInt()); + byte status = buffer.get(); // status is ignored + NMEvent event = new NMEvent(channel, (double) time * timeCoef * 1e-9); + events.add(event); + } + buffer.clear(); // do something with the data and clear/compact it. + } + } catch (Exception ex) { throw new RuntimeException(ex); } - buffer.position(0); - buffer.order(ByteOrder.LITTLE_ENDIAN); - double timeCoef = envelope.meta().getDouble("time_coeff", 50); - while (buffer.hasRemaining()) { - try { - short channel = (short) Short.toUnsignedInt(buffer.getShort()); - long length = Integer.toUnsignedLong(buffer.getInt()); - byte status = buffer.get(); - NMEvent event = new NMEvent(channel, (double) length * timeCoef * 1e-9); - events.add(event); - } catch (Exception ex) { - //LoggerFactory.getLogger(MainDataReader.class).error("Error in data format", ex); - throw new RuntimeException(ex); - } - } + // LocalDateTime startTime = envelope.meta().get double u = envelope.meta().getDouble("external_meta.HV1_value", 0); diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index 582ab11e..1f92a995 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -19,12 +19,14 @@ configurations { compile.exclude module: 'commons-math3' compile.exclude module: 'dataforge-fitting' compile.exclude module: 'dataforge-minuit' + compile.exclude module: 'dataforge-grind' + compile.exclude module: 'grind-terminal' } dependencies { compile project(':numass-main') - compile project(':dataforge-fx') - compile 'com.jcraft:jsch:0.1.53' + compile project(':dataforge-plots:plots-jfc') + compile 'com.jcraft:jsch:0.1.54' } shadowJar {