Numass block sorting

This commit is contained in:
darksnake 2017-07-31 22:12:57 +03:00
parent a3120d72e7
commit 115cf378e4
9 changed files with 37 additions and 33 deletions

View File

@ -8,6 +8,7 @@ import hep.dataforge.tables.TableFormatBuilder;
import inr.numass.data.api.*;
import org.jetbrains.annotations.Nullable;
import java.util.Comparator;
import java.util.stream.Stream;
import static hep.dataforge.tables.XYAdapter.*;
@ -44,7 +45,12 @@ public abstract class AbstractAnalyzer implements NumassAnalyzer {
} else if (getProcessor() == null) {
throw new IllegalArgumentException("Signal processor needed to analyze frames");
} else {
return Stream.concat(block.getEvents(), block.getFrames().flatMap(getProcessor()::analyze));
//TODO
Stream<NumassEvent> res = Stream.concat(block.getEvents(), block.getFrames().flatMap(getProcessor()::analyze));
if (config.getBoolean("sort", false)) {
res = res.sorted(Comparator.comparing(NumassEvent::getTimeOffset));
}
return res;
}
}

View File

@ -90,9 +90,6 @@ public class TimeAnalyzer extends AbstractAnalyzer {
AtomicReference<NumassEvent> lastEvent = new AtomicReference<>(null);
Stream<NumassEvent> eventStream = super.getEvents(block, config);//using super implementation
if (config.getBoolean("sort", false)) {
eventStream = eventStream.sorted();
}
return eventStream.map(event -> {
if (lastEvent.get() == null) {

View File

@ -32,11 +32,15 @@ public class MetaBlock implements NumassBlock {
@Override
public Stream<NumassEvent> getEvents() {
return blocks.stream().flatMap(NumassBlock::getEvents).sorted(Comparator.comparing(NumassEvent::getTime));
return blocks.stream()
.sorted(Comparator.comparing(NumassBlock::getStartTime))
.flatMap(NumassBlock::getEvents);
}
@Override
public Stream<NumassFrame> getFrames() {
return blocks.stream().flatMap(NumassBlock::getFrames).sorted(Comparator.comparing(NumassFrame::getTime));
return blocks.stream()
.sorted(Comparator.comparing(NumassBlock::getStartTime))
.flatMap(NumassBlock::getFrames);
}
}

View File

@ -15,8 +15,6 @@
*/
package inr.numass.data.api;
import org.jetbrains.annotations.NotNull;
import java.io.Serializable;
import java.time.Instant;
@ -25,7 +23,7 @@ import java.time.Instant;
*
* @author Darksnake
*/
public class NumassEvent implements Comparable<NumassEvent>, Serializable {
public class NumassEvent implements Serializable {
// channel
private final short chanel;
//The time of the block start
@ -65,9 +63,4 @@ public class NumassEvent implements Comparable<NumassEvent>, Serializable {
public Instant getTime() {
return blockTime.plusNanos(timeOffset);
}
@Override
public int compareTo(@NotNull NumassEvent o) {
return this.getTime().compareTo(o.getTime());
}
}

View File

@ -4,6 +4,7 @@ import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.utils.MetaHolder;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Stream;
@ -21,11 +22,13 @@ public class SimpleNumassPoint extends MetaHolder implements NumassPoint {
*/
public SimpleNumassPoint(double voltage, List<NumassBlock> blocks) {
this.blocks = blocks;
blocks.sort(Comparator.comparing(NumassBlock::getStartTime));
super.setMeta(new MetaBuilder("point").setValue(HV_KEY, voltage));
}
public SimpleNumassPoint(Meta meta, List<NumassBlock> blocks) {
super(meta);
blocks.sort(Comparator.comparing(NumassBlock::getStartTime));
this.blocks = blocks;
}

View File

@ -28,6 +28,7 @@ import hep.dataforge.storage.filestorage.FileEnvelope;
import hep.dataforge.storage.filestorage.FileStorage;
import hep.dataforge.storage.loaders.AbstractLoader;
import hep.dataforge.tables.Table;
import hep.dataforge.values.Value;
import inr.numass.data.api.NumassPoint;
import inr.numass.data.api.NumassSet;
import org.slf4j.LoggerFactory;
@ -221,11 +222,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
@Override
public Instant getStartTime() {
if (meta().hasValue("start_time")) {
return meta().getValue("start_time").timeValue();
} else {
return NumassSet.super.getStartTime();
}
return meta.optValue("start_time").map(Value::timeValue).orElseGet(()->NumassSet.super.getStartTime());
}
@Override

View File

@ -15,6 +15,7 @@ import java.nio.ByteBuffer;
import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.util.Comparator;
import java.util.stream.IntStream;
import java.util.stream.Stream;
@ -44,8 +45,11 @@ public class ProtoNumassPoint implements NumassPoint {
@Override
public Stream<NumassBlock> getBlocks() {
return getPoint().getChannelsList().stream().flatMap(channel ->
channel.getBlocksList().stream().map(block -> new ProtoBlock((int) channel.getNum(), block))
return getPoint().getChannelsList().stream()
.flatMap(channel ->
channel.getBlocksList().stream()
.map(block -> new ProtoBlock((int) channel.getNum(), block))
.sorted(Comparator.comparing(ProtoBlock::getStartTime))
);
}

View File

@ -58,6 +58,6 @@ task simulate(dependsOn: classes, type: JavaExec) {
task underflow(dependsOn: classes, type: JavaExec) {
group "numass"
main 'inr.numass.scripts.Underflow'
main 'inr.numass.scripts.underflow.Underflow'
classpath = sourceSets.main.runtimeClasspath
}

View File

@ -46,7 +46,7 @@ ctx.pluginManager().load(CachePlugin.class)
Meta meta = buildMeta {
data(dir: "D:\\Work\\Numass\\data\\2017_05\\Fill_2", mask: "set_.{1,3}")
generate(t0: 3e4, sort: true)
generate(t0: 3e4, sort: false)
subtract(reference: 18600)
fit(xlow: 450, xHigh: 700, upper: 3100, binning: 20)
}
@ -102,7 +102,7 @@ new GrindShell(ctx).eval {
spectraMap = spectra
.findAll { it.name != referenceVoltage }
.collectEntries {
return [(it.meta["voltage"].doubleValue()): NumassDataUtils.subtractSpectrum(it.get(), referencePoint)]
[(it.meta["voltage"].doubleValue()): NumassDataUtils.subtractSpectrum(it.get(), referencePoint)]
}
} else {
spectraMap = spectra.collectEntries { return [(it.meta["voltage"].doubleValue()): it.get()] }