Replaced OutputStreams with Output objects

This commit is contained in:
Alexander Nozik 2018-01-30 21:29:30 +03:00
parent 13a3376433
commit b5aece6d8e
16 changed files with 33 additions and 40 deletions

View File

@ -21,7 +21,7 @@ import java.util.Properties;
public class NumassProperties { public class NumassProperties {
private static File getNumassPropertiesFile() throws IOException { 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()) { if (!file.exists()) {
file.mkdirs(); file.mkdirs();
} }
@ -54,7 +54,7 @@ public class NumassProperties {
} }
props.store(new FileOutputStream(store), ""); props.store(new FileOutputStream(store), "");
} catch (IOException ex) { } catch (IOException ex) {
Global.instance().getLogger().error("Failed to save numass properties", ex); Global.Companion.instance().getLogger().error("Failed to save numass properties", ex);
} }
} }
} }

View File

@ -2,7 +2,7 @@ package inr.numass.data.api;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import hep.dataforge.meta.MetaBuilder; import hep.dataforge.meta.MetaBuilder;
import hep.dataforge.utils.MetaHolder; import hep.dataforge.meta.MetaHolder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;

View File

@ -69,7 +69,7 @@ public class NumassStorageFactory implements StorageType {
return new NumassStorage(context, meta, path); return new NumassStorage(context, meta, path);
} else { } else {
context.getLogger().warn("A storage path not provided. Creating default root storage in the working directory"); 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());
} }
} }

View File

