diff --git a/numass-core/src/main/java/inr/numass/NumassProperties.java b/numass-core/src/main/java/inr/numass/NumassProperties.java index 8e2ca56c..6ccdf66e 100644 --- a/numass-core/src/main/java/inr/numass/NumassProperties.java +++ b/numass-core/src/main/java/inr/numass/NumassProperties.java @@ -21,7 +21,7 @@ import java.util.Properties; public class NumassProperties { private static File getNumassPropertiesFile() throws IOException { - File file = new File(Global.instance().getUserDirectory(), "numass"); + File file = new File(Global.Companion.instance().getUserDirectory(), "numass"); if (!file.exists()) { file.mkdirs(); } @@ -54,7 +54,7 @@ public class NumassProperties { } props.store(new FileOutputStream(store), ""); } catch (IOException ex) { - Global.instance().getLogger().error("Failed to save numass properties", ex); + Global.Companion.instance().getLogger().error("Failed to save numass properties", ex); } } } diff --git a/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java b/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java index b69b4495..a8361c87 100644 --- a/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java +++ b/numass-core/src/main/java/inr/numass/data/api/SimpleNumassPoint.java @@ -2,7 +2,7 @@ package inr.numass.data.api; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.utils.MetaHolder; +import hep.dataforge.meta.MetaHolder; import java.util.ArrayList; import java.util.Collection; diff --git a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java index ab0364ad..488e5cf0 100644 --- a/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java +++ b/numass-core/src/main/java/inr/numass/data/storage/NumassStorageFactory.java @@ -69,7 +69,7 @@ public class NumassStorageFactory implements StorageType { return new NumassStorage(context, meta, path); } else { context.getLogger().warn("A storage path not provided. Creating default root storage in the working directory"); - return new NumassStorage(context, meta, context.getIo().getWorkDirectory()); + return new NumassStorage(context, meta, context.getIo().getWorkDir()); } } 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 7173ec42..c5978507 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 @@ -2,7 +2,7 @@ package inr.numass.scripts.workspace import hep.dataforge.actions.ActionUtils import hep.dataforge.context.Context -import hep.dataforge.io.IOManager +import hep.dataforge.context.IOManager import inr.numass.NumassPlugin /** diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index 37e50510..b51cc990 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -18,8 +18,8 @@ package inr.numass; import hep.dataforge.actions.ActionUtils; import hep.dataforge.context.Context; import hep.dataforge.context.Global; +import hep.dataforge.context.IOManager; import hep.dataforge.data.FileDataFactory; -import hep.dataforge.io.IOManager; import hep.dataforge.io.MetaFileReader; import hep.dataforge.meta.Meta; import org.apache.commons.cli.*; @@ -52,7 +52,7 @@ public class Main { public static void run(Context context, String[] args) throws Exception { if(context == null){ - context = Global.instance(); + context = Global.Companion.instance(); } Logger logger = LoggerFactory.getLogger("numass-main"); @@ -78,7 +78,7 @@ public class Main { if (args.length == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar DataReader.jar [OPTIONS]", options); - out().println("Trying to use default config location..."); + Companion.out().println("Trying to use default config location..."); } if (line.hasOption("c")) { diff --git a/numass-main/src/main/java/inr/numass/Numass.java b/numass-main/src/main/java/inr/numass/Numass.java index b28ca7be..5804cbf3 100644 --- a/numass-main/src/main/java/inr/numass/Numass.java +++ b/numass-main/src/main/java/inr/numass/Numass.java @@ -31,14 +31,14 @@ import hep.dataforge.meta.Meta; public class Numass { public static Context buildContext(Context parent, Meta meta) { - return Context.builder("NUMASS", parent) + return Context.Companion.builder("NUMASS", parent) .properties(meta) .plugin(NumassPlugin.class) .build(); } public static Context buildContext() { - return buildContext(Global.instance(), Meta.empty()); + return buildContext(Global.Companion.instance(), Meta.empty()); } public static void printDescription(Context context) throws DescriptorException { diff --git a/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java b/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java index 243d8aa2..8181b9d1 100644 --- a/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java +++ b/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java @@ -39,7 +39,7 @@ public class MonitorCorrector { private final List list; public MonitorCorrector(String path) throws ParseException, IOException { - this(Global.instance().getIo().getFile(path)); + this(Global.Companion.instance().getIo().getFile(path)); } public MonitorCorrector(Path monitorFile) throws ParseException, IOException { diff --git a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java index 1a0616d9..b296d5e6 100644 --- a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java +++ b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java @@ -40,7 +40,7 @@ public class OldDataReader { public static Table readConfig(String path) throws IOException { String[] list = {"X", "time", "ushift"}; ListTable.Builder res = new ListTable.Builder(list); - Path file = Global.instance().getIo().getFile(path); + Path file = Global.Companion.instance().getIo().getFile(path); Scanner sc = new Scanner(file); sc.nextLine(); @@ -62,7 +62,7 @@ public class OldDataReader { public static Table readData(String path, double Elow) { SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); - Path file = Global.instance().getIo().getFile(path); + Path file = Global.Companion.instance().getIo().getFile(path); double x; int count; int time; @@ -114,7 +114,7 @@ public class OldDataReader { public static Table readDataAsGun(String path, double Elow) { SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); - Path file = Global.instance().getIo().getFile(path); + Path file = Global.Companion.instance().getIo().getFile(path); double x; long count; int time; @@ -147,7 +147,7 @@ public class OldDataReader { public static Table readSpectrumData(String path) { SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); - Path file = Global.instance().getIo().getFile(path); + Path file = Global.Companion.instance().getIo().getFile(path); double x; double count; double time; diff --git a/numass-main/src/main/kotlin/inr/numass/NumassIO.kt b/numass-main/src/main/kotlin/inr/numass/NumassIO.kt index 1030ee3e..b21c4d68 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassIO.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassIO.kt @@ -21,9 +21,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent import ch.qos.logback.core.Appender import ch.qos.logback.core.FileAppender import hep.dataforge.context.Context +import hep.dataforge.context.DefaultIOManager +import hep.dataforge.context.IOManager import hep.dataforge.fx.plots.plusAssign -import hep.dataforge.io.BasicIOManager -import hep.dataforge.io.IOManager import hep.dataforge.meta.Meta import hep.dataforge.names.Name import hep.dataforge.plots.PlotUtils @@ -45,7 +45,7 @@ import java.util.* /** * @author Darksnake */ -class NumassIO : BasicIOManager() { +class NumassIO : DefaultIOManager() { internal var registry = ReferenceRegistry() // FileAppender appender; @@ -63,7 +63,7 @@ class NumassIO : BasicIOManager() { ple.context = lc ple.start() val appender = FileAppender() - appender.file = File(workDirectory.toFile(), meta.getString("logFileName", "numass.log")).toString() + appender.file = File(workDir.toFile(), meta.getString("logFileName", "numass.log")).toString() appender.encoder = ple return appender } @@ -103,7 +103,7 @@ class NumassIO : BasicIOManager() { val dirName = tokens.joinToString(File.separator) val fileName = name.toString() + getExtension(type) - val out = buildOut(workDirectory, dirName, fileName) + val out = buildOut(workDir, dirName, fileName) registry.add(out) return out } diff --git a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt index 38b8cb26..6364663f 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassPlugin.kt @@ -50,7 +50,7 @@ class NumassPlugin : BasicPlugin() { override fun attach(context: Context) { // StorageManager.buildFrom(context); super.attach(context) - context.getPluginManager().load(NumassIO()) + context.pluginManager.load(NumassIO()) loadModels(context.getFeature(ModelManager::class.java)) loadMath(MathPlugin.buildFrom(context)) diff --git a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt index 47a8a5a2..880002c1 100644 --- a/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt +++ b/numass-main/src/main/kotlin/inr/numass/NumassUtils.kt @@ -18,12 +18,14 @@ package inr.numass import hep.dataforge.context.Context import hep.dataforge.data.DataNode import hep.dataforge.data.DataSet +import hep.dataforge.data.binary.Binary import hep.dataforge.io.envelopes.DefaultEnvelopeType import hep.dataforge.io.envelopes.Envelope import hep.dataforge.io.envelopes.EnvelopeBuilder import hep.dataforge.io.envelopes.TaglessEnvelopeType import hep.dataforge.io.markup.Markedup import hep.dataforge.io.markup.SimpleMarkupRenderer +import hep.dataforge.kodex.nullable import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaBuilder import hep.dataforge.plots.jfreechart.JFreeChartFrame @@ -45,7 +47,6 @@ import tornadofx.* import java.awt.Color import java.awt.Font import java.io.IOException -import java.io.InputStream import java.io.OutputStream import java.lang.Math.* import java.util.* @@ -165,18 +166,10 @@ object NumassUtils { fun getFSS(context: Context, meta: Meta): FSS? { return if (meta.getBoolean("useFSS", true)) { - val fssStream = meta.optString("fssFile") - .map { fssFile -> - try { - context.io.optBinary(fssFile) - .orElseThrow({ RuntimeException("Could not locate FSS file") }) - .stream - } catch (e: IOException) { - throw RuntimeException("Could not load FSS file", e) - } - } - .orElse(context.io.optResource("data/FS.txt").get().stream) - FSS(fssStream) + val fssBinary: Binary? = meta.optString("fssFile") + .map { fssFile -> context.io.getFile(fssFile).binary } + .orElse(context.io.optResource("data/FS.txt").nullable) + fssBinary?.let { FSS(it.stream) } ?: throw RuntimeException("Could not load FSS file") } else { null } 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 b745a6b0..8084386e 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/MergeDataAction.kt @@ -120,7 +120,7 @@ class MergeDataAction : ManyToOneAction() { } companion object { - val MERGE_NAME = "mergeName" + const val MERGE_NAME = "mergeName" } } 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 94c803c1..d032382a 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -175,7 +175,7 @@ val subtractEmptyTask = task("dif") { res.goal.onComplete { r, _ -> if (r != null) { - context.getIo().out("numass.merge", input.name + "_subtract").use { + context.io.out("numass.merge", input.name + "_subtract").use { NumassUtils.write(it, resMeta, r) } } @@ -228,7 +228,7 @@ val fitTask = task("fit") { configure(meta.getMeta("fit")) } pipe { data -> - context.getIo().out("numass.fit", name).use { out -> + context.io.out("numass.fit", name).use { out -> val writer = PrintWriter(out) writer.printf("%n*** META ***%n") writer.println(meta.toString()) diff --git a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java index 15ddde55..618bc19f 100644 --- a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java +++ b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java @@ -30,7 +30,7 @@ public class TransmissionInterpolatorTest { public static void main(String[] args) { JFreeChartFrame frame = NumassPluginKt.displayJFreeChart("TransmissionInterpolatorTest"); //JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); - TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.instance(), + TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.Companion.instance(), "d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.onComplete", "Uset", "CR", 15, 0.8, 19002d); frame.add(DataPlot.plot("data", interpolator.getX(), interpolator.getY())); frame.add(XYFunctionPlot.Companion.plot("interpolated", interpolator.getXmin(), interpolator.getXmax(), 2000, interpolator::value)); diff --git a/numass-server/src/main/java/inr/numass/server/ServerRunner.java b/numass-server/src/main/java/inr/numass/server/ServerRunner.java index 7af4ac8a..ed91bc59 100644 --- a/numass-server/src/main/java/inr/numass/server/ServerRunner.java +++ b/numass-server/src/main/java/inr/numass/server/ServerRunner.java @@ -24,7 +24,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable { // private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; NumassStorage root; NumassServer listener; - Context context = Global.getContext("NUMASS_SERVER"); + Context context = Global.Companion.getContext("NUMASS_SERVER"); public ServerRunner() throws IOException, ParseException { // Global.instance().getPluginManager().load(StorageManager.class); diff --git a/numass-server/src/main/java/inr/numass/server/TestServer.java b/numass-server/src/main/java/inr/numass/server/TestServer.java index 54a0c9ed..a8914979 100644 --- a/numass-server/src/main/java/inr/numass/server/TestServer.java +++ b/numass-server/src/main/java/inr/numass/server/TestServer.java @@ -27,7 +27,7 @@ public class TestServer { * @throws hep.dataforge.exceptions.StorageException */ public static void main(String[] args) throws Exception { - Context context = Global.getContext("NUMASS-SERVER"); + Context context = Global.Companion.getContext("NUMASS-SERVER"); StorageManager storageManager = context.getPluginManager().load(StorageManager.class);