Commit in hps-java/src/main/java/org/lcsim/hps/conditions on MAIN
ConditionsConstants.java+61.1 -> 1.2
DatabaseConditionsReader.java+15-61.9 -> 1.10
ecal/EcalBadChannelCollection.java+12added 1.1
    /EcalBadChannelConverter.java+95added 1.1
    /EcalCalibration.java+53added 1.1
    /EcalCalibrationCollection.java+10added 1.1
    /EcalCalibrationConverter.java+96added 1.1
    /EcalChannel.java+2-11.2 -> 1.3
    /EcalConditions.java+29-41.2 -> 1.3
    /EcalConditionsLoader.java+21-31.2 -> 1.3
    /EcalGainCollection.java+2-21.2 -> 1.3
    /EcalGainConverter.java+3-61.2 -> 1.3
+344-22
5 added + 7 modified, total 12 files
more work on conditions system; add implementation of bad channels and calibrations for ecal

hps-java/src/main/java/org/lcsim/hps/conditions
ConditionsConstants.java 1.1 -> 1.2
diff -u -r1.1 -r1.2
--- ConditionsConstants.java	25 Sep 2013 22:14:24 -0000	1.1
+++ ConditionsConstants.java	1 Oct 2013 00:34:29 -0000	1.2
@@ -13,6 +13,12 @@
     /** Conditions key for ECal gain data. */
     public static final String ECAL_GAINS = "ecal_gains";
     
+    /** Conditions key for ECal bad channel set. */
+    public static final String ECAL_BAD_CHANNELS = "ecal_bad_channels";
+    
+    /** Conditions key for ECal calibration information. */
+    public static final String ECAL_CALIBRATIONS = "ecal_calibrations";
+    
     /** Table with SVT channel data. */
     public static final String SVT_CHANNELS = "svt_channels";
         

hps-java/src/main/java/org/lcsim/hps/conditions
DatabaseConditionsReader.java 1.9 -> 1.10
diff -u -r1.9 -r1.10
--- DatabaseConditionsReader.java	25 Sep 2013 22:14:24 -0000	1.9
+++ DatabaseConditionsReader.java	1 Oct 2013 00:34:29 -0000	1.10
@@ -12,29 +12,39 @@
 
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsReader;
+import org.lcsim.hps.conditions.ecal.EcalBadChannelConverter;
+import org.lcsim.hps.conditions.ecal.EcalCalibrationConverter;
 import org.lcsim.hps.conditions.ecal.EcalChannelConverter;
 import org.lcsim.hps.conditions.ecal.EcalGainConverter;
 import org.lcsim.hps.conditions.svt.SvtCalibrationConverter;
 
 /**
+ * <p>
  * This a rewritten version of Dima's ExampleDatabaseConditionsReader that attempts to handle 
  * the conditions and their meta data in a fully generic fashion.
+ * </p>
  * 
+ * <p>
  * In order to override the default database connection parameters, the system property
  * <code>hps.conditions.db.configuration</code> should point to a properties file defining 
  * the variables read by ConnectionParameters (see that class for details).  Otherwise, the 
  * defaults will be used to connect to a test database at SLAC.
+ * <p>
  * 
+ * <p>
  * Setting custom connection properties would look something like the following from the CL:
+ * </p>
  * 
- *     java -Dhps.conditions.db.configuration=/path/to/my/config.prop [...]
+ * <p><code>java -Dhps.conditions.db.configuration=/path/to/my/config.prop [...]</code></p>
  * 
+ * <p>
  * Currently, this class should "know" directly about all the converters that are needed for loading
  * conditions data via the <code>registerConditionsConverters</code> method.  The SVT is the only example 
  * currently of an actual HPS sub-system, but more will be added as they are created.
+ * </p>
  * 
- * @author jeremym
- * @version $Id: DatabaseConditionsReader.java,v 1.9 2013/09/25 22:14:24 jeremy Exp $ 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @version $Id: DatabaseConditionsReader.java,v 1.10 2013/10/01 00:34:29 jeremy Exp $ 
  */
 public class DatabaseConditionsReader extends ConditionsReader {
         
@@ -198,8 +208,7 @@
         manager.registerConditionsConverter(new SvtCalibrationConverter());
         manager.registerConditionsConverter(new EcalChannelConverter());
         manager.registerConditionsConverter(new EcalGainConverter());
-        //
-        // TODO: Add other converters here as they are made available.
-        //
+        manager.registerConditionsConverter(new EcalBadChannelConverter());
+        manager.registerConditionsConverter(new EcalCalibrationConverter());        
     }
 }

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalBadChannelCollection.java added at 1.1
diff -N EcalBadChannelCollection.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalBadChannelCollection.java	1 Oct 2013 00:34:29 -0000	1.1
@@ -0,0 +1,12 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.util.HashSet;
+
+/**
+ * This class represents a set of bad channels in the ECal.  The integer
+ * values are database IDs of the channels from the ecal_channels table.
+ * @author jeremym
+ */
+public class EcalBadChannelCollection extends HashSet<Integer> { 
+
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalBadChannelConverter.java added at 1.1
diff -N EcalBadChannelConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalBadChannelConverter.java	1 Oct 2013 00:34:29 -0000	1.1
@@ -0,0 +1,95 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+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 list of {@link EcalBadChannel} objects from the conditions database.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalBadChannelConverter extends DatabaseConditionsConverter<EcalBadChannelCollection> {
+
+    /**
+     * Create the collection from the conditions database. 
+     * @param manager The conditions manager.
+     * @param name The name of the conditions set.
+     */
+    public EcalBadChannelCollection getData(ConditionsManager manager, String name) {
+
+        // Collection to be returned to caller.
+        EcalBadChannelCollection badChannels = new EcalBadChannelCollection();
+
+        // Get the ConditionsRecord with the meta-data, which will use the
+        // current run number from the manager.
+        ConditionsRecord record = ConditionsRecord.find(manager, name);
+
+        // 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();
+
+        // References to database objects.
+        Statement statement = null;
+        ResultSet resultSet = null;
+        Connection connection = null;
+
+        try {
+
+            // Get a connection from the manager.
+            connection = ConnectionManager.createConnection();
+
+            // Get the name of the current database being used.
+            String database = ConnectionManager.getConnectionParameters().getDatabase();
+
+            String query = "SELECT ecal_channel_id FROM " 
+                    + database + "." + tableName + " WHERE " 
+                    + fieldName + " = " + fieldValue 
+                    + " ORDER BY id ASC";
+
+            // Execute the query and get the results.
+            statement = connection.createStatement();
+            resultSet = statement.executeQuery(query);
+
+            // Loop over the records.
+            while (resultSet.next()) {
+                int channelId = resultSet.getInt(1);
+                badChannels.add(channelId);
+            }
+        } catch (SQLException x) {
+            throw new RuntimeException("Database error.", x);
+        } finally {
+            // Cleanup the SQL statement.
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (Exception xx) {
+                }
+            }
+            // Cleanup the connection.
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (Exception x) {
+                }
+            }
+        }
+        return badChannels;
+    }
+
+    /**
+     * Get the type handled by this converter.
+     * 
+     * @return The type handled by this converter.
+     */
+    public Class<EcalBadChannelCollection> getType() {
+        return EcalBadChannelCollection.class;
+    }
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalCalibration.java added at 1.1
diff -N EcalCalibration.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalCalibration.java	1 Oct 2013 00:34:29 -0000	1.1
@@ -0,0 +1,53 @@
+package org.lcsim.hps.conditions.ecal;
+
+/**
+ * This class is a simplistic representation of ECal pedestal and noise
+ * values from the conditions database.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+class EcalCalibration {
+   
+    /** The database ID of the ecal channel. */
+    private int id;
+    
+    /** The pedestal value. */
+    private double pedestal;
+    
+    /** The noise value. */
+    private double noise;
+    
+    /**
+     * Fully qualified class constructor.
+     * @param id
+     * @param gain
+     */
+    EcalCalibration(int id, double pedestal, double noise) {
+        this.id = id;
+        this.pedestal = pedestal;
+        this.noise = noise;
+    }
+    
+    /**
+     * Get the database ID of the ecal channel.
+     * @return The database ID.
+     */
+    public int getId() {
+        return id;
+    }
+    
+    /**
+     * Get the pedestal value.
+     * @return The gain value.
+     */
+    public double getPedestal() {
+        return pedestal;
+    }       
+    
+    /**
+     * Get the noise value.
+     */
+    public double getNoise() {
+        return noise;
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalCalibrationCollection.java added at 1.1
diff -N EcalCalibrationCollection.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalCalibrationCollection.java	1 Oct 2013 00:34:29 -0000	1.1
@@ -0,0 +1,10 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.util.ArrayList;
+
+/**
+ * This class represents a list of {@link EcalCalibration} objects.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalCalibrationCollection extends ArrayList<EcalCalibration> {
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalCalibrationConverter.java added at 1.1
diff -N EcalCalibrationConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalCalibrationConverter.java	1 Oct 2013 00:34:29 -0000	1.1
@@ -0,0 +1,96 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+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 list of {@link EcalCalibration} objects from the conditions database.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalCalibrationConverter extends DatabaseConditionsConverter<EcalCalibrationCollection> {
+
+    /**
+     * Create the collection from the conditions database. 
+     * @param manager The conditions manager.
+     * @param name The name of the conditions set.
+     */
+    public EcalCalibrationCollection getData(ConditionsManager manager, String name) {
+
+        // Collection to be returned to caller.
+        EcalCalibrationCollection calibrations = new EcalCalibrationCollection();
+
+        // Get the ConditionsRecord with the meta-data, which will use the
+        // current run number from the manager.
+        ConditionsRecord record = ConditionsRecord.find(manager, name);
+
+        // 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();
+
+        // References to database objects.
+        Statement statement = null;
+        ResultSet resultSet = null;
+        Connection connection = null;
+
+        try {
+
+            // Get a connection from the manager.
+            connection = ConnectionManager.createConnection();
+
+            // Get the name of the current database being used.
+            String database = ConnectionManager.getConnectionParameters().getDatabase();
+
+            String query = "SELECT ecal_channel_id, pedestal, noise FROM " 
+                    + database + "." + tableName 
+                    + " WHERE " + fieldName + " = " + fieldValue 
+                    + " ORDER BY ecal_channel_id ASC";
+
+            // Execute the query and get the results.
+            statement = connection.createStatement();
+            resultSet = statement.executeQuery(query);
+
+            // Loop over the records.
+            while (resultSet.next()) {
+                int channelId = resultSet.getInt(1);
+                double pedestal = resultSet.getDouble(2);
+                double noise = resultSet.getDouble(3);
+                calibrations.add(new EcalCalibration(channelId, pedestal, noise));
+            }
+        } catch (SQLException x) {
+            throw new RuntimeException("Database error.", x);
+        } finally {
+            // Cleanup the SQL statement.
+            if (statement != null) {
+                try {
+                    statement.close();
+                } catch (Exception xx) {
+                }
+            }
+            // Cleanup the connection.
+            if (connection != null) {
+                try {
+                    connection.close();
+                } catch (Exception x) {
+                }
+            }
+        }
+        return calibrations;
+    }
+
+    /**
+     * Get the type handled by this converter.     
+     * @return The type handled by this converter.
+     */
+    public Class<EcalCalibrationCollection> getType() {
+        return EcalCalibrationCollection.class;
+    }
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalChannel.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalChannel.java	25 Sep 2013 22:36:52 -0000	1.2
+++ EcalChannel.java	1 Oct 2013 00:34:29 -0000	1.3
@@ -6,7 +6,8 @@
  * from the DAQ hardware; and the physical x and y values of the geometric crystal volumes. 
  * Each of these three pieces of data specifies a unique channel, so the information is in 
  * some sense redundant.  This class allows all these values to be associated by channel 
- * in the same place.
+ * in the same place.  The object references are used as keys into a {@link EcalChannelMap}
+ * in the {@link EcalConditions} object for getting channel data.
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalChannel {

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalConditions.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalConditions.java	25 Sep 2013 22:36:52 -0000	1.2
+++ EcalConditions.java	1 Oct 2013 00:34:29 -0000	1.3
@@ -6,17 +6,22 @@
 import java.util.Set;
 
 /**
- * This class allows accses to all ECal conditions from the database,
- * including gain, pedestal and bad channel settings per crystal. 
+ * This class provides access to all ECal conditions from the database,
+ * including gain, pedestal and bad channel settings, per crystal. 
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalConditions {
     
+    /** Channel map. */
     EcalChannelMap channels = new EcalChannelMap();
      
+    /**
+     * Data structures for retrieving conditions by channel.
+     */
     Map<EcalChannel, Double> gains = new HashMap<EcalChannel, Double>();
     Map<EcalChannel, Double> pedestals = new HashMap<EcalChannel, Double>();
+    Map<EcalChannel, Double> noises = new HashMap<EcalChannel, Double>();
     Set<EcalChannel> badChannels = new HashSet<EcalChannel>();
         
     /**
@@ -45,12 +50,21 @@
     }
     
     /**
+     * Get the noise by channel.
+     * @param channel The channel.
+     * @return The noise value for this channel
+     */
+    public Double getNoise(EcalChannel channel) {
+        return noises.get(channel);
+    }
+    
+    /**
      * Get whether or not the given channel is "bad" in some way, 
      * meaning it should not be used for reconstruction, etc.
      * @param channel The channel.
      * @return True if channel is bad; false if not.
      */
-    public boolean isDeadChannel(EcalChannel channel) {        
+    public boolean isBadChannel(EcalChannel channel) {        
         return badChannels.contains(channel);
     }
     
@@ -81,10 +95,19 @@
     } 
     
     /**
+     * Set the noise for the channel.
+     * @param channel The channel.
+     * @param noise The noise value.
+     */
+    void setNoise(EcalChannel channel, double noise) {
+        noises.put(channel, noise);
+    }
+    
+    /**
      * Flag a channel as bad.
      * @param channel The channel.
      */
-    void addDeadChannel(EcalChannel channel) {
+    void addBadChannel(EcalChannel channel) {
         badChannels.add(channel);
     }
     
@@ -106,9 +129,11 @@
             boolean badChannel = badChannels.contains(channel);
             Double gain = getGain(channel);
             Double pedestal = getPedestal(channel);
+            Double noise = getNoise(channel);
             buff.append(channel 
                     + ", gain: " + (gain == null ? "NONE" : gain)
                     + ", pedestal: " + (pedestal == null ? "NONE" : pedestal)
+                    + ", noise: " + (noise == null ? "NONE" : pedestal)
                     + ", badChannel: " + badChannel + '\n');
         }
         return buff.toString();

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalConditionsLoader.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalConditionsLoader.java	25 Sep 2013 22:36:52 -0000	1.2
+++ EcalConditionsLoader.java	1 Oct 2013 00:34:29 -0000	1.3
@@ -1,6 +1,8 @@
 package org.lcsim.hps.conditions.ecal;
 
 import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_GAINS;
+import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_BAD_CHANNELS;
+import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_CALIBRATIONS;
 
 import java.util.Map;
 
@@ -32,11 +34,27 @@
         // Set the channel map.
         conditions.setChannelMap(channelMap);
                                        
-        // Add gain data by channel to conditions object.
+        // Add gain data.
         EcalGainCollection gains = manager.getCachedConditions(EcalGainCollection.class, ECAL_GAINS).getCachedData();        
-        for (Map.Entry<Integer, EcalGain> entry : gains.entrySet()) {
-            conditions.setGain(channelMap.get(entry.getKey()), entry.getValue().getGain());
+        for (EcalGain gain : gains) {
+            conditions.setGain(channelMap.get(gain.getId()), gain.getGain());
         }
+        
+        // Add bad channels.
+        EcalBadChannelCollection badChannels = manager.getCachedConditions(
+                EcalBadChannelCollection.class, ECAL_BAD_CHANNELS).getCachedData();
+        for (Integer badChannel : badChannels) {
+            conditions.addBadChannel(channelMap.get(badChannel));
+        }
+        
+        // Add calibrations by channel including pedestal and noise.
+        EcalCalibrationCollection calibrations = 
+                manager.getCachedConditions(EcalCalibrationCollection.class, ECAL_CALIBRATIONS).getCachedData();
+        for (EcalCalibration calibration : calibrations) {
+            EcalChannel channel = channelMap.get(calibration.getId());
+            conditions.setPedestal(channel, calibration.getPedestal());
+            conditions.setNoise(channel, calibration.getNoise());
+        }       
     }
     
     /**

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalGainCollection.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalGainCollection.java	25 Sep 2013 22:36:52 -0000	1.2
+++ EcalGainCollection.java	1 Oct 2013 00:34:29 -0000	1.3
@@ -1,9 +1,9 @@
 package org.lcsim.hps.conditions.ecal;
 
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
 
 /**
  * This class maps integer IDs from the database to ECal gain parameters.
  */
-class EcalGainCollection extends LinkedHashMap<Integer,EcalGain> {
+class EcalGainCollection extends ArrayList<EcalGain> {
 }

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalGainConverter.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- EcalGainConverter.java	25 Sep 2013 22:36:52 -0000	1.2
+++ EcalGainConverter.java	1 Oct 2013 00:34:29 -0000	1.3
@@ -56,13 +56,10 @@
             resultSet = statement.executeQuery(query);
                 
             // Loop over the records.
-            while(resultSet.next()) {    
-                
+            while(resultSet.next()) {
                 int channelId = resultSet.getInt(1);
-                double gain = resultSet.getDouble(2);
-                
-                EcalGain channelGain = new EcalGain(channelId, gain);
-                gains.put(channelId, channelGain);
+                double gain = resultSet.getDouble(2);                
+                gains.add(new EcalGain(channelId, gain));
             }            
         } catch (SQLException x) {
             throw new RuntimeException("Database error.", x);
CVSspam 0.2.12


Use REPLY-ALL to reply to list

To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1