From dd4c15f0a352deb949009f11a8c3b2e3f572ecf4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Thu, 17 Nov 2016 20:57:30 +0300 Subject: [PATCH] Context constructors now can be called only via Global. Fixes in plugin reloading and context reusing. --- .../inr/numass/control/msp/fx/MspApp.java | 9 ++- .../control/msp/fx/MspViewController.java | 4 +- .../groovy/inr/numass/LaunchGrindShell.groovy | 4 +- .../groovy/inr/numass/scripts/OldTest.groovy | 4 +- .../inr/numass/scripts/ResolutionTest.groovy | 8 +- .../numass/scripts/SignificanceTest.groovy | 6 +- .../groovy/inr/numass/scripts/Simulate.groovy | 4 +- .../inr/numass/scripts/SimulateGun.groovy | 4 +- .../inr/numass/scripts/SterileDemo.groovy | 4 +- .../numass/scripts/SystTransmission.groovy | 7 +- .../inr/numass/scripts/Systematics.groovy | 9 ++- .../inr/numass/scripts/TritiumTest.groovy | 4 +- .../src/main/java/inr/numass/Main.java | 2 +- .../src/main/java/inr/numass/Numass.java | 7 +- .../java/inr/numass/NumassProperties.java | 7 +- .../inr/numass/data/MonitorCorrector.java | 38 +++++----- .../inr/numass/data/SpectrumGenerator.java | 13 ++-- .../inr/numass/models/GaussResolution.java | 73 ++----------------- .../sterile/SterileNeutrinoSpectrum.java | 6 +- .../java/inr/numass/utils/OldDataReader.java | 14 ++-- .../workbench/NumassWorkbenchController.java | 6 +- .../java/inr/numass/workbench/Workbench.java | 4 +- .../models/TransmissionInterpolatorTest.java | 4 +- .../inr/numass/storage/NumassDataLoader.java | 4 +- .../numass/storage/SetDirectionUtility.java | 12 +-- .../numass/viewer/MainViewerController.java | 6 +- .../numass/viewer/TestDirectoryViewer.java | 9 ++- 27 files changed, 108 insertions(+), 164 deletions(-) diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java index 8e693028..098a046e 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspApp.java @@ -16,13 +16,11 @@ package inr.numass.control.msp.fx; import ch.qos.logback.classic.Level; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.io.MetaFileReader; import hep.dataforge.io.XMLMetaReader; import hep.dataforge.meta.Meta; import hep.dataforge.storage.commons.StorageManager; -import java.io.File; -import java.util.Locale; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; @@ -30,6 +28,9 @@ import javafx.scene.Scene; import javafx.stage.Stage; import org.slf4j.LoggerFactory; +import java.io.File; +import java.util.Locale; + /** * * @author darksnake @@ -63,7 +64,7 @@ public class MspApp extends Application { Parent parent = loader.load(); controller = loader.getController(); - controller.setDeviceConfig(GlobalContext.instance(), config); + controller.setDeviceConfig(Global.instance(), config); Scene scene = new Scene(parent, 600, 400); diff --git a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java index a60aab88..f9af7e85 100644 --- a/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java +++ b/numass-control/msp/src/main/java/inr/numass/control/msp/fx/MspViewController.java @@ -16,7 +16,7 @@ package inr.numass.control.msp.fx; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.control.connections.Roles; import hep.dataforge.control.connections.StorageConnection; import hep.dataforge.exceptions.ControlException; @@ -174,7 +174,7 @@ public class MspViewController implements Initializable, MspListener { } catch (IOException | URISyntaxException | ParseException ex) { throw new Error(ex); } - setDeviceConfig(GlobalContext.instance(), defaultDeviceConfig); + setDeviceConfig(Global.instance(), defaultDeviceConfig); } return device; } diff --git a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy index b09c041f..01390cec 100644 --- a/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy +++ b/numass-main/src/main/groovy/inr/numass/LaunchGrindShell.groovy @@ -1,6 +1,6 @@ package inr.numass -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.grind.GrindShell import hep.dataforge.grind.GrindWorkspaceBuilder @@ -25,5 +25,5 @@ try { } catch (Exception ex) { ex.printStackTrace(); } finally { - GlobalContext.instance().close(); + Global.instance().close(); } \ No newline at end of file diff --git a/numass-main/src/main/groovy/inr/numass/scripts/OldTest.groovy b/numass-main/src/main/groovy/inr/numass/scripts/OldTest.groovy index 4080598a..4b011ded 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/OldTest.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/OldTest.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.stat.fit.FitManager import hep.dataforge.stat.fit.FitState import hep.dataforge.stat.fit.MINUITPlugin @@ -31,7 +31,7 @@ import org.apache.commons.math3.analysis.BivariateFunction import static inr.numass.utils.OldDataReader.readData -PrintWriter out = GlobalContext.out(); +PrintWriter out = Global.out(); Locale.setDefault(Locale.US); new MINUITPlugin().startGlobal(); diff --git a/numass-main/src/main/groovy/inr/numass/scripts/ResolutionTest.groovy b/numass-main/src/main/groovy/inr/numass/scripts/ResolutionTest.groovy index e0df5b46..8002603b 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/ResolutionTest.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/ResolutionTest.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.stat.fit.FitManager import hep.dataforge.stat.fit.FitState import hep.dataforge.stat.fit.ParamSet @@ -28,7 +28,7 @@ import inr.numass.models.ModularSpectrum import inr.numass.models.NBkgSpectrum import inr.numass.utils.DataModelUtils -import static hep.dataforge.context.GlobalContext.out +import static Global.out import static java.util.Locale.setDefault /** @@ -37,7 +37,7 @@ import static java.util.Locale.setDefault */ setDefault(Locale.US); -GlobalContext global = GlobalContext.instance(); +Global global = Global.instance(); // global.loadModule(new MINUITModule()); FitManager fm = new FitManager(); @@ -72,7 +72,7 @@ allPars.setParValue("trap", 0); allPars.setParError("trap", 0.01d); allPars.setParDomain("trap", 0d, Double.POSITIVE_INFINITY); -// PrintNamed.printSpectrum(GlobalContext.onComplete(), spectrum, allPars, 0.0, 18700.0, 600); +// PrintNamed.printSpectrum(Global.onComplete(), spectrum, allPars, 0.0, 18700.0, 600); //String fileName = "d:\\PlayGround\\merge\\scans.onComplete"; // String configName = "d:\\PlayGround\\SCAN.CFG"; // ListTable config = OldDataReader.readConfig(configName); diff --git a/numass-main/src/main/groovy/inr/numass/scripts/SignificanceTest.groovy b/numass-main/src/main/groovy/inr/numass/scripts/SignificanceTest.groovy index 1ce04d8d..48d63a1a 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/SignificanceTest.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/SignificanceTest.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.meta.MetaBuilder import hep.dataforge.stat.fit.ParamSet import inr.numass.data.SpectrumInformation @@ -28,7 +28,7 @@ import org.apache.commons.math3.analysis.UnivariateFunction import static java.util.Locale.setDefault setDefault(Locale.US); -GlobalContext global = GlobalContext.instance(); +Global global = Global.instance(); // global.loadModule(new MINUIT()); // FitManager fm = new FitManager("data 2013"); @@ -83,7 +83,7 @@ SpectrumInformation sign = new SpectrumInformation(spectrum); // PrintNamed.printNamedMatrix(Out.out, infoMatrix); // NamedMatrix cov = sign.getExpetedCovariance(allPars, config,"U2","E0","N"); // -// PrintWriter onComplete = GlobalContext.onComplete(); +// PrintWriter onComplete = Global.onComplete(); // // printNamedMatrix(out, cov); // diff --git a/numass-main/src/main/groovy/inr/numass/scripts/Simulate.groovy b/numass-main/src/main/groovy/inr/numass/scripts/Simulate.groovy index b82d8e0c..7380c5fc 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/Simulate.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/Simulate.groovy @@ -29,7 +29,7 @@ import inr.numass.models.NBkgSpectrum import inr.numass.utils.DataModelUtils import inr.numass.utils.TritiumUtils -import static hep.dataforge.context.GlobalContext.out +import static hep.dataforge.context.Global.out import static java.util.Locale.setDefault /** @@ -73,7 +73,7 @@ allPars.setParValue("trap", 1d); allPars.setParError("trap", 0.01d); allPars.setParDomain("trap", 0d, Double.POSITIVE_INFINITY); -// PrintNamed.printSpectrum(GlobalContext.onComplete(), spectrum, allPars, 0.0, 18700.0, 600); +// PrintNamed.printSpectrum(Global.onComplete(), spectrum, allPars, 0.0, 18700.0, 600); //String fileName = "d:\\PlayGround\\merge\\scans.onComplete"; // String configName = "d:\\PlayGround\\SCAN.CFG"; // ListTable config = OldDataReader.readConfig(configName); diff --git a/numass-main/src/main/groovy/inr/numass/scripts/SimulateGun.groovy b/numass-main/src/main/groovy/inr/numass/scripts/SimulateGun.groovy index e08acf60..fe2fad0a 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/SimulateGun.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/SimulateGun.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.io.FittingIOUtils import hep.dataforge.stat.fit.FitManager import hep.dataforge.stat.fit.ParamSet @@ -27,7 +27,7 @@ import inr.numass.models.NBkgSpectrum import static java.util.Locale.setDefault setDefault(Locale.US); -GlobalContext global = GlobalContext.instance(); +Global global = Global.instance(); // global.loadModule(new MINUITModule()); FitManager fm = new FitManager(); diff --git a/numass-main/src/main/groovy/inr/numass/scripts/SterileDemo.groovy b/numass-main/src/main/groovy/inr/numass/scripts/SterileDemo.groovy index 065db734..9678313a 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/SterileDemo.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/SterileDemo.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.grind.GrindMetaBuilder import hep.dataforge.io.FittingIOUtils import hep.dataforge.meta.Meta @@ -60,7 +60,7 @@ allPars.setPar("U2", 0.0, 1e-4, -1d, 1d); allPars.setPar("X", 0.04, 0.01, 0d, Double.POSITIVE_INFINITY); allPars.setPar("trap", 1.634, 0.01,0d, Double.POSITIVE_INFINITY); -FittingIOUtils.printSpectrum(GlobalContext.out(), spectrum, allPars, 14000, 18600.0, 400); +FittingIOUtils.printSpectrum(Global.out(), spectrum, allPars, 14000, 18600.0, 400); //SpectrumGenerator generator = new SpectrumGenerator(model, allPars, 12316); // diff --git a/numass-main/src/main/groovy/inr/numass/scripts/SystTransmission.groovy b/numass-main/src/main/groovy/inr/numass/scripts/SystTransmission.groovy index 265549b4..3f343f80 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/SystTransmission.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/SystTransmission.groovy @@ -15,7 +15,10 @@ */ package inr.numass.scripts -import hep.dataforge.stat.fit.* +import hep.dataforge.stat.fit.FitManager +import hep.dataforge.stat.fit.FitState +import hep.dataforge.stat.fit.MINUITPlugin +import hep.dataforge.stat.fit.ParamSet import hep.dataforge.stat.models.XYModel import hep.dataforge.tables.ListTable import inr.numass.data.SpectrumDataAdapter @@ -26,7 +29,7 @@ import inr.numass.models.NBkgSpectrum import inr.numass.models.ResolutionFunction import inr.numass.utils.DataModelUtils -import static hep.dataforge.context.GlobalContext.out +import static hep.dataforge.context.Global.out import static java.util.Locale.setDefault /** diff --git a/numass-main/src/main/groovy/inr/numass/scripts/Systematics.groovy b/numass-main/src/main/groovy/inr/numass/scripts/Systematics.groovy index 5d43593b..93b1144f 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/Systematics.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/Systematics.groovy @@ -15,7 +15,10 @@ */ package inr.numass.scripts -import hep.dataforge.stat.fit.* +import hep.dataforge.stat.fit.FitManager +import hep.dataforge.stat.fit.FitState +import hep.dataforge.stat.fit.MINUITPlugin +import hep.dataforge.stat.fit.ParamSet import hep.dataforge.stat.models.XYModel import hep.dataforge.tables.ListTable import inr.numass.data.SpectrumDataAdapter @@ -27,7 +30,7 @@ import inr.numass.models.ResolutionFunction import inr.numass.utils.DataModelUtils import org.apache.commons.math3.analysis.BivariateFunction -import static hep.dataforge.context.GlobalContext.out +import static hep.dataforge.context.Global.out import static java.util.Locale.setDefault /** @@ -76,7 +79,7 @@ ListTable data = generator.generateData(DataModelUtils.getUniformSpectrumConfigu // data = data.filter("X", Value.of(15510.0), Value.of(18610.0)); allPars.setParValue("U2", 0); FitState state = new FitState(data, model, allPars); -//new PlotFitResultAction(GlobalContext.instance(), null).runOne(state); +//new PlotFitResultAction(Global.instance(), null).runOne(state); //double delta = 4e-6; diff --git a/numass-main/src/main/groovy/inr/numass/scripts/TritiumTest.groovy b/numass-main/src/main/groovy/inr/numass/scripts/TritiumTest.groovy index f6424718..4b406e78 100644 --- a/numass-main/src/main/groovy/inr/numass/scripts/TritiumTest.groovy +++ b/numass-main/src/main/groovy/inr/numass/scripts/TritiumTest.groovy @@ -15,7 +15,7 @@ */ package inr.numass.scripts -import hep.dataforge.context.GlobalContext +import hep.dataforge.context.Global import hep.dataforge.data.DataSet import hep.dataforge.stat.fit.FitManager import hep.dataforge.stat.fit.FitState @@ -31,7 +31,7 @@ import inr.numass.models.NBkgSpectrum import static hep.dataforge.maths.RandomUtils.setSeed import static inr.numass.utils.DataModelUtils.getUniformSpectrumConfiguration -PrintWriter out = GlobalContext.out(); +PrintWriter out = Global.out(); FitManager fm = new FitManager(); setSeed(543982); diff --git a/numass-main/src/main/java/inr/numass/Main.java b/numass-main/src/main/java/inr/numass/Main.java index 968673d4..5d4dcd0f 100644 --- a/numass-main/src/main/java/inr/numass/Main.java +++ b/numass-main/src/main/java/inr/numass/Main.java @@ -32,7 +32,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; -import static hep.dataforge.context.GlobalContext.out; +import static hep.dataforge.context.Global.out; import static inr.numass.Numass.printDescription; import static java.util.Locale.setDefault; diff --git a/numass-main/src/main/java/inr/numass/Numass.java b/numass-main/src/main/java/inr/numass/Numass.java index 198d5664..a8d4d72e 100644 --- a/numass-main/src/main/java/inr/numass/Numass.java +++ b/numass-main/src/main/java/inr/numass/Numass.java @@ -17,7 +17,7 @@ package inr.numass; import hep.dataforge.actions.ActionManager; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.description.ActionDescriptor; import hep.dataforge.description.DescriptorFormatter; import hep.dataforge.description.DescriptorUtils; @@ -34,14 +34,13 @@ import java.io.PrintWriter; public class Numass { public static Context buildContext(Context parent, Meta meta) { - Context numassContext = new Context(parent, "numass", meta); - GlobalContext.registerContext(numassContext); + Context numassContext = Global.getContext("numass").withParent(parent).withProperties(meta); numassContext.pluginManager().loadPlugin("inr.numass:numass"); return numassContext; } public static Context buildContext() { - return buildContext(GlobalContext.instance(), Meta.empty()); + return buildContext(Global.instance(), Meta.empty()); } public static void printDescription(Context context, boolean allowANSI) throws DescriptorException { diff --git a/numass-main/src/main/java/inr/numass/NumassProperties.java b/numass-main/src/main/java/inr/numass/NumassProperties.java index cbcf5aaf..233c028c 100644 --- a/numass-main/src/main/java/inr/numass/NumassProperties.java +++ b/numass-main/src/main/java/inr/numass/NumassProperties.java @@ -5,7 +5,8 @@ */ package inr.numass; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -19,7 +20,7 @@ import java.util.Properties; public class NumassProperties { private static File getNumassPropertiesFile() throws IOException { - File file = new File(GlobalContext.instance().getUserDirectory(), "numass"); + File file = new File(Global.instance().getUserDirectory(), "numass"); if (!file.exists()) { file.mkdirs(); } @@ -48,7 +49,7 @@ public class NumassProperties { props.setProperty(key, value); props.store(new FileOutputStream(store), ""); } catch (IOException ex) { - GlobalContext.instance().getLogger().error("Failed to save numass properties", ex); + Global.instance().getLogger().error("Failed to save numass properties", ex); } } } 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 820a2b40..0a829353 100644 --- a/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java +++ b/numass-main/src/main/java/inr/numass/data/MonitorCorrector.java @@ -1,31 +1,33 @@ -/* - * Copyright 2015 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. - */ +/* + * Copyright 2015 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.data; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; + import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.text.ParseException; import java.time.LocalDateTime; -import static java.time.temporal.ChronoUnit.SECONDS; import java.util.ArrayList; import java.util.List; +import static java.time.temporal.ChronoUnit.SECONDS; + /** * Заплатка для задания поправки на масс-спектрометр * @@ -37,7 +39,7 @@ public class MonitorCorrector { private final List list; public MonitorCorrector(String path) throws ParseException, IOException { - this(GlobalContext.instance().io().getFile(path)); + this(Global.instance().io().getFile(path)); } public MonitorCorrector(File monitorFile) throws ParseException, IOException { diff --git a/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java b/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java index 91e7dabc..f761c47b 100644 --- a/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java +++ b/numass-main/src/main/java/inr/numass/data/SpectrumGenerator.java @@ -18,19 +18,18 @@ package inr.numass.data; import hep.dataforge.stat.fit.ParamSet; import hep.dataforge.stat.models.Generator; import hep.dataforge.stat.models.XYModel; -import static hep.dataforge.maths.RandomUtils.getDefaultRandomGenerator; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.Table; -import static java.lang.Double.isNaN; -import static java.lang.Math.sqrt; -import java.util.Iterator; import org.apache.commons.math3.random.JDKRandomGenerator; import org.apache.commons.math3.random.RandomDataGenerator; import org.apache.commons.math3.random.RandomGenerator; + +import java.util.Iterator; + +import static hep.dataforge.maths.RandomUtils.getDefaultRandomGenerator; import static java.lang.Double.isNaN; -import static java.lang.Double.isNaN; -import static java.lang.Double.isNaN; +import static java.lang.Math.sqrt; /** * Генератор наборов данных для спектров. На входе требуется набор данных, @@ -145,7 +144,7 @@ public class SpectrumGenerator implements Generator { // private double getSigma(DataPoint point) { // if (!point.containsName("time")) { -// GlobalContext.instance().logString("SpectrumGenerator : Neither point error nor time is defined. Suspected wrong error bars for data."); +// Global.instance().logString("SpectrumGenerator : Neither point error nor time is defined. Suspected wrong error bars for data."); // } // return sqrt(this.getMu(point)); // } diff --git a/numass-main/src/main/java/inr/numass/models/GaussResolution.java b/numass-main/src/main/java/inr/numass/models/GaussResolution.java index 1dd98b88..fe16da2e 100644 --- a/numass-main/src/main/java/inr/numass/models/GaussResolution.java +++ b/numass-main/src/main/java/inr/numass/models/GaussResolution.java @@ -15,82 +15,19 @@ */ package inr.numass.models; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.exceptions.NameNotFoundException; import hep.dataforge.stat.parametric.AbstractParametricFunction; import hep.dataforge.stat.parametric.ParametricFunction; -import static hep.dataforge.names.NamedUtils.combineNamesWithEquals; import hep.dataforge.values.NamedValueSet; import hep.dataforge.values.ValueProvider; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Math.exp; -import static java.lang.Math.sqrt; import org.apache.commons.math3.analysis.UnivariateFunction; import org.apache.commons.math3.analysis.integration.SimpsonIntegrator; import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; + +import static hep.dataforge.names.NamedUtils.combineNamesWithEquals; import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; -import static java.lang.Double.isNaN; -import static java.lang.Math.abs; +import static java.lang.Math.*; /** * @@ -131,7 +68,7 @@ public class GaussResolution extends AbstractParametricFunction implements Trans @Override public ParametricFunction getConvolutedSpectrum(final RangedNamedSetSpectrum bare) { return new AbstractParametricFunction(combineNamesWithEquals(this.namesAsArray(), bare.namesAsArray())) { - int maxEval = GlobalContext.instance().getInt("INTEGR_POINTS", 500); + int maxEval = Global.instance().getInt("INTEGR_POINTS", 500); @Override public double derivValue(String parName, double x, NamedValueSet set) { diff --git a/numass-main/src/main/java/inr/numass/models/sterile/SterileNeutrinoSpectrum.java b/numass-main/src/main/java/inr/numass/models/sterile/SterileNeutrinoSpectrum.java index fb3a8c96..811316e4 100644 --- a/numass-main/src/main/java/inr/numass/models/sterile/SterileNeutrinoSpectrum.java +++ b/numass-main/src/main/java/inr/numass/models/sterile/SterileNeutrinoSpectrum.java @@ -6,7 +6,7 @@ package inr.numass.models.sterile; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.description.NodeDef; import hep.dataforge.description.ValueDef; import hep.dataforge.exceptions.NotDefinedException; @@ -79,11 +79,11 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction { } public SterileNeutrinoSpectrum(Meta configuration) { - this(GlobalContext.instance(), configuration); + this(Global.instance(), configuration); } public SterileNeutrinoSpectrum() { - this(GlobalContext.instance(), Meta.empty()); + this(Global.instance(), Meta.empty()); } @Override 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 827c52cb..409ded8b 100644 --- a/numass-main/src/main/java/inr/numass/utils/OldDataReader.java +++ b/numass-main/src/main/java/inr/numass/utils/OldDataReader.java @@ -15,18 +15,20 @@ */ package inr.numass.utils; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.tables.DataPoint; import hep.dataforge.tables.ListTable; import hep.dataforge.tables.MapPoint; import hep.dataforge.tables.Table; import inr.numass.data.SpectrumDataAdapter; + import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; -import static java.util.Locale.setDefault; import java.util.Scanner; +import static java.util.Locale.setDefault; + /** * * @author Darksnake @@ -36,7 +38,7 @@ public class OldDataReader { public static Table readConfig(String path) throws FileNotFoundException { String[] list = {"X", "time", "ushift"}; ListTable.Builder res = new ListTable.Builder(list); - File file = GlobalContext.instance().io().getFile(path); + File file = Global.instance().io().getFile(path); Scanner sc = new Scanner(file); sc.nextLine(); @@ -58,7 +60,7 @@ public class OldDataReader { public static Table readData(String path, double Elow) { SpectrumDataAdapter factory = new SpectrumDataAdapter(); ListTable.Builder res = new ListTable.Builder(factory.getFormat()); - File file = GlobalContext.instance().io().getFile(path); + File file = Global.instance().io().getFile(path); double x; int count; int time; @@ -110,7 +112,7 @@ public class OldDataReader { public static Table readDataAsGun(String path, double Elow) { SpectrumDataAdapter factory = new SpectrumDataAdapter(); ListTable.Builder res = new ListTable.Builder(factory.getFormat()); - File file = GlobalContext.instance().io().getFile(path); + File file = Global.instance().io().getFile(path); double x; long count; int time; @@ -143,7 +145,7 @@ public class OldDataReader { public static Table readSpectrumData(String path) { SpectrumDataAdapter factory = new SpectrumDataAdapter(); ListTable.Builder res = new ListTable.Builder(factory.getFormat()); - File file = GlobalContext.instance().io().getFile(path); + File file = Global.instance().io().getFile(path); double x; double count; double time; diff --git a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java index f0a8586b..cbdfa12b 100644 --- a/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java +++ b/numass-main/src/main/java/inr/numass/workbench/NumassWorkbenchController.java @@ -10,7 +10,7 @@ import hep.dataforge.actions.ActionManager; import hep.dataforge.actions.ActionStateListener; import hep.dataforge.actions.ActionUtils; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.data.DataNode; import hep.dataforge.data.FileDataFactory; import hep.dataforge.description.ActionDescriptor; @@ -367,13 +367,13 @@ public class NumassWorkbenchController implements Initializable, StagePaneHolder } catch (Exception ex) { if (ex instanceof java.util.concurrent.CancellationException) { //cach cancelation exception - GlobalContext.instance().getLogger().info("Interrupted by user"); + Global.instance().getLogger().info("Interrupted by user"); Platform.runLater(() -> { statusBar.setText("Execution interrupted by user"); }); } else { //cach all other exceptions - GlobalContext.instance().getLogger().error("Exception while executing action chain", ex); + Global.instance().getLogger().error("Exception while executing action chain", ex); ex.printStackTrace(System.err); Platform.runLater(() -> { //printing stack trace to the default output diff --git a/numass-main/src/main/java/inr/numass/workbench/Workbench.java b/numass-main/src/main/java/inr/numass/workbench/Workbench.java index cadfa997..8da1a176 100644 --- a/numass-main/src/main/java/inr/numass/workbench/Workbench.java +++ b/numass-main/src/main/java/inr/numass/workbench/Workbench.java @@ -5,7 +5,7 @@ */ package inr.numass.workbench; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import inr.numass.Numass; import javafx.application.Application; import javafx.fxml.FXMLLoader; @@ -55,7 +55,7 @@ public class Workbench extends Application { @Override public void stop() throws Exception { - GlobalContext.instance().close(); + Global.instance().close(); super.stop(); } 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 9df1899a..f98458fb 100644 --- a/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java +++ b/numass-main/src/test/java/inr/numass/models/TransmissionInterpolatorTest.java @@ -15,7 +15,7 @@ */ package inr.numass.models; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.plots.data.PlottableData; import hep.dataforge.plots.data.PlottableXYFunction; import hep.dataforge.plots.jfreechart.JFreeChartFrame; @@ -30,7 +30,7 @@ public class TransmissionInterpolatorTest { public static void main(String[] args) { JFreeChartFrame frame = NumassPlugin.displayJFreeChart("TransmissionInterpolatorTest", null); //JFreeChartFrame.drawFrame("TransmissionInterpolatorTest", null); - TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(GlobalContext.instance(), + TransmissionInterpolator interpolator = TransmissionInterpolator.fromFile(Global.instance(), "d:\\sterile-new\\loss2014-11\\.dataforge\\merge\\empty_sum.onComplete", "Uset", "CR", 15, 0.8, 19002d); frame.add(PlottableData.plot("data", interpolator.getX(), interpolator.getY())); frame.add(PlottableXYFunction.plotFunction("interpolated", x->interpolator.value(x), interpolator.getXmin(), interpolator.getXmax(), 2000)); diff --git a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java index 512db645..79a78a48 100644 --- a/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java +++ b/numass-storage/src/main/java/inr/numass/storage/NumassDataLoader.java @@ -15,7 +15,7 @@ */ package inr.numass.storage; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.data.binary.Binary; import hep.dataforge.exceptions.StorageException; import hep.dataforge.io.ColumnedDataReader; @@ -147,7 +147,7 @@ public class NumassDataLoader extends AbstractLoader implements ObjectLoader provider) { if (!isLoaded) { - load(GlobalContext.instance()); + load(Global.instance()); } return directionMap.computeIfAbsent(setName, provider); } diff --git a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java index 0babe78d..3a8e2a99 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/MainViewerController.java @@ -17,7 +17,7 @@ package inr.numass.viewer; import hep.dataforge.computation.ProgressCallback; import hep.dataforge.context.Context; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.exceptions.StorageException; import hep.dataforge.fx.fragments.FragmentWindow; import hep.dataforge.fx.fragments.LogFragment; @@ -104,7 +104,7 @@ public class MainViewerController implements Initializable { LogFragment logFragment = new LogFragment(); logFragment.hookStd(); new FragmentWindow(logFragment).bindTo(consoleButton); - new FragmentWindow(WorkManagerFragment.attachToContext(GlobalContext.instance())).bindTo(processManagerButton); + new FragmentWindow(WorkManagerFragment.attachToContext(Global.instance())).bindTo(processManagerButton); mspController = new MspViewController(getContext()); this.mspTab.setContent(mspController.getRoot()); @@ -148,7 +148,7 @@ public class MainViewerController implements Initializable { } private Context getContext() { - return GlobalContext.instance(); + return Global.instance(); } public void setRootStorage(NumassStorage root) { diff --git a/numass-viewer/src/main/java/inr/numass/viewer/TestDirectoryViewer.java b/numass-viewer/src/main/java/inr/numass/viewer/TestDirectoryViewer.java index cbb32dc9..994393a2 100644 --- a/numass-viewer/src/main/java/inr/numass/viewer/TestDirectoryViewer.java +++ b/numass-viewer/src/main/java/inr/numass/viewer/TestDirectoryViewer.java @@ -15,15 +15,16 @@ */ package inr.numass.viewer; -import hep.dataforge.context.GlobalContext; +import hep.dataforge.context.Global; import hep.dataforge.storage.commons.StorageManager; import inr.numass.storage.NumassDataLoader; -import java.io.File; -import java.io.IOException; import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; +import java.io.File; +import java.io.IOException; + /** * * @author darksnake @@ -37,7 +38,7 @@ public class TestDirectoryViewer extends Application { NumassDataLoader reader = NumassDataLoader.fromLocalDir(null, new File("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\20150703143643_1\\")); // NumassLoader reader = NumassLoader.fromZip(null, new File("C:\\Users\\darksnake\\Dropbox\\PlayGround\\data-test\\20150703143643_1.zip")); - NumassLoaderViewComponent comp = new NumassLoaderViewComponent(GlobalContext.instance()); + NumassLoaderViewComponent comp = new NumassLoaderViewComponent(Global.instance()); comp.loadData(reader); // FXMLLoader fxml = new FXMLLoader(getClass().getResource("/fxml/DirectoryViewer.fxml")); //