[no commit message]

This commit is contained in:
darksnake 2016-05-23 16:59:02 +03:00
parent 3767d13756
commit 091dfd8f8d
6 changed files with 38 additions and 47 deletions

View File

@ -30,8 +30,7 @@ import hep.dataforge.tables.MapPoint;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Value;
import java.io.OutputStream;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
@ -58,7 +57,7 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
double monitor = meta.getDouble("monitorPoint", Double.NaN);
TreeMap<LocalDateTime, DataPoint> index = getMonitorIndex(monitor, sourceData);
TreeMap<Instant, DataPoint> index = getMonitorIndex(monitor, sourceData);
if (index.isEmpty()) {
log.reportError("No monitor points found");
return sourceData;
@ -82,9 +81,9 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
MapPoint.Builder pb = new MapPoint.Builder(dp);
pb.putValue("Monitor", 1.0);
if (!isMonitorPoint(monitor, dp) || index.isEmpty()) {
LocalDateTime time = getTime(dp);
Entry<LocalDateTime, DataPoint> previousMonitor = index.floorEntry(time);
Entry<LocalDateTime, DataPoint> nextMonitor = index.ceilingEntry(time);
Instant time = getTime(dp);
Entry<Instant, DataPoint> previousMonitor = index.floorEntry(time);
Entry<Instant, DataPoint> nextMonitor = index.ceilingEntry(time);
if (previousMonitor == null) {
previousMonitor = nextMonitor;
@ -95,10 +94,14 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
}
double p;
// p = (getTime(dp).toEpochMilli() - previousMonitor.getKey().toEpochMilli())/
p = 0.5;
if (nextMonitor.getKey().isAfter(time) && time.isAfter(previousMonitor.getKey())) {
p = 1.0 * (time.toEpochMilli() - previousMonitor.getKey().toEpochMilli())
/ (nextMonitor.getKey().toEpochMilli() - previousMonitor.getKey().toEpochMilli());
} else {
p = 0.5;
}
double corrFactor = (getCR(previousMonitor.getValue()) * p + getCR(nextMonitor.getValue()) * (1 - p)) / norm;
double corrFactor = (getCR(previousMonitor.getValue()) * (1 - p) + getCR(nextMonitor.getValue()) * p) / norm;
double corrErr = previousMonitor.getValue().getValue("CRerr").doubleValue() / getCR(previousMonitor.getValue());
double pointErr = dp.getValue("CRerr").doubleValue() / getCR(dp);
double err = Math.sqrt(corrErr * corrErr + pointErr * pointErr) * getCR(dp);
@ -156,8 +159,8 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
return point.getValue("Uset").doubleValue() == monitor;
}
private LocalDateTime getTime(DataPoint point) {
return LocalDateTime.ofInstant(point.getValue("Timestamp").timeValue(), ZoneId.systemDefault());
private Instant getTime(DataPoint point) {
return point.getValue("Timestamp").timeValue();
}
private int getTotal(DataPoint point) {
@ -168,8 +171,8 @@ public class MonitorCorrectAction extends OneToOneAction<Table, Table> {
return point.getValue("CR").doubleValue();
}
private TreeMap<LocalDateTime, DataPoint> getMonitorIndex(double monitor, Iterable<DataPoint> data) {
TreeMap<LocalDateTime, DataPoint> res = new TreeMap<>();
private TreeMap<Instant, DataPoint> getMonitorIndex(double monitor, Iterable<DataPoint> data) {
TreeMap<Instant, DataPoint> res = new TreeMap<>();
for (DataPoint dp : data) {
if (isMonitorPoint(monitor, dp)) {
res.put(getTime(dp), dp);

View File

@ -39,6 +39,7 @@ public class StagePane extends TabPane implements Named {
public synchronized void closeTab(String name) {
tabs.get(name).close();
Platform.runLater(() -> getTabs().remove(tabs.get(name)));
tabs.remove(name);
}
public synchronized TextOutputTab buildTextOutput(String name) {

View File

@ -26,10 +26,9 @@ import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.storage.api.ObjectLoader;
import hep.dataforge.storage.api.Storage;
import hep.dataforge.storage.loaders.AbstractLoader;
import hep.dataforge.tables.ListTable;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Value;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@ -42,10 +41,9 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
@ -177,9 +175,9 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
while (buffer.hasRemaining()) {
try {
short channel = (short) Short.toUnsignedInt(buffer.getShort());
long time = Integer.toUnsignedLong(buffer.getInt());
long length = Integer.toUnsignedLong(buffer.getInt());
byte status = buffer.get();
NMEvent event = new NMEvent(channel, (double) time * timeCoef * 1e-9);
NMEvent event = new NMEvent(channel, (double) length * timeCoef * 1e-9);
events.add(event);
} catch (Exception ex) {
//LoggerFactory.getLogger(MainDataReader.class).error("Error in data format", ex);
@ -333,12 +331,17 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
@Override
public Instant startTime() {
if (meta().hasValue("file.timeCreated")) {
return meta().getValue("file.timeCreated").timeValue();
//Temporary substitution for meta tag
Envelope hvEnvelope = getHVEnvelope();
if (hvEnvelope != null) {
try {
return Value.of(new Scanner(hvEnvelope.getData().getStream()).next()).timeValue();
} catch (IOException ex) {
return null;
}
} else {
return null;
}
}
@Override

View File

@ -21,7 +21,6 @@ import hep.dataforge.context.ProcessManager;
import hep.dataforge.exceptions.StorageException;
import hep.dataforge.fx.ConsoleFragment;
import hep.dataforge.fx.ProcessManagerFragment;
import inr.numass.NumassContext;
import inr.numass.NumassProperties;
import inr.numass.storage.NumassData;
import inr.numass.storage.NumassStorage;

View File

@ -38,26 +38,14 @@ import org.slf4j.LoggerFactory;
*/
public class NumassLoaderTreeBuilder {
// private final TreeTableView<TreeItemValue> numassLoaderDataTree;
// private final NumassStorage rootStorage;
// private final Consumer<NumassData> numassViewBuilder;
//
// public NumassLoaderTreeBuilder(TreeTableView<TreeItemValue> numassLoaderDataTree, NumassStorage rootStorage, Consumer<NumassData> numassViewBuilder) {
// this.numassLoaderDataTree = numassLoaderDataTree;
// this.rootStorage = rootStorage;
// this.numassViewBuilder = numassViewBuilder;
// }
public void build(ProcessManager.Callback callback,
TreeTableView<TreeItemValue> numassLoaderDataTree,
NumassStorage rootStorage,
Consumer<NumassData> numassViewBuilder) throws StorageException {
// callback.updateTitle("Load numass data (" + rootStorage.getName() + ")");
TreeItem<TreeItemValue> root = buildNode(rootStorage, numassViewBuilder, callback);
// callback.updateMessage("finished loading numass tree");
root.setExpanded(true);
// numassLoaderDataTree.setShowRoot(true);
Platform.runLater(() -> {
numassLoaderDataTree.setRoot(root);
@ -76,6 +64,8 @@ public class NumassLoaderTreeBuilder {
numassLoaderDataTree.getColumns().setAll(numassLoaderNameColumn, numassLoaderTimeColumn, nummassLoaderDescriptionColumn);
numassLoaderNameColumn.setSortType(TreeTableColumn.SortType.ASCENDING);
numassLoaderDataTree.getSortOrder().addAll(numassLoaderTimeColumn, numassLoaderNameColumn);
numassLoaderDataTree.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
if (e.getClickCount() == 2) {
TreeItemValue value = numassLoaderDataTree.getFocusModel().getFocusedCell().getTreeItem().getValue();
@ -92,17 +82,6 @@ public class NumassLoaderTreeBuilder {
private TreeItem<TreeItemValue> buildNode(NumassStorage storage,
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));
node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback));
return node;

View File

@ -16,6 +16,12 @@ See the License for the specific language governing permissions and
limitations under the License.
-->
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<?import org.controlsfx.control.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
@ -32,7 +38,7 @@ limitations under the License.
<?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.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="inr.numass.viewer.MainViewerController">
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<top>