Plugin system redone

This commit is contained in:
Alexander Nozik 2018-02-04 22:00:56 +03:00
parent a548acd803
commit a731d26a0e
24 changed files with 58 additions and 50 deletions

View File

@ -24,7 +24,7 @@ import kotlin.streams.toList
*/
class BoardController() : Controller(), AutoCloseable {
val contextProperty = SimpleObjectProperty<Context>(Global.instance())
val contextProperty = SimpleObjectProperty<Context>(Global)
var context: Context by contextProperty
private set
@ -38,14 +38,14 @@ class BoardController() : Controller(), AutoCloseable {
fun configure(meta: Meta) {
Context.build("NUMASS", Global.instance(), meta.getMeta("context", meta)).apply {
Context.build("NUMASS", Global, meta.getMeta("context", meta)).apply {
val numassRun = meta.optMeta("numass").map { ClientUtils.getRunName(it) }.orElse("")
meta.useMeta("storage") {
pluginManager.getOrLoad(StorageManager::class.java).configure(it);
pluginManager.load(StorageManager::class.java).configure(it);
}
val rootStorage = pluginManager.getOrLoad(StorageManager::class.java).defaultStorage
val rootStorage = pluginManager.load(StorageManager::class.java).defaultStorage
val storage = if (!numassRun.isEmpty()) {
logger.info("Run information found. Selecting run {}", numassRun)
@ -66,7 +66,7 @@ class BoardController() : Controller(), AutoCloseable {
}.also {
runLater {
context = it
devices.setAll(context.getFeature(DeviceManager::class.java).devices.toList());
devices.setAll(context.get(DeviceManager::class.java).devices.toList());
}
}
}

View File

@ -40,7 +40,7 @@ import static java.util.Locale.setDefault
setDefault(Locale.US);
new NumassPlugin().startGlobal()
FitManager fm = Global.instance().getFeature(FitManager)
FitManager fm = Global.instance().get(FitManager)
SterileNeutrinoSpectrum sp = new SterileNeutrinoSpectrum(Global.instance(), Meta.empty());

View File

@ -2,7 +2,7 @@ package inr.numass.scripts.models
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper
import hep.dataforge.meta.Meta
@ -26,7 +26,7 @@ import inr.numass.utils.DataModelUtils
import static hep.dataforge.grind.Grind.morph
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
ctx.getPluginManager().load(NumassPlugin)
new GrindShell(ctx).eval {
@ -94,7 +94,7 @@ new GrindShell(ctx).eval {
FitState state = new FitState(data, model, params);
def fm = ctx.getFeature(FitManager)
def fm = ctx.get(FitManager)
def res = fm.runStage(state, "MINUIT", FitStage.TASK_RUN, "N", "bkg", "E0", "U2");

View File

@ -3,7 +3,7 @@ package inr.numass.scripts.temp
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.description.Descriptors
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.Grind
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper
@ -21,7 +21,7 @@ import inr.numass.data.storage.NumassStorage
import inr.numass.data.storage.NumassStorageFactory
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
ctx.getPluginManager().load(NumassPlugin.class)

View File

@ -12,6 +12,6 @@ new GrindShell().eval {
def storageMeta = Grind.buildMeta(type: "numass", path: "sftp://192.168.111.1/home/trdat/data/2017_11", userName: "trdat", password: "Anomaly")
Storage storage = ctx.loadFeature("hep.dataforge:storage", StorageManager).buildStorage(storageMeta);
Storage storage = ctx.load("hep.dataforge:storage", StorageManager).buildStorage(storageMeta);
}

View File

@ -18,12 +18,12 @@ package inr.numass.scripts.temp
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
new GrindShell(ctx).eval {
(plots as PlotHelper).plotFunction(0,1){Math.sin it}

View File

@ -3,7 +3,7 @@ package inr.numass.scripts.times
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.data.DataSet
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.Grind
import hep.dataforge.grind.GrindShell
import hep.dataforge.meta.Meta
@ -21,7 +21,7 @@ import inr.numass.data.storage.NumassStorageFactory
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
ctx.getPluginManager().load(NumassPlugin)
new GrindShell(ctx).eval {

View File

@ -2,7 +2,7 @@ package inr.numass.scripts.times
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.GrindShell
import hep.dataforge.meta.Meta
import inr.numass.NumassPlugin
@ -19,7 +19,7 @@ import java.time.Instant
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
ctx.getPluginManager().load(NumassPlugin.class)
new GrindShell(ctx).eval {

View File

@ -10,7 +10,7 @@ import hep.dataforge.cache.CachePlugin
import hep.dataforge.context.Context
import hep.dataforge.context.Global
import hep.dataforge.data.DataNode
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.grind.GrindShell
import hep.dataforge.grind.helpers.PlotHelper
import hep.dataforge.io.ColumnedDataWriter
@ -30,7 +30,7 @@ import static inr.numass.data.analyzers.NumassAnalyzer.CHANNEL_KEY
import static inr.numass.data.analyzers.NumassAnalyzer.COUNT_RATE_KEY
Context ctx = Global.instance()
ctx.getPluginManager().load(PlotManager)
ctx.getPluginManager().load(FXPlotManager)
ctx.getPluginManager().load(NumassPlugin)
ctx.getPluginManager().load(CachePlugin)

View File

@ -119,7 +119,7 @@ public class Main {
dataDir = new File(workDir, dataPath);
}
if (dataDir.exists() && dataDir.isDirectory()) {
context.setValue(FileDataFactory.DATA_DIR_KEY, dataDir.getAbsolutePath());
context.setValue(FileDataFactory.Companion.getDATA_DIR_KEY(), dataDir.getAbsolutePath());
} else {
throw new FileNotFoundException("Data directory not found");
}

View File

@ -55,7 +55,7 @@ public class Numass {
.ln();
ActionManager am = context.getFeature(ActionManager.class);
ActionManager am = context.get(ActionManager.class);
am.getAllActions()
.map(name -> am.optAction(name).get())

View File

@ -51,10 +51,10 @@ class NumassPlugin : BasicPlugin() {
// StorageManager.buildFrom(context);
super.attach(context)
context.pluginManager.load(NumassIO())
loadModels(context.getFeature(ModelManager::class.java))
loadModels(context.get(ModelManager::class.java))
loadMath(MathPlugin.buildFrom(context))
context.getFeature(ActionManager::class.java).apply {
context.get(ActionManager::class.java).apply {
putTask(NumassFitScanTask::class.java)
putTask(NumassFitScanSummaryTask::class.java)
putTask(NumassFitSummaryTask::class.java)
@ -267,9 +267,8 @@ class NumassPlugin : BasicPlugin() {
}
class Factory : PluginFactory {
override fun getTag(): PluginTag {
return Plugin.resolveTag(NumassPlugin::class.java)
override fun type(): Class<out Plugin> {
return NumassPlugin::class.java
}
override fun build(meta: Meta): Plugin {

View File

@ -89,6 +89,14 @@ object NumassUtils {
return res * 1E-23
}
fun <T> wrap(obj: T, meta: Meta = Meta.empty(), serializer: OutputStream.(T) -> Unit): EnvelopeBuilder {
return EnvelopeBuilder().setMeta(meta).setData { serializer.invoke(it, obj) }
}
fun wrap(obj: Markedup, meta: Meta = Meta.empty()): EnvelopeBuilder {
return wrap(obj,meta){SimpleMarkupRenderer(this).render(it.markup(meta))}
}
/**
* Write an envelope wrapping given data to given stream

View File

@ -27,7 +27,9 @@ class AnalyzeDataAction : OneToOneAction<NumassSet, Table>() {
//TODO add processor here
val analyzer = NumassAnalyzer.DEFAULT_ANALYZER
val res = analyzer.analyzeSet(input, inputMeta)
output(context, name) { stream -> NumassUtils.write(stream, inputMeta, res) }
push(context, name, NumassUtils.wrap(res, inputMeta))
// output(context, name) { stream -> NumassUtils.write(stream, inputMeta, res) }
return res
}
}

View File

@ -41,7 +41,7 @@ class TimeAnalyzerAction : OneToOneAction<NumassPoint, Table>() {
//val t0 = inputMeta.getDouble("t0", 30e3);
// val loChannel = inputMeta.getInt("window.lo", 500);
// val upChannel = inputMeta.getInt("window.up", 10000);
val pm = context.getFeature(PlotPlugin::class.java);
val pm = context.get(PlotPlugin::class.java);
val trueCR = analyzer.analyze(input, inputMeta).getDouble("cr")

View File

@ -42,7 +42,7 @@ class TimeSpectrumAction : OneToOneAction<NumassPoint, Table>() {
val t0 = inputMeta.getDouble("t0", 30e3);
val loChannel = inputMeta.getInt("window.lo", 500);
val upChannel = inputMeta.getInt("window.up", 10000);
val pm = context.getFeature(PlotPlugin::class.java);
val pm = context.get(PlotPlugin::class.java);
val trueCR = analyzer.analyze(input, buildMeta {

View File

@ -1,8 +1,7 @@
package inr.numass.models.mc
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.global
import hep.dataforge.maths.chain.Chain
import hep.dataforge.plots.XYFunctionPlot
import hep.dataforge.stat.PolynomialDistribution
@ -17,7 +16,7 @@ fun sampleBeta(params: ParamSet): Chain<Double> {
fun main(args: Array<String>) {
NumassPlugin().startGlobal()
val pm = PlotManager().apply { startGlobal() }
val pm = FXPlotManager().apply { startGlobal() }
val meta = buildMeta("model") {
"fast" to true
node("resolution") {

View File

@ -1,6 +1,6 @@
package inr.numass.scripts
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildMeta
import inr.numass.actions.TimeAnalyzerAction
import inr.numass.data.api.SimpleNumassPoint
@ -12,7 +12,7 @@ import java.time.Instant
fun main(args: Array<String>) {
PlotManager().startGlobal()
FXPlotManager().startGlobal()
val cr = 10.0
val length = 1e12.toLong()

View File

@ -17,7 +17,7 @@
package inr.numass.scripts
import hep.dataforge.description.Descriptors
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildContext
import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.replaceColumn
@ -32,7 +32,7 @@ import inr.numass.data.storage.NumassStorageFactory
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java) {
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlotManager::class.java) {
rootDir = "D:\\Work\\Numass\\sterile\\2017_11"
dataDir = "D:\\Work\\Numass\\data\\2017_11"
}
@ -58,7 +58,7 @@ fun main(args: Array<String>) {
"window.up" to 1600
}
val plots = context.getFeature(PlotManager::class.java)
val plots = context.get(FXPlotManager::class.java)
val frame = plots.getPlotFrame("differential").apply {
this.plots.descriptor = Descriptors.buildDescriptor(DataPlot::class)

View File

@ -17,7 +17,7 @@
package inr.numass.scripts
import hep.dataforge.description.Descriptors
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildContext
import hep.dataforge.kodex.buildMeta
import hep.dataforge.plots.data.DataPlot
@ -32,7 +32,7 @@ import inr.numass.data.storage.NumassStorageFactory
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java) {
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlotManager::class.java) {
rootDir = "D:\\Work\\Numass\\sterile\\2017_11"
dataDir = "D:\\Work\\Numass\\data\\2017_11"
}
@ -63,7 +63,7 @@ fun main(args: Array<String>) {
val metaForChainInverted = metaForChain.builder.setValue("inverted", true)
val plots = context.getFeature(PlotManager::class.java)
val plots = context.get(FXPlotManager::class.java)
for (hv in arrayOf(14000.0, 14500.0, 15000.0, 15500.0, 16050.0)) {

View File

@ -17,7 +17,7 @@
package inr.numass.scripts
import hep.dataforge.description.Descriptors
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildContext
import hep.dataforge.kodex.buildMeta
import hep.dataforge.plots.data.DataPlot
@ -31,7 +31,7 @@ import java.nio.file.Paths
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java)
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlotManager::class.java)
val analyzer = SmartAnalyzer()
@ -45,7 +45,7 @@ fun main(args: Array<String>) {
val metaForChainInverted = metaForChain.builder.setValue("inverted", true)
val plots = context.getFeature(PlotManager::class.java)
val plots = context.get(FXPlotManager::class.java)
val point = ProtoNumassPoint.readFile(Paths.get("D:\\Work\\Numass\\data\\2017_05_frames\\Fill_3_events\\set_33\\p36(30s)(HV1=17000).df"))

View File

@ -1,7 +1,7 @@
package inr.numass.scripts.timeanalysis
import hep.dataforge.data.DataSet
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.kodex.buildContext
import hep.dataforge.kodex.buildMeta
import inr.numass.NumassPlugin
@ -15,7 +15,7 @@ import java.util.stream.Collectors
fun main(args: Array<String>) {
val context = buildContext("NUMASS", NumassPlugin::class.java, PlotManager::class.java) {
val context = buildContext("NUMASS", NumassPlugin::class.java, FXPlotManager::class.java) {
rootDir = "D:\\Work\\Numass\\sterile\\2017_11"
dataDir = "D:\\Work\\Numass\\data\\2017_11"
}

View File

@ -5,7 +5,7 @@ import hep.dataforge.data.DataSet
import hep.dataforge.data.DataTree
import hep.dataforge.data.DataUtils
import hep.dataforge.description.ValueDef
import hep.dataforge.fx.plots.PlotManager
import hep.dataforge.fx.plots.FXPlotManager
import hep.dataforge.fx.plots.plus
import hep.dataforge.kodex.buildMeta
import hep.dataforge.kodex.configure
@ -70,7 +70,7 @@ val monitorTableTask = task("monitor") {
).build()
if (meta.getBoolean("showPlot", true)) {
context.provide("plots", PlotManager::class.java).ifPresent {
context.provide("plots", FXPlotManager::class.java).ifPresent {
it.display(stage = "monitor") {
configure {
"xAxis.title" to "time"

View File

@ -32,7 +32,7 @@ private suspend fun ApplicationCall.json(json: suspend JsonObjectBuilder.() -> U
}
val storageInterceptor = InterceptorFactory { context, meta ->
val storageManager = context.getFeature(StorageManager::class.java);
val storageManager = context.get(StorageManager::class.java);
val storage = storageManager.buildStorage(meta);
ServerInterceptor("storage") {
get("listStorage") {
@ -86,7 +86,7 @@ val storageInterceptor = InterceptorFactory { context, meta ->
}
val deviceInterceptor = InterceptorFactory { context, meta ->
val deviceManager = context.getFeature(DeviceManager::class.java);
val deviceManager = context.get(DeviceManager::class.java);
ServerInterceptor("devices") {
get("listDevices") {
call.json {