From 9721b173c5ef19f3c5138ded233e2939150762e4 Mon Sep 17 00:00:00 2001 From: darksnake Date: Mon, 21 Dec 2015 16:40:21 +0300 Subject: [PATCH] [no commit message] --- .nb-gradle-properties | 4 + .../src/main/java/inr/numass/Main.java | 21 +-- .../inr/numass/storage/NumassDataLoader.java | 31 +++- .../inr/numass/storage/NumassStorage.java | 36 +++-- .../numass/viewer/MainViewerController.java | 16 +- .../viewer/NumassLoaderViewComponent.java | 145 ++++++++++++------ .../main/resources/fxml/NumassLoaderView.fxml | 19 ++- 7 files changed, 164 insertions(+), 108 deletions(-) create mode 100644 .nb-gradle-properties diff --git a/.nb-gradle-properties b/.nb-gradle-properties new file mode 100644 index 00000000..e374bd9d --- /dev/null +++ b/.nb-gradle-properties @@ -0,0 +1,4 @@ + + + + diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index 65f396fe..363783a5 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -27,34 +27,19 @@ import inr.numass.workbench.Workbench; import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; +import static java.util.Locale.setDefault; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; -import org.apache.commons.cli.BasicParser; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; +import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; -import static java.util.Locale.setDefault; /** * @@ -74,7 +59,7 @@ public class Main { Logger logger = LoggerFactory.getLogger("numass-main"); Options options = prepareOptions(); - CommandLineParser parser = new BasicParser(); + CommandLineParser parser = new DefaultParser(); CommandLine line; try { // parse the command line arguments 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 3c0f5229..2a01a011 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -15,7 +15,6 @@ */ package inr.numass.storage; -import inr.numass.data.NumassData; import hep.dataforge.exceptions.StorageException; import hep.dataforge.io.envelopes.DefaultEnvelopeReader; import hep.dataforge.io.envelopes.Envelope; @@ -26,10 +25,12 @@ import hep.dataforge.storage.api.Storage; import hep.dataforge.storage.loaders.AbstractLoader; import inr.numass.data.NMEvent; import inr.numass.data.NMPoint; +import inr.numass.data.NumassData; import inr.numass.data.RawNMPoint; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.time.Instant; @@ -100,7 +101,6 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader { + FileObject dir = null; try { - Map items1 = new HashMap<>(); - for (FileObject it : directory.getChildren()) { + dir = VFS.getManager().resolveFile(url.toString()); + + Map items = new HashMap<>(); + for (FileObject it : dir.getChildren()) { Envelope envelope = readFile(it); if (envelope != null) { - items1.put(it.getName().getBaseName(), envelope); + items.put(it.getName().getBaseName(), envelope); } } - return items1; - } catch (FileSystemException ex) { + return items; + } catch (Exception ex) { LoggerFactory.getLogger(NumassDataLoader.class) .error("Can't load numass data directory " + directory.getName().getBaseName(), ex); return null; + } finally { + if (dir != null) { + try { + dir.close(); + } catch (FileSystemException ex) { + LoggerFactory.getLogger(NumassDataLoader.class) + .error("Can't close remote directory", ex); + } + } } }); } @@ -163,6 +177,8 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader { res.add(readPoint(point)); }); +// res.sort((NMPoint o1, NMPoint o2) -> o1.getAbsouteTime().compareTo(o2.getAbsouteTime())); return res; } 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 60021a43..bd3c5e7a 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassStorage.java @@ -18,6 +18,7 @@ package inr.numass.storage; import hep.dataforge.events.Event; import hep.dataforge.exceptions.StorageException; import hep.dataforge.meta.Meta; +import hep.dataforge.meta.MetaBuilder; import hep.dataforge.storage.filestorage.FileStorage; import hep.dataforge.storage.filestorage.VFSUtils; import inr.numass.data.NMFile; @@ -62,7 +63,11 @@ public class NumassStorage extends FileStorage { */ public static NumassStorage buildLocalNumassRoot(File dir, boolean readOnly) throws StorageException { try { - return new NumassStorage(VFSUtils.getLocalFile(dir), readOnly); + Meta meta = new MetaBuilder("storage") + .setValue("type", "file.numass") + .setValue("readOnly", readOnly) + .setValue("monitor", true); + return new NumassStorage(VFSUtils.getLocalFile(dir), meta); } catch (FileSystemException ex) { throw new RuntimeException(ex); } @@ -70,19 +75,27 @@ public class NumassStorage extends FileStorage { public static NumassStorage buildRemoteNumassRoot(String ip, int port, String login, String password, String path) throws StorageException { try { - return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), true); + Meta meta = new MetaBuilder("storage") + .setValue("type", "file.numass") + .setValue("readOnly", true) + .setValue("monitor", false); + return new NumassStorage(VFSUtils.getRemoteFile(ip, port, login, password, path), meta); } catch (FileSystemException ex) { throw new RuntimeException(ex); } } - + public static NumassStorage buildRemoteNumassRoot(String uri) throws StorageException { try { - return new NumassStorage(VFSUtils.getRemoteFile(uri), true); + Meta meta = new MetaBuilder("storage") + .setValue("type", "file.numass") + .setValue("readOnly", true) + .setValue("monitor", false); + return new NumassStorage(VFSUtils.getRemoteFile(uri), meta); } catch (FileSystemException ex) { throw new RuntimeException(ex); } - } + } public NumassStorage(FileStorage parent, String path, Meta config) throws StorageException { super(parent, path, config); @@ -95,12 +108,11 @@ public class NumassStorage extends FileStorage { super.refresh(); } - protected NumassStorage(FileObject dir, boolean readOnly) throws StorageException { - super(dir, null); - super.setReadOnly(readOnly); - super.refresh(); - } - +// protected NumassStorage(FileObject dir, boolean readOnly) throws StorageException { +// super(dir, null); +// super.setReadOnly(readOnly); +// super.refresh(); +// } @Override protected void updateDirectoryLoaders() { try { @@ -114,7 +126,7 @@ public class NumassStorage extends FileStorage { NumassDataLoader.fromDir(this, file, null)); } else { this.shelves.put(file.getName().getBaseName(), - new NumassStorage(this, file.getName().getBaseName(), null)); + new NumassStorage(this, file.getName().getBaseName(), meta())); } } else if (file.getName().toString().endsWith(NUMASS_ZIP_EXTENSION)) { this.loaders.put(file.getName().getBaseName(), NumassDataLoader.fromZip(this, file)); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java index 387c2e90..cdd050b3 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -17,7 +17,6 @@ package inr.numass.viewer; import de.jensd.shichimifx.utils.ConsoleDude; import de.jensd.shichimifx.utils.SplitPaneDividerSlider; -import de.jensd.shichimifx.utils.TabPaneDetacher; import hep.dataforge.exceptions.StorageException; import inr.numass.data.NumassData; import inr.numass.storage.NumassStorage; @@ -46,7 +45,6 @@ import javafx.scene.control.TextArea; import javafx.scene.control.TextField; import javafx.scene.control.ToggleButton; import javafx.scene.control.TreeTableView; -import javafx.scene.image.ImageView; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.stage.DirectoryChooser; @@ -109,7 +107,7 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba */ @Override public void initialize(URL url, ResourceBundle rb) { - TabPaneDetacher.create().makeTabsDetachable(tabPane); +// TabPaneDetacher.create().makeTabsDetachable(tabPane); ConsoleDude.hookStdStreams(consoleArea); SplitPaneDividerSlider slider = new SplitPaneDividerSlider(consoleSplit, 0, SplitPaneDividerSlider.Direction.DOWN); @@ -117,7 +115,7 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba consoleButton.selectedProperty().addListener((ObservableValue ov, Boolean t, Boolean t1) -> { slider.setAimContentVisible(t1); }); - consoleButton.setSelected(false); + slider.setAimContentVisible(false); } @FXML @@ -205,9 +203,6 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba dialog.setTitle("Remote storage selection"); dialog.setHeaderText("Select remote storage login options and run"); -// Set the icon (must be included in the project). -// dialog.setGraphic(new ImageView(this.getClass().getResource("login.png").toString())); -// Set the button types. ButtonType loginButtonType = new ButtonType("Load", ButtonData.OK_DONE); dialog.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); @@ -228,13 +223,6 @@ public class MainViewerController implements Initializable, ProgressUpdateCallba grid.add(new Label("Run name:"), 0, 1); grid.add(runText, 1, 1); - // Enable/Disable login button depending on whether a username was entered. -// Node loginButton = dialog.getDialogPane().lookupButton(loginButtonType); -// loginButton.setDisable(true); -// Do some validation (using the Java 8 lambda syntax). -// storageText.textProperty().addListener((observable, oldValue, newValue) -> { -// loginButton.setDisable(newValue.trim().isEmpty()); -// }); dialog.getDialogPane().setContent(grid); // Request focus on the username field by default. diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java index 07dcfead..05215f3a 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java @@ -20,27 +20,30 @@ package inr.numass.viewer; * To change this template file, choose Tools | Templates * and open the template in the editor. */ +import hep.dataforge.data.DataPoint; import hep.dataforge.data.DataSet; +import hep.dataforge.data.MapDataPoint; import hep.dataforge.io.ColumnedDataWriter; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.plots.XYPlotFrame; import hep.dataforge.plots.XYPlottable; +import hep.dataforge.plots.data.ChangeablePlottableData; import hep.dataforge.plots.data.PlotDataUtils; import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.jfreechart.JFreeChartFrame; import hep.dataforge.storage.commons.JSONMetaWriter; import inr.numass.data.NMPoint; import inr.numass.data.NumassData; -import static inr.numass.viewer.NumassViewerUtils.displayPlot; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.ResourceBundle; -import java.util.function.Function; +import java.util.stream.Collectors; import javafx.beans.property.BooleanProperty; +import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.event.ActionEvent; @@ -53,16 +56,13 @@ import javafx.scene.control.ChoiceBox; import javafx.scene.control.SelectionMode; import javafx.scene.control.Tab; import javafx.scene.control.TextArea; +import javafx.scene.control.TextField; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.VBox; import javafx.stage.FileChooser; +import javafx.util.converter.NumberStringConverter; import org.controlsfx.control.CheckListView; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.axis.NumberAxis; -import org.jfree.chart.plot.XYPlot; -import org.jfree.chart.renderer.xy.XYErrorRenderer; -import org.jfree.data.xy.XYIntervalSeries; -import org.jfree.data.xy.XYIntervalSeriesCollection; +import org.controlsfx.control.RangeSlider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,11 +88,13 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab component.setData(numassLoader); return component; } - - + Logger logger = LoggerFactory.getLogger(NumassLoaderViewComponent.class); private NumassData data; private XYPlotFrame detectorPlotFrame; + private XYPlotFrame spectrumPlotFrame; + private ChangeablePlottableData spectrumData; + private List points; @FXML private AnchorPane detectorPlotPane; @@ -119,8 +121,18 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab @FXML private Button detectorDataExportButton; + @FXML + private TextField lowChannelField; + + @FXML + private TextField upChannelField; + + @FXML + private RangeSlider channelSlider; + /** * Initializes the controller class. + * * @param url * @param rb */ @@ -133,6 +145,18 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab detectorPointListView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE); detectorDataExportButton.setOnAction(this::onExportButtonClick); + lowChannelField.textProperty().bindBidirectional(channelSlider.lowValueProperty(), new NumberStringConverter()); + upChannelField.textProperty().bindBidirectional(channelSlider.highValueProperty(), new NumberStringConverter()); + + channelSlider.setLowValue(300); + channelSlider.setHighValue(1900); + + ChangeListener rangeChangeListener = (ObservableValue observable, Number oldValue, Number newValue) -> { + updateSpectrumPane(); + }; + + channelSlider.lowValueProperty().addListener(rangeChangeListener); + channelSlider.highValueProperty().addListener(rangeChangeListener); } public NumassData getData() { @@ -142,11 +166,11 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab public void setData(NumassData data) { this.data = data; if (data != null) { - List points = data.getNMPoints(); + points = data.getNMPoints(); //setup detector data setupDetectorPane(points); //setup spectrum plot - setupSpectrumPane(points); + updateSpectrumPane(); setupInfo(data); @@ -183,23 +207,51 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab replace("\\r", "\r").replace("\\n", "\n")); } - private void setupSpectrumPane(List points) { - updateSpectrumData(fillSpectrumData(points, (point) -> point.getEventsCount())); + private void updateSpectrumPane() { + if (spectrumPlotFrame == null) { + spectrumPlotFrame = new JFreeChartFrame("spectrum", null, spectrumPlotPane); + } + + if (spectrumData == null) { + spectrumData = new ChangeablePlottableData("", null); + spectrumPlotFrame.add(spectrumData); + } + + int lowChannel = (int) channelSlider.getLowValue(); + int highChannel = (int) channelSlider.getHighValue(); + if (points == null || points.isEmpty()) { + spectrumData.clear(); + } else { + spectrumData.fillData(points.stream() + .map((NMPoint point) -> getSpectrumPoint(point, lowChannel, highChannel)) + .collect(Collectors.toList())); + } } - private void updateSpectrumData(XYIntervalSeriesCollection data) { - spectrumPlotPane.getChildren().clear(); - NumberAxis xAxis = new NumberAxis("HV"); - NumberAxis yAxis = new NumberAxis("count rate"); - - xAxis.setAutoRangeIncludesZero(false); - yAxis.setAutoRangeIncludesZero(false); - - XYPlot plot = new XYPlot(data, xAxis, yAxis, new XYErrorRenderer()); - JFreeChart spectrumPlot = new JFreeChart("spectrum", plot); - displayPlot(spectrumPlotPane, spectrumPlot); + private DataPoint getSpectrumPoint(NMPoint point, int lowChannel, int highChannel) { + double u = point.getUread(); + double count = point.getCountInWindow(lowChannel, highChannel); + double time = point.getLength(); + double err = Math.sqrt(count); + return new MapDataPoint(new String[]{"x", "y", "yErr"}, u, count / time, err / time); } +// private void setupSpectrumPane(List points, int lowChannel, int upChannel) { +// updateSpectrumData(fillSpectrumData(points, (point) -> point.getCountInWindow(lowChannel, upChannel))); +// } +// +// private void updateSpectrumData(XYIntervalSeriesCollection data) { +// spectrumPlotPane.getChildren().clear(); +// NumberAxis xAxis = new NumberAxis("HV"); +// NumberAxis yAxis = new NumberAxis("count rate"); +// +// xAxis.setAutoRangeIncludesZero(false); +// yAxis.setAutoRangeIncludesZero(false); +// +// XYPlot plot = new XYPlot(data, xAxis, yAxis, new XYErrorRenderer()); +// JFreeChart spectrumPlot = new JFreeChart("spectrum", plot); +// displayPlot(spectrumPlotPane, spectrumPlot); +// } /** * update detector pane with new data */ @@ -258,28 +310,27 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab return plottables; } - /** - * Fill spectrum with custom window calculator - * - * @param points - * @param lowerBoundCalculator - * @param upperBoundCalculator - * @return - */ - private XYIntervalSeriesCollection fillSpectrumData(List points, Function calculator) { - XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection(); - XYIntervalSeries ser = new XYIntervalSeries("spectrum"); - for (NMPoint point : points) { - double u = point.getUread(); - double count = calculator.apply(point).doubleValue(); - double time = point.getLength(); - double err = Math.sqrt(count); - ser.add(u, u, u, count / time, (count - err) / time, (count + err) / time); - } - collection.addSeries(ser); - return collection; - } - +// /** +// * Fill spectrum with custom window calculator +// * +// * @param points +// * @param lowerBoundCalculator +// * @param upperBoundCalculator +// * @return +// */ +// private XYIntervalSeriesCollection fillSpectrumData(List points, Function calculator) { +// XYIntervalSeriesCollection collection = new XYIntervalSeriesCollection(); +// XYIntervalSeries ser = new XYIntervalSeries("spectrum"); +// for (NMPoint point : points) { +// double u = point.getUread(); +// double count = calculator.apply(point).doubleValue(); +// double time = point.getLength(); +// double err = Math.sqrt(count); +// ser.add(u, u, u, count / time, (count - err) / time, (count + err) / time); +// } +// collection.addSeries(ser); +// return collection; +// } @FXML private void checkAllAction(ActionEvent event) { detectorPointListView.getCheckModel().checkAll(); diff --git a/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml b/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml index 234fba91..70d5cf29 100644 --- a/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml +++ b/numass-viewer/src/main/resources/fxml/NumassLoaderView.fxml @@ -97,16 +97,15 @@ limitations under the License.
- - - - - - - - - - + + + + + + + + +