hps-java/src/main/java/org/lcsim/hps/conditions/svt
diff -N SvtConditions.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ SvtConditions.java 20 Sep 2013 08:52:42 -0000 1.1
@@ -0,0 +1,113 @@
+package org.lcsim.hps.conditions.svt;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.List;
+
+import org.lcsim.conditions.ConditionsConverter;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.tracker.silicon.SiSensor;
+
+import org.lcsim.hps.recon.tracking.SvtUtils;
+import org.lcsim.hps.util.Pair;
+
+/**
+ *
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: SvtConditions.java,v 1.1 2013/09/20 08:52:42 omoreno Exp $
+ */
+public class SvtConditions {
+
+ private static Map<SiSensor, double[]> noiseMap = new HashMap<SiSensor, double[]>();
+ private static Map<SiSensor, double[]> pedestalMap = new HashMap<SiSensor, double[]>();
+ private static Map<SiSensor, double[]> tpMap = new HashMap<SiSensor, double[]>();
+ private static Map<SiSensor, Double> t0ShiftMap = new HashMap<SiSensor, Double>();
+
+ /**
+ * Ctor
+ */
+ private SvtConditions(){
+ }
+
+ public static void loadSvtConditions(ConditionsConverter<ChannelConstants> converter){
+
+ ConditionsManager conditionsManager = ConditionsManager.defaultInstance();
+
+ SvtCalibrationConverter calibrationsConverter = new SvtCalibrationConverter();
+ ChannelConstants channelConstants;
+
+
+ while(calibrationsConverter.hasNext()){
+
+ channelConstants = calibrationsConverter.getData(conditionsManager, "svt_calibrations");
+
+ int fpga = channelConstants.getFpga();
+ int hybrid = channelConstants.getHybrid();
+ int channel = channelConstants.getChannel();
+
+ Pair<Integer, Integer> daqPair = new Pair<Integer, Integer>(fpga, hybrid);
+ SiSensor sensor = SvtUtils.getInstance().getSensor(daqPair);
+
+ if(noiseMap.get(sensor) == null) noiseMap.put(sensor, new double[640]);
+ if(pedestalMap.get(sensor) == null) pedestalMap.put(sensor, new double[640]);
+ if(tpMap.get(sensor) == null) tpMap.put(sensor, new double[640]);
+
+ noiseMap.get(sensor)[channel] = channelConstants.getNoise();
+ pedestalMap.get(sensor)[channel] = channelConstants.getPedestal();
+ tpMap.get(sensor)[channel] = channelConstants.getShapingTime();
+
+ }
+ }
+
+
+ /**
+ *
+ * Get the noise for a given channel on a sensor.
+ *
+ * @param sensor
+ * @param channel
+ * @return noise
+ */
+ public static Double getNoise(SiSensor sensor, int channel){
+ double[] noise = noiseMap.get(sensor);
+ if(noise == null || channel < 0 || channel > 640){
+ return null;
+ } else {
+ return noise[channel];
+ }
+ }
+
+ /**
+ *
+ * Get the pedestal for a given channel on a sensor.
+ *
+ * @param sensor
+ * @param channel
+ * @return pedestal
+ */
+ public static Double getPedestal(SiSensor sensor, int channel){
+ double[] pedestal = pedestalMap.get(sensor);
+ if(pedestal == null || channel < 0 || channel > 640){
+ return null;
+ } else {
+ return pedestal[channel];
+ }
+ }
+
+ /**
+ *
+ * Get the shaping time for a given channel on a sensor
+ *
+ * @param sensor
+ * @param channel
+ * @return shaping time
+ */
+ public static Double getShapingTime(SiSensor sensor, int channel){
+ double[] tp = tpMap.get(sensor);
+ if(tp == null || channel < 0 || channel > 640){
+ return null;
+ } else {
+ return tp[channel];
+ }
+ }
+}
hps-java/src/main/java/org/lcsim/hps/conditions/svt
diff -N ChannelConstants.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ChannelConstants.java 20 Sep 2013 08:52:42 -0000 1.1
@@ -0,0 +1,121 @@
+package org.lcsim.hps.conditions.svt;
+
+
+/**
+ *
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: ChannelConstants.java,v 1.1 2013/09/20 08:52:42 omoreno Exp $
+ */
+public class ChannelConstants {
+
+ private int fpga = -1;
+ private int hybrid = -1;
+ private int channel = -1;
+
+ private double pedestal = Double.NaN;
+ private double noise = Double.NaN;
+ private double tp = Double.NaN;
+ private double t0Shift = Double.NaN;
+ private double[][] pulseShape = null;
+
+
+ /**
+ * Default Ctor
+ */
+ public ChannelConstants(){
+ }
+
+ public ChannelConstants(int fpga, int hybrid, int channel,
+ double pedestal, double noise, double tp, double t0Shift, double[][] pulseShape){
+ this.setFpga(fpga);
+ this.setHybrid(hybrid);
+ this.setChannel(channel);
+ this.setPedestal(pedestal);
+ this.setNoise(noise);
+ this.setShapingTime(tp);
+ this.setT0Shift(t0Shift);
+ this.setPulseShape(pulseShape);
+ }
+
+
+ //--- Setters ---//
+ //---------------//
+
+ public void setFpga(int fpga){
+ this.fpga = fpga;
+ }
+
+ public void setHybrid(int hybrid){
+ this.hybrid = hybrid;
+ }
+
+ public void setChannel(int channel){
+ this.channel = channel;
+ }
+
+ public void setNoise(double noise){
+ this.noise = noise;
+ }
+
+ public void setPedestal(double pedestal){
+ this.pedestal = pedestal;
+ }
+
+ public void setShapingTime(double tp){
+ this.tp = tp;
+ }
+
+ public void setT0Shift(double t0Shift){
+ this.t0Shift = t0Shift;
+ }
+
+ public void setPulseShape(double[][] pulseShape){
+ this.pulseShape = pulseShape;
+ }
+
+ //--- Getters ---//
+ //---------------//
+
+ public int getFpga(){
+ return fpga;
+ }
+
+ public int getHybrid(){
+ return hybrid;
+ }
+
+ public int getChannel(){
+ return channel;
+ }
+
+ public double getNoise(){
+ return noise;
+ }
+
+ public double getPedestal(){
+ return pedestal;
+ }
+
+ public double getShapingTime(){
+ return tp;
+ }
+
+ public double getT0Shift(){
+ return t0Shift;
+ }
+
+ public double[][] getPulseShape(){
+ return pulseShape;
+ }
+
+ @Override
+ public String toString(){
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("FPGA: " + this.getFpga() + "\n");
+ buffer.append("Hybrid: " + this.getHybrid() + "\n");
+ buffer.append("Channel: " + this.getChannel() + "\n");
+ buffer.append("Pedestal: " + this.getPedestal() + "\n");
+ buffer.append("Noise: " + this.getNoise() + "\n");
+ return buffer.toString();
+ }
+}
hps-java/src/main/java/org/lcsim/hps/conditions/svt
diff -u -r1.4 -r1.5
--- SvtCalibrationConverter.java 19 Sep 2013 01:38:17 -0000 1.4
+++ SvtCalibrationConverter.java 20 Sep 2013 08:52:42 -0000 1.5
@@ -5,59 +5,64 @@
import java.sql.SQLException;
import java.sql.Statement;
+import org.lcsim.conditions.ConditionsConverter;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsSet;
import org.lcsim.hps.conditions.ConnectionManager;
-import org.lcsim.hps.conditions.DatabaseConditionsConverter;
/**
* Read from conditions database and create SVT calibration data.
*
* @author jeremym
- * @version $Id: SvtCalibrationConverter.java,v 1.4 2013/09/19 01:38:17 jeremy Exp $
+ * @version $Id: SvtCalibrationConverter.java,v 1.5 2013/09/20 08:52:42 omoreno Exp $
*/
-public class SvtCalibrationConverter extends DatabaseConditionsConverter<SvtCalibrationConstants> {
+public class SvtCalibrationConverter implements ConditionsConverter<ChannelConstants> {
+
+ Connection connection = null;
+ Statement statement = null;
+ String database;
+ ResultSet resultSet = null;
+ ConditionsSet conditionsSet = null;
- /**
- * Constructor with argument.
- * @param connectionParameters The connection information for the condition database.
- */
- public SvtCalibrationConverter() {
- }
+ private boolean hasNext = true;
+ private boolean connectionEstablished = false;
+
+ public SvtCalibrationConverter() {
+ // Connect to the database.
+ connection = ConnectionManager.createConnection();
+ database = ConnectionManager.getConnectionParameters().getDatabase();
+ }
- /**
- * Primary hook for loading data, which is called by the ConditionsReader.
- * It produces a calibration object based on the appropriate database records.
- */
- public SvtCalibrationConstants getData(ConditionsManager manager, String name) {
+ public ChannelConstants getData(ConditionsManager manager, String name) {
- Connection connection = null;
- Statement statement = null;
- SvtCalibrationConstants calibration = new SvtCalibrationConstants();
+ ChannelConstants constants = null;
try {
- // Get the meta data for this conditions set.
- ConditionsSet cs = manager.getConditions(name);
-
- // Connect to the database.
- connection = ConnectionManager.createConnection();
-
- String db = ConnectionManager.getConnectionParameters().getDatabase();
-
- String query = "SELECT fpga, hybrid, channel, noise, pedestal FROM "
- + db + "."
- + cs.getString("table") + " WHERE "
- + cs.getString("column") + " = "
- + cs.getString("id");
- statement = connection.createStatement();
- ResultSet rs = statement.executeQuery(query);
- while (rs.next()) {
- int fpga = rs.getInt(1);
- int hybrid = rs.getInt(2);
- int channel = rs.getInt(3);
- double noise = rs.getDouble(4);
- double pedestal = rs.getDouble(5);
- calibration.addData(fpga, hybrid, channel, pedestal, noise);
- }
+
+ if(!connectionEstablished){
+ conditionsSet = manager.getConditions(name);
+
+ String query = "SELECT fpga, hybrid, channel, noise, pedestal FROM "
+ + database + "."
+ + conditionsSet.getString("table") + " WHERE "
+ + conditionsSet.getString("column") + " = "
+ + conditionsSet.getString("id");
+
+ statement = connection.createStatement();
+ resultSet = statement.executeQuery(query);
+ hasNext = resultSet.next();
+ }
+
+ int fpga = resultSet.getInt(1);
+ int hybrid = resultSet.getInt(2);
+ int channel = resultSet.getInt(3);
+ double noise = resultSet.getDouble(4);
+ double pedestal = resultSet.getDouble(5);
+
+ constants
+ = new ChannelConstants(fpga, hybrid, channel, pedestal, noise,
+ Double.NaN, Double.NaN, null);
+ resultSet.next();
+
} catch (SQLException x) {
if (statement != null) {
try {
@@ -73,14 +78,18 @@
}
throw new RuntimeException("Database error", x);
}
- return calibration;
+ return constants;
}
/**
* Get the type handled by this converter.
* @return The type handled by this converter.
*/
- public Class<SvtCalibrationConstants> getType() {
- return SvtCalibrationConstants.class;
+ public Class<ChannelConstants> getType() {
+ return ChannelConstants.class;
}
+
+ public boolean hasNext() {
+ return hasNext;
+ }
}
hps-java/src/test/java/org/lcsim/hps/conditions
diff -u -r1.3 -r1.4
--- DatabaseConditionsReaderTest.java 18 Sep 2013 02:56:39 -0000 1.3
+++ DatabaseConditionsReaderTest.java 20 Sep 2013 08:52:42 -0000 1.4
@@ -8,6 +8,7 @@
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
import org.lcsim.conditions.ConditionsSet;
+import org.lcsim.hps.conditions.svt.ChannelConstants;
import org.lcsim.hps.conditions.svt.SvtCalibrationConstants;
/**
@@ -51,8 +52,8 @@
ps.println("column: " + conditions.getString("column"));
ps.println("id: " + conditions.getString("id"));
- CachedConditions<SvtCalibrationConstants> c = manager.getCachedConditions(SvtCalibrationConstants.class, conditionsSetName);
- SvtCalibrationConstants calibration = c.getCachedData();
+ CachedConditions<ChannelConstants> c = manager.getCachedConditions(ChannelConstants.class, conditionsSetName);
+ ChannelConstants calibration = c.getCachedData();
System.out.println("Got calibration conditions ... ");
System.out.println(calibration);
System.out.println("Success!");