Removing wildcards from Data and DataNodes

This commit is contained in:
Alexander Nozik 2017-09-14 22:13:51 +03:00
parent 675bd291b8
commit c8d6391219
7 changed files with 32 additions and 26 deletions

View File

@ -22,6 +22,7 @@ import hep.dataforge.data.FileDataFactory;
import hep.dataforge.io.IOManager; 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 hep.dataforge.providers.Path;
import org.apache.commons.cli.*; import org.apache.commons.cli.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -31,6 +32,7 @@ import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.nio.file.Files;
import java.util.Locale; import java.util.Locale;
import static hep.dataforge.context.Global.out; import static hep.dataforge.context.Global.out;
@ -87,15 +89,15 @@ public class Main {
return; return;
} }
File configFile = context.io().getFile(cfgPath); java.nio.file.Path configFile = context.io().getFile(cfgPath);
if (!configFile.exists()) { if (!Files.exists(configFile)) {
throw new FileNotFoundException("Configuration file not found"); throw new FileNotFoundException("Configuration file not found");
} }
Meta config = MetaFileReader.read(configFile).build(); Meta config = MetaFileReader.read(configFile);
context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParentFile().toString()); context.putValue(IOManager.ROOT_DIRECTORY_CONTEXT_KEY, configFile.getParent().toString());
applyCLItoContext(line, context); applyCLItoContext(line, context);

View File

@ -28,6 +28,8 @@ import org.apache.commons.io.output.TeeOutputStream;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.*; import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -57,7 +59,7 @@ public class NumassIO extends BasicIOManager {
ple.setContext(lc); ple.setContext(lc);
ple.start(); ple.start();
FileAppender<ILoggingEvent> appender = new FileAppender<>(); FileAppender<ILoggingEvent> appender = new FileAppender<>();
appender.setFile(new File(getWorkDirectory(), meta().getString("logFileName", "numass.log")).toString()); appender.setFile(new File(getWorkDirectory().toFile(), meta().getString("logFileName", "numass.log")).toString());
appender.setEncoder(ple); appender.setEncoder(ple);
return appender; return appender;
} }
@ -97,26 +99,24 @@ public class NumassIO extends BasicIOManager {
return out; return out;
} }
private OutputStream buildOut(File parentDir, String dirName, String fileName) { private OutputStream buildOut(Path parentDir, String dirName, String fileName) {
File outputFile; Path outputFile;
if (!parentDir.exists()) { if (!Files.exists(parentDir)) {
throw new RuntimeException("Working directory does not exist"); throw new RuntimeException("Working directory does not exist");
} }
if (dirName != null && !dirName.isEmpty()) { if (dirName != null && !dirName.isEmpty()) {
parentDir = new File(parentDir, dirName); parentDir = parentDir.resolve(dirName);
if (!parentDir.exists()) { Files.createDirectories(parentDir);
parentDir.mkdirs();
}
} }
// String output = source.meta().getString("output", this.meta().getString("output", fileName + ".onComplete")); // String output = source.meta().getString("output", this.meta().getString("output", fileName + ".onComplete"));
outputFile = new File(parentDir, fileName); outputFile = parentDir.resolve(fileName);
try { try {
if (getContext().getBoolean("numass.consoleOutput", false)) { if (getContext().getBoolean("numass.consoleOutput", false)) {
return new TeeOutputStream(new FileOutputStream(outputFile), System.out); return new TeeOutputStream(Files.newOutputStream(outputFile), System.out);
} else { } else {
return new FileOutputStream(outputFile); return Files.newOutputStream(outputFile);
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);

View File

@ -21,6 +21,8 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
@ -42,10 +44,10 @@ public class MonitorCorrector {
this(Global.instance().io().getFile(path)); this(Global.instance().io().getFile(path));
} }
public MonitorCorrector(File monitorFile) throws ParseException, IOException { public MonitorCorrector(Path monitorFile) throws ParseException, IOException {
list = new ArrayList<>(); list = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader(monitorFile)); BufferedReader reader = new BufferedReader(Files.newBufferedReader(monitorFile));
// Scanner sc = new Scanner(monitorFile); // Scanner sc = new Scanner(monitorFile);
double sum = 0; double sum = 0;

View File

@ -29,6 +29,9 @@ import org.apache.commons.math3.analysis.interpolation.LinearInterpolator;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -40,10 +43,10 @@ public class TransmissionInterpolator implements UnivariateFunction {
public static TransmissionInterpolator fromFile(Context context, String path, String xName, String yName, int nSmooth, double w, double border) { public static TransmissionInterpolator fromFile(Context context, String path, String xName, String yName, int nSmooth, double w, double border) {
try { try {
File dataFile = context.io().getFile(path); Path dataFile = context.io().getFile(path);
ColumnedDataReader reader = new ColumnedDataReader(new FileInputStream(dataFile)); ColumnedDataReader reader = new ColumnedDataReader(Files.newInputStream(dataFile));
return new TransmissionInterpolator(reader, xName, yName, nSmooth, w, border); return new TransmissionInterpolator(reader, xName, yName, nSmooth, w, border);
} catch (FileNotFoundException ex) { } catch (IOException ex) {
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }

View File

@ -63,11 +63,9 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction {
if (configuration.getBoolean("useFSS", true)) { if (configuration.getBoolean("useFSS", true)) {
InputStream fssStream; InputStream fssStream;
if (configuration.hasValue("fssFile")) { if (configuration.hasValue("fssFile")) {
try { fssStream = context.io().optBinary(configuration.getString("fssFile"))
fssStream = new FileInputStream(context.io().getFile(configuration.getString("fssFile"))); .orElseThrow(()-> new RuntimeException("Could not locate FSS file"))
} catch (FileNotFoundException e) { .getStream();
throw new RuntimeException("Could not locate FSS file");
}
} else { } else {
fssStream = getClass().getResourceAsStream("/data/FS.txt"); fssStream = getClass().getResourceAsStream("/data/FS.txt");
} }

View File

@ -6,6 +6,7 @@
package inr.numass.tasks; package inr.numass.tasks;
import hep.dataforge.actions.Action; import hep.dataforge.actions.Action;
import hep.dataforge.data.Data;
import hep.dataforge.data.DataNode; import hep.dataforge.data.DataNode;
import hep.dataforge.data.DataTree; import hep.dataforge.data.DataTree;
import hep.dataforge.meta.Meta; import hep.dataforge.meta.Meta;

View File

@ -42,7 +42,7 @@ public class NumassPrepareTask extends AbstractTask<Table> {
//acquiring initial data. Data node could not be empty //acquiring initial data. Data node could not be empty
DataFilter filter = new DataFilter().configure(config.getMeta("data")); DataFilter filter = new DataFilter(config.getMeta("data"));
DataNode<NumassSet> data = filter.filter(input.checked(NumassSet.class)); DataNode<NumassSet> data = filter.filter(input.checked(NumassSet.class));