minor update

This commit is contained in:
Alexander Nozik 2018-06-06 10:23:40 +03:00
parent b451af5a80
commit 1c3ce3ae2b
2 changed files with 76 additions and 8 deletions

View File

@ -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<String>) {
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}")
}
}

View File

@ -28,12 +28,10 @@ import hep.dataforge.storage.commons.LoaderFactory;
import hep.dataforge.values.Value; import hep.dataforge.values.Value;
import hep.dataforge.values.ValueFactory; import hep.dataforge.values.ValueFactory;
import inr.numass.data.storage.NumassStorage; import inr.numass.data.storage.NumassStorage;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.time.Instant; import java.time.Instant;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream; import java.util.stream.Stream;
import static hep.dataforge.messages.MessagesKt.errorResponseBase; import static hep.dataforge.messages.MessagesKt.errorResponseBase;
@ -175,7 +173,7 @@ public class NumassRun implements Metoid, Responder {
} }
//TODO add checksum here //TODO add checksum here
return okResponseBase("numass.data.push.response", false, false).build(); return okResponseBase("numass.data.push.response", false, false).build();
} catch (StorageException ex) { } catch (StorageException ex) {
logger.error("Failed to push point", ex); logger.error("Failed to push point", ex);
return errorResponseBase("numass.data.push.response", ex).build(); return errorResponseBase("numass.data.push.response", ex).build();
} }
@ -198,9 +196,4 @@ public class NumassRun implements Metoid, Responder {
return states; return states;
} }
@NotNull
@Override
public CompletableFuture<Envelope> respondInFuture(@NotNull Envelope message) {
return CompletableFuture.supplyAsync(() -> respond(message));
}
} }