Commit in java/trunk/conditions/src/main/java/org/hps/conditions on MAIN
ConditionsObjectCollection.java+4315 -> 316
ConditionsTableRegistry.java+10-1315 -> 316
DatabaseConditionsConverter.java+1-2315 -> 316
ecal/EcalBadChannelConverter.java+4-8315 -> 316
    /EcalChannel.java+24-44315 -> 316
    /EcalChannelMap.java+34-12315 -> 316
    /EcalChannelMapConverter.java+23-17315 -> 316
    /EcalConditions.java+2-2315 -> 316
    /EcalConditionsConverter.java+10-5315 -> 316
    /EcalConditionsLoader.java+10-4315 -> 316
+122-95
10 modified files
Change EcalChannel condition to use new API.

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsObjectCollection.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -33,6 +33,10 @@
     public List<T> getObjects() {
         return Collections.unmodifiableList(objects);
     }
+    
+    public boolean contains(Object object) {
+        return getObjects().contains(object);
+    }
         
     public void add(T object) {
         if (objects.contains(object)) {

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsTableRegistry.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableRegistry.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableRegistry.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -90,13 +90,22 @@
         fields.add("gain");
         addTableMetaData(new ConditionsTableMetaData(ConditionsTableConstants.ECAL_GAINS, fields));
         
-        // Ecal calibrations
+        // ECal calibrations
         fields = new HashSet<String>();
         fields.add("ecal_channel_id");
         fields.add("noise");
         fields.add("pedestal");
         addTableMetaData(new ConditionsTableMetaData(ConditionsTableConstants.ECAL_CALIBRATIONS, fields));
         
+        // ECal channels
+        fields = new HashSet<String>();
+        fields.add("crate");
+        fields.add("slot");
+        fields.add("channel");
+        fields.add("x");
+        fields.add("y"); 
+        addTableMetaData(new ConditionsTableMetaData(ConditionsTableConstants.ECAL_CHANNELS, fields));
+        
         // Beam current
         fields = new HashSet<String>();
         fields.add("beam_current");

java/trunk/conditions/src/main/java/org/hps/conditions
DatabaseConditionsConverter.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsConverter.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsConverter.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -3,8 +3,7 @@
 import org.lcsim.conditions.ConditionsConverter;
 
 /**
- * This class is basically just a typedef right now but functionality may be added here
- * that all converters can use.
+ * The abstract base class for database conditions converters to extend.
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {   

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalBadChannelConverter.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalBadChannelConverter.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalBadChannelConverter.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -52,15 +52,11 @@
             
             // Loop over the records.
             try {
-                while (resultSet.next()) {
-                    
-                    int rowId = resultSet.getInt(1);
-                                        
+                while (resultSet.next()) {                    
+                    int rowId = resultSet.getInt(1);                                       
                     FieldValueMap fieldValues = new FieldValueMap();
-                    fieldValues.put("ecal_channel_id", resultSet.getInt(2));
-                    
-                    EcalBadChannel newObject = _objectFactory.createObject(EcalBadChannel.class, tableName, rowId, fieldValues, true);
-                    
+                    fieldValues.put("ecal_channel_id", resultSet.getInt(2));                    
+                    EcalBadChannel newObject = _objectFactory.createObject(EcalBadChannel.class, tableName, rowId, fieldValues, true);                    
                     collection.add(newObject);
                 }
             } catch (SQLException x) {

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalChannel.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -1,47 +1,26 @@
 package org.hps.conditions.ecal;
 
+import org.hps.conditions.AbstractConditionsObject;
+
 /**
  * This class encapsulates all the setup information about a single ECal channel, e.g. one crystal.
  * This includes the channel 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. 
+ * 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.  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 {
+public class EcalChannel extends AbstractConditionsObject {
     
-    /** 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;
-    }
-
-    /**
      * Get the crate number.
      * @return The crate number.
      */
     public int getCrate() {
-        return crate;
+        return getFieldValue("crate");
     }
     
     /**
@@ -49,7 +28,7 @@
      * @return The slot number.
      */
     public int getSlot() {
-        return slot;
+        return getFieldValue("slot");
     }
     
     /**
@@ -57,7 +36,7 @@
      * @return The channel number.
      */
     public int getChannel() {
-        return channel;
+        return getFieldValue("channel");
     }
     
     /**
@@ -65,7 +44,7 @@
      * @return The x value.
      */
     public int getX() {
-        return x;
+        return getFieldValue("x");
     }
     
     /**
@@ -73,7 +52,7 @@
      * @return The y value.
      */
     public int getY() {
-        return y;
+        return getFieldValue("y");
     }
 
     /**
@@ -81,7 +60,8 @@
      * @return The ID of the channel.
      */
     public int getId() {
-        return id;
+        // FIXME: Needs to be changed to channel ID reference.
+        return this.getRowId();
     }
     
     /**
@@ -99,12 +79,12 @@
             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;
+        return c.getId() == getId() 
+                && c.getCrate() == getCrate()
+                && c.getSlot() == getSlot()
+                && c.getChannel() == getChannel()
+                && c.getX() == getX()
+                && c.getY() == getY();
     }
     
     /**
@@ -112,11 +92,11 @@
      * @return The string representation of this channel data.
      */
     public String toString() {
-        return "id: " + id 
-                + ", crate: " + crate 
-                + ", slot: " + slot 
-                + ", channel: " + channel 
-                + ", x: " + x 
-                + ", y: " + y;
+        return "id: " + getId() 
+                + ", crate: " + getCrate() 
+                + ", slot: " + getSlot()
+                + ", channel: " + getChannel() 
+                + ", x: " + getX()
+                + ", y: " + getY();
     }
 }
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalChannelMap.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelMap.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelMap.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -1,14 +1,29 @@
 package org.hps.conditions.ecal;
 
-import java.util.HashMap;
+import org.hps.conditions.ConditionsObjectCollection;
 
 /**
  * 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 {@link EcalConditions} class.
  */
-public class EcalChannelMap extends HashMap<Integer, EcalChannel> {
+public class EcalChannelMap extends ConditionsObjectCollection<EcalChannel> {
     
+    public static final class DaqId {
+        public int crate;
+        public int slot;
+        public int channel;
+    }
+    
+    public static final class GeometryId {
+        public int x;
+        public int y;
+    }
+    
+    public static final class ChannelId {
+        public int id;
+    }
+    
     /**
      * Class constructor.
      */
@@ -22,11 +37,11 @@
      * @param channelNumber The channel number.
      * @return The matching channel or null if does not exist.
      */
-    public EcalChannel find(int crate, int slot, int channelNumber) {
-        for (EcalChannel channel : values()) {
-            if (channel.getCrate() == crate 
-                    && channel.getSlot() == slot 
-                    && channel.getChannel() == channelNumber) {
+    public EcalChannel findChannel(DaqId daqId) {
+        for (EcalChannel channel : getObjects()) {
+            if (channel.getCrate() == daqId.crate 
+                    && channel.getSlot() == daqId.slot 
+                    && channel.getChannel() == daqId.channel) {
                 return channel;
             }
         }
@@ -38,15 +53,22 @@
      * @param x The x value.
      * @param y The y value.
      * @return The matching channel or null if does not exist.
-     * 
-     * FIXME: Improve performance of this method from O(N).
      */
-    public EcalChannel find(int x, int y) {
-        for (EcalChannel channel : values()) {
-            if (channel.getX() == x && channel.getY()== y) {
+    public EcalChannel findChannel(GeometryId geometryId) {
+        for (EcalChannel channel : getObjects()) {
+            if (channel.getX() == geometryId.x && channel.getY() == geometryId.y) {
                 return channel;
             }
         }
         return null;
     }
+    
+    public EcalChannel findChannel(ChannelId channelId) {
+        for (EcalChannel channel : getObjects()) {
+            if (channel.getId() == channelId.id) {
+                return channel;
+            }
+        }
+        return null;
+    }
 }
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalChannelMapConverter.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelMapConverter.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelMapConverter.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -5,10 +5,12 @@
 import java.sql.ResultSet;
 import java.sql.SQLException;
 
-import org.lcsim.conditions.ConditionsManager;
+import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
+import org.hps.conditions.ConditionsObjectException;
 import org.hps.conditions.ConditionsObjectFactory;
 import org.hps.conditions.ConnectionManager;
 import org.hps.conditions.DatabaseConditionsConverter;
+import org.lcsim.conditions.ConditionsManager;
 
 /**
  * This class creates the {@link EcalChannelMap} from the conditions table
@@ -30,16 +32,17 @@
      */
     public EcalChannelMap getData(ConditionsManager manager, String name) {
 
-        // Collection to be returned to caller.
-        EcalChannelMap channels = new EcalChannelMap();
-
         // References to database objects.
         ResultSet resultSet = null;
         ConnectionManager connectionManager = getConnectionManager();
+        
+        // Collection to be returned to caller.
+        EcalChannelMap collection = new EcalChannelMap();
 
         // Assign default key name if none was given.
-        if (name == null)
-            name = ECAL_CHANNELS;
+        String tableName = name;
+        if (tableName == null)
+            tableName = ECAL_CHANNELS;
 
         // Query to retrieve channel data.
         String query = "SELECT id, x, y, crate, slot, channel FROM " + name;
@@ -50,21 +53,24 @@
         try {
             // Loop over the records.
             while (resultSet.next()) {
-                // Create channel data object from database record.
-                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);
+                
+                int rowId = resultSet.getInt(1);                                       
+                FieldValueMap fieldValues = new FieldValueMap();
+                fieldValues.put("x", resultSet.getInt(2));
+                fieldValues.put("y", resultSet.getInt(3));
+                fieldValues.put("crate", resultSet.getInt(4));
+                fieldValues.put("slot", resultSet.getInt(5));
+                fieldValues.put("channel", resultSet.getInt(6));                                
+                EcalChannel newObject = _objectFactory.createObject(EcalChannel.class, tableName, rowId, fieldValues, true);                    
+                collection.add(newObject);
             }
         } catch (SQLException x) {
             throw new RuntimeException("Database error.", x);
-        } 
+        } catch (ConditionsObjectException x) {
+            throw new RuntimeException("Error converting to " + getType().getSimpleName() + " type.", x);
+        }
         
-        return channels;
+        return collection;
     }
 
     /**

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConditions.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -49,7 +49,7 @@
      */
     public EcalChannelConstants getChannelConstants(EcalChannel channel) {
         // This channel must come from the map.
-        if (!channelMap.containsValue(channel)) {
+        if (!channelMap.contains(channel)) {
             System.err.println("Channel not found in map => " + channel);
             throw new IllegalArgumentException("Channel was not found in map.");
         }
@@ -98,7 +98,7 @@
         buff.append('\n');
         
         // Loop over all channels.
-        for (EcalChannel channel : channelMap.values()) {
+        for (EcalChannel channel : channelMap.getObjects()) {
             
             EcalChannelConstants constants = getChannelConstants(channel);
             

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConditionsConverter.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -5,10 +5,9 @@
 import static org.hps.conditions.ConditionsTableConstants.ECAL_CHANNELS;
 import static org.hps.conditions.ConditionsTableConstants.ECAL_GAINS;
 
-import java.util.Map.Entry;
-
 import org.hps.conditions.ConditionsObjectFactory;
 import org.hps.conditions.DatabaseConditionsConverter;
+import org.hps.conditions.ecal.EcalChannelMap.ChannelId;
 import org.lcsim.conditions.ConditionsManager;
 
 /**
@@ -39,7 +38,9 @@
         // Add gains.
         EcalGainCollection gains = manager.getCachedConditions(EcalGainCollection.class, ECAL_GAINS).getCachedData();        
         for (EcalGain gain : gains.getObjects()) {
-            EcalChannel channel = channelMap.get(gain.getChannelId());
+            ChannelId channelId = new ChannelId();
+            channelId.id = gain.getChannelId();
+            EcalChannel channel = channelMap.findChannel(channelId);
             conditions.getChannelConstants(channel).setGain(gain);
         }
         
@@ -47,7 +48,9 @@
         EcalBadChannelCollection badChannels = manager.getCachedConditions(
                 EcalBadChannelCollection.class, ECAL_BAD_CHANNELS).getCachedData();
         for (EcalBadChannel badChannel : badChannels.getObjects()) {
-            EcalChannel channel = channelMap.get(badChannel.getChannelId());
+            ChannelId channelId = new ChannelId();
+            channelId.id = badChannel.getChannelId();
+            EcalChannel channel = channelMap.findChannel(channelId);
             conditions.getChannelConstants(channel).setBadChannel(true);
         }
         
@@ -55,7 +58,9 @@
         EcalCalibrationCollection calibrations = 
                 manager.getCachedConditions(EcalCalibrationCollection.class, ECAL_CALIBRATIONS).getCachedData();
         for (EcalCalibration calibration : calibrations.getObjects()) {
-            EcalChannel channel = channelMap.get(calibration.getChannelId());
+            ChannelId channelId = new ChannelId();
+            channelId.id = calibration.getChannelId();
+            EcalChannel channel = channelMap.findChannel(channelId);
             conditions.getChannelConstants(channel).setCalibration(calibration);
         }       
         

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConditionsLoader.java 315 -> 316
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsLoader.java	2014-03-18 22:30:45 UTC (rev 315)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsLoader.java	2014-03-18 23:05:19 UTC (rev 316)
@@ -2,17 +2,18 @@
 
 import java.util.List;
 
+import org.hps.conditions.ecal.EcalChannelMap.GeometryId;
 import org.lcsim.detector.converter.compact.EcalCrystal;
 import org.lcsim.geometry.Detector;
 
 /**
- * Load {@link SvtConditions} data onto <code>HpsSiSensor</code> objects.
+ * Load {@link EcalConditions} data onto <code>EcalCrystal</code> objects.
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalConditionsLoader {
     
     /**
-     * Load ECal conditions data onto a detector object.
+     * Load ECal conditions data onto a full detector object.
      * @param detector The detector object.
      * @param conditions The conditions object.
      */
@@ -27,11 +28,16 @@
         // Loop over crystals.
         for (EcalCrystal crystal : crystals) {
             
+            //System.out.println(crystal.getName() + " @ " + crystal.getX() + ", " + crystal.getY());
+            
             // Reset possibly existing conditions data.
             crystal.reset();
             
             // Find the corresponding entry in the channel map for this crystal.
-            EcalChannel channel = channelMap.find(crystal.getX(), crystal.getY());
+            GeometryId geometryId = new GeometryId();
+            geometryId.x = crystal.getX();
+            geometryId.y = crystal.getY();
+            EcalChannel channel = channelMap.findChannel(geometryId);
             if (channel == null) {
                 throw new RuntimeException("EcalChannel not found for crystal: " + crystal.getName());
             }
@@ -48,7 +54,7 @@
             // Get the channel constants.
             EcalChannelConstants constants = conditions.getChannelConstants(channel);
             if (constants == null) {
-                throw new RuntimeException("EcalChannelConstants not found for crystal: " + crystal.getName());
+                throw new RuntimeException("EcalChannelConstants object not found for crystal: " + crystal.getName());
             }
                         
             // Set bad channel.
SVNspam 0.1