From cd8562abc0ce1a3f386f772ab78fc37bdf3cc07f Mon Sep 17 00:00:00 2001 From: darksnake Date: Mon, 30 May 2016 16:55:36 +0300 Subject: [PATCH] [no commit message] --- .../inr/numass/actions/MergeDataAction.java | 1 - .../inr/numass/actions/PrepareDataAction.java | 4 +-- .../actions/ReadNumassStorageAction.java | 30 +++++++++++++++++-- .../main/java/inr/numass/storage/NMFile.java | 2 +- .../java/inr/numass/storage/NumassData.java | 6 ++-- .../inr/numass/storage/NumassDataLoader.java | 30 ++++++++++++------- .../viewer/NumassLoaderTreeBuilder.java | 7 ++++- .../viewer/NumassLoaderViewComponent.java | 2 +- 8 files changed, 60 insertions(+), 22 deletions(-) diff --git a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java index f44005ed..1a9ba582 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -30,7 +30,6 @@ 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; diff --git a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java index 4540d239..d54610e7 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -100,8 +100,8 @@ public class PrepareDataAction extends OneToOneAction { } String head; - if (dataFile.getInfo() != null) { - head = dataFile.getInfo().toString(); + if (dataFile.meta() != null) { + head = dataFile.meta().toString(); } else { head = dataFile.getName(); } diff --git a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java index afc8336d..67496852 100644 --- a/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java +++ b/numass-main/src/main/java/inr/numass/actions/ReadNumassStorageAction.java @@ -19,6 +19,7 @@ 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.NumassDataLoader; import inr.numass.storage.NumassStorage; /** @@ -36,17 +37,36 @@ public class ReadNumassStorageAction extends GenericAction { try { NumassStorage storage = NumassStorage.buildNumassRoot(actionMeta.getString("uri"), true, false); DataFilter filter = new DataFilter().configure(actionMeta); + DataSet.Builder builder = DataSet.builder(NumassData.class); + boolean forwardOnly = actionMeta.getBoolean("forwardOnly", false); + boolean reverseOnly = actionMeta.getBoolean("reverseOnly", false); + StorageUtils.loaderStream(storage).forEach(pair -> { Loader loader = pair.getValue(); if (loader instanceof NumassData) { - Data datum = new StaticData<>((NumassData) loader); - if (filter.acceptData(pair.getKey(), datum)) { - builder.putData(pair.getKey(), datum); + NumassDataLoader nd = (NumassDataLoader) loader; + boolean reversed = nd.isReversed(); + if ((reverseOnly && reversed) || (forwardOnly && !reversed) || (!forwardOnly && !reverseOnly)) { + Data datum = new StaticData<>(nd); + if (filter.acceptData(pair.getKey(), datum)) { + builder.putData(pair.getKey(), datum); + } } } }); +// DataSet.Builder builder = DataSet.builder(NumassData.class); +// +// StorageUtils.loaderStream(storage).forEach(pair -> { +// Loader loader = pair.getValue(); +// if (loader instanceof NumassData) { +// Data datum = new StaticData<>((NumassData) loader); +// if (filter.acceptData(pair.getKey(), datum)) { +// builder.putData(pair.getKey(), datum); +// } +// } +// }); storage.legacyFiles().forEach(nd -> { Data datum = new StaticData<>(nd); @@ -60,5 +80,9 @@ public class ReadNumassStorageAction extends GenericAction { throw new RuntimeException("Failed to load storage", ex); } } + /* + + + */ } diff --git a/numass-storage/src/main/java/inr/numass/storage/NMFile.java b/numass-storage/src/main/java/inr/numass/storage/NMFile.java index c19380db..a26b246f 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NMFile.java +++ b/numass-storage/src/main/java/inr/numass/storage/NMFile.java @@ -69,7 +69,7 @@ public class NMFile extends NamedMetaHolder implements NumassData { } @Override - public Meta getInfo() { + public Meta meta() { return new MetaBuilder("info").setValue("info", head); } diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassData.java b/numass-storage/src/main/java/inr/numass/storage/NumassData.java index 530b661b..dc97f31c 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassData.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassData.java @@ -5,6 +5,7 @@ */ package inr.numass.storage; +import hep.dataforge.meta.Annotated; import hep.dataforge.meta.Meta; import hep.dataforge.names.Named; import hep.dataforge.tables.Table; @@ -16,11 +17,12 @@ import java.util.function.Supplier; * * @author Alexander Nozik */ -public interface NumassData extends Named { +public interface NumassData extends Named, Annotated { String getDescription(); - Meta getInfo(); + @Override + Meta meta(); List getNMPoints(); 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 612b9910..426c024d 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -25,6 +25,7 @@ import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; import hep.dataforge.storage.api.ObjectLoader; import hep.dataforge.storage.api.Storage; +import hep.dataforge.storage.filestorage.FileEnvelope; import hep.dataforge.storage.loaders.AbstractLoader; import hep.dataforge.tables.Table; import hep.dataforge.values.Value; @@ -35,6 +36,7 @@ import java.io.InputStream; import java.net.URL; import java.nio.ByteBuffer; import java.nio.ByteOrder; +import java.text.ParseException; import java.time.Instant; import java.util.ArrayList; import java.util.Collection; @@ -144,8 +146,8 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader MAX_EVENTS_PER_POINT) { pointTime = events.get(events.size() - 1).getTime() - events.get(0).getTime(); } @@ -234,10 +236,8 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader getNMPoints() { return this.getPoints().stream().parallel().map(env -> readPoint(env)).collect(Collectors.toList()); @@ -310,12 +308,22 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader 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? + .map(entry -> entry.getValue().get()) .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()); } + public boolean isReversed() { + //TODO replace by meta tag in later revisions + List points = getPoints(); + if (getPoints().size() >= 2) { + return readTime(points.get(0).meta()).isAfter(readTime(points.get(1).meta())); + } else { + return false; + } + } + @Override public boolean isEmpty() { return getItems().isEmpty(); diff --git a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java index 9c4856d1..5a00ffdb 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderTreeBuilder.java @@ -192,7 +192,12 @@ public class NumassLoaderTreeBuilder { @Override public String getName() { - return loader.getName(); +// if (loader.meta().getBoolean("reverse", false)) { +// return loader.getName() + " \u2191"; +// } else { +// return loader.getName(); +// } + return loader.getName(); } @Override 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 64ae8cef..1927659a 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/NumassLoaderViewComponent.java @@ -292,7 +292,7 @@ public class NumassLoaderViewComponent extends AnchorPane implements Initializab } private void setupInfo(NumassData loader) { - Meta info = loader.getInfo(); + Meta info = loader.meta(); infoTextBox.setText(new JSONMetaWriter().writeString(info, null). replace("\\r", "\r\t").replace("\\n", "\n\t")); }