From 243f9f541c5d74ec3b6cb18b815435cb44567487 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Sun, 10 Jan 2016 22:11:35 +0300 Subject: [PATCH] [no commit message] --- .../main/java/inr/numass/NumassPlugin.java | 4 +- .../inr/numass/actions/MergeDataAction.java | 2 +- .../inr/numass/actions/PrepareDataAction.java | 1 - .../src/main/java/inr/numass/data/NMFile.java | 4 +- .../main/java/inr/numass/data/RawNMFile.java | 235 +++++++++--------- .../java/inr/numass/prop/ar/JNAEpisode.java | 80 +++--- .../java/inr/numass/prop/ar/JNASpectrum.java | 4 +- .../numass/prop/ar/MergeJNADataAction.java | 1 - .../test/java/inr/numass/prop/TestFit.java | 82 +++--- .../test/java/inr/numass/prop/TestReader.java | 2 +- 10 files changed, 207 insertions(+), 208 deletions(-) diff --git a/numass-main/src/main/java/inr/numass/NumassPlugin.java b/numass-main/src/main/java/inr/numass/NumassPlugin.java index 40191613..878fad94 100644 --- a/numass-main/src/main/java/inr/numass/NumassPlugin.java +++ b/numass-main/src/main/java/inr/numass/NumassPlugin.java @@ -160,7 +160,7 @@ public class NumassPlugin extends BasicPlugin { double weightReductionFactor = an.getDouble("weightReductionFactor", 2.0); Model res = new WeightedXYModel("scatter-variable", spectrum, getAdapter(an), (dp) -> weightReductionFactor); - res.configure(an); + res.setMeta(an); return res; }); @@ -196,7 +196,7 @@ public class NumassPlugin extends BasicPlugin { double weightReductionFactor = an.getDouble("weightReductionFactor", 2.0); Model res = new WeightedXYModel("scatter-empiric-experimental", spectrum, getAdapter(an), (dp) -> weightReductionFactor); - res.configure(an); + res.setMeta(an); return res; }); diff --git a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java index 1984ce34..c2b02bd9 100644 --- a/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/MergeDataAction.java @@ -102,7 +102,7 @@ public class MergeDataAction extends ManyToOneAction { * Указываем путь только если он одинаковый для всех входных файлов */ if (numassPath != null) { - res.configure(res.meta().getBuilder().putValue("numass.path", numassPath).build()); + res.setMeta(res.meta().getBuilder().putValue("numass.path", numassPath).build()); } res = res.sort("Uset", true); diff --git a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java index c3188713..3369220e 100644 --- a/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java +++ b/numass-main/src/main/java/inr/numass/actions/PrepareDataAction.java @@ -34,7 +34,6 @@ import inr.numass.data.NMPoint; import inr.numass.data.RawNMPoint; import java.io.OutputStream; import java.time.Instant; -import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; diff --git a/numass-main/src/main/java/inr/numass/data/NMFile.java b/numass-main/src/main/java/inr/numass/data/NMFile.java index 0c7d237a..7fd64139 100644 --- a/numass-main/src/main/java/inr/numass/data/NMFile.java +++ b/numass-main/src/main/java/inr/numass/data/NMFile.java @@ -15,7 +15,7 @@ */ package inr.numass.data; -import hep.dataforge.content.AbstractContent; +import hep.dataforge.content.NamedMetaHolder; import hep.dataforge.description.ValueDef; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; @@ -33,7 +33,7 @@ import java.util.List; */ @ValueDef(name = "numass.path", info = "Path to this data file in numass repository.") @ValueDef(name = "numass.name", info = "The name of this data file.") -public class NMFile extends AbstractContent implements NumassData { +public class NMFile extends NamedMetaHolder implements NumassData { public static NMFile readStream(InputStream is, String fname, Meta config) throws IOException{ return new NMFile(new NumassDataReader(is, fname, config).read()); diff --git a/numass-main/src/main/java/inr/numass/data/RawNMFile.java b/numass-main/src/main/java/inr/numass/data/RawNMFile.java index e761e5d4..dd4545f8 100644 --- a/numass-main/src/main/java/inr/numass/data/RawNMFile.java +++ b/numass-main/src/main/java/inr/numass/data/RawNMFile.java @@ -13,120 +13,121 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package inr.numass.data; - -import hep.dataforge.content.AbstractContent; -import java.io.BufferedOutputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.List; - -/** - * Contains the whole data but requires a lot of memory - * @author Darksnake - */ -public class RawNMFile extends AbstractContent { - -// public static String TYPE = ":data:numassdatafile"; - - private final List points; - - private String head; - - public void setHead(String head) { - this.head = head; - } - - public String getHead() { - return head; - } - - public RawNMFile(String fileName) { - super(fileName); - this.points = new ArrayList<>(); - } - - public void generatePAW(OutputStream stream) { - PrintWriter writer = new PrintWriter(new BufferedOutputStream(stream)); - long counter = 0; - for (RawNMPoint point : this.getData()) { - double U = point.getUread(); - for (NMEvent event : point.getEvents()) { - counter++; - writer.printf("%d\t%f\t%d\t%.1f\t%.2f%n", counter, event.getTime(), event.getChanel(), point.getLength(), U); - } - - } - writer.flush(); - } - - /** - * merge of all point with given Uset - * @param U - * @return - */ - public RawNMPoint getByUset(double U) { - RawNMPoint res = null; - - for (RawNMPoint point : points) { - if (point.getUset() == U) { - if (res == null) { - res = point.clone(); - } else { - res = res.merge(point); - } - } - } - return res; - } - - - /** - * merge of all point with given Uread - * @param U - * @return - */ - public RawNMPoint getByUread(double U) { - RawNMPoint res = null; - - for (RawNMPoint point : points) { - if (point.getUread()== U) { - if (res == null) { - res = point.clone(); - } else { - res = res.merge(point); - } - } - } - return res; - } - - /** - * @return the data - */ - public List getData() { - return points; - } - - void putEvent(double U, short chanel, double time) { - for (RawNMPoint point : this.getData()) { - if (U == point.getUread()) { - point.putEvent(new NMEvent(chanel, time)); - return; - } - } - RawNMPoint newpoint = new RawNMPoint(); - newpoint.putEvent(new NMEvent(chanel, time)); - this.putPoint(newpoint); - } - - public void putPoint(RawNMPoint point) { - points.add(point); - } - - public int size() { - return this.points.size(); - } - -} +package inr.numass.data; + +import hep.dataforge.content.Content; +import hep.dataforge.content.NamedMetaHolder; +import java.io.BufferedOutputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + +/** + * Contains the whole data but requires a lot of memory + * @author Darksnake + */ +public class RawNMFile extends NamedMetaHolder implements Content { + +// public static String TYPE = ":data:numassdatafile"; + + private final List points; + + private String head; + + public void setHead(String head) { + this.head = head; + } + + public String getHead() { + return head; + } + + public RawNMFile(String fileName) { + super(fileName); + this.points = new ArrayList<>(); + } + + public void generatePAW(OutputStream stream) { + PrintWriter writer = new PrintWriter(new BufferedOutputStream(stream)); + long counter = 0; + for (RawNMPoint point : this.getData()) { + double U = point.getUread(); + for (NMEvent event : point.getEvents()) { + counter++; + writer.printf("%d\t%f\t%d\t%.1f\t%.2f%n", counter, event.getTime(), event.getChanel(), point.getLength(), U); + } + + } + writer.flush(); + } + + /** + * merge of all point with given Uset + * @param U + * @return + */ + public RawNMPoint getByUset(double U) { + RawNMPoint res = null; + + for (RawNMPoint point : points) { + if (point.getUset() == U) { + if (res == null) { + res = point.clone(); + } else { + res = res.merge(point); + } + } + } + return res; + } + + + /** + * merge of all point with given Uread + * @param U + * @return + */ + public RawNMPoint getByUread(double U) { + RawNMPoint res = null; + + for (RawNMPoint point : points) { + if (point.getUread()== U) { + if (res == null) { + res = point.clone(); + } else { + res = res.merge(point); + } + } + } + return res; + } + + /** + * @return the data + */ + public List getData() { + return points; + } + + void putEvent(double U, short chanel, double time) { + for (RawNMPoint point : this.getData()) { + if (U == point.getUread()) { + point.putEvent(new NMEvent(chanel, time)); + return; + } + } + RawNMPoint newpoint = new RawNMPoint(); + newpoint.putEvent(new NMEvent(chanel, time)); + this.putPoint(newpoint); + } + + public void putPoint(RawNMPoint point) { + points.add(point); + } + + public int size() { + return this.points.size(); + } + +} diff --git a/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java b/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java index 6b01f317..e6127b4c 100644 --- a/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java +++ b/numass-prop/src/main/java/inr/numass/prop/ar/JNAEpisode.java @@ -13,43 +13,43 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package inr.numass.prop.ar; - -import hep.dataforge.meta.Meta; -import hep.dataforge.content.AbstractContent; -import java.util.Iterator; -import java.util.List; - -/** - * An episode of JNA measurements - * - * @author Darksnake - */ -public class JNAEpisode extends AbstractContent implements Iterable { - - private final List spectra; - - public JNAEpisode(String name, List spectra) { - super(name); - this.spectra = spectra; - } - - public JNAEpisode(String name, Meta annotation, List spectra) { - super(name, annotation); - this.spectra = spectra; - } - - @Override - public Iterator iterator() { - return spectra.iterator(); - } - - public JNASpectrum get(int i) { - return spectra.get(i); - } - - public int size() { - return spectra.size(); - } - -} +package inr.numass.prop.ar; + +import hep.dataforge.meta.Meta; +import hep.dataforge.content.NamedMetaHolder; +import java.util.Iterator; +import java.util.List; + +/** + * An episode of JNA measurements + * + * @author Darksnake + */ +public class JNAEpisode extends NamedMetaHolder implements Iterable { + + private final List spectra; + + public JNAEpisode(String name, List spectra) { + super(name); + this.spectra = spectra; + } + + public JNAEpisode(String name, Meta annotation, List spectra) { + super(name, annotation); + this.spectra = spectra; + } + + @Override + public Iterator iterator() { + return spectra.iterator(); + } + + public JNASpectrum get(int i) { + return spectra.get(i); + } + + public int size() { + return spectra.size(); + } + +} diff --git a/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java b/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java index 0bdf9a94..9f8a0b09 100644 --- a/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java +++ b/numass-prop/src/main/java/inr/numass/prop/ar/JNASpectrum.java @@ -17,7 +17,7 @@ package inr.numass.prop.ar; import hep.dataforge.meta.Meta; import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.content.AbstractContent; +import hep.dataforge.content.NamedMetaHolder; import hep.dataforge.description.NodeDef; import hep.dataforge.description.ValueDef; import hep.dataforge.data.DataPoint; @@ -37,7 +37,7 @@ import java.util.Map; @NodeDef(name = "temperature", info = "The temperature measurements data for this spectrum.") @ValueDef(name = "relativeStartTime", type = "NUMBER", info = "Start time in days relative to some starting point.") @ValueDef(name = "relativeStopTime", type = "NUMBER", info = "Stop time in days relative to some starting point.") -public class JNASpectrum extends AbstractContent { +public class JNASpectrum extends NamedMetaHolder { public static String[] names = {"chanel", "count"}; diff --git a/numass-prop/src/main/java/inr/numass/prop/ar/MergeJNADataAction.java b/numass-prop/src/main/java/inr/numass/prop/ar/MergeJNADataAction.java index e7fb3cc9..5297e029 100644 --- a/numass-prop/src/main/java/inr/numass/prop/ar/MergeJNADataAction.java +++ b/numass-prop/src/main/java/inr/numass/prop/ar/MergeJNADataAction.java @@ -21,7 +21,6 @@ import hep.dataforge.context.Context; import hep.dataforge.description.ValueDef; import hep.dataforge.description.TypedActionDef; import hep.dataforge.io.log.Logable; -import hep.dataforge.values.ValueType; import java.util.ArrayList; import java.util.Iterator; import java.util.List; diff --git a/numass-prop/src/test/java/inr/numass/prop/TestFit.java b/numass-prop/src/test/java/inr/numass/prop/TestFit.java index 9411d869..5dd91125 100644 --- a/numass-prop/src/test/java/inr/numass/prop/TestFit.java +++ b/numass-prop/src/test/java/inr/numass/prop/TestFit.java @@ -13,44 +13,44 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package inr.numass.prop; - -import hep.dataforge.meta.MetaBuilder; -import hep.dataforge.context.GlobalContext; -import hep.dataforge.data.DataSet; -import hep.dataforge.data.FileData; -import hep.dataforge.datafitter.MINUITPlugin; -import hep.dataforge.io.ColumnedDataWriter; -import inr.numass.prop.ar.FitJNAData; -import inr.numass.prop.ar.JNAEpisode; -import inr.numass.prop.ar.ReadJNADataAction; -import java.io.File; -import java.io.FileNotFoundException; - -/** - * - * @author Darksnake - */ -public class TestFit { - - /** - * @param args the command line arguments - */ - public static void main(String[] args) throws FileNotFoundException, InterruptedException { - GlobalContext.instance().loadPlugin(new MINUITPlugin()); - - File sourceDir = new File("c:\\Users\\Darksnake\\Dropbox\\jna_data"); - - FileData file = new FileData(new File(sourceDir, "ar37e2.dat")); - file.annotate(new MetaBuilder("meta") - .putValue("timeFile", "tar37e2.dat") - .putValue("temperatureFile", "e2temp.txt") - ); - JNAEpisode spectra = new ReadJNADataAction(GlobalContext.instance(), null).runOne(file); - - DataSet data = new FitJNAData(GlobalContext.instance(), null).runOne(spectra); - - ColumnedDataWriter.writeDataSet(System.out, data, "***RESULT***"); - } - -} +package inr.numass.prop; + +import hep.dataforge.meta.MetaBuilder; +import hep.dataforge.context.GlobalContext; +import hep.dataforge.data.DataSet; +import hep.dataforge.data.FileData; +import hep.dataforge.datafitter.MINUITPlugin; +import hep.dataforge.io.ColumnedDataWriter; +import inr.numass.prop.ar.FitJNAData; +import inr.numass.prop.ar.JNAEpisode; +import inr.numass.prop.ar.ReadJNADataAction; +import java.io.File; +import java.io.FileNotFoundException; + +/** + * + * @author Darksnake + */ +public class TestFit { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) throws FileNotFoundException, InterruptedException { + GlobalContext.instance().loadPlugin(new MINUITPlugin()); + + File sourceDir = new File("c:\\Users\\Darksnake\\Dropbox\\jna_data"); + + FileData file = new FileData(new File(sourceDir, "ar37e2.dat")); + file.setMeta(new MetaBuilder("meta") + .putValue("timeFile", "tar37e2.dat") + .putValue("temperatureFile", "e2temp.txt") + ); + JNAEpisode spectra = new ReadJNADataAction(GlobalContext.instance(), null).runOne(file); + + DataSet data = new FitJNAData(GlobalContext.instance(), null).runOne(spectra); + + ColumnedDataWriter.writeDataSet(System.out, data, "***RESULT***"); + } + +} diff --git a/numass-prop/src/test/java/inr/numass/prop/TestReader.java b/numass-prop/src/test/java/inr/numass/prop/TestReader.java index 6e6ceca2..f5e8778e 100644 --- a/numass-prop/src/test/java/inr/numass/prop/TestReader.java +++ b/numass-prop/src/test/java/inr/numass/prop/TestReader.java @@ -45,7 +45,7 @@ public class TestReader { // new MINUITModule().load(); FileData file = new FileData(new File("c:\\Users\\Darksnake\\Dropbox\\jna_data\\ar37e2.dat")); - file.annotate(new MetaBuilder("meta") + file.setMeta(new MetaBuilder("meta") .putValue("timeFile", "c:\\Users\\Darksnake\\Dropbox\\jna_data\\tar37e2.dat") .putValue("temperatureFile", "c:\\Users\\Darksnake\\Dropbox\\jna_data\\e2temp.txt") );