Commit in hps-java/src on MAIN
main/java/org/lcsim/hps/conditions/ConditionsConstants.java+21added 1.1
                                  /DatabaseConditionsReader.java+8-21.8 -> 1.9
main/java/org/lcsim/hps/conditions/ecal/EcalChannel.java+86added 1.1
                                       /EcalChannelConverter.java+78added 1.1
                                       /EcalChannelMap.java+12added 1.1
                                       /EcalConditions.java+69added 1.1
                                       /EcalConditionsLoader.java+37added 1.1
                                       /EcalGain.java+20added 1.1
                                       /EcalGainCollection.java+11added 1.1
                                       /EcalGainConverter.java+94added 1.1
main/java/org/lcsim/hps/conditions/svt/SvtConditionsLoader.java+10-141.2 -> 1.3
test/java/org/lcsim/hps/conditions/ecal/EcalConditionsLoaderTest.java+43added 1.1
+489-16
10 added + 2 modified, total 12 files
checkpointing work on reading ecal conditions from db

hps-java/src/main/java/org/lcsim/hps/conditions
ConditionsConstants.java added at 1.1
diff -N ConditionsConstants.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ConditionsConstants.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,21 @@
+package org.lcsim.hps.conditions;
+
+/**
+ * Constants for HPS conditions system, such as conditions set key names.
+ */
+public final class ConditionsConstants {
+    
+    private ConditionsConstants() {}
+
+    /** Table with ECal channel data. */
+    public static final String ECAL_CHANNELS = "ecal_channels";
+
+    /** Conditions key for ECal gain data. */
+    public static final String ECAL_GAINS = "ecal_gains";
+    
+    /** Table with SVT channel data. */
+    public static final String SVT_CHANNELS = "svt_channels";
+        
+    /** Conditions key for SVT calibration data. */ 
+    public static final String SVT_CALIBRATIONS = "svt_calibrations";
+}

hps-java/src/main/java/org/lcsim/hps/conditions
DatabaseConditionsReader.java 1.8 -> 1.9
diff -u -r1.8 -r1.9
--- DatabaseConditionsReader.java	24 Sep 2013 02:51:35 -0000	1.8
+++ DatabaseConditionsReader.java	25 Sep 2013 22:14:24 -0000	1.9
@@ -12,6 +12,8 @@
 
 import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.conditions.ConditionsReader;
+import org.lcsim.hps.conditions.ecal.EcalChannelConverter;
+import org.lcsim.hps.conditions.ecal.EcalGainConverter;
 import org.lcsim.hps.conditions.svt.SvtCalibrationConverter;
 
 /**
@@ -32,7 +34,7 @@
  * currently of an actual HPS sub-system, but more will be added as they are created.
  * 
  * @author jeremym
- * @version $Id: DatabaseConditionsReader.java,v 1.8 2013/09/24 02:51:35 jeremy Exp $ 
+ * @version $Id: DatabaseConditionsReader.java,v 1.9 2013/09/25 22:14:24 jeremy Exp $ 
  */
 public class DatabaseConditionsReader extends ConditionsReader {
         
@@ -191,9 +193,13 @@
      * Register the default conditions converters.
      * @param manager The ConditionsManager.
      */
-    private void registerConditionsConverters(ConditionsManager manager) {        
+    private void registerConditionsConverters(ConditionsManager manager) {
         manager.registerConditionsConverter(new ConditionsRecordConverter());
         manager.registerConditionsConverter(new SvtCalibrationConverter());
+        manager.registerConditionsConverter(new EcalChannelConverter());
+        manager.registerConditionsConverter(new EcalGainConverter());
+        //
         // TODO: Add other converters here as they are made available.
+        //
     }
 }

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalChannel.java added at 1.1
diff -N EcalChannel.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalChannel.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,86 @@
+package org.lcsim.hps.conditions.ecal;
+
+/**
+ * This class encapsulates all the information about a single ECal channel, e.g. one crystal.
+ * This includes the ID from the conditions database; the crate, slot, and channel numbers
+ * from the DAQ hardware; and the physical x and y values of the geometric crystal volumes. 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class EcalChannel {
+    
+    /** Channel info. */
+    int id, crate, slot, channel, x, y;
+    
+    /**
+     * Identifying information for an ECal channel.  This is over-specified in 
+     * that crate-slot-channel, x-y, and id all uniquely identify the 
+     * channel by themselves.  But we add them all here to have the information 
+     * in one place.
+     * @param id The database ID of the channel.
+     * @param crate The crate number (1 or 2).
+     * @param slot The slot number.
+     * @param channel The channel number.
+     * @param x The x value of the channel.
+     * @param y The y value of the channel.
+     */
+    EcalChannel(int id, int crate, int slot, int channel, int x, int y) {
+        this.id = id;
+        this.crate = crate;
+        this.slot = slot;
+        this.channel = channel;
+        this.x = x;
+        this.y = y;
+    }
+
+    public int getCrate() {
+        return crate;
+    }
+    
+    public int getSlot() {
+        return slot;
+    }
+    
+    public int getChannel() {
+        return channel;
+    }
+    
+    public int getX() {
+        return x;
+    }
+    
+    public int getY() {
+        return y;
+    }
+
+    public int getId() {
+        return id;
+    }
+    
+    public boolean equals(Object o) {
+        if (o == null) {
+            return false;
+        }
+        if (!(o instanceof EcalChannel)) {
+            return false;
+        }
+        if (o.equals(this)) {
+            return true;
+        }
+        EcalChannel c = (EcalChannel)o;
+        return c.getId() == id 
+                && c.getCrate() == crate 
+                && c.getSlot() == slot 
+                && c.getChannel() == channel
+                && c.getX() == x
+                && c.getY() == y;
+    }
+    
+    public String toString() {
+        return "id: " + id 
+                + ", crate: " + crate 
+                + ", slot: " + slot 
+                + ", channel: " + channel 
+                + ", x: " + x 
+                + ", y: " + y;
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalChannelConverter.java added at 1.1
diff -N EcalChannelConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalChannelConverter.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,78 @@
+package org.lcsim.hps.conditions.ecal;
+
+import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_CHANNELS;
+
+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.ConnectionManager;
+import org.lcsim.hps.conditions.DatabaseConditionsConverter;
+
+public class EcalChannelConverter extends DatabaseConditionsConverter<EcalChannelMap> {
+
+     public EcalChannelMap getData(ConditionsManager manager, String name) {
+                  
+         // Collection to be returned to caller.
+         EcalChannelMap channels = new EcalChannelMap();
+                          
+         // 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 id, x, y, crate, slot, channel FROM "  
+                     + database + "." + ECAL_CHANNELS;
+                                      
+             // Execute the query and get the results.
+             statement = connection.createStatement();
+             resultSet = statement.executeQuery(query);
+                 
+             // Loop over the records.
+             while(resultSet.next()) {    
+                 
+                 int id = resultSet.getInt(1);
+                 int x = resultSet.getInt(2);
+                 int y = resultSet.getInt(3);
+                 int crate = resultSet.getInt(4);
+                 int slot = resultSet.getInt(5);
+                 int channel = resultSet.getInt(6);
+                 
+                 EcalChannel channelData = new EcalChannel(id, crate, slot, channel, x, y);
+                 channels.put(channelData.getId(), channelData);
+             }            
+         } 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 channels;
+    }
+
+    public Class<EcalChannelMap> getType() {
+        return EcalChannelMap.class;
+    }
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalChannelMap.java added at 1.1
diff -N EcalChannelMap.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalChannelMap.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,12 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.util.HashMap;
+
+/**
+ * This class maps ID values from the database to detailed ECal channel information.
+ * There should really only be one of these data structures per job, as the EcalChannel 
+ * objects are used as unique identifiers in the EcalConditions class.
+ */
+public class EcalChannelMap extends HashMap<Integer, EcalChannel> {
+    EcalChannelMap() {}
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalConditions.java added at 1.1
diff -N EcalConditions.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalConditions.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,69 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.io.PrintStream;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class EcalConditions {
+    
+    EcalChannelMap channels = new EcalChannelMap();
+     
+    Map<EcalChannel, Double> gains = new HashMap<EcalChannel, Double>();
+    Map<EcalChannel, Double> pedestals = new HashMap<EcalChannel, Double>();
+    Set<EcalChannel> badChannels = new HashSet<EcalChannel>();
+    
+    PrintStream ps = System.out;
+    
+    /**
+     * Class constructor, which is package protected.
+     */
+    EcalConditions() {        
+    }
+    
+    public Double getGain(EcalChannel channel) {
+        return gains.get(channel);
+    } 
+    
+    public Double getPedestal(EcalChannel channel) {
+        return pedestals.get(channel);
+    }
+    
+    public boolean isDeadChannel(EcalChannel channel) {        
+        return badChannels.contains(channel);
+    }
+    
+    public EcalChannelMap getChannelMap() {
+        return channels;
+    }
+    
+    void setGain(EcalChannel channel, double gain) {
+        gains.put(channel, gain);
+    }
+    
+    void setPedestal(EcalChannel channel, double pedestal) {
+        pedestals.put(channel, pedestal);
+    } 
+    
+    void addDeadChannel(EcalChannel channel) {
+        badChannels.add(channel);
+    }
+    
+    void setChannelMap(EcalChannelMap channels) {
+        this.channels = channels;
+    }
+    
+    public String toString() {
+        StringBuffer buff = new StringBuffer();
+        for (EcalChannel channel : channels.values()) {
+            boolean badChannel = badChannels.contains(channel);
+            Double gain = getGain(channel);
+            Double pedestal = getPedestal(channel);
+            ps.println(channel + ", gain: " + (gain == null ? "NONE" : gain)
+                    + ", pedestal: " + (pedestal == null ? "NONE" : pedestal)
+                    + ", badChannel: " + badChannel);
+        }
+        return buff.toString();
+    }
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalConditionsLoader.java added at 1.1
diff -N EcalConditionsLoader.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalConditionsLoader.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,37 @@
+package org.lcsim.hps.conditions.ecal;
+
+import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_GAINS;
+
+import java.util.Map;
+
+import org.lcsim.conditions.ConditionsManager;
+
+public class EcalConditionsLoader {
+    
+    private EcalConditions conditions = null;
+    
+    public void load() {
+        
+        // Reset conditions object.
+        conditions = new EcalConditions();
+        
+        // Get the default conditions manager.  This needs to be setup beforehand with the detector.        
+        ConditionsManager manager = ConditionsManager.defaultInstance();
+                               
+        // Get the channel information from the database.                
+        EcalChannelMap channelMap = manager.getCachedConditions(EcalChannelMap.class, null).getCachedData();
+        
+        // Set the channel map.
+        conditions.setChannelMap(channelMap);
+                                       
+        // Add gain data by channel to conditions object.
+        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());
+        }
+    }
+    
+    public EcalConditions getEcalConditions() {
+        return conditions;
+    }
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalGain.java added at 1.1
diff -N EcalGain.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalGain.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,20 @@
+package org.lcsim.hps.conditions.ecal;
+
+public class EcalGain {
+    
+    private int id;
+    private double gain;
+    
+    public EcalGain(int id, double gain) {
+        this.id = id;
+        this.gain = gain;
+    }
+    
+    public int getId() {
+        return id;
+    }
+    
+    public double getGain() {
+        return gain;
+    }       
+}
\ No newline at end of file

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalGainCollection.java added at 1.1
diff -N EcalGainCollection.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalGainCollection.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,11 @@
+package org.lcsim.hps.conditions.ecal;
+
+import java.util.LinkedHashMap;
+
+/**
+ * This class maps integer IDs from the database to ECal gain parameters.
+ * The EcalChannelMap data structure can be used to retrieve the channel
+ * data from the ID.
+ */
+public class EcalGainCollection extends LinkedHashMap<Integer,EcalGain> {
+}

hps-java/src/main/java/org/lcsim/hps/conditions/ecal
EcalGainConverter.java added at 1.1
diff -N EcalGainConverter.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalGainConverter.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,94 @@
+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;
+
+public class EcalGainConverter extends DatabaseConditionsConverter<EcalGainCollection> {
+    
+    public EcalGainCollection getData(ConditionsManager manager, String name) {
+        
+        // Collection to be returned to caller.
+        EcalGainCollection gains = new EcalGainCollection();
+        
+        // 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, crate, slot, channel, gain FROM "  
+                    + database + "." + tableName + ", " 
+                    + database + "." + ECAL_CHANNELS 
+                    + "WHERE " + fieldName + " = " + fieldValue 
+                    + " AND " + tableName + ".ecal_channel_id = ecal_channels.id " 
+                    + " ORDER BY " + ECAL_CHANNELS + ".id ASC";
+                    */
+            String query = "SELECT ecal_channel_id, gain FROM "  
+                    + database + "." + tableName   
+                    + " WHERE " + fieldName + " = " + fieldValue  
+                    + " ORDER BY id ASC";
+            
+            //System.out.println(query);
+                        
+            // 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 gain = resultSet.getDouble(2);
+                
+                EcalGain channelGain = new EcalGain(channelId, gain);
+                gains.put(channelId, channelGain);
+            }            
+        } 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 gains;
+    }
+
+    public Class<EcalGainCollection> getType() {
+        return EcalGainCollection.class;
+    }
+
+}

hps-java/src/main/java/org/lcsim/hps/conditions/svt
SvtConditionsLoader.java 1.2 -> 1.3
diff -u -r1.2 -r1.3
--- SvtConditionsLoader.java	24 Sep 2013 02:51:35 -0000	1.2
+++ SvtConditionsLoader.java	25 Sep 2013 22:14:24 -0000	1.3
@@ -8,20 +8,16 @@
 import org.lcsim.hps.recon.tracking.SvtUtils;
 import org.lcsim.hps.util.Pair;
 
+import static org.lcsim.hps.conditions.ConditionsConstants.SVT_CALIBRATIONS;
+
 /**
- * @author Jeremy McCormick <[log in to unmask]>
+ * 
  */
 public class SvtConditionsLoader {
-    
-    SvtConditions conditions = null;
-    
-    /** 
-     * The name of the conditions to retrieve.  
-     * This is not necessarily the same as the database table name. 
-     */
-    private static final String CALIBRATIONS = "svt_calibrations";
         
-    void load() {
+    private SvtConditions conditions = null;
+              
+    public void load() {
                         
         // Get the default conditions manager.  This needs to be setup beforehand with the detector.        
         ConditionsManager manager = ConditionsManager.defaultInstance();
@@ -31,7 +27,7 @@
                        
         // Get the SVT calibrations from the database.
         CachedConditions<ChannelConstantsCollection> c = 
-                manager.getCachedConditions(ChannelConstantsCollection.class, CALIBRATIONS);
+                manager.getCachedConditions(ChannelConstantsCollection.class, SVT_CALIBRATIONS);
         ChannelConstantsCollection channelData = c.getCachedData();
         
         // Get SvtUtils reference.
@@ -52,15 +48,15 @@
                 throw new RuntimeException("SiSensor not found for fpga <" + channel.getFpga() + "> and hybrid <" + channel.getHybrid() + "> !");
             }
             
-            // Set the noise value.
+            // Set the noise value for the channel.
             conditions.setNoise(sensor, channel.getChannel(), channel.getNoise());
             
-            // Set the pedestal value.
+            // Set the pedestal value for the channel.
             conditions.setPedestal(sensor, channel.getChannel(), channel.getPedestal());
         }                         
     }
     
-    SvtConditions getSvtConditions() {
+    public SvtConditions getSvtConditions() {
         return conditions;
     }
 }

hps-java/src/test/java/org/lcsim/hps/conditions/ecal
EcalConditionsLoaderTest.java added at 1.1
diff -N EcalConditionsLoaderTest.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ EcalConditionsLoaderTest.java	25 Sep 2013 22:14:24 -0000	1.1
@@ -0,0 +1,43 @@
+package org.lcsim.hps.conditions.ecal;
+
+import junit.framework.TestCase;
+
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+import org.lcsim.geometry.Detector;
+import org.lcsim.hps.recon.tracking.SvtUtils;
+import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
+
+public class EcalConditionsLoaderTest 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;
+        
+    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);
+        }
+        
+        // Now we need to setup the Detector for the conditions loader.
+        Detector detector =
+                manager.getCachedConditions(Detector.class, "compact.xml").getCachedData();
+        SvtUtils.getInstance().setup(detector);
+                                
+        // Test that the loader returns valid conditions.
+        EcalConditionsLoader loader = new EcalConditionsLoader();
+        loader.load();
+        EcalConditions conditions = loader.getEcalConditions();
+        assertNotNull(conditions);
+        System.out.println(conditions);
+        System.out.println("ECal conditions loaded successfully.");
+    }    
+}
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