3 added + 4 modified, total 7 files
hps-java/src/main/java/org/lcsim/hps/conditions
diff -N ConditionsRecord.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConditionsRecord.java 24 Sep 2013 02:40:21 -0000 1.1
@@ -0,0 +1,279 @@
+package org.lcsim.hps.conditions;
+
+import java.io.Serializable;
+import java.sql.Blob;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Date;
+
+import org.lcsim.conditions.CachedConditions;
+import org.lcsim.conditions.ConditionsManager;
+
+/**
+ * This class represents a single record from the primary conditions data table
+ * that defines validity for a conditions set.
+ *
+ * @author Jeremy McCormick <[log in to unmask]>
+ */
+public class ConditionsRecord implements Serializable {
+
+ int id;
+ int runStart;
+ int runEnd;
+ Date updated;
+ Date created;
+ Date validFrom;
+ Date validTo;
+ String createdBy;
+ String notes;
+ String name;
+ String formatVersion;
+ String tableName;
+ String fieldName;
+ int fieldValue;
+
+ protected ConditionsRecord() {
+ }
+
+ /**
+ * Load state into this object from a ResultSet, which must be positioned a priori
+ * to the correct row number.
+ * @param rs The ResultSet containing database records from the conditions table.
+ */
+ void load(ResultSet rs) {
+ try {
+ id = rs.getInt(1);
+ runStart = rs.getInt(2);
+ runEnd = rs.getInt(3);
+ updated = rs.getTimestamp(4);
+ created = rs.getDate(5);
+ validFrom = rs.getDate(6);
+ validTo = rs.getDate(7);
+ createdBy = rs.getString(8);
+ Blob blob = rs.getBlob(9);
+ if (blob != null) {
+ byte[] blobData = blob.getBytes(1, (int)blob.length());
+ notes = new String(blobData);
+ }
+ name = rs.getString(10);
+ formatVersion = rs.getString(11);
+ tableName = rs.getString(12);
+ fieldName = rs.getString(13);
+ fieldValue = rs.getInt(14);
+
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Get the unique ID.
+ * @return The unique ID.
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * Get the starting run number.
+ * @return The starting run number.
+ */
+ public int getRunStart() {
+ return runStart;
+ }
+
+ /**
+ * Get the ending run number.
+ * @return The ending run number.
+ */
+ public int getRunEnd() {
+ return runEnd;
+ }
+
+ /**
+ * Get the date this record was last updated.
+ * @return The date this record was updated.
+ */
+ public Date getUpdated() {
+ return updated;
+ }
+
+ /**
+ * Get the date this record was created.
+ * @return The date this record was created.
+ */
+ public Date getCreated() {
+ return created;
+ }
+
+ /**
+ * Get the starting valid time.
+ * @return The starting valid time.
+ */
+ public Date getValidFrom() {
+ return validFrom;
+ }
+
+ /**
+ * Get the ending valid time.
+ * @return The ending valid time.
+ */
+ public Date getValidTo() {
+ return validTo;
+ }
+
+ /**
+ * Get the name of the user who created this record.
+ * @return The name of the person who created the record.
+ */
+ public String getCreatedBy() {
+ return createdBy;
+ }
+
+ /**
+ * Get the notes.
+ * @return The notes about this condition.
+ */
+ public String getNotes() {
+ return notes;
+ }
+
+ /**
+ * Get the name of these conditions, which should be unique by run number.
+ * @return The name of the conditions.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Get the version of the format these conditions are stored in.
+ * @return The conditions version.
+ */
+ public String getFormatVersion() {
+ return formatVersion;
+ }
+
+ /**
+ * Get the name of the table containing the actual raw conditions data.
+ * @return The name of the table with the conditions data.
+ */
+ public String getTableName() {
+ return tableName;
+ }
+
+ /**
+ * Get the field that will define which set of conditions to fetch.
+ * @return The field used as a group ID of the conditions.
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * Get the value of the identifying field.
+ * @return The value of identifying field for these conditions.
+ */
+ public int getFieldValue() {
+ return fieldValue;
+ }
+
+ /**
+ * Convert this record to a human readable string, one field per line.
+ * @return This object represented as a string.
+ */
+ public String toString() {
+ StringBuffer buff = new StringBuffer();
+ buff.append("id: " + id + '\n');
+ buff.append("runStart: " + runStart + '\n');
+ buff.append("runEnd: " + runEnd + '\n');
+ buff.append("updated: " + updated + '\n');
+ buff.append("created: " + created + '\n');
+ buff.append("validFrom: " + validFrom + '\n');
+ buff.append("validTo: " + validTo + '\n');
+ buff.append("createdBy: " + createdBy + '\n');
+ buff.append("notes: " + notes + '\n');
+ buff.append("formatVersion: " + formatVersion + '\n');
+ buff.append("tableName: " + tableName + '\n');
+ buff.append("fieldName: " + fieldName + '\n');
+ buff.append("fieldValue: " + fieldValue + '\n');
+ return buff.toString();
+ }
+
+ /**
+ * 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.
+ * @param manager The current conditions manager.
+ * @param name The name of the ConditionsSet.
+ * @return The ConditionsRecord called <code>name</code> for the current run.
+ */
+ public static ConditionsRecord find(ConditionsManager manager, String name) {
+ CachedConditions<ConditionsRecordCollection> c = manager.getCachedConditions(ConditionsRecordCollection.class, "");
+ ConditionsRecordCollection conditionsRecords = c.getCachedData();
+ conditionsRecords = conditionsRecords.find(name);
+ if (conditionsRecords.size() == 0) {
+ throw new IllegalArgumentException("No ConditionsRecord with name: " + name);
+ }
+ if (conditionsRecords.size() > 1) {
+ throw new IllegalArgumentException("Duplicate ConditionsRecord with name: " + name);
+ }
+ return conditionsRecords.values().toArray(new ConditionsRecord[1])[0];
+ }
+
+ /**
+ * Find conditions records of all types in the database by run number.
+ * @param run The run number.
+ * @return The set of matching ConditionsRecords.
+ */
+ public static ConditionsRecordCollection find(int run) {
+
+ ConditionsRecordCollection conditionsRecords = new ConditionsRecordCollection();
+
+ String db = ConnectionManager.getConnectionParameters().getDatabase();
+ String table = ConnectionManager.getConnectionParameters().getConditionsTable();
+ Connection connection = ConnectionManager.createConnection();
+
+ String query = "SELECT * FROM "
+ + db + "." + table
+ + " WHERE "
+ + "run_start <= "
+ + run
+ + " AND run_end >= "
+ + run;
+
+ Statement statement = null;
+ try {
+ statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery(query);
+
+ // Iterate over conditions records.
+ while (resultSet.next()) {
+ ConditionsRecord record = new ConditionsRecord();
+ record.load(resultSet);
+ conditionsRecords.put(record);
+ }
+ } catch (SQLException x) {
+ throw new RuntimeException(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);
+ }
+ }
+ }
+ return conditionsRecords;
+ }
+
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/conditions
diff -N ConditionsRecordCollection.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConditionsRecordCollection.java 24 Sep 2013 02:40:21 -0000 1.1
@@ -0,0 +1,42 @@
+package org.lcsim.hps.conditions;
+
+import java.util.LinkedHashMap;
+
+/**
+ * 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;
+ }
+
+ /**
+ * Find a ConditionsRecord by its name or key. This is the 'name' field from the conditions database table.
+ * @param name The name of the conditions set, e.g. 'svt_calibrations' etc.
+ * @return The collection of ConditionsRecords, which can be empty if none were found.
+ */
+ public ConditionsRecordCollection find(String name) {
+ ConditionsRecordCollection records = new ConditionsRecordCollection();
+ for (ConditionsRecord rec : values()) {
+ if (rec.getName().equals(name)) {
+ records.put(rec.getId(), rec);
+ }
+ }
+ return records;
+ }
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/conditions
diff -N ConditionsRecordConverter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ConditionsRecordConverter.java 24 Sep 2013 02:40:21 -0000 1.1
@@ -0,0 +1,87 @@
+package org.lcsim.hps.conditions;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import org.lcsim.conditions.ConditionsManager;
+
+/**
+ * Read from conditions database and create SVT calibration data.
+ *
+ * @author Omar Moreno <[log in to unmask]>
+ * @version $Id: ConditionsRecordConverter.java,v 1.1 2013/09/24 02:40:21 jeremy Exp $
+ */
+public class ConditionsRecordConverter extends DatabaseConditionsConverter<ConditionsRecordCollection> {
+
+ /**
+ * Class constructor.
+ */
+ public ConditionsRecordConverter() {
+ }
+
+ /**
+ * Get the ConditionsRecords for a run. This method ignores the name argument
+ * and will fetch all conditions records for the current run.
+ * @param manager The current conditions manager.
+ * @param name The name of the conditions set.
+ * @return The matching ConditionsRecords.
+ */
+ public ConditionsRecordCollection getData(ConditionsManager manager, String name) {
+
+ Statement statement = null;
+ ResultSet resultSet = null;
+ Connection connection = null;
+
+ ConditionsRecordCollection records = new ConditionsRecordCollection();
+
+ 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);
+ }
+ } 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) {
+ }
+ }
+ }
+ return records;
+ }
+
+ /**
+ * Get the type handled by this converter.
+ * @return The type handled by this converter, which is <code>ConditionsRecordCollection</code>.
+ */
+ public Class<ConditionsRecordCollection> getType() {
+ return ConditionsRecordCollection.class;
+ }
+}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/conditions
diff -u -r1.3 -r1.4
--- DatabaseConditionsConverter.java 20 Sep 2013 21:56:24 -0000 1.3
+++ DatabaseConditionsConverter.java 24 Sep 2013 02:40:21 -0000 1.4
@@ -2,5 +2,5 @@
import org.lcsim.conditions.ConditionsConverter;
-public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {
+public abstract class DatabaseConditionsConverter<T> implements ConditionsConverter<T> {
}
\ No newline at end of file
hps-java/src/main/java/org/lcsim/hps/conditions
diff -u -r1.6 -r1.7
--- DatabaseConditionsReader.java 23 Sep 2013 23:09:10 -0000 1.6
+++ DatabaseConditionsReader.java 24 Sep 2013 02:40:21 -0000 1.7
@@ -1,15 +1,11 @@
package org.lcsim.hps.conditions;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
-import java.util.HashMap;
-import java.util.Properties;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
import java.util.logging.Level;
@@ -38,7 +34,7 @@
* currently, but more will be added as they are created.
*
* @author jeremym
- * @version $Id: DatabaseConditionsReader.java,v 1.6 2013/09/23 23:09:10 jeremy Exp $
+ * @version $Id: DatabaseConditionsReader.java,v 1.7 2013/09/24 02:40:21 jeremy Exp $
*/
public class DatabaseConditionsReader extends ConditionsReader {
@@ -56,9 +52,9 @@
/** Current maximum run number. This is updated as conditions are loaded. */
private int maxRun = Integer.MIN_VALUE;
-
- /** This maps conditions types to their table, field, and set id. */
- private final HashMap<String, byte[]> propertyCache = new HashMap<String, byte[]>();
+
+ /** Converter for making ConditionsRecord objects from the database. */
+ ConditionsRecordConverter conditionsRecordConverter = new ConditionsRecordConverter();
/** The logger for printing messages. */
static Logger logger = null;
@@ -103,43 +99,47 @@
}
/**
- * Update conditions for possibly new detector and run number. This will cache the
- * conditions meta data but will not automatically do any conversion.
+ * Update conditions for possibly new detector and run number.
* @param manager The current conditions manager.
* @param detectorName The detector name.
* @param run The run number.
*/
public boolean update(ConditionsManager manager, String detectorName, int run) throws IOException {
+ System.out.println("update");
+
+ logger.info("update");
+ logger.info(" detectorName: " + detectorName);
+ logger.info(" run: " + run);
+
// Setup detector.
if (this.detectorName == null) {
this.detectorName = detectorName;
- logger.info("set detector name: " + this.detectorName);
+ logger.info("set detectorName: " + this.detectorName);
} else {
if (!this.detectorName.equals(detectorName))
throw new IllegalArgumentException();
}
// Check if conditions for this run are already loaded.
- if (run <= maxRun && run >= minRun)
+ if (run <= maxRun && run >= minRun) {
+ logger.info("conditions already cached");
return false;
+ }
+
+ // Register the converters on the manager.
+ registerConditionsConverters(manager);
- // Clear the property cache.
- propertyCache.clear();
-
// Open a connection to the database.
connection = ConnectionManager.createConnection();
- // Register the conditions converters.
- registerConditionsConverters(manager);
-
- // Cache the meta data for the fetched conditions records.
+ // Cache the run numbers.
try {
- cacheDataIdent(run);
+ setup(run);
} catch (Exception e) {
throw new RuntimeException(e);
}
-
+
// Close the database connection.
try {
connection.close();
@@ -147,7 +147,7 @@
} catch (SQLException x) {
throw new IOException("Failed to close connection", x);
}
-
+
return true;
}
@@ -163,113 +163,39 @@
* @return An InputStream with the cached properties for <code>name</code>.
*/
public InputStream open(String name, String type) throws IOException {
- byte[] ba = propertyCache.get(name);
- if (ba == null) {
- return reader.open(name, type);
- } else {
- return new ByteArrayInputStream(ba);
- }
+ return reader.open(name, type);
}
/**
- * This will cache the conditions meta data for a run so that the actual data can be fetched later.
+ * This will cache the run numbers so that the actual data can be fetched later.
* @param run The run number.
* @throws SQLException
* @throws IOException
*/
- private final void cacheDataIdent(int run) throws SQLException, IOException {
-
- logger.info("cacheDataIdent");
-
- String db = ConnectionManager.getConnectionParameters().getDatabase();
- String table = ConnectionManager.getConnectionParameters().getConditionsTable();
-
- String query = "SELECT run_start, run_end, name, table_name, field_name, field_value FROM "
- + db + "." + table
- + " WHERE "
- + "run_start <= "
- + run
- + " AND run_end >= "
- + run;
+ private final void setup(int run) throws SQLException, IOException {
+
+ ConditionsRecordCollection records = ConditionsRecord.find(run);
- logger.info(query);
-
- Statement statement = null;
- try {
- statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery(query);
+ for (ConditionsRecord record : records.values()) {
- // Iterate over conditions records.
- while (resultSet.next()) {
-
- // The minimum run number.
- minRun = resultSet.getInt(1);
-
- // The maximum run number.
- maxRun = resultSet.getInt(2);
-
- // The name of the conditions used as a key for lookup.
- String name = resultSet.getString(3);
-
- // The name of the table containing the actual data.
- String tableName = resultSet.getString(4);
-
- // The field used to ID the data set.
- String fieldName = resultSet.getString(5);
-
- // The value of the ID field.
- int fieldValue = resultSet.getInt(6);
-
- // Cache the meta data for later use by converters.
- addDataKey(name, tableName, fieldName, fieldValue);
+ if (record.getRunStart() < minRun) {
+ minRun = record.getRunStart();
+ logger.info("Set min run: " + minRun);
}
- } finally {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException x) {
- throw new IOException("Failed to close statement", x);
- }
+
+ if (record.getRunEnd() > maxRun) {
+ maxRun = record.getRunEnd();
+ logger.info("Set max run: " + maxRun);
}
- }
- }
-
- /**
- * Register meta data properties for a certain condition type.
- * This includes table name, column name, and the id field.
- * The information is later used by the converters to create the application
- * data objects from SQL queries.
- * @param key The key of the conditions. (for instance "svt_calibration")
- * @param data The raw string data from the data_ident field in the database.
- * @throws IOException if the data format is wrong.
- * @throws IllegalArgumentException if the key already exists.
- */
- private void addDataKey(String key, String tableName, String columnName, int value) {
-
- logger.info("addDataKey: " + key + " => " + tableName + ":" + columnName + ":" + value);
-
- if (propertyCache.get(key) != null) {
- throw new IllegalArgumentException("Duplicate key found for condition: " + key);
- }
-
- Properties p = new Properties();
- p.put("table", tableName);
- p.put("column", columnName);
- p.put("id", new Integer(value).toString());
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- try {
- p.store(stream, null);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- propertyCache.put(key, stream.toByteArray());
+ }
}
-
+
/**
* Register the default conditions converters.
* @param manager The ConditionsManager.
*/
- private void registerConditionsConverters(ConditionsManager manager) {
+ private void registerConditionsConverters(ConditionsManager manager) {
+ manager.registerConditionsConverter(new ConditionsRecordConverter());
manager.registerConditionsConverter(new SvtCalibrationConverter());
// TODO: Add other converters here as they are made available.
}
hps-java/src/main/java/org/lcsim/hps/conditions/svt
diff -u -r1.7 -r1.8
--- SvtCalibrationConverter.java 23 Sep 2013 23:09:10 -0000 1.7
+++ SvtCalibrationConverter.java 24 Sep 2013 02:40:21 -0000 1.8
@@ -6,18 +6,20 @@
import java.sql.Statement;
import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.conditions.ConditionsSet;
+import org.lcsim.hps.conditions.ConditionsRecord;
import org.lcsim.hps.conditions.ConnectionManager;
import org.lcsim.hps.conditions.DatabaseConditionsConverter;
/**
- * Read from conditions database and create SVT calibration data.
- *
+ * Read SVT calibration data from the conditions database.
* @author Omar Moreno <[log in to unmask]>
- * @version $Id: SvtCalibrationConverter.java,v 1.7 2013/09/23 23:09:10 jeremy Exp $
+ * @version $Id: SvtCalibrationConverter.java,v 1.8 2013/09/24 02:40:21 jeremy Exp $
*/
public class SvtCalibrationConverter extends DatabaseConditionsConverter<ChannelConstantsCollection> {
-
+
+ /** The name of the table in the database containing the channel IDs. */
+ private static final String CHANNEL_TABLE = "svt_channels";
+
/**
* Class constructor.
*/
@@ -25,41 +27,55 @@
}
/**
- * Get the channel constants data by name.
+ * Get the SVT channel constants by named conditions set.
* @param manager The current conditions manager.
* @param name The name of the conditions set.
* @return The channel constants data.
*/
public ChannelConstantsCollection getData(ConditionsManager manager, String name) {
-
- ChannelConstants constants = null;
- ChannelConstantsCollection collection = new ChannelConstantsCollection();
+ // Get the ConditionsRecord with the meta-data, which will use the current run number.
+ ConditionsRecord record = ConditionsRecord.find(manager, name);
+
+ // Get the table name, field name, and field value defining the applicable conditions for this run.
+ 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.
+ ChannelConstants constants = null;
+ ChannelConstantsCollection collection = new ChannelConstantsCollection();
try {
-
- ConditionsSet conditionsSet = manager.getConditions(name);
- String database = ConnectionManager.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();
+
+ // Construct the query to find matching calibration records using the ID field.
String query = "SELECT channel_id, fpga, hybrid, channel, noise, pedestal FROM "
- + database + "." + conditionsSet.getString("table") + ", "
- + database + "." + "svt_channels"
+ + database + "." + tableName + ", "
+ + database + "." + CHANNEL_TABLE
+ " WHERE "
- + conditionsSet.getString("column") + " = " + conditionsSet.getString("id")
- + " AND svt_channels.id = " + conditionsSet.getString("table") + ".channel_id "
+ + fieldName + " = " + fieldValue
+ + " AND svt_channels.id = " + tableName + ".channel_id "
+ "ORDER BY svt_channels.id ASC";
- System.out.println(query);
-
+ // 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.
int channelId = resultSet.getInt(1);
int fpga = resultSet.getInt(2);
int hybrid = resultSet.getInt(3);
@@ -67,19 +83,21 @@
double noise = resultSet.getDouble(5);
double pedestal = resultSet.getDouble(6);
- constants = new ChannelConstants(fpga, hybrid, channel, pedestal, noise, Double.NaN, Double.NaN, null);
-
+ // Add channel constants to the return collection.
+ constants = new ChannelConstants(fpga, hybrid, channel, pedestal, noise, Double.NaN, Double.NaN, null);
collection.put(channelId, constants);
}
} catch (SQLException x) {
- throw new RuntimeException("Database error", 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();
@@ -87,15 +105,15 @@
}
}
}
+ // 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>ChannelConstantsCollection</code>.
+ * Get the type handled by this converter.
+ * @return The type handled by this converter, which is <code>ConditionsRecordCollection</code>.
*/
public Class<ChannelConstantsCollection> getType() {
return ChannelConstantsCollection.class;
}
-}
+}
\ No newline at end of file
hps-java/src/test/java/org/lcsim/hps/conditions
diff -u -r1.5 -r1.6
--- DatabaseConditionsReaderTest.java 23 Sep 2013 23:09:10 -0000 1.5
+++ DatabaseConditionsReaderTest.java 24 Sep 2013 02:40:21 -0000 1.6
@@ -8,7 +8,6 @@
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
import org.lcsim.conditions.ConditionsSet;
-import org.lcsim.hps.conditions.svt.ChannelConstants;
import org.lcsim.hps.conditions.svt.ChannelConstantsCollection;
/**
@@ -43,17 +42,23 @@
throw new RuntimeException(e);
}
- ConditionsSet conditions = manager.getConditions(conditionsSetName);
- ps.println("Got conditions " + conditionsSetName + " of size " + conditions.size());
- ps.println("table: " + conditions.getString("table"));
- ps.println("column: " + conditions.getString("column"));
- ps.println("id: " + conditions.getString("id"));
-
- CachedConditions<ChannelConstantsCollection> c = manager.getCachedConditions(ChannelConstantsCollection.class, conditionsSetName);
- ChannelConstantsCollection calibration = c.getCachedData();
- System.out.println("Got calibration conditions ... ");
- System.out.println(calibration);
- System.out.println("Success!");
+ //ConditionsSet conditions = manager.getConditions(conditionsSetName);
+ //ps.println("Got conditions " + conditionsSetName + " of size " + conditions.size());
+ //ps.println("table: " + conditions.getString("table"));
+ //ps.println("column: " + conditions.getString("column"));
+ //ps.println("id: " + conditions.getString("id"));
+
+ CachedConditions<ConditionsRecordCollection> c2 = manager.getCachedConditions(ConditionsRecordCollection.class, null);
+ ConditionsRecordCollection rc = c2.getCachedData();
+ for (ConditionsRecord r : rc.values()) {
+ ps.println(r.toString());
+ }
+ CachedConditions<ChannelConstantsCollection> c = manager.getCachedConditions(ChannelConstantsCollection.class, conditionsSetName);
+ ChannelConstantsCollection calibration = c.getCachedData();
+ assertTrue("Calibration object is null.", calibration != null);
+ //System.out.println("Got calibration conditions ... ");
+ //System.out.println(calibration);
+ //System.out.println("Success!");
}
}
\ No newline at end of file
CVSspam 0.2.12