[no commit message]

This commit is contained in:
Alexander Nozik 2016-04-23 19:12:55 +03:00
parent b6323d2f90
commit 70ee806674
5 changed files with 127 additions and 177 deletions

View File

@ -5,13 +5,13 @@ if (!hasProperty('mainClass')) {
} }
mainClassName = mainClass mainClassName = mainClass
version = "0.2.5" version = "0.3.0"
description = "The viewer for numass data" description = "The viewer for numass data"
dependencies { dependencies {
compile project(':numass-main') compile project(':numass-main')
compile project(':dataforge-storage') // compile project(':dataforge-storage')
compile project(':numass-storage') compile project(':numass-storage')
compile project(':dataforge-fx') compile project(':dataforge-fx')
compile 'com.jcraft:jsch:0.1.53' compile 'com.jcraft:jsch:0.1.53'

View File

@ -27,11 +27,9 @@ import java.io.File;
import java.net.URL; import java.net.URL;
import java.util.Optional; import java.util.Optional;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.Initializable; import javafx.fxml.Initializable;
@ -150,50 +148,22 @@ public class MainViewerController implements Initializable {
}); });
} }
private class DirectoryLoadTask extends Task<Void> {
private final String uri;
public DirectoryLoadTask(String uri) {
this.uri = uri;
}
@Override
protected Void call() throws Exception {
updateTitle("Load storage (" + uri + ")");
updateProgress(-1, 1);
updateMessage("Building numass storage tree...");
try {
NumassStorage root = NumassStorage.buildNumassRoot(uri, true, false);
setRootStorage(root);
Platform.runLater(() -> storagePathLabel.setText("Storage: " + uri));
} catch (StorageException ex) {
updateProgress(0, 1);
updateMessage("Failed to load storage " + uri);
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
}
private Context getContext() { private Context getContext() {
return GlobalContext.instance(); return GlobalContext.instance();
} }
public void setRootStorage(NumassStorage root) { public void setRootStorage(NumassStorage root) {
// Task fillTask = new StorageDataFillTask(root);
// postTask(fillTask);
// Viewer.runTask(fillTask);
getContext().processManager().post("viewer.storage.load", new Consumer<ProcessManager.Callback>() { getContext().processManager().cleanup();
@Override getContext().processManager().post("viewer.storage.load", (ProcessManager.Callback callback) -> {
public void accept(ProcessManager.Callback callback) {
callback.updateTitle("Fill data to UI (" + root.getName() + ")"); callback.updateTitle("Fill data to UI (" + root.getName() + ")");
callback.updateProgress(-1, 1); // callback.updateProgress(-1, 1);
Platform.runLater(() -> statusBar.setProgress(-1));
callback.updateMessage("Loading numass storage tree..."); callback.updateMessage("Loading numass storage tree...");
new NumassLoaderTreeBuilder().build(getContext(), numassLoaderDataTree, root, (NumassData loader) -> { try {
new NumassLoaderTreeBuilder().build(callback, numassLoaderDataTree, root, (NumassData loader) -> {
NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext()); NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext());
component.loadData(loader); component.loadData(loader);
numassLoaderViewContainer.getChildren().clear(); numassLoaderViewContainer.getChildren().clear();
@ -204,13 +174,14 @@ public class MainViewerController implements Initializable {
AnchorPane.setBottomAnchor(component, 0.0); AnchorPane.setBottomAnchor(component, 0.0);
numassLoaderViewContainer.requestLayout(); numassLoaderViewContainer.requestLayout();
}); });
} catch (StorageException ex) {
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
}
callback.updateProgress(0, 1); // callback.updateProgress(1, 1);
Platform.runLater(() -> statusBar.setProgress(0));
callback.updateMessage("Numass storage tree loaded."); callback.updateMessage("Numass storage tree loaded.");
});
}
}
);
mspController = new MspViewController(getContext(), mspPlotPane); mspController = new MspViewController(getContext(), mspPlotPane);
mspController.fillMspData(root); mspController.fillMspData(root);

View File

@ -21,6 +21,9 @@ package inr.numass.viewer;
* and open the template in the editor. * and open the template in the editor.
*/ */
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.context.DFProcess;
import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.points.DataPoint; import hep.dataforge.points.DataPoint;
import hep.dataforge.points.MapPoint; import hep.dataforge.points.MapPoint;
import hep.dataforge.plots.PlotUtils; import hep.dataforge.plots.PlotUtils;
@ -33,9 +36,11 @@ import hep.dataforge.storage.api.Storage;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.StreamSupport; import java.util.stream.StreamSupport;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -46,7 +51,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class MspViewController { public class MspViewController {
private final AnchorPane mspPlotPane; private final AnchorPane mspPlotPane;
private final Context context; private final Context context;
@ -75,8 +79,8 @@ public class MspViewController {
PlotUtils.setXAxis(frame, "time", null, "time"); PlotUtils.setXAxis(frame, "time", null, "time");
StreamSupport.stream(mspData.spliterator(), false) StreamSupport.stream(mspData.spliterator(), false)
.sorted((DynamicPlottable o1, DynamicPlottable o2) -> .sorted((DynamicPlottable o1, DynamicPlottable o2)
Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl)); -> Integer.valueOf(o1.getName()).compareTo(Integer.valueOf(o2.getName()))).forEach((pl) -> frame.add(pl));
Platform.runLater(() -> { Platform.runLater(() -> {
PlotContainer container = PlotContainer.anchorTo(mspPlotPane); PlotContainer container = PlotContainer.anchorTo(mspPlotPane);
container.setPlot(frame); container.setPlot(frame);
@ -85,32 +89,35 @@ public class MspViewController {
public void fillMspData(Storage rootStorage) { public void fillMspData(Storage rootStorage) {
if (rootStorage != null) { if (rootStorage != null) {
MspDataFillTask fillTask = new MspDataFillTask(rootStorage); context.processManager().post("viewer.msp.fill", (ProcessManager.Callback callback) -> {
if (callback != null) { try {
callback.postTask(fillTask); // callback.updateTitle("Fill msp data (" + rootStorage.getName() + ")");
callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
List<DataPoint> mspData = new ArrayList<>();
DataPoint last = null;
for (String loaderName : rootStorage.loaders().keySet()) {
if (loaderName.startsWith("msp")) {
try (final PointLoader mspLoader = (PointLoader) rootStorage.getLoader(loaderName)) {
mspLoader.open();
callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
for (DataPoint dp : mspLoader.asDataSet()) {
mspData.add(dp);
last = dp;
} }
Viewer.runTask(fillTask); if (last != null) {
mspData.add(terminatorPoint(last));
}
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
} }
} }
private class MspDataFillTask extends Task<Void> {
private final Storage storage;
public MspDataFillTask(Storage storage) {
this.storage = storage;
} }
callback.updateMessage("Loading msp data finished");
// return mspData;
// List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
@Override if (!mspData.isEmpty()) {
protected Void call() throws Exception {
updateTitle("Fill msp data (" + storage.getName() + ")");
MspDataLoadTask loadTask = new MspDataLoadTask(storage);
if (callback != null) {
callback.postTask(loadTask);
}
Viewer.runTask(loadTask);
List<DataPoint> mspData = loadTask.get();
DynamicPlottableSet plottables = new DynamicPlottableSet(); DynamicPlottableSet plottables = new DynamicPlottableSet();
for (DataPoint point : mspData) { for (DataPoint point : mspData) {
@ -125,50 +132,13 @@ public class MspViewController {
} }
updateMspPane(plottables); updateMspPane(plottables);
return null;
} }
} catch (StorageException ex) {
throw new RuntimeException(ex);
} }
});
private class MspDataLoadTask extends Task<List<DataPoint>> {
private final Storage storage;
public MspDataLoadTask(Storage storage) {
this.storage = storage;
}
@Override
protected List<DataPoint> call() throws Exception {
updateTitle("Load msp data (" + storage.getName() + ")");
List<DataPoint> mspData = new ArrayList<>();
DataPoint last = null;
for (String loaderName : storage.loaders().keySet()) {
if (loaderName.startsWith("msp")) {
try (PointLoader mspLoader = (PointLoader) storage.getLoader(loaderName)) {
mspLoader.open();
updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
updateProgress(-1, 1);
for (DataPoint dp : mspLoader.asDataSet()) {
mspData.add(dp);
last = dp;
}
if (last != null) {
mspData.add(terminatorPoint(last));
}
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
} }
} }
}
updateMessage("Loading msp data finished");
updateProgress(0, 1);
return mspData;
}
}
/** /**
* Create a null value point to terminate msp series * Create a null value point to terminate msp series

View File

@ -15,7 +15,6 @@
*/ */
package inr.numass.viewer; package inr.numass.viewer;
import hep.dataforge.context.Context;
import hep.dataforge.context.ProcessManager; import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException; import hep.dataforge.exceptions.StorageException;
import hep.dataforge.storage.api.Loader; import hep.dataforge.storage.api.Loader;
@ -48,14 +47,12 @@ public class NumassLoaderTreeBuilder {
// this.rootStorage = rootStorage; // this.rootStorage = rootStorage;
// this.numassViewBuilder = numassViewBuilder; // this.numassViewBuilder = numassViewBuilder;
// } // }
public void build(Context context, public void build(ProcessManager.Callback callback,
TreeTableView<TreeItemValue> numassLoaderDataTree, TreeTableView<TreeItemValue> numassLoaderDataTree,
NumassStorage rootStorage, NumassStorage rootStorage,
Consumer<NumassData> numassViewBuilder) { Consumer<NumassData> numassViewBuilder) throws StorageException {
context.processManager().post("viewer.storage.load.buildTree", (ProcessManager.Callback callback) -> { // callback.updateTitle("Load numass data (" + rootStorage.getName() + ")");
try {
callback.updateTitle("Load numass data (" + rootStorage.getName() + ")");
TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder, callback); TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder, callback);
root.setExpanded(true); root.setExpanded(true);
@ -89,15 +86,22 @@ public class NumassLoaderTreeBuilder {
numassLoaderTimeColumn.setVisible(false); numassLoaderTimeColumn.setVisible(false);
nummassLoaderDescriptionColumn.setVisible(false); nummassLoaderDescriptionColumn.setVisible(false);
}); });
} catch (StorageException ex) {
throw new RuntimeException(ex);
}
});
} }
private TreeItem<TreeItemValue> buildNode(NumassStorage storage, private TreeItem<TreeItemValue> buildNode(NumassStorage storage,
Consumer<NumassData> numassViewBuilder, ProcessManager.Callback callback) throws StorageException { Consumer<NumassData> numassViewBuilder, ProcessManager.Callback callback) throws StorageException {
// CompletableFuture<TreeItem<TreeItemValue>> future = CompletableFuture.supplyAsync(() -> {
// try {
// TreeItem<TreeItemValue> node = new TreeItem<>(buildValue(storage));
// node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback));
// return node;
// } catch (StorageException ex) {
// throw new RuntimeException(ex);
// }
// });
// callback.getProcess().addChild(storage.getName(), future);
// return future.join();
TreeItem<TreeItemValue> node = new TreeItem<>(buildValue(storage)); TreeItem<TreeItemValue> node = new TreeItem<>(buildValue(storage));
node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback)); node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback));
return node; return node;
@ -110,16 +114,18 @@ public class NumassLoaderTreeBuilder {
for (Storage subStorage : storage.shelves().values()) { for (Storage subStorage : storage.shelves().values()) {
if (subStorage instanceof NumassStorage) { if (subStorage instanceof NumassStorage) {
NumassStorage numassSubStorage = (NumassStorage) subStorage; NumassStorage numassSubStorage = (NumassStorage) subStorage;
TreeItem<TreeItemValue> childNode = buildNode(numassSubStorage, numassViewBuilder, callback);
if (!childNode.isLeaf()) {
list.add(buildNode(numassSubStorage, numassViewBuilder, callback)); list.add(buildNode(numassSubStorage, numassViewBuilder, callback));
} }
} }
}
callback.updateMessage("Building storage " + storage.getName()); callback.updateMessage("Building storage " + storage.getName());
callback.updateProgress(-1, 1);
double counter = 0; callback.updateProgress(0, storage.loaders().size());
for (Loader loader : storage.loaders().values()) { for (Loader loader : storage.loaders().values()) {
callback.updateMessage("Building numass data loader " + loader.getName()); callback.updateMessage("Building numass data loader " + loader.getName());
callback.updateProgress(counter, storage.loaders().size());
if (loader instanceof NumassData) { if (loader instanceof NumassData) {
NumassData numassLoader = (NumassData) loader; NumassData numassLoader = (NumassData) loader;
@ -135,17 +141,19 @@ public class NumassLoaderTreeBuilder {
// }); // });
list.add(numassLoaderTreeItem); list.add(numassLoaderTreeItem);
} }
counter++; callback.changeProgress(1, 0);
} }
callback.updateMessage("Loading legacy DAT files");
callback.updateProgress(-1, 1);
List<NumassData> legacyFiles = storage.legacyFiles();
callback.updateProgress(0, legacyFiles.size());
//adding legacy data files //adding legacy data files
counter = 0; for (NumassData legacyDat : legacyFiles) {
for (NumassData legacyDat : storage.legacyFiles()) {
callback.updateMessage("Loading numass DAT file " + legacyDat.getName()); callback.updateMessage("Loading numass DAT file " + legacyDat.getName());
callback.updateProgress(counter, storage.loaders().size());
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(legacyDat)); TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(legacyDat));
callback.changeProgress(1, 0);
list.add(numassLoaderTreeItem); list.add(numassLoaderTreeItem);
counter++;
} }
return list; return list;

View File

@ -30,6 +30,7 @@ limitations under the License.
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?> <?import javafx.scene.layout.Pane?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<?import org.controlsfx.control.StatusBar?>
<AnchorPane id="AnchorPane" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.viewer.MainViewerController"> <AnchorPane id="AnchorPane" prefHeight="768.0" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.viewer.MainViewerController">
<children> <children>