From 1177bdfa6c8fdbe13ac922effbf9ab4e1148bc27 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 19 Sep 2016 22:56:24 +0300 Subject: [PATCH] Fixes for numass-viewer --- .../inr/numass/server/NumassRootHandler.java | 12 +++-- .../inr/numass/storage/NumassDataLoader.java | 2 +- .../inr/numass/storage/NumassStorage.java | 9 ++++ numass-viewer/build.gradle | 2 +- .../inr/numass/viewer/MspViewController.java | 53 ++++++++++--------- .../src/main/resources/fxml/MainView.fxml | 22 ++------ 6 files changed, 49 insertions(+), 51 deletions(-) diff --git a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java index 516393d6..78d4e8e3 100644 --- a/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java +++ b/numass-storage/numass-server/src/main/java/inr/numass/server/NumassRootHandler.java @@ -12,14 +12,16 @@ import hep.dataforge.storage.api.StateLoader; import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.commons.JSONMetaWriter; import hep.dataforge.storage.servlet.Utils; -import static inr.numass.server.HandlerUtils.renderStates; -import java.io.StringWriter; -import java.util.HashMap; -import java.util.Map; import org.slf4j.LoggerFactory; import ratpack.handling.Context; import ratpack.handling.Handler; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; + +import static inr.numass.server.HandlerUtils.renderStates; + /** * * @author Alexander Nozik @@ -98,7 +100,7 @@ public class NumassRootHandler implements Handler { } private void renderLoader(Context ctx, StringBuilder b, Loader loader) { - String href = "/storage?path=" + loader.getFullPath(); + String href = "/storage?path=" + loader.getPath(); b.append(String.format("

%s (%s)

", href, loader.getName(), loader.getType())); } } 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 b3b24e1e..b2084225 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -311,7 +311,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader { + return SetDirectionUtility.isReversed(getPath(), n -> { List points = getPoints(); if (getPoints().size() >= 2) { return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta())); 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 0b5bb966..6e5a2e66 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java @@ -20,8 +20,10 @@ import hep.dataforge.events.EventBuilder; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.storage.filestorage.FilePointLoader; import hep.dataforge.storage.filestorage.FileStorage; import hep.dataforge.storage.filestorage.VFSUtils; +import org.apache.commons.io.FilenameUtils; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileType; @@ -146,6 +148,13 @@ public class NumassStorage extends FileStorage { } } else if (file.getName().toString().endsWith(NUMASS_ZIP_EXTENSION)) { this.loaders.put(file.getName().getBaseName(), NumassDataLoader.fromZip(this, file)); + } else if (file.getName().toString().endsWith(".points")) { + try { + loaders.put(FilenameUtils.getBaseName(file.getName().getBaseName()), + FilePointLoader.fromFile(this, file, true)); + } catch (Exception ex) { + getContext().getLogger().error("Failed to build numass point loader from file {}", file.getName()); + } } else { //updating non-numass loader files updateFile(file); diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index a10f8112..9bb52c60 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -5,7 +5,7 @@ if (!hasProperty('mainClass')) { } mainClassName = mainClass -version = "0.3.4" +version = "0.3.5" description = "The viewer for numass data" diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java index 5cddebe9..5a0ec03b 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MspViewController.java @@ -23,7 +23,7 @@ package inr.numass.viewer; import hep.dataforge.computation.ProgressCallback; import hep.dataforge.context.Context; -import hep.dataforge.exceptions.StorageException; +import hep.dataforge.names.Name; import hep.dataforge.plots.PlotUtils; import hep.dataforge.plots.data.DynamicPlottable; import hep.dataforge.plots.data.DynamicPlottableSet; @@ -31,6 +31,7 @@ import hep.dataforge.plots.fx.PlotContainer; import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.storage.api.PointLoader; import hep.dataforge.storage.api.Storage; +import hep.dataforge.storage.commons.StorageUtils; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.MapPoint; import hep.dataforge.values.Value; @@ -88,17 +89,23 @@ public class MspViewController { public void fillMspData(Storage rootStorage) { if (rootStorage != null) { context.taskManager().submit("viewer.msp.fill", (ProgressCallback callback) -> { - try { -// callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")"); + // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")"); - callback.updateTitle("Load msp data (" + rootStorage.getName() + ")"); - List mspData = new ArrayList<>(); - DataPoint last = null; - for (String loaderName : rootStorage.loaders().keySet()) { - if (loaderName.startsWith("msp")) { - try (final PointLoader mspLoader = (PointLoader) rootStorage.getLoader(loaderName)) { + callback.updateTitle("Load msp data (" + rootStorage.getName() + ")"); + + List mspData = new ArrayList<>(); + + StorageUtils.loaderStream(rootStorage) + .filter(pair -> pair.getValue() instanceof PointLoader) + .filter(pair -> Name.of(pair.getKey()).getLast().toString().startsWith("msp")) + .map(pair -> pair.getValue()) + .filter(loader -> PointLoader.POINT_LOADER_TYPE.equals(loader.getType())) + .forEach(loader -> { + try { + PointLoader mspLoader = (PointLoader) loader; mspLoader.open(); callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName()); + DataPoint last = null; for (DataPoint dp : mspLoader) { mspData.add(dp); last = dp; @@ -109,30 +116,26 @@ public class MspViewController { } catch (Exception ex) { LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex); } - } - } - callback.updateMessage("Loading msp data finished"); + }); + callback.updateMessage("Loading msp data finished"); // return mspData; // List mspData = (List) loadProcess.getTask().get(); - if (!mspData.isEmpty()) { - DynamicPlottableSet plottables = new DynamicPlottableSet(); + if (!mspData.isEmpty()) { + DynamicPlottableSet plottables = new DynamicPlottableSet(); - for (DataPoint point : mspData) { - for (String name : point.names()) { - if (!name.equals("timestamp")) { - if (!plottables.hasPlottable(name)) { - plottables.addPlottable(new DynamicPlottable(name, name)); - } + for (DataPoint point : mspData) { + for (String name : point.names()) { + if (!name.equals("timestamp")) { + if (!plottables.hasPlottable(name)) { + plottables.addPlottable(new DynamicPlottable(name, name)); } } - plottables.put(point); } - - updateMspPane(plottables); + plottables.put(point); } - } catch (StorageException ex) { - throw new RuntimeException(ex); + + updateMspPane(plottables); } }); } diff --git a/numass-viewer/src/main/resources/fxml/MainView.fxml b/numass-viewer/src/main/resources/fxml/MainView.fxml index bcf314de..73af8da1 100644 --- a/numass-viewer/src/main/resources/fxml/MainView.fxml +++ b/numass-viewer/src/main/resources/fxml/MainView.fxml @@ -16,29 +16,13 @@ See the License for the specific language governing permissions and limitations under the License. --> - - + - - - - - - - - - - - - - - - - - +