From 2af3659d3c1ee06e07bafd19512a9e8ccd8c9a9e Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Wed, 15 Aug 2018 18:53:05 +0300 Subject: [PATCH] Faster file type infer --- .../kotlin/inr/numass/NumassEnvelopeType.kt | 10 ++++----- .../inr/numass/data/analyzers/TimeAnalyzer.kt | 8 +++---- .../scripts/timeanalysis/AnalyzePoint.kt | 21 +++++++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/numass-core/src/main/kotlin/inr/numass/NumassEnvelopeType.kt b/numass-core/src/main/kotlin/inr/numass/NumassEnvelopeType.kt index 7a3c147f..19312aa9 100644 --- a/numass-core/src/main/kotlin/inr/numass/NumassEnvelopeType.kt +++ b/numass-core/src/main/kotlin/inr/numass/NumassEnvelopeType.kt @@ -103,14 +103,12 @@ class NumassEnvelopeType : EnvelopeType { return try { FileChannel.open(path, StandardOpenOption.READ).use { val buffer = it.map(FileChannel.MapMode.READ_ONLY, 0, 6) - val array = ByteArray(6) - buffer.get(array) - val header = String(array) when { //TODO use templates from appropriate types - header.startsWith("#!") -> NumassEnvelopeType.INSTANCE - header.startsWith("#~DFTL") -> TaglessEnvelopeType.INSTANCE - header.startsWith("#~") -> DefaultEnvelopeType.INSTANCE + buffer.get(0) == '#'.toByte() && buffer.get(1) == '!'.toByte() -> NumassEnvelopeType.INSTANCE + buffer.get(0) == '#'.toByte() && buffer.get(1) == '!'.toByte() && + buffer.get(4) == 'T'.toByte() && buffer.get(5) == 'L'.toByte() -> TaglessEnvelopeType.INSTANCE + buffer.get(0) == '#'.toByte() && buffer.get(1) == '~'.toByte() -> DefaultEnvelopeType.INSTANCE else -> null } } diff --git a/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt b/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt index fb2f1dfe..70df4e3b 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/analyzers/TimeAnalyzer.kt @@ -61,13 +61,13 @@ class TimeAnalyzer(processor: SignalProcessor? = null) : AbstractAnalyzer(proces val chunkSize = config.getInt("chunkSize", -1) - val res = if(chunkSize>0) { + val res = if (chunkSize > 0) { getEventsWithDelay(block, config) .chunked(chunkSize) { analyzeSequence(it.asSequence(), t0) } .toList() .mean(config.getEnum("mean", WEIGHTED)) - } else{ - analyzeSequence(getEventsWithDelay(block, config),t0) + } else { + analyzeSequence(getEventsWithDelay(block, config), t0) } return ValueMap.Builder(res) @@ -126,7 +126,7 @@ class TimeAnalyzer(processor: SignalProcessor? = null) : AbstractAnalyzer(proces */ private fun List.mean(method: AveragingMethod): Values { - if(this.isEmpty()){ + if (this.isEmpty()) { return ValueMap.Builder() .putValue(LENGTH_KEY, 0) .putValue(COUNT_KEY, 0) diff --git a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt index ab18e1b5..9a3b9276 100644 --- a/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt +++ b/numass-main/src/main/kotlin/inr/numass/scripts/timeanalysis/AnalyzePoint.kt @@ -8,7 +8,6 @@ import hep.dataforge.plots.jfreechart.JFreeChartPlugin import inr.numass.NumassPlugin import inr.numass.actions.TimeAnalyzerAction import inr.numass.data.NumassDataUtils -import inr.numass.data.analyzers.TimeAnalyzer import inr.numass.data.api.NumassPoint import inr.numass.data.api.NumassSet import inr.numass.data.api.SimpleNumassPoint @@ -19,38 +18,38 @@ fun main(args: Array) { val context = buildContext("NUMASS", NumassPlugin::class.java, JFreeChartPlugin::class.java) { output = FXOutputManager() - rootDir = "D:\\Work\\Numass\\sterile2018_04" - dataDir = "D:\\Work\\Numass\\data\\2018_04" + rootDir = "D:\\Work\\Numass\\sterile2017_11" + dataDir = "D:\\Work\\Numass\\data\\2017_11" } - val storage = NumassDirectory.read(context, "Fill_4")!! + val storage = NumassDirectory.read(context, "Fill_2")!! val meta = buildMeta { "t0" to 3000 "binNum" to 200 - "t0Step" to 100 - "chunkSize" to 3000 - "mean" to TimeAnalyzer.AveragingMethod.ARITHMETIC + "t0Step" to 600 + //"chunkSize" to 3000 + //"mean" to TimeAnalyzer.AveragingMethod.ARITHMETIC //"separateParallelBlocks" to true "window" to { - "lo" to 0 + "lo" to 400 "up" to 4000 } //"plot.showErrors" to false } //def sets = ((2..14) + (22..31)).collect { "set_$it" } - val sets = (2..12).map { "set_$it" } + val sets = (22..22).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) + storage.provide(set, NumassSet::class.java).orElse(null) }.filter { it != null } val all = NumassDataUtils.join("sum", loaders) - val hvs = listOf(12000.0, 14000.0, 16000.0)//, 15000d, 15200d, 15400d, 15600d, 15800d] + val hvs = listOf(14000.0, 15000.0)//, 15000d, 15200d, 15400d, 15600d, 15800d] //listOf(18500.0, 18600.0, 18995.0, 19000.0) val data = DataSet.edit(NumassPoint::class).apply {