@ -2,7 +2,7 @@ package inr.numass.scripts.workspace
import hep.dataforge.actions.ActionUtils import hep.dataforge.actions.ActionUtils
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.io.IOManager import hep.dataforge.context.IOManager
import inr.numass.NumassPlugin import inr.numass.NumassPlugin
/** /**

View File

@ -18,8 +18,8 @@ package inr.numass;
import hep.dataforge.actions.ActionUtils; import hep.dataforge.actions.ActionUtils;
import hep.dataforge.context.Context; import hep.dataforge.context.Context;
import hep.dataforge.context.Global; import hep.dataforge.context.Global;
import hep.dataforge.context.IOManager;
import hep.dataforge.data.FileDataFactory; import hep.dataforge.data.FileDataFactory;
import hep.dataforge.io.IOManager;
import hep.dataforge.io.MetaFileReader; import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
@ -52,7 +52,7 @@ public class Main {
public static void run(Context context, String[] args) throws Exception { public static void run(Context context, String[] args) throws Exception {
if(context == null){ if(context == null){
context = Global.instance(); context = Global.Companion.instance();
} }
Logger logger = LoggerFactory.getLogger("numass-main"); Logger logger = LoggerFactory.getLogger("numass-main");
@ -78,7 +78,7 @@ public class Main {
if (args.length == 0) { if (args.length == 0) {
HelpFormatter formatter = new HelpFormatter(); HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar DataReader.jar [OPTIONS]", options); 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")) { if (line.hasOption("c")) {

View File

@ -31,14 +31,14 @@ import hep.dataforge.meta.Meta;
public class Numass { public class Numass {
public static Context buildContext(Context parent, Meta meta) { public static Context buildContext(Context parent, Meta meta) {
return Context.builder("NUMASS", parent) return Context.Companion.builder("NUMASS", parent)
.properties(meta) .properties(meta)
.plugin(NumassPlugin.class) .plugin(NumassPlugin.class)
.build(); .build();
} }
public static Context buildContext() { 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 { public static void printDescription(Context context) throws DescriptorException {

View File

@ -39,7 +39,7 @@ public class MonitorCorrector {
private final List<MonitorPoint> list; private final List<MonitorPoint> list;
public MonitorCorrector(String path) throws ParseException, IOException { 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 { public MonitorCorrector(Path monitorFile) throws ParseException, IOException {

View File

@ -40,7 +40,7 @@ public class OldDataReader {
public static Table readConfig(String path) throws IOException { public static Table readConfig(String path) throws IOException {
String[] list = {"X", "time", "ushift"}; String[] list = {"X", "time", "ushift"};
ListTable.Builder res = new ListTable.Builder(list); 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); Scanner sc = new Scanner(file);
sc.nextLine(); sc.nextLine();
@ -62,7 +62,7 @@ public class OldDataReader {
public static Table readData(String path, double Elow) { public static Table readData(String path, double Elow) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); 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 x;
int count; int count;
int time; int time;
@ -114,7 +114,7 @@ public class OldDataReader {
public static Table readDataAsGun(String path, double Elow) { public static Table readDataAsGun(String path, double Elow) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); 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 x;
long count; long count;
int time; int time;
@ -147,7 +147,7 @@ public class OldDataReader {
public static Table readSpectrumData(String path) { public static Table readSpectrumData(String path) {
SpectrumAdapter factory = new SpectrumAdapter(Meta.empty()); SpectrumAdapter factory = new SpectrumAdapter(Meta.empty());
ListTable.Builder res = new ListTable.Builder(Adapters.getFormat(factory)); 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 x;
double count; double count;
double time; double time;

View File

@ -21,9 +21,9 @@ import ch.qos.logback.classic.spi.ILoggingEvent
import ch.qos.logback.core.Appender import ch.qos.logback.core.Appender
import ch.qos.logback.core.FileAppender import ch.qos.logback.core.FileAppender
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.context.DefaultIOManager
import hep.dataforge.context.IOManager
import hep.dataforge.fx.plots.plusAssign import hep.dataforge.fx.plots.plusAssign
import hep.dataforge.io.BasicIOManager
import hep.dataforge.io.IOManager
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.names.Name import hep.dataforge.names.Name
import hep.dataforge.plots.PlotUtils import hep.dataforge.plots.PlotUtils
@ -45,7 +45,7 @@ import java.util.*
/** /**
* @author Darksnake * @author Darksnake
*/ */
class NumassIO : BasicIOManager() { class NumassIO : DefaultIOManager() {
internal var registry = ReferenceRegistry<OutputStream>() internal var registry = ReferenceRegistry<OutputStream>()
// FileAppender<ILoggingEvent> appender; // FileAppender<ILoggingEvent> appender;
@ -63,7 +63,7 @@ class NumassIO : BasicIOManager() {
ple.context = lc ple.context = lc
ple.start() ple.start()
val appender = FileAppender<ILoggingEvent>() val appender = FileAppender<ILoggingEvent>()
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 appender.encoder = ple
return appender return appender
} }
@ -103,7 +103,7 @@ class NumassIO : BasicIOManager() {
val dirName = tokens.joinToString(File.separator) val dirName = tokens.joinToString(File.separator)
val fileName = name.toString() + getExtension(type) val fileName = name.toString() + getExtension(type)
val out = buildOut(workDirectory, dirName, fileName) val out = buildOut(workDir, dirName, fileName)
registry.add(out) registry.add(out)
return out return out
} }

View File

@ -50,7 +50,7 @@ class NumassPlugin : BasicPlugin() {
override fun attach(context: Context) { override fun attach(context: Context) {
// StorageManager.buildFrom(context); // StorageManager.buildFrom(context);
super.attach(context) super.attach(context)
context.getPluginManager().load(NumassIO()) context.pluginManager.load(NumassIO())
loadModels(context.getFeature(ModelManager::class.java)) loadModels(context.getFeature(ModelManager::class.java))
loadMath(MathPlugin.buildFrom(context)) loadMath(MathPlugin.buildFrom(context))

View File

@ -18,12 +18,14 @@ package inr.numass
import hep.dataforge.context.Context import hep.dataforge.context.Context
import hep.dataforge.data.DataNode import hep.dataforge.data.DataNode
import hep.dataforge.data.DataSet import hep.dataforge.data.DataSet
import hep.dataforge.data.binary.Binary
import hep.dataforge.io.envelopes.DefaultEnvelopeType import hep.dataforge.io.envelopes.DefaultEnvelopeType
import hep.dataforge.io.envelopes.Envelope import hep.dataforge.io.envelopes.Envelope
import hep.dataforge.io.envelopes.EnvelopeBuilder import hep.dataforge.io.envelopes.EnvelopeBuilder
import hep.dataforge.io.envelopes.TaglessEnvelopeType import hep.dataforge.io.envelopes.TaglessEnvelopeType
import hep.dataforge.io.markup.Markedup import hep.dataforge.io.markup.Markedup
import hep.dataforge.io.markup.SimpleMarkupRenderer import hep.dataforge.io.markup.SimpleMarkupRenderer
import hep.dataforge.kodex.nullable
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.meta.MetaBuilder import hep.dataforge.meta.MetaBuilder
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
@ -45,7 +47,6 @@ import tornadofx.*
import java.awt.Color import java.awt.Color
import java.awt.Font import java.awt.Font
import java.io.IOException import java.io.IOException
import java.io.InputStream
import java.io.OutputStream import java.io.OutputStream
import java.lang.Math.* import java.lang.Math.*
import java.util.* import java.util.*
@ -165,18 +166,10 @@ object NumassUtils {
fun getFSS(context: Context, meta: Meta): FSS? { fun getFSS(context: Context, meta: Meta): FSS? {
return if (meta.getBoolean("useFSS", true)) { return if (meta.getBoolean("useFSS", true)) {
val fssStream = meta.optString("fssFile") val fssBinary: Binary? = meta.optString("fssFile")
.map<InputStream> { fssFile -> .map { fssFile -> context.io.getFile(fssFile).binary }
try { .orElse(context.io.optResource("data/FS.txt").nullable)
context.io.optBinary(fssFile) fssBinary?.let { FSS(it.stream) } ?: throw RuntimeException("Could not load FSS file")
.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)
} else { } else {
null null
} }

View File

@ -120,7 +120,7 @@ class MergeDataAction : ManyToOneAction<Table, Table>() {
} }
companion object { companion object {
val MERGE_NAME = "mergeName" const val MERGE_NAME = "mergeName"
} }
} }

View File

@ -175,7 +175,7 @@ val subtractEmptyTask = task("dif") {
res.goal.onComplete { r, _ -> res.goal.onComplete { r, _ ->
if (r != null) { 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) NumassUtils.write(it, resMeta, r)
} }
} }
@ -228,7 +228,7 @@ val fitTask = task("fit") {
configure(meta.getMeta("fit")) configure(meta.getMeta("fit"))
} }
pipe<Table, FitResult> { data -> pipe<Table, FitResult> { data ->
context.getIo().out("numass.fit", name).use { out -> context.io.out("numass.fit", name).use { out ->
val writer = PrintWriter(out) val writer = PrintWriter(out)
writer.printf("%n*** META ***%n") writer.printf("%n*** META ***%n")
writer.println(meta.toString()) writer.println(meta.toString())

View File

@ -30,7 +30,7 @@ public class TransmissionInterpolatorTest {
public static void main(String[] args) { public static void main(String[] args) {
JFreeChartFrame frame = NumassPluginKt.displayJFreeChart("TransmissionInterpolatorTest"); JFreeChartFrame frame = NumassPluginKt.displayJFreeChart("TransmissionInterpolatorTest");
//JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); //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); "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(DataPlot.plot("data", interpolator.getX(), interpolator.getY()));
frame.add(XYFunctionPlot.Companion.plot("interpolated", interpolator.getXmin(), interpolator.getXmax(), 2000, interpolator::value)); frame.add(XYFunctionPlot.Companion.plot("interpolated", interpolator.getXmin(), interpolator.getXmax(), 2000, interpolator::value));

View File

@ -24,7 +24,7 @@ public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
// private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path"; // private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path";
NumassStorage root; NumassStorage root;
NumassServer listener; NumassServer listener;
Context context = Global.getContext("NUMASS_SERVER"); Context context = Global.Companion.getContext("NUMASS_SERVER");
public ServerRunner() throws IOException, ParseException { public ServerRunner() throws IOException, ParseException {
// Global.instance().getPluginManager().load(StorageManager.class); // Global.instance().getPluginManager().load(StorageManager.class);

View File

@ -27,7 +27,7 @@ public class TestServer {
* @throws hep.dataforge.exceptions.StorageException * @throws hep.dataforge.exceptions.StorageException
*/ */
public static void main(String[] args) throws Exception { 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); StorageManager storageManager = context.getPluginManager().load(StorageManager.class);