12 removed files
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ChannelCollection.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ChannelCollection.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,10 +0,0 @@
-package org.lcsim.hps.conditions;
-
-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> {
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsConstants.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsConstants.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,55 +0,0 @@
-package org.lcsim.hps.conditions;
-
-/**
- * Constants for HPS conditions system, such as conditions set key names.
- */
-public final class ConditionsConstants {
-
- /** Prevent instantiation of this class, which is only a holder of static constant values. */
- private ConditionsConstants() {}
-
- /** Conditions key for ConditionsRecord. */
- public static final String CONDITIONS_RECORD = "conditions_record";
-
- /** Conditions key for combined ECal conditions. */
- public static final String ECAL_CONDITIONS = "ecal_conditions";
-
- /** Table with ECal channel data. */
- public static final String ECAL_CHANNELS = "ecal_channels";
-
- /** Conditions key for ECal gain data. */
- public static final String ECAL_GAINS = "ecal_gains";
-
- /** Conditions key for ECal bad channel set. */
- public static final String ECAL_BAD_CHANNELS = "ecal_bad_channels";
-
- /** Conditions key for ECal calibration information. */
- public static final String ECAL_CALIBRATIONS = "ecal_calibrations";
-
- /** Conditions key for combined ECal conditions. */
- public static final String SVT_CONDITIONS = "svt_conditions";
-
- /** Table with SVT channel data. */
- public static final String SVT_CHANNELS = "svt_channels";
-
- /** Table with the SVT DAQ map. */
- public static final String SVT_DAQ_MAP = "svt_daq_map";
-
- /** Conditions key for SVT calibration data. */
- public static final String SVT_CALIBRATIONS = "svt_calibrations";
-
- /** Conditions key for SVT bad channels. */
- public static final String SVT_BAD_CHANNELS = "svt_bad_channels";
-
- /** Conditions key for SVT pulse parameters. */
- public static final String SVT_PULSE_PARAMETERS = "svt_pulse_parameters";
-
- /** Conditions key for SVT gain data. */
- public static final String SVT_GAINS = "svt_gains";
-
- /** Conditions key for SVT time shifts by sensor. */
- public static final String SVT_TIME_SHIFTS = "svt_time_shifts";
-
- /** Conditions key for integrated beam current. */
- public static final String BEAM_CURRENT = "beam_current";
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsConverterRegister.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsConverterRegister.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,76 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.hps.conditions.beam.BeamCurrentConverter;
-import org.lcsim.hps.conditions.ecal.EcalBadChannelConverter;
-import org.lcsim.hps.conditions.ecal.EcalCalibrationConverter;
-import org.lcsim.hps.conditions.ecal.EcalChannelMapConverter;
-import org.lcsim.hps.conditions.ecal.EcalConditionsConverter;
-import org.lcsim.hps.conditions.ecal.EcalGainConverter;
-import org.lcsim.hps.conditions.svt.PulseParametersConverter;
-import org.lcsim.hps.conditions.svt.SvtBadChannelConverter;
-import org.lcsim.hps.conditions.svt.SvtCalibrationConverter;
-import org.lcsim.hps.conditions.svt.SvtChannelMapConverter;
-import org.lcsim.hps.conditions.svt.SvtConditionsConverter;
-import org.lcsim.hps.conditions.svt.SvtDaqMapConverter;
-import org.lcsim.hps.conditions.svt.SvtGainConverter;
-import org.lcsim.hps.conditions.svt.SvtTimeShiftConverter;
-
-/**
- * This class registers the full set of conditions converters onto the manager.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-class ConditionsConverterRegister {
-
- /**
- * This method will register all the conditions converters onto the given manager.
- * @param manager The conditions manager.
- */
- static void register(ConditionsManager manager) {
-
- // ConditionsRecords with validity meta data.
- manager.registerConditionsConverter(new ConditionsRecordConverter());
-
- // SVT channel map.
- manager.registerConditionsConverter(new SvtChannelMapConverter());
-
- // SVT DAQ map.
- manager.registerConditionsConverter(new SvtDaqMapConverter());
-
- // SVT calibrations.
- manager.registerConditionsConverter(new SvtCalibrationConverter());
-
- // SVT gains.
- manager.registerConditionsConverter(new SvtGainConverter());
-
- // SVT bad channels.
- manager.registerConditionsConverter(new SvtBadChannelConverter());
-
- // SVT time shift by sensor.
- manager.registerConditionsConverter(new SvtTimeShiftConverter());
-
- // SVT combined conditions.
- manager.registerConditionsConverter(new SvtConditionsConverter());
-
- // ECAL bad channels.
- manager.registerConditionsConverter(new EcalBadChannelConverter());
-
- // ECAL channel map.
- manager.registerConditionsConverter(new EcalChannelMapConverter());
-
- // ECAL gains.
- manager.registerConditionsConverter(new EcalGainConverter());
-
- // ECAL calibrations.
- manager.registerConditionsConverter(new EcalCalibrationConverter());
-
- // ECAL pulse parameters.
- manager.registerConditionsConverter(new PulseParametersConverter());
-
- // ECAL combined conditions.
- manager.registerConditionsConverter(new EcalConditionsConverter());
-
- // Beam current condition.
- manager.registerConditionsConverter(new BeamCurrentConverter());
- }
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsDriver.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsDriver.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,49 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.geometry.Detector;
-import org.lcsim.hps.conditions.ecal.EcalConditions;
-import org.lcsim.hps.conditions.ecal.EcalConditionsLoader;
-import org.lcsim.hps.conditions.svt.SvtConditions;
-import org.lcsim.hps.conditions.svt.SvtConditionsLoader;
-import org.lcsim.util.Driver;
-
-import static org.lcsim.hps.conditions.ConditionsConstants.SVT_CONDITIONS;
-import static org.lcsim.hps.conditions.ConditionsConstants.ECAL_CONDITIONS;
-
-/**
- * This {@link org.lcsim.util.Driver} loads conditions onto an HPS detector.
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class ConditionsDriver extends Driver {
-
- /**
- * This method updates a new detector with SVT and ECal conditions data.
- */
- public void detectorChanged(Detector detector) {
- loadSvtConditions(detector);
- loadEcalConditions(detector);
- }
-
- /**
- * Load the SVT conditions onto the Detector.
- * @param detector The detector to update.
- */
- private void loadSvtConditions(Detector detector) {
- ConditionsManager manager = ConditionsManager.defaultInstance();
- SvtConditions conditions = manager.getCachedConditions(SvtConditions.class, SVT_CONDITIONS).getCachedData();
- SvtConditionsLoader loader = new SvtConditionsLoader();
- loader.load(detector, conditions);
- }
-
- /**
- * Load the ECal conditions onto the Detector.
- * @param detector The detector to update.
- */
- private void loadEcalConditions(Detector detector) {
- ConditionsManager manager = ConditionsManager.defaultInstance();
- EcalConditions conditions = manager.getCachedConditions(EcalConditions.class, ECAL_CONDITIONS).getCachedData();
- EcalConditionsLoader loader = new EcalConditionsLoader();
- loader.load(detector, conditions);
- }
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecord.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecord.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,261 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import static org.lcsim.hps.conditions.ConditionsConstants.CONDITIONS_RECORD;
-
-import java.sql.Blob;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-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,
- * which defines the run validity range for a specific conditions set.
- *
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class ConditionsRecord {
-
- 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();
- }
-
- /**
- * Find a ConditionsRecord with conditions key matching <code>name</code>.
- * @param manager The current conditions manager.
- * @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 ConditionsRecordCollection find(ConditionsManager manager, String name) {
- CachedConditions<ConditionsRecordCollection> c = manager.getCachedConditions(ConditionsRecordCollection.class, CONDITIONS_RECORD);
- 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;
- }
-
- /**
- * 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();
-
- ConnectionManager manager = ConnectionManager.getConnectionManager();
- String db = manager.getConnectionParameters().getDatabase();
- String table = manager.getConnectionParameters().getConditionsTable();
-
- String query = "SELECT * FROM "
- + db + "." + table
- + " WHERE "
- + "run_start <= "
- + run
- + " AND run_end >= "
- + run;
-
- ResultSet resultSet = manager.query(query);
-
- // Iterate over conditions records.
- try {
- while (resultSet.next()) {
- ConditionsRecord record = new ConditionsRecord();
- record.load(resultSet);
- conditionsRecords.add(record);
- }
- } catch (SQLException x) {
- throw new RuntimeException("Database error", x);
- }
-
- return conditionsRecords;
- }
-}
\ No newline at end of file
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecordCollection.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecordCollection.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,26 +0,0 @@
-package org.lcsim.hps.conditions;
-
-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 ArrayList<ConditionsRecord> {
-
- /**
- * Find a ConditionsRecord by its name or key in this collection.
- * 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 : this) {
- if (rec.getName().equals(name)) {
- records.add(rec);
- }
- }
- return records;
- }
-}
\ No newline at end of file
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecordConverter.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConditionsRecordConverter.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,65 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import java.sql.ResultSet;
-import java.sql.SQLException;
-
-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.5 2013/10/15 23:24:47 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) {
-
- ConditionsRecordCollection records = new ConditionsRecordCollection();
-
- ConnectionManager connectionManager = this.getConnectionManager();
- String tableName = connectionManager.getConnectionParameters().getConditionsTable();
-
- String query = "SELECT * from "
- + tableName
- + " WHERE "
- + "run_start <= "
- + manager.getRun()
- + " AND run_end >= "
- + manager.getRun();
-
- ResultSet resultSet = connectionManager.query(query);
-
- try {
- while(resultSet.next()) {
- ConditionsRecord record = new ConditionsRecord();
- record.load(resultSet);
- records.add(record);
- }
- } catch (SQLException x) {
- throw new RuntimeException("Database error", 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
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConnectionManager.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConnectionManager.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,150 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-/**
- * This class provides various database utilities for the conditions system, primarily the
- * converter classes.
- *
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class ConnectionManager {
-
- private ConnectionParameters connectionParameters = new ConnectionParameters();
- private static ConnectionManager instance = null;
- private Connection connection = 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;
- }
-
- /**
- * Create a connection to the database.
- * @return The database connection.
- */
- Connection createConnection() {
- Connection newConnection = connectionParameters.createConnection();
- try {
- newConnection.createStatement().execute("USE " + connectionParameters.getDatabase());
- } catch (SQLException e) {
- throw new RuntimeException("Failed to connect to database.", e);
- }
- return newConnection;
- }
-
- /**
- * 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);
- }
- }
- }
-
- /**
- * 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);
- }
- }
- }
-
- /**
- * This method can be used to perform a database query.
- * @param query The SQL query string.
- * @return The ResultSet from the query or null.
- */
- public ResultSet query(String query) {
- if (connection == null)
- connection = createConnection();
- 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 void disconnect() {
- cleanup(connection);
- }
-
- /**
- * 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();
- Properties p = new Properties();
- try {
- p.load(new FileInputStream(new File(config)));
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- connectionParameters = ConnectionParameters.fromProperties(p);
- }
- }
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConnectionParameters.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/ConnectionParameters.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,129 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.util.Properties;
-
-/**
- * This class encapsulates the parameters for connecting to a database,
- * including hostname, port, user and password. It can also create and
- * return a Connection object based on these parameters.
- * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: ConnectionParameters.java,v 1.8 2013/10/04 01:54:16 jeremy Exp $
- */
-public final class ConnectionParameters {
-
- /** Default values for the MySQL test database at SLAC. */
- private String user = "rd_hps_cond_ro";
- private String password = "2jumpinphotons.";
- private int port = 3306;
- private String hostname = "mysql-node03.slac.stanford.edu";
- private String database = "rd_hps_cond";
- private String conditionsTable = "conditions_dev";
-
- /**
- * No argument constructor that uses the defaults.
- */
- ConnectionParameters() {
- }
-
- /**
- * Fully qualified constructor.
- * @param user The user name.
- * @param password The password.
- * @param hostname The hostname.
- * @param port The port number.
- * @param conditionsTable The table containing conditions validity data.
- */
- ConnectionParameters(String user, String password, String database, String hostname, int port, String conditionsTable) {
- this.user = user;
- this.password = password;
- this.database = database;
- this.hostname = hostname;
- this.port = port;
- this.conditionsTable = conditionsTable;
- }
-
- /**
- * Get Properties object for this connection.
- * @return The Properties for this connection.
- */
- public Properties getConnectionProperties() {
- Properties p = new Properties();
- p.put("user", user);
- p.put("password", password);
- return p;
- }
-
- /**
- * Get the hostname.
- * @return The hostname.
- */
- public String getHostname() {
- return hostname;
- }
-
- /**
- * Get the port number.
- * @return The port number.
- */
- public int getPort() {
- return port;
- }
-
- /**
- * Get the name of the database.
- * @return The name of the database.
- */
- public String getDatabase() {
- return database;
- }
-
- /**
- * Get the connection string for these parameters.
- * @return The connection string.
- */
- public String getConnectionString() {
- return "jdbc:mysql://" + hostname + ":" + port + "/";
- }
-
- /**
- * Get the name of the conditions validity data.
- * @return The name of the conditions validity data table.
- */
- public String getConditionsTable() {
- return conditionsTable;
- }
-
- /**
- * Create a database connection from these parameters.
- * The caller is responsible for closing it when finished.
- * @return The Connection object.
- */
- public Connection createConnection() {
- Properties connectionProperties = getConnectionProperties();
- Connection connection = null;
- try {
- connection = DriverManager.getConnection(getConnectionString(), connectionProperties);
- } catch (SQLException x) {
- throw new RuntimeException("Failed to connect to database: " + getConnectionString(), x);
- }
- return connection;
- }
-
- /**
- * Create ConnectionParameters from data in a properties file.
- * @param properties The properties file.
- * @return The ConnectionParameters created from the properties file.
- */
- public static final ConnectionParameters fromProperties(Properties properties) {
- String user = properties.get("user").toString();
- String password = properties.getProperty("password").toString();
- String database = properties.getProperty("database").toString();
- String hostname = properties.getProperty("hostname").toString();
- int port = Integer.parseInt(properties.getProperty("port").toString());
- String conditionsTable = properties.getProperty("conditionsTable").toString();
- return new ConnectionParameters(user, password, database, hostname, port, conditionsTable);
- }
-}
\ No newline at end of file
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/DatabaseConditionsConverter.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/DatabaseConditionsConverter.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,21 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import org.lcsim.conditions.ConditionsConverter;
-
-/**
- * This class is basically just a typedef right now but functionality may be added here
- * that all converters can use.
- * @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
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/DatabaseConditionsReader.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/DatabaseConditionsReader.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,164 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.conditions.ConditionsReader;
-
-/**
- * <p>
- * This a rewritten version of Dima's ExampleDatabaseConditionsReader that attempts to handle
- * the conditions and their meta data in a fully generic fashion.
- * </p>
- *
- * <p>
- * In order to override the default database connection parameters, the system property
- * <code>hps.conditions.db.configuration</code> should point to a properties file defining
- * the variables read by ConnectionParameters (see that class for details). Otherwise, the
- * defaults will be used to connect to a test database at SLAC.
- * <p>
- *
- * <p>
- * Setting custom connection properties would look something like the following from the CL:
- * </p>
- *
- * <p><code>java -Dhps.conditions.db.configuration=/path/to/my/config.prop [...]</code></p>
- *
- * <p>
- * Currently, this class should "know" directly about all the converters that are needed for loading
- * conditions data via the <code>registerConditionsConverters</code> method.
- * </p>
- *
- * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: DatabaseConditionsReader.java,v 1.21 2013/10/18 06:08:55 jeremy Exp $
- */
-public class DatabaseConditionsReader extends ConditionsReader {
-
- /** Database connection. */
- private Connection connection = null;
-
- /** Base ConditionsReader for getting the Detector. */
- private final ConditionsReader reader;
-
- /** The current run number to determine if conditions are already loaded. */
- private int currentRun = Integer.MIN_VALUE;
-
- /** Converter for making ConditionsRecord objects from the database. */
- ConditionsRecordConverter conditionsRecordConverter = new ConditionsRecordConverter();
-
- /** The logger for printing messages. */
- static Logger logger = null;
-
- /**
- * Class constructor taking a ConditionsReader. This constructor is automatically called
- * by the ConditionsManager when this type of reader has been requested via the detector
- * properties file.
- *
- * @param reader The basic ConditionsReader allowing access to the detector.
- */
- public DatabaseConditionsReader(ConditionsReader reader) {
- this.reader = reader;
-
- setupLogger();
- }
-
- /**
- * Setup the logger.
- */
- private final void setupLogger() {
- if (logger == null) {
- logger = Logger.getLogger(this.getClass().getSimpleName());
- logger.setUseParentHandlers(false);
- logger.setLevel(Level.ALL);
- ConsoleHandler handler = new ConsoleHandler();
- handler.setFormatter(new ConditionsFormatter());
- logger.addHandler(handler);
- }
- }
-
- /**
- * Simple log formatter for this class.
- */
- private static final class ConditionsFormatter extends Formatter {
-
- public String format(LogRecord record) {
- StringBuilder sb = new StringBuilder();
- sb.append(record.getLoggerName() + " [ " + record.getLevel() + " ] " + record.getMessage() + '\n');
- return sb.toString();
- }
- }
-
- /**
- * 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 {
-
- logger.info("updating detector <" + detectorName + "> for run <" + run + "> ...");
-
- // Check if conditions are already cached for the run.
- if (run == currentRun) {
- logger.warning("Conditions already cached for run <" + run + ">.");
- return false;
- }
-
- // Register the converters on the manager.
- // FIXME: This should really only happen once instead of being called here every time.
- ConditionsConverterRegister.register(manager);
-
- // Open a connection to the database.
- connection = ConnectionManager.getConnectionManager().createConnection();
-
- // Cache the ConditionsRecords.
- try {
- setup(run);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- // Close the database connection.
- try {
- connection.close();
- connection = null;
- } catch (SQLException x) {
- throw new IOException("Failed to close connection", x);
- }
-
- return true;
- }
-
- /**
- * Close the base reader.
- */
- public void close() throws IOException {
- reader.close();
- }
-
- /**
- * Implementation of ConditionReader API method.
- * @return An InputStream with the conditions for <code>type</code>.
- */
- public InputStream open(String name, String type) throws IOException {
- return reader.open(name, type);
- }
-
- /**
- * This will cache the ConditionsRecords for the run.
- * @param run The run number.
- * @throws SQLException
- * @throws IOException
- */
- private final void setup(int run) throws SQLException, IOException {
- ConditionsRecord.find(run);
- }
-}
java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions
--- java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/TestRunConditionsReader.java 2013-12-03 18:14:27 UTC (rev 59)
+++ java/trunk/hps-java/src/main/java/org/lcsim/hps/conditions/TestRunConditionsReader.java 2013-12-03 21:34:34 UTC (rev 60)
@@ -1,61 +0,0 @@
-package org.lcsim.hps.conditions;
-
-import java.io.IOException;
-import java.io.InputStream;
-import org.lcsim.conditions.ConditionsManager;
-import org.lcsim.conditions.ConditionsReader;
-
-/**
- *
- * @author Sho Uemura <[log in to unmask]>
- * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: TestRunConditionsReader.java,v 1.4 2013/10/17 23:04:19 jeremy Exp $
- */
-public class TestRunConditionsReader extends DatabaseConditionsReader {
-
- private String detectorName = null;
- //private int run;
-
- public TestRunConditionsReader(ConditionsReader reader) {
- super(reader);
- }
-
- public InputStream open(String name, String type) throws IOException {
- // 1) Check the detector base directory.
- InputStream in = getClass().getResourceAsStream("/" + detectorName + "/" + name + "." + type);
- if (in == null) {
- // 2) Check for embedded jar resources.
- in = getClass().getResourceAsStream("/org/lcsim/hps/calib/testrun/" + name + "." + type);
- if (in == null) {
- // 3) Use super's open method.
- in = super.open(name, type);
-
- // If all of these failed to find conditions, then something went wrong.
- if (in == null) {
- throw new IOException("Conditions " + name + " for " + detectorName + " with type " + type + " were not found");
- }
- }
- }
- return in;
- }
-
- public void close() throws IOException {
- }
-
-
- public boolean update(ConditionsManager manager, String detectorName, int run) throws IOException {
-// loadCalibsByRun(run);
-// Detector detector = manager.getCachedConditions(Detector.class,"compact.xml").getCachedData();
-// HPSEcalConditions.detectorChanged(detector, "Ecal");
-// HPSSVTCalibrationConstants.loadCalibration(run);
- this.detectorName = detectorName;
- //this.run = run;
- super.update(manager, detectorName, run);
-// System.out.println(detectorName+run);
- return true;
- }
-// private void loadCalibsByRun(int run) {
-// HPSSVTCalibrationConstants.loadCalibration(run);
-// FieldMap.loadFieldMap(run);
-// }
-}
SVNspam 0.1