lcsim/src/org/lcsim/digisim
diff -u -r1.3 -r1.4
--- ConfigReader.java 14 May 2005 00:26:52 -0000 1.3
+++ ConfigReader.java 27 Jun 2005 21:47:19 -0000 1.4
@@ -1,19 +1,51 @@
package org.lcsim.digisim;
-//import java.util.*;
import java.util.Vector;
import java.util.Map;
import java.util.HashMap;
import java.io.*;
+/**
+ * Utility class to read the DigiSim configuration parameters from an
+ * ASCII file.
+ *
+ * An important design issue is that the format of the configuration
+ * file is the same for both the C++ and the java versions of
+ * DigiSim. The implementation is easier if java can correctly
+ * interpret the Marlin steering file.
+ *
+ * @author Guilherme Lima
+ * @version $Id: ConfigReader.java,v 1.4 2005/06/27 21:47:19 lima Exp $
+ */
class ConfigReader {
- // constructor
+ /**
+ * Convenience constructor to be used from lcsim drivers.
+ * Configuration is provided by an InputStream object, which may
+ * be taken from a released .jar file through a call to
+ * getResourceAsStream (e.g. @see DigiSimDriver).
+ * @param input InputStream object
+ */
ConfigReader(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
delimiter = " ";
}
+ /** Constructor for local config files.
+ * @param filename Configuration file name
+ */
+ ConfigReader(String filename) {
+ try {
+ FileReader input = new FileReader(new File(filename));
+ reader = new BufferedReader(input);
+ delimiter = " ";
+ System.out.println("Using local configuration file: "+filename);
+ }
+ catch(FileNotFoundException e) {
+ assert false : "File not found: "+ filename;
+ }
+ }
+
public void close() {
try {
reader.close();
@@ -23,6 +55,10 @@
}
}
+ /** Read next line from configuration file. Note that the line
+ * read is stored in a field, not as the object returned.
+ * @return true if a new line was read in, false otherwise (end of file).
+ */
public boolean getNextLine() {
// static boolean endOfFile = false;
boolean endOfFile = false;
@@ -41,8 +77,8 @@
}
/**
- * Validates and cleans up lines.
- * @return true for valid line found, false when EndOfFile is
+ * Validates and cleans up lines. Comment lines are not returned.
+ * @return true for valid line found, false when end of file is
* reached.
*/
public boolean getNextValidLine() {
@@ -52,7 +88,7 @@
if(line.equals("")) continue;
// good line found
break;
- }
+ }
if(line==null) return false;
@@ -68,10 +104,15 @@
} while( newlen<lastlen );
// debug
-// System.out.println(line);
+// System.out.println(line);
return true;
}
+ /**
+ * Parses the configuration file
+ * @return a map containing all the sections in the configuration
+ * file, keyed by section name.
+ */
public Map<String,Vector<String>> digiSimParse() {
Map<String,Vector<String>> sections
= new HashMap<String,Vector<String>>();
@@ -88,7 +129,7 @@
/**
* Return a complete section of the configuration file. It is
* called when the first line of a section is found (.begin).
- * @return a Vector<String> containing all the valid lines of a
+ * @return a vector containing all the valid lines of a
* section.
*/
public Vector<String> getNextSection() {