From fb158ffffd66eed3d83aeb5d266a48c13cd64855 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 10 Dec 2017 11:14:18 +0300 Subject: [PATCH] Fixed Coal lazy execution --- .../numass/data/storage/NumassDataLoader.java | 2 +- .../inr/numass/scripts/temp/KotlinCall.kt | 33 ++++++++ .../inr/numass/scripts/temp/KotlinCallTest.kt | 78 +++++++++++++++++++ .../scripts/workspace/TestActions.groovy | 2 +- .../src/main/java/inr/numass/Main.java | 8 +- .../kotlin/inr/numass/tasks/NumassTasks.kt | 5 +- .../java/inr/numass/server/NumassServer.java | 4 +- .../numass/server/NumassStorageHandler.java | 2 +- .../kotlin/inr/numass/viewer/AmplitudeView.kt | 6 +- 9 files changed, 126 insertions(+), 14 deletions(-) create mode 100644 numass-main/src/main/groovy/inr/numass/scripts/temp/KotlinCall.kt create mode 100644 numass-main/src/main/groovy/inr/numass/scripts/temp/KotlinCallTest.kt diff --git a/numass-core/src/main/java/inr/numass/data/storage/NumassDataLoader.java b/numass-core/src/main/java/inr/numass/data/storage/NumassDataLoader.java index a8fd0a1c..13f80eef 100644 --- a/numass-core/src/main/java/inr/numass/data/storage/NumassDataLoader.java +++ b/numass-core/src/main/java/inr/numass/data/storage/NumassDataLoader.java @@ -69,7 +69,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader) { + val numass = FileBasedWorkspace.build(GLOBAL, File("D:\\Work\\Numass\\sterile2017_05\\workspace.groovy").toPath()) + runBlocking { + val res = numass + .runTask("analyze", "test") + .getData("Fill_2.set_2").goal.await() + println(res) + } +} diff --git a/numass-main/src/main/groovy/inr/numass/scripts/temp/KotlinCallTest.kt b/numass-main/src/main/groovy/inr/numass/scripts/temp/KotlinCallTest.kt new file mode 100644 index 00000000..0c32d564 --- /dev/null +++ b/numass-main/src/main/groovy/inr/numass/scripts/temp/KotlinCallTest.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2017 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.scripts.temp + +import hep.dataforge.kodex.* +import hep.dataforge.meta.Meta +import hep.dataforge.workspace.BasicWorkspace +import kotlinx.coroutines.experimental.runBlocking + +fun main(args: Array) { + runBlocking { + + + val action = KPipe( + name = "test", + inType = String::class.java, + outType = String::class.java, + action = { + result { + Thread.sleep(300) + "the result is $it" + } + } + ) + + val testTask = task("test") { + model { meta -> + data("static"); + } + action(action) + } + + GLOBAL.setValue("cache.enabled", false) + + val workspace = BasicWorkspace.Builder() + .setContext(GLOBAL) + .staticData("static", "22") + .task(testTask) + .target(buildMeta("test")) + .build() + + + + val resData = workspace + .runTask("test", "test") + .getData("static") + + val taskRes = resData.goal.await() + println(taskRes) + + + val actionRes = action.run(GLOBAL, workspace.data.checked(String::class.java), Meta.empty()) + + println(actionRes.getData("static").goal.await()) + + GLOBAL.close() + +// val res = static.pipe(GLOBAL.coroutineContext) { +// Thread.sleep(300) +// "the result is $it" +// } +// println(res.goal.await()) + } +} diff --git a/numass-main/src/main/groovy/inr/numass/scripts/workspace/TestActions.groovy b/numass-main/src/main/groovy/inr/numass/scripts/workspace/TestActions.groovy index 1e4284ff..7173ec42 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/workspace/TestActions.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/workspace/TestActions.groovy @@ -12,5 +12,5 @@ import inr.numass.NumassPlugin Context context = new Context("numass"); context.loadPlugin(new NumassPlugin()); -context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, "D:\\Work\\Numass\\sterile2016"); +context.setValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, "D:\\Work\\Numass\\sterile2016"); ActionUtils.runConfig(context, "test.xml").computeAll() \ No newline at end of file diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index bde52920..37e50510 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -96,7 +96,7 @@ public class Main { Meta config = MetaFileReader.read(configFile); - context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParent().toString()); + context.setValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParent().toString()); applyCLItoContext(line, context); @@ -109,7 +109,7 @@ public class Main { if (line.hasOption("h")) { workDir = new File(line.getOptionValue("h")); - context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, workDir.toString()); + context.setValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, workDir.toString()); } if (line.hasOption("d")) { @@ -119,7 +119,7 @@ public class Main { dataDir = new File(workDir, dataPath); } if (dataDir.exists() && dataDir.isDirectory()) { - context.putValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath()); + context.setValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath()); } else { throw new FileNotFoundException("Data directory not found"); } @@ -134,7 +134,7 @@ public class Main { if (!outDir.exists()) { outDir.mkdirs(); } - context.putValue(NumassIO.Companion.getNUMASS_OUTPUT_CONTEXT_KEY(), outDir.toString()); + context.setValue(NumassIO.Companion.getNUMASS_OUTPUT_CONTEXT_KEY(), outDir.toString()); } } 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 a2a85944..28ae6d14 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -91,7 +91,7 @@ val monitorTableTask = task("monitor") { } } - context.getIo().out("numass.monitor", name).use { + context.io.out("numass.monitor", name).use { NumassUtils.write(it, meta, res) } @@ -106,8 +106,9 @@ val analyzeTask = task("analyze") { } pipe { set -> SmartAnalyzer().analyzeSet(set, meta).also { res -> + val outputMeta = meta.builder.putNode("data",set.meta) context.io.out("numass.analyze", name).use { - NumassUtils.write(it, meta, res) + NumassUtils.write(it, outputMeta, res) } } } diff --git a/numass-server/src/main/java/inr/numass/server/NumassServer.java b/numass-server/src/main/java/inr/numass/server/NumassServer.java index 977da72c..9c32c5f8 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassServer.java +++ b/numass-server/src/main/java/inr/numass/server/NumassServer.java @@ -204,8 +204,8 @@ public class NumassServer extends AbstractNetworkListener implements ContextAwar // return responseBase("error") // .setDataType(MESSAGE_FAIL_CODE) // .putMetaNode(new AnnotationBuilder("error") -// .putValue("type", "auth") -// .putValue("message", "Authorisation faild. Need the role '"+requiredRole+"'") +// .setValue("type", "auth") +// .setValue("message", "Authorisation faild. Need the role '"+requiredRole+"'") // .builder() // ); // } diff --git a/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java b/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java index 7f3caaf9..689264ab 100644 --- a/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java +++ b/numass-server/src/main/java/inr/numass/server/NumassStorageHandler.java @@ -86,7 +86,7 @@ public class NumassStorageHandler extends StorageRatpackHandler { ); builder.putNode(new MetaBuilder("hAxis") .putValue("title", "timestamp") -// .putValue("gridlines.count", -1) +// .setValue("gridlines.count", -1) // .putValues("gridlines.units.days.format", "MMM dd") // .putValues("gridlines.units.hours.format", "HH:mm", "ha") ); diff --git a/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt b/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt index 355f233b..57a746c5 100644 --- a/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt +++ b/numass-viewer/src/main/kotlin/inr/numass/viewer/AmplitudeView.kt @@ -2,9 +2,9 @@ package inr.numass.viewer import hep.dataforge.fx.dfIcon import hep.dataforge.fx.plots.PlotContainer +import hep.dataforge.fx.runGoal import hep.dataforge.fx.ui import hep.dataforge.goals.Goal -import hep.dataforge.kodex.Coal import hep.dataforge.kodex.configure import hep.dataforge.meta.Meta import hep.dataforge.plots.PlotFrame @@ -124,7 +124,7 @@ class AmplitudeView( private fun invalidate() { data.forEach { key, point -> plots.computeIfAbsent(key) { - Coal { + runGoal("loadAmplitudeSpectrum_$key") { val valueAxis = if (normalize) { NumassAnalyzer.COUNT_RATE_KEY } else { @@ -145,7 +145,7 @@ class AmplitudeView( }.ui { plot -> frame.add(plot) progress.invalidate() - }.start() + } } plots.keys.filter { !data.containsKey(it) }.forEach { remove(it) } }