Commit in projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions on MAIN | |||
ConditionsReader.java | +23 | -113 | 3060 -> 3061 |
readers/BaseClasspathConditionsReader.java | +48 | added 3061 | |
/DirectoryConditionsReader.java | +29 | added 3061 | |
/DummyConditionsReader.java | +16 | added 3061 | |
/ZipConditionsReader.java | +30 | added 3061 | |
+146 | -113 |
Put the reader classes in their own package from which they are publicly accessible. They did not belong as private embedded classes in their abstract superclass's file.
--- projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/ConditionsReader.java 2014-03-20 19:06:30 UTC (rev 3060) +++ projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/ConditionsReader.java 2014-03-20 20:47:42 UTC (rev 3061) @@ -1,6 +1,5 @@
package org.lcsim.conditions;
-import java.io.BufferedInputStream;
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream;
@@ -18,13 +17,19 @@
import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile;
+
import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.conditions.readers.BaseClasspathConditionsReader; +import org.lcsim.conditions.readers.DirectoryConditionsReader; +import org.lcsim.conditions.readers.DummyConditionsReader; +import org.lcsim.conditions.readers.ZipConditionsReader;
import org.lcsim.util.cache.FileCache; import org.lcsim.util.cache.FileCache.Validator; /** * * @author tonyj
+ * @author Jeremy McCormick <[log in to unmask]>
*/ public abstract class ConditionsReader {
@@ -55,6 +60,7 @@
if (detectorName.equals(manager.getDetector())) { return false; } else {
+ // ?????
throw new IllegalArgumentException(); } }
@@ -62,6 +68,7 @@
/** * Get a list of available detectors */
+ // FIXME: This should be removed.
public static List<String> getDetectorNames() { Set<String> set = new HashSet<String>(); if (aliases == null) {
@@ -75,6 +82,7 @@
if (cache == null) { cache = new FileCache(new File(home, "cache")); }
+ // FIXME: Not even sure this taglist should be supported at all any longer.
File file = cache.getCachedFile(new URL("http://www.lcsim.org/detectors/taglist.txt")); if (file != null) { BufferedReader reader = new BufferedReader(new FileReader(file));
@@ -107,6 +115,7 @@
return new DummyConditionsReader(); }
+ // FIXME: Alias should be a feature that is easily turned off.
private static String resolveAlias(final String detectorName) throws IOException { String name = detectorName; for (int i = 0;; i++) {
@@ -127,13 +136,9 @@
* details see @link * http://confluence.slac.stanford.edu/display/ilc/Conditions+database */
+ // FIXME: This method should not be present in this class. It uses the ConditionsReader interface, + // as well as all its sub-classes. Probably better put in the ConditionsManagerImplementation.
static ConditionsReader create(String detectorName, int run) throws ConditionsNotFoundException {
- // boolean debug = true; - // if (debug) - // System.out.println("ConditionsReader.create - " + detectorName); - // System.out.println("ConditionsReader.create - " + detectorName); - // System.out.println("Called from ..."); - // (new RuntimeException()).printStackTrace();
String name = detectorName; try { if (cache == null) {
@@ -173,7 +178,7 @@
} // Search for a local, cached copy.
- File detectorDir = new File(home, "detectors");
+ File detectorDir = new File(home, "detectors"); // FIXME: Hard-coded directory location.
File zipFile = new File(detectorDir, name + ".zip"); if (zipFile.exists()) { return new ZipConditionsReader(zipFile);
@@ -183,10 +188,9 @@
return new DirectoryConditionsReader(dirFile); }
- // Finally, try to pull the detector conditions from the - // lcsim.org website.
+ // Finally, try to pull the detector conditions from the lcsim.org website.
try {
- URL url = new URL("http://www.lcsim.org/detectors/" + name + ".zip");
+ URL url = new URL("http://www.lcsim.org/detectors/" + name + ".zip"); // FIXME: Hard-coded URL.
File file = downloadDetectorDescription(url); return new ZipConditionsReader(file); } catch (FileNotFoundException x) {
@@ -218,11 +222,12 @@
} } catch (IOException x) { // For now: having failed to find or load detector.properties, use
- // unmodified reader - // Uncomment the line below if we decide this should be treated as - // an error - // throw new ConditionsNotFoundException(detectorName, run, x);
+ // unmodified reader. Uncomment the line below if we decide this should + // be treated as an error. + //throw new ConditionsNotFoundException(detectorName, run, x);
}
+ // FIXME: The detector conditions themselves should not determine what reader is used. + // This should be handled by configuring the conditions system itself directly.
String readerClassName = prop.getProperty("ConditionsReader"); if (readerClassName != null) { try {
@@ -240,6 +245,8 @@
abstract public void close() throws IOException;
+ // FIXME: Aliasing is very dangerous when matching detectors with event data files. + // There should be an option to turn this off.
private static Properties loadAliases() { Properties result = new Properties(); try {
@@ -261,16 +268,11 @@
return cache.getCachedFile(url, new DetectorFileValidator()); }
- // private static File downloadAliasFile(URL url) throws IOException - // { - // return cache.getCachedFile(url,new PropertiesFileValidator()); - // }
private static class DetectorFileValidator implements Validator { public void checkValidity(URL url, File file) throws IOException { // Check if the file looks good. It should contain a file called
- // detector.properties - // in the root directory
+ // detector.properties in the root directory
ZipFile zip = new ZipFile(file, ZipFile.OPEN_READ); try { ZipEntry header = zip.getEntry("detector.properties");
@@ -284,96 +286,4 @@
} } }
- - /* - * private static class PropertiesFileValidator implements Validator { - * public void checkValidity(URL url, File file) throws IOException { - * InputStream in = new FileInputStream(file); try { Properties props = new - * Properties(); props.load(in); - * - * } finally { in.close(); } } } - */ - private static class ZipConditionsReader extends ConditionsReader { - - private ZipFile zip; - - ZipConditionsReader(File file) throws IOException { - this.zip = new ZipFile(file, ZipFile.OPEN_READ); - } - - public InputStream open(String name, String type) throws IOException { - ZipEntry entry = zip.getEntry(name + "." + type); - if (entry == null) { - throw new IOException("Conditions " + name + "." + type + " not found"); - } - return zip.getInputStream(entry); - } - - public void close() throws IOException { - zip.close(); - } - } - - private static class DirectoryConditionsReader extends ConditionsReader { - - private File dir; - - DirectoryConditionsReader(File file) throws IOException { - this.dir = file; - } - - public InputStream open(String name, String type) throws IOException { - File file = new File(dir, name + "." + type); - if (!file.exists()) { - throw new IOException("Conditions " + name + "." + type + " not found, because directory " + file.getAbsolutePath() + " does not exist."); - } - return new BufferedInputStream(new FileInputStream(file)); - } - - public void close() throws IOException { - } - } - - /** - * This ConditionsReader finds detector conditions with the assumption that - * they are located in a package called <code>detectorName</code>, which - * must be accessible to the ContextClassLoader of the current thread. - */ - private static class BaseClasspathConditionsReader extends ConditionsReader { - - private String detectorName; - // private ClassLoader classLoader; - String propFileName = "detector.properties"; - - BaseClasspathConditionsReader(String detectorName) throws IOException { - this.detectorName = detectorName; - // classLoader = Thread.currentThread().getContextClassLoader(); - // if (ConditionsReader.class.getResourceAsStream("/" + detectorName - // + "/detector.properties") == null) { - if (getClass().getResourceAsStream("/" + detectorName + "/" + propFileName) == null) { - throw new IOException("Unable to find " + detectorName + "/" + propFileName + " on the classpath."); - } - } - - public InputStream open(String name, String type) throws IOException { - InputStream in = getClass().getResourceAsStream("/" + detectorName + "/" + name + "." + type); - if (in == null) { - throw new IOException("Conditions for " + detectorName + " with type " + type + " were not found"); - } - return in; - } - - public void close() throws IOException { - } - } - - private static class DummyConditionsReader extends ConditionsReader { - - public InputStream open(String name, String type) throws IOException { - throw new IOException("Conditions " + name + "." + type + " not found"); - } - - public void close() throws IOException { - } - }
}
--- projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/BaseClasspathConditionsReader.java (rev 0) +++ projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/BaseClasspathConditionsReader.java 2014-03-20 20:47:42 UTC (rev 3061) @@ -0,0 +1,48 @@
+package org.lcsim.conditions.readers; + +import java.io.IOException; +import java.io.InputStream; + +import org.lcsim.conditions.ConditionsReader; + +/** + * This ConditionsReader finds conditions from embedded jar resources + * based on a resource path. + */ +public class BaseClasspathConditionsReader extends ConditionsReader { + + private String _resourcePath; + + String propFileName = "detector.properties"; + + public BaseClasspathConditionsReader(String resourcePath) throws IOException { + _resourcePath = resourcePath; + + // This shouldn't be here but some (insane) logic in ConditionsReader depends on it for now. + if (getClass().getResourceAsStream("/" + _resourcePath + "/" + propFileName) == null) { + throw new IOException("Unable to find " + _resourcePath + "/" + propFileName + " on the classpath."); + } + } + + /** + * Open an InputStream to conditions data by name and type. + * + * To be found, the conditions data must exist as a resource on the classpath like: + * + * /[resourcePath]/[name].[type] + * + * It will throw an <code>IOException</code> if the conditions do not exist. + * + * @return An InputStream to the conditions data or null if does not exist. + */ + public InputStream open(String name, String type) throws IOException { + InputStream in = getClass().getResourceAsStream("/" + _resourcePath + "/" + name + "." + type); + if (in == null) { + throw new IOException("The conditions " + name + " of type " + type + " do not exist at path " + _resourcePath); + } + return in; + } + + public void close() throws IOException { + } +}
\ No newline at end of file
--- projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/DirectoryConditionsReader.java (rev 0) +++ projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/DirectoryConditionsReader.java 2014-03-20 20:47:42 UTC (rev 3061) @@ -0,0 +1,29 @@
+package org.lcsim.conditions.readers; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.lcsim.conditions.ConditionsReader; + +public class DirectoryConditionsReader extends ConditionsReader { + + private File dir; + + public DirectoryConditionsReader(File file) throws IOException { + this.dir = file; + } + + public InputStream open(String name, String type) throws IOException { + File file = new File(dir, name + "." + type); + if (!file.exists()) { + throw new IOException("Conditions " + name + "." + type + " not found, because directory " + file.getAbsolutePath() + " does not exist."); + } + return new BufferedInputStream(new FileInputStream(file)); + } + + public void close() throws IOException { + } +}
\ No newline at end of file
--- projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/DummyConditionsReader.java (rev 0) +++ projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/DummyConditionsReader.java 2014-03-20 20:47:42 UTC (rev 3061) @@ -0,0 +1,16 @@
+package org.lcsim.conditions.readers; + +import java.io.IOException; +import java.io.InputStream; + +import org.lcsim.conditions.ConditionsReader; + +public class DummyConditionsReader extends ConditionsReader { + + public InputStream open(String name, String type) throws IOException { + throw new IOException("Conditions " + name + "." + type + " not found"); + } + + public void close() throws IOException { + } +}
\ No newline at end of file
--- projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/ZipConditionsReader.java (rev 0) +++ projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions/readers/ZipConditionsReader.java 2014-03-20 20:47:42 UTC (rev 3061) @@ -0,0 +1,30 @@
+package org.lcsim.conditions.readers; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.lcsim.conditions.ConditionsReader; + +public class ZipConditionsReader extends ConditionsReader { + + private ZipFile zip; + + public ZipConditionsReader(File file) throws IOException { + this.zip = new ZipFile(file, ZipFile.OPEN_READ); + } + + public InputStream open(String name, String type) throws IOException { + ZipEntry entry = zip.getEntry(name + "." + type); + if (entry == null) { + throw new IOException("Conditions " + name + "." + type + " not found"); + } + return zip.getInputStream(entry); + } + + public void close() throws IOException { + zip.close(); + } +}
\ No newline at end of file
Use REPLY-ALL to reply to list
To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1