Print

Print


Commit in java/trunk/conditions on MAIN
pom.xml+1-1335 -> 336
src/main/java/org/hps/conditions/AbstractConditionsObject.java+54-135335 -> 336
                                /ConditionsDriver.java+2-2335 -> 336
                                /ConditionsObject.java+19-15335 -> 336
                                /ConditionsObjectCollection.java+17-8335 -> 336
                                /ConditionsObjectConverter.java+17-9335 -> 336
                                /ConditionsObjectException.java+2-2335 -> 336
                                /ConditionsRecord.java+1-1335 -> 336
                                /ConditionsTableConstants.java-57335 removed
                                /ConditionsTableMetaData.java-53335 removed
                                /ConditionsTableMetaDataXMLLoader.java-99335 removed
                                /ConnectionManager.java+21-36335 -> 336
                                /ConnectionParameters.java+28-26335 -> 336
                                /ConverterXMLLoader.java-45335 removed
                                /DatabaseConditionsManager.java+316-45335 -> 336
                                /QueryBuilder.java+35-6335 -> 336
                                /TestRunConditionsReader.java+4-4335 -> 336
src/main/java/org/hps/conditions/ecal/EcalBadChannel.java+4335 -> 336
                                     /EcalCalibration.java+7-2335 -> 336
                                     /EcalChannel.java+32-13335 -> 336
                                     /EcalChannelConstants.java+1-3335 -> 336
                                     /EcalConditions.java+3-2335 -> 336
                                     /EcalConditionsConverter.java+4-6335 -> 336
                                     /EcalConverterRegistry.java+4-1335 -> 336
                                     /EcalGain.java+3-3335 -> 336
                                     /package-info.java+21added 336
src/main/java/org/hps/conditions/package-info.java-6335 -> 336
src/main/java/org/hps/conditions/svt/SvtChannel.java+6-1335 -> 336
                                    /SvtConditionsConverter.java+7-7335 -> 336
                                    /SvtTimeShift.java+6-1335 -> 336
src/test/java/org/hps/conditions/ConditionsObjectTest.java+96added 336
                                /DatabaseConditionsManagerTest.java+2-2335 -> 336
src/test/java/org/hps/conditions/beam/BeamCurrentTest.java+1-1335 -> 336
src/test/java/org/hps/conditions/ecal/EcalConditionsConverterTest.java+1-1335 -> 336
+715-593
2 added + 4 removed + 28 modified, total 34 files
More conditions system updates.  This includes full implementation of select, update, insert and delete operations on ConditionsObjects along with a test case (currently excluded from build because it uses a local test database).  Also some class renaming and addition of documentation.

java/trunk/conditions
pom.xml 335 -> 336
--- java/trunk/conditions/pom.xml	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/pom.xml	2014-03-22 00:23:31 UTC (rev 336)
@@ -27,7 +27,7 @@
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
                     <excludes>
-                        <exclude>org/hps/conditions/ConditionsDatabaseObjectTest.java</exclude>
+                        <exclude>org/hps/conditions/ConditionsObjectTest.java</exclude>
                     </excludes>
                 </configuration>
             </plugin>

java/trunk/conditions/src/main/java/org/hps/conditions
AbstractConditionsObject.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsObject.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsObject.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -3,8 +3,6 @@
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
 
 /**
  * The abstract implementation of {@link ConditionsObject}.
@@ -13,88 +11,21 @@
 // FIXME: Database query methods need to be rewritten to use QueryBuilder (which itself needs to be written).
 public abstract class AbstractConditionsObject implements ConditionsObject {
 
-    private ConnectionManager _connectionManager = null;
-    private ConditionsTableMetaData _tableMetaData = null;
+    private TableMetaData _tableMetaData = null;
     protected int _rowId = -1;
     protected int _collectionId = -1;
     protected boolean _isDirty = false;
     protected boolean _isReadOnly = false;
-    protected FieldValueMap _fieldValues = null;
-    
-    /**
-     * Class that maps field names to values.
-     */
-    public static final class FieldValueMap extends LinkedHashMap<String, Object> {
-    }      
-    
-    /**
-     * Constructor for sub-classing with no arguments.
-     */
-    protected AbstractConditionsObject() {}
-    
-    /**
-     * Constructor for a new object which cannot initially be read only as it must be inserted.
-     * @param tableMetaData
-     * @param fieldValues
-     * @param collectionId
-     * @param isReadOnly
-     */
-    // FIXME: This can maybe be removed.
-    public AbstractConditionsObject(
-            ConnectionManager connectionManager,
-            ConditionsTableMetaData tableMetaData,  
-            int collectionId,
-            FieldValueMap fieldValues) {
+    protected FieldValueMap _fieldValues;
         
-        if (connectionManager == null) {
-            throw new IllegalArgumentException("The connectionManager is null.");
-        }
-        if (tableMetaData == null) {
-            throw new IllegalArgumentException("The tableMetaData is null");
-        }
-        if (collectionId <= 0) {
-            throw new IllegalArgumentException("The set ID value is invalid: " + collectionId);
-        }        
-        _connectionManager = connectionManager;
-        _tableMetaData = tableMetaData;
-        _collectionId = collectionId;
-        _rowId = -1;
-        if (fieldValues != null) {
-            _fieldValues = fieldValues;
-        } else {
-            _fieldValues = new FieldValueMap();
-        }
-    }
-    
     /**
-     * Constructor for loading data from an existing object with a row ID.
-     * @param tableMetaData
-     * @param rowId
-     * @param isReadOnly
+     * Constructor for sub-classing.
      */
