projects/lcsim/trunk/conditions/src/main/java/org/lcsim/conditions
--- 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 {
- }
- }
}