A lot of minor fixes. Moving some code to kotlin

This commit is contained in:
Alexander Nozik 2017-12-20 22:32:50 +03:00
parent 01b3da3a91
commit a0087c2e17

View File

@ -6,6 +6,9 @@ import hep.dataforge.maths.chain.StatefulChain
import inr.numass.data.api.NumassBlock import inr.numass.data.api.NumassBlock
import inr.numass.data.api.NumassEvent import inr.numass.data.api.NumassEvent
import inr.numass.data.api.SimpleBlock import inr.numass.data.api.SimpleBlock
import kotlinx.coroutines.experimental.channels.takeWhile
import kotlinx.coroutines.experimental.channels.toList
import kotlinx.coroutines.experimental.runBlocking
import org.apache.commons.math3.random.JDKRandomGenerator import org.apache.commons.math3.random.JDKRandomGenerator
import org.apache.commons.math3.random.RandomGenerator import org.apache.commons.math3.random.RandomGenerator
import java.time.Duration import java.time.Duration
@ -20,7 +23,8 @@ private fun RandomGenerator.nextDeltaTime(cr: Double): Long {
} }
fun generateBlock(start: Instant, length: Long, chain: Chain<NumassEvent>): NumassBlock { fun generateBlock(start: Instant, length: Long, chain: Chain<NumassEvent>): NumassBlock {
val events = chain.asSequence().takeWhile { it.timeOffset < length }.toList()
val events = runBlocking { chain.asChannel().takeWhile { it.timeOffset < length }.toList()}
return SimpleBlock(start, Duration.ofNanos(length), events) return SimpleBlock(start, Duration.ofNanos(length), events)
} }