diff --git a/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy b/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy index 809ba7f3..a3ec13d1 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/times/TestAnalyzer.groovy @@ -3,8 +3,8 @@ package inr.numass.scripts.times import hep.dataforge.context.Context import hep.dataforge.context.Global import hep.dataforge.fx.plots.PlotManager -import hep.dataforge.grind.Grind import hep.dataforge.grind.GrindShell +import hep.dataforge.meta.Meta import inr.numass.NumassPlugin import inr.numass.actions.TimeAnalyzerAction import inr.numass.data.SimpleChainGenerator @@ -24,20 +24,21 @@ ctx.pluginManager().load(NumassPlugin.class) new GrindShell(ctx).eval { - double cr = 15e3; + double cr = 30e3; long length = 30e9; def num = 5; + def dt = 6.5 def blocks = (1..num).collect { - def generator = new SimpleChainGenerator(1e4 + 1000*num, new JDKRandomGenerator(), { 1000 }) - generator.generateBlock(Instant.now().plusNanos(it * length), length) + def generator = new SimpleChainGenerator(cr, new JDKRandomGenerator(), { 1000 }) + generator.generateBlock(Instant.now().plusNanos(it * length), length) { prev, next -> next.timeOffset - prev.timeOffset > dt * 1000 } } def point = new SimpleNumassPoint(10000, blocks) - def meta = Grind.buildMeta(plotHist: false) + def meta = Meta.empty()//Grind.buildMeta(plotHist: false) new TimeAnalyzerAction().simpleRun(point, meta); } \ No newline at end of file diff --git a/numass-main/src/main/kotlin/inr/numass/data/ChainGenerator.kt b/numass-main/src/main/kotlin/inr/numass/data/ChainGenerator.kt index 04cbbcd7..78b0f9c8 100644 --- a/numass-main/src/main/kotlin/inr/numass/data/ChainGenerator.kt +++ b/numass-main/src/main/kotlin/inr/numass/data/ChainGenerator.kt @@ -13,24 +13,35 @@ interface ChainGenerator { fun next(event: NumassEvent?): NumassEvent - fun generateBlock(start: Instant, length: Long): NumassBlock { + fun generateBlock(start: Instant, length: Long, filter: (NumassEvent, NumassEvent) -> Boolean = { _, _ -> true }): NumassBlock { val events = ArrayList() var event = next(null) + events.add(event) while (event.timeOffset < length) { - events.add(event) - event = next(event) + val nextEvent = next(event) + if (filter(event, nextEvent)) { + event = nextEvent + if (event.timeOffset < length) { + events.add(event) + } + } } return SimpleBlock(start, Duration.ofNanos(length), events) } } -class SimpleChainGenerator(val cr: Double, private var rnd: RandomGenerator = JDKRandomGenerator(), private val amp: () -> Short = { 1 }) : ChainGenerator { +class SimpleChainGenerator( + val cr: Double, + private val rnd: RandomGenerator = JDKRandomGenerator(), + private val amp: (Long) -> Short = { 1 } +) : ChainGenerator { override fun next(event: NumassEvent?): NumassEvent { return if (event == null) { - NumassEvent(amp(), Instant.EPOCH, 0) + NumassEvent(amp(0), Instant.EPOCH, 0) } else { - NumassEvent(amp(), event.blockTime, event.timeOffset + generateDeltaTime()) + val deltaT = generateDeltaTime() + NumassEvent(amp(deltaT), event.blockTime, event.timeOffset + deltaT) } }