Commit in hps-java/src on MAIN | |||
main/java/org/lcsim/hps/conditions/AbstractConditionsLoader.java | +40 | added 1.1 | |
/BadChannelConverter.java | +26 | -48 | 1.2 -> 1.3 |
/ChannelCollection.java | +4 | 1.1 -> 1.2 | |
/ConditionsLoader.java | +28 | -4 | 1.1 -> 1.2 |
/ConditionsRecord.java | +20 | -33 | 1.1 -> 1.2 |
/ConditionsRecordCollection.java | +5 | -22 | 1.2 -> 1.3 |
/ConditionsRecordConverter.java | +20 | -36 | 1.2 -> 1.3 |
/ConnectionManager.java | +104 | -14 | 1.3 -> 1.4 |
/DatabaseConditionsConverter.java | +12 | 1.5 -> 1.6 | |
/DatabaseConditionsReader.java | +5 | -5 | 1.14 -> 1.15 |
main/java/org/lcsim/hps/conditions/ecal/EcalCalibration.java | +3 | -2 | 1.2 -> 1.3 |
/EcalCalibrationCollection.java | +1 | -1 | 1.3 -> 1.4 |
/EcalCalibrationConverter.java | +20 | -34 | 1.3 -> 1.4 |
/EcalChannel.java | +2 | -2 | 1.4 -> 1.5 |
/EcalChannelConstants.java | +2 | -1 | 1.1 -> 1.2 |
/EcalChannelMap.java | +1 | -1 | 1.3 -> 1.4 |
/EcalChannelMapConverter.java | +51 | -69 | 1.1 -> 1.2 |
/EcalConditionsLoader.java | +10 | -4 | 1.5 -> 1.6 |
/EcalGain.java | +1 | -4 | 1.3 -> 1.4 |
/EcalGainCollection.java | +1 | -1 | 1.5 -> 1.6 |
/EcalGainConverter.java | +31 | -46 | 1.4 -> 1.5 |
main/java/org/lcsim/hps/conditions/svt/PulseParametersConverter.java | +41 | -55 | 1.1 -> 1.2 |
/SvtCalibrationConverter.java | +44 | -54 | 1.13 -> 1.14 |
/SvtChannelMapConverter.java | +23 | -46 | 1.2 -> 1.3 |
/SvtConditionsLoader.java | +11 | -5 | 1.7 -> 1.8 |
/SvtGainConverter.java | +21 | -40 | 1.2 -> 1.3 |
/ChannelConstantsCollection.java | -26 | 1.4 removed | |
main/java/org/lcsim/hps/monitoring/DefaultEtEventProcessor.java | +11 | -2 | 1.11 -> 1.12 |
/EtEventProcessor.java | +4 | 1.2 -> 1.3 | |
/MonitoringApplication.java | +41 | -41 | 1.58 -> 1.59 |
test/java/org/lcsim/hps/conditions/ConditionsLoaderTest.java | +4 | -9 | 1.2 -> 1.3 |
/DatabaseConditionsReaderTest.java | +1 | -1 | 1.9 -> 1.10 |
test/java/org/lcsim/hps/conditions/ecal/EcalConditionsLoaderTest.java | +1 | -1 | 1.3 -> 1.4 |
test/java/org/lcsim/hps/conditions/svt/SvtConditionsLoaderTest.java | +1 | -1 | 1.3 -> 1.4 |
+590 | -608 |
database conditions system refactoring and comment cleanup
diff -N AbstractConditionsLoader.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ AbstractConditionsLoader.java 4 Oct 2013 06:02:19 -0000 1.1 @@ -0,0 +1,40 @@
+package org.lcsim.hps.conditions; + +import org.lcsim.conditions.ConditionsManager; + +/** + * This is an abstract class for conditions data loaders. + * Users should call {@link #load()} to have the loader + * create local objects from conditions data in the database. + * The interface for getting back the data is (for now) + * defined by each sub-class. + * + * @author Jeremy McCormick <[log in to unmask]> + * + */ +public abstract class AbstractConditionsLoader { + + /** The current conditions manager. */ + protected ConditionsManager manager = null; + + /** + * Class constructor. + * @param manager The current conditions manager. + */ + public AbstractConditionsLoader(ConditionsManager manager) { + this.manager = manager; + } + + /** + * Load conditions. + */ + public abstract void load(); + + /** + * Setup required components before load is called. + * This is optionally implemented by child classes + * and is not called automatically. + */ + public void setup() { + } +}
\ No newline at end of file
diff -u -r1.2 -r1.3 --- BadChannelConverter.java 4 Oct 2013 01:52:16 -0000 1.2 +++ BadChannelConverter.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -6,7 +6,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager;
@@ -29,69 +28,48 @@
// Get the ConditionsRecord with the meta-data, which will use the // current run number from the manager. ConditionsRecord record = ConditionsRecord.find(manager, name);
-
+
// Get the table name, field name, and field value defining the // applicable conditions. String tableName = record.getTableName(); String fieldName = record.getFieldName(); int fieldValue = record.getFieldValue();
- // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null; - - try {
+ // Get the name of the current database being used. + String database = this.getConnectionManager().getConnectionParameters().getDatabase();
- // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - // Select the correct field name depending on if SVT or ECAL is being queried. - String idFieldName = null; - if (name == SVT_BAD_CHANNELS) { - idFieldName = "svt_channel_id"; - } else if (name == ECAL_BAD_CHANNELS) { - idFieldName = "ecal_channel_id"; - } else { - throw new IllegalArgumentException("Unknown conditions key for this converter: " + name); - }
+ // Select the correct field name depending on if SVT or ECAL is being queried. + // FIXME: Might be better to go back to having 2 separate converters!!! + String idFieldName = null; + if (name == SVT_BAD_CHANNELS) { + idFieldName = "svt_channel_id"; + } else if (name == ECAL_BAD_CHANNELS) { + idFieldName = "ecal_channel_id"; + } else { + throw new IllegalArgumentException("Unknown conditions key for this converter: " + name); + }
- // Query for getting back bad channel records. - String query = "SELECT " + idFieldName + " FROM " - + database + "." + tableName + " WHERE " - + fieldName + " = " + fieldValue - + " ORDER BY id ASC"; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query);
+ // Connect to the conditions database. + ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Query for getting back bad channel records. + String query = "SELECT " + idFieldName + " FROM " + database + "." + tableName + " WHERE " + fieldName + " = " + fieldValue + " ORDER BY id ASC"; + ResultSet resultSet = ConnectionManager.getConnectionManager().query(connection, query);
- // Loop over the records.
+ // Loop over the records. + try {
while (resultSet.next()) { int channelId = resultSet.getInt(1); badChannels.add(channelId); } } catch (SQLException x) {
- throw new RuntimeException("Database error.", x);
+ throw new RuntimeException(x);
} finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ this.getConnectionManager().cleanup(resultSet); + this.getConnectionManager().cleanup(connection);
}
+
return badChannels; }
diff -u -r1.1 -r1.2 --- ChannelCollection.java 4 Oct 2013 01:43:47 -0000 1.1 +++ ChannelCollection.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -2,5 +2,9 @@
import java.util.HashSet;
+/** + * This class represents a set of channel IDs from the conditions database. + * @author Jeremy McCormick <[log in to unmask]> + */
public class ChannelCollection extends HashSet<Integer> { }
diff -u -r1.1 -r1.2 --- ConditionsLoader.java 4 Oct 2013 01:43:47 -0000 1.1 +++ ConditionsLoader.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -4,29 +4,53 @@
import org.lcsim.hps.conditions.ecal.EcalConditionsLoader; import org.lcsim.hps.conditions.svt.SvtConditions; import org.lcsim.hps.conditions.svt.SvtConditionsLoader;
+import org.lcsim.conditions.ConditionsManager;
-public class ConditionsLoader {
+/** + * This class loads both SVT and ECAL conditions. + * @author Jeremy McCormick <[log in to unmask]> + */ +public class ConditionsLoader extends AbstractConditionsLoader {
SvtConditions svtConditions = null; EcalConditions ecalConditions = null;
- void load() {
+ /** + * Class constructor. + * @param manager The current conditions manager. + */ + ConditionsLoader(ConditionsManager manager) { + super(manager); + } + + /** + * Load the conditions. + */ + public void load() {
// Load SVT conditions.
- SvtConditionsLoader loaderSvt = new SvtConditionsLoader();
+ SvtConditionsLoader loaderSvt = new SvtConditionsLoader(manager);
loaderSvt.load(); svtConditions = loaderSvt.getSvtConditions(); // Load ECAL conditions.
- EcalConditionsLoader loaderEcal = new EcalConditionsLoader();
+ EcalConditionsLoader loaderEcal = new EcalConditionsLoader(manager);
loaderEcal.load(); ecalConditions = loaderEcal.getEcalConditions(); }
+ /** + * Get the loaded SvtConditions. + * @return The SVT conditions or null if not loaded. + */
public SvtConditions getSvtConditions() { return svtConditions; }
+ /** + * Get the loaded EcalConditions. + * @return The ECAL conditions or null if not loaded. + */
public EcalConditions getEcalConditions() { return ecalConditions; }
diff -u -r1.1 -r1.2 --- ConditionsRecord.java 24 Sep 2013 02:40:21 -0000 1.1 +++ ConditionsRecord.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -203,12 +203,12 @@
} /**
- * Get the ConditionsRecord from the database with a certain name, e.g. "svt_calibrations" etc. - * The run number from the ConditionsManager will be used to limit the results to a single record - * via the ConditionsRecordConverter.
+ * Find a ConditionsRecord with conditions key matching <code>name</code>.
* @param manager The current conditions manager.
- * @param name The name of the ConditionsSet. - * @return The ConditionsRecord called <code>name</code> for the current run.
+ * @param name The name of the conditions key. + * @return The matching ConditionsRecord. + * @throws IllegalArgumentException if no records are found. + * @throws IllegalArgumentException if more than one record is found.
*/ public static ConditionsRecord find(ConditionsManager manager, String name) { CachedConditions<ConditionsRecordCollection> c = manager.getCachedConditions(ConditionsRecordCollection.class, "");
@@ -220,7 +220,7 @@
if (conditionsRecords.size() > 1) { throw new IllegalArgumentException("Duplicate ConditionsRecord with name: " + name); }
- return conditionsRecords.values().toArray(new ConditionsRecord[1])[0];
+ return conditionsRecords.get(0);
} /**
@@ -232,9 +232,10 @@
ConditionsRecordCollection conditionsRecords = new ConditionsRecordCollection();
- String db = ConnectionManager.getConnectionParameters().getDatabase(); - String table = ConnectionManager.getConnectionParameters().getConditionsTable(); - Connection connection = ConnectionManager.createConnection();
+ ConnectionManager manager = ConnectionManager.getConnectionManager(); + String db = manager.getConnectionParameters().getDatabase(); + String table = manager.getConnectionParameters().getConditionsTable(); + Connection connection = manager.createConnection();
String query = "SELECT * FROM " + db + "." + table
@@ -244,36 +245,22 @@
+ " AND run_end >= " + run;
- Statement statement = null; - try { - statement = connection.createStatement(); - ResultSet resultSet = statement.executeQuery(query);
+ ResultSet resultSet = manager.query(connection, query);
- // Iterate over conditions records.
+ // Iterate over conditions records. + try {
while (resultSet.next()) { ConditionsRecord record = new ConditionsRecord(); record.load(resultSet);
- conditionsRecords.put(record); - }
+ conditionsRecords.add(record); + }
} catch (SQLException x) {
- throw new RuntimeException(x);
+ throw new RuntimeException("Database error", x);
} finally {
- if (statement != null) { - try { - statement.close(); - } catch (SQLException x) { - throw new RuntimeException("Failed to close statement.", x); - } - } - if (statement != null) { - try { - connection.close(); - } catch (SQLException x) { - throw new RuntimeException("Failed to close connection.", x); - } - } - }
+ manager.cleanup(resultSet); + manager.cleanup(connection); + } +
return conditionsRecords; }
-
}
\ No newline at end of file
diff -u -r1.2 -r1.3 --- ConditionsRecordCollection.java 24 Sep 2013 02:51:35 -0000 1.2 +++ ConditionsRecordCollection.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -1,30 +1,13 @@
package org.lcsim.hps.conditions;
-import java.util.LinkedHashMap;
+import java.util.ArrayList;
/** * This is a simple container class for objects with the type <code>ConditionsRecord</code>. * @author Jeremy McCormick <[log in to unmask]> */
-public class ConditionsRecordCollection extends LinkedHashMap<Integer, ConditionsRecord> { - - /** - * Add a new ConditionsRecord by its <code>id</code>. - * Duplicates are not allowed. - * @param record The ConditionsRecord object. - * @return The inserted ConditionsRecord. - */ - public ConditionsRecord put(ConditionsRecord record) { - if (record == null) { - throw new IllegalArgumentException("The ConditionsRecord argument points to null"); - } - if (get(record.getId()) != null) { - throw new IllegalArgumentException("ConditionsRecord already exists with ID: " + record.getId()); - } - super.put(record.getId(), record); - return record; - } -
+public class ConditionsRecordCollection extends ArrayList<ConditionsRecord> { +
/** * Find a ConditionsRecord by its name or key in this collection. * This is the 'name' field from the conditions database table.
@@ -33,9 +16,9 @@
*/ public ConditionsRecordCollection find(String name) { ConditionsRecordCollection records = new ConditionsRecordCollection();
- for (ConditionsRecord rec : values()) {
+ for (ConditionsRecord rec : this) {
if (rec.getName().equals(name)) {
- records.put(rec.getId(), rec);
+ records.add(rec);
} } return records;
diff -u -r1.2 -r1.3 --- ConditionsRecordConverter.java 24 Sep 2013 02:51:35 -0000 1.2 +++ ConditionsRecordConverter.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -3,14 +3,13 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; /** * Read ConditionsRecord objects from the conditions database. * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: ConditionsRecordConverter.java,v 1.2 2013/09/24 02:51:35 jeremy Exp $
+ * @version $Id: ConditionsRecordConverter.java,v 1.3 2013/10/04 06:02:19 jeremy Exp $
*/ public class ConditionsRecordConverter extends DatabaseConditionsConverter<ConditionsRecordCollection> {
@@ -28,50 +27,35 @@
* @return The matching ConditionsRecords. */ public ConditionsRecordCollection getData(ConditionsManager manager, String name) {
- - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null; -
+
ConditionsRecordCollection records = new ConditionsRecordCollection();
+ ConnectionManager connectionManager = this.getConnectionManager(); + String database = connectionManager.getConnectionParameters().getDatabase(); + String tableName = connectionManager.getConnectionParameters().getConditionsTable(); + Connection connection = connectionManager.createConnection(); + + String query = "SELECT * from " + + database + "." + tableName + + " WHERE " + + "run_start <= " + + manager.getRun() + + " AND run_end >= " + + manager.getRun(); + + ResultSet resultSet = connectionManager.query(connection, query); +
try {
- - String database = ConnectionManager.getConnectionParameters().getDatabase(); - String tableName = ConnectionManager.getConnectionParameters().getConditionsTable(); - connection = ConnectionManager.createConnection(); - - String query = "SELECT * from " - + database + "." + tableName - + " WHERE " - + "run_start <= " - + manager.getRun() - + " AND run_end >= " - + manager.getRun(); - - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); -
while(resultSet.next()) { ConditionsRecord record = new ConditionsRecord(); record.load(resultSet);
- records.put(record.getId(), record);
+ records.add(record);
} } catch (SQLException x) { throw new RuntimeException("Database error", x); } finally {
- if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
} return records; }
diff -u -r1.3 -r1.4 --- ConnectionManager.java 4 Oct 2013 01:54:16 -0000 1.3 +++ ConnectionManager.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -5,35 +5,125 @@
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 converter classes. + *
* @author Jeremy McCormick <[log in to unmask]> */ public class ConnectionManager {
- private static ConnectionParameters connectionParameters = new ConnectionParameters(); - - static { - setupFromProperties();
+ private ConnectionParameters connectionParameters = new ConnectionParameters(); + private static ConnectionManager instance = null; + + /** + * Class constructor which is private so singleton must be used. + */ + private ConnectionManager() { + setupFromProperties(); + } + + /** + * Get the singleton instance of this class. + * @return The instance of this class. + */ + public static ConnectionManager getConnectionManager() { + if (instance == null) { + instance = new ConnectionManager(); + } + return instance; + } + + /** + * Set the connection parameters. + * @param connectionParameters The connection parameters. + */ + void setConnectionParameters(ConnectionParameters connectionParameters) { + this.connectionParameters = connectionParameters; + } + + /** + * Get the connection parameters. + * @return The connection parameters. + */ + public ConnectionParameters getConnectionParameters() { + return connectionParameters;
}
- private ConnectionManager() {
+ /** + * Create a connection to the database. + * @return The database connection. + */ + public Connection createConnection() { + Connection newConnection = connectionParameters.createConnection(); + return newConnection;
}
- public static void setConnectionParameters(ConnectionParameters connectionParameters) { - ConnectionManager.connectionParameters = connectionParameters;
+ /** + * Cleanup a connection. + * @param connection The Connection to cleanup. + */ + public void cleanup(Connection connection) { + if (connection != null) { + try { + if (!connection.isClosed()) + connection.close(); + else + System.err.println("Connection already closed!"); + } catch (SQLException x) { + throw new RuntimeException("Failed to close connection.", x); + } + }
}
- public static ConnectionParameters getConnectionParameters() { - return connectionParameters;
+ /** + * Cleanup a result set, or the Statement connected to it. + * @param resultSet The ResultSet to cleanup. + */ + public void cleanup(ResultSet resultSet) { + if (resultSet != null) { + try { + // This should close the ResultSet itself, too. + Statement statement = resultSet.getStatement(); + if (statement != null) + if (!statement.isClosed()) + statement.close(); + else + System.err.println("Statement already closed!"); + } catch (SQLException x) { + throw new RuntimeException("Failed to close statement.", x); + } + }
}
- - public static Connection createConnection() { - return connectionParameters.createConnection();
+ + /** + * This method can be used to perform a database query. + * Caller should then execute the methods {@link #cleanup(ResultSet)} + * and {@link #cleanup(Connection)} to cleanly close down the + * statement and connection after results are processed. + * @param query The SQL query string. + * @return The ResultSet from the query or null. + */ + public ResultSet query(Connection connection, String query) { + ResultSet result = null; + try { + Statement statement = connection.createStatement(); + result = statement.executeQuery(query); + } catch (SQLException x) { + throw new RuntimeException("Error in query: " + query, x); + } + return result;
}
- - public static void setupFromProperties() {
+ + /** + * Setup the object from a properties file. + */ + private void setupFromProperties() {
Object obj = System.getProperties().get("hps.conditions.db.configuration"); if (obj != null) { String config = obj.toString();
diff -u -r1.5 -r1.6 --- DatabaseConditionsConverter.java 24 Sep 2013 02:51:35 -0000 1.5 +++ DatabaseConditionsConverter.java 4 Oct 2013 06:02:19 -0000 1.6 @@ -1,5 +1,7 @@
package org.lcsim.hps.conditions;
+import java.sql.Connection; +
import org.lcsim.conditions.ConditionsConverter; /**
@@ -8,4 +10,14 @@
* @author Jeremy McCormick <[log in to unmask]> */ public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {
+ + /** + * Get the the {@link ConnectionManager} associated with this converter. + * For now, this calls the singleton method of the ConnectionManager + * to get its instance. + * @return The ConnectionManager of this converter. + */ + public ConnectionManager getConnectionManager() { + return ConnectionManager.getConnectionManager(); + }
}
\ No newline at end of file
diff -u -r1.14 -r1.15 --- DatabaseConditionsReader.java 4 Oct 2013 02:03:32 -0000 1.14 +++ DatabaseConditionsReader.java 4 Oct 2013 06:02:19 -0000 1.15 @@ -45,7 +45,7 @@
* </p> * * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DatabaseConditionsReader.java,v 1.14 2013/10/04 02:03:32 jeremy Exp $
+ * @version $Id: DatabaseConditionsReader.java,v 1.15 2013/10/04 06:02:19 jeremy Exp $
*/ public class DatabaseConditionsReader extends ConditionsReader {
@@ -140,7 +140,7 @@
registerConditionsConverters(manager); // Open a connection to the database.
- connection = ConnectionManager.createConnection();
+ connection = ConnectionManager.getConnectionManager().createConnection();
// Cache the run numbers. try {
@@ -186,16 +186,16 @@
ConditionsRecordCollection records = ConditionsRecord.find(run);
- for (ConditionsRecord record : records.values()) {
+ for (ConditionsRecord record : records) {
if (record.getRunStart() < minRun) { minRun = record.getRunStart();
- logger.info("Set min run: " + minRun);
+ logger.info("set min run: " + minRun);
} if (record.getRunEnd() > maxRun) { maxRun = record.getRunEnd();
- logger.info("Set max run: " + maxRun);
+ logger.info("set max run: " + maxRun);
} } }
diff -u -r1.2 -r1.3 --- EcalCalibration.java 4 Oct 2013 01:43:47 -0000 1.2 +++ EcalCalibration.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -16,8 +16,8 @@
/** * Fully qualified class constructor.
- * @param id - * @param gain
+ * @param pedestal The pedestal value. + * @param noise The noise value.
*/ EcalCalibration(double pedestal, double noise) { this.pedestal = pedestal;
@@ -34,6 +34,7 @@
/** * Get the noise value.
+ * @return The noise value.
*/ public double getNoise() { return noise;
diff -u -r1.3 -r1.4 --- EcalCalibrationCollection.java 4 Oct 2013 02:03:32 -0000 1.3 +++ EcalCalibrationCollection.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -3,7 +3,7 @@
import java.util.LinkedHashMap; /**
- * This class represents a list of {@link EcalCalibration} objects.
+ * This class represents a list of {@link EcalCalibration} objects and their ECAL channel IDs.
* @author Jeremy McCormick <[log in to unmask]> */ public class EcalCalibrationCollection extends LinkedHashMap<Integer,EcalCalibration> {
diff -u -r1.3 -r1.4 --- EcalCalibrationConverter.java 4 Oct 2013 02:03:32 -0000 1.3 +++ EcalCalibrationConverter.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -3,7 +3,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConditionsRecord;
@@ -11,13 +10,15 @@
import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class creates a list of {@link EcalCalibrationCollection} from the conditions database.
+ * This class creates a list of {@link EcalCalibrationCollection} from the + * conditions database. + *
* @author Jeremy McCormick <[log in to unmask]> */ public class EcalCalibrationConverter extends DatabaseConditionsConverter<EcalCalibrationCollection> { /**
- * Create the collection from the conditions database.
+ * Create the calibration collection from the conditions database.
* @param manager The conditions manager. * @param name The name of the conditions set. */
@@ -37,29 +38,25 @@
int fieldValue = record.getFieldValue(); // References to database objects.
- Statement statement = null;
ResultSet resultSet = null;
- Connection connection = null;
+ ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection();
- try { - - // Get a connection from the manager. - connection = ConnectionManager.createConnection();
+ // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase();
- // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase();
+ // The query to get conditions. + String query = "SELECT ecal_channel_id, pedestal, noise FROM " + + database + "." + tableName + " WHERE " + + fieldName + " = " + fieldValue + " ORDER BY ecal_channel_id ASC";
- String query = "SELECT ecal_channel_id, pedestal, noise FROM " - + database + "." + tableName - + " WHERE " + fieldName + " = " + fieldValue - + " ORDER BY ecal_channel_id ASC"; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query);
+ // Execute the query. + resultSet = connectionManager.query(connection, query);
+ try {
// Loop over the records. while (resultSet.next()) {
+ // Create calibration object from record.
int channelId = resultSet.getInt(1); double pedestal = resultSet.getDouble(2); double noise = resultSet.getDouble(3);
@@ -68,26 +65,15 @@
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
} return calibrations; } /**
- * Get the type handled by this converter.
+ * Get the type handled by this converter. + *
* @return The type handled by this converter. */ public Class<EcalCalibrationCollection> getType() {
diff -u -r1.4 -r1.5 --- EcalChannel.java 4 Oct 2013 01:43:47 -0000 1.4 +++ EcalChannel.java 4 Oct 2013 06:02:19 -0000 1.5 @@ -1,8 +1,8 @@
package org.lcsim.hps.conditions.ecal; /**
- * This class encapsulates all the information about a single ECal channel, e.g. one crystal. - * This includes the ID from the conditions database; the crate, slot, and channel numbers
+ * 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
diff -u -r1.1 -r1.2 --- EcalChannelConstants.java 4 Oct 2013 01:49:23 -0000 1.1 +++ EcalChannelConstants.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -2,7 +2,8 @@
/** * This class represents ECAL conditions per channel. Individual channel
- * settings can be retrieved using the {@link EcalConditions} object.
+ * settings can be retrieved using the {@link EcalConditions} object + * and its {@link EcalChannelMap}.
* @author Jeremy McCormick <[log in to unmask]> */ public class EcalChannelConstants {
diff -u -r1.3 -r1.4 --- EcalChannelMap.java 4 Oct 2013 02:03:33 -0000 1.3 +++ EcalChannelMap.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -9,7 +9,7 @@
* * FIXME: When adding new channels, there should be data structures setup for lookup using * using x, y or crate, slot, channel. See Sho's bit packing routines in original
- * EcalConditions class for ideas.
+ * EcalConditions class for ideas on how to make keys for them.
*/ public class EcalChannelMap extends HashMap<Integer, EcalChannel> {
diff -u -r1.1 -r1.2 --- EcalChannelMapConverter.java 4 Oct 2013 01:43:47 -0000 1.1 +++ EcalChannelMapConverter.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -5,14 +5,15 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConnectionManager; import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class creates the {@link EcalChannelMap} from the conditions table containing the channel data.
+ * This class creates the {@link EcalChannelMap} from the conditions table + * containing the channel data. + *
* @author Jeremy McCormick <[log in to unmask]> */ public class EcalChannelMapConverter extends DatabaseConditionsConverter<EcalChannelMap> {
@@ -20,76 +21,57 @@
/** * Load the data from the conditions database. * @param manager The conditions manager.
- * @param name The name of the conditions set.
+ * @param name The name of the conditions set.
*/
- public EcalChannelMap getData(ConditionsManager manager, String name) { - - // Collection to be returned to caller. - EcalChannelMap channels = new EcalChannelMap(); - - // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null; - - try { - - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - // Assign default key name if none was given. - if (name == null) - name = ECAL_CHANNELS; - - // Query to retrieve channel data. - String query = "SELECT id, x, y, crate, slot, channel FROM " - + database + "." + name; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); - - // Loop over the records. - while(resultSet.next()) { - - int id = resultSet.getInt(1); - int x = resultSet.getInt(2); - int y = resultSet.getInt(3); - int crate = resultSet.getInt(4); - int slot = resultSet.getInt(5); - int channel = resultSet.getInt(6); - - EcalChannel channelData = new EcalChannel(id, crate, slot, channel, x, y); - channels.put(channelData.getId(), channelData); - } - } catch (SQLException x) { - throw new RuntimeException("Database error.", x); - } finally { - // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - } - } - return channels;
+ public EcalChannelMap getData(ConditionsManager manager, String name) { + + // Collection to be returned to caller. + EcalChannelMap channels = new EcalChannelMap(); + + // References to database objects. + ResultSet resultSet = null; + ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase(); + + // Assign default key name if none was given. + if (name == null) + name = ECAL_CHANNELS; + + // Query to retrieve channel data. + String query = "SELECT id, x, y, crate, slot, channel FROM " + database + "." + name; + + // Execute the query and get the results. + resultSet = connectionManager.query(connection, query); + + try { + // Loop over the records. + while (resultSet.next()) { + // Create channel data object from database record. + int id = resultSet.getInt(1); + int x = resultSet.getInt(2); + int y = resultSet.getInt(3); + int crate = resultSet.getInt(4); + int slot = resultSet.getInt(5); + int channel = resultSet.getInt(6); + EcalChannel channelData = new EcalChannel(id, crate, slot, channel, x, y); + channels.put(channelData.getId(), channelData); + } + } catch (SQLException x) { + throw new RuntimeException("Database error.", x); + } finally { + connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection); + } + return channels;
}
- /** - * Get the type that this converter handles. - * @return The type handled by this converter. - */
+ /** + * Get the type that this converter handles. + * @return The type handled by this converter. + */
public Class<EcalChannelMap> getType() { return EcalChannelMap.class; }
diff -u -r1.5 -r1.6 --- EcalConditionsLoader.java 4 Oct 2013 01:43:47 -0000 1.5 +++ EcalConditionsLoader.java 4 Oct 2013 06:02:19 -0000 1.6 @@ -8,16 +8,25 @@
import java.util.Map.Entry; import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.hps.conditions.AbstractConditionsLoader;
import org.lcsim.hps.conditions.ChannelCollection; /** * This class loads all ecal conditions into an {@link EcalConditions} object. * @author Jeremy McCormick <[log in to unmask]> */
-public class EcalConditionsLoader {
+public class EcalConditionsLoader extends AbstractConditionsLoader {
/** The conditions object that will be constructed. */ private EcalConditions conditions = null;
+ + /** + * Class constructor. + * @param manager The current conditions manager. + */ + public EcalConditionsLoader(ConditionsManager manager) { + super(manager); + }
/** * Load ECal conditions into the <code>conditions</code> instance variable.
@@ -26,9 +35,6 @@
// Reset conditions object. conditions = new EcalConditions();
- - // Get the default conditions manager. This needs to be setup beforehand with the detector. - ConditionsManager manager = ConditionsManager.defaultInstance();
// Get the channel information from the database. EcalChannelMap channelMap = manager.getCachedConditions(EcalChannelMap.class, ECAL_CHANNELS).getCachedData();
diff -u -r1.3 -r1.4 --- EcalGain.java 4 Oct 2013 01:43:47 -0000 1.3 +++ EcalGain.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -2,10 +2,7 @@
/** * This class is a simplistic representation of gain values from the ecal
- * conditions database. The assigned channels can be looked up by using the - * {@link EcalChannelMap} for the event. This class is used as input for - * setting up gains within an {@link EcalConditions} object by the - * {@link EcalConditionsLoader}.
+ * conditions database.
* * @author Jeremy McCormick <[log in to unmask]> */
diff -u -r1.5 -r1.6 --- EcalGainCollection.java 4 Oct 2013 02:03:33 -0000 1.5 +++ EcalGainCollection.java 4 Oct 2013 06:02:19 -0000 1.6 @@ -3,7 +3,7 @@
import java.util.LinkedHashMap; /**
- * This class maps integer IDs from the database to ECal gain parameters.
+ * This class maps ECAL channel IDs from the database to ECal gain parameters.
*/ public class EcalGainCollection extends LinkedHashMap<Integer,EcalGain> { EcalGainCollection() {
diff -u -r1.4 -r1.5 --- EcalGainConverter.java 4 Oct 2013 01:43:47 -0000 1.4 +++ EcalGainConverter.java 4 Oct 2013 06:02:19 -0000 1.5 @@ -3,7 +3,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConditionsRecord;
@@ -11,74 +10,60 @@
import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class creates an {@link EcalGainCollection} from the appropriate conditions database information.
+ * This class creates an {@link EcalGainCollection} from the appropriate + * conditions database information.
*/ public class EcalGainConverter extends DatabaseConditionsConverter<EcalGainCollection> {
-
+
/** * Create the collection from the conditions database. * @param manager The conditions manager. * @param name The name of the conditions set. */ public EcalGainCollection getData(ConditionsManager manager, String name) {
-
+
// Collection to be returned to caller. EcalGainCollection gains = new EcalGainCollection();
- - // Get the ConditionsRecord with the meta-data, which will use the current run number from the manager.
+ + // Get the ConditionsRecord with the meta-data, which will use the + // current run number from the manager.
ConditionsRecord record = ConditionsRecord.find(manager, name);
- - // Get the table name, field name, and field value defining the applicable conditions.
+ + // Get the table name, field name, and field value defining the + // applicable conditions.
String tableName = record.getTableName(); String fieldName = record.getFieldName(); int fieldValue = record.getFieldValue();
-
+
// References to database objects.
- Statement statement = null; - ResultSet resultSet = null; - Connection connection = null; -
+ ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase(); + + // Database query on ecal gain table. + String query = "SELECT ecal_channel_id, gain FROM " + + database + "." + tableName + " WHERE " + + fieldName + " = " + fieldValue + " ORDER BY id ASC"; + + // Execute the query and get the results. + ResultSet resultSet = connectionManager.query(connection, query); +
try {
- - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - String query = "SELECT ecal_channel_id, gain FROM " - + database + "." + tableName - + " WHERE " + fieldName + " = " + fieldValue - + " ORDER BY id ASC"; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); -
// Loop over the records.
- while(resultSet.next()) {
+ while (resultSet.next()) {
+ // Create gain object from database record.
int channelId = resultSet.getInt(1); double gain = resultSet.getDouble(2); gains.put(channelId, new EcalGain(gain));
- }
+ }
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection); + }
return gains; }
diff -u -r1.1 -r1.2 --- PulseParametersConverter.java 4 Oct 2013 01:43:48 -0000 1.1 +++ PulseParametersConverter.java 4 Oct 2013 06:02:19 -0000 1.2 @@ -3,7 +3,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConditionsRecord;
@@ -11,93 +10,80 @@
import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class creates a {@link PulseParametersCollection} object from the conditions database.
+ * This class creates a {@link PulseParametersCollection} object from the + * conditions database. + *
* @author Jeremy McCormick <[log in to unmask]> */ public class PulseParametersConverter extends DatabaseConditionsConverter<PulseParametersCollection> {
-
+
/** * Get the pulse parameters by channel for this run by named conditions set.
- * @param manager The current conditions manager. - * @param name The name of the conditions set.
+ * + * @param manager + * The current conditions manager. + * @param name + * The name of the conditions set.
* @return The channel constants data. */ public PulseParametersCollection getData(ConditionsManager manager, String name) {
- - // Get the ConditionsRecord with the meta-data, which will use the current run number from the manager.
+ + // Get the ConditionsRecord with the meta-data, which will use the + // current run number from the manager.s
ConditionsRecord record = ConditionsRecord.find(manager, name);
- - // Get the table name, field name, and field value defining the applicable conditions.
+ + // Get the table name, field name, and field value defining the + // applicable conditions.
String tableName = record.getTableName(); String fieldName = record.getFieldName(); int fieldValue = record.getFieldValue();
- - // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null;
- // Objects for building the return value.
+ // Object for building the return value.
PulseParametersCollection collection = new PulseParametersCollection();
+ + // Connection objects. + ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase(); + + // Construct the query to find matching calibration records. + String query = "SELECT svt_channel_id, amplitude, t0, tp, chisq FROM " + + database + "." + tableName + " WHERE " + + fieldName + " = " + fieldValue + " ORDER BY id ASC"; + + // Execute the query and get the results. + ResultSet resultSet = connectionManager.query(connection, query);
try {
- - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - // Construct the query to find matching calibration records using the ID field. - String query = "SELECT svt_channel_id, amplitude, t0, tp, chisq FROM " - + database + "." + tableName - + " WHERE " - + fieldName + " = " + fieldValue - + " ORDER BY id ASC"; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); -
// Loop over the calibration records.
- while(resultSet.next()) { - - // Get the calibration data for a single channel.
+ while (resultSet.next()) { + // Create calibration object from database record.
int channelId = resultSet.getInt(1); double amplitude = resultSet.getDouble(2); double t0 = resultSet.getDouble(3); double tp = resultSet.getDouble(4); double chisq = resultSet.getDouble(5);
-
collection.put(channelId, new PulseParameters(amplitude, t0, tp, chisq));
- }
+ }
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
} // Return the collection of channel constants to caller. return collection; } /**
- * Get the type handled by this converter. - * @return The type handled by this converter, which is <code>ConditionsRecordCollection</code>.
+ * Get the type handled by this converter. + * + * @return The type handled by this converter, which is + * <code>ConditionsRecordCollection</code>.
*/ public Class<PulseParametersCollection> getType() { return PulseParametersCollection.class;
- }
+ }
}
diff -u -r1.13 -r1.14 --- SvtCalibrationConverter.java 4 Oct 2013 01:43:48 -0000 1.13 +++ SvtCalibrationConverter.java 4 Oct 2013 06:02:19 -0000 1.14 @@ -3,7 +3,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConditionsRecord;
@@ -11,13 +10,16 @@
import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class creates a {@link SvtCalibrationCollection} from the conditions database.
+ * This class creates a {@link SvtCalibrationCollection} from the conditions + * database. + *
* @author Omar Moreno <[log in to unmask]> * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: SvtCalibrationConverter.java,v 1.13 2013/10/04 01:43:48 jeremy Exp $
+ * @version $Id: SvtCalibrationConverter.java,v 1.13 2013/10/04 01:43:48 jeremy + * Exp $
*/ public class SvtCalibrationConverter extends DatabaseConditionsConverter<SvtCalibrationCollection> {
-
+
/** * Class constructor. */
@@ -26,84 +28,72 @@
/** * Get the SVT channel constants for this run by named set.
- * @param manager The current conditions manager. - * @param name The name of the conditions set.
+ * + * @param manager + * The current conditions manager. + * @param name + * The name of the conditions set.
* @return The channel constants data. */ public SvtCalibrationCollection getData(ConditionsManager manager, String name) {
- - // Get the ConditionsRecord with the meta-data, which will use the current run number from the manager.
+ + // Get the ConditionsRecord with the meta-data, which will use the + // current run number from the manager.
ConditionsRecord record = ConditionsRecord.find(manager, name);
- - // Get the table name, field name, and field value defining the applicable conditions.
+ + // Get the table name, field name, and field value defining the + // applicable conditions.
String tableName = record.getTableName(); String fieldName = record.getFieldName(); int fieldValue = record.getFieldValue();
- - // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null;
// Objects for building the return value. SvtCalibrationCollection collection = new SvtCalibrationCollection();
-
+ + // Get a connection from the manager. + ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase(); + + // Construct the query to find matching calibration records using the ID + // field. + String query = "SELECT svt_channel_id, noise, pedestal FROM " + + database + "." + tableName + " WHERE " + + fieldName + " = " + fieldValue + " ORDER BY svt_channel_id ASC"; + + // Execute the query and get the results. + ResultSet resultSet = connectionManager.query(connection, query); +
try {
- - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - // Construct the query to find matching calibration records using the ID field. - String query = "SELECT svt_channel_id, noise, pedestal FROM " - + database + "." + tableName - + " WHERE " - + fieldName + " = " + fieldValue - + " ORDER BY svt_channel_id ASC"; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); -
// Loop over the calibration records.
- while(resultSet.next()) { -
+ while (resultSet.next()) { +
// Get the calibration data for a single channel. int channelId = resultSet.getInt(1); double noise = resultSet.getDouble(2); double pedestal = resultSet.getDouble(3); collection.put(channelId, new SvtCalibration(noise, pedestal));
- }
+ }
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
} // Return the collection of channel constants to caller. return collection; } /**
- * Get the type handled by this converter. - * @return The type handled by this converter, which is <code>ConditionsRecordCollection</code>.
+ * Get the type handled by this converter. + * + * @return The type handled by this converter, which is + * <code>ConditionsRecordCollection</code>.
*/ public Class<SvtCalibrationCollection> getType() { return SvtCalibrationCollection.class;
- }
+ }
}
\ No newline at end of file
diff -u -r1.2 -r1.3 --- SvtChannelMapConverter.java 4 Oct 2013 01:43:48 -0000 1.2 +++ SvtChannelMapConverter.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -5,14 +5,13 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConnectionManager; import org.lcsim.hps.conditions.DatabaseConditionsConverter; /**
- * This class converts conditions database records into an {@link SvtChannelMap}.
+ * This class converts a table of SVT channel setup data into an {@link SvtChannelMap}.
* @author Jeremy McCormick <[log in to unmask]> */ public class SvtChannelMapConverter extends DatabaseConditionsConverter<SvtChannelMap> {
@@ -23,62 +22,41 @@
* @param name The name of the conditions set. */ public SvtChannelMap getData(ConditionsManager manager, String name) {
- - // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null;
// Objects for building the return value. SvtChannelMap channels = new SvtChannelMap();
- - try { - - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase(); - - // Assign default key name for channel data if none given. - if (name == null) - name = SVT_CHANNELS; - - // Construct the query to find matching calibration records using the ID field. - String query = "SELECT id, fpga, hybrid, channel FROM " - + database + "." + name; - - // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); - - while(resultSet.next()) {
+ ConnectionManager connectionManager = getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + String database = connectionManager.getConnectionParameters().getDatabase(); + + // Assign default key name for channel data if none given. + if (name == null) + name = SVT_CHANNELS; + + // Construct the query to get the channel data. + String query = "SELECT id, fpga, hybrid, channel FROM " + database + "." + name; + + // Execute the query and get the results. + ResultSet resultSet = connectionManager.query(connection, query); + + try { + // Loop over records. + while (resultSet.next()) { + // Add SVT channel data for this record.
int id = resultSet.getInt(1); int fpga = resultSet.getInt(2); int hybrid = resultSet.getInt(3); int channel = resultSet.getInt(4);
-
SvtChannel data = new SvtChannel(id, fpga, hybrid, channel); channels.put(data.getId(), data);
- }
+ }
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
} return channels; }
@@ -90,5 +68,4 @@
public Class<SvtChannelMap> getType() { return SvtChannelMap.class; }
-
}
diff -u -r1.7 -r1.8 --- SvtConditionsLoader.java 4 Oct 2013 01:43:48 -0000 1.7 +++ SvtConditionsLoader.java 4 Oct 2013 06:02:19 -0000 1.8 @@ -2,32 +2,38 @@
import static org.lcsim.hps.conditions.ConditionsConstants.SVT_BAD_CHANNELS; import static org.lcsim.hps.conditions.ConditionsConstants.SVT_CALIBRATIONS;
-import static org.lcsim.hps.conditions.ConditionsConstants.SVT_PULSE_PARAMETERS;
import static org.lcsim.hps.conditions.ConditionsConstants.SVT_CHANNELS; import static org.lcsim.hps.conditions.ConditionsConstants.SVT_GAINS;
+import static org.lcsim.hps.conditions.ConditionsConstants.SVT_PULSE_PARAMETERS;
import java.util.Map.Entry; import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.hps.conditions.AbstractConditionsLoader;
import org.lcsim.hps.conditions.ChannelCollection; /** * This class creates an {@link SvtConditions} object from the conditions database, * based on the current run number known by the conditions manager. */
-public class SvtConditionsLoader {
+public class SvtConditionsLoader extends AbstractConditionsLoader {
// Object to be returned to caller. private SvtConditions conditions = null;
+ + /** + * Class constructor. + * @param manager The current conditions manager. + */ + public SvtConditionsLoader(ConditionsManager manager) { + super(manager); + }
/** * Load the SVT conditions. */ public void load() {
- // Get the default conditions manager. This needs to be setup beforehand with the detector. - ConditionsManager manager = ConditionsManager.defaultInstance(); -
// Get the SVT channel map. SvtChannelMap channels = manager.getCachedConditions(SvtChannelMap.class, SVT_CHANNELS).getCachedData();
diff -u -r1.2 -r1.3 --- SvtGainConverter.java 4 Oct 2013 01:49:23 -0000 1.2 +++ SvtGainConverter.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -3,7 +3,6 @@
import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException;
-import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager; import org.lcsim.hps.conditions.ConditionsRecord;
@@ -13,7 +12,7 @@
/** * This class creates a {@link SvtGainCollection} from the conditions database. * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: SvtGainConverter.java,v 1.2 2013/10/04 01:49:23 jeremy Exp $
+ * @version $Id: SvtGainConverter.java,v 1.3 2013/10/04 06:02:19 jeremy Exp $
*/ public class SvtGainConverter extends DatabaseConditionsConverter<SvtGainCollection> {
@@ -39,34 +38,28 @@
String fieldName = record.getFieldName(); int fieldValue = record.getFieldValue();
- // References to database objects. - Statement statement = null; - ResultSet resultSet = null; - Connection connection = null; -
// Objects for building the return value. SvtGainCollection collection = new SvtGainCollection();
- try { - - // Get a connection from the manager. - connection = ConnectionManager.createConnection(); - - // Get the name of the current database being used. - String database = ConnectionManager.getConnectionParameters().getDatabase();
+ // Get a connection from the manager. + ConnectionManager connectionManager = ConnectionManager.getConnectionManager(); + Connection connection = connectionManager.createConnection(); + + // Get the name of the current database being used. + String database = connectionManager.getConnectionParameters().getDatabase();
- // Construct the query to find matching calibration records using the ID field. - String query = "SELECT svt_channel_id, gain, offset FROM " - + database + "." + tableName - + " WHERE " - + fieldName + " = " + fieldValue - + " ORDER BY svt_channel_id ASC";
+ // Construct the query to find matching calibration records using the ID field. + String query = "SELECT svt_channel_id, gain, offset FROM " + + database + "." + tableName + + " WHERE " + + fieldName + " = " + fieldValue + + " ORDER BY svt_channel_id ASC";
- // Execute the query and get the results. - statement = connection.createStatement(); - resultSet = statement.executeQuery(query); - - // Loop over the calibration records.
+ // Execute the query and get the results. + ResultSet resultSet = connectionManager.query(connection, query); + + try { + // Loop over the gain records.
while(resultSet.next()) { // Create the object with this channel's gain parameters. int channelId = resultSet.getInt(1);
@@ -77,22 +70,10 @@
} catch (SQLException x) { throw new RuntimeException("Database error.", x); } finally {
- // Cleanup the SQL statement. - if (statement != null) { - try { - statement.close(); - } catch (Exception xx) { - } - } - // Cleanup the connection. - if (connection != null) { - try { - connection.close(); - } catch (Exception x) { - } - }
+ connectionManager.cleanup(resultSet); + connectionManager.cleanup(connection);
}
- // Return the collection of channel constants to caller.
+ // Return collection of gain objects to caller.
return collection; }
diff -N ChannelConstantsCollection.java --- ChannelConstantsCollection.java 4 Oct 2013 02:03:33 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,26 +0,0 @@
-package org.lcsim.hps.conditions.svt; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * This is a set of ChannelConstant objects mapped to their IDs (from the database). - * @author Jeremy McCormick <[log in to unmask]> - */ -public class ChannelConstantsCollection extends LinkedHashMap<Integer,ChannelConstants> { - - ChannelConstantsCollection() { - } - - ChannelConstants getChannelConstants(Integer channelId) { - return this.get(channelId); - } - - public String toString() { - StringBuffer buff = new StringBuffer(); - for (Map.Entry<Integer,ChannelConstants> entry : entrySet()) { - buff.append(entry.getKey() + " => " + entry.getValue()); - } - return buff.toString(); - } -}
diff -u -r1.11 -r1.12 --- DefaultEtEventProcessor.java 5 Jun 2013 16:01:29 -0000 1.11 +++ DefaultEtEventProcessor.java 4 Oct 2013 06:02:19 -0000 1.12 @@ -26,7 +26,7 @@
* having a direct reference to the actual application. * * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DefaultEtEventProcessor.java,v 1.11 2013/06/05 16:01:29 jeremy Exp $
+ * @version $Id: DefaultEtEventProcessor.java,v 1.12 2013/10/04 06:02:19 jeremy Exp $
*/ public class DefaultEtEventProcessor implements EtEventProcessor {
@@ -211,11 +211,15 @@
} public void processEtEvent(EtEvent mev) throws EventProcessingException, MaxEventsException {
-
+
// Check if max events was reached or exceeded. if (maxEvents != -1 && eventsProcessed >= maxEvents) { throw new MaxEventsException(); }
+ + if (mev == null) { + throw new EventProcessingException("supplied EtEvent is null"); + }
// Notify listeners of start of event. startOfEvent();
@@ -229,6 +233,11 @@
// Create EvioEvent from EtEvent. try { evioEvent = createEvioEvent(mev);
+ + if (evioEvent == null) { + throw new EventProcessingException("createEvioEvent returned null EvioEvent"); + } +
//let event builder check for run information eventBuilder.readEvioEvent(evioEvent);
diff -u -r1.2 -r1.3 --- EtEventProcessor.java 3 May 2012 16:59:28 -0000 1.2 +++ EtEventProcessor.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -61,6 +61,10 @@
EventProcessingException(String m, Exception e) { super(m, e); }
+ + EventProcessingException(String m) { + super(m); + }
} // Exception that is thrown when max number of events is reached or exceeded.
diff -u -r1.58 -r1.59 --- MonitoringApplication.java 5 Jun 2013 20:49:38 -0000 1.58 +++ MonitoringApplication.java 4 Oct 2013 06:02:19 -0000 1.59 @@ -32,7 +32,6 @@
import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Dimension;
-import java.awt.GraphicsConfiguration;
import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets;
@@ -61,7 +60,6 @@
import java.util.logging.Logger; import javax.imageio.ImageIO;
-import javax.swing.BorderFactory;
import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JMenu;
@@ -94,8 +92,12 @@
* calling its main() method. * * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: MonitoringApplication.java,v 1.58 2013/06/05 20:49:38 jeremy Exp $
+ * @version $Id: MonitoringApplication.java,v 1.59 2013/10/04 06:02:19 jeremy Exp $
*/
+// FIXME: Review minimum size settings to see which are actually being respected. Remove where not needed. +// FIXME: Since this class is almost 2k lines, might want to refactor into multiple classes. +// TODO: Capture std err and out and redirect to a text panel within the app. +// TODO: Review use of Resettable and Redrawable to see if they can be removed and standard Driver API used instead.
public class MonitoringApplication { // Top-level Swing components.
@@ -752,7 +754,7 @@
eventProcessor.setLogLevel(newLevel); }
- log("Log Level was changed to <" + jobPanel.getLogLevel().toString() + ">.");
+ log(Level.INFO, "Log Level was changed to <" + jobPanel.getLogLevel().toString() + ">.");
} /*
@@ -844,7 +846,8 @@
} /**
- * End of job.
+ * End of job actions. This cleans up the Monitoring Application to put + * it into the proper state for subsequent disconnection from the ET ring.
*/ public void finish() {
@@ -886,10 +889,10 @@
// Disconnect from remote AIDA session if active. if (server != null) {
- log(Level.CONFIG, "Closing remote AIDA server.");
+ log(Level.INFO, "Closing remote AIDA server.");
server.close(); server = null;
- log(Level.CONFIG, "Remote AIDA server was closed.");
+ log(Level.INFO, "Remote AIDA server was closed.");
} } catch (Exception e) { e.printStackTrace();
@@ -905,7 +908,7 @@
eventPanel.setRunNumber(runNumber); eventPanel.setRunStartTime(millis); log(Level.INFO, "Set run number <" + runNumber + "> from Pre Start.");
- log(Level.INFO, "Pre Start time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
+ log(Level.INFO, "Run start time <" + EventPanel.dateFormat.format(new Date(millis)) + "> from Pre Start.");
} /**
@@ -916,7 +919,7 @@
eventPanel.setRunEndTime(millis); eventPanel.setRunEventCount(events); log(Level.INFO, "Set number of events in run to <" + events + ">.");
- log(Level.INFO, "End Event time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
+ log(Level.INFO, "End run time <" + EventPanel.dateFormat.format(new Date(millis)) + ">.");
} }
@@ -926,10 +929,9 @@
* @param status The connection status. */ private void setConnectionStatus(int status) {
- //System.out.println("setConnectionStatus = " + ConnectionStatus.toString(status));
connectionStatus = status; connectionStatusPanel.setStatus(status);
- log("Connection status changed to <" + ConnectionStatus.toString(status) + ">.");
+ log(Level.FINE, "Connection status changed to <" + ConnectionStatus.toString(status) + ">.");
logHandler.flush(); }
@@ -1322,11 +1324,12 @@
} /**
- * Execute a monitoring session.
+ * Execute a monitoring session. This is executed in a separate thread so as + * not to block the GUI or other threads during a monitoring session.
*/ private void session() {
- log("Starting a new monitoring session.");
+ log(Level.INFO, "Starting a new monitoring session.");
int endStatus = ConnectionStatus.DISCONNECTING;
@@ -1396,7 +1399,7 @@
// Create a new event processor. eventProcessor = new DefaultEtEventProcessor(this.connection, this.eventBuilder, this.jobManager, getMaxEvents(), disconnectOnError(), this.logHandler);
- // Add the application's listener for callback to the GUI.
+ // Add the application's listener for callbacks to the GUI components.
eventProcessor.addListener(this.etListener); // Set pause mode from JobPanel, after which it can be toggled using the event buttons.
@@ -1513,8 +1516,6 @@
eventProcessor.stop(); }
- -
// Set the application status from the caller. setConnectionStatus(status);
@@ -1532,9 +1533,8 @@
/** * This is a thread for cleaning up the ET connection. This is executed
- * under a separate path of execution, because it could potentially block - * forever. So we need to be able to kill it after waiting for X amount of - * time.
+ * under a separate thread, because it could potentially block forever. + * So we need to be able to kill it after waiting for X amount of time.
*/ private class EtCleanupThread extends Thread {
@@ -1566,25 +1566,26 @@
if (connection != null) {
- // Put cleanup on a separate thread in case it hangs forever.
+ // Execute the connection cleanup thread.
EtCleanupThread cleanupThread = new EtCleanupThread();
- log(Level.FINEST, "Starting EtCleanupThread to disconnect from ET system.");
+ log(Level.FINE, "Starting EtCleanupThread to disconnect from ET system.");
logHandler.flush(); cleanupThread.start(); try {
- // Wait for cleanup thread to finish.
+ // Wait X seconds for cleanup thread to finish.
cleanupThread.join(this.maxCleanupTime); } catch (InterruptedException e) { e.printStackTrace(); } if (cleanupThread.succeeded()) {
- log("EtCleanupThread succeeded in disconnecting from ET system.");
+ log(Level.FINE, "EtCleanupThread succeeded in disconnecting from ET system.");
} else { log(Level.SEVERE, "EtCleanupThread failed to disconnect. Your station <" + this.connection.stat.getName() + "> is zombified."); // Make the cleanup thread yield. cleanupThread.stopCleanup(); // Stop the cleanup thread.
+ // FIXME: Should call yield() instead?
cleanupThread.stop(); // Join to cleanup thread until it dies. log(Level.FINEST, "Waiting for EtCleanupThread to die");
@@ -1600,7 +1601,7 @@
*/ private void setupLCSim() {
- log("Setting up LCSim.");
+ log(Level.INFO, "Setting up LCSim.");
// Clear the static AIDA tree in case plots are hanging around from previous sessions. resetAidaTree();
@@ -1611,12 +1612,12 @@
// Get steering resource or file as a String parameter. String steering = getSteering(); int steeringType = jobPanel.getSteeringType();
- log(Level.FINE, "LCSim using steering <" + steering + "> of type <" + (steeringType == JobPanel.RESOURCE ? "RESOURCE" : "FILE") + ">.");
+ log(Level.CONFIG, "LCSim steering <" + steering + "> of type <" + (steeringType == JobPanel.RESOURCE ? "RESOURCE" : "FILE") + ">.");
// Check if the LCSim steering file looks valid. if (jobPanel.checkSteering() == false) {
- log(Level.SEVERE, "Steering file or resource <" + steering + "> is not valid."); - throw new RuntimeException("Invalid steering file or resource < " + steering + ">.");
+ log(Level.SEVERE, "Steering file <" + steering + "> is not valid."); + throw new RuntimeException("Invalid LCSim steering file < " + steering + ">.");
} try {
@@ -1624,19 +1625,19 @@
jobManager = new JobControlManager(); jobManager.setPerformDryRun(true); if (steeringType == JobPanel.RESOURCE) {
- log(Level.FINE, "Setting up steering resource <" + steering + ">.");
+ log(Level.CONFIG, "Setting up steering resource <" + steering + ">.");
InputStream is = this.getClass().getClassLoader().getResourceAsStream(steering); jobManager.setup(is); is.close(); } else if (getSteeringType() == JobPanel.FILE) {
- log(Level.FINE, "Setting up steering file <" + steering + ">.");
+ log(Level.CONFIG, "Setting up steering file <" + steering + ">.");
jobManager.setup(new File(steering)); }
- // Call configure to fire conditions setup.
+ // Call configure to trigger conditions setup and other initialization.
jobManager.configure();
- // Reset the reference to the event builder.
+ // Setup the event builder to translate from EVIO to LCIO.
createEventBuilder(); } // Catch all other setup exceptions and re-throw them as RuntimeExceptions. catch (Exception e) {
@@ -1645,7 +1646,7 @@
throw new RuntimeException(LCSIM_FAIL_MESSAGE, e); }
- log(Level.CONFIG, "LCSim setup was successful.");
+ log(Level.INFO, "LCSim setup was successful.");
} /**
@@ -1656,7 +1657,7 @@
// Setup the EventBuilder class. String eventBuilderClassName = getEventBuilderClassName();
- log("Initializing event builder <" + eventBuilderClassName + ">.");
+ log(Level.CONFIG, "Initializing event builder <" + eventBuilderClassName + ">.");
try { eventBuilder = (LCSimEventBuilder) Class.forName(eventBuilderClassName).newInstance();
@@ -1667,7 +1668,7 @@
// Set the detector name on the event builder so it can find conditions data. eventBuilder.setDetectorName(getDetectorName());
- log("Successfully initialized event builder <" + eventBuilderClassName + ">.");
+ log(Level.INFO, "Successfully initialized event builder <" + eventBuilderClassName + ">.");
} /**
@@ -1701,9 +1702,9 @@
// Set status to connected as there is now a live ET connection. setConnectionStatus(ConnectionStatus.CONNECTED);
- log("Created ET connection to <" + connectionParameters.etName + ">.");
+ log(Level.CONFIG, "Created ET connection to <" + connectionParameters.etName + ">.");
} else {
- // An error occurred.
+ // Some error occurred and the connection is not valid.
setConnectionStatus(ConnectionStatus.ERROR); log(Level.SEVERE, "Failed to create ET connection to <" + connectionParameters.etName + ">."); throw new RuntimeException("Failed to create ET connection.");
@@ -1760,8 +1761,7 @@
StringBuffer buf = new StringBuffer(); Vector<Vector> rows = logTableModel.getDataVector(); for (Vector row : (Vector<Vector>) rows) {
- buf.append(row.get(0).toString() + '\t' + row.get(1).toString() + '\t' + row.get(2).toString() + '\t' + row.get(3).toString() - + '\n');
+ buf.append(row.get(0).toString() + '\t' + row.get(1).toString() + '\t' + row.get(2).toString() + '\t' + row.get(3).toString() + '\n');
} try { BufferedWriter out = new BufferedWriter(new FileWriter(logFile.getPath()));
@@ -1782,7 +1782,7 @@
*/ private void clearLog() { logTableModel.setRowCount(0);
- log("Log was cleared.");
+ log(Level.FINE, "Log table was cleared.");
} /**
@@ -1800,7 +1800,7 @@
*/ private void next() { if (connectionStatus == ConnectionStatus.CONNECTED) {
- log(Level.FINE, "Notifying event processor to get next events.");
+ log(Level.FINER, "Notifying event processor to get next events.");
eventProcessor.nextEvents(); } else { log(Level.WARNING, "Ignored next events command because app is disconnected.");
@@ -1836,7 +1836,7 @@
eventProcessor.pauseMode(true); buttonsPanel.setPauseModeState(true); jobPanel.enablePauseMode(false);
- log(Level.FINEST, "Enabled pause mode.");
+ log(Level.FINER, "Enabled pause mode.");
} }
diff -u -r1.2 -r1.3 --- ConditionsLoaderTest.java 4 Oct 2013 02:03:33 -0000 1.2 +++ ConditionsLoaderTest.java 4 Oct 2013 06:02:19 -0000 1.3 @@ -39,26 +39,21 @@
} // Load the SVT and ECAL conditions.
- ConditionsLoader loader = new ConditionsLoader();
+ ConditionsLoader loader = new ConditionsLoader(manager);
loader.load(); // Check SVT conditions. SvtConditions svt = loader.getSvtConditions();
- System.out.println();
+ assertNotNull(svt);
System.out.println("Printing SVT conditions ...");
- System.out.println();
System.out.println(svt);
- assertNotNull(svt);
assertEquals("Wrong number of SVT channels in map.", SVT_CHANNELS, svt.getChannelMap().size()); // Check ECAL conditions. EcalConditions ecal = loader.getEcalConditions();
+ assertNotNull(ecal);
System.out.println("Printing ECAL conditions ...");
- System.out.println();
System.out.println(ecal);
- assertNotNull(ecal);
assertEquals("Wrong number of ECAL channels in map.", ECAL_CHANNELS, ecal.getChannelMap().size()); }
- -} -
+}
\ No newline at end of file
diff -u -r1.9 -r1.10 --- DatabaseConditionsReaderTest.java 4 Oct 2013 02:03:33 -0000 1.9 +++ DatabaseConditionsReaderTest.java 4 Oct 2013 06:02:19 -0000 1.10 @@ -43,7 +43,7 @@
CachedConditions<ConditionsRecordCollection> c2 = manager.getCachedConditions(ConditionsRecordCollection.class, null); ConditionsRecordCollection rc = c2.getCachedData();
- for (ConditionsRecord r : rc.values()) {
+ for (ConditionsRecord r : rc) {
ps.println(r.toString()); }
diff -u -r1.3 -r1.4 --- EcalConditionsLoaderTest.java 2 Oct 2013 23:19:55 -0000 1.3 +++ EcalConditionsLoaderTest.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -26,7 +26,7 @@
} // Test that the loader returns valid conditions.
- EcalConditionsLoader loader = new EcalConditionsLoader();
+ EcalConditionsLoader loader = new EcalConditionsLoader(manager);
loader.load(); EcalConditions conditions = loader.getEcalConditions(); assertNotNull(conditions);
diff -u -r1.3 -r1.4 --- SvtConditionsLoaderTest.java 4 Oct 2013 01:43:48 -0000 1.3 +++ SvtConditionsLoaderTest.java 4 Oct 2013 06:02:19 -0000 1.4 @@ -34,7 +34,7 @@
} // Test that the loader returns valid conditions.
- SvtConditionsLoader loader = new SvtConditionsLoader();
+ SvtConditionsLoader loader = new SvtConditionsLoader(manager);
loader.load(); SvtConditions conditions = loader.getSvtConditions(); assertNotNull(conditions);
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1