From 1c3ce3ae2b4ea3e32dfc17ff182e8a97385d8c50 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 6 Jun 2018 10:23:40 +0300 Subject: [PATCH] minor update --- .../numass/scripts/timeanalysis/Histogram.kt | 75 +++++++++++++++++++ .../java/inr/numass/server/NumassRun.java | 9 +-- 2 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt new file mode 100644 index 00000000..22a334c0 --- /dev/null +++ b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/Histogram.kt @@ -0,0 +1,75 @@ +/* + * Copyright 2018 Alexander Nozik. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package inr.numass.scripts.timeanalysis + +import hep.dataforge.kodex.buildContext +import hep.dataforge.kodex.buildMeta +import hep.dataforge.maths.histogram.SimpleHistogram +import inr.numass.NumassPlugin +import inr.numass.data.NumassDataUtils +import inr.numass.data.analyzers.TimeAnalyzer +import inr.numass.data.api.NumassSet +import inr.numass.data.storage.NumassStorageFactory +import kotlin.streams.asStream + +fun main(args: Array) { + val context = buildContext("NUMASS", NumassPlugin::class.java) { + rootDir = "D:\\Work\\Numass\\sterile2018_04" + dataDir = "D:\\Work\\Numass\\data\\2018_04" + } + + val storage = NumassStorageFactory.buildLocal(context, "Fill_4", true, false); + + val meta = buildMeta { + "t0" to 3000 + "chunkSize" to 3000 + "mean" to TimeAnalyzer.AveragingMethod.ARITHMETIC + //"separateParallelBlocks" to true + "window" to { + "lo" to 0 + "up" to 4000 + } + //"plot.showErrors" to false + } + + //def sets = ((2..14) + (22..31)).collect { "set_$it" } + val sets = (2..12).map { "set_$it" } + //def sets = (16..31).collect { "set_$it" } + //def sets = (20..28).collect { "set_$it" } + + val loaders = sets.map { set -> + storage.provide("loader::$set", NumassSet::class.java).orElse(null) + }.filter { it != null } + + val joined = NumassDataUtils.join("sum", loaders) + + val hv = 14000.0 + + val point = joined.first { it.voltage == hv } + + val histogram = SimpleHistogram(arrayOf(0.0, 0.0), arrayOf(20.0, 100.0)) + histogram.fill( + TimeAnalyzer().getEventsWithDelay(point, meta) + .map { arrayOf(it.first.amplitude.toDouble(), it.second.toDouble()/1e3) } + .asStream() + ) + + histogram.binStream().forEach { + println("${it.getLowerBound(0)}\t${it.getLowerBound(1)}\t${it.count}") + } + +} \ No newline at end of file diff --git a/numass-server/src/main/java/inr/numass/server/NumassRun.java b/numass-server/src/main/java/inr/numass/server/NumassRun.java index 5a2d6fcd..02088e57 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassRun.java +++ b/numass-server/src/main/java/inr/numass/server/NumassRun.java @@ -28,12 +28,10 @@ import hep.dataforge.storage.commons.LoaderFactory; import hep.dataforge.values.Value; import hep.dataforge.values.ValueFactory; import inr.numass.data.storage.NumassStorage; -import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.time.Instant; -import java.util.concurrent.CompletableFuture; import java.util.stream.Stream; import static hep.dataforge.messages.MessagesKt.errorResponseBase; @@ -175,7 +173,7 @@ public class NumassRun implements Metoid, Responder { } //TODO add checksum here return okResponseBase("numass.data.push.response", false, false).build(); - } catch (StorageException ex) { + } catch (StorageException ex) { logger.error("Failed to push point", ex); return errorResponseBase("numass.data.push.response", ex).build(); } @@ -198,9 +196,4 @@ public class NumassRun implements Metoid, Responder { return states; } - @NotNull - @Override - public CompletableFuture respondInFuture(@NotNull Envelope message) { - return CompletableFuture.supplyAsync(() -> respond(message)); - } }