3 added + 2 modified, total 5 files
hps-java/src/main/java/org/lcsim/hps/conditions
diff -u -r1.9 -r1.10
--- ConditionsConstants.java 18 Oct 2013 05:46:32 -0000 1.9
+++ ConditionsConstants.java 22 Oct 2013 19:59:27 -0000 1.10
@@ -49,4 +49,7 @@
/** Conditions key for SVT time shifts by sensor. */
public static final String SVT_TIME_SHIFTS = "svt_time_shifts";
+
+ /** Conditions key for integrated beam current. */
+ public static final String BEAM_CURRENT = "beam_current";
}
hps-java/src/main/java/org/lcsim/hps/conditions
diff -u -r1.2 -r1.3
--- ConditionsConverterRegister.java 15 Oct 2013 23:14:47 -0000 1.2
+++ ConditionsConverterRegister.java 22 Oct 2013 19:59:27 -0000 1.3
@@ -1,6 +1,7 @@
package org.lcsim.hps.conditions;
import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.hps.conditions.beam.BeamCurrentConverter;
import org.lcsim.hps.conditions.ecal.EcalBadChannelConverter;
import org.lcsim.hps.conditions.ecal.EcalCalibrationConverter;
import org.lcsim.hps.conditions.ecal.EcalChannelMapConverter;
@@ -68,6 +69,8 @@
// ECAL combined conditions.
manager.registerConditionsConverter(new EcalConditionsConverter());
+
+ // Beam current condition.
+ manager.registerConditionsConverter(new BeamCurrentConverter());
}
-
}
hps-java/src/main/java/org/lcsim/hps/conditions/beam
diff -N BeamCurrent.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeamCurrent.java 22 Oct 2013 19:59:27 -0000 1.1
@@ -0,0 +1,26 @@
+package org.lcsim.hps.conditions.beam;
+
+/**
+ * This class is a simple data holder for the integrated beam current condition.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class BeamCurrent {
+
+ double beamCurrent = Double.NaN;
+
+ /**
+ * Class constructor.
+ * @param beamCurrent The integrated beam current value.
+ */
+ BeamCurrent(double beamCurrent) {
+ this.beamCurrent = beamCurrent;
+ }
+
+ /**
+ * Get the integrated beam current.
+ * @return The integrated beam current.
+ */
+ double getIntegratedBeamCurrent() {
+ return beamCurrent;
+ }
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/conditions/beam
diff -N BeamCurrentConverter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeamCurrentConverter.java 22 Oct 2013 19:59:27 -0000 1.1
@@ -0,0 +1,72 @@
+package org.lcsim.hps.conditions.beam;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.hps.conditions.ConditionsRecord;
+import org.lcsim.hps.conditions.ConnectionManager;
+import org.lcsim.hps.conditions.DatabaseConditionsConverter;
+
+/**
+ * This class creates a {@link BeamCurrent} from the conditions database.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class BeamCurrentConverter extends DatabaseConditionsConverter<BeamCurrent> {
+
+ /**
+ * Class constructor.
+ */
+ public BeamCurrentConverter() {
+ }
+
+ /**
+ * Get the conditions data.
+ * @param manager The current conditions manager.
+ * @param name The name of the conditions set.
+ */
+ public BeamCurrent getData(ConditionsManager manager, String name) {
+
+ // Get the ConditionsRecord with the meta-data, which will use the current run number from the manager.
+ ConditionsRecord record = ConditionsRecord.find(manager, name).get(0);
+
+ // Get the table name, field name, and field value defining the applicable conditions.
+ String tableName = record.getTableName();
+ String fieldName = record.getFieldName();
+ int fieldValue = record.getFieldValue();
+
+ // Get the connection manager.
+ ConnectionManager connectionManager = ConnectionManager.getConnectionManager();
+
+ // Construct the query to find matching records using the ID field.
+ String query = "SELECT beam_current FROM "
+ + tableName + " WHERE " + fieldName + " = " + fieldValue;
+
+ // Execute the query and get the results.
+ ResultSet resultSet = connectionManager.query(query);
+
+ // The object to be returned to caller.
+ BeamCurrent beamCurrent = null;
+
+ try {
+ // Loop over the gain records.
+ while(resultSet.next()) {
+ beamCurrent = new BeamCurrent(resultSet.getDouble(1));
+ break;
+ }
+ } catch (SQLException x) {
+ throw new RuntimeException("Database error.", x);
+ }
+
+ // Return collection of gain objects to caller.
+ return beamCurrent;
+ }
+
+ /**
+ * Get the type handled by this converter.
+ * @return The type handled by this converter.
+ */
+ public Class<BeamCurrent> getType() {
+ return BeamCurrent.class;
+ }
+}
\ No newline at end of file
hps-java/src/test/java/org/lcsim/hps/conditions/beam
diff -N BeamCurrentTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BeamCurrentTest.java 22 Oct 2013 19:59:27 -0000 1.1
@@ -0,0 +1,81 @@
+package org.lcsim.hps.conditions.beam;
+
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.event.EventHeader;
+import org.lcsim.util.Driver;
+import org.lcsim.util.cache.FileCache;
+import org.lcsim.util.loop.LCSimLoop;
+
+import static org.lcsim.hps.conditions.ConditionsConstants.BEAM_CURRENT;
+
+/**
+ * This test checks the beam current values by run.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class BeamCurrentTest extends TestCase {
+
+ /** This test file has a few events from the "good runs" of the Test Run. */
+ private static final String TEST_FILE_URL = "http://www.lcsim.org/test/hps/conditions_test.slcio";
+
+ /** Answer key for beam current by run. */
+ static Map<Integer,Double> beamCurrentAnswerKey = new HashMap<Integer,Double>();
+
+ /** Setup the beam current answer key by run. */
+ static {
+ beamCurrentAnswerKey.put(1349, 54879.7343788147);
+ beamCurrentAnswerKey.put(1351, 26928.0426635742);
+ beamCurrentAnswerKey.put(1353, 204325.132622242);
+ beamCurrentAnswerKey.put(1354, 148839.141475141);
+ beamCurrentAnswerKey.put(1358, 92523.9428218845);
+ beamCurrentAnswerKey.put(1359, 91761.4541434497);
+ beamCurrentAnswerKey.put(1360, 209883.979889035);
+ beamCurrentAnswerKey.put(1362, 110298.553449392);
+ beamCurrentAnswerKey.put(1363, 8556.8459701538);
+ }
+
+ /**
+ * Run the test.
+ * @throws Exception
+ */
+ public void test() throws Exception {
+
+ // Cache file locally from URL.
+ FileCache cache = new FileCache();
+ File testFile = cache.getCachedFile(new URL(TEST_FILE_URL));
+
+ // Run the ConditionsDriver over test data containing multiple runs from the Test Run.
+ LCSimLoop loop = new LCSimLoop();
+ loop.setLCIORecordSource(testFile);
+ loop.add(new BeamCurrentChecker());
+ loop.loop(-1, null);
+ }
+
+ /**
+ * This Driver will check the beam current for a run against the answer key.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+ class BeamCurrentChecker extends Driver {
+
+ int currentRun = Integer.MIN_VALUE;
+
+ /**
+ * This method will check the beam current against the answer key
+ * for the first event of a new run.
+ */
+ public void process(EventHeader event) {
+ if (currentRun != event.getRunNumber()) {
+ currentRun = event.getRunNumber();
+ BeamCurrent beamCurrent = ConditionsManager.defaultInstance().getCachedConditions(BeamCurrent.class, BEAM_CURRENT).getCachedData();
+ System.out.println("Run " + event.getRunNumber() + " has integrated beam current " + beamCurrent.getIntegratedBeamCurrent() + " nC.");
+ assertEquals("Wrong beam current for run.", beamCurrentAnswerKey.get(currentRun), beamCurrent.getIntegratedBeamCurrent());
+ }
+ }
+ }
+}
\ No newline at end of file
CVSspam 0.2.12