Migrating to new coroutines and kotlin 1.3

This commit is contained in:
Alexander Nozik 2018-11-17 20:02:37 +03:00
parent 15e7974225
commit 61aef39670
40 changed files with 145 additions and 182 deletions

View File

@ -1,10 +1,7 @@
buildscript { buildscript {
ext.kotlin_version = "1.2.70" ext.kotlin_version = "1.3.10"
repositories { repositories {
jcenter() jcenter()
maven {
url = "https://dl.bintray.com/kotlin/kotlin-eap"
}
} }
dependencies { dependencies {
@ -28,36 +25,37 @@ allprojects {
//maven { url = "https://jitpack.io" } //maven { url = "https://jitpack.io" }
maven { url = "http://dl.bintray.com/kotlin/ktor" } maven { url = "http://dl.bintray.com/kotlin/ktor" }
maven { url = "https://dl.bintray.com/kotlin/kotlinx" } maven { url = "https://dl.bintray.com/kotlin/kotlinx" }
maven { url = "https://dl.bintray.com/kotlin/kotlin-eap"}
} }
dependencies { dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.+' testImplementation group: 'junit', name: 'junit', version: '4.+'
} }
compileKotlin { compileKotlin {
kotlinOptions { kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=enable']
jvmTarget = "1.8" jvmTarget = "1.8"
javaParameters = true javaParameters = true
freeCompilerArgs += [
'-Xjvm-default=enable',
"-progressive",
"-Xuse-experimental=kotlin.Experimental"
]
} }
} }
compileTestKotlin { compileTestKotlin {
kotlinOptions { kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=enable']
jvmTarget = "1.8" jvmTarget = "1.8"
javaParameters = true javaParameters = true
} freeCompilerArgs += [
} '-Xjvm-default=enable',
"-progressive",
kotlin { "-Xuse-experimental=kotlin.Experimental"
experimental { ]
coroutines "enable"
} }
} }
} }

View File

@ -16,12 +16,12 @@ allprojects {
} }
dependencies { dependencies {
compile "hep.dataforge:plots-jfc" // project(':dataforge-plots:plots-jfc') implementation "hep.dataforge:plots-jfc" // project(':dataforge-plots:plots-jfc')
compile "hep.dataforge:dataforge-control" //project(':dataforge-control') implementation "hep.dataforge:dataforge-control" //project(':dataforge-control')
compile "hep.dataforge:dataforge-gui" implementation "hep.dataforge:dataforge-gui"
// https://mvnrepository.com/artifact/commons-cli/commons-cli // https://mvnrepository.com/artifact/commons-cli/commons-cli
compile group: 'commons-cli', name: 'commons-cli', version: '1.4' implementation group: 'commons-cli', name: 'commons-cli', version: '1.4'
} }

View File

@ -22,8 +22,8 @@ configurations {
dependencies { dependencies {
//DataForge dependencies //DataForge dependencies
compile project(':numass-control') implementation project(':numass-control')
//compile project(':numass-server') //implementation project(':numass-server')
// optional device classpath // optional device classpath
devices project(':numass-control:cryotemp') devices project(':numass-control:cryotemp')

View File

@ -11,7 +11,7 @@ version = "0.2.0";
//mainClassName = "inr.numass.readvac.Main" //mainClassName = "inr.numass.readvac.Main"
dependencies { dependencies {
compile project(':numass-control') implementation project(':numass-control')
} }
task testDevice(dependsOn: classes, type: JavaExec) { task testDevice(dependsOn: classes, type: JavaExec) {

View File

@ -17,6 +17,6 @@
version = "0.1.0" version = "0.1.0"
dependencies { dependencies {
compile project(':numass-control') implementation project(':numass-control')
compile project(':numass-core') implementation project(':numass-core')
} }

View File

@ -18,15 +18,10 @@ package inr.numass.control.dante
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.buildMeta import hep.dataforge.meta.buildMeta
import hep.dataforge.orElse
import inr.numass.control.dante.DanteClient.Companion.CommandType.* import inr.numass.control.dante.DanteClient.Companion.CommandType.*
import inr.numass.control.dante.DanteClient.Companion.Register.* import inr.numass.control.dante.DanteClient.Companion.Register.*
import inr.numass.data.NumassProto
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
import inr.numass.data.storage.ProtoNumassPoint import inr.numass.data.storage.ProtoNumassPoint
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.channels.Channel
import org.slf4j.LoggerFactory
import java.io.DataInputStream import java.io.DataInputStream
import java.io.OutputStream import java.io.OutputStream
import java.lang.Math.pow import java.lang.Math.pow
@ -38,7 +33,6 @@ import java.time.Instant
import java.util.* import java.util.*
import java.util.concurrent.atomic.AtomicLong import java.util.concurrent.atomic.AtomicLong
import kotlin.collections.HashMap import kotlin.collections.HashMap
import kotlin.coroutines.experimental.buildSequence
import kotlin.math.ceil import kotlin.math.ceil
internal val Byte.positive internal val Byte.positive
@ -254,7 +248,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
message = comChannel.receive() message = comChannel.receive()
} }
return buildSequence { return sequence {
val intBuffer = ByteBuffer.wrap(message.payload).asIntBuffer() val intBuffer = ByteBuffer.wrap(message.payload).asIntBuffer()
while (intBuffer.hasRemaining()) { while (intBuffer.hasRemaining()) {
yield(intBuffer.get()) yield(intBuffer.get())
@ -543,7 +537,7 @@ class DanteClient(val ip: String, chainLength: Int) : AutoCloseable {
* Escape the sequence using DANTE convention * Escape the sequence using DANTE convention
*/ */
private fun ByteArray.escape(): ByteArray { private fun ByteArray.escape(): ByteArray {
return buildSequence { return sequence {
this@escape.forEach { this@escape.forEach {
yield(it) yield(it)
if (it == 0xdd.toByte()) { if (it == 0xdd.toByte()) {

View File

@ -30,7 +30,6 @@ import inr.numass.data.analyzers.SimpleAnalyzer
import inr.numass.data.analyzers.withBinning import inr.numass.data.analyzers.withBinning
import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassBlock
import inr.numass.data.channel import inr.numass.data.channel
import kotlinx.coroutines.experimental.runBlocking
fun main(args: Array<String>) { fun main(args: Array<String>) {
val client = DanteClient("192.168.111.120", 8) val client = DanteClient("192.168.111.120", 8)

View File

@ -8,7 +8,7 @@ if (!hasProperty('mainClass')) {
mainClassName = mainClass mainClassName = mainClass
dependencies { dependencies {
compile project(':numass-control') implementation project(':numass-control')
} }
task talkToServer(type: JavaExec) { task talkToServer(type: JavaExec) {

View File

@ -15,23 +15,13 @@
*/ */
package inr.numass.control.magnet package inr.numass.control.magnet
import hep.dataforge.context.Context
import hep.dataforge.control.devices.AbstractDevice import hep.dataforge.control.devices.AbstractDevice
import hep.dataforge.control.ports.Port import hep.dataforge.control.ports.Port
import hep.dataforge.control.ports.PortFactory import hep.dataforge.control.ports.PortFactory
import hep.dataforge.description.ValueDef
import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.ControlException
import hep.dataforge.exceptions.PortException import hep.dataforge.exceptions.PortException
import hep.dataforge.meta.Meta
import hep.dataforge.meta.buildMeta
import hep.dataforge.states.StateDef
import hep.dataforge.states.StateDefs
import hep.dataforge.states.valueState
import hep.dataforge.utils.DateTimeUtils
import hep.dataforge.values.ValueType.*
import inr.numass.control.DeviceView import inr.numass.control.DeviceView
import inr.numass.control.magnet.fx.MagnetDisplay import inr.numass.control.magnet.fx.MagnetDisplay
import kotlinx.coroutines.experimental.runBlocking
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit

View File

@ -16,8 +16,6 @@
package inr.numass.control.magnet.fx package inr.numass.control.magnet.fx
import hep.dataforge.exceptions.PortException import hep.dataforge.exceptions.PortException
import hep.dataforge.fx.asDoubleProperty
import hep.dataforge.states.ValueState
import inr.numass.control.DeviceDisplayFX import inr.numass.control.DeviceDisplayFX
import inr.numass.control.magnet.LambdaMagnet import inr.numass.control.magnet.LambdaMagnet
import javafx.application.Platform import javafx.application.Platform
@ -26,7 +24,6 @@ import javafx.beans.value.ObservableValue
import javafx.scene.control.* import javafx.scene.control.*
import javafx.scene.layout.AnchorPane import javafx.scene.layout.AnchorPane
import javafx.scene.paint.Color import javafx.scene.paint.Color
import tornadofx.*
/** /**
* FXML Controller class * FXML Controller class
@ -61,13 +58,13 @@ class MagnetDisplay : DeviceDisplayFX<LambdaMagnet>() {
init { init {
targetIField.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String -> targetIField.textProperty().addListener { _: ObservableValue<out String>, oldValue: String, newValue: String ->
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) { if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
targetIField.text = oldValue targetIField.text = oldValue
} }
} }
magnetSpeedField.textProperty().addListener { observable: ObservableValue<out String>, oldValue: String, newValue: String -> magnetSpeedField.textProperty().addListener { _: ObservableValue<out String>, oldValue: String, newValue: String ->
if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) { if (!newValue.matches("\\d*(\\.)?\\d*".toRegex())) {
magnetSpeedField.text = oldValue magnetSpeedField.text = oldValue
} }

View File

@ -9,5 +9,5 @@ mainClassName = mainClass
dependencies { dependencies {
compile project(':numass-control') implementation project(':numass-control')
} }

View File

@ -8,7 +8,7 @@ if (!hasProperty('mainClass')) {
mainClassName = mainClass mainClassName = mainClass
dependencies { dependencies {
compile project(':numass-control') implementation project(':numass-control')
} }
task testDevice(dependsOn: classes, type: JavaExec) { task testDevice(dependsOn: classes, type: JavaExec) {

View File

@ -2,7 +2,6 @@ package inr.numass.control.readvac
import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.Sensor
import hep.dataforge.control.devices.Sensor.Companion.RESULT_VALUE import hep.dataforge.control.devices.Sensor.Companion.RESULT_VALUE
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.cli.DefaultParser import org.apache.commons.cli.DefaultParser
import org.apache.commons.cli.HelpFormatter import org.apache.commons.cli.HelpFormatter
import org.apache.commons.cli.Options import org.apache.commons.cli.Options

View File

@ -5,9 +5,6 @@
*/ */
package inr.numass.control.readvac package inr.numass.control.readvac
import hep.dataforge.connections.Connection
import hep.dataforge.connections.RoleDef
import hep.dataforge.context.Context
import hep.dataforge.control.collectors.RegularPointCollector import hep.dataforge.control.collectors.RegularPointCollector
import hep.dataforge.control.connections.Roles import hep.dataforge.control.connections.Roles
import hep.dataforge.control.devices.Device import hep.dataforge.control.devices.Device
@ -15,24 +12,9 @@ import hep.dataforge.control.devices.DeviceHub
import hep.dataforge.control.devices.DeviceListener import hep.dataforge.control.devices.DeviceListener
import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE import hep.dataforge.control.devices.PortSensor.Companion.CONNECTED_STATE
import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.Sensor
import hep.dataforge.description.ValueDef
import hep.dataforge.exceptions.ControlException import hep.dataforge.exceptions.ControlException
import hep.dataforge.meta.Meta
import hep.dataforge.names.Name
import hep.dataforge.states.StateDef
import hep.dataforge.storage.api.TableLoader
import hep.dataforge.storage.commons.LoaderFactory
import hep.dataforge.storage.commons.StorageConnection
import hep.dataforge.tables.TableFormatBuilder
import hep.dataforge.utils.DateTimeUtils
import hep.dataforge.values.Value
import hep.dataforge.values.ValueMap
import hep.dataforge.values.ValueType
import hep.dataforge.values.Values
import inr.numass.control.DeviceView import inr.numass.control.DeviceView
import inr.numass.control.StorageHelper import inr.numass.control.StorageHelper
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.time.delay
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*

View File

@ -13,12 +13,12 @@ description = "A bse package with minimal dependencies for numass"
dependencies { dependencies {
compile "hep.dataforge:dataforge-storage2" implementation "hep.dataforge:dataforge-storage2"
compile "hep.dataforge:dataforge-json" implementation "hep.dataforge:dataforge-json"
compile 'com.google.protobuf:protobuf-java:3.5.0' implementation 'com.google.protobuf:protobuf-java:3.5.0'
// https://mvnrepository.com/artifact/com.github.robtimus/sftp-fs // https://mvnrepository.com/artifact/com.github.robtimus/sftp-fs
compile group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3' implementation group: 'com.github.robtimus', name: 'sftp-fs', version: '1.1.3'
} }
protobuf { protobuf {

View File

@ -8,8 +8,6 @@ import hep.dataforge.names.Name
import hep.dataforge.storage.Storage import hep.dataforge.storage.Storage
import hep.dataforge.storage.StorageElement import hep.dataforge.storage.StorageElement
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import kotlinx.coroutines.experimental.runBlocking
import kotlin.coroutines.experimental.buildSequence
/** /**
* Created by darksnake on 03-Feb-17. * Created by darksnake on 03-Feb-17.
@ -22,7 +20,7 @@ class NumassDataFactory : DataFactory<NumassSet>(NumassSet::class.java) {
* Build the sequence of name * Build the sequence of name
*/ */
private fun Storage.sequence(prefix: Name = Name.empty()): Sequence<Pair<Name, StorageElement>> { private fun Storage.sequence(prefix: Name = Name.empty()): Sequence<Pair<Name, StorageElement>> {
return buildSequence { return sequence {
runBlocking { getChildren() }.forEach { runBlocking { getChildren() }.forEach {
val newName = prefix + it.name val newName = prefix + it.name
yield(Pair(newName, it)) yield(Pair(newName, it))

View File

@ -24,7 +24,6 @@ import hep.dataforge.storage.StorageElement
import hep.dataforge.storage.files.FileStorage import hep.dataforge.storage.files.FileStorage
import hep.dataforge.storage.files.FileStorageElement import hep.dataforge.storage.files.FileStorageElement
import inr.numass.NumassEnvelopeType import inr.numass.NumassEnvelopeType
import kotlinx.coroutines.experimental.runBlocking
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path

View File

@ -27,16 +27,16 @@ compileGroovy.dependsOn(compileKotlin)
compileGroovy.classpath += files(compileKotlin.destinationDir) compileGroovy.classpath += files(compileKotlin.destinationDir)
dependencies { dependencies {
compile group: 'commons-cli', name: 'commons-cli', version: '1.+' implementation group: 'commons-cli', name: 'commons-cli', version: '1.+'
compile group: 'commons-io', name: 'commons-io', version: '2.+' implementation group: 'commons-io', name: 'commons-io', version: '2.+'
compile project(':numass-core') implementation project(':numass-core')
compile "hep.dataforge:dataforge-minuit" //project(':dataforge-stat:dataforge-minuit') implementation "hep.dataforge:dataforge-minuit" //project(':dataforge-stat:dataforge-minuit')
compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal') implementation "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
compile "hep.dataforge:dataforge-gui" implementation "hep.dataforge:dataforge-gui"
//compile "hep.dataforge:dataforge-html" //implementation "hep.dataforge:dataforge-html"
// https://mvnrepository.com/artifact/org.ehcache/ehcache // https://mvnrepository.com/artifact/org.ehcache/ehcache
//compile group: 'org.ehcache', name: 'ehcache', version: '3.4.0' //implementation group: 'org.ehcache', name: 'ehcache', version: '3.4.0'
} }

View File

@ -37,12 +37,9 @@ import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import inr.numass.models.FSS import inr.numass.models.FSS
import inr.numass.utils.ExpressionUtils import inr.numass.utils.ExpressionUtils
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.math3.analysis.UnivariateFunction import org.apache.commons.math3.analysis.UnivariateFunction
import org.jfree.chart.plot.IntervalMarker import org.jfree.chart.plot.IntervalMarker
import org.jfree.chart.ui.RectangleInsets import org.jfree.chart.ui.RectangleInsets
import org.slf4j.Logger
import tornadofx.*
import java.awt.Color import java.awt.Color
import java.awt.Font import java.awt.Font
import java.io.IOException import java.io.IOException

View File

@ -10,9 +10,6 @@ import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_KEY
import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassBlock
import inr.numass.data.api.OrphanNumassEvent import inr.numass.data.api.OrphanNumassEvent
import inr.numass.data.api.SimpleBlock import inr.numass.data.api.SimpleBlock
import kotlinx.coroutines.experimental.channels.asReceiveChannel
import kotlinx.coroutines.experimental.channels.takeWhile
import kotlinx.coroutines.experimental.channels.toList
import org.apache.commons.math3.distribution.EnumeratedRealDistribution import org.apache.commons.math3.distribution.EnumeratedRealDistribution
import org.apache.commons.math3.random.RandomGenerator import org.apache.commons.math3.random.RandomGenerator
import java.time.Duration import java.time.Duration
@ -28,7 +25,7 @@ private fun RandomGenerator.nextDeltaTime(cr: Double): Long {
suspend fun Sequence<OrphanNumassEvent>.generateBlock(start: Instant, length: Long): NumassBlock { suspend fun Sequence<OrphanNumassEvent>.generateBlock(start: Instant, length: Long): NumassBlock {
return SimpleBlock.produce(start, Duration.ofNanos(length)) { return SimpleBlock.produce(start, Duration.ofNanos(length)) {
asReceiveChannel().takeWhile { it.timeOffset < length }.toList() takeWhile { it.timeOffset < length }.toList()
} }
} }

View File

@ -25,7 +25,6 @@ import hep.dataforge.maths.chain.Chain
import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassBlock
import inr.numass.data.api.OrphanNumassEvent import inr.numass.data.api.OrphanNumassEvent
import inr.numass.data.api.SimpleBlock import inr.numass.data.api.SimpleBlock
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.math3.random.RandomGenerator import org.apache.commons.math3.random.RandomGenerator
import java.lang.Math.max import java.lang.Math.max
import java.time.Duration import java.time.Duration

View File

@ -21,14 +21,9 @@ import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.data.XYFunctionPlot import hep.dataforge.plots.data.XYFunctionPlot
import hep.dataforge.utils.Misc import hep.dataforge.utils.Misc
import hep.dataforge.values.Values import hep.dataforge.values.Values
import kotlinx.coroutines.experimental.CompletableDeferred
import kotlinx.coroutines.experimental.Deferred
import kotlinx.coroutines.experimental.async
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.math3.analysis.BivariateFunction import org.apache.commons.math3.analysis.BivariateFunction
import org.apache.commons.math3.analysis.UnivariateFunction import org.apache.commons.math3.analysis.UnivariateFunction
import org.apache.commons.math3.exception.OutOfRangeException import org.apache.commons.math3.exception.OutOfRangeException
import org.slf4j.LoggerFactory
import java.lang.Math.exp import java.lang.Math.exp
import java.util.* import java.util.*
@ -41,6 +36,23 @@ import java.util.*
object LossCalculator { object LossCalculator {
private val cache = HashMap<Int, Deferred<UnivariateFunction>>() private val cache = HashMap<Int, Deferred<UnivariateFunction>>()
private const val ION_POTENTIAL = 15.4//eV
val adjustX = true
private fun getX(set: Values, eIn: Double): Double {
return if (adjustX) {
//From our article
set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6
} else {
set.getDouble("X")
}
}
fun p0(set: Values, eIn: Double): Double {
return LossCalculator.getLossProbability(0, getX(set, eIn))
}
fun getGunLossProbabilities(X: Double): List<Double> { fun getGunLossProbabilities(X: Double): List<Double> {
val res = ArrayList<Double>() val res = ArrayList<Double>()
@ -72,7 +84,7 @@ object LossCalculator {
} }
private fun getCachedSpectrum(order: Int): Deferred<UnivariateFunction> { private fun CoroutineScope.getCachedSpectrum(order: Int): Deferred<UnivariateFunction> {
return when { return when {
order <= 0 -> error("Non-positive loss cache order") order <= 0 -> error("Non-positive loss cache order")
order == 1 -> CompletableDeferred(singleScatterFunction) order == 1 -> CompletableDeferred(singleScatterFunction)
@ -235,23 +247,24 @@ object LossCalculator {
* порядков * порядков
* *
* @param X * @param X
* @param Ei * @param eIn
* @param Ef * @param eOut
* @return * @return
*/ */
fun getTotalLossDeriv(X: Double, Ei: Double, Ef: Double): Double { fun getTotalLossDeriv(X: Double, eIn: Double, eOut: Double): Double {
val probs = getLossProbDerivs(X) val probs = getLossProbDerivs(X)
var sum = 0.0 var sum = 0.0
for (i in 1 until probs.size) { for (i in 1 until probs.size) {
sum += probs[i] * getLossValue(i, Ei, Ef) sum += probs[i] * getLossValue(i, eIn, eOut)
} }
return sum return sum
} }
fun getTotalLossDerivBivariateFunction(X: Double): BivariateFunction { fun getTotalLossDeriv(pars: Values, eIn: Double, eOut: Double) = getTotalLossDeriv(getX(pars, eIn), eIn, eOut)
return BivariateFunction { Ei: Double, Ef: Double -> getTotalLossDeriv(X, Ei, Ef) }
} fun getTotalLossDerivBivariateFunction(X: Double) = BivariateFunction { Ei: Double, Ef: Double -> getTotalLossDeriv(X, Ei, Ef) }
/** /**
* Значение полной функции потерь с учетом всех неисчезающих порядков * Значение полной функции потерь с учетом всех неисчезающих порядков
@ -272,6 +285,8 @@ object LossCalculator {
} }
} }
fun getTotalLossValue(pars: Values, Ei: Double, Ef: Double): Double = getTotalLossValue(getX(pars, Ei), Ei, Ef)
/** /**
* порог по вероятности, до которого вычисляются компоненты функции потерь * порог по вероятности, до которого вычисляются компоненты функции потерь

View File

@ -13,7 +13,6 @@ import hep.dataforge.values.Values
import inr.numass.models.misc.LossCalculator import inr.numass.models.misc.LossCalculator
import inr.numass.utils.ExpressionUtils import inr.numass.utils.ExpressionUtils
import org.apache.commons.math3.analysis.BivariateFunction import org.apache.commons.math3.analysis.BivariateFunction
import org.slf4j.LoggerFactory
import java.util.* import java.util.*
/** /**
@ -44,23 +43,10 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
} }
} }
private fun getX(eIn: Double, set: Values): Double {
return if (adjustX) {
//From our article
set.getDouble("X") * Math.log(eIn / ION_POTENTIAL) * eIn * ION_POTENTIAL / 1.9580741410115568e6
} else {
set.getDouble("X")
}
}
fun p0(eIn: Double, set: Values): Double {
return LossCalculator.getLossProbability(0, getX(eIn, set))
}
override fun derivValue(parName: String, eIn: Double, eOut: Double, set: Values): Double { override fun derivValue(parName: String, eIn: Double, eOut: Double, set: Values): Double {
return when (parName) { return when (parName) {
"trap" -> trapFunc.value(eIn, eOut) "trap" -> trapFunc.value(eIn, eOut)
"X" -> LossCalculator.getTotalLossDeriv(getX(eIn, set), eIn, eOut) "X" -> LossCalculator.getTotalLossDeriv(set, eIn, eOut)
else -> super.derivValue(parName, eIn, eOut, set) else -> super.derivValue(parName, eIn, eOut, set)
} }
} }
@ -70,10 +56,8 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
} }
override fun value(eIn: Double, eOut: Double, set: Values): Double { override fun value(eIn: Double, eOut: Double, set: Values): Double {
//calculate X taking into account its energy dependence
val X = getX(eIn, set)
// loss part // loss part
val loss = LossCalculator.getTotalLossValue(X, eIn, eOut) val loss = LossCalculator.getTotalLossValue(set, eIn, eOut)
// double loss; // double loss;
// //
// if(eIn-eOut >= 300){ // if(eIn-eOut >= 300){
@ -94,7 +78,6 @@ class NumassTransmission(context: Context, meta: Meta) : AbstractParametricBiFun
companion object { companion object {
private val list = arrayOf("trap", "X") private val list = arrayOf("trap", "X")
private const val ION_POTENTIAL = 15.4//eV
} }
} }

View File

@ -0,0 +1,39 @@
/*
* 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.models.sterile
import hep.dataforge.names.NameList
import hep.dataforge.stat.parametric.ParametricBiFunction
import hep.dataforge.values.Values
class ParametricBiFunctionCache(val function: ParametricBiFunction): ParametricBiFunction {
override fun derivValue(parName: String?, x: Double, y: Double, set: Values?): Double {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun getNames(): NameList {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun value(x: Double, y: Double, set: Values?): Double {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun providesDeriv(name: String?): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}

View File

@ -20,6 +20,7 @@ import hep.dataforge.values.ValueType.BOOLEAN
import hep.dataforge.values.Values import hep.dataforge.values.Values
import inr.numass.getFSS import inr.numass.getFSS
import inr.numass.models.FSS import inr.numass.models.FSS
import inr.numass.models.misc.LossCalculator
import inr.numass.utils.NumassIntegrator import inr.numass.utils.NumassIntegrator
/** /**
@ -46,7 +47,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
context: Context, context: Context,
configuration: Meta, configuration: Meta,
val source: ParametricBiFunction = NumassBeta(), val source: ParametricBiFunction = NumassBeta(),
val transmission: NumassTransmission = NumassTransmission(context, configuration.getMetaOrEmpty("transmission")), val transmission: ParametricBiFunction = NumassTransmission(context, configuration.getMetaOrEmpty("transmission")),
val resolution: ParametricBiFunction = NumassResolution(context, configuration.getMeta("resolution", Meta.empty())) val resolution: ParametricBiFunction = NumassResolution(context, configuration.getMeta("resolution", Meta.empty()))
) : AbstractParametricFunction(*list) { ) : AbstractParametricFunction(*list) {
@ -119,6 +120,8 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
} }
} }
private inner class TransRes : AbstractParametricBiFunction(arrayOf("X", "trap")) { private inner class TransRes : AbstractParametricBiFunction(arrayOf("X", "trap")) {
override fun providesDeriv(name: String): Boolean { override fun providesDeriv(name: String): Boolean {
@ -135,7 +138,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor(
override fun value(eIn: Double, u: Double, set: Values): Double { override fun value(eIn: Double, u: Double, set: Values): Double {
val p0 = transmission.p0(eIn, set) val p0 = LossCalculator.p0(set, eIn)
return p0 * resolution.value(eIn, u, set) + lossRes(transmission, eIn, u, set) return p0 * resolution.value(eIn, u, set) + lossRes(transmission, eIn, u, set)
} }

View File

@ -5,9 +5,6 @@ import inr.numass.actions.TimeAnalyzerAction
import inr.numass.data.NumassGenerator import inr.numass.data.NumassGenerator
import inr.numass.data.api.SimpleNumassPoint import inr.numass.data.api.SimpleNumassPoint
import inr.numass.data.generateBlock import inr.numass.data.generateBlock
import kotlinx.coroutines.experimental.channels.produce
import kotlinx.coroutines.experimental.channels.toList
import kotlinx.coroutines.experimental.runBlocking
import java.time.Instant import java.time.Instant
fun main(args: Array<String>) { fun main(args: Array<String>) {
@ -17,7 +14,7 @@ fun main(args: Array<String>) {
val start = Instant.now() val start = Instant.now()
val blockchannel = produce { val blockchannel = GlobalScope.produce {
(1..num).forEach { (1..num).forEach {
val regularChain = NumassGenerator.generateEvents(cr) val regularChain = NumassGenerator.generateEvents(cr)
val bunchChain = NumassGenerator.generateBunches(40.0, 0.01, 5.0) val bunchChain = NumassGenerator.generateBunches(40.0, 0.01, 5.0)

View File

@ -38,7 +38,6 @@ import inr.numass.data.SpectrumAdapter
import inr.numass.data.SpectrumGenerator import inr.numass.data.SpectrumGenerator
import inr.numass.models.NBkgSpectrum import inr.numass.models.NBkgSpectrum
import inr.numass.models.sterile.SterileNeutrinoSpectrum import inr.numass.models.sterile.SterileNeutrinoSpectrum
import kotlinx.coroutines.experimental.launch
import java.io.PrintWriter import java.io.PrintWriter
import kotlin.math.sqrt import kotlin.math.sqrt
@ -136,7 +135,7 @@ fun main(args: Array<String>) {
} }
plots.setType<DataPlot>() plots.setType<DataPlot>()
+plotResidual("trap", "trap" to 0.99) +plotResidual("trap", "trap" to 0.99)
launch { context.launch(Dispatchers.Main) {
try { try {
+plotFitResidual("trap_fit", "trap" to 0.99) +plotFitResidual("trap_fit", "trap" to 0.99)
} catch (ex: Exception) { } catch (ex: Exception) {
@ -144,15 +143,15 @@ fun main(args: Array<String>) {
} }
} }
+plotResidual("X", "X" to 0.11) +plotResidual("X", "X" to 0.11)
launch { context.launch(Dispatchers.Main) {
+plotFitResidual("X_fit", "X" to 0.11) +plotFitResidual("X_fit", "X" to 0.11)
} }
+plotResidual("sterile_1", "U2" to 1e-3) +plotResidual("sterile_1", "U2" to 1e-3)
launch { context.launch(Dispatchers.Main) {
+plotFitResidual("sterile_1_fit", "U2" to 1e-3) +plotFitResidual("sterile_1_fit", "U2" to 1e-3)
} }
+plotResidual("sterile_3", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3) +plotResidual("sterile_3", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
launch { context.launch(Dispatchers.Main) {
+plotFitResidual("sterile_3_fit", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3) +plotFitResidual("sterile_3_fit", "msterile2" to (3000 * 3000).toDouble(), "U2" to 1e-3)
} }

View File

@ -1,7 +1,6 @@
package inr.numass.scripts.timeanalysis package inr.numass.scripts.timeanalysis
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.coroutineContext
import hep.dataforge.fx.output.FXOutputManager import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.goals.generate import hep.dataforge.goals.generate
import hep.dataforge.goals.join import hep.dataforge.goals.join
@ -39,7 +38,7 @@ fun main(args: Array<String>) {
.withDeadTime { (dt * 1000).toLong() } .withDeadTime { (dt * 1000).toLong() }
.generateBlock(start.plusNanos(it * length), length) .generateBlock(start.plusNanos(it * length), length)
} }
}.join(Global.coroutineContext) { blocks -> }.join(Global) { blocks ->
SimpleNumassPoint(blocks, 12000.0) SimpleNumassPoint(blocks, 12000.0)
}.get() }.get()

View File

@ -17,7 +17,6 @@
package inr.numass.scripts.timeanalysis package inr.numass.scripts.timeanalysis
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.coroutineContext
import hep.dataforge.fx.output.FXOutputManager import hep.dataforge.fx.output.FXOutputManager
import hep.dataforge.goals.generate import hep.dataforge.goals.generate
import hep.dataforge.goals.join import hep.dataforge.goals.join
@ -59,7 +58,7 @@ fun main(args: Array<String>) {
.withDeadTime { (dt * 1000).toLong() } .withDeadTime { (dt * 1000).toLong() }
.generateBlock(start.plusNanos(it * length), length) .generateBlock(start.plusNanos(it * length), length)
} }
}.join(Global.coroutineContext) { blocks -> }.join(Global) { blocks ->
SimpleNumassPoint(blocks, 18000.0) SimpleNumassPoint(blocks, 18000.0)
}.get() }.get()

View File

@ -4,7 +4,6 @@ import inr.numass.data.channel
import inr.numass.data.plotAmplitudeSpectrum import inr.numass.data.plotAmplitudeSpectrum
import inr.numass.data.storage.ProtoNumassPoint import inr.numass.data.storage.ProtoNumassPoint
import inr.numass.data.transformChain import inr.numass.data.transformChain
import kotlinx.coroutines.experimental.runBlocking
import java.io.File import java.io.File
fun main(args: Array<String>) { fun main(args: Array<String>) {

View File

@ -10,7 +10,6 @@ import hep.dataforge.storage.Storage
import hep.dataforge.useValue import hep.dataforge.useValue
import inr.numass.data.storage.NumassDataLoader import inr.numass.data.storage.NumassDataLoader
import inr.numass.data.storage.NumassDirectory import inr.numass.data.storage.NumassDirectory
import kotlinx.coroutines.experimental.runBlocking
import java.io.File import java.io.File
private suspend fun createSummaryNode(storage: Storage): MetaBuilder { private suspend fun createSummaryNode(storage: Storage): MetaBuilder {

View File

@ -22,13 +22,11 @@ import inr.numass.data.api.NumassSet
import inr.numass.data.api.SimpleNumassPoint import inr.numass.data.api.SimpleNumassPoint
import inr.numass.data.storage.NumassDataLoader import inr.numass.data.storage.NumassDataLoader
import inr.numass.data.storage.NumassDirectory import inr.numass.data.storage.NumassDirectory
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.math3.analysis.ParametricUnivariateFunction import org.apache.commons.math3.analysis.ParametricUnivariateFunction
import org.apache.commons.math3.exception.DimensionMismatchException import org.apache.commons.math3.exception.DimensionMismatchException
import org.apache.commons.math3.fitting.SimpleCurveFitter import org.apache.commons.math3.fitting.SimpleCurveFitter
import org.apache.commons.math3.fitting.WeightedObservedPoint import org.apache.commons.math3.fitting.WeightedObservedPoint
import java.util.stream.Collectors import java.util.stream.Collectors
import kotlin.coroutines.experimental.buildSequence
object Threshold { object Threshold {
@ -39,7 +37,7 @@ object Threshold {
val storage = NumassDirectory.read(context, meta.getString("data.dir")) as Storage val storage = NumassDirectory.read(context, meta.getString("data.dir")) as Storage
fun Storage.loaders(): Sequence<NumassDataLoader>{ fun Storage.loaders(): Sequence<NumassDataLoader>{
return buildSequence<NumassDataLoader> { return sequence<NumassDataLoader> {
print("Reading ${this@loaders.fullName}") print("Reading ${this@loaders.fullName}")
runBlocking { this@loaders.getChildren()}.forEach { runBlocking { this@loaders.getChildren()}.forEach {
if(it is NumassDataLoader){ if(it is NumassDataLoader){

View File

@ -17,10 +17,10 @@ apply plugin: 'com.github.johnrengelman.shadow'
mainClassName = "inr.numass.server.ServerRunner" mainClassName = "inr.numass.server.ServerRunner"
dependencies { dependencies {
compile project(':numass-core') implementation project(':numass-core')
compile "hep.dataforge:storage-server" // project(':dataforge-storage:storage-servlet') implementation "hep.dataforge:storage-server" // project(':dataforge-storage:storage-servlet')
compile "hep.dataforge:dataforge-messages" implementation "hep.dataforge:dataforge-messages"
compile 'commons-daemon:commons-daemon:1.+' implementation 'commons-daemon:commons-daemon:1.+'
} }
//processResources { //processResources {

View File

@ -18,8 +18,8 @@ description = "The viewer for numass data"
dependencies { dependencies {
compile project(':numass-core') implementation project(':numass-core')
compile "hep.dataforge:plots-jfc" //project(':dataforge-plots:plots-jfc') implementation "hep.dataforge:plots-jfc" //project(':dataforge-plots:plots-jfc')
compile "hep.dataforge:dataforge-gui" implementation "hep.dataforge:dataforge-gui"
} }

View File

@ -22,9 +22,6 @@ import inr.numass.data.analyzers.SimpleAnalyzer
import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassBlock
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
import inr.numass.data.api.NumassSet import inr.numass.data.api.NumassSet
import kotlinx.coroutines.experimental.CoroutineStart
import kotlinx.coroutines.experimental.Deferred
import kotlinx.coroutines.experimental.async
private val analyzer = SimpleAnalyzer() private val analyzer = SimpleAnalyzer()
@ -35,11 +32,11 @@ class CachedPoint(val point: NumassPoint) : NumassPoint by point {
override val meta: Meta = point.meta override val meta: Meta = point.meta
val channelSpectra: Deferred<Map<Int, Table>> = async(start = CoroutineStart.LAZY) { val channelSpectra: Deferred<Map<Int, Table>> = GlobalScope.async(start = CoroutineStart.LAZY) {
point.channels.mapValues { (_, value) -> analyzer.getAmplitudeSpectrum(value) } point.channels.mapValues { (_, value) -> analyzer.getAmplitudeSpectrum(value) }
} }
val spectrum: Deferred<Table> = async(start = CoroutineStart.LAZY) { analyzer.getAmplitudeSpectrum(point) } val spectrum: Deferred<Table> = GlobalScope.async(start = CoroutineStart.LAZY) { analyzer.getAmplitudeSpectrum(point) }
} }
class CachedSet(set: NumassSet) : NumassSet by set { class CachedSet(set: NumassSet) : NumassSet by set {

View File

@ -3,9 +3,6 @@ package inr.numass.viewer
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.fx.dfIconView import hep.dataforge.fx.dfIconView
import hep.dataforge.fx.except
import hep.dataforge.fx.runGoal
import hep.dataforge.fx.ui
import hep.dataforge.storage.Storage import hep.dataforge.storage.Storage
import inr.numass.NumassProperties import inr.numass.NumassProperties
import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassPoint
@ -19,8 +16,6 @@ import javafx.scene.layout.Priority
import javafx.scene.text.Font import javafx.scene.text.Font
import javafx.stage.DirectoryChooser import javafx.stage.DirectoryChooser
import javafx.stage.FileChooser import javafx.stage.FileChooser
import org.controlsfx.control.StatusBar
import tornadofx.*
import java.io.File import java.io.File
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
@ -65,7 +60,7 @@ class MainView(val context: Context = Global.getContext("viewer")) : View(title
if (rootDir != null) { if (rootDir != null) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", rootDir.absolutePath) NumassProperties.setNumassProperty("numass.viewer.lastPath", rootDir.absolutePath)
kotlinx.coroutines.experimental.launch { GlobalScope.launch {
runLater { runLater {
path = rootDir.toPath() path = rootDir.toPath()
} }
@ -94,7 +89,7 @@ class MainView(val context: Context = Global.getContext("viewer")) : View(title
val file = chooser.showOpenDialog(primaryStage.scene.window) val file = chooser.showOpenDialog(primaryStage.scene.window)
if (file != null) { if (file != null) {
NumassProperties.setNumassProperty("numass.viewer.lastPath", file.parentFile.absolutePath) NumassProperties.setNumassProperty("numass.viewer.lastPath", file.parentFile.absolutePath)
kotlinx.coroutines.experimental.launch { GlobalScope.launch {
runLater { runLater {
path = file.toPath() path = file.toPath()
} }

View File

@ -3,11 +3,6 @@ package inr.numass.viewer
import hep.dataforge.fx.meta.MetaViewer import hep.dataforge.fx.meta.MetaViewer
import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer
import javafx.beans.property.SimpleIntegerProperty import javafx.beans.property.SimpleIntegerProperty
import kotlinx.coroutines.experimental.async
import org.controlsfx.glyphfont.FontAwesome
import tornadofx.*
import tornadofx.controlsfx.borders
import tornadofx.controlsfx.toGlyph
class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) { class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
@ -24,7 +19,7 @@ class PointInfoView(val point: CachedPoint) : MetaViewer(point.meta) {
row { row {
button(graphic = FontAwesome.Glyph.REFRESH.toGlyph()) { button(graphic = FontAwesome.Glyph.REFRESH.toGlyph()) {
action { action {
async { GlobalScope.launch {
val res = point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int } val res = point.spectrum.await().sumBy { it.getValue(NumassAnalyzer.COUNT_KEY).int }
runLater { count = res } runLater { count = res }
} }

View File

@ -14,8 +14,6 @@ import inr.numass.data.storage.NumassDataLoader
import javafx.beans.property.SimpleBooleanProperty import javafx.beans.property.SimpleBooleanProperty
import javafx.scene.control.ContextMenu import javafx.scene.control.ContextMenu
import javafx.scene.control.TreeItem import javafx.scene.control.TreeItem
import kotlinx.coroutines.experimental.runBlocking
import tornadofx.*
class StorageView(val storage: Storage) : View(title = "Numass storage", icon = dfIconView) { class StorageView(val storage: Storage) : View(title = "Numass storage", icon = dfIconView) {

View File

@ -10,7 +10,6 @@ import inr.numass.data.storage.NumassDirectory
import inr.numass.viewer.* import inr.numass.viewer.*
import javafx.application.Application import javafx.application.Application
import javafx.scene.image.ImageView import javafx.scene.image.ImageView
import tornadofx.*
import java.io.File import java.io.File
import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentHashMap
@ -33,7 +32,7 @@ class ViewerComponentsTest : View(title = "Numass viewer test", icon = ImageView
top { top {
button("Click me!") { button("Click me!") {
action { action {
kotlinx.coroutines.experimental.launch { GlobalScope.launch {
val set: NumassSet = NumassDirectory.INSTANCE.read(Global, File("D:\\Work\\Numass\\data\\2017_05\\Fill_2").toPath()) val set: NumassSet = NumassDirectory.INSTANCE.read(Global, File("D:\\Work\\Numass\\data\\2017_05\\Fill_2").toPath())
?.provide("loader::set_2", NumassSet::class.java).nullable ?.provide("loader::set_2", NumassSet::class.java).nullable
?: kotlin.error("Error") ?: kotlin.error("Error")

View File

@ -9,10 +9,10 @@ description = 'kodex/ktor based server'
//mainClassName = "inr.numass.server.ServerRunner" //mainClassName = "inr.numass.server.ServerRunner"
dependencies { dependencies {
compile "hep.dataforge:kodex-server" implementation "hep.dataforge:kodex-server"
compile "hep.dataforge:dataforge-storage" implementation "hep.dataforge:dataforge-storage"
compile "hep.dataforge:dataforge-control" implementation "hep.dataforge:dataforge-control"
compile project(":numass-core") implementation project(":numass-core")
} }
compileKotlin { compileKotlin {