-    // FIXME: This can maybe be removed.
-    public AbstractConditionsObject(
-            ConnectionManager connectionManager,
-            ConditionsTableMetaData tableMetaData,
-            int rowId,
-            boolean isReadOnly) {
-        if (connectionManager == null) {
-            throw new IllegalArgumentException("The connectionManager cannot be null!");
-        }
-        if (tableMetaData == null) {
-            throw new IllegalArgumentException("The tableMetaData cannot be null");
-        }
-        if (rowId <= 0) {
-            throw new IllegalArgumentException("Invalid row ID: " + rowId);
-        }
-        _connectionManager = connectionManager;
-        _tableMetaData = tableMetaData;
-        _rowId = rowId;
-        _isReadOnly = isReadOnly;
+    protected AbstractConditionsObject() {     
         _fieldValues = new FieldValueMap();
     }
-    
-    public ConditionsTableMetaData getTableMetaData() {
+        
+    public TableMetaData getTableMetaData() {
         return _tableMetaData;
     }
     
@@ -122,75 +53,69 @@
         if (isReadOnly()) {
             throw new ConditionsObjectException("This object is set to read only.");
         }
-        String query = "DELETE FROM " + _tableMetaData.getTableName() + " WHERE id = " + _rowId;
-        _connectionManager.update(query);
+        if (isNew()) {
+            throw new ConditionsObjectException("This object is not in the database and cannot be deleted.");
+        }
+        String query = QueryBuilder.buildDelete(_tableMetaData.getTableName(), _rowId);
+        ConnectionManager.getConnectionManager().update(query);
+        // TODO: Need to check here if delete was successful!
         _rowId = -1;
     }
     
-    public void insert() throws ConditionsObjectException, SQLException {
+    public void insert() throws ConditionsObjectException {
         if (!isNew())
-            throw new ConditionsObjectException("Record already exists in database.");        
+            throw new ConditionsObjectException("Record already exists in database and cannot be inserted.");
         if (isReadOnly())
-            throw new ConditionsObjectException("This object is set to read only mode.");        
+            throw new ConditionsObjectException("This object is set to read only mode.");
         if (_fieldValues.size() == 0) 
-            throw new ConditionsObjectException("There are no field values to insert.");             
+            throw new ConditionsObjectException("There are no field values to insert.");
         if (!hasValidCollection())
-            throw new ConditionsObjectException("The object's collection ID is not valid");
-        StringBuffer buff = new StringBuffer();
-        buff.append("INSERT INTO " + _tableMetaData.getTableName() + "( set_id");
-        for (Entry<String, Object> entry : _fieldValues.entrySet()) {
-            buff.append(", " + entry.getKey());
-        }
-        buff.append(" ) VALUES ( ");
-        buff.append(_collectionId);
-        for (Entry<String, Object> entry : _fieldValues.entrySet()) {
-            buff.append(", " + entry.getValue());
-        } 
-        buff.append(") ");       
-        int key = _connectionManager.update(buff.toString());        
-        _rowId = key;        
+            throw new ConditionsObjectException("The object's collection ID is not valid.");
+        String query = QueryBuilder.buildInsert(getTableMetaData().getTableName(), 
+                getCollectionId(),
+                getTableMetaData().getFieldNames(),
+                _fieldValues.valuesToArray());
+        int key = ConnectionManager.getConnectionManager().update(query);
+        // TODO: Need to check here that insert was succcessful!
+        _rowId = key;
     }
 
-    public void select() throws ConditionsObjectException, SQLException {
+    public void select() throws ConditionsObjectException {
         if (isNew()) {
-            throw new ConditionsObjectException("Record has not been inserted into database yet.");
+            throw new ConditionsObjectException("Record has not been inserted into the database yet.");
         } 
-        StringBuffer buff = new StringBuffer();
-        buff.append("SELECT ");
-        for (String fieldName : _tableMetaData.getFieldNames()) {
-            buff.append(fieldName + ", ");
+        String query = QueryBuilder.buildSelect(
+                getTableMetaData().getTableName(), _collectionId, _fieldValues.fieldsToArray(), "id ASC");
+        ResultSet resultSet = ConnectionManager.getConnectionManager().query(query);  
+        try {
+            ResultSetMetaData metadata = resultSet.getMetaData();
+            int ncolumns = metadata.getColumnCount();
+            if (resultSet.next()) {        
+                for (int i=1; i<=ncolumns; i++) {
+                    _fieldValues.put(metadata.getColumnName(i), resultSet.getObject(i));
+                }
+            }    
+        } catch (SQLException e) {
+            throw new ConditionsObjectException(e.getMessage(), this);
         }
-        buff.delete(buff.length()-2, buff.length()-1);
-        buff.append(" FROM " + _tableMetaData.getTableName());        
-        buff.append(" WHERE id = " + _rowId);
-        ResultSet resultSet = _connectionManager.query(buff.toString());        
-        ResultSetMetaData metadata = resultSet.getMetaData();
-        int ncolumns = metadata.getColumnCount();
-        if (resultSet.next()) {        
-            for (int i=1; i<=ncolumns; i++) {
-                _fieldValues.put(metadata.getColumnName(i), resultSet.getObject(i));
-            }
-        }        
     }
         
     public void update() throws ConditionsObjectException {
         if (isReadOnly()) {
-            throw new ConditionsObjectException("This object is set to read only.");
+            throw new ConditionsObjectException("This object is set to read only.", this);
         }
         if (isNew()) {
-            throw new ConditionsObjectException("Cannot call update on new record.");
+            throw new ConditionsObjectException("Cannot call update on a new record.", this);
         }
         if (_fieldValues.size() == 0) {
-            throw new ConditionsObjectException("No field values to update.");
+            throw new ConditionsObjectException("No field values to update.", this);
         }
-        StringBuffer buff = new StringBuffer();
-        buff.append("UPDATE " + _tableMetaData.getTableName() + " SET ");
-        for (Entry<String, Object> entry : _fieldValues.entrySet()) {
-            buff.append(entry.getKey() + " = '" + entry.getValue() + "', ");
-        }
-        buff.delete(buff.length()-2, buff.length()-1);
-        buff.append(" WHERE id = " + _rowId); 
-        _connectionManager.update(buff.toString());
+        String query = QueryBuilder.buildUpdate(
+                _tableMetaData.getTableName(), 
+                _rowId, 
+                _fieldValues.fieldsToArray(), 
+                _fieldValues.valuesToArray());
+        ConnectionManager.getConnectionManager().update(query);
         setIsDirty(false);
     }
     
@@ -207,7 +132,7 @@
     }
     
     public <T> T getFieldValue(Class<T> klass, String field) {
-        return klass.cast(_fieldValues.get(field));
+        return klass.cast(_fieldValues.get(field)); 
     }
     
     @SuppressWarnings("unchecked")
@@ -215,21 +140,15 @@
         return (T)_fieldValues.get(field);
     }
 
-    public void setConnectionManager(ConnectionManager connectionManager) throws ConditionsObjectException {
-        if (_connectionManager != null)
-            throw new ConditionsObjectException("The connection manager cannot be reset.");
-        _connectionManager = connectionManager;        
-    }
-
-    public void setTableMetaData(ConditionsTableMetaData tableMetaData) throws ConditionsObjectException {
+    public void setTableMetaData(TableMetaData tableMetaData) throws ConditionsObjectException {
         if (_tableMetaData != null) 
-            throw new ConditionsObjectException("The table meta data cannot be reset.");
+            throw new ConditionsObjectException("The table meta data cannot be reset on an object.", this);
         _tableMetaData = tableMetaData;
     }
 
     public void setCollectionId(int collectionId) throws ConditionsObjectException {
         if (_collectionId != -1)
-            throw new ConditionsObjectException("The collection ID cannot be reassigned.");
+            throw new ConditionsObjectException("The collection ID cannot be reassigned once set.", this);
         _collectionId = collectionId;
     }
         
@@ -243,11 +162,11 @@
     
     public void setRowId(int rowId) throws ConditionsObjectException {
         if (_rowId != -1)
-            throw new ConditionsObjectException("The row ID cannot be reassigned.");
+            throw new ConditionsObjectException("The row ID cannot be reassigned on an existing object.");
         _rowId = rowId;
     }
     
     private boolean hasValidCollection() {
         return _collectionId != -1;
-    }
+    }    
 }
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsDriver.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -8,8 +8,8 @@
 import org.hps.conditions.svt.SvtConditionsLoader;
 import org.lcsim.util.Driver;
 
-import static org.hps.conditions.ConditionsTableConstants.SVT_CONDITIONS;
-import static org.hps.conditions.ConditionsTableConstants.ECAL_CONDITIONS;
+import static org.hps.conditions.TableConstants.SVT_CONDITIONS;
+import static org.hps.conditions.TableConstants.ECAL_CONDITIONS;
 
 /**
  * This {@link org.lcsim.util.Driver} loads conditions onto an HPS detector.

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsObject.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObject.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObject.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,9 +1,7 @@
 package org.hps.conditions;
 
-import java.sql.SQLException;
+import java.util.LinkedHashMap;
 
-import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
-
 /**
  * This is an ORM interface for accessing conditions database information by row.
  * It can handle new or existing records.  The ID values for new records are -1
@@ -16,7 +14,7 @@
      * Get the database table meta data associated to this object.
      * @return The database table meta data associated to this object.
      */
-    ConditionsTableMetaData getTableMetaData();
+    TableMetaData getTableMetaData();
     
     /**
      * Get the row ID of this object.
@@ -43,12 +41,12 @@
     /**
      * Insert this object into the database using a SQL INSERT statement.     
      */
-    void insert() throws ConditionsObjectException, SQLException;
+    void insert() throws ConditionsObjectException;
     
     /**
      * Select data into this object from the database using a SQL SELECT statement.     
      */
-    void select() throws ConditionsObjectException, SQLException;
+    void select() throws ConditionsObjectException;
     
     /**
      * Return true if this object is read-only.
@@ -97,20 +95,12 @@
     public <T> T getFieldValue(String field);
     
     /**
-     * Set the ConnectionManager of this object.
-     * This cannot be reset once set.
-     * @param connectionManager The ConnectionManager.
-     * @throws ConditionsObjectException if already set
-     */
-    void setConnectionManager(ConnectionManager connectionManager) throws ConditionsObjectException ;
-
-    /**
      * Set the ConditionsTableMetaData of this object.
      * This cannot be reset once set.
      * @param tableMetaData The ConditionsTableMetaData.
      * @throws ConditionsObjectException if already set
      */
-    void setTableMetaData(ConditionsTableMetaData tableMetaData) throws ConditionsObjectException;
+    void setTableMetaData(TableMetaData tableMetaData) throws ConditionsObjectException;
     
     /**
      * Set the collection ID of this object.
@@ -132,4 +122,18 @@
      * Set the object to read only mode.  This cannot be changed back once it is set.
      */
     void setIsReadOnly();    
+    
+    /**
+     * Simple class extending <code>java.lang.Map</code> that maps field names to values.
+     */
+    public static final class FieldValueMap extends LinkedHashMap<String, Object> {       
+        
+        Object[] valuesToArray() {
+            return values().toArray();
+        }
+        
+        String[] fieldsToArray() {
+            return keySet().toArray(new String[] {});
+        }
+    }      
 }

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsObjectCollection.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectCollection.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -8,7 +8,7 @@
 public class ConditionsObjectCollection<T extends ConditionsObject> {
 
     List<T> objects = new ArrayList<T>();    
-    ConditionsTableMetaData _tableMetaData;
+    TableMetaData _tableMetaData;
     int _collectionId = -1;
     boolean _isReadOnly;
     boolean _isDirty;
@@ -16,8 +16,8 @@
     
     protected ConditionsObjectCollection() {
     }
-    
-    public ConditionsObjectCollection(ConditionsTableMetaData tableMetaData, int collectionId, boolean isReadOnly) {
+            
+    public ConditionsObjectCollection(TableMetaData tableMetaData, int collectionId, boolean isReadOnly) {
         _tableMetaData = tableMetaData;
         _collectionId = collectionId;
         _isReadOnly = isReadOnly;
@@ -38,7 +38,7 @@
         return getObjects().contains(object);
     }
         
-    public void add(T object) {
+    public void add(T object) throws ConditionsObjectException {
         if (objects.contains(object)) {
             throw new IllegalArgumentException("Collection already contains this object.");
         }
@@ -49,12 +49,15 @@
         } catch (ConditionsObjectException x) {
             throw new IllegalArgumentException("Error assigning collection ID to object.", x);
         }
+        // Set the table meta data if the object does not have any.
+        if (object.getTableMetaData() == null && _tableMetaData != null)
+            object.setTableMetaData(_tableMetaData);
         objects.add(object);
         if (!isNew())
             setIsDirty(true);
     }
 
-    public ConditionsTableMetaData getTableMetaData() {
+    public TableMetaData getTableMetaData() {
         return _tableMetaData;        
     }
 
@@ -115,11 +118,17 @@
         return _isNew;
     }
     
-    void setCollectionId(int collectionId) {
+    public void setCollectionId(int collectionId) throws ConditionsObjectException {
+        if (_collectionId != -1)
+            throw new ConditionsObjectException("The collection ID is already set.");
         _collectionId = collectionId;
     }
     
-    void setIsReadOnly(boolean isReadOnly) {
+    public void setTableMetaData(TableMetaData tableMetaData) {
+        _tableMetaData = tableMetaData;
+    }
+    
+    public void setIsReadOnly(boolean isReadOnly) {
         _isReadOnly = isReadOnly;
-    }
+    }    
 }

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsObjectConverter.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectConverter.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectConverter.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -4,7 +4,7 @@
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 
-import org.hps.conditions.AbstractConditionsObject.FieldValueMap;
+import org.hps.conditions.ConditionsObject.FieldValueMap;
 import org.lcsim.conditions.ConditionsConverter;
 import org.lcsim.conditions.ConditionsManager;
 
@@ -32,7 +32,9 @@
         }
         
         // Get the table meta data from the key given by the caller.
-        ConditionsTableMetaData tableMetaData = databaseConditionsManager.findTableMetaData(name);
+        TableMetaData tableMetaData = databaseConditionsManager.findTableMetaData(name);
+        if (tableMetaData == null)
+            throw new RuntimeException("Table meta data for " + name + " was not found.");
         
         // Create a collection to return.
         ConditionsObjectCollection collection;
@@ -54,10 +56,14 @@
                 // then this is a fatal error.
                 throw new RuntimeException("Multiple conditions records returned but this is not allowed.");
         } else {
-            // The collection ID is only set on the collection object if all rows have the same
-            // collection ID.  Otherwise, the collection contains a mix of objects with different 
-            // collectionIDs and has no meaningful ID of its own.
-            collection.setCollectionId(conditionsRecords.get(0).getCollectionId());
+            // The collection ID and table meta data are only set on the collection object 
+            // if all rows have the same collection ID.
+            try {
+                collection.setCollectionId(conditionsRecords.get(0).getCollectionId());
+                collection.setTableMetaData(tableMetaData);
+            } catch (ConditionsObjectException e) {
+                throw new RuntimeException(e);
+            }
         }
 
         // Loop over conditions records.  This will usually just be one record.
@@ -73,6 +79,7 @@
             String query = QueryBuilder.buildSelect(tableName, collectionId, tableMetaData.getFieldNames(), "id ASC");
         
             // Query the database.
+            // TODO: Get the connection from the manager rather than the static instance.
             ResultSet resultSet = ConnectionManager.getConnectionManager().query(query);
             
             try {
@@ -81,10 +88,11 @@
                     // Create new ConditionsObject.
                     ConditionsObject newObject = createConditionsObject(resultSet, tableMetaData);
                     
-                    // Add new object to collection, which will also assign it a collection ID if applicable.
+                    // Add new object to collection, which will also assign it a 
+                    // collection ID if applicable.                    
                     collection.add(newObject);
                 }
-            } catch (SQLException e) {
+            } catch (SQLException | ConditionsObjectException e) {
                 throw new RuntimeException(e);
             }                 
         }
@@ -94,7 +102,7 @@
     }
 
     private ConditionsObject createConditionsObject(ResultSet resultSet, 
-            ConditionsTableMetaData tableMetaData) throws SQLException {
+            TableMetaData tableMetaData) throws SQLException {
         ResultSetMetaData metaData = resultSet.getMetaData();
         int rowId = resultSet.getInt(1);
         int ncols = metaData.getColumnCount();

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsObjectException.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectException.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectException.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -13,10 +13,10 @@
         super(message);
     }
 
-    public ConditionsObjectException(ConditionsObject object, String message) {
+    public ConditionsObjectException(String message, ConditionsObject object) {
         super(message);
     }
-
+    
     public ConditionsObject getConditionsObject() {
         return _object;
     }

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsRecord.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsRecord.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsRecord.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,6 +1,6 @@
 package org.hps.conditions;
 
-import static org.hps.conditions.ConditionsTableConstants.CONDITIONS_RECORD;
+import static org.hps.conditions.TableConstants.CONDITIONS_RECORD;
 
 import java.sql.Blob;
 import java.sql.ResultSet;

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsTableConstants.java removed after 335
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableConstants.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableConstants.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,57 +0,0 @@
-package org.hps.conditions;
-
-/**
- * This is a static set of constants defining default table names and lookup key values for conditions data.
- * The actual table names for the conditions data are defined externally in an XML configuration file read by the 
- * {@link DatabaseConditionsManager}.
- */
-public final class ConditionsTableConstants {
-    
-    /** Prevent instantiation of this class, which is only a holder of static constant values. */
-    private ConditionsTableConstants() {}
-    
-    /** Conditions key for ConditionsRecord. */
-    public static final String CONDITIONS_RECORD = "conditions_record";
-
-    /** Conditions key for combined ECal conditions. */
-    public static final String ECAL_CONDITIONS = "ecal_conditions";
-    
-    /** 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";
-    
-    /** 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";
-    
-    /** Conditions key for combined ECal conditions. */
-    public static final String SVT_CONDITIONS = "svt_conditions";
-    
-    /** Table with SVT channel data. */
-    public static final String SVT_CHANNELS = "svt_channels";
-    
-    /** Table with the SVT DAQ map. */
-    public static final String SVT_DAQ_MAP = "svt_daq_map";
-            
-    /** Conditions key for SVT calibration data. */ 
-    public static final String SVT_CALIBRATIONS = "svt_calibrations";
-    
-    /** Conditions key for SVT bad channels. */
-    public static final String SVT_BAD_CHANNELS = "svt_bad_channels";
-    
-    /** Conditions key for SVT pulse parameters. */
-    public static final String SVT_PULSE_PARAMETERS = "svt_pulse_parameters";
-    
-    /** Conditions key for SVT gain data. */
-    public static final String SVT_GAINS = "svt_gains";
-        
-    /** 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";
-}

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsTableMetaData.java removed after 335
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableMetaData.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableMetaData.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,53 +0,0 @@
-package org.hps.conditions;
-
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-/**
- * This class provides meta data about a conditions table, including a
- * list of conditions data fields (not including collection ID or row ID
- * which are assumed).  It also has references to the classes which are
- * used to map the data onto Java classes via the {@link ConditionsObject}
- * and {@link ConditionsObjectCollection} APIs.
- * 
- * @author Jeremy McCormick <[log in to unmask]>
- *
- */
-public class ConditionsTableMetaData {
-    
-    String _tableName;
-    Class<? extends ConditionsObject> _objectClass;
-    Class<? extends ConditionsObjectCollection<?>> _collectionClass;
-    Set<String> _fieldNames = new LinkedHashSet<String>();
-        
-    ConditionsTableMetaData(String tableName, 
-            Class<? extends ConditionsObject> objectClass, 
-            Class<? extends ConditionsObjectCollection<?>> collectionClass) {
-        _tableName = tableName;
-        _objectClass = objectClass;
-        _collectionClass = collectionClass;
-    }
-    
-    Class<? extends ConditionsObject> getObjectClass() {
-        return _objectClass;
-    }
-    
-    Class<? extends ConditionsObjectCollection<?>> getCollectionClass() {
-        return _collectionClass;
-    }
-    
-    String[] getFieldNames() {
-        return _fieldNames.toArray(new String[]{});
-    }
-       
-    void addField(String name) {
-        if (_fieldNames.contains(name)) {
-            throw new RuntimeException("The table meta data already has a field called " + name);
-        }
-        _fieldNames.add(name);
-    }
-    
-    public String getTableName() {
-        return _tableName;
-    }
-}
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions
ConditionsTableMetaDataXMLLoader.java removed after 335
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableMetaDataXMLLoader.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsTableMetaDataXMLLoader.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,99 +0,0 @@
-package org.hps.conditions;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jdom.Element;
-
-/**
- * This class loads an XML configuration of conditions table meta data.
- * 
- * @author Jeremy McCormick <[log in to unmask]>
- */
-class ConditionsTableMetaDataXMLLoader {
-    
-    List<ConditionsTableMetaData> _tableDataList = null;
-        
-    @SuppressWarnings("unchecked")
-    /**
-     * This method expects an XML element containing child "table" elements.
-     * @param element
-     */
-    void load(Element element) {
-        
-        _tableDataList = new ArrayList<ConditionsTableMetaData>();
-        
-        for (Iterator<?> iterator = element.getChildren("table").iterator(); iterator.hasNext();) {
-            Element tableElement = (Element)iterator.next();
-            String tableName = tableElement.getAttributeValue("name");
-            
-            //System.out.println("tableName: " + tableName);
-            
-            Element classesElement = tableElement.getChild("classes");
-            Element classElement = classesElement.getChild("object");
-            Element collectionElement = classesElement.getChild("collection");
-            
-            String className = classElement.getAttributeValue("class");
-            String collectionName = collectionElement.getAttributeValue("class");
-            
-            //System.out.println("className: " + className);
-            //System.out.println("collectionName: " + collectionName);
-            
-            Class<? extends ConditionsObject> objectClass;
-            Class<?> rawObjectClass;
-            try {
-                rawObjectClass = Class.forName(className);
-                //System.out.println("created raw object class: " + rawObjectClass.getSimpleName());
-                if (!ConditionsObject.class.isAssignableFrom(rawObjectClass)) {
-                    throw new RuntimeException("The class " + rawObjectClass.getSimpleName() + " does not extend ConditionsObject.");
-                }
-                objectClass = (Class<? extends ConditionsObject>)rawObjectClass;
-                //System.out.println("created ConditionsObject class: " + objectClass.getSimpleName());
-            } catch (ClassNotFoundException e) {
-                throw new RuntimeException(e);
-            }            
-            
-            Class<? extends ConditionsObjectCollection<?>> collectionClass;
-            Class<?> rawCollectionClass;
-            try {
-                rawCollectionClass = Class.forName(collectionName);
-                //System.out.println("created raw collection class: " + rawCollectionClass.getSimpleName());
-                if (!ConditionsObjectCollection.class.isAssignableFrom(rawCollectionClass))
-                    throw new RuntimeException("The class " + rawCollectionClass.getSimpleName() + " does not extend ConditionsObjectCollection.");
-                collectionClass = (Class<? extends ConditionsObjectCollection<?>>)rawCollectionClass;
-            } catch (ClassNotFoundException e) {
-                throw new RuntimeException(e);
-            }
-            
-            ConditionsTableMetaData tableData = new ConditionsTableMetaData(tableName, objectClass, collectionClass);
-            
-            Element fieldsElement = tableElement.getChild("fields");
-            
-            for (Iterator<?> fieldsIterator = fieldsElement.getChildren("field").iterator(); fieldsIterator.hasNext();) {
-                Element fieldElement = (Element)fieldsIterator.next();
-                
-                String fieldName = fieldElement.getAttributeValue("name");                                
-                //System.out.println("field: " + fieldName);
-                
-                tableData.addField(fieldName);
-            }
-            
-            _tableDataList.add(tableData);
-            
-            //System.out.println();
-        }                      
-    }    
-    
-    List<ConditionsTableMetaData> getTableMetaDataList() {
-        return _tableDataList;
-    }
-    
-    ConditionsTableMetaData findTableMetaData(String name) {
-        for (ConditionsTableMetaData metaData : _tableDataList) {
-            if (metaData.getTableName().equals(name))
-                return metaData;
-        }
-        return null;
-    }
-}

java/trunk/conditions/src/main/java/org/hps/conditions
ConnectionManager.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionManager.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionManager.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,14 +1,9 @@
 package org.hps.conditions;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
-import java.util.Properties;
 
 /**
  * This class provides various database utilities for the conditions system, primarily the
@@ -18,9 +13,9 @@
  */
 public class ConnectionManager {
 
-    private ConnectionParameters connectionParameters = new ConnectionParameters();
-    private static ConnectionManager instance = null;
-    private Connection connection = null;
+    private ConnectionParameters _connectionParameters;
+    private static ConnectionManager _instance = null;
+    private Connection _connection = null;
 
     /**
      * Class constructor.  Override at your own risk!
@@ -33,10 +28,10 @@
      * @return The instance of this class.
      */
     public static ConnectionManager getConnectionManager() {
-        if (instance == null) {
-            instance = new ConnectionManager();
+        if (_instance == null) {
+            _instance = new ConnectionManager();
         }
-        return instance;
+        return _instance;
     }
 
     /**
@@ -44,7 +39,7 @@
      * @param connectionParameters The connection parameters.
      */
     void setConnectionParameters(ConnectionParameters connectionParameters) {
-        this.connectionParameters = connectionParameters;
+        this._connectionParameters = connectionParameters;
     }
 
     /**
@@ -52,7 +47,7 @@
      * @return The connection parameters.
      */
     public ConnectionParameters getConnectionParameters() {
-        return connectionParameters;
+        return _connectionParameters;
     }
 
     /**
@@ -60,10 +55,12 @@
      * @return The database connection.
      */
     Connection createConnection() {
-        Connection newConnection = connectionParameters.createConnection();
+        if (_connectionParameters == null)
+            throw new RuntimeException("Connection parameters have not been set.");
+        Connection newConnection = _connectionParameters.createConnection();
         try {
-            System.out.println("USE " + connectionParameters.getDatabase());
-            newConnection.createStatement().execute("USE " + connectionParameters.getDatabase());
+            System.out.println("USE " + _connectionParameters.getDatabase());
+            newConnection.createStatement().execute("USE " + _connectionParameters.getDatabase());
         } catch (SQLException e) {
             throw new RuntimeException("Failed to connect to database.", e);
         }
@@ -116,11 +113,11 @@
         
         System.out.println(query);
         
-        if (connection == null)
-            connection = createConnection();
+        if (_connection == null)
+            _connection = createConnection();
         ResultSet result = null;
         try {
-            Statement statement = connection.createStatement();
+            Statement statement = _connection.createStatement();
             result = statement.executeQuery(query);
         } catch (SQLException x) {
             throw new RuntimeException("Error in query: " + query, x);
@@ -137,12 +134,12 @@
         
         System.out.println(query);
         
-        if (connection == null)
-            connection = createConnection();
+        if (_connection == null)
+            _connection = createConnection();
         int key = -1;
         try {
             // NOTE: Assumes only one row is updated!
-            Statement statement = connection.createStatement();
+            Statement statement = _connection.createStatement();
             statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); 
             ResultSet resultSet = statement.getGeneratedKeys();
             if (resultSet.next()) {
@@ -155,18 +152,6 @@
     }
         
     public void disconnect() {
-        cleanup(connection);
-    }
-
-    public void setupFromProperties(File propertiesFile) {
-        Properties p = new Properties();
-        try {
-            p.load(new FileInputStream(propertiesFile));
-        } catch (FileNotFoundException e) {
-            throw new RuntimeException(e);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-        connectionParameters = ConnectionParameters.fromProperties(p);
-    }
+        cleanup(_connection);
+    }  
 }

java/trunk/conditions/src/main/java/org/hps/conditions
ConnectionParameters.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionParameters.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionParameters.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -16,21 +16,14 @@
  */
 public final class ConnectionParameters {
     
-    /** Default values for the MySQL test database at SLAC. */
-    private String user = "rd_hps_cond_ro";
-    private String password = "2jumpinphotons.";
-    private int port = 3306;
-    private String hostname = "mysql-node03.slac.stanford.edu";
-    private String database = "rd_hps_cond";
-    private String conditionsTable = "conditions_dev";
+    private String user;
+    private String password;
+    private int port;
+    private String hostname;
+    private String database;
+    private String conditionsTable;
 
     /**
-     * No argument constructor that uses the defaults.
-     */
-    ConnectionParameters() {
-    }
-
-    /**
      * Fully qualified constructor.
      * @param user The user name.
      * @param password The password.
@@ -81,6 +74,20 @@
     public String getDatabase() {
         return database;
     }
+    
+    /**
+     * Get the user name.
+     */
+    public String getUser() {
+        return user;
+    }
+    
+    /**
+     * Get the password.
+     */
+    public String getPassword() {
+        return password;
+    }
 
     /**
      * Get the connection string for these parameters.
@@ -115,22 +122,17 @@
     }
     
     /**
-     * Create ConnectionParameters from data in a properties file.
-     * @param properties The properties file.
-     * @return The ConnectionParameters created from the properties file.
+     * Create the connection parameters from an XML container node 
+     * with the appropriate child elements.    
+     * @param element The connection XML element.
+     * @return The ConnectionParameters created from XML.
      */
-    public static final ConnectionParameters fromProperties(Properties properties) {        
-        String user = properties.get("user").toString();
-        String password = properties.getProperty("password").toString();
-        String database = properties.getProperty("database").toString();
-        String hostname = properties.getProperty("hostname").toString();
-        int port = Integer.parseInt(properties.getProperty("port").toString());
-        String conditionsTable = properties.getProperty("conditionsTable").toString();
-        return new ConnectionParameters(user, password, database, hostname, port, conditionsTable);
-    }    
-    
     public static final ConnectionParameters fromXML(Element element) {
+        if (element.getChild("user") == null)
+            throw new IllegalArgumentException("missing user element");
         String user = element.getChild("user").getText();
+        if (element.getChild("password") == null)
+            throw new IllegalArgumentException("missing password element");
         String password = element.getChild("password").getText();
         String database = element.getChild("database").getText();
         String hostname = element.getChild("hostname").getText();

java/trunk/conditions/src/main/java/org/hps/conditions
ConverterXMLLoader.java removed after 335
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConverterXMLLoader.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConverterXMLLoader.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,45 +0,0 @@
-package org.hps.conditions;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.jdom.Element;
-import org.lcsim.conditions.ConditionsConverter;
-
-/**
- * This class reads in an XML configuration specifying a list of converter classes,
- * e.g. from the config file for the {@link DatabaseConditionsManager}.
- *  
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class ConverterXMLLoader {
-    
-    List<ConditionsConverter> _converterList;
-    
-    void load(Element element) {
-        _converterList = new ArrayList<ConditionsConverter>();
-        for (Iterator iterator = element.getChildren("converter").iterator(); iterator.hasNext(); ) {
-            Element converterElement = (Element)iterator.next();
-            try {
-                Class converterClass = Class.forName(converterElement.getAttributeValue("class"));
-                if (ConditionsConverter.class.isAssignableFrom(converterClass)) {
-                    try {
-                        //System.out.println("adding converter: " + converterClass.getSimpleName());
-                        _converterList.add((ConditionsConverter)converterClass.newInstance());
-                    } catch (InstantiationException | IllegalAccessException e) {
-                        throw new RuntimeException(e);
-                    }
-                } else {
-                    throw new RuntimeException("The converter class " + converterClass.getSimpleName() + " does not extend the correct base type.");
-                }
-            } catch (ClassNotFoundException e) {
-                throw new RuntimeException(e);
-            }
-        }
-    }
-    
-    List<ConditionsConverter> getConverterList() {
-        return _converterList;
-    }
-}

java/trunk/conditions/src/main/java/org/hps/conditions
DatabaseConditionsManager.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -5,130 +5,278 @@
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
 
 import org.jdom.Document;
+import org.jdom.Element;
 import org.jdom.JDOMException;
 import org.jdom.input.SAXBuilder;
 import org.lcsim.conditions.ConditionsConverter;
 import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsReader;
 import org.lcsim.conditions.readers.BaseClasspathConditionsReader;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
 
 /**
- * This class should be used as the top-level ConditionsManager for HPS when legacy access to text
- * conditions is not needed.
+ * <p>
+ * This class should be used as the top-level ConditionsManager for database access to conditions
+ * data.
+ * </p>
+ * <p>
+ * In general, this will be overriding the <code>LCSimConditionsManagerImplementation</code> which
+ * is setup from within <code>LCSimLoop</code>.
+ * </p>
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
  */
-// TODO: Add a method to set the "base" reader for resource or file-based conditions, instead
-// of hard-coding to BaseClasspathConditionsReader.
+// TODO: Move query methods from ConnectionManager to this API so that ConnectionManager need not 
+// be itself statically accessible.  Add access to ConnectionManager object to this class.
 public class DatabaseConditionsManager extends LCSimConditionsManagerImplementation {
 
     static DatabaseConditionsManager _instance;
     int _runNumber = -1;
-    String _detectorName;    
+    String _detectorName;
+    List<TableMetaData> _tableData;
+    List<ConditionsConverter> _converters;
+    ConditionsReader _baseReader;    
+    static Logger _logger = null;
     ConnectionManager _connectionManager;
-    ConditionsTableMetaDataXMLLoader _loader;
-    ConverterXMLLoader _converters;
 
-    public DatabaseConditionsManager() {
+    /**
+     * Constructor is set to private as this class should not be instantiated directly. Use
+     * {@link #createInstance()} instead.
+     */
+    private DatabaseConditionsManager() {
     }
-    
+
     /**
+     * Simple log formatter for this class.
+     */
+    private static final class LogFormatter extends Formatter {
+
+        public String format(LogRecord record) {
+            StringBuilder sb = new StringBuilder();
+            sb.append(record.getLoggerName() + " [ " + record.getLevel() + " ] " + record.getMessage() + '\n');
+            return sb.toString();
+        }
+    }
+
+    /**
+     * Setup the logger.
+     */
+    static {
+        _logger = Logger.getLogger(DatabaseConditionsManager.class.getSimpleName());
+        _logger.setUseParentHandlers(false);
+        _logger.setLevel(Level.ALL);
+        ConsoleHandler handler = new ConsoleHandler();
+        handler.setFormatter(new LogFormatter());
+        _logger.addHandler(handler);
+        _logger.info("setup logger");
+    }
+
+    /**
      * Create a static instance of this class and register it as the default conditions manager.
+     * 
+     * @return The new conditions manager.
      */
     public static DatabaseConditionsManager createInstance() {
         _instance = new DatabaseConditionsManager();
-        ConditionsManager.setDefaultConditionsManager(_instance); // FIXME: This probably should not be called here.
+        ConditionsManager.setDefaultConditionsManager(_instance);
+        // setupLogger();
+        _logger.config("created and registered " + DatabaseConditionsManager.class.getSimpleName());
         return _instance;
     }
 
     /**
+     * Get the static instance of this class.
+     * @return The static instance of the manager.
+     */
+    public static DatabaseConditionsManager getInstance() {
+        return _instance;
+    }
+
+    /**
      * Perform setup for the current detector and run number.
      */
     public void setup() {
         try {
-            // Setup a reader to handle both jar based detector resources (given first priority) 
-            // and database conditions via the DatabaseConditionsReader.
             try {
-                // FIXME: Make the reader passed to the DataConditionsReader configurable via public method or XML arg.
-                setConditionsReader(new DatabaseConditionsReader(
-                        new BaseClasspathConditionsReader( _detectorName)), 
-                        _detectorName);
+                // Create a new, default base ConditionsReader if one was not externally set.
+                if (_baseReader == null)
+                    // Setup the default base reader to handle classpath resources.
+                    _baseReader = new BaseClasspathConditionsReader(_detectorName);
+
+                _logger.config("using base conditions reader: " + _baseReader.getClass().getSimpleName());
+                // Set the ConditionsReader on the manager.
+                setConditionsReader(new DatabaseConditionsReader(_baseReader), _detectorName);
             } catch (IOException e) {
                 throw new RuntimeException(e);
             }
-            
+
+            _logger.config("setting up with detector: " + _detectorName);
+            _logger.config("setting up with run number: " + _runNumber);
             // Setup the manager with the detector and run number.
             setDetector(_detectorName, _runNumber);
         } catch (ConditionsNotFoundException e) {
             throw new RuntimeException(e);
         }
     }
-    
+
+    /**
+     * Set the run number. This will not trigger conditions change until {@link #setup()} is
+     * called.
+     * @param runNumber The new run number.
+     */
     public void setRunNumber(int runNumber) {
         _runNumber = runNumber;
     }
 
+    /**
+     * Set the detector name. This will not trigger conditions change until {@link #setup()} is
+     * called.
+     * @param detectorName The name of the new detector.
+     */
     public void setDetectorName(String detectorName) {
         _detectorName = detectorName;
     }
-    
+
+    /**
+     * Get the current run number.
+     * @return The current run number.
+     */
     public int getRunNumber() {
         return _runNumber;
     }
 
+    /**
+     * Get the current detector name.
+     * @return The name of the current detector.
+     */
     public String getDetectorName() {
         return this.getDetector();
     }
-    
+
+    /**
+     * Get the lcsim compact Detector object from the conditions system.
+     * @return The detector object.
+     */
     public Detector getDetectorObject() {
         return getCachedConditions(Detector.class, "compact.xml").getCachedData();
     }
-    
-    public <T> T getConditionsData(Class<T> klass, String name) {
-        return getCachedConditions(klass, name).getCachedData();
+
+    /**
+     * Get conditions data by class and name.
+     * @param type The class of the conditions.
+     * @param name The name of the conditions set.
+     * @return The conditions or null (???) if does not exist.
+     */
+    public <T> T getConditionsData(Class<T> type, String name) {
+        _logger.info("getting conditions " + name + " of type " + type.getSimpleName());
+        return getCachedConditions(type, name).getCachedData();
     }
-    
+
     /**
      * Configure this object from an XML file.
      * @param file The XML file.
      */
-    public void configure(File file) {                        
+    public void configure(File file) {
         try {
+            _logger.info("configuring from file: " + file.getCanonicalPath());
+        } catch (IOException e) {
+        }
+        if (!file.exists()) {
+            throw new IllegalArgumentException("Config file does not exist.");
+        }
+        try {
             configure(new FileInputStream(file));
         } catch (FileNotFoundException e) {
             throw new RuntimeException(e);
         }
     }
-    
+
     /**
      * Configure this object from an embedded XML resource.
      * @param resource The embedded XML resource.
      */
     public void configure(String resource) {
-        configure(getClass().getResourceAsStream(resource)); 
+        _logger.config("configuring from resource: " + resource);
+        InputStream in = getClass().getResourceAsStream(resource);
+        if (in == null)
+            throw new IllegalArgumentException("The resource does not exist.");
+        configure(in);
     }
-    
-    List<ConditionsTableMetaData> getTableMetaDataList() {
-        return _loader.getTableMetaDataList();
+
+    /**
+     * Set externally the base ConditionsReader that will be used to find non-database conditions
+     * such as the compact.xml file for the detector.
+     * @param reader The base ConditionsReader.
+     */
+    public void setBaseConditionsReader(ConditionsReader reader) {
+        _baseReader = reader;
     }
-    
-    ConditionsTableMetaData findTableMetaData(String name) {
-        return _loader.findTableMetaData(name);
+
+    /**
+     * Get the next collection ID for a database table.
+     * @param tableName The name of the table.
+     * @return The next collection ID.
+     */
+    public int getNextCollectionId(String tableName) {
+        TableMetaData tableData = findTableMetaData(tableName);
+        if (tableData == null)
+            throw new IllegalArgumentException("There is no meta data for table " + tableName);
+        ResultSet resultSet = ConnectionManager.getConnectionManager().query("SELECT MAX(collection_id)+1 FROM " + tableName);
+        int collectionId = -1;
+        try {
+            resultSet.next();
+            collectionId = resultSet.getInt(1);
+        } catch (SQLException e) {
+            throw new RuntimeException(e);
+        }
+        return collectionId;
     }
-    
+
+    /**
+     * Get the list of table meta data.
+     * @return The list of table meta data.
+     */
+    public List<TableMetaData> getTableMetaDataList() {
+        return _tableData;
+    }
+
+    /**
+     * Find a table's meta data.
+     * @param name The name of the table.
+     * @return The table's meta data or null if does not exist.
+     */
+    public TableMetaData findTableMetaData(String name) {
+        for (TableMetaData meta : _tableData) {
+            if (meta.getTableName().equals(name))
+                return meta;
+        }
+        return null;
+    }
+
     private void configure(InputStream in) {
-        
+
         // Create XML document.
         Document config = createDocument(in);
 
         // Load the connection parameters from XML.
         loadConnectionParameters(config);
-        
+
         // Load the table meta data from XML.
         loadTableMetaData(config);
-        
+
         // Load the converter classes from XML.
         loadConverters(config);
     }
@@ -147,24 +295,147 @@
 
     private void loadConverters(Document config) {
         // Load the list of converters from the "converters" section of the config document.
-        _converters = new ConverterXMLLoader();
-        _converters.load(config.getRootElement().getChild("converters"));
-        
-        // Register the converters with this manager.
-        for (ConditionsConverter converter : _converters.getConverterList()) {
+        (this.new ConditionsConverterLoader()).load(config.getRootElement().getChild("converters"));
+
+        // Register the list of converters with this manager.
+        // FIXME: Should this happen here or when setup is called?
+        for (ConditionsConverter converter : _converters) {
             registerConditionsConverter(converter);
+            _logger.config("registered converter " + converter.getClass().getSimpleName() + " which handles type " + converter.getType().getSimpleName());
         }
     }
 
     private void loadTableMetaData(Document config) {
         // Load table meta data from the "tables" section of the config document.
-        _loader = new ConditionsTableMetaDataXMLLoader();
-        _loader.load(config.getRootElement().getChild("tables"));
+        (this.new TableMetaDataLoader()).load(config.getRootElement().getChild("tables"));
     }
 
     private void loadConnectionParameters(Document config) {
         // Setup the connection parameters from the "connection" section of the config document.
-        ConnectionManager.getConnectionManager().setConnectionParameters(
+        _connectionManager = ConnectionManager.getConnectionManager();
+        _connectionManager.setConnectionParameters(
                 ConnectionParameters.fromXML(config.getRootElement().getChild("connection")));
+        ConnectionParameters p = _connectionManager.getConnectionParameters();
+        
+        _logger.config("set connection parameters ...");
+        _logger.config("database: " + p.getDatabase());
+        _logger.config("user: " + p.getUser());
+        _logger.config("password: " + p.getPassword());
+        _logger.config("hostname: " + p.getHostname());
+        _logger.config("port: " + p.getPort());
+        _logger.config("connection: " + p.getConnectionString());
     }
+
+    /**
+     * This class loads an XML configuration of conditions table meta data.
+     * 
+     * @author Jeremy McCormick <[log in to unmask]>
+     */
+    class TableMetaDataLoader {
+
+        @SuppressWarnings("unchecked")
+        /**
+         * This method expects an XML element containing child "table" elements.
+         * @param element
+         */
+        void load(Element element) {
+
+            _tableData = new ArrayList<TableMetaData>();
+
+            for (Iterator<?> iterator = element.getChildren("table").iterator(); iterator.hasNext();) {
+                Element tableElement = (Element) iterator.next();
+                String tableName = tableElement.getAttributeValue("name");
+
+                // System.out.println("tableName: " + tableName);
+
+                Element classesElement = tableElement.getChild("classes");
+                Element classElement = classesElement.getChild("object");
+                Element collectionElement = classesElement.getChild("collection");
+
+                String className = classElement.getAttributeValue("class");
+                String collectionName = collectionElement.getAttributeValue("class");
+
+                // System.out.println("className: " + className);
+                // System.out.println("collectionName: " + collectionName);
+
+                Class<? extends ConditionsObject> objectClass;
+                Class<?> rawObjectClass;
+                try {
+                    rawObjectClass = Class.forName(className);
+                    // System.out.println("created raw object class: " +
+                    // rawObjectClass.getSimpleName());
+                    if (!ConditionsObject.class.isAssignableFrom(rawObjectClass)) {
+                        throw new RuntimeException("The class " + rawObjectClass.getSimpleName() + " does not extend ConditionsObject.");
+                    }
+                    objectClass = (Class<? extends ConditionsObject>) rawObjectClass;
+                    // System.out.println("created ConditionsObject class: " +
+                    // objectClass.getSimpleName());
+                } catch (ClassNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+
+                Class<? extends ConditionsObjectCollection<?>> collectionClass;
+                Class<?> rawCollectionClass;
+                try {
+                    rawCollectionClass = Class.forName(collectionName);
+                    // System.out.println("created raw collection class: " +
+                    // rawCollectionClass.getSimpleName());
+                    if (!ConditionsObjectCollection.class.isAssignableFrom(rawCollectionClass))
+                        throw new RuntimeException("The class " + rawCollectionClass.getSimpleName() + " does not extend ConditionsObjectCollection.");
+                    collectionClass = (Class<? extends ConditionsObjectCollection<?>>) rawCollectionClass;
+                } catch (ClassNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+
+                TableMetaData tableData = new TableMetaData(tableName, objectClass, collectionClass);
+
+                Element fieldsElement = tableElement.getChild("fields");
+
+                for (Iterator<?> fieldsIterator = fieldsElement.getChildren("field").iterator(); fieldsIterator.hasNext();) {
+                    Element fieldElement = (Element) fieldsIterator.next();
+
+                    String fieldName = fieldElement.getAttributeValue("name");
+                    // System.out.println("field: " + fieldName);
+
+                    tableData.addField(fieldName);
+                }
+
+                _tableData.add(tableData);
+
+                // System.out.println();
+            }
+        }      
+    }
+
+    /**
+     * This class reads in an XML configuration specifying a list of converter classes, e.g. from
+     * the config file for the {@link DatabaseConditionsManager}.
+     * 
+     * @author Jeremy McCormick <[log in to unmask]>
+     */
+    class ConditionsConverterLoader {
+
+        void load(Element element) {
+            _converters = new ArrayList<ConditionsConverter>();
+            for (Iterator iterator = element.getChildren("converter").iterator(); iterator.hasNext();) {
+                Element converterElement = (Element) iterator.next();
+                try {
+                    Class converterClass = Class.forName(converterElement.getAttributeValue("class"));
+                    if (ConditionsConverter.class.isAssignableFrom(converterClass)) {
+                        try {
+                            // System.out.println("adding converter: " +
+                            // converterClass.getSimpleName());
+                            _converters.add((ConditionsConverter) converterClass.newInstance());
+                        } catch (InstantiationException | IllegalAccessException e) {
+                            throw new RuntimeException(e);
+                        }
+                    } else {
+                        throw new RuntimeException("The converter class " + converterClass.getSimpleName() + " does not extend the correct base type.");
+                    }
+                } catch (ClassNotFoundException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
 }

java/trunk/conditions/src/main/java/org/hps/conditions
QueryBuilder.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/QueryBuilder.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/QueryBuilder.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,7 +1,13 @@
 package org.hps.conditions;
 
-
+/**
+ * This is a static utility class for building SQL queries for the conditions system.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
 class QueryBuilder {
+    
+    private QueryBuilder() {}
 
     static String buildSelect(String tableName, int collectionId, String[] fields, String order) {
         StringBuffer buff = new StringBuffer();
@@ -22,20 +28,43 @@
         if (order != null) {
             buff.append(" ORDER BY " + order);
         }
-        System.out.println("QueryBuilder.buildSelectQuery: " + buff.toString());
         return buff.toString();
     }
     
     static String buildUpdate(String tableName, int rowId, String[] fields, Object[] values) {
-        return null;
+        if (fields.length != values.length)
+            throw new IllegalArgumentException("The field and value arrays are different lengths.");        
+        StringBuffer buff = new StringBuffer();        
+        buff.append("UPDATE " + tableName + " SET ");
+        for (int i=0; i<fields.length; i++) {
+            buff.append(fields[i] + " = '" + values[i] + "', ");
+        }
+        buff.delete(buff.length()-2, buff.length()-1);
+        buff.append(" WHERE id = " + rowId); 
+        return buff.toString();
     }
     
-    static String buildInsert(String tableName, String[] fields, Object[] values) {
-        return null;
+    static String buildInsert(String tableName, int collectionId, String[] fields, Object[] values) {
+        if (fields.length != values.length)
+            throw new IllegalArgumentException("The field and value arrays are different lengths.");
+        StringBuffer buff = new StringBuffer();
+        buff.append("INSERT INTO " + tableName + "( collection_id");
+        for (String field : fields) {
+            buff.append(", " + field);
+        }
+        buff.append(" ) VALUES ( " + collectionId);
+        for (Object value : values) {
+            buff.append(", " + value);
+        } 
+        buff.append(") ");
+        return buff.toString();
     }
     
     static String buildDelete(String tableName, int rowId) {
-        return null;
+        if (rowId <= 0)
+            throw new IllegalArgumentException("Invalid row ID: " + rowId);
+        String query = "DELETE FROM " + tableName + " WHERE id = " + rowId;
+        return query;
     }
     
 }

java/trunk/conditions/src/main/java/org/hps/conditions
TestRunConditionsReader.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/TestRunConditionsReader.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/TestRunConditionsReader.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -7,7 +7,7 @@
 import org.lcsim.conditions.ConditionsReader;
 
 /**
- * This is a simple extension of [log in to unmask] to find
+ * This is a simple extension of {@link org.lcsim.conditions.ConditionsReader} to find
  * text file conditions data for the HPS Test Run 2012.  It basically just checks
  * two resource locations for files and fails if they do not exist.
  * 
@@ -19,17 +19,17 @@
 
     private String detectorName = null;
 
-    public TestRunConditionsReader(ConditionsReader reader) {       
+    public TestRunConditionsReader(ConditionsReader reader) {
     }
 
     public InputStream open(String name, String type) throws IOException {
         
         //System.out.println(this.getClass().getSimpleName() + ".open - " + name + ", " + type);
         
-        // 1) Check the detector base directory.
+        // Check the detector base directory.
         InputStream in = getClass().getResourceAsStream("/" + detectorName + "/" + name + "." + type);
         if (in == null) {
-            // 2) Check for embedded jar resources e.g. in hps-java.
+            // Check for embedded jar resources e.g. in hps-java.
             in = getClass().getResourceAsStream("/org/lcsim/hps/calib/testrun/" + name + "." + type);
 
             // If these failed to find conditions, then something went wrong.

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalBadChannel.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalBadChannel.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalBadChannel.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -3,6 +3,10 @@
 import org.hps.conditions.AbstractConditionsObject;
 import org.hps.conditions.ConditionsObjectCollection;
 
+/**
+ * This class represents an ECAL channel that is considered "bad" which means
+ * it should not be used in reconstruction.
+ */
 public class EcalBadChannel extends AbstractConditionsObject {
     
     public static class EcalBadChannelCollection extends ConditionsObjectCollection<EcalBadChannel> {    

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalCalibration.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCalibration.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalCalibration.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -7,6 +7,9 @@
  * This class is a simplistic representation of ECal pedestal and noise
  * values from the conditions database.
  * 
+ * The pedestal and noise are in units of ADC counts.  They are the mean and the
+ * standard deviation of the digitized pre-amp output.
+ * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalCalibration extends AbstractConditionsObject {
@@ -23,7 +26,8 @@
     }
     
     /**
-     * Get the pedestal value.
+     * Get the pedestal value in units of ADC counts, which is the 
+     * mean of the digitized pre-amp output.
      * @return The gain value.
      */
     public double getPedestal() {
@@ -31,7 +35,8 @@
     }       
     
     /**
-     * Get the noise value.
+     * Get the noise value in units of ADC counts, which is the 
+     * standard deviation of the digitized pre-amp output.
      * @return The noise value.
      */
     public double getNoise() {

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalChannel.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -5,32 +5,46 @@
 
 /**
  * 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. 
- * 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 EcalChannelCollection}
- * in the {@link EcalConditions} object for getting channel data.
+ *
+ * Any one of the three ID types specifies a unique channel.  This class allows all these values to be 
+ * associated together by channel in the same place for ease of lookup.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalChannel extends AbstractConditionsObject {
     
+    /**
+     * The <code>DaqId</code> is the combination of crate, slot and channel that specify the channel's 
+     * DAQ configuration.
+     */
     public static final class DaqId {
         public int crate;
         public int slot;
         public int channel;
     }
     
+    /**
+     * The <code>GeometryId</code> contains the x and y indices of the crystal in the LCSIM-based geometry 
+     * representation.
+     */
     public static final class GeometryId {
         public int x;
         public int y;
     }
     
+    /**
+     * The <code>channelId</code> is a unique number identifying the channel within its conditions collection.
+     * The channels in the database are given sequential channel IDs from 1 to N in semi-arbitrary order.
+     * The channel ID is generally the number used to connect other conditions objects such as {@link EcalGain}
+     * or {@link EcalCalibration} to the appropriate crystal in the calorimeter.
+     */
     public static final class ChannelId {
         public int id;
     }
     
+    /**
+     * A collection of {@link EcalChannel} objects that can be queried.         
+     */
     public static class EcalChannelCollection extends ConditionsObjectCollection<EcalChannel> {
                     
         /**
@@ -66,6 +80,11 @@
             return null;
         }
         
+        /**
+         * Find a channel by its channel ID.
+         * @param channelId The channel ID to find.
+         * @return The matching channel or null if does not exist.
+         */
         public EcalChannel findChannel(ChannelId channelId) {
             for (EcalChannel channel : getObjects()) {
                 if (channel.getChannelId() == channelId.id) {
@@ -77,7 +96,7 @@
     }
     
     /**
-     * Get the crate number.
+     * Get the crate number of the channel.
      * @return The crate number.
      */
     public int getCrate() {
@@ -85,7 +104,7 @@
     }
     
     /**
-     * Get the slot number.
+     * Get the slot number of the channel.
      * @return The slot number.
      */
     public int getSlot() {
@@ -93,7 +112,7 @@
     }
     
     /**
-     * Get the channel number.
+     * Get the channel number of the channel.
      * @return The channel number.
      */
     public int getChannel() {
@@ -101,7 +120,7 @@
     }
     
     /**
-     * Get the x value.
+     * Get the x value of the channel.
      * @return The x value.
      */
     public int getX() {
@@ -109,7 +128,7 @@
     }
     
     /**
-     * Get the y value.
+     * Get the y value of the channel.
      * @return The y value.
      */
     public int getY() {
@@ -117,7 +136,7 @@
     }
 
     /**
-     * Get the ID.
+     * Get the ID of the channel.
      * @return The ID of the channel.
      */
     public int getChannelId() {
@@ -126,7 +145,7 @@
     
     /**
      * Implementation of equals.
-     * @return True if objects are equal; false if not.
+     * @return True if objects are equal.
      */
     public boolean equals(Object o) {
         if (o == null) {

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalChannelConstants.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelConstants.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannelConstants.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,9 +1,7 @@
 package org.hps.conditions.ecal;
 
 /**
- * This class represents ECAL conditions per channel.  Individual channel
- * settings can be retrieved using the {@link EcalConditions} object
- * and its {@link EcalChannelCollection}.
+ * This class represents ECAL conditions per channel.
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalChannelConstants {

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConditions.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -6,12 +6,13 @@
 import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
 
 /**
- * This class provides access to all ECal conditions from the database,
+ * This class provides access to all ECAL conditions from the database,
  * including gain, pedestal and bad channel settings, per crystal.
  * 
  * Unlike most conditions data types, it does not extend 
  * {@link org.hps.conditions.ConditionsObject}, because it is a composite
- * object containing data assembled from many other <code>ConditionsObjects</code>
+ * object containing data assembled from many other 
+ * {@link org.hps.conditions.ConditionsObjects}.
  * 
  * @author Jeremy McCormick <[log in to unmask]>
  */

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConditionsConverter.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsConverter.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,9 +1,9 @@
 package org.hps.conditions.ecal;
 
-import static org.hps.conditions.ConditionsTableConstants.ECAL_BAD_CHANNELS;
-import static org.hps.conditions.ConditionsTableConstants.ECAL_CALIBRATIONS;
-import static org.hps.conditions.ConditionsTableConstants.ECAL_CHANNELS;
-import static org.hps.conditions.ConditionsTableConstants.ECAL_GAINS;
+import static org.hps.conditions.TableConstants.ECAL_BAD_CHANNELS;
+import static org.hps.conditions.TableConstants.ECAL_CALIBRATIONS;
+import static org.hps.conditions.TableConstants.ECAL_CHANNELS;
+import static org.hps.conditions.TableConstants.ECAL_GAINS;
 
 import org.hps.conditions.ecal.EcalBadChannel.EcalBadChannelCollection;
 import org.hps.conditions.ecal.EcalCalibration.EcalCalibrationCollection;
@@ -18,13 +18,11 @@
  * from the database, based on the current run number known by the conditions manager.
  * @author Jeremy McCormick <[log in to unmask]>
  */
-// FIXME: This converter is not needed.  The data loading can be done from within EcalConditions itself.
 public class EcalConditionsConverter implements ConditionsConverter<EcalConditions> {
       
     /**
      * Create ECAL conditions object containing all data for the current run.
      */
-    // TODO: This should be a method on EcalConditions itself.
     public EcalConditions getData(ConditionsManager manager, String name) {
         
         // Create new, empty conditions object to fill with data.

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalConverterRegistry.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConverterRegistry.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConverterRegistry.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -6,7 +6,10 @@
 import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
 import org.hps.conditions.ecal.EcalGain.EcalGainCollection;
 
-
+/**
+ * This is a set of data converters for ECAL conditions in the database.
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
 public class EcalConverterRegistry {
     
     public static final class EcalBadChannelConverter extends ConditionsObjectConverter<EcalBadChannelCollection> {         

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
EcalGain.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalGain.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalGain.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -4,8 +4,8 @@
 import org.hps.conditions.ConditionsObjectCollection;
 
 /**
- * This class is a simplistic representation of gain values from the ECal
- * conditions database.     
+ * A simplistic representation of gain values from the ECal conditions database.
+ * 
  * @author Jeremy McCormick <[log in to unmask]>
  */
 public class EcalGain extends AbstractConditionsObject {
@@ -14,7 +14,7 @@
     }
                
     /**
-     * Get the gain value.
+     * Get the gain value in units of MeV/ADC count.
      * @return The gain value.
      */
     public double getGain() {

java/trunk/conditions/src/main/java/org/hps/conditions/ecal
package-info.java added at 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/package-info.java	                        (rev 0)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/package-info.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -0,0 +1,21 @@
+/**
+ * The classes in this package represent detector conditions in the HPS ECAL subsystem.
+ * 
+ * Each {@link EcalChannel} represents one physical crystal in the detector.
+ * 
+ * The {@link EcalBadChannel} is a channel that is malfunctioning or dead and should not 
+ * be used for reconstruction.  It is up to the reconstruction Drivers to filter out 
+ * these channels.
+ * 
+ * The {@link EcalCalibration} contains the pedestal and noise values for a channel, 
+ * which are the mean and the standard deviation of the digitized pre-amp output.
+ * 
+ * The {@link EcalGain} is the channel gain in units of MeV/ADC counts.
+ * 
+ * The energy of a hit is reconstructed by multipling the gain by the pedestal-subtracted
+ * ADC integral (e.g. in Test Run 2012 data). 
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ * @author Sho Uemura <[log in to unmask]>
+ */
+package org.hps.conditions.ecal;
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions
package-info.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/package-info.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/package-info.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -5,15 +5,12 @@
  * The {@link DatabaseConditionsReader} has a set of converters for reading data from
  * tables using SQL queries and creating appropriate, typed objects for them.
  * </p>
- * 
  * <p>
  * There is a chain of readers that is called by the manager which looks like:
  * </p>
- * 
  * <p>
  * DetectorConditionsReader => DatabaseConditionsReader => ConditionsReader
  * </p>
- * 
  * <p>
  * The {@link DetectorConditionsReader} extends the {@link DatabaseConditionsReader} and 
  * handles compact.xml files or other files embedded as jar resources in the detector directories 
@@ -21,7 +18,6 @@
  * name and type.  When it does not find a set of condition data, it will call its
  * super class's method, which will then attempt to find the data.
  * </p>
- * 
  * <p>
  * The {@link DatabaseConditionsReader} in fact mostly relies on built-in behavior of the 
  * {@link org.lcsim.conditions.ConditionsReader} class, which has a set of converters
@@ -29,8 +25,6 @@
  * to Java objects.
  * </p>
  * 
- * <p>
  * @author Jeremy McCormick <[log in to unmask]>
- * </p>
  */
 package org.hps.conditions;
\ No newline at end of file

java/trunk/conditions/src/main/java/org/hps/conditions/svt
SvtChannel.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtChannel.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtChannel.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -8,6 +8,7 @@
 
 import org.hps.conditions.AbstractConditionsObject;
 import org.hps.conditions.ConditionsObjectCollection;
+import org.hps.conditions.ConditionsObjectException;
 import org.lcsim.hps.util.Pair;
 
 /**
@@ -28,7 +29,11 @@
             channelMap.put(channel.getChannelId(), channel);
             
             // Add to collection.
-            super.add(channel);
+            try {
+                super.add(channel);
+            } catch (ConditionsObjectException e) {
+                throw new RuntimeException(e);
+            }
         }
         
         public SvtChannel findChannel(int channelId) {

java/trunk/conditions/src/main/java/org/hps/conditions/svt
SvtConditionsConverter.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsConverter.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtConditionsConverter.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,12 +1,12 @@
 package org.hps.conditions.svt;
 
-import static org.hps.conditions.ConditionsTableConstants.SVT_BAD_CHANNELS;
-import static org.hps.conditions.ConditionsTableConstants.SVT_CALIBRATIONS;
-import static org.hps.conditions.ConditionsTableConstants.SVT_CHANNELS;
-import static org.hps.conditions.ConditionsTableConstants.SVT_DAQ_MAP;
-import static org.hps.conditions.ConditionsTableConstants.SVT_GAINS;
-import static org.hps.conditions.ConditionsTableConstants.SVT_PULSE_PARAMETERS;
-import static org.hps.conditions.ConditionsTableConstants.SVT_TIME_SHIFTS;
+import static org.hps.conditions.TableConstants.SVT_BAD_CHANNELS;
+import static org.hps.conditions.TableConstants.SVT_CALIBRATIONS;
+import static org.hps.conditions.TableConstants.SVT_CHANNELS;
+import static org.hps.conditions.TableConstants.SVT_DAQ_MAP;
+import static org.hps.conditions.TableConstants.SVT_GAINS;
+import static org.hps.conditions.TableConstants.SVT_PULSE_PARAMETERS;
+import static org.hps.conditions.TableConstants.SVT_TIME_SHIFTS;
 
 import org.hps.conditions.svt.SvtBadChannel.SvtBadChannelCollection;
 import org.hps.conditions.svt.SvtCalibration.SvtCalibrationCollection;

java/trunk/conditions/src/main/java/org/hps/conditions/svt
SvtTimeShift.java 335 -> 336
--- java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimeShift.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/svt/SvtTimeShift.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -2,6 +2,7 @@
 
 import org.hps.conditions.AbstractConditionsObject;
 import org.hps.conditions.ConditionsObjectCollection;
+import org.hps.conditions.ConditionsObjectException;
 import org.lcsim.hps.util.Pair;
 
 /**
@@ -19,7 +20,11 @@
             int hybrid = pair.getSecondElement();
             for (SvtTimeShift timeShift : getObjects()) {
                 if (timeShift.getFpga() == fpga && timeShift.getHybrid() == hybrid) {
-                    timeShifts.add(timeShift);
+                    try {
+                        timeShifts.add(timeShift);
+                    } catch (ConditionsObjectException e) {
+                        throw new RuntimeException(e);
+                    }
                 }
             }
             return timeShifts;

java/trunk/conditions/src/test/java/org/hps/conditions
ConditionsObjectTest.java added at 336
--- java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsObjectTest.java	                        (rev 0)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsObjectTest.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -0,0 +1,96 @@
+package org.hps.conditions;
+
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+import org.hps.conditions.svt.SvtGain;
+import org.hps.conditions.svt.SvtGain.SvtGainCollection;
+
+/**
+ * Test some basic operations of {@link org.hps.conditions.ConditionsObject}
+ * using the {@link org.hps.conditions.svt.SvtGain} type.
+ * 
+ * @author Jeremy McCormick <[log in to unmask]>
+ *
+ */
+public class ConditionsObjectTest extends TestCase {
+    
+    String detectorName = "HPS-conditions-test";
+    int runNumber = 1351;
+    DatabaseConditionsManager conditionsManager;
+    
+    public void setUp() {
+        // Create and configure the conditions manager.
+        conditionsManager = DatabaseConditionsManager.createInstance();
+        conditionsManager.configure("/org/hps/conditions/config/conditions_database_dev.xml");
+        conditionsManager.setDetectorName(detectorName);
+        conditionsManager.setRunNumber(runNumber);
+        conditionsManager.setup();
+    }
+    
+    public void testBasicOperations() throws ConditionsObjectException {    
+        
+        // Create a new collection.
+        TableMetaData tableMetaData = conditionsManager.findTableMetaData(TableConstants.SVT_GAINS);
+        int collectionId = conditionsManager.getNextCollectionId(tableMetaData.getTableName());        
+        SvtGainCollection collection = new SvtGainCollection();
+        collection.setTableMetaData(tableMetaData);
+        try {
+            collection.setCollectionId(collectionId);
+        } catch (ConditionsObjectException e) {
+            throw new RuntimeException(e);
+        }
+        collection.setIsReadOnly(false);
+                
+        // Create a dummy conditions object and add to collection.
+        SvtGain gain = new SvtGain();
+        gain.setFieldValue("svt_channel_id", 1);
+        gain.setFieldValue("gain", 1.234);
+        gain.setFieldValue("offset", 5.678);
+        collection.add(gain);
+        
+        // Insert into the database.
+        try {
+            gain.insert();
+            System.out.println("inserted row " + gain.getRowId()  
+                    + " into table " + gain.getTableMetaData().getTableName() 
+                    + " with collection ID " + gain.getCollectionId());
+        } catch (ConditionsObjectException e) {
+            throw new RuntimeException(e);
+        }
+        
+        // Select the gain that was just inserted.
+        SvtGain selectGain = new SvtGain();
+        selectGain.setRowId(gain.getRowId());
+        selectGain.setTableMetaData(tableMetaData);
+        selectGain.select();
+        
+        // Update the value in the database.
+        double newValue = 2.345;
+        gain.setFieldValue("gain", 2.345);
+        gain.update();
+        System.out.println("updated gain to new value " + newValue);
+        
+        // Delete the object.
+        gain.delete();
+        assertEquals("The deleted object still has a row ID.", -1, gain.getRowId());
+        
+        // Try an update which should fail.
+        try {
+            gain.update();
+            throw new RuntimeException("Should not get here.");
+        } catch (ConditionsObjectException e) {
+            System.out.println("caught expected error: " + e.getMessage());
+        }
+        
+        // Try a delete which should fail.
+        try {
+            gain.delete();
+            throw new RuntimeException("Should not get here.");
+        } catch (ConditionsObjectException e) {
+            System.out.println("caught expected error: " + e.getMessage());
+        }
+    }
+
+}

java/trunk/conditions/src/test/java/org/hps/conditions
DatabaseConditionsManagerTest.java 335 -> 336
--- java/trunk/conditions/src/test/java/org/hps/conditions/DatabaseConditionsManagerTest.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/DatabaseConditionsManagerTest.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -6,7 +6,7 @@
     
     String detectorName = "HPS-conditions-test";
     int runNumber = 1351;
-    DatabaseConditionsManager conditionsManager = new DatabaseConditionsManager();
+    DatabaseConditionsManager conditionsManager;
     
     public void setUp() {
         // Create and configure the conditions manager.
@@ -20,7 +20,7 @@
     @SuppressWarnings("rawtypes")
     public void testLoad() {                       
         // Load data from every table registered with the manager.
-        for (ConditionsTableMetaData metaData : conditionsManager.getTableMetaDataList()) {
+        for (TableMetaData metaData : conditionsManager.getTableMetaDataList()) {
             System.out.println(">>>> loading conditions from table: " + metaData.getTableName());
             ConditionsObjectCollection conditionsObjects = 
                     conditionsManager.getConditionsData(metaData.getCollectionClass(), metaData.getTableName());

java/trunk/conditions/src/test/java/org/hps/conditions/beam
BeamCurrentTest.java 335 -> 336
--- java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -1,6 +1,6 @@
 package org.hps.conditions.beam;
 
-import static org.hps.conditions.ConditionsTableConstants.BEAM_CURRENT;
+import static org.hps.conditions.TableConstants.BEAM_CURRENT;
 
 import java.io.File;
 import java.net.URL;

java/trunk/conditions/src/test/java/org/hps/conditions/ecal
EcalConditionsConverterTest.java 335 -> 336
--- java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalConditionsConverterTest.java	2014-03-21 22:18:16 UTC (rev 335)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/ecal/EcalConditionsConverterTest.java	2014-03-22 00:23:31 UTC (rev 336)
@@ -14,7 +14,7 @@
     final String detectorName = "HPS-conditions-test";
     final int runNumber = 777;
     
-    DatabaseConditionsManager conditionsManager = new DatabaseConditionsManager();
+    DatabaseConditionsManager conditionsManager;
     
     public void setUp() {
         // Create and configure the conditions manager.
SVNspam 0.1