diff --git a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java index 56b462e7..68f6ed12 100644 --- a/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MonitorCorrectAction.java @@ -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 { double monitor = meta.getDouble("monitorPoint", Double.NaN); - TreeMap index = getMonitorIndex(monitor, sourceData); + TreeMap index = getMonitorIndex(monitor, sourceData); if (index.isEmpty()) { log.reportError("No monitor points found"); return sourceData; @@ -82,9 +81,9 @@ public class MonitorCorrectAction extends OneToOneAction { MapPoint.Builder pb = new MapPoint.Builder(dp); pb.putValue("Monitor", 1.0); if (!isMonitorPoint(monitor, dp) || index.isEmpty()) { - LocalDateTime time = getTime(dp); - Entry previousMonitor = index.floorEntry(time); - Entry nextMonitor = index.ceilingEntry(time); + Instant time = getTime(dp); + Entry previousMonitor = index.floorEntry(time); + Entry nextMonitor = index.ceilingEntry(time); if (previousMonitor == null) { previousMonitor = nextMonitor; @@ -95,10 +94,14 @@ public class MonitorCorrectAction extends OneToOneAction { } 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 { 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 { return point.getValue("CR").doubleValue(); } - private TreeMap getMonitorIndex(double monitor, Iterable data) { - TreeMap res = new TreeMap<>(); + private TreeMap getMonitorIndex(double monitor, Iterable data) { + TreeMap res = new TreeMap<>(); for (DataPoint dp : data) { if (isMonitorPoint(monitor, dp)) { res.put(getTime(dp), dp); diff --git a/numass-main/src/main/java/inr/numass/workbench/StagePane.java b/numass-main/src/main/java/inr/numass/workbench/StagePane.java index 5908ba57..cc121c8c 100644 --- a/numass-main/src/main/java/inr/numass/workbench/StagePane.java +++ b/numass-main/src/main/java/inr/numass/workbench/StagePane.java @@ -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) { 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 f7c794a8..81498925 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -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 numassLoaderDataTree; -// private final NumassStorage rootStorage; -// private final Consumer numassViewBuilder; -// -// public NumassLoaderTreeBuilder(TreeTableView numassLoaderDataTree, NumassStorage rootStorage, Consumer numassViewBuilder) { -// this.numassLoaderDataTree = numassLoaderDataTree; -// this.rootStorage = rootStorage; -// this.numassViewBuilder = numassViewBuilder; -// } public void build(ProcessManager.Callback callback, TreeTableView numassLoaderDataTree, NumassStorage rootStorage, Consumer numassViewBuilder) throws StorageException { -// callback.updateTitle("Load numass data (" + rootStorage.getName() + ")"); TreeItem 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 buildNode(NumassStorage storage, Consumer numassViewBuilder, ProcessManager.Callback callback) throws StorageException { -// CompletableFuture> future = CompletableFuture.supplyAsync(() -> { -// try { -// TreeItem 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 node = new TreeItem<>(buildValue(storage)); node.getChildren().setAll(buildChildren(storage, numassViewBuilder, callback)); return node; diff --git a/numass-viewer/src/main/resources/fxml/MainView.fxml b/numass-viewer/src/main/resources/fxml/MainView.fxml index 3ed5e6c7..bcf314de 100644 --- a/numass-viewer/src/main/resources/fxml/MainView.fxml +++ b/numass-viewer/src/main/resources/fxml/MainView.fxml @@ -16,6 +16,12 @@ See the License for the specific language governing permissions and limitations under the License. --> + + + + + + @@ -32,7 +38,7 @@ limitations under the License. - +