From 66fc5f0f3c3f7b7b5ac4bb11b961a974c9053be4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 21 Jun 2018 16:28:44 +0300 Subject: [PATCH] Minor fixes --- .../inr/numass/data/storage/NumassDataLoader.kt | 5 ----- .../src/main/kotlin/inr/numass/NumassUtils.kt | 8 ++++---- .../inr/numass/actions/AnalyzeDataAction.kt | 2 +- .../kotlin/inr/numass/actions/MergeDataAction.kt | 6 ++---- .../inr/numass/actions/PlotFitResultAction.kt | 2 +- .../inr/numass/actions/TimeAnalyzerAction.kt | 2 +- .../inr/numass/actions/TimeSpectrumAction.kt | 2 +- .../inr/numass/actions/TransformDataAction.kt | 4 ++-- .../models/sterile/SterileNeutrinoSpectrum.kt | 6 ++---- .../main/kotlin/inr/numass/tasks/NumassTasks.kt | 15 +++++++-------- 10 files changed, 21 insertions(+), 31 deletions(-) diff --git a/numass-core/src/main/kotlin/inr/numass/data/storage/NumassDataLoader.kt b/numass-core/src/main/kotlin/inr/numass/data/storage/NumassDataLoader.kt index 638d6ad0..c997e850 100644 --- a/numass-core/src/main/kotlin/inr/numass/data/storage/NumassDataLoader.kt +++ b/numass-core/src/main/kotlin/inr/numass/data/storage/NumassDataLoader.kt @@ -113,14 +113,9 @@ class NumassDataLoader( TODO() } - override fun respond(message: Envelope): Envelope { - throw TODO("Not supported yet.") - } - override val startTime: Instant get() = meta.optValue("start_time").map { it.time }.orElseGet { super.startTime } - override val isOpen: Boolean get() = true diff --git a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt index 2bdc939d..bc37b77f 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt @@ -195,10 +195,10 @@ fun getFSS(context: Context, meta: Meta): FSS? { fun pointExpression(expression: String, point: Values): Double { val exprParams = HashMap() //Adding all point values to expression parameters - point.names.forEach { name -> exprParams.put(name, point.getValue(name).value) } + point.names.forEach { name -> exprParams[name] = point.getValue(name).value } //Adding aliases for commonly used parameters - exprParams.put("T", point.getDouble("length")) - exprParams.put("U", point.getDouble("voltage")) + exprParams["T"] = point.getDouble("length") + exprParams["U"] = point.getDouble("voltage") return ExpressionUtils.function(expression, exprParams) } @@ -252,7 +252,7 @@ fun Values.unbox(): Map { val res = HashMap() for (field in this.names) { val value = this.getValue(field) - res.put(field, value.value) + res[field] = value.value } return res } diff --git a/numass-main/src/main/kotlin/inr/numass/actions/AnalyzeDataAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/AnalyzeDataAction.kt index 7e3e3421..e24495cc 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/AnalyzeDataAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/AnalyzeDataAction.kt @@ -22,7 +22,7 @@ import inr.numass.data.api.NumassSet ValueDef(key = "window.lo", type = arrayOf(NUMBER, STRING), def = "0", info = "Lower bound for window"), ValueDef(key = "window.up", type = arrayOf(NUMBER, STRING), def = "10000", info = "Upper bound for window") ) -class AnalyzeDataAction : OneToOneAction() { +object AnalyzeDataAction : OneToOneAction() { override fun execute(context: Context, name: String, input: NumassSet, inputMeta: Laminate): Table { //TODO add processor here val analyzer = NumassAnalyzer.DEFAULT_ANALYZER diff --git a/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt index 71090f8d..5ac4029f 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt @@ -39,7 +39,7 @@ import java.util.* */ @TypedActionDef(name = "numass.merge", inputType = Table::class, outputType = Table::class, info = "Merge different numass data files into one.") @NodeDef(key = "grouping", info = "The definition of grouping rule for this merge", from = "method::hep.dataforge.actions.GroupBuilder.byMeta") -class MergeDataAction : ManyToOneAction() { +object MergeDataAction : ManyToOneAction() { private val parnames = arrayOf(NumassPoint.HV_KEY, NumassPoint.LENGTH_KEY, NumassAnalyzer.COUNT_KEY, NumassAnalyzer.COUNT_RATE_KEY, NumassAnalyzer.COUNT_RATE_ERROR_KEY) @@ -123,8 +123,6 @@ class MergeDataAction : ManyToOneAction() { } - companion object { - const val MERGE_NAME = "mergeName" - } + const val MERGE_NAME = "mergeName" } diff --git a/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt index fc7c0897..c78308c9 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/PlotFitResultAction.kt @@ -36,7 +36,7 @@ import java.util.stream.StreamSupport */ @TypedActionDef(name = "plotFit", info = "Plot fit result", inputType = FitState::class, outputType = FitState::class) @NodeDef(key = "adapter", info = "adapter for DataSet being fitted. By default is taken from model.") -class PlotFitResultAction : OneToOneAction() { +object PlotFitResultAction : OneToOneAction() { override fun execute(context: Context, name: String, input: FitResult, metaData: Laminate): FitResult { diff --git a/numass-main/src/main/kotlin/inr/numass/actions/TimeAnalyzerAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/TimeAnalyzerAction.kt index c6a7c28b..84276dca 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/TimeAnalyzerAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/TimeAnalyzerAction.kt @@ -34,7 +34,7 @@ import kotlin.streams.asStream NodeDef(key = "plot", info = "Configuration for stat plots") ) @TypedActionDef(name = "timeSpectrum", inputType = NumassPoint::class, outputType = Table::class) -class TimeAnalyzerAction : OneToOneAction() { +object TimeAnalyzerAction : OneToOneAction() { private val analyzer = TimeAnalyzer(); override fun execute(context: Context, name: String, input: NumassPoint, inputMeta: Laminate): Table { diff --git a/numass-main/src/main/kotlin/inr/numass/actions/TimeSpectrumAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/TimeSpectrumAction.kt index 8bdc270e..57c9bb7e 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/TimeSpectrumAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/TimeSpectrumAction.kt @@ -33,7 +33,7 @@ import kotlin.streams.asStream NodeDef(key = "plot", info = "Configuration for stat plots") ) @TypedActionDef(name = "numass.timeSpectrum", inputType = NumassPoint::class, outputType = Table::class) -class TimeSpectrumAction : OneToOneAction() { +object TimeSpectrumAction : OneToOneAction() { private val analyzer = TimeAnalyzer(); override fun execute(context: Context, name: String, input: NumassPoint, inputMeta: Laminate): Table { diff --git a/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt index 69be71db..44f97abc 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt @@ -35,7 +35,7 @@ import java.util.* ValueDef(key = "utransform", info = "Expression for voltage transformation. Uses U as input") ) @NodeDef(key = "correction", multiple = true, from = "method::inr.numass.actions.TransformDataAction.makeCorrection") -class TransformDataAction : OneToOneAction() { +object TransformDataAction : OneToOneAction() { override fun execute(context: Context, name: String, input: Table, meta: Laminate): Table { @@ -103,7 +103,7 @@ class TransformDataAction : OneToOneAction() { val res = table.addColumn(ListColumn.build(table.getColumn(COUNT_RATE_KEY).format, cr.stream())) .addColumn(ListColumn.build(table.getColumn(COUNT_RATE_ERROR_KEY).format, crErr.stream())) - context.output.get("", name).render(NumassUtils.wrap(res, meta)) + context.output["", name].render(NumassUtils.wrap(res, meta)) return res } diff --git a/numass-main/src/main/kotlin/inr/numass/models/sterile/SterileNeutrinoSpectrum.kt b/numass-main/src/main/kotlin/inr/numass/models/sterile/SterileNeutrinoSpectrum.kt index 645b0cc8..62da06cc 100644 --- a/numass-main/src/main/kotlin/inr/numass/models/sterile/SterileNeutrinoSpectrum.kt +++ b/numass-main/src/main/kotlin/inr/numass/models/sterile/SterileNeutrinoSpectrum.kt @@ -76,7 +76,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor( /** - * Direct Gauss-Legandre integration + * Direct Gauss-Legendre integration * * @param u * @param sourceFunction @@ -98,9 +98,7 @@ class SterileNeutrinoSpectrum @JvmOverloads constructor( val fsSource: (Double) -> Double = fss?.let { fss -> - { eIn: Double -> - (0 until fss.size()).sumByDouble { fss.getP(it) * sourceFunction.value(fss.getE(it), eIn, set) } - } + { eIn: Double -> (0 until fss.size()).sumByDouble { fss.getP(it) * sourceFunction.value(fss.getE(it), eIn, set) } } } ?: { eIn: Double -> sourceFunction.value(0.0, eIn, set) } diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt index 384f1ebd..68d87153 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -25,7 +25,7 @@ import hep.dataforge.values.ValueType import hep.dataforge.values.Values import inr.numass.NumassUtils import inr.numass.actions.MergeDataAction -import inr.numass.actions.MergeDataAction.Companion.MERGE_NAME +import inr.numass.actions.MergeDataAction.MERGE_NAME import inr.numass.actions.TransformDataAction import inr.numass.addSetMarkers import inr.numass.data.analyzers.SmartAnalyzer @@ -44,7 +44,7 @@ val selectTask = task("select") { } transform { data -> logger.info("Starting selection from data node with size ${data.size}") - CustomDataFilter(meta).filter(data.checked(NumassSet::class.java)).also { + CustomDataFilter(meta).filter(data.checked(NumassSet::class.java)).also { logger.info("Selected ${it.size} elements") } } @@ -99,7 +99,7 @@ val monitorTableTask = task("monitor") { ((context.output["numass.monitor", name] as? PlotOutput)?.frame as? JFreeChartFrame)?.addSetMarkers(data.values) } - context.output.get("numass.monitor", name).render(NumassUtils.wrap(res, meta)) + context.output["numass.monitor", name].render(NumassUtils.wrap(res, meta)) return@join res; } @@ -110,7 +110,7 @@ val mergeTask = task("merge") { dependsOn(analyzeTask, meta) configure(meta.getMetaOrEmpty("merge")) } - action(MergeDataAction()) + action(MergeDataAction) } val mergeEmptyTask = task("empty") { @@ -147,7 +147,7 @@ val subtractEmptyTask = task("dif") { val empty = data.getCheckedNode("empty", Table::class.java).data ?: throw RuntimeException("No empty data found") - rootNode.visit(Table::class.java, { input -> + rootNode.visit(Table::class.java) { input -> val resMeta = buildMeta { putNode("data", input.meta) putNode("empty", empty.meta) @@ -163,7 +163,7 @@ val subtractEmptyTask = task("dif") { } builder.putData(input.name, res) - }) + } builder.build() } } @@ -179,9 +179,8 @@ val transformTask = task("transform") { } else { dependsOn(analyzeTask, meta); } - configure(MetaUtils.optEither(meta, "transform", "prepare").orElse(Meta.empty())) } - action(TransformDataAction()) + action(TransformDataAction) } val filterTask = task("filter") {