This commit is contained in:
Alexander Nozik 2016-05-09 21:28:11 +03:00
parent aa9cac6e8a
commit b15e9e2ad5
21 changed files with 326 additions and 210 deletions

View File

@ -244,7 +244,7 @@ public class MspViewController implements Initializable, MspListener {
)
.setValue("xAxis.type", "time");
this.plot = new JFreeChartFrame(mspName, plotConfig);
this.plot = new JFreeChartFrame(plotConfig);
PlotContainer container = PlotContainer.anchorTo(plotPane);
container.setPlot(plot);
updatePlot();

View File

@ -433,7 +433,7 @@ public class VACFrame extends javax.swing.JFrame {
.setValue("axisUnits", "mbar")
)
.setValue("xAxis.timeAxis", true);
this.plotFrame = new JFreeChartFrame("pressures", plotConfig).display(chartPannel);
this.plotFrame = new JFreeChartFrame(plotConfig).display(chartPannel);
XYPlot xyPlot = plotFrame.getChart().getXYPlot();
LogarithmicAxis logAxis = new LogarithmicAxis("Pressure (mbar)");

View File

@ -171,7 +171,7 @@ public class VacCollectorController implements Initializable, DeviceListener, Me
.setValue("axisUnits", "mbar")
)
.setValue("xAxis.type", "time");
JFreeChartFrame frame = new JFreeChartFrame("pressure", plotConfig);
JFreeChartFrame frame = new JFreeChartFrame(plotConfig);
frame.addAll(plottables);
return frame;
}

View File

@ -0,0 +1,23 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.scripts
import inr.numass.storage.NMFile
import inr.numass.storage.NumassData
import inr.numass.storage.NumassDataLoader
import hep.dataforge.meta.Meta
import inr.numass.actions.FindBorderAction
import hep.dataforge.grind.GrindMetaBuilder
File dataDir = new File("D:\\Work\\Numass\\data\\2016_04\\T2_data\\Fill_1_7\\set_2_3b127e3254010000")
if(!dataDir.exists()){
println "dataDir directory does not exist"
}
Meta config = new GrindMetaBuilder().config(lower: 500, upper: 1600)
println config
NumassData data = NumassDataLoader.fromLocalDir(null, dataDir)
new FindBorderAction().eval(data, config)

View File

@ -27,6 +27,7 @@ import hep.dataforge.datafitter.models.XYModel;
import hep.dataforge.meta.Meta;
import hep.dataforge.plotfit.PlotFitResultAction;
import hep.dataforge.plots.PlotDataAction;
import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.tables.PointAdapter;
import hep.dataforge.tables.XYAdapter;
import inr.numass.actions.AdjustErrorsAction;
@ -35,6 +36,7 @@ import inr.numass.actions.MergeDataAction;
import inr.numass.actions.MonitorCorrectAction;
import inr.numass.actions.PrepareDataAction;
import inr.numass.actions.ReadNumassDataAction;
import inr.numass.actions.ReadNumassStorageAction;
import inr.numass.actions.ShowLossSpectrumAction;
import inr.numass.actions.ShowSpectrumAction;
import inr.numass.actions.SlicingAction;
@ -65,6 +67,7 @@ public class NumassPlugin extends BasicPlugin {
@Override
public void attach(Context context) {
// StorageManager.buildFrom(context);
FitManager fm = context.provide("fitting", FitPlugin.class).getFitManager();
ModelManager mm = fm.getModelManager();
loadModels(mm);
@ -82,6 +85,7 @@ public class NumassPlugin extends BasicPlugin {
actions.registerAction(PlotFitResultAction.class);
actions.registerAction(ShowLossSpectrumAction.class);
actions.registerAction(AdjustErrorsAction.class);
actions.registerAction(ReadNumassStorageAction.class);
}
@Override
@ -194,7 +198,7 @@ public class NumassPlugin extends BasicPlugin {
double weightReductionFactor = an.getDouble("weightReductionFactor", 2.0);
WeightedXYModel res
WeightedXYModel res
= new WeightedXYModel("scatter-empiric-experimental", spectrum, getAdapter(an), (dp) -> weightReductionFactor);
res.setMeta(an);
return res;

View File

@ -20,6 +20,7 @@ import hep.dataforge.tables.SimplePointSource;
import hep.dataforge.values.Value;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import java.util.HashMap;
import java.util.Map;
@ -43,7 +44,7 @@ public class BorderData extends SimplePointSource {
return res;
}
public BorderData(NMFile file, int upper, int lower, NMPoint reference) {
public BorderData(NumassData file, int upper, int lower, NMPoint reference) {
super(names);
if (upper <= lower) {
throw new IllegalArgumentException();
@ -51,7 +52,7 @@ public class BorderData extends SimplePointSource {
fill(file, lower, upper, reference);
}
private void fill(NMFile file, int lower, int upper, NMPoint reference) {
private void fill(NumassData file, int lower, int upper, NMPoint reference) {
for (NMPoint point : file.getNMPoints()) {
if ((reference != null) && (point.getUset() == reference.getUset())) {
continue;

View File

@ -24,6 +24,7 @@ import hep.dataforge.io.reports.Reportable;
import hep.dataforge.meta.Laminate;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import java.io.OutputStream;
/**
@ -31,13 +32,13 @@ import java.io.OutputStream;
* @author Darksnake
*/
@TypedActionDef(name = "findBorder", inputType = NMFile.class, outputType = NMFile.class)
public class FindBorderAction extends OneToOneAction<NMFile, NMFile> {
public class FindBorderAction extends OneToOneAction<NumassData, NumassData> {
@Override
protected NMFile execute(Context context, Reportable log, String name, Laminate meta, NMFile source) throws ContentException {
protected NumassData execute(Context context, Reportable log, String name, Laminate meta, NumassData source) throws ContentException {
log.report("File {} started", source.getName());
int upperBorder = meta.getInt("upper", 4096);
int upperBorder = meta.getInt("upper", 4094);
int lowerBorder = meta.getInt("lower", 0);
double substractReference = meta.getDouble("reference", 0);

View File

@ -30,6 +30,7 @@ import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.PointSource;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.TableFormat;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
@ -168,7 +169,7 @@ public class MergeDataAction extends ManyToOneAction<Table, Table> {
}).forEach((curPoint) -> {
res.add(curPoint);
});
return new ListTable(res);
}

View File

@ -144,10 +144,12 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
}
private void printMonitorData(Context context, Meta meta) {
String monitorFileName = meta.getString("monitorFile", "monitor");
OutputStream stream = buildActionOutput(context, monitorFileName);
ListTable data = new ListTable(monitorPoints);
ColumnedDataWriter.writeDataSet(stream, data.sort("Timestamp", true), "Monitor points", monitorNames);
if (!monitorPoints.isEmpty()) {
String monitorFileName = meta.getString("monitorFile", "monitor");
OutputStream stream = buildActionOutput(context, monitorFileName);
ListTable data = new ListTable(monitorPoints);
ColumnedDataWriter.writeDataSet(stream, data.sort("Timestamp", true), "Monitor points", monitorNames);
}
}
private boolean isMonitorPoint(double monitor, DataPoint point) {
@ -155,7 +157,7 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
}
private LocalDateTime getTime(DataPoint point) {
return LocalDateTime.ofInstant(point.getValue("Timestamp").timeValue(), ZoneId.of("GMT+3"));
return LocalDateTime.ofInstant(point.getValue("Timestamp").timeValue(), ZoneId.systemDefault());
}
private int getTotal(DataPoint point) {

View File

@ -30,8 +30,8 @@ import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import hep.dataforge.tables.TableFormat;
import inr.numass.storage.NMFile;
import inr.numass.storage.NMPoint;
import inr.numass.storage.NumassData;
import inr.numass.storage.RawNMPoint;
import java.io.OutputStream;
import java.time.Instant;
@ -42,12 +42,12 @@ import java.util.List;
*
* @author Darksnake
*/
@TypedActionDef(name = "prepareData", inputType = NMFile.class, outputType = Table.class)
@TypedActionDef(name = "prepareData", inputType = NumassData.class, outputType = Table.class)
@ValueDef(name = "lowerWindow", type = "NUMBER", def = "0", info = "Base for the window lowerWindow bound")
@ValueDef(name = "lowerWindowSlope", type = "NUMBER", def = "0", info = "Slope for the window lowerWindow bound")
@ValueDef(name = "upperWindow", type = "NUMBER", info = "Upper bound for window")
@ValueDef(name = "deadTime", type = "NUMBER", def = "0", info = "Dead time in us")
public class PrepareDataAction extends OneToOneAction<NMFile, Table> {
public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
public static String[] parnames = {"Uset", "Uread", "Length", "Total", "Window", "Corrected", "CR", "CRerr", "Timestamp"};
@ -59,8 +59,8 @@ public class PrepareDataAction extends OneToOneAction<NMFile, Table> {
}
@Override
protected ListTable execute(Context context, Reportable log, String name, Laminate meta, NMFile dataFile) {
// log.logString("File %s started", dataFile.getName());
protected ListTable execute(Context context, Reportable log, String name, Laminate meta, NumassData dataFile) {
// log.report("File %s started", dataFile.getName());
int upper = meta.getInt("upperWindow", RawNMPoint.MAX_CHANEL - 1);
@ -99,11 +99,9 @@ public class PrepareDataAction extends OneToOneAction<NMFile, Table> {
format = TableFormat.fixedWidth(8, parnames);
}
// AnnotationBuilder builder = dataFile.meta().getBuilder();
String head;
if (dataFile.getHead() != null) {
head = dataFile.getHead();
// builder.putValue("datafilehead",head);
if (dataFile.getInfo() != null) {
head = dataFile.getInfo().toString();
} else {
head = dataFile.getName();
}

View File

@ -0,0 +1,64 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package inr.numass.actions;
import hep.dataforge.actions.GenericAction;
import hep.dataforge.context.Context;
import hep.dataforge.data.Data;
import hep.dataforge.data.DataFilter;
import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataSet;
import hep.dataforge.data.StaticData;
import hep.dataforge.description.TypedActionDef;
import hep.dataforge.description.ValueDef;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.commons.StorageUtils;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage;
/**
*
* @author Alexander Nozik
*/
@TypedActionDef(name = "readStorage",
outputType = NumassData.class, info = "Read numass storage data")
@ValueDef(name = "uri", info = "The path to Numass storage")
//@NodeDef(name = "debunch", target = "class::inr.numass.actions.DebunchAction", info = "If given, governs debunching")
public class ReadNumassStorageAction extends GenericAction<Void, NumassData> {
@Override
public DataNode<NumassData> run(Context context, DataNode<Void> data, Meta actionMeta) {
try {
NumassStorage storage = NumassStorage.buildNumassRoot(actionMeta.getString("uri"), true, false);
DataFilter filter = new DataFilter().configure(actionMeta);
DataSet.Builder<NumassData> builder = DataSet.builder(NumassData.class);
StorageUtils.loaderStream(storage).forEach(pair -> {
Loader loader = pair.getValue();
if (loader instanceof NumassData) {
Data<NumassData> datum = new StaticData<>((NumassData) loader);
if (filter.acceptData(pair.getKey(), datum)) {
builder.putData(pair.getKey(), datum);
}
}
});
storage.legacyFiles().forEach(nd -> {
Data<NumassData> datum = new StaticData<>(nd);
if (filter.acceptData(nd.getName(), datum)) {
builder.putData("legacy." + nd.getName(), datum);
}
});
return builder.build();
} catch (StorageException ex) {
throw new RuntimeException("Failed to load storage", ex);
}
}
}

View File

@ -5,8 +5,6 @@
*/
package inr.numass.workbench;
import ch.qos.logback.classic.Level;
import de.jensd.shichimifx.utils.ConsoleDude;
import hep.dataforge.actions.Action;
import hep.dataforge.actions.ActionManager;
import hep.dataforge.actions.ActionStateListener;
@ -18,6 +16,7 @@ import hep.dataforge.data.FileDataFactory;
import hep.dataforge.description.ActionDescriptor;
import hep.dataforge.description.DescriptorUtils;
import hep.dataforge.exceptions.NameNotFoundException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.FXProcessManager;
import hep.dataforge.fx.LogOutputPane;
import hep.dataforge.fx.MetaEditor;
@ -51,11 +50,13 @@ import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Accordion;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.scene.control.ToggleButton;
import javafx.stage.FileChooser;
import org.controlsfx.control.StatusBar;
@ -79,6 +80,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
Map<String, StagePane> stages = new ConcurrentHashMap<>();
ProcessManagerFragment processWindow = new ProcessManagerFragment(new FXProcessManager());
ConsoleFragment consoleWindow = new ConsoleFragment();
@FXML
private StatusBar statusBar;
@ -97,7 +99,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
@FXML
private Button runButton;
@FXML
private TextArea consoleArea;
private ToggleButton consoleButton;
@Override
public void clearStage(String stageName) {
@ -117,7 +119,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
public void initialize(URL url, ResourceBundle rb) {
logPane = new LogOutputPane();
logTab.setContent(logPane);
ConsoleDude.hookStdStreams(consoleArea);
consoleWindow.bindTo(consoleButton);
consoleWindow.addRootLogHandler();
consoleWindow.hookStd();
}
public Context getContext() {
@ -132,17 +136,15 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
this.context = this.contextFactory.build(parentContext, config);
context.setIO(new WorkbenchIOManager(new NumassIO(), this));
processWindow = ProcessManagerFragment.attachToContext(context);
processWindow.setOwner(this.logPane.getScene().getWindow());
buildContextPane();
this.logPane.attachLog(context);
context.getLogger().addAppender(logPane.getLoggerAppender());
context.getLogger().setLevel(Level.ALL);
GlobalContext.instance().getLogger().addAppender(logPane.getLoggerAppender());
this.logPane.listenTo(context);
// this.logPane.listenTo(context);
// this.logPane.listenTo(GlobalContext.instance().getLogger());
((PlotsPlugin) context.provide("plots")).setPlotHolderDelegate(this);
}
private Tab findTabWithName(TabPane pane, String name) {
return pane.getTabs().stream().filter((t) -> t.getText().equals(name)).findFirst().orElse(null);
}
@ -254,9 +256,9 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
private void clearAllStages() {
logPane.clear();
for (String stageName : stages.keySet()) {
stages.keySet().stream().forEach((stageName) -> {
clearStage(stageName);
}
});
}
/**
@ -264,6 +266,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
*/
private synchronized void cleanUp() {
//clear previus action panes
processWindow.getManager().cleanup();
metaContainer.getPanes().removeIf((ap) -> ap.getText().startsWith("action"));
clearAllStages();
actionsConfig = null;
@ -294,7 +297,7 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
@FXML
private void onRunButtonClick(ActionEvent event) {
if (getContext() != null && !dataConfig.isEmpty() && !actionsConfig.isEmpty()) {
if (getContext() != null && !actionsConfig.isEmpty()) {
statusBar.setText("Starting action execution");
runActions();
}
@ -314,12 +317,26 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder
processWindow.show();
new Thread(() -> {
DataNode data = new FileDataFactory().build(getContext(), getDataConfiguration());
if (data.isEmpty()) {
//FIXME evaluate error here
throw new Error("Empty data");
Platform.runLater(() -> statusBar.setProgress(-1));
try {
ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute();
Platform.runLater(() -> statusBar.setText("Execution complete"));
} catch (Exception ex) {
GlobalContext.instance().getLogger().error("Exception while executing action chain", ex);
Platform.runLater(() -> {
// ex.printStackTrace();
statusBar.setText("Execution failed");
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle("Exception!");
alert.setHeaderText("Action execution failure");
alert.setContentText(ex.getMessage());
alert.show();
});
} finally {
Platform.runLater(() -> statusBar.setProgress(0));
}
ActionUtils.runAction(getContext(), data, getActionConfiguration()).compute();
Platform.runLater(() -> statusBar.setText("Execution complete"));
}, "actions").start();
}

View File

@ -16,7 +16,7 @@ public class PlotOutputTab extends OutputTab {
public PlotOutputTab(String name, Meta meta) {
super(name);
PlotContainer container = new PlotContainer();
frame = new JFreeChartFrame(name, meta);
frame = new JFreeChartFrame(meta);
container.setPlot(frame);
// AnchorPane pane = new AnchorPane();
// frame = new JFreeChartFrame(name, meta).display(pane);
@ -26,7 +26,7 @@ public class PlotOutputTab extends OutputTab {
public PlotOutputTab(String name, String title, Meta meta) {
super(name, title);
PlotContainer container = new PlotContainer();
frame = new JFreeChartFrame(name, meta);
frame = new JFreeChartFrame(meta);
container.setPlot(frame);
setContent(container);
}

View File

@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.text.*?>
<?import org.controlsfx.control.*?>
<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.ToggleButton?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import org.controlsfx.control.StatusBar?>
<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.40" fx:controller="inr.numass.workbench.NumassWorkbenchController">
<AnchorPane id="AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.workbench.NumassWorkbenchController">
<children>
<BorderPane layoutX="-165.0" layoutY="100.0" prefHeight="200.0" prefWidth="765.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<bottom>
@ -21,12 +27,7 @@
<items>
<TabPane fx:id="stagesPane" prefHeight="200.0" prefWidth="200.0" side="LEFT" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="LogTab" closable="false" text="Log" />
<Tab text="System">
<content>
<TextArea fx:id="consoleArea" editable="false" prefHeight="200.0" prefWidth="200.0" wrapText="true" />
</content>
</Tab>
<Tab fx:id="logTab" closable="false" text="Log" />
</tabs>
</TabPane>
<VBox alignment="TOP_CENTER" style="-fx-border-color: blue;">
@ -39,6 +40,8 @@
<Font name="System Bold" size="12.0" />
</font>
</Button>
<Pane />
<ToggleButton fx:id="consoleButton" mnemonicParsing="false" text="Console" />
</items>
</ToolBar>
<ScrollPane fitToHeight="true" fitToWidth="true">

View File

@ -82,36 +82,6 @@ public class NMFile extends NamedMetaHolder implements NumassData {
return points;
}
/**
* merge of all point with given Uset
*
* @param U
* @return
*/
public NMPoint getByUset(double U) {
for (NMPoint point : points) {
if (point.getUset() == U) {
return point;
}
}
return null;
}
/**
* merge of all point with given Uread
*
* @param U
* @return
*/
public NMPoint getByUread(double U) {
for (NMPoint point : points) {
if (point.getUread() == U) {
return point;
}
}
return null;
}
@Override
public boolean isEmpty() {
return false;

View File

@ -5,7 +5,6 @@
*/
package inr.numass.storage;
import inr.numass.storage.NMPoint;
import hep.dataforge.meta.Meta;
import hep.dataforge.names.Named;
import java.time.Instant;
@ -15,7 +14,7 @@ import java.util.List;
*
* @author Alexander Nozik <altavir@gmail.com>
*/
public interface NumassData extends Named{
public interface NumassData extends Named {
String getDescription();
@ -27,4 +26,34 @@ public interface NumassData extends Named{
Instant startTime();
/**
* Find first point with given Uset
*
* @param U
* @return
*/
default NMPoint getByUset(double U) {
for (NMPoint point : getNMPoints()) {
if (point.getUset() == U) {
return point;
}
}
return null;
}
/**
* Find first point with given Uread
*
* @param U
* @return
*/
default NMPoint getByUread(double U) {
for (NMPoint point : getNMPoints()) {
if (point.getUread() == U) {
return point;
}
}
return null;
}
}

View File

@ -15,6 +15,7 @@
*/
package inr.numass.storage;
import hep.dataforge.context.GlobalContext;
import hep.dataforge.data.binary.Binary;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.io.envelopes.DefaultEnvelopeReader;
@ -31,24 +32,19 @@ import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import static org.apache.commons.vfs2.FileType.FOLDER;
import org.apache.commons.vfs2.VFS;
import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider;
import org.slf4j.LoggerFactory;
/**
@ -75,7 +71,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
public static final String HV_FRAGMENT_NAME = "voltage";
public static NumassDataLoader fromLocalDir(Storage storage, File directory) throws IOException {
return fromDir(storage, new DefaultLocalFileProvider().findLocalFile(directory), null);
return fromDir(storage, VFS.getManager().toFileObject(directory), null);
}
public static NumassDataLoader fromZip(Storage storage, FileObject zipFile) throws IOException {
@ -98,6 +94,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
Meta annotation = new MetaBuilder("loader")
.putValue("type", "numass")
.putValue("numass.loaderFormat", "dir")
.putValue("file.timeCreated", Instant.ofEpochMilli(directory.getContent().getLastModifiedTime()))
.build();
if (name == null || name.isEmpty()) {
@ -106,44 +103,50 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
URL url = directory.getURL();
return new NumassDataLoader(storage, name, annotation, () -> {
FileObject dir = null;
try {
dir = VFS.getManager().resolveFile(url.toString());
Map<String, Supplier<Envelope>> items = new LinkedHashMap<>();
Map<String, Envelope> items = new HashMap<>();
for (FileObject it : dir.getChildren()) {
Envelope envelope = readFile(it);
if (envelope != null) {
items.put(it.getName().getBaseName(), envelope);
}
}
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);
}
FileObject dir = null;
try {
dir = VFS.getManager().resolveFile(url.toString());
for (FileObject it : dir.getChildren()) {
items.put(it.getName().getBaseName(), () -> readFile(it));
}
} 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);
}
}
});
}
return new NumassDataLoader(storage, name, annotation, items);
}
private static Envelope readFile(FileObject file) throws FileSystemException {
String fileName = file.getName().getBaseName();
if (fileName.equals(META_FRAGMENT_NAME)
|| fileName.equals(HV_FRAGMENT_NAME)
|| fileName.startsWith(POINT_FRAGMENT_NAME)) {
return readStream(file.getContent().getInputStream());
} else {
return null;
private static Envelope readFile(FileObject file) {
//VFS file reading seems to work basly in parallel
synchronized (GlobalContext.instance()) {
String fileName = file.getName().getBaseName();
if (fileName.equals(META_FRAGMENT_NAME)
|| fileName.equals(HV_FRAGMENT_NAME)
|| fileName.startsWith(POINT_FRAGMENT_NAME)) {
try {
return readStream(file.getContent().getInputStream());
} catch (FileSystemException ex) {
LoggerFactory.getLogger(NumassDataLoader.class).error("Can't read file envelope", ex);
return null;
}
} else {
return null;
}
}
}
@ -154,7 +157,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param transformation
* @return
*/
public static NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) {
public NMPoint readPoint(Envelope envelope, Function<RawNMPoint, NMPoint> transformation) {
List<NMEvent> events = new ArrayList<>();
ByteBuffer buffer;
try {
@ -181,7 +184,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
// LocalDateTime startTime = envelope.meta().get
double u = envelope.meta().getDouble("external_meta.HV1_value", 0);
double pointTime;
if(envelope.meta().hasValue("external_meta.acquisition_time")){
if (envelope.meta().hasValue("external_meta.acquisition_time")) {
pointTime = envelope.meta().getValue("external_meta.acquisition_time").doubleValue();
} else {
pointTime = envelope.meta().getValue("acquisition_time").doubleValue();
@ -194,12 +197,15 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
return transformation.apply(raw);
}
/**
* "start_time": "2016-04-20T04:08:50",
*
* @param meta
* @return
*/
private static Instant readTime(Meta meta) {
if (meta.hasValue("date") && meta.hasValue("start_time")) {
LocalDate date = LocalDate.parse(meta.getString("date"), DateTimeFormatter.ofPattern("uuuu.MM.dd"));
LocalTime time = LocalTime.parse(meta.getString("start_time"));
LocalDateTime dateTime = LocalDateTime.of(date, time);
return dateTime.toInstant(ZoneOffset.UTC);
if (meta.hasValue("start_time")) {
return meta.getValue("start_time").timeValue();
} else {
return Instant.EPOCH;
}
@ -211,7 +217,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
* @param envelope
* @return
*/
public static NMPoint readPoint(Envelope envelope) {
public NMPoint readPoint(Envelope envelope) {
return readPoint(envelope, (p) -> new NMPoint(p));
}
@ -226,27 +232,22 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
}
}
private final Supplier<Map<String, Envelope>> items;
private final Map<String, Supplier<Envelope>> itemsProvider;
private NumassDataLoader(Storage storage, String name, Meta annotation) {
super(storage, name, annotation);
items = () -> new HashMap<>();
itemsProvider = new HashMap<>();
readOnly = true;
}
private NumassDataLoader(Storage storage, String name, Meta annotation, Supplier<Map<String, Envelope>> items) {
private NumassDataLoader(Storage storage, String name, Meta annotation, Map<String, Supplier<Envelope>> items) {
super(storage, name, annotation);
this.items = items;
this.itemsProvider = items;
readOnly = true;
}
private Map<String, Envelope> getItems() {
Map<String, Envelope> map = items.get();
if (map == null) {
return Collections.emptyMap();
} else {
return map;
}
private Map<String, Supplier<Envelope>> getItems() {
return itemsProvider;
}
@Override
@ -258,6 +259,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
public Meta getInfo() {
return getItems()
.get(META_FRAGMENT_NAME)
.get()
.meta();
}
@ -266,28 +268,16 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
// }
@Override
public List<NMPoint> getNMPoints() {
List<NMPoint> res = new ArrayList<>();
this.getPoints().stream().forEachOrdered((point) -> {
res.add(readPoint(point));
});
// res.sort((NMPoint o1, NMPoint o2) -> o1.getStartTime().compareTo(o2.getStartTime()));
return res;
return this.getPoints().stream().parallel().map(env -> readPoint(env)).collect(Collectors.toList());
}
protected List<Envelope> getPoints() {
List<Envelope> res = new ArrayList<>();
getItems().forEach((k, v) -> {
if (k.startsWith(POINT_FRAGMENT_NAME)) {
if (v != null) {
res.add(v);
}
}
});
res.sort((Envelope t, Envelope t1) -> t.meta().getInt("external_meta.point_index", -1)
.compareTo(t1.meta().getInt("external_meta.point_index", -1)));
return res;
private List<Envelope> getPoints() {
return getItems().entrySet().stream()
.filter(entry -> entry.getKey().startsWith(POINT_FRAGMENT_NAME) && entry.getValue() != null)
.map(entry -> entry.getValue().get())//TODO check for nulls?
.sorted((Envelope t, Envelope t1)
-> t.meta().getInt("external_meta.point_index", -1).compareTo(t1.meta().getInt("external_meta.point_index", -1)))
.collect(Collectors.toList());
}
@Override
@ -298,7 +288,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
@Override
public Envelope pull(String header) {
//PENDING read data to memory?
return getItems().get(header);
return getItems().get(header).get();
}
@Override
@ -313,13 +303,12 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
@Override
public Instant startTime() {
return null;
// List<NMPoint> points = getNMPoints();
// if(!points.isEmpty()){
// return points.get(0).getStartTime();
// } else {
// return null;
// }
if (meta().hasValue("file.timeCreated")) {
return meta().getValue("file.timeCreated").timeValue();
} else {
return null;
}
}
@Override

View File

@ -0,0 +1,9 @@
-injars build\libs\numass-viewer-0.3.1-all.jar
-outjars build\libs\numass-viewer-0.3.1-min.jar
-libraryjars 'c:\Program Files\Java\jdk\jre\lib\rt.jar'
-libraryjars 'C:\Program Files\Java\jdk\jre\lib\ext\jfxrt.jar'
-libraryjars 'C:\Users\darksnake\.posh_gvm\groovy\2.4.6\lib\groovy-2.4.6.jar'
-dontobfuscate
-dontwarn

View File

@ -68,7 +68,7 @@ public class MspViewController {
// .setValue("axisUnits", "mbar")
// .setValue("type", "log")
// );
JFreeChartFrame frame = new JFreeChartFrame("mspData", null);
JFreeChartFrame frame = new JFreeChartFrame();
PlotUtils.setYAxis(frame, "partial pressure", "mbar", "log");
frame.getConfig().setValue("yAxis.range.lower", 1e-10);
frame.getConfig().setValue("yAxis.range.upper", 1e-3);

View File

@ -17,8 +17,6 @@ package inr.numass.viewer;
import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.storage.api.Loader;
import hep.dataforge.storage.api.Storage;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage;
import java.time.Instant;
@ -31,6 +29,8 @@ import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeTableColumn;
import javafx.scene.control.TreeTableView;
import javafx.scene.input.MouseEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
@ -108,41 +108,41 @@ public class NumassLoaderTreeBuilder {
return node;
}
private Logger getLogger() {
return LoggerFactory.getLogger(getClass());
}
private List<TreeItem<TreeItemValue>> buildChildren(NumassStorage storage,
Consumer<NumassData> numassViewBuilder, ProcessManager.Callback callback) throws StorageException {
List<TreeItem<TreeItemValue>> list = new ArrayList<>();
for (Storage subStorage : storage.shelves().values()) {
storage.shelves().values().stream().forEach(subStorage -> {
if (subStorage instanceof NumassStorage) {
NumassStorage numassSubStorage = (NumassStorage) subStorage;
TreeItem<TreeItemValue> childNode = buildNode(numassSubStorage, numassViewBuilder, callback);
if (!childNode.isLeaf()) {
list.add(buildNode(numassSubStorage, numassViewBuilder, callback));
try {
NumassStorage numassSubStorage = (NumassStorage) subStorage;
TreeItem<TreeItemValue> childNode = buildNode(numassSubStorage, numassViewBuilder, callback);
if (!childNode.isLeaf()) {
list.add(buildNode(numassSubStorage, numassViewBuilder, callback));
}
} catch (StorageException ex) {
getLogger().error("Error while loading numass storage node", ex);
}
}
}
});
callback.updateMessage("Building storage " + storage.getName());
callback.setProgress(0);
callback.setMaxProgress(storage.loaders().size());
for (Loader loader : storage.loaders().values()) {
if (loader instanceof NumassData) {
callback.updateMessage("Building numass data loader " + loader.getName());
NumassData numassLoader = (NumassData) loader;
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(numassLoader));
// numassLoaderTreeItem.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent event) -> {
// if (event.getClickCount() >= 2) {
// TreeItemValue value = numassLoaderTreeItem.getValue();
// if (value.isLoader()) {
// numassViewBuilder.accept(value.getLoader());
// }
// }
// });
list.add(numassLoaderTreeItem);
}
callback.increaseProgress(1);
}
storage.loaders().values().stream()
.forEach(loader -> {
if (loader instanceof NumassData) {
callback.updateMessage("Building numass data loader " + loader.getName());
NumassData numassLoader = (NumassData) loader;
TreeItem<TreeItemValue> numassLoaderTreeItem = new TreeItem<>(buildValue(numassLoader));
list.add(numassLoaderTreeItem);
}
callback.increaseProgress(1);
});
callback.updateMessage("Loading legacy DAT files");
callback.setProgress(0);
@ -184,7 +184,11 @@ public class NumassLoaderTreeBuilder {
@Override
public String getTime() {
return "";
if (getStorage().meta().hasValue("file.timeModified")) {
return getStorage().meta().getValue("file.timeModified").stringValue();
} else {
return null;
}
}
@Override

View File

@ -279,7 +279,8 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
.setValue("yAxis.axisUnits", "Hz")
.setValue("legend.show", false);
spectrumPlotFrame = new JFreeChartFrame("spectrum", plotMeta).display(spectrumPlotPane);
spectrumPlotFrame = new JFreeChartFrame(plotMeta).display(spectrumPlotPane);
}
if (spectrumData == null) {
@ -337,7 +338,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab
.build())
.build();
detectorPlotFrame = new JFreeChartFrame("detectorSignal", frameMeta).display(detectorPlotPane);
detectorPlotFrame = new JFreeChartFrame(frameMeta).display(detectorPlotPane);
for (XYPlottable pl : detectorData) {
detectorPlotFrame.add(pl);