From 038a40dbeea374c526166c437f90f49c8c70ddca Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 8 Dec 2017 12:40:47 +0300 Subject: [PATCH] Multiple fixes to storage --- .../data/analyzers/AbstractAnalyzer.java | 6 +- .../numass/data/analyzers/SmartAnalyzer.java | 28 +--------- .../numass/data/analyzers/TimeAnalyzer.java | 32 +++++++++-- .../data/storage/NumassStorageFactory.java | 21 ++++--- .../main/resources/fxml/NumassWorkbench.fxml | 55 ------------------- .../java/inr/numass/server/ServerRunner.java | 3 +- .../java/inr/numass/server/TestServer.java | 4 +- .../kotlin/inr/numass/viewer/StorageView.kt | 5 +- .../inr/numass/viewer/test/ComponentTest.kt | 4 +- 9 files changed, 55 insertions(+), 103 deletions(-) delete mode 100644 numass-main/src/main/resources/fxml/NumassWorkbench.fxml diff --git a/numass-core/src/main/java/inr/numass/data/analyzers/AbstractAnalyzer.java b/numass-core/src/main/java/inr/numass/data/analyzers/AbstractAnalyzer.java index a8d6cf26..7f8ee9d4 100644 --- a/numass-core/src/main/java/inr/numass/data/analyzers/AbstractAnalyzer.java +++ b/numass-core/src/main/java/inr/numass/data/analyzers/AbstractAnalyzer.java @@ -18,10 +18,10 @@ import static inr.numass.data.api.NumassPoint.HV_KEY; * Created by darksnake on 11.07.2017. */ public abstract class AbstractAnalyzer implements NumassAnalyzer { - public static String WINDOW_KEY = "window"; - public static String TIME_KEY = "timestamp"; + public static final String WINDOW_KEY = "window"; + public static final String TIME_KEY = "timestamp"; - public static String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY}; + public static final String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY}; // public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY}; @Nullable private final SignalProcessor processor; diff --git a/numass-core/src/main/java/inr/numass/data/analyzers/SmartAnalyzer.java b/numass-core/src/main/java/inr/numass/data/analyzers/SmartAnalyzer.java index ef5e4391..9bb45939 100644 --- a/numass-core/src/main/java/inr/numass/data/analyzers/SmartAnalyzer.java +++ b/numass-core/src/main/java/inr/numass/data/analyzers/SmartAnalyzer.java @@ -1,11 +1,9 @@ package inr.numass.data.analyzers; -import hep.dataforge.description.ValueDef; import hep.dataforge.meta.Meta; import hep.dataforge.tables.TableFormat; import hep.dataforge.tables.ValueMap; import hep.dataforge.values.Value; -import hep.dataforge.values.ValueType; import hep.dataforge.values.Values; import inr.numass.data.api.NumassAnalyzer; import inr.numass.data.api.NumassBlock; @@ -48,7 +46,7 @@ public class SmartAnalyzer extends AbstractAnalyzer { throw new IllegalArgumentException("Analyzer not found"); } } else { - if(config.hasValue("t0")||config.hasValue("t0")){ + if(config.hasValue("t0")||config.hasMeta("t0")){ return timeAnalyzer; } else { return simpleAnalyzer; @@ -64,35 +62,11 @@ public class SmartAnalyzer extends AbstractAnalyzer { return new ValueMap(map); } - private double estimateCountRate(NumassBlock block) { - return (double) block.getEvents().count() / block.getLength().toMillis() * 1000; - } - @Override public Stream getEvents(NumassBlock block, Meta config) { return getAnalyzer(config).getEvents(block, config); } - @ValueDef(name = "t0", type = ValueType.NUMBER, info = "Constant t0 cut") - @ValueDef(name = "t0.crFraction", type = ValueType.NUMBER, info = "The relative fraction of events that should be removed by time cut") - @ValueDef(name = "t0.min", type = ValueType.NUMBER, def = "0", info = "Minimal t0") - private int getT0(NumassBlock block, Meta meta) { - if (meta.hasValue("t0")) { - return meta.getInt("t0"); - } else if (meta.hasMeta("t0")) { - double fraction = meta.getDouble("t0.crFraction"); - double cr = estimateCountRate(block); - if (cr < meta.getDouble("t0.minCR", 0)) { - return 0; - } else { - return (int) Math.max(-1e9 / cr * Math.log(1d - fraction), meta.getDouble("t0.min", 0)); - } - } else { - return 0; - } - - } - @Override protected TableFormat getTableFormat(Meta config) { if (config.hasValue(TimeAnalyzer.T0_KEY) || config.hasMeta(TimeAnalyzer.T0_KEY)) { diff --git a/numass-core/src/main/java/inr/numass/data/analyzers/TimeAnalyzer.java b/numass-core/src/main/java/inr/numass/data/analyzers/TimeAnalyzer.java index c10d4a29..9f062e59 100644 --- a/numass-core/src/main/java/inr/numass/data/analyzers/TimeAnalyzer.java +++ b/numass-core/src/main/java/inr/numass/data/analyzers/TimeAnalyzer.java @@ -1,10 +1,12 @@ package inr.numass.data.analyzers; +import hep.dataforge.description.ValueDef; import hep.dataforge.meta.Meta; import hep.dataforge.tables.TableFormat; import hep.dataforge.tables.TableFormatBuilder; import hep.dataforge.tables.ValueMap; import hep.dataforge.values.Value; +import hep.dataforge.values.ValueType; import hep.dataforge.values.Values; import inr.numass.data.api.NumassBlock; import inr.numass.data.api.NumassEvent; @@ -29,7 +31,7 @@ import static inr.numass.data.api.NumassPoint.HV_KEY; public class TimeAnalyzer extends AbstractAnalyzer { public static String T0_KEY = "t0"; - public static String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY, T0_KEY}; + public static final String[] NAME_LIST = {LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY, T0_KEY}; // public static String[] NAME_LIST_WITH_HV = {HV_KEY, LENGTH_KEY, COUNT_KEY, COUNT_RATE_KEY, COUNT_RATE_ERROR_KEY, WINDOW_KEY, TIME_KEY, T0_KEY}; public TimeAnalyzer(@Nullable SignalProcessor processor) { @@ -81,7 +83,9 @@ public class TimeAnalyzer extends AbstractAnalyzer { @Override public Values analyzePoint(NumassPoint point, Meta config) { //Average count rates, do not sum events - Values res = point.getBlocks().map(it -> analyze(it, config)).reduce(null, this::combineBlockResults); + Values res = point.getBlocks() + .map(it -> analyze(it, config)) + .reduce(null, this::combineBlockResults); Map map = new HashMap<>(res.asMap()); map.put(HV_KEY, Value.of(point.getVoltage())); @@ -127,8 +131,28 @@ public class TimeAnalyzer extends AbstractAnalyzer { ); } - private long getT0(NumassBlock block, Meta config) { - return config.getValue("t0", 0).longValue(); + @ValueDef(name = "t0", type = ValueType.NUMBER, info = "Constant t0 cut") + @ValueDef(name = "t0.crFraction", type = ValueType.NUMBER, info = "The relative fraction of events that should be removed by time cut") + @ValueDef(name = "t0.min", type = ValueType.NUMBER, def = "0", info = "Minimal t0") + private int getT0(NumassBlock block, Meta meta) { + if (meta.hasValue("t0")) { + return meta.getInt("t0"); + } else if (meta.hasMeta("t0")) { + double fraction = meta.getDouble("t0.crFraction"); + double cr = estimateCountRate(block); + if (cr < meta.getDouble("t0.minCR", 0)) { + return 0; + } else { + return (int) Math.max(-1e9 / cr * Math.log(1d - fraction), meta.getDouble("t0.min", 0)); + } + } else { + return 0; + } + + } + + private double estimateCountRate(NumassBlock block) { + return (double) block.getEvents().count() / block.getLength().toMillis() * 1000; } /** diff --git a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java index bc6a7505..408437b2 100644 --- a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java +++ b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java @@ -2,11 +2,12 @@ package inr.numass.data.storage; import com.github.robtimus.filesystems.sftp.SFTPEnvironment; import hep.dataforge.context.Context; -import hep.dataforge.context.Global; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.api.StorageType; +import hep.dataforge.storage.commons.StorageManager; +import hep.dataforge.storage.filestorage.FileStorage; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -28,13 +29,9 @@ public class NumassStorageFactory implements StorageType { * @return */ @NotNull - public static NumassStorage buildLocal(File file, boolean monitor) { - Path path = file.toPath(); - Meta meta = new MetaBuilder("storage") - .setValue("path", path) - .setValue("monitor", monitor); - - return new NumassStorage(Global.instance(), meta, path); + public static FileStorage buildLocal(Context context, File file, boolean readOnly, boolean monitor) { + StorageManager manager = context.loadFeature("hep.dataforge:storage", StorageManager.class); + return (FileStorage) manager.buildStorage(buildStorageMeta(file.toURI(),readOnly,monitor)); } @Override @@ -70,4 +67,12 @@ public class NumassStorageFactory implements StorageType { return new NumassStorage(context, meta, context.getIo().getWorkDirectory()); } } + + public static MetaBuilder buildStorageMeta(URI path, boolean readOnly, boolean monitor) { + return new MetaBuilder("storage") + .setValue("path", path.toString()) + .setValue("type", "numass") + .setValue("readOnly", readOnly) + .setValue("monitor", monitor); + } } diff --git a/numass-main/src/main/resources/fxml/NumassWorkbench.fxml b/numass-main/src/main/resources/fxml/NumassWorkbench.fxml deleted file mode 100644 index e92e7e88..00000000 --- a/numass-main/src/main/resources/fxml/NumassWorkbench.fxml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - -
- - - - - - - - -