[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,67 +148,40 @@ 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...");
new NumassLoaderTreeBuilder().build(getContext(), numassLoaderDataTree, root, (NumassData loader) -> { callback.updateMessage("Loading numass storage tree...");
NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext());
component.loadData(loader);
numassLoaderViewContainer.getChildren().clear();
numassLoaderViewContainer.getChildren().add(component);
AnchorPane.setTopAnchor(component, 0.0);
AnchorPane.setRightAnchor(component, 0.0);
AnchorPane.setLeftAnchor(component, 0.0);
AnchorPane.setBottomAnchor(component, 0.0);
numassLoaderViewContainer.requestLayout();
});
callback.updateProgress(0, 1);
callback.updateMessage("Numass storage tree loaded.");
try {
new NumassLoaderTreeBuilder().build(callback, numassLoaderDataTree, root, (NumassData loader) -> {
NumassLoaderViewComponent component = new NumassLoaderViewComponent(getContext());
component.loadData(loader);
numassLoaderViewContainer.getChildren().clear();
numassLoaderViewContainer.getChildren().add(component);
AnchorPane.setTopAnchor(component, 0.0);
AnchorPane.setRightAnchor(component, 0.0);
AnchorPane.setLeftAnchor(component, 0.0);
AnchorPane.setBottomAnchor(component, 0.0);
numassLoaderViewContainer.requestLayout();
});
} catch (StorageException ex) {
Logger.getLogger(MainViewerController.class.getName()).log(Level.SEVERE, null, ex);
} }
}
); // callback.updateProgress(1, 1);
Platform.runLater(() -> statusBar.setProgress(0));
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,91 +89,57 @@ 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() + ")");
}
Viewer.runTask(fillTask);
}
}
private class MspDataFillTask extends Task<Void> { callback.updateTitle("Load msp data (" + rootStorage.getName() + ")");
List<DataPoint> mspData = new ArrayList<>();
private final Storage storage; DataPoint last = null;
for (String loaderName : rootStorage.loaders().keySet()) {
public MspDataFillTask(Storage storage) { if (loaderName.startsWith("msp")) {
this.storage = storage; try (final PointLoader mspLoader = (PointLoader) rootStorage.getLoader(loaderName)) {
} mspLoader.open();
callback.updateMessage("Loading mass spectrometer data from " + mspLoader.getName());
@Override for (DataPoint dp : mspLoader.asDataSet()) {
protected Void call() throws Exception { mspData.add(dp);
updateTitle("Fill msp data (" + storage.getName() + ")"); last = dp;
MspDataLoadTask loadTask = new MspDataLoadTask(storage); }
if (callback != null) { if (last != null) {
callback.postTask(loadTask); mspData.add(terminatorPoint(last));
} }
Viewer.runTask(loadTask); } catch (Exception ex) {
List<DataPoint> mspData = loadTask.get(); LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
}
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));
} }
} }
} callback.updateMessage("Loading msp data finished");
plottables.put(point); // return mspData;
} // List<DataPoint> mspData = (List<DataPoint>) loadProcess.getTask().get();
updateMspPane(plottables); if (!mspData.isEmpty()) {
return null; DynamicPlottableSet plottables = new DynamicPlottableSet();
}
} for (DataPoint point : mspData) {
for (String name : point.names()) {
private class MspDataLoadTask extends Task<List<DataPoint>> { if (!name.equals("timestamp")) {
if (!plottables.hasPlottable(name)) {
private final Storage storage; plottables.addPlottable(new DynamicPlottable(name, name));
}
public MspDataLoadTask(Storage storage) { }
this.storage = storage; }
} plottables.put(point);
@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)); updateMspPane(plottables);
}
} catch (Exception ex) {
LoggerFactory.getLogger(getClass()).error("Can't read msp loader data", ex);
} }
} catch (StorageException ex) {
throw new RuntimeException(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,56 +47,61 @@ 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 { TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder, callback);
callback.updateTitle("Load numass data (" + rootStorage.getName() + ")"); root.setExpanded(true);
TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder, callback);
root.setExpanded(true);
// numassLoaderDataTree.setShowRoot(true); // numassLoaderDataTree.setShowRoot(true);
Platform.runLater(() -> { Platform.runLater(() -> {
numassLoaderDataTree.setRoot(root); numassLoaderDataTree.setRoot(root);
TreeTableColumn<TreeItemValue, String> numassLoaderNameColumn = new TreeTableColumn<>("name"); TreeTableColumn<TreeItemValue, String> numassLoaderNameColumn = new TreeTableColumn<>("name");
numassLoaderNameColumn.setCellValueFactory( numassLoaderNameColumn.setCellValueFactory(
(TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getName())); (TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getName()));
TreeTableColumn<TreeItemValue, String> numassLoaderTimeColumn = new TreeTableColumn<>("time"); TreeTableColumn<TreeItemValue, String> numassLoaderTimeColumn = new TreeTableColumn<>("time");
numassLoaderTimeColumn.setCellValueFactory( numassLoaderTimeColumn.setCellValueFactory(
(TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getTime())); (TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getTime()));
TreeTableColumn<TreeItemValue, String> nummassLoaderDescriptionColumn = new TreeTableColumn<>("description"); TreeTableColumn<TreeItemValue, String> nummassLoaderDescriptionColumn = new TreeTableColumn<>("description");
nummassLoaderDescriptionColumn.setCellValueFactory( nummassLoaderDescriptionColumn.setCellValueFactory(
(TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getDescription())); (TreeTableColumn.CellDataFeatures<TreeItemValue, String> param) -> new SimpleStringProperty(param.getValue().getValue().getDescription()));
numassLoaderDataTree.getColumns().setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn); numassLoaderDataTree.getColumns().setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn);
numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> { numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
if (e.getClickCount() == 2) { if (e.getClickCount() == 2) {
TreeItemValue value = numassLoaderDataTree.getFocusModel().getFocusedCell().getTreeItem().getValue(); TreeItemValue value = numassLoaderDataTree.getFocusModel().getFocusedCell().getTreeItem().getValue();
if (value.isLoader()) { if (value.isLoader()) {
numassViewBuilder.accept(value.getLoader()); numassViewBuilder.accept(value.getLoader());
} }
} }
}); });
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;
list.add(buildNode(numassSubStorage, numassViewBuilder, callback)); TreeItem<TreeItemValue> childNode = buildNode(numassSubStorage, numassViewBuilder, callback);
if (!childNode.isLeaf()) {
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>