Print

Print


Author: [log in to unmask]
Date: Fri Jun 12 16:55:16 2015
New Revision: 3144

Log:
Fix compilation and test errors on conditions branch.

Modified:
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObjectConverter.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObject.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsRecord.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/package-info.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java
    java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java
    java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java
    java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java
    java/branches/HPSJAVA-488/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedSequenceMonitor.java

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java	Fri Jun 12 16:55:16 2015
@@ -33,7 +33,7 @@
  * end of the hps-distribution. If that class is not being used, then the method must be executed manually at the right
  * time to achieve the proper behavior.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  */
 public class ConditionsDriver extends Driver {
 

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObjectConverter.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObjectConverter.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/AbstractConditionsObjectConverter.java	Fri Jun 12 16:55:16 2015
@@ -9,12 +9,11 @@
 import org.lcsim.conditions.ConditionsManager;
 
 /**
- * <p>
  * Implementation of default conversion from database tables to a {@link ConditionsObject} class.
  * <p>
  * This class actually returns collections and not individual objects.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  * @param <T> The type of the returned data which should be a class extending {@link BaseConditionsObjectCollection}.
  */
 public abstract class AbstractConditionsObjectConverter<T> implements ConditionsConverter<T> {

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObject.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObject.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObject.java	Fri Jun 12 16:55:16 2015
@@ -1,6 +1,7 @@
 package org.hps.conditions.api;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
@@ -37,24 +38,31 @@
      */
     static final int UNSET_ROW_ID = -1;
 
+    /**
+     * Perform the default to string operation on a conditions object.
+     * 
+     * @param object the conditions object
+     * @return the object converted to a string
+     */
     protected static String defaultToString(final BaseConditionsObject object) {
         final StringBuffer sb = new StringBuffer();
+        sb.append(object.getClass().getSimpleName() + " { ");
         sb.append("id: " + object.getRowId() + ", ");
         for (final String field : object.getFieldValues().getFieldNames()) {
             sb.append(field + ": " + object.getFieldValue(Object.class, field) + ", ");
         }
         sb.setLength(sb.length() - 2);
-        sb.append('\n');
+        sb.append(" }");
         return sb.toString();
     }
 
     /**
-     * The JDBC database connection.
+     * The JDBC connection used for database operations.
      */
     private Connection connection;
 
     /**
-     * The field values.
+     * The field values which is a map of key-value pairs corresponding to column values in the database.
      */
     private FieldValues fieldValues;
 
@@ -64,7 +72,7 @@
     private int rowId = UNSET_ROW_ID;
 
     /**
-     * Flag to indicate object is locally changed and database update has not been executed.
+     * Flag to indicate that the object is locally changed and a database update has not been executed.
      */
     private boolean isDirty;
 
@@ -74,20 +82,20 @@
     private TableMetaData tableMetaData;
 
     /**
-     *
+     * No argument class constructor; usable by sub-classes only.
      */
     protected BaseConditionsObject() {
         this.fieldValues = new FieldValuesMap();
     }
 
     /**
-     * Class constructor.
+     * Public class constructor.
      * <p>
      * This should be used when creating new objects without a list of field values. A new <code>FieldValues</code>
      * object will be automatically created from the table information.
      *
-     * @param connection
-     * @param tableMetaData
+     * @param connection the database connection
+     * @param tableMetaData the table meta data
      */
     public BaseConditionsObject(final Connection connection, final TableMetaData tableMetaData) {
         this.connection = connection;
@@ -96,13 +104,13 @@
     }
 
     /**
-     * Class constructor.
+     * Full qualified class constructor.
      * <p>
      * This should be used when creating new objects from a list of field values.
      *
-     * @param connection
-     * @param tableMetaData
-     * @param fields
+     * @param connection the database connection
+     * @param tableMetaData the table meta data
+     * @param fields the field values
      */
     public BaseConditionsObject(final Connection connection, final TableMetaData tableMetaData, final FieldValues fields) {
         this.connection = connection;
@@ -114,18 +122,24 @@
     }
 
     /**
-     *
+     * Delete the object from the database using its row ID.
+     * 
+     * @throws DatabaseObjectException if object is not in the database
+     * @throws SQLException if there is an error performing the delete operation
      */
     @Override
     public final void delete() throws DatabaseObjectException, SQLException {
-        if (isNew()) {
-            throw new DatabaseObjectException("Object is not in database and so cannot be deleted.", this);
-        }
-        final String sql = "DELETE FROM " + this.tableMetaData.getTableName() + " WHERE id=" + this.getRowId();
-        Statement statement = null;
+        if (isNew()) {            
+            throw new DatabaseObjectException("Object is not in the database.", this);
+        }
+        if (connection.getAutoCommit() == false) {
+            connection.setAutoCommit(true);
+        }
+        PreparedStatement statement = null;
         try {
-            statement = this.connection.createStatement();
-            statement.executeUpdate(sql);
+            statement = this.connection.prepareStatement("DELETE FROM " + this.tableMetaData.getTableName() + " WHERE id = ?");
+            statement.setInt(1, + this.getRowId());
+            statement.executeUpdate();
             this.rowId = UNSET_ROW_ID;
         } finally {
             if (statement != null) {
@@ -135,7 +149,9 @@
     }
 
     /**
-     *
+     * Get the collection ID of the object.
+     * 
+     * @return the collection ID of the object
      */
     @Override
     @Field(names = {"collection_id"})
@@ -148,7 +164,9 @@
     }
 
     /**
-     *
+     * Get the field values.
+     * 
+     * @return the field values
      */
     @Override
     public FieldValues getFieldValues() {
@@ -156,7 +174,9 @@
     }
 
     /**
-     *
+     * Get the row ID.
+     * 
+     * @return the row ID
      */
     @Override
     public final int getRowId() {
@@ -164,7 +184,9 @@
     }
 
     /**
-     *
+     * Get the table meta data for the object.
+     * 
+     * @return the table meta data or <code>null</code> if not set
      */
     @Override
     public final TableMetaData getTableMetaData() {
@@ -172,17 +194,21 @@
     }
 
     /**
-     *
+     * Get a field value by name.
+     * 
+     * @param type the return type
+     * @param name the name of the field
      */
     @Override
     public final <T> T getFieldValue(final Class<T> type, final String name) {
         return type.cast(this.fieldValues.getValue(type, name));
     }
-
-    /**
-     *
-     */
-    @Override
+   
+    /**
+     *
+     */
+    @Override
+    // FIXME: Rewrite to use a PreparedStatement.
     public final void insert() throws DatabaseObjectException, SQLException {
         if (!this.isNew()) {
             throw new DatabaseObjectException("Cannot insert existing record with row ID: " + this.getRowId(), this);
@@ -291,12 +317,12 @@
      *
      */
     void setCollectionId(final int collectionId) throws ConditionsObjectException {
-        if (this.getCollectionId() != UNSET_COLLECTION_ID) {
-            throw new ConditionsObjectException("The collection ID is already set on this object.");
-        }
-        if (collectionId <= UNSET_COLLECTION_ID) {
-            throw new ConditionsObjectException("Invalid collection ID value: " + collectionId);
-        }
+        //if (this.getCollectionId() != UNSET_COLLECTION_ID) {
+        //    throw new ConditionsObjectException("The collection ID is already set on this object.");
+        //}
+        //if (collectionId <= UNSET_COLLECTION_ID) {
+        //    throw new ConditionsObjectException("Invalid collection ID value: " + collectionId);
+        //}
         this.setFieldValue(COLLECTION_ID_FIELD, collectionId);
     }
 

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/BaseConditionsObjectCollection.java	Fri Jun 12 16:55:16 2015
@@ -148,7 +148,7 @@
                         + " table.", this);
             }
         }
-
+        
         // Set collection ID on objects.
         try {
             setConditionsObjectCollectionIds();
@@ -184,7 +184,7 @@
                 ((BaseConditionsObject) object).setRowId(resultSet.getInt(1));
                 resultSet.close();
             }
-            // This will commit the insert statements for the collections info table and the records.
+            // Commit the object insert statements together.
             this.connection.commit();
 
         } catch (final SQLException e1) {
@@ -302,13 +302,7 @@
     private final void setConditionsObjectCollectionIds() throws ConditionsObjectException {
         if (this.collectionId != BaseConditionsObject.UNSET_COLLECTION_ID) {
             for (final ConditionsObject object : this) {
-                if (object.getCollectionId() != this.getCollectionId()) {
-                    throw new ConditionsObjectException("The collection ID on the object does not match.");
-                }
-                if (!object.hasValidCollection()) {
-                    // FIXME: Uses concrete type instead of interface.
-                    ((BaseConditionsObject) object).setCollectionId(this.collectionId);
-                }
+                ((BaseConditionsObject) object).setCollectionId(this.collectionId);
             }
         }
     }
@@ -408,24 +402,27 @@
 
     @Override
     public boolean isNew() {
-        if (this.collectionId == BaseConditionsObject.UNSET_COLLECTION_ID) {
+        if (this.collectionId == BaseConditionsObject.UNSET_COLLECTION_ID) {           
             return true;
         }
         try {
-            return checkExists();
+            // Valid collection ID exists but need to check if inserted into database yet.
+            return checkExists() == false;
         } catch (final SQLException e) {
             throw new RuntimeException(e);
         }
     }
 
-    private boolean checkExists() throws SQLException {
-        Statement statement = null;
+    // FIXME: Use PreparedStatement instead of Statement.
+    private boolean checkExists() throws SQLException {                     
+        PreparedStatement statement = null;
         ResultSet resultSet = null;
         boolean exists = false;
         try {
-            statement = this.connection.createStatement();
-            resultSet = statement.executeQuery("SELECT id FROM " + this.tableMetaData.getTableName()
-                    + " where collection_id=" + this.collectionId);
+            statement = this.connection.prepareStatement("SELECT id FROM " + this.tableMetaData.getTableName()
+                    + " where collection_id = ?");
+            statement.setInt(1, this.collectionId);
+            resultSet = statement.executeQuery();
             exists = resultSet.next();
         } finally {
             if (statement != null) {

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObject.java	Fri Jun 12 16:55:16 2015
@@ -32,4 +32,8 @@
      * @param value
      */
     void setFieldValue(String name, Object value);
+            
+    // void setCollectionId(Integer id);
+    
+    // void setRowId(Integer id);
 }

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsObjectCollection.java	Fri Jun 12 16:55:16 2015
@@ -11,15 +11,12 @@
 
     int getCollectionId();
 
-    // FIXME: Perhaps this should not be in the interface.
     void setCollectionId(int id);
 
     int size();
 
-    // FIXME: It might be better if this was external to this interface.
     void sort(final Comparator<ObjectType> comparator);
 
-    // FIXME: It might be better if this was external to this interface.
     ConditionsObjectCollection<ObjectType> sorted(final Comparator<ObjectType> comparator);
 
     boolean contains(Object object);

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsRecord.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsRecord.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/api/ConditionsRecord.java	Fri Jun 12 16:55:16 2015
@@ -25,18 +25,6 @@
      */
     @SuppressWarnings("serial")
     public static class ConditionsRecordCollection extends BaseConditionsObjectCollection<ConditionsRecord> {
-
-        @Override
-        public boolean add(final ConditionsRecord object) throws ConditionsObjectException {
-            if (object == null) {
-                throw new IllegalArgumentException("The object argument is null.");
-            }
-            final boolean added = getObjects().add(object);
-            if (!added) {
-                throw new RuntimeException("Failed to add object.");
-            }
-            return added;
-        }
 
         /**
          * Compare conditions records by creation date.
@@ -126,6 +114,35 @@
             }
         }
 
+        @Override
+        public boolean add(final ConditionsRecord object) throws ConditionsObjectException {
+            if (object == null) {
+                throw new IllegalArgumentException("The object argument is null.");
+            }
+            final boolean added = this.getObjects().add(object);
+            if (!added) {
+                throw new RuntimeException("Failed to add object.");
+            }
+            return added;
+        }
+
+        /**
+         * Find a sub-set of the records with matching key name.
+         */
+        public ConditionsRecordCollection findByKey(final String key) {
+            final ConditionsRecordCollection collection = new ConditionsRecordCollection();
+            for (final ConditionsRecord record : this) {
+                if (record.getName().equals(key)) {
+                    try {
+                        collection.add(record);
+                    } catch (final ConditionsObjectException e) {
+                        throw new RuntimeException("Error adding record to new collection.", e);
+                    }
+                }
+            }
+            return collection;
+        }
+
         /**
          * Get the unique conditions keys from the records in this collection.
          *
@@ -143,21 +160,21 @@
          * Sort in place by creation date.
          */
         public final void sortByCreated() {
-            sort(new CreatedComparator());
+            this.sort(new CreatedComparator());
         }
 
         /**
          * Sort in place by key.
          */
         public final void sortByKey() {
-            sort(new KeyComparator());
+            this.sort(new KeyComparator());
         }
 
         /**
          * Sort in place by run start.
          */
         public final void sortByRunStart() {
-            sort(new RunStartComparator());
+            this.sort(new RunStartComparator());
         }
 
         /**
@@ -173,7 +190,7 @@
          * @return the sorted collection
          */
         public final ConditionsRecordCollection sortedByCreated() {
-            return (ConditionsRecordCollection) sorted(new CreatedComparator());
+            return (ConditionsRecordCollection) this.sorted(new CreatedComparator());
         }
 
         /**
@@ -182,7 +199,7 @@
          * @return the sorted collection
          */
         public final ConditionsRecordCollection sortedByKey() {
-            return (ConditionsRecordCollection) sorted(new KeyComparator());
+            return (ConditionsRecordCollection) this.sorted(new KeyComparator());
         }
 
         /**
@@ -191,7 +208,7 @@
          * @return the sorted collection
          */
         public final ConditionsRecordCollection sortedByRunStart() {
-            return (ConditionsRecordCollection) sorted(new RunStartComparator());
+            return (ConditionsRecordCollection) this.sorted(new RunStartComparator());
         }
 
         /**
@@ -200,24 +217,7 @@
          * @return the sorted collection
          */
         public final ConditionsRecordCollection sortedByUpdated() {
-            return (ConditionsRecordCollection) sorted(new UpdatedComparator());
-        }
-
-        /**
-         * Find a sub-set of the records with matching key name.
-         */
-        public ConditionsRecordCollection findByKey(String key) {
-            ConditionsRecordCollection collection = new ConditionsRecordCollection();
-            for (ConditionsRecord record : this) {
-                if (record.getName().equals(key)) {
-                    try {
-                        collection.add(record);
-                    } catch (ConditionsObjectException e) {
-                        throw new RuntimeException("Error adding record to new collection.", e);
-                    }
-                }
-            }
-            return collection;
+            return (ConditionsRecordCollection) this.sorted(new UpdatedComparator());
         }
     }
 
@@ -269,23 +269,13 @@
     }
 
     /**
-     * Get the collection ID, overriding this method from the parent class.
-     *
-     * @return the collection ID
-     */
-    @Field(names = {"collection_id"})
-    public Integer getCollectionId() {
-        return getFieldValue("collection_id");
-    }
-
-    /**
      * Get the date this record was created.
      *
      * @return the date this record was created
      */
     @Field(names = {"created"})
     public Date getCreated() {
-        return getFieldValue("created");
+        return this.getFieldValue("created");
     }
 
     /**
@@ -295,7 +285,7 @@
      */
     @Field(names = {"created_by"})
     public String getCreatedBy() {
-        return getFieldValue("created_by");
+        return this.getFieldValue("created_by");
     }
 
     /**
@@ -306,7 +296,7 @@
      */
     @Field(names = {"name"})
     public String getName() {
-        return getFieldValue("name");
+        return this.getFieldValue("name");
     }
 
     /**
@@ -316,7 +306,7 @@
      */
     @Field(names = {"notes"})
     public String getNotes() {
-        return getFieldValue("notes");
+        return this.getFieldValue("notes");
     }
 
     /**
@@ -326,7 +316,7 @@
      */
     @Field(names = {"run_end"})
     public Integer getRunEnd() {
-        return getFieldValue("run_end");
+        return this.getFieldValue("run_end");
     }
 
     /**
@@ -336,7 +326,7 @@
      */
     @Field(names = {"run_start"})
     public Integer getRunStart() {
-        return getFieldValue("run_start");
+        return this.getFieldValue("run_start");
     }
 
     /**
@@ -346,7 +336,7 @@
      */
     @Field(names = {"table_name"})
     public String getTableName() {
-        return getFieldValue("table_name");
+        return this.getFieldValue("table_name");
     }
 
     /**
@@ -356,7 +346,7 @@
      */
     @Field(names = {"tag"})
     public String getTag() {
-        return getFieldValue("tag");
+        return this.getFieldValue("tag");
     }
 
     /**
@@ -366,7 +356,7 @@
      */
     @Field(names = {"updated"})
     public Date getUpdated() {
-        return getFieldValue("updated");
+        return this.getFieldValue("updated");
     }
 
     /**
@@ -377,17 +367,17 @@
     @Override
     public String toString() {
         final StringBuffer sb = new StringBuffer();
-        sb.append("id: " + getRowId() + '\n');
-        sb.append("name: " + getName() + '\n');
-        sb.append("runStart: " + getRunStart() + '\n');
-        sb.append("runEnd: " + getRunEnd() + '\n');
-        sb.append("tableName: " + getTableName() + '\n');
-        sb.append("collectionId: " + getCollectionId() + '\n');
-        sb.append("updated: " + getUpdated() + '\n');
-        sb.append("created: " + getCreated() + '\n');
-        sb.append("tag: " + getTag() + '\n');
-        sb.append("createdBy: " + getCreatedBy() + '\n');
-        sb.append("notes: " + getNotes() + '\n');
+        sb.append("id: " + this.getRowId() + '\n');
+        sb.append("name: " + this.getName() + '\n');
+        sb.append("runStart: " + this.getRunStart() + '\n');
+        sb.append("runEnd: " + this.getRunEnd() + '\n');
+        sb.append("tableName: " + this.getTableName() + '\n');
+        sb.append("collectionId: " + this.getCollectionId() + '\n');
+        sb.append("updated: " + this.getUpdated() + '\n');
+        sb.append("created: " + this.getCreated() + '\n');
+        sb.append("tag: " + this.getTag() + '\n');
+        sb.append("createdBy: " + this.getCreatedBy() + '\n');
+        sb.append("notes: " + this.getNotes() + '\n');
         return sb.toString();
     }
 }

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/package-info.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/package-info.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/package-info.java	Fri Jun 12 16:55:16 2015
@@ -3,7 +3,7 @@
  * a framework built on the LCSim conditions system. The {@link DatabaseConditionsReader} has a set of converters for
  * reading data from tables using SQL queries and creating appropriate, typed objects for them.
  *
- * @author <a href="mailto:[log in to unmask]">Jeremy McCormick</a>
+ * @author Jeremy McCormick, SLAC
  * @see org.hps.conditions.api
  * @see org.hps.conditions.database
  */

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtBiasConditionsLoader.java	Fri Jun 12 16:55:16 2015
@@ -1,5 +1,5 @@
 /**
- * 
+ *
  */
 package org.hps.conditions.svt;
 
@@ -40,13 +40,11 @@
 
 /**
  * @author Per Hansson Adrian <[log in to unmask]>
- *
  */
 public class SvtBiasConditionsLoader {
 
     private static final Set<String> FIELDS = new HashSet<String>();
-    private static Logger logger = LogUtil.create(SvtBiasConditionsLoader.class, new BasicLogFormatter(),Level.INFO);
-    
+    private static Logger logger = LogUtil.create(SvtBiasConditionsLoader.class, new BasicLogFormatter(), Level.INFO);
 
     /**
      * Setup conditions.
@@ -65,85 +63,81 @@
     private static AIDA aida = AIDA.defaultInstance();
     static IDataPointSet dpsRuns = null;
     static IDataPointSet dpsBiasRuns = null;
-    
-    private static void setupPlots(boolean show) {
-        IDataPointSetFactory dpsf = aida.analysisFactory().createDataPointSetFactory(aida.tree());
-        dpsRuns = dpsf.create("dpsRuns","Run intervals", 2);
-        dpsBiasRuns = dpsf.create("dpsBiasRuns","Bias ON intervals associated with runs", 2);
-        IPlotter plotter = aida.analysisFactory().createPlotterFactory().create("Bias run ranges");
-        IPlotterStyle plotterStyle = aida.analysisFactory().createPlotterFactory().createPlotterStyle();
+
+    private static void setupPlots(final boolean show) {
+        final IDataPointSetFactory dpsf = aida.analysisFactory().createDataPointSetFactory(aida.tree());
+        dpsRuns = dpsf.create("dpsRuns", "Run intervals", 2);
+        dpsBiasRuns = dpsf.create("dpsBiasRuns", "Bias ON intervals associated with runs", 2);
+        final IPlotter plotter = aida.analysisFactory().createPlotterFactory().create("Bias run ranges");
+        final IPlotterStyle plotterStyle = aida.analysisFactory().createPlotterFactory().createPlotterStyle();
         plotterStyle.xAxisStyle().setParameter("type", "date");
         plotter.createRegions(1, 3);
-        plotter.region(0).plot(dpsRuns,plotterStyle);
-        plotter.region(1).plot(dpsBiasRuns,plotterStyle);
-        plotter.region(2).plot(dpsRuns,plotterStyle);
-        plotter.region(2).plot(dpsBiasRuns,plotterStyle,"mode=overlay");
-        if(show) plotter.show();
-        
-    }
-    
-    private static IDataPoint addPoint(IDataPointSet dps, long mstime, double val) {
-        IDataPoint dp = dps.addPoint();
-        dp.coordinate(0).setValue(mstime/1000.);
+        plotter.region(0).plot(dpsRuns, plotterStyle);
+        plotter.region(1).plot(dpsBiasRuns, plotterStyle);
+        plotter.region(2).plot(dpsRuns, plotterStyle);
+        plotter.region(2).plot(dpsBiasRuns, plotterStyle, "mode=overlay");
+        if (show) {
+            plotter.show();
+        }
+
+    }
+
+    private static IDataPoint addPoint(final IDataPointSet dps, final long mstime, final double val) {
+        final IDataPoint dp = dps.addPoint();
+        dp.coordinate(0).setValue(mstime / 1000.);
         dp.coordinate(1).setValue(val);
         return dp;
     }
-    
-    
-    /**
-     *  Default constructor
+
+    /**
+     * Default constructor
      */
     public SvtBiasConditionsLoader() {
     }
 
-    
-    
-    
     /**
      * Check validity of @link RunData
+     *
      * @param data the @link RunData to check
      * @return <code>true</code> if valid, <code>false</code> otherwise.
      */
-    private static boolean isValid(RunData data) {
-        if(data.getStartDate() == null || data.getEndDate() == null || data.getStartDate().before(new Date(99,1,1))) {
+    private static boolean isValid(final RunData data) {
+        if (data.getStartDate() == null || data.getEndDate() == null || data.getStartDate().before(new Date(99, 1, 1))) {
             logger.warning("This run data is not valid: " + data.toString());
             return false;
-        } 
+        }
         if (data.getStartDate().after(data.getEndDate())) {
             throw new RuntimeException("start date is after end date?!" + data.toString());
         }
         return true;
     }
-    
-    //private static Options options = null;
-    
-    
+
+    // private static Options options = null;
+
     /**
      * Load SVT HV bias constants into the conditions database.
-     * 
+     *
      * @param args the command line arguments (requires a CVS run log file and a MYA dump file.)
      */
-    public static void main(String[] args) {
-
-        Options options = new Options();
+    public static void main(final String[] args) {
+
+        final Options options = new Options();
         options.addOption(new Option("c", true, "CVS run file"));
         options.addOption(new Option("m", true, "MYA dump file"));
         options.addOption(new Option("g", false, "Actually load stuff into DB"));
         options.addOption(new Option("s", false, "Show plots"));
-        
+
         final CommandLineParser parser = new PosixParser();
         CommandLine cl = null;
         try {
             cl = parser.parse(options, args);
-        } catch (ParseException e) {
+        } catch (final ParseException e) {
             throw new RuntimeException("Cannot parse.", e);
         }
-        
- 
+
         // Setup plots
-        setupPlots(cl.hasOption("s")?true:false);
-
-        
+        setupPlots(cl.hasOption("s") ? true : false);
+
         // Load in CSV records from the exported run spreadsheet.
         final String path = cl.getOptionValue("c");
         logger.info(path);
@@ -152,116 +146,120 @@
         // Find the run ranges that have the same fields values.
         final List<RunRange> ranges = RunRange.findRunRanges(runSheet, FIELDS);
         logger.info("Found " + ranges.size() + " ranges.");
-        for(RunRange range : ranges) logger.info(range.toString());
+        for (final RunRange range : ranges) {
+            logger.info(range.toString());
+        }
         // find the run records (has converted dates and stuff) for these ranges
-        RunMap runmap  = runSheet.getRunMap(ranges);
+        final RunMap runmap = runSheet.getRunMap(ranges);
         logger.info("Found " + runmap.size() + " runs in the run map.");
-        
-        
-        
+
         // Load MYA dump
-        SvtBiasMyaDumpReader biasMyaReader = new SvtBiasMyaDumpReader(cl.getOptionValue("m"));
+        final SvtBiasMyaDumpReader biasMyaReader = new SvtBiasMyaDumpReader(cl.getOptionValue("m"));
         logger.info("Got " + biasMyaReader.getRanges().size() + " bias ranges");
-        
-        
-        // Combine them to run ranges when bias was on        
+
+        // Combine them to run ranges when bias was on
         // each run may have multiple bias ranges
-        
-        List<SvtBiasRunRange> biasRunRanges = new ArrayList<SvtBiasRunRange>();
-        // loop over runs from CSV        
+
+        final List<SvtBiasRunRange> biasRunRanges = new ArrayList<SvtBiasRunRange>();
+        // loop over runs from CSV
         RunData prev = null;
-        for(Entry<Integer,RunData> entry : runmap.entrySet()) {
-            int run = entry.getKey();
-            RunData data = entry.getValue();
+        for (final Entry<Integer, RunData> entry : runmap.entrySet()) {
+            final int run = entry.getKey();
+            final RunData data = entry.getValue();
             logger.info("Processing " + run + " " + data.toString());
-            
-            //check that data is ok
+
+            // check that data is ok
             if (isValid(data)) {
-                if(prev!=null) {
-                    if(isValid(prev)) {
-                        if(prev.getEndDate().after(data.getStartDate())) {
-                            throw new RuntimeException("prev end date after run started?: " + prev.toString() + "   " + data.toString());
-                        } else if(prev.getStartDate().after(data.getEndDate())) {
-                            throw new RuntimeException("prev start date before run ended?: " + prev.toString() + "   " + data.toString());
+                if (prev != null) {
+                    if (isValid(prev)) {
+                        if (prev.getEndDate().after(data.getStartDate())) {
+                            throw new RuntimeException("prev end date after run started?: " + prev.toString() + "   "
+                                    + data.toString());
+                        } else if (prev.getStartDate().after(data.getEndDate())) {
+                            throw new RuntimeException("prev start date before run ended?: " + prev.toString() + "   "
+                                    + data.toString());
                         }
                     }
                 }
-                
+
                 // find the bias ranges applicable to this run
-                SvtBiasMyaRanges overlaps = biasMyaReader.findOverlappingRanges(data.getStartDate(), data.getEndDate());
+                final SvtBiasMyaRanges overlaps = biasMyaReader.findOverlappingRanges(data.getStartDate(),
+                        data.getEndDate());
                 logger.fine("Found " + overlaps.size() + " overlapping bias ranges");
                 logger.fine(overlaps.toString());
 
-                biasRunRanges.add(new SvtBiasRunRange(data,overlaps));
+                biasRunRanges.add(new SvtBiasRunRange(data, overlaps));
                 prev = data;
 
             }
         }
-        
-        
+
         // fill graphs
-        if(cl.hasOption("s")) {
-            for(SvtBiasRunRange r : biasRunRanges) {
+        if (cl.hasOption("s")) {
+            for (final SvtBiasRunRange r : biasRunRanges) {
                 logger.info(r.toString());
-                if(r.getRun().getRun()>5600) {//9999999999999.0) {
-                    //if(dpsRuns.size()/4.0<500) {//9999999999999.0) {
-                    addPoint(dpsRuns, r.getRun().getStartDate().getTime(),0.0);
-                    addPoint(dpsRuns, r.getRun().getStartDate().getTime(),1.0);
-                    addPoint(dpsRuns, r.getRun().getEndDate().getTime(),1.0);
-                    addPoint(dpsRuns, r.getRun().getEndDate().getTime(),0.0);
-
-                    for(SvtBiasMyaRange br : r.getRanges()) {
-                        addPoint(dpsBiasRuns, br.getStart().getDate().getTime(),0.0);
-                        addPoint(dpsBiasRuns, br.getStart().getDate().getTime(),0.5);
-                        addPoint(dpsBiasRuns, br.getEnd().getDate().getTime(),0.5);
-                        addPoint(dpsBiasRuns, br.getEnd().getDate().getTime(),0.0);
+                if (r.getRun().getRun() > 5600) {// 9999999999999.0) {
+                    // if(dpsRuns.size()/4.0<500) {//9999999999999.0) {
+                    addPoint(dpsRuns, r.getRun().getStartDate().getTime(), 0.0);
+                    addPoint(dpsRuns, r.getRun().getStartDate().getTime(), 1.0);
+                    addPoint(dpsRuns, r.getRun().getEndDate().getTime(), 1.0);
+                    addPoint(dpsRuns, r.getRun().getEndDate().getTime(), 0.0);
+
+                    for (final SvtBiasMyaRange br : r.getRanges()) {
+                        addPoint(dpsBiasRuns, br.getStart().getDate().getTime(), 0.0);
+                        addPoint(dpsBiasRuns, br.getStart().getDate().getTime(), 0.5);
+                        addPoint(dpsBiasRuns, br.getEnd().getDate().getTime(), 0.5);
+                        addPoint(dpsBiasRuns, br.getEnd().getDate().getTime(), 0.0);
                     }
 
-
-                }   
-
-            }
-        }
-
-        
+                }
+
+            }
+        }
+
         // load to DB
-        loadToConditionsDB(biasRunRanges,cl.hasOption("g")?true:false);
-        
-    }
-    
-    private final static SvtBiasConstantCollection findCollection(final List<SvtBiasConstantCollection> list, Date date) {
-        for( SvtBiasConstantCollection collection : list) {
-            if(collection.find(date) != null) {
+        loadToConditionsDB(biasRunRanges, cl.hasOption("g") ? true : false);
+
+    }
+
+    private final static SvtBiasConstantCollection findCollection(final List<SvtBiasConstantCollection> list,
+            final Date date) {
+        for (final SvtBiasConstantCollection collection : list) {
+            if (collection.find(date) != null) {
                 return collection;
-            } 
+            }
         }
         return null;
     }
 
-    private static final void loadToConditionsDB(List<SvtBiasRunRange> ranges, boolean doIt) {
+    private static final void loadToConditionsDB(final List<SvtBiasRunRange> ranges, final boolean doIt) {
         logger.info("Load to DB...");
-        
+
         // Create a new collection for each run
-        List<Integer> runsadded = new ArrayList<Integer>();
-        
-        for(SvtBiasRunRange range : ranges) {
+        final List<Integer> runsadded = new ArrayList<Integer>();
+
+        for(final SvtBiasRunRange range : ranges) {
             logger.info("Loading " + range.toString());
-            RunData rundata = range.getRun();
+            final RunData rundata = range.getRun();
             if(runsadded.contains(rundata.getRun())) {
                 logger.warning("Run " + Integer.toString(rundata.getRun()) + " was already added?");
                 throw new RuntimeException("Run " + Integer.toString(rundata.getRun()) + " was already added?");
             }
             runsadded.add(rundata.getRun());
-            for (SvtBiasMyaRange biasRange : range.getRanges()) {
+            for (final SvtBiasMyaRange biasRange : range.getRanges()) {
                 //create a collection
-                SvtBiasConstantCollection collection = new SvtBiasConstantCollection();
+                final SvtBiasConstantCollection collection = new SvtBiasConstantCollection();
                 //create a constant and add to the collection
                 final SvtBiasConstant constant = new SvtBiasConstant();
                 constant.setFieldValue("start", biasRange.getStartDate());
                 constant.setFieldValue("end", biasRange.getEndDate());
                 constant.setFieldValue("value", biasRange.getStart().getValue());
-                collection.add(constant);
-                
+                try {
+                    collection.add(constant);
+                } catch (final ConditionsObjectException e) {
+                    throw new RuntimeException(e);
+                }
+
                 final ConditionsRecord condition = new ConditionsRecord();
                 condition.setFieldValue("run_start", rundata.getRun());
                 condition.setFieldValue("run_end", rundata.getRun());
@@ -270,25 +268,21 @@
                 condition.setFieldValue("notes", "constants from mya");
                 condition.setFieldValue("created", new Date());
                 condition.setFieldValue("created_by", System.getProperty("user.name"));
-                
+
                 condition.setFieldValue("collection_id", collection.getCollectionId());
-                
+
                 logger.info(condition.toString());
 
                 if(doIt) {
                     try {
                         condition.insert();
-                    } catch (ConditionsObjectException e) {
+                    } catch (Exception e) {
                         throw new RuntimeException(e);
                     }
                 }
             }
         }
-        
-
-    }
-    
-   
-    
-
+
+
+    }
 }

Modified: java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java
 =============================================================================
--- java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java	(original)
+++ java/branches/HPSJAVA-488/conditions/src/main/java/org/hps/conditions/svt/SvtTimingConstantsLoader.java	Fri Jun 12 16:55:16 2015
@@ -9,6 +9,7 @@
 import java.util.List;
 import java.util.Set;
 
+import org.hps.conditions.api.ConditionsObjectException;
 import org.hps.conditions.api.ConditionsRecord;
 import org.hps.conditions.database.DatabaseConditionsManager;
 import org.hps.conditions.run.RunRange;
@@ -58,7 +59,11 @@
             timing.setFieldValue("offset_time", offsetTime);
 
             final SvtTimingConstantsCollection collection = new SvtTimingConstantsCollection();
-            collection.add(timing);
+            try {
+                collection.add(timing);
+            } catch (ConditionsObjectException e) {
+                throw new RuntimeException(e);
+            }
             collections.add(collection);
         }
         return collections;
@@ -113,8 +118,7 @@
         for (final SvtTimingConstantsCollection collection : collections) {
             int collectionId = 0;
             try {
-                collectionId = MANAGER.addCollection("svt_timing_constants", "SVT timing constants added by " + System.getProperty("user.name"),
-                        "timing constants from run spreadsheet");
+                collectionId = MANAGER.getCollectionId(collection, "timing constants from run spreadsheet");
                 collection.setCollectionId(collectionId);
                 collection.insert();
             } catch (final Exception e) {

Modified: java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java
 =============================================================================
--- java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java	(original)
+++ java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalCalibrationsDriver.java	Fri Jun 12 16:55:16 2015
@@ -293,7 +293,7 @@
     private void loadCalibrations(EcalCalibrationCollection calibrations) {
         int collectionId = -1;
         try {
-            conditionsManager.getCollectionId(calibrations, "EcalCalibrationsDriver added by " + System.getProperty("user.name"), null);
+            conditionsManager.getCollectionId(calibrations, "loaded by EcalCalibrationsDriver");
         } catch (Exception e) {
             throw new RuntimeException(e);
         }

Modified: java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java
 =============================================================================
--- java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java	(original)
+++ java/branches/HPSJAVA-488/ecal-recon/src/main/java/org/hps/recon/ecal/EcalPedestalCalculator.java	Fri Jun 12 16:55:16 2015
@@ -168,7 +168,7 @@
 
         int collectionId = -1;
         try {
-            collectionId = conditionsManager.getCollectionId(calibrations, "EcalPedestalCalculator added by " + System.getProperty("user.name"), null);
+            collectionId = conditionsManager.getCollectionId(calibrations, "loaded by EcalPedestalCalculator");
         } catch (Exception e) {
             throw new RuntimeException(e);
         }

Modified: java/branches/HPSJAVA-488/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedSequenceMonitor.java
 =============================================================================
--- java/branches/HPSJAVA-488/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedSequenceMonitor.java	(original)
+++ java/branches/HPSJAVA-488/monitoring-drivers/src/main/java/org/hps/monitoring/ecal/plots/EcalLedSequenceMonitor.java	Fri Jun 12 16:55:16 2015
@@ -667,7 +667,7 @@
         int collectionId = -1;
 
         try {
-            collectionId = conditionsManager.getCollectionId(led_calibrations, "EcalLedSequenceMonitor generated by " + System.getProperty("user.name"), null);
+            collectionId = conditionsManager.getCollectionId(led_calibrations, "loaded by EcalLedSequenceMonitor");
         } catch (Exception e) {
             throw new RuntimeException(e);
         }