[no commit message]
This commit is contained in:
parent
3cbc3e9aee
commit
cd8562abc0
@ -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;
|
||||
|
@ -100,8 +100,8 @@ public class PrepareDataAction extends OneToOneAction<NumassData, Table> {
|
||||
}
|
||||
|
||||
String head;
|
||||
if (dataFile.getInfo() != null) {
|
||||
head = dataFile.getInfo().toString();
|
||||
if (dataFile.meta() != null) {
|
||||
head = dataFile.meta().toString();
|
||||
} else {
|
||||
head = dataFile.getName();
|
||||
}
|
||||
|
@ -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<Void, NumassData> {
|
||||
try {
|
||||
NumassStorage storage = NumassStorage.buildNumassRoot(actionMeta.getString("uri"), true, false);
|
||||
DataFilter filter = new DataFilter().configure(actionMeta);
|
||||
|
||||
DataSet.Builder<NumassData> 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<NumassData> 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<NumassData> datum = new StaticData<>(nd);
|
||||
if (filter.acceptData(pair.getKey(), datum)) {
|
||||
builder.putData(pair.getKey(), datum);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
// 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);
|
||||
@ -60,5 +80,9 @@ public class ReadNumassStorageAction extends GenericAction<Void, NumassData> {
|
||||
throw new RuntimeException("Failed to load storage", ex);
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 <altavir@gmail.com>
|
||||
*/
|
||||
public interface NumassData extends Named {
|
||||
public interface NumassData extends Named, Annotated {
|
||||
|
||||
String getDescription();
|
||||
|
||||
Meta getInfo();
|
||||
@Override
|
||||
Meta meta();
|
||||
|
||||
List<NMPoint> getNMPoints();
|
||||
|
||||
|
@ -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<Env
|
||||
|| fileName.equals(HV_FRAGMENT_NAME)
|
||||
|| fileName.startsWith(POINT_FRAGMENT_NAME)) {
|
||||
try {
|
||||
return readStream(file.getContent().getInputStream());
|
||||
} catch (FileSystemException ex) {
|
||||
return new FileEnvelope(file.getPublicURIString(), true);
|
||||
} catch (IOException | ParseException ex) {
|
||||
LoggerFactory.getLogger(NumassDataLoader.class).error("Can't read file envelope", ex);
|
||||
return null;
|
||||
}
|
||||
@ -196,8 +198,8 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
||||
}
|
||||
|
||||
//Check if the point is composite
|
||||
boolean segmented = envelope.meta().hasValue("events") && envelope.meta().getValue("events").isList();
|
||||
|
||||
boolean segmented = envelope.meta().getBoolean("split", false);
|
||||
|
||||
if (!segmented && events.size() > 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<Env
|
||||
}
|
||||
|
||||
private static Envelope readStream(InputStream stream) {
|
||||
// Tag override = new Tag((short) 1, (short) 1, -1, 256, -1);
|
||||
try {
|
||||
return new DefaultEnvelopeReader().read(stream);
|
||||
// return new DefaultEnvelopeReader().customRead(stream, override.asProperties());
|
||||
} catch (IOException ex) {
|
||||
LoggerFactory.getLogger(NumassDataLoader.class).warn("Can't read a fragment from numass zip or directory", ex);
|
||||
return null;
|
||||
@ -268,11 +268,12 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
||||
}
|
||||
|
||||
@Override
|
||||
public Meta getInfo() {
|
||||
public Meta meta() {
|
||||
return getItems()
|
||||
.get(META_FRAGMENT_NAME)
|
||||
.get()
|
||||
.meta();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -299,9 +300,6 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
||||
}
|
||||
}
|
||||
|
||||
// public Envelope getHvData() {
|
||||
// return hvData;
|
||||
// }
|
||||
@Override
|
||||
public List<NMPoint> getNMPoints() {
|
||||
return this.getPoints().stream().parallel().map(env -> readPoint(env)).collect(Collectors.toList());
|
||||
@ -310,12 +308,22 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
|
||||
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?
|
||||
.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<Envelope> 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();
|
||||
|
@ -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
|
||||
|
@ -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"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user