[no commit message]

This commit is contained in:
darksnake 2015-12-21 16:40:21 +03:00
parent 4bdc1d492e
commit 9721b173c5
7 changed files with 164 additions and 108 deletions

4
.nb-gradle-properties Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<gradle-project-properties>
<!--DO NOT EDIT THIS FILE! - Used by the Gradle plugin of NetBeans.-->
</gradle-project-properties>

View File

@ -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

View File

@ -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<Env
if (directory.getType() != FOLDER || !directory.exists()) {
throw new IllegalArgumentException("numass data directory reuired");
}
Meta annotation = new MetaBuilder("loader")
.putValue("type", "numass")
.putValue("numass.loaderFormat", "dir")
@ -110,20 +110,34 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
name = directory.getName().getBaseName();
}
URL url = directory.getURL();
return new NumassDataLoader(storage, name, annotation, () -> {
FileObject dir = null;
try {
Map<String, Envelope> items1 = new HashMap<>();
for (FileObject it : directory.getChildren()) {
dir = VFS.getManager().resolveFile(url.toString());
Map<String, Envelope> 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<Env
throw new RuntimeException(ex);
}
}
// LocalDateTime startTime = envelope.meta().get
RawNMPoint raw = new RawNMPoint(envelope.meta().getDouble("external_meta.HV1_value", 0),
events,
envelope.meta().getValue("external_meta.acquisition_time").doubleValue());
@ -235,6 +251,7 @@ public class NumassDataLoader extends AbstractLoader implements BinaryLoader<Env
this.getPoints().stream().forEach((point) -> {
res.add(readPoint(point));
});
// res.sort((NMPoint o1, NMPoint o2) -> o1.getAbsouteTime().compareTo(o2.getAbsouteTime()));
return res;
}

View File

@ -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,7 +75,11 @@ 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);
}
@ -78,7 +87,11 @@ public class NumassStorage extends FileStorage {
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);
}
@ -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));

View File

@ -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<? extends Boolean> 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.

View File

@ -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;
@ -89,10 +89,12 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
return component;
}
Logger logger = LoggerFactory.getLogger(NumassLoaderViewComponent.class);
private NumassData data;
private XYPlotFrame detectorPlotFrame;
private XYPlotFrame spectrumPlotFrame;
private ChangeablePlottableData spectrumData;
private List<NMPoint> 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<? super Number> rangeChangeListener = (ObservableValue<? extends Number> 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<NMPoint> 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<NMPoint> 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()
.<DataPoint>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<NMPoint> 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<NMPoint> points, Function<NMPoint, Number> 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<NMPoint> points, Function<NMPoint, Number> 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();

View File

@ -97,16 +97,15 @@ limitations under the License.
<center>
<AnchorPane fx:id="spectrumPlotPane" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</center>
<right>
<VBox fx:id="spectrumOptionsPane" minWidth="-Infinity" prefWidth="140.0" spacing="2.0" style="-fx-border-color: blue;" BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets />
</BorderPane.margin>
<padding>
<Insets bottom="2.0" left="2.0" right="2.0" top="2.0" />
</padding>
</VBox>
</right>
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<TextField fx:id="lowChannelField" prefWidth="60.0" />
<RangeSlider fx:id="channelSlider" accessibleRole="SLIDER" highValue="1900.0" lowValue="300.0" majorTickUnit="500.0" max="4000.0" minorTickCount="5" prefHeight="38.0" prefWidth="336.0" showTickLabels="true" showTickMarks="true" />
<TextField fx:id="upChannelField" prefWidth="60.0" />
</items>
</ToolBar>
</top>
</BorderPane>
</children></AnchorPane>
</content>