hps-java/src/test/java/org/lcsim/hps/conditions
diff -N DatabaseConditionsReaderTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ DatabaseConditionsReaderTest.java 17 Sep 2013 23:25:49 -0000 1.1
@@ -0,0 +1,52 @@
+package org.lcsim.hps.conditions;
+
+import java.io.PrintStream;
+
+import junit.framework.TestCase;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.conditions.ConditionsSet;
+
+/**
+ * This class tests that the example DatabaseConditionsReader authored by Dima
+ * actually works with a test detector.
+ * @author jeremym
+ */
+public class DatabaseConditionsReaderTest extends TestCase {
+
+ /* Example detector from hps-detectors. */
+ private final String detectorName = "HPS-conditions-test";
+
+ /* Run number of conditions set. */
+ private final int runNumber = 0;
+
+ /* Name of conditions set. */
+ private final String conditionsSetName = "calibration";
+
+ /* Print output. */
+ private final PrintStream ps = System.out;
+
+ /**
+ * Create the manager, load the detector, and then get the conditions meta-data
+ * for the selected conditions set. Finally, use the sample converter to create
+ * a Calibration object from the database rows.
+ */
+ public void test() {
+ ConditionsManager manager = ConditionsManager.defaultInstance();
+ try {
+ manager.setDetector(detectorName, runNumber);
+ } catch (ConditionsNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ ConditionsSet conditions = manager.getConditions(conditionsSetName);
+ ps.println("Got conditions " + conditionsSetName + " of size " + conditions.size());
+ ps.println("table: " + conditions.getString("table"));
+ ps.println("column: " + conditions.getString("column"));
+ ps.println("id: " + conditions.getString("id"));
+ CalibrationConverter calibrationConverter = new CalibrationConverter();
+ Calibration calibration = calibrationConverter.getData(manager, null);
+ ps.println("Fetched calibration conditions: ");
+ ps.println(calibration.toString());
+ }
+}