Fixed Coal lazy execution

This commit is contained in:
Alexander Nozik 2017-12-10 11:14:18 +03:00
parent 038a40dbee
commit fb158ffffd
9 changed files with 126 additions and 14 deletions

View File

@ -69,7 +69,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader<Env
Meta annotation = new MetaBuilder("loader") Meta annotation = new MetaBuilder("loader")
.putValue("type", "numass") .putValue("type", "numass")
.putValue("numass.loaderFormat", "dir") .putValue("numass.loaderFormat", "dir")
// .putValue("file.timeCreated", Instant.ofEpochMilli(directory.getContent().getLastModifiedTime())) // .setValue("file.timeCreated", Instant.ofEpochMilli(directory.getContent().getLastModifiedTime()))
.build(); .build();
if (name == null || name.isEmpty()) { if (name == null || name.isEmpty()) {

View File

@ -0,0 +1,33 @@
/*
* 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.GLOBAL
import hep.dataforge.kodex.await
import hep.dataforge.workspace.FileBasedWorkspace
import kotlinx.coroutines.experimental.runBlocking
import java.io.File
fun main(args: Array<String>) {
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)
}
}

View File

@ -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<String>) {
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<Int, String>(GLOBAL.coroutineContext) {
// Thread.sleep(300)
// "the result is $it"
// }
// println(res.goal.await())
}
}

View File

@ -12,5 +12,5 @@ import inr.numass.NumassPlugin
Context context = new Context("numass"); Context context = new Context("numass");
context.loadPlugin(new NumassPlugin()); 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() ActionUtils.runConfig(context, "test.xml").computeAll()

View File

@ -96,7 +96,7 @@ public class Main {
Meta config = MetaFileReader.read(configFile); 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); applyCLItoContext(line, context);
@ -109,7 +109,7 @@ public class Main {
if (line.hasOption("h")) { if (line.hasOption("h")) {
workDir = new File(line.getOptionValue("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")) { if (line.hasOption("d")) {
@ -119,7 +119,7 @@ public class Main {
dataDir = new File(workDir, dataPath); dataDir = new File(workDir, dataPath);
} }
if (dataDir.exists() && dataDir.isDirectory()) { if (dataDir.exists() && dataDir.isDirectory()) {
context.putValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath()); context.setValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath());
} else { } else {
throw new FileNotFoundException("Data directory not found"); throw new FileNotFoundException("Data directory not found");
} }
@ -134,7 +134,7 @@ public class Main {
if (!outDir.exists()) { if (!outDir.exists()) {
outDir.mkdirs(); outDir.mkdirs();
} }
context.putValue(NumassIO.Companion.getNUMASS_OUTPUT_CONTEXT_KEY(), outDir.toString()); context.setValue(NumassIO.Companion.getNUMASS_OUTPUT_CONTEXT_KEY(), outDir.toString());
} }
} }

View File

@ -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) NumassUtils.write(it, meta, res)
} }
@ -106,8 +106,9 @@ val analyzeTask = task("analyze") {
} }
pipe<NumassSet, Table> { set -> pipe<NumassSet, Table> { set ->
SmartAnalyzer().analyzeSet(set, meta).also { res -> SmartAnalyzer().analyzeSet(set, meta).also { res ->
val outputMeta = meta.builder.putNode("data",set.meta)
context.io.out("numass.analyze", name).use { context.io.out("numass.analyze", name).use {
NumassUtils.write(it, meta, res) NumassUtils.write(it, outputMeta, res)
} }
} }
} }

View File

@ -204,8 +204,8 @@ public class NumassServer extends AbstractNetworkListener implements ContextAwar
// return responseBase("error") // return responseBase("error")
// .setDataType(MESSAGE_FAIL_CODE) // .setDataType(MESSAGE_FAIL_CODE)
// .putMetaNode(new AnnotationBuilder("error") // .putMetaNode(new AnnotationBuilder("error")
// .putValue("type", "auth") // .setValue("type", "auth")
// .putValue("message", "Authorisation faild. Need the role '"+requiredRole+"'") // .setValue("message", "Authorisation faild. Need the role '"+requiredRole+"'")
// .builder() // .builder()
// ); // );
// } // }

View File

@ -86,7 +86,7 @@ public class NumassStorageHandler extends StorageRatpackHandler {
); );
builder.putNode(new MetaBuilder("hAxis") builder.putNode(new MetaBuilder("hAxis")
.putValue("title", "timestamp") .putValue("title", "timestamp")
// .putValue("gridlines.count", -1) // .setValue("gridlines.count", -1)
// .putValues("gridlines.units.days.format", "MMM dd") // .putValues("gridlines.units.days.format", "MMM dd")
// .putValues("gridlines.units.hours.format", "HH:mm", "ha") // .putValues("gridlines.units.hours.format", "HH:mm", "ha")
); );

View File

@ -2,9 +2,9 @@ package inr.numass.viewer
import hep.dataforge.fx.dfIcon import hep.dataforge.fx.dfIcon
import hep.dataforge.fx.plots.PlotContainer import hep.dataforge.fx.plots.PlotContainer
import hep.dataforge.fx.runGoal
import hep.dataforge.fx.ui import hep.dataforge.fx.ui
import hep.dataforge.goals.Goal import hep.dataforge.goals.Goal
import hep.dataforge.kodex.Coal
import hep.dataforge.kodex.configure import hep.dataforge.kodex.configure
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
@ -124,7 +124,7 @@ class AmplitudeView(
private fun invalidate() { private fun invalidate() {
data.forEach { key, point -> data.forEach { key, point ->
plots.computeIfAbsent(key) { plots.computeIfAbsent(key) {
Coal<DataPlot> { runGoal("loadAmplitudeSpectrum_$key") {
val valueAxis = if (normalize) { val valueAxis = if (normalize) {
NumassAnalyzer.COUNT_RATE_KEY NumassAnalyzer.COUNT_RATE_KEY
} else { } else {
@ -145,7 +145,7 @@ class AmplitudeView(
}.ui { plot -> }.ui { plot ->
frame.add(plot) frame.add(plot)
progress.invalidate() progress.invalidate()
}.start() }
} }
plots.keys.filter { !data.containsKey(it) }.forEach { remove(it) } plots.keys.filter { !data.containsKey(it) }.forEach { remove(it) }
} }