hps-java/src/test/java/org/lcsim/hps/conditions/svt
diff -N SvtConditionsLoaderTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SvtConditionsLoaderTest.java 11 Oct 2013 01:27:33 -0000 1.6
@@ -0,0 +1,100 @@
+package org.lcsim.hps.conditions.svt;
+
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.detector.tracker.silicon.HpsSiSensor;
+import org.lcsim.geometry.Detector;
+import org.lcsim.hps.conditions.ConnectionManager;
+import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
+
+/**
+ * This test loads conditions data onto the detector and then checks that
+ * all channels of each sensor have non-zero data values for these parameters.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class SvtConditionsLoaderTest extends TestCase {
+
+ /** An example detector from hps-detectors. */
+ private static final String detectorName = "HPS-conditions-test";
+
+ /** The run number of the conditions set in the database. */
+ private static final int runNumber = 777;
+
+ /**
+ * Load SVT conditions data onto the detector and perform basic checks afterwards.
+ */
+ public void test() {
+
+ // Setup the conditions manager.
+ ConditionsManager.setDefaultConditionsManager(new LCSimConditionsManagerImplementation());
+ ConditionsManager manager = ConditionsManager.defaultInstance();
+ try {
+ manager.setDetector(detectorName, runNumber);
+ } catch (ConditionsNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+
+ // Get the detector.
+ Detector detector = manager.getCachedConditions(Detector.class, "compact.xml").getCachedData();
+
+ // Get conditions.
+ SvtConditions conditions = manager.getCachedConditions(SvtConditions.class, null).getCachedData();
+
+ // Load conditions onto detector.
+ SvtConditionsLoader loader = new SvtConditionsLoader();
+ loader.load(detector, conditions);
+
+ // Check sensor data.
+ List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class);
+ final int nchannels = sensors.get(0).getNumberOfChannels();
+ int deadChannels = 0;
+ // Loop over sensors.
+ for (HpsSiSensor sensor : sensors) {
+ // Loop over channels.
+ for (int channel=0; channel<nchannels; channel++) {
+
+ // Check that hardware information seems reasonable.
+ int hybrid = sensor.getHybridNumber();
+ assertTrue("Invalid hybrid value.", hybrid >= 0 && hybrid <= 2);
+ int fpga = sensor.getFpgaNumber();
+ assertTrue("Invalid FPGA value.", fpga >= 0 && fpga <=5);
+
+ // Check that conditions values are not zero:
+ assertTrue("Gain is zero.", sensor.getGain(channel) != 0);
+ assertTrue("Noise is zero.", sensor.getNoise(channel) != 0);
+ assertTrue("Pedestal is zero.", sensor.getPedestal(channel) != 0);
+ assertTrue("Time offset is zero.", sensor.getTimeOffset(channel) != 0);
+ assertTrue("PulseParameters points to null.", sensor.getPulseParameters(channel) != null);
+ double[] pulse = sensor.getPulseParameters(channel);
+
+ // There are four channels in the database where these are all zeroes.
+ if (pulse[0] != 0) {
+ // Check pulse parameters:
+ assertTrue("amplitude is zero", pulse[0] != 0);
+ assertTrue("t0 is zero", pulse[1] != 0);
+ assertTrue("tp is zero", pulse[2] != 0);
+ assertTrue("chisq is zero", pulse[3] != 0);
+ }
+
+ // Add to bad channel count.
+ if (sensor.isBadChannel(channel)) {
+ ++deadChannels;
+ }
+ }
+ }
+
+ // Check that there were at least some bad channels.
+ assertTrue("Number of bad channels was zero.", deadChannels != 0);
+
+ // There should be 50 dead channels found for the QA set.
+ assertEquals("Wrong number of dead channels found.", 50, deadChannels);
+
+ // Cleanup the database connection.
+ ConnectionManager.getConnectionManager().disconnect();
+ }
+}