From 5cf68cc21f0585537f5c993fd881b74fb30c4149 Mon Sep 17 00:00:00 2001 From: darksnake Date: Thu, 9 Feb 2017 16:23:00 +0300 Subject: [PATCH] numass fixes --- .../inr/numass/utils/UnderflowCorrection.java | 2 +- .../java/inr/numass/server/NumassServer.java | 4 +-- .../inr/numass/storage/NumassDataLoader.java | 21 +++++-------- .../inr/numass/storage/NumassStorage.java | 30 +++++++++++-------- .../inr/numass/scripts/TestServer.groovy | 15 +++++----- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/numass-main/src/main/java/inr/numass/utils/UnderflowCorrection.java b/numass-main/src/main/java/inr/numass/utils/UnderflowCorrection.java index c8ddbd7b..4bb914d5 100644 --- a/numass-main/src/main/java/inr/numass/utils/UnderflowCorrection.java +++ b/numass-main/src/main/java/inr/numass/utils/UnderflowCorrection.java @@ -68,7 +68,7 @@ public class UnderflowCorrection { double sigma = fitRes[1]; //builder.row(point.getUset(), a, sigma, (a * sigma * (Math.exp(xLow / sigma) - 1) - a*xLow) / norm + 1d); - builder.row(point.getUset(), a, sigma, a * sigma * (Math.exp(xLow / sigma) - 1) / norm + 1d); + builder.row(point.getUset(), a, sigma, a * sigma * (Math.exp(xLow / sigma)) / norm + 1d); } return builder.build(); } diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java index b45b2031..bd033746 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassServer.java @@ -49,8 +49,8 @@ public class NumassServer extends AbstractNetworkListener { private StateLoader rootState; private NumassRun run; - public NumassServer(FileStorage storage, Meta listnerConfig) { - super(listnerConfig); + public NumassServer(FileStorage storage, Meta listenerConfig) { + super(listenerConfig); init(storage); } 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 51311e3f..cb4045fd 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -184,7 +184,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader events = new ArrayList<>(); double timeCoef = envelope.meta().getDouble("time_coeff", 50); @@ -283,32 +283,27 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader stream() { - return this.getPoints().stream().parallel().map(this::readPoint); + return this.getPoints().map(this::readPoint); } public List getNMPoints(Function transformation) { - return this.getPoints().stream().parallel().map(env -> readPoint(env, transformation)).collect(Collectors.toList()); + return this.getPoints().map(env -> readPoint(env, transformation)).collect(Collectors.toList()); } public List getRawPoints() { - return this.getPoints().stream().parallel().map(this::readRawPoint).collect(Collectors.toList()); + return this.getPoints().map(this::readRawPoint).collect(Collectors.toList()); } - private List getPoints() { + private Stream getPoints() { return getItems().entrySet().stream() .filter(entry -> entry.getKey().startsWith(POINT_FRAGMENT_NAME) && entry.getValue() != null) .map(entry -> entry.getValue().get()) - .sorted((Envelope t, Envelope t1) - -> t.meta().getInt("external_meta.point_index", -1).compareTo(t1.meta().getInt("external_meta.point_index", -1))) - .collect(Collectors.toList()); + .sorted(Comparator.comparing(t -> t.meta().getInt("external_meta.point_index", -1))); + } public boolean isReversed() { - //TODO replace by meta tag in later revisions - return SetDirectionUtility.isReversed(getPath(), n -> { - List points = getPoints(); - return getPoints().size() >= 2 && readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta())); - }); + return meta().getBoolean("iteration_info.reverse", false); } @Override diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java b/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java index 4116d007..49b589f8 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java @@ -56,6 +56,17 @@ public class NumassStorage extends FileStorage { public static final String NUMASS_DATA_LOADER_TYPE = "numassData"; public static final String GROUP_META_FILE = "numass_group_meta"; + protected NumassStorage(FileStorage parent, String path, Meta config) throws StorageException { + super(parent, path, config); + super.refresh(); + //TODO read meta from numass_group_meta to .numass element + } + + protected NumassStorage(FileObject dir, Meta config) throws StorageException { + super(dir, config); + super.refresh(); + } + /** * Create root numass storage * @@ -64,18 +75,22 @@ public class NumassStorage extends FileStorage { * @return * @throws StorageException */ - public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException { + public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly, boolean monitor) throws StorageException { try { Meta meta = new MetaBuilder("storage") .setValue("type", "file.numass") .setValue("readOnly", readOnly) - .setValue("monitor", false); + .setValue("monitor", monitor); return new NumassStorage(VFSUtils.getLocalFile(dir), meta); } catch (FileSystemException ex) { throw new RuntimeException(ex); } } + public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException { + return buildLocalNumassRoot(dir, readOnly, false); + } + public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException { try { Meta meta = new MetaBuilder("storage") @@ -120,17 +135,6 @@ public class NumassStorage extends FileStorage { } } - protected NumassStorage(FileStorage parent, String path, Meta config) throws StorageException { - super(parent, path, config); - super.refresh(); - //TODO read meta from numass_group_meta to .numass element - } - - protected NumassStorage(FileObject dir, Meta config) throws StorageException { - super(dir, config); - super.refresh(); - } - @Override protected void updateDirectoryLoaders() { try { diff --git a/numass-storage/test/src/main/groovy/inr/numass/scripts/TestServer.groovy b/numass-storage/test/src/main/groovy/inr/numass/scripts/TestServer.groovy index aca62a18..11928384 100644 --- a/numass-storage/test/src/main/groovy/inr/numass/scripts/TestServer.groovy +++ b/numass-storage/test/src/main/groovy/inr/numass/scripts/TestServer.groovy @@ -15,27 +15,26 @@ */ package inr.numass.scripts -import hep.dataforge.storage.filestorage.VFSUtils +import hep.dataforge.meta.Meta import inr.numass.server.NumassServer import inr.numass.storage.NumassStorage -import org.apache.commons.vfs2.FileObject -String path = "D:\\temp\\test\\numass\\" +String path = "D:\\Work\\Numass\\data\\2016_10\\" -FileObject file = VFSUtils.getLocalFile(new File(path)) +//FileObject file = VFSUtils.getLocalFile(new File(path)) -NumassStorage storage = new NumassStorage(file,null) +NumassStorage storage = NumassStorage.buildLocalNumassRoot(new File(path), true, true); -println "Starting test numass listener in "+path +println "Starting test numass listener in " + path -NumassServer listener = new NumassServer(storage, null); +NumassServer listener = new NumassServer(storage, Meta.empty()); listener.open() String stopLine = ""; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) -while(stopLine == null || !stopLine.startsWith("exit")){ +while (stopLine == null || !stopLine.startsWith("exit")) { // print ">" stopLine = br.readLine(); }