diff --git a/numass-main/src/main/java/inr/numass/NumassIO.java b/numass-main/src/main/java/inr/numass/NumassIO.java index 068453d2..cde9755f 100644 --- a/numass-main/src/main/java/inr/numass/NumassIO.java +++ b/numass-main/src/main/java/inr/numass/NumassIO.java @@ -27,7 +27,9 @@ import hep.dataforge.utils.ReferenceRegistry; import org.apache.commons.io.output.TeeOutputStream; import org.slf4j.LoggerFactory; -import java.io.*; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -105,20 +107,21 @@ public class NumassIO extends BasicIOManager { if (!Files.exists(parentDir)) { throw new RuntimeException("Working directory does not exist"); } - if (dirName != null && !dirName.isEmpty()) { - parentDir = parentDir.resolve(dirName); - Files.createDirectories(parentDir); - } + try { + if (dirName != null && !dirName.isEmpty()) { + parentDir = parentDir.resolve(dirName); + Files.createDirectories(parentDir); + } // String output = source.meta().getString("output", this.meta().getString("output", fileName + ".onComplete")); - outputFile = parentDir.resolve(fileName); - try { + outputFile = parentDir.resolve(fileName); + if (getContext().getBoolean("numass.consoleOutput", false)) { return new TeeOutputStream(Files.newOutputStream(outputFile), System.out); } else { return Files.newOutputStream(outputFile); } - } catch (FileNotFoundException ex) { + } catch (IOException ex) { throw new RuntimeException(ex); } } 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 d787ef46..c254803f 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 @@ -20,8 +20,7 @@ import inr.numass.models.FSS; import inr.numass.utils.NumassIntegrator; import org.apache.commons.math3.analysis.UnivariateFunction; -import java.io.FileInputStream; -import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import static hep.dataforge.values.ValueType.BOOLEAN; @@ -61,14 +60,19 @@ public class SterileNeutrinoSpectrum extends AbstractParametricFunction { public SterileNeutrinoSpectrum(Context context, Meta configuration) { super(list); if (configuration.getBoolean("useFSS", true)) { - InputStream fssStream; - if (configuration.hasValue("fssFile")) { - fssStream = context.io().optBinary(configuration.getString("fssFile")) - .orElseThrow(()-> new RuntimeException("Could not locate FSS file")) - .getStream(); - } else { - fssStream = getClass().getResourceAsStream("/data/FS.txt"); - } + InputStream fssStream = configuration.optString("fssFile") + .map(fssFile -> { + try { + return context.io().optBinary(fssFile) + .orElseThrow(() -> new RuntimeException("Could not locate FSS file")) + .getStream(); + } catch (IOException e) { + throw new RuntimeException("Could not load FSS file", e); + } + }) + .orElse(getClass().getResourceAsStream("/data/FS.txt")); + + fss = new FSS(fssStream); }