lcsim/test/org/lcsim/conditions
diff -u -r1.5 -r1.6
--- ConditionsManagerTest.java 6 Jul 2005 05:18:16 -0000 1.5
+++ ConditionsManagerTest.java 13 Jul 2005 01:12:46 -0000 1.6
@@ -1,9 +1,19 @@
package org.lcsim.conditions;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
-import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.GeometryReader;
+import org.lcsim.util.cache.FileCache;
/**
*
@@ -11,69 +21,93 @@
*/
public class ConditionsManagerTest extends TestCase
{
- ConditionsManager _mgr;
- public final static String testDet = "sdjan03";
+ private ConditionsManager _mgr;
+ public List<String> testDets;
public final static String[] condNames = {"TrackParameters","ClusterParameters","HitSmearing","SamplingFractions"};
/** Creates a new instance of ConditionsReaderTest */
- public ConditionsManagerTest(String testName)
+ public ConditionsManagerTest (String testName)
{
- super(testName);
+ super (testName);
}
- public static Test suite()
+ public static Test suite ()
{
- return new TestSuite(ConditionsManagerTest.class);
+ return new TestSuite (ConditionsManagerTest.class);
}
- protected void setUp() throws Exception
+ protected void setUp () throws Exception
{
- _mgr = ConditionsManager.defaultInstance();
- _mgr.setDetector(testDet, 0);
+ _mgr = ConditionsManager.defaultInstance ();
+
+ FileCache cache = new FileCache ();
+ File file = cache.getCachedFile (new URL ("http://lcsim.org/detectors/taglist.txt"));
+ BufferedReader reader = new BufferedReader (new FileReader (file));
+ testDets = new ArrayList<String>();
+ for (;;)
+ {
+ String line = reader.readLine ();
+ if (line == null) break;
+ testDets.add (line.trim ());
+ }
+ reader.close ();
}
- public void test_files()
+ public void test_files () throws Exception
{
- for ( String s : condNames )
+ for (String detName : testDets )
{
- ConditionsSet cs = _mgr.getConditions(s);
- if ( cs == null )
- {
- throw new RuntimeException("ConditionSet not found: " + s);
- }
- else
+ _mgr.setDetector (detName,0);
+
+ // First check we have a compact description
+
+ RawConditions conditions = _mgr.getRawConditions ("compact.xml");
+ InputStream in = conditions.getInputStream ();
+ GeometryReader reader = new GeometryReader ();
+ Detector detector = (Detector) reader.read (in);
+
+ for ( String s : condNames )
{
- assertTrue(cs instanceof ConditionsSet);
- //System.out.println("Found ConditionSet: " + s);
-
- //System.out.println("key=val pairs");
-
- for ( Object o : cs.keySet() )
+ try
{
- String k = o.toString();
- //System.out.println(k + "=" + cs.getString(k) );
-
- Class typ = cs.getType(k);
- try
+ ConditionsSet cs = _mgr.getConditions (s);
+ if ( cs == null )
{
- if ( typ == double.class )
- {
- double dblVal = cs.getDouble(k);
- }
- if ( typ == int.class )
- {
- int intVal = cs.getInt(k);
- }
- else if ( typ == java.lang.String.class )
- {
- String strVal = cs.getString(k);
- }
+ throw new RuntimeException ("ConditionSet not found: " + s);
}
- catch (IllegalArgumentException iae)
+ else
{
- throw new RuntimeException("Bad key to ConditionsSet.getX() function.", iae);
+ for ( Object o : cs.keySet () )
+ {
+ String k = o.toString ();
+
+ Class typ = cs.getType (k);
+ if ( typ == double.class )
+ {
+ double dblVal = cs.getDouble (k);
+ }
+ if ( typ == int.class )
+ {
+ int intVal = cs.getInt (k);
+ }
+ else if ( typ == java.lang.String.class )
+ {
+ String strVal = cs.getString (k);
+ }
+
+ }
}
}
+ catch (ConditionsSetNotFoundException csnf)
+ {
+ // Currently we only demand that sdjan03 has valid parameters
+ if ("sdjan03".equals (detName)) throw csnf;
+ //System.err.println("Warning: "+detName+" has no "+s);
+ }
+ catch (IllegalArgumentException iae)
+ {
+ throw new RuntimeException ("Bad key to ConditionsSet.getX() function.", iae);
+ }
}
}
}