Author: [log in to unmask]
Date: Fri Aug 26 17:25:33 2016
New Revision: 4471
Log:
Do some code cleanup of conditions system with extreme prejudice; remove special handling of test run conditions in db manager; remove usage of conditions XML config that is not really needed; refactor connection setup into separate class handling all cases; get run manager connection settings from conditions config (on dev branch).
Added:
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionSetup.java
Modified:
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/RunSummaryCommand.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/TagCommand.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/AbstractConditionsObjectConverter.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsSeriesConverter.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsTagConverter.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java
java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/api/ConditionsTagTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/database/DatabaseConditionsManagerTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectCollectionTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtBadChannelsTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtConditionsConverterTest.java
java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtDaqMappingTest.java
java/branches/jeremy-dev/detector-model/src/test/java/org/hps/detector/svt/TestRunSvtDetectorSetupTest.java
java/branches/jeremy-dev/evio/src/main/java/org/hps/evio/EvioToLcio.java
java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java
java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimTestRunEventBuilderTest.java
java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/TestRunSvtEvioReaderTest.java
java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java
java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioEventUtilities.java
java/branches/jeremy-dev/run-database/src/main/java/org/hps/rundb/RunManager.java
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java Fri Aug 26 17:25:33 2016
@@ -70,11 +70,6 @@
public final void initialize() {
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
-
- if (this.xmlConfigResource != null) {
- // Set a custom XML configuration resource.
- conditionsManager.setXmlConfig(this.xmlConfigResource);
- }
if (this.tag != null) {
// Set a tag for filtering ConditionsRecord objects.
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/AddCommand.java Fri Aug 26 17:25:33 2016
@@ -137,15 +137,12 @@
collectionId, createdBy, notes);
LOGGER.info("inserting conditions record ..." + '\n' + conditionsRecord);
try {
- boolean createdConnection = false;
final DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
- if (!DatabaseConditionsManager.getInstance().isConnected()) {
- createdConnection = manager.openConnection();
- }
+ manager.openConnection();
conditionsRecord.setConnection(manager.getConnection());
conditionsRecord.setTableMetaData(TableRegistry.getTableRegistry().findByTableName("conditions"));
conditionsRecord.insert();
- manager.closeConnection(createdConnection);
+ manager.closeConnection();
} catch (final SQLException | DatabaseObjectException e) {
LOGGER.log(Level.SEVERE, "Error adding conditions record", e);
throw new RuntimeException("An error occurred while adding a conditions record.", e);
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/CommandLineTool.java Fri Aug 26 17:25:33 2016
@@ -183,13 +183,6 @@
LOGGER.config("using connection properties " + connectionPropertiesFile.getPath());
}
- // Conditions system XML configuration file.
- if (commandLine.hasOption("x")) {
- final File xmlConfigFile = new File(commandLine.getOptionValue("x"));
- this.conditionsManager.setXmlConfig(xmlConfigFile);
- LOGGER.config("using XML config " + xmlConfigFile.getPath());
- }
-
// User specified tag of conditions records.
if (commandLine.hasOption("t")) {
final String tag = commandLine.getOptionValue("t");
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/LoadCommand.java Fri Aug 26 17:25:33 2016
@@ -70,12 +70,9 @@
}
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
-
- boolean openedConnection = false;
- if (!conditionsManager.isConnected()) {
- openedConnection = conditionsManager.openConnection();
- }
-
+
+ conditionsManager.openConnection();
+
String description = null;
if (commandLine.hasOption("d")) {
description = commandLine.getOptionValue("d");
@@ -114,9 +111,9 @@
} catch (SQLException | DatabaseObjectException e) {
throw new RuntimeException("Error getting collection ID.", e);
}
-
- conditionsManager.closeConnection(openedConnection);
-
+
+ conditionsManager.closeConnection();
+
LOGGER.info("Collection was loaded successfully!");
}
}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java Fri Aug 26 17:25:33 2016
@@ -89,10 +89,6 @@
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- if (!conditionsManager.isInitialized()) {
- throw new RuntimeException("conditions system is not initialized");
- }
-
// Print conditions sets matching a specific conditions key.
String userConditionsKey = null;
if (commandLine.hasOption("t")) {
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/RunSummaryCommand.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/RunSummaryCommand.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/RunSummaryCommand.java Fri Aug 26 17:25:33 2016
@@ -58,10 +58,6 @@
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- if (!conditionsManager.isInitialized()) {
- throw new RuntimeException("The conditions system is not initialized.");
- }
-
final int run = conditionsManager.getRun();
final boolean printAll = commandLine.hasOption("a");
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/TagCommand.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/TagCommand.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/cli/TagCommand.java Fri Aug 26 17:25:33 2016
@@ -148,9 +148,6 @@
promptBeforeTagging = false;
}
LOGGER.config("prompt before tagging = " + promptBeforeTagging);
-
- // Conditions system configuration.
- this.getManager().setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
// Find all the applicable conditions records by their run number ranges.
ConditionsRecordCollection tagConditionsRecordCollection = this.findConditionsRecords(runStart, runEnd);
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/AbstractConditionsObjectConverter.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/AbstractConditionsObjectConverter.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/AbstractConditionsObjectConverter.java Fri Aug 26 17:25:33 2016
@@ -81,9 +81,6 @@
// Get the DatabaseConditionsManager which is required for using this converter.
final DatabaseConditionsManager databaseConditionsManager = (DatabaseConditionsManager) conditionsManager;
- // Setup connection if necessary.
- final boolean openedConnection = databaseConditionsManager.openConnection();
-
// Get the TableMetaData from the table name.
final TableMetaData tableMetaData = TableRegistry.getTableRegistry().findByTableName(name);
@@ -139,11 +136,6 @@
+ " with collection ID " + conditionsRecord.getCollectionId(), e);
}
- if (openedConnection) {
- // Close connection if one was opened.
- databaseConditionsManager.closeConnection();
- }
-
return (T) collection;
}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsRecordConverter.java Fri Aug 26 17:25:33 2016
@@ -31,13 +31,6 @@
public ConditionsRecordCollection getData(final ConditionsManager manager, final String name) {
final DatabaseConditionsManager databaseConditionsManager = DatabaseConditionsManager.getInstance();
-
- // Setup connection if necessary.
- boolean reopenedConnection = false;
- if (!databaseConditionsManager.isConnected()) {
- databaseConditionsManager.openConnection();
- reopenedConnection = true;
- }
final TableMetaData tableMetaData = databaseConditionsManager.findTableMetaData(name);
@@ -77,10 +70,6 @@
// Close the ResultSet and Statement.
DatabaseUtilities.cleanup(resultSet);
- if (reopenedConnection) {
- databaseConditionsManager.closeConnection();
- }
-
return this.getType().cast(collection);
}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsSeriesConverter.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsSeriesConverter.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsSeriesConverter.java Fri Aug 26 17:25:33 2016
@@ -62,13 +62,6 @@
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- // Setup connection if necessary.
- boolean reopenedConnection = false;
- if (!conditionsManager.isConnected()) {
- conditionsManager.openConnection();
- reopenedConnection = true;
- }
-
// Get the table meta data for the collection type.
final TableMetaData tableMetaData = conditionsManager.findTableMetaData(tableName);
if (tableMetaData == null) {
@@ -99,10 +92,6 @@
series.add((ConditionsObjectCollection<ObjectType>) collection);
}
- if (reopenedConnection) {
- conditionsManager.closeConnection();
- }
-
// Return new collection.
return series;
}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsTagConverter.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsTagConverter.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConditionsTagConverter.java Fri Aug 26 17:25:33 2016
@@ -39,7 +39,6 @@
if (dbConditionsManager == null) {
throw new IllegalArgumentException("The conditions manager has the wrong type.");
}
- boolean openedConnection = dbConditionsManager.openConnection();
Connection connection = DatabaseConditionsManager.getInstance().getConnection();
try {
PreparedStatement statement = connection.prepareStatement(SELECT_SQL);
@@ -55,9 +54,7 @@
throw new RuntimeException(e);
} catch (ConditionsObjectException e) {
throw new RuntimeException(e);
- } finally {
- dbConditionsManager.closeConnection(openedConnection);
- }
+ }
if (conditionsTagCollection.size() == 0) {
throw new IllegalArgumentException("The conditions tag " + name + " does not exist in the database.");
}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionParameters.java Fri Aug 26 17:25:33 2016
@@ -217,7 +217,7 @@
*
* @return the name of the database
*/
- String getDatabase() {
+ public String getDatabase() {
return this.database;
}
@@ -226,7 +226,7 @@
*
* @return the hostname
*/
- String getHostname() {
+ public String getHostname() {
return this.hostname;
}
@@ -235,7 +235,7 @@
*
* @return the password
*/
- String getPassword() {
+ public String getPassword() {
return this.password;
}
@@ -244,7 +244,7 @@
*
* @return the port number
*/
- int getPort() {
+ public int getPort() {
return this.port;
}
@@ -253,7 +253,7 @@
*
* @return the user name
*/
- String getUser() {
+ public String getUser() {
return this.user;
}
Added: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionSetup.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionSetup.java (added)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/ConnectionSetup.java Fri Aug 26 17:25:33 2016
@@ -0,0 +1,98 @@
+package org.hps.conditions.database;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * Setup database connection for conditions system from optional system property settings
+ * or supply a default connection. Connection properties file or resource may also be
+ * specified directly, overriding any possible settings from the environment.
+ *
+ * @author Jeremy McCormick, SLAC
+ */
+public class ConnectionSetup {
+
+ private ConnectionParameters connectionParameters = ConnectionParameters.fromResource(DEFAULT_CONNECTION_PROPERTIES_RESOURCE);
+
+ private Connection connection = null;
+
+ /**
+ * Name of system property that can be used to specify custom database connection parameters.
+ */
+ private static final String CONNECTION_PROPERTY_FILE = "org.hps.conditions.connection.file";
+
+ /**
+ * Connection property resource.
+ */
+ private static final String CONNECTION_PROPERTY_RESOURCE = "org.hps.conditions.connection.resource";
+
+ /**
+ * The connection properties resource for connecting to the default JLAB database.
+ */
+ private static final String DEFAULT_CONNECTION_PROPERTIES_RESOURCE = "/org/hps/conditions/config/jlab_connection.prop";
+
+ public synchronized void openConnection() {
+ if (connection == null) {
+ connection = connectionParameters.createConnection();
+ }
+ }
+
+ public synchronized Connection getConnection() {
+ openConnection();
+ return connection;
+ }
+
+ public synchronized void closeConnection() {
+ if (connection != null) {
+ try {
+ if (!connection.isClosed()) {
+ connection.close();
+ }
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ connection = null;
+ }
+ }
+
+ public synchronized void setup() {
+
+ // Setup connection from system property pointing to a file, if it was set.
+ fromSystemPropertyFile();
+
+ // Setup connection from system property pointing to a resource, if it was set.
+ fromSystemPropertyResource();
+ }
+
+ public void setConnectionProperties(final File file) {
+ this.connectionParameters = ConnectionParameters.fromProperties(file);
+ }
+
+ public void setConnectionResource(final String resource) {
+ this.connectionParameters = ConnectionParameters.fromResource(resource);
+ }
+
+ public ConnectionParameters getConnectionParameters() {
+ return this.connectionParameters;
+ }
+
+ private void fromSystemPropertyFile() {
+ final String systemPropertiesConnectionPath = (String) System.getProperties().get(CONNECTION_PROPERTY_FILE);
+ if (systemPropertiesConnectionPath != null) {
+ final File f = new File(systemPropertiesConnectionPath);
+ if (!f.exists()) {
+ throw new RuntimeException("Connection properties file from " + CONNECTION_PROPERTY_FILE + " does not exist.");
+ }
+ this.setConnectionProperties(f);
+ }
+ }
+
+ private void fromSystemPropertyResource() {
+ final String systemPropertiesConnectionResource = (String) System.getProperties().get(
+ CONNECTION_PROPERTY_RESOURCE);
+ if (systemPropertiesConnectionResource != null) {
+ this.setConnectionResource(systemPropertiesConnectionResource);
+ }
+ }
+}
Modified: java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java (original)
+++ java/branches/jeremy-dev/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java Fri Aug 26 17:25:33 2016
@@ -1,10 +1,6 @@
package org.hps.conditions.database;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
@@ -29,15 +25,8 @@
import org.hps.conditions.api.TableRegistry;
import org.hps.conditions.ecal.EcalConditions;
import org.hps.conditions.ecal.EcalConditionsConverter;
-import org.hps.conditions.ecal.TestRunEcalConditionsConverter;
import org.hps.conditions.svt.SvtConditions;
import org.hps.conditions.svt.SvtConditionsConverter;
-import org.hps.conditions.svt.TestRunSvtConditionsConverter;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.JDOMException;
-import org.jdom.input.SAXBuilder;
-import org.lcsim.conditions.ConditionsConverter;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsManagerImplementation;
import org.lcsim.geometry.Detector;
@@ -57,46 +46,11 @@
*/
@SuppressWarnings("rawtypes")
public final class DatabaseConditionsManager extends ConditionsManagerImplementation {
-
- /**
- * Name of system property that can be used to specify custom database connection parameters.
- */
- private static final String CONNECTION_PROPERTY_FILE = "org.hps.conditions.connection.file";
-
- /**
- * Connection property resource.
- */
- private static final String CONNECTION_PROPERTY_RESOURCE = "org.hps.conditions.connection.resource";
-
- /**
- * The default XML config.
- */
- private static final String DEFAULT_CONFIG = "/org/hps/conditions/config/conditions_database_prod.xml";
-
- /**
- * The connection properties resource for connecting to the default JLAB database.
- */
- private static final String DEFAULT_CONNECTION_PROPERTIES_RESOURCE = "/org/hps/conditions/config/jlab_connection.prop";
-
- /**
- * The Eng Run XML config.
- */
- private static final String ENGRUN_CONFIG = "/org/hps/conditions/config/conditions_database_engrun.xml";
-
+
/**
* Initialize the logger.
*/
private static Logger LOGGER = Logger.getLogger(DatabaseConditionsManager.class.getPackage().getName());
-
- /**
- * The Test Run XML config.
- */
- private static final String TEST_RUN_CONFIG = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
-
- /**
- * The max value for a run to be considered Test Run.
- */
- private static final int TEST_RUN_MAX_RUN = 1365;
static {
// Set default login timeout of 5 seconds.
@@ -129,17 +83,7 @@
return (DatabaseConditionsManager) manager;
}
-
- /**
- * Utility method to determine if a run number is from the 2012 Test Run.
- *
- * @param runNumber the run number
- * @return <code>true</code> if run number is from the Test Run
- */
- public static boolean isTestRun(final int runNumber) {
- return runNumber > 0 && runNumber <= TEST_RUN_MAX_RUN;
- }
-
+
/**
* Reset the global static instance of the conditions manager to a new object.
*/
@@ -155,16 +99,6 @@
}
/**
- * True to cache all known conditions sets (from keys) during initialization.
- */
- private boolean cacheAllConditions = false;
-
- /**
- * True to close the connection after initialization.
- */
- private boolean closeConnectionAfterInitialize = true;
-
- /**
* The current set of conditions for the run.
*/
private ConditionsRecordCollection conditionsRecordCollection = null;
@@ -175,29 +109,9 @@
private final ConditionsTagCollection conditionsTagCollection = new ConditionsTagCollection();
/**
- * The current database connection.
- */
- private Connection connection;
-
- /**
- * The current connection parameters.
- */
- private ConnectionParameters connectionParameters;
-
- /**
- * The connection properties file, if one is being used from the command line.
- */
- private File connectionPropertiesFile;
-
- /**
* Create the global registry of conditions object converters.
*/
- private final ConverterRegistry converters = ConverterRegistry.create();
-
- /**
- * The converter for creating the combined ECAL conditions object.
- */
- private ConditionsConverter ecalConverter;
+ private final ConverterRegistry objectConverters = ConverterRegistry.create();
/**
* The default ECAL detector name in the detector geometry.
@@ -205,56 +119,11 @@
private String ecalName = "Ecal";
/**
- * True to freeze the system after initialization.
- */
- private boolean freezeAfterInitialize = false;
-
- /**
- * True if the conditions manager was configured from an XML configuration resource or file.
- */
- private boolean isConfigured = false;
-
- /**
- * True if manager is connected to the database.
- */
- private boolean isConnected = false;
-
- /**
* True if the conditions system has been frozen and will ignore updates after it is initialized.
*/
private boolean isFrozen = false;
/**
- * True if the manager has been initialized, e.g. the {@link #setDetector(String, int)} method was called.
- */
- private boolean isInitialized = false;
-
- /**
- * True if current run number is from Test Run.
- */
- private boolean isTestRun = false;
-
- /**
- * Flag used to print connection parameters one time.
- */
- private boolean loggedConnectionParameters = false;
-
- /**
- * True to setup the SVT detector model with conditions.
- */
- private boolean setupSvtDetector = true;
-
- /**
- * The converter for creating the combined SVT conditions object.
- */
- private ConditionsConverter svtConverter;
-
- /**
- * The default SVT name in the detector geometry.
- */
- private String svtName = "Tracker";
-
- /**
* Create the global registry of table meta data.
*/
private final TableRegistry tableRegistry = TableRegistry.getTableRegistry();
@@ -263,28 +132,37 @@
* The currently applied conditions tags.
*/
private final Set<String> tags = new HashSet<String>();
+
+ /**
+ * Wrapper for connection settings and setup.
+ */
+ private ConnectionSetup connectionSetup = new ConnectionSetup();
+
+ /**
+ * Sets whether or not system will accept new detector or run after initial setup.
+ */
+ boolean freezeAfterInitialize;
/**
* Class constructor. Calling this will automatically register this manager as the global default.
*/
protected DatabaseConditionsManager() {
- // Register detector conditions converter.
+ // Setup connection parameters property settings or use default.
+ connectionSetup.setup();
+
+ // Register conditions converters.
this.registerConditionsConverter(new DetectorConditionsConverter());
-
- // Setup connection from system property pointing to a file, if it was set.
- this.setupConnectionSystemPropertyFile();
-
- // Setup connection from system property pointing to a resource, if it was set.
- this.setupConnectionSystemPropertyResource();
-
+ this.registerConditionsConverter(new SvtConditionsConverter());
+ this.registerConditionsConverter(new EcalConditionsConverter());
+
+ // Register conditions converters.
+ for (final AbstractConditionsObjectConverter converter : this.objectConverters.values()) {
+ this.registerConditionsConverter(converter);
+ }
+
// Set run to invalid number.
this.setRun(-1);
-
- // Register conditions converters.
- for (final AbstractConditionsObjectConverter converter : this.converters.values()) {
- this.registerConditionsConverter(converter);
- }
}
/**
@@ -322,21 +200,6 @@
}
/**
- * Cache conditions sets for all known tables.
- */
- private void cacheConditionsSets() {
- for (final TableMetaData meta : this.tableRegistry.values()) {
- try {
- LOGGER.fine("caching conditions " + meta.getKey() + " with type "
- + meta.getCollectionClass().getCanonicalName());
- this.getCachedConditions(meta.getCollectionClass(), meta.getKey());
- } catch (final Exception e) {
- LOGGER.warning("could not cache conditions " + meta.getKey());
- }
- }
- }
-
- /**
* Clear the tags used to filter the {@link org.hps.conditions.api.ConditionsRecord}s.
*/
public void clearTags() {
@@ -345,37 +208,6 @@
}
/**
- * Close the database connection.
- */
- public synchronized void closeConnection() {
- LOGGER.fine("closing connection");
- if (this.connection != null) {
- try {
- if (!this.connection.isClosed()) {
- this.connection.close();
- }
- } catch (final SQLException e) {
- throw new RuntimeException(e);
- }
- }
- this.connection = null;
- this.isConnected = false;
- LOGGER.fine("connection closed");
- }
-
- /**
- * Close the database connection but only if there was a connection opened based on the flag. Otherwise, it should
- * be left open. Used in conjunction with return value of {@link #openConnection()}.
- *
- * @param connectionOpened <code>true</code> to close the connection; <code>false</code> to leave it open
- */
- public synchronized void closeConnection(final boolean connectionOpened) {
- if (connectionOpened) {
- this.closeConnection();
- }
- }
-
- /**
* This method will return <code>true</code> if the given collection ID already exists in the table.
*
* @param tableName the name of the table
@@ -397,32 +229,6 @@
e.printStackTrace();
}
return rowCount != 0;
- }
-
- /**
- * Configure this class from an <code>InputStream</code> which should point to an XML document.
- *
- * @param in the InputStream which should be in XML format
- */
- private void configure(final InputStream in) {
- if (!this.isConfigured) {
- final SAXBuilder builder = new SAXBuilder();
- Document config = null;
- try {
- config = builder.build(in);
- } catch (JDOMException | IOException e) {
- throw new RuntimeException(e);
- }
- this.loadConfiguration(config);
- try {
- in.close();
- } catch (final IOException e) {
- LOGGER.warning(e.getMessage());
- }
- this.isConfigured = true;
- } else {
- LOGGER.warning("System is already configured, so call to configure is ignored!");
- }
}
/**
@@ -475,7 +281,6 @@
*/
public Set<String> getAvailableTags() {
LOGGER.fine("getting list of available conditions tags");
- final boolean openedConnection = this.openConnection();
final Set<String> tags = new LinkedHashSet<String>();
final ResultSet rs = this
.selectQuery("select distinct(tag) from conditions_tags where tag is not null order by tag");
@@ -498,7 +303,6 @@
}
sb.setLength(sb.length() - 1);
LOGGER.fine(sb.toString());
- this.closeConnection(openedConnection);
return tags;
}
@@ -515,12 +319,11 @@
final String caller = Thread.currentThread().getStackTrace()[2].getClassName();
final String log = "created by " + System.getProperty("user.name") + " using "
+ caller.substring(caller.lastIndexOf('.') + 1);
- final boolean opened = this.openConnection();
PreparedStatement statement = null;
ResultSet resultSet = null;
int collectionId = -1;
try {
- statement = this.connection.prepareStatement(
+ statement = connectionSetup.getConnection().prepareStatement(
"INSERT INTO collections (table_name, log, description, created) VALUES (?, ?, ?, NOW())",
Statement.RETURN_GENERATED_KEYS);
statement.setString(1, collection.getTableMetaData().getTableName());
@@ -541,7 +344,6 @@
if (statement != null) {
statement.close();
}
- this.closeConnection(opened);
}
collection.setCollectionId(collectionId);
return collectionId;
@@ -599,18 +401,6 @@
}
/**
- * Get the JDBC connection.
- *
- * @return the JDBC connection
- */
- public Connection getConnection() {
- if (!this.isConnected()) {
- this.openConnection();
- }
- return this.connection;
- }
-
- /**
* Get the current LCSim compact <code>Detector</code> object with the geometry and detector model.
*
* @return the detector object
@@ -678,33 +468,8 @@
LOGGER.config("initializing with detector " + detectorName + " and run " + runNumber);
- // Clear the conditions cache.
- // this.clearCache();
-
- // Set flag if run number is from Test Run 2012 data.
- if (isTestRun(runNumber)) {
- this.isTestRun = true;
- }
-
- // Is not configured yet?
- if (!this.isConfigured) {
- if (this.isTestRun()) {
- // This looks like the Test Run so use the custom configuration for it.
- this.setXmlConfig(DatabaseConditionsManager.TEST_RUN_CONFIG);
- } else if (runNumber > TEST_RUN_MAX_RUN) {
- // Run numbers greater than max of Test Run assumed to be Eng Run (for now!).
- this.setXmlConfig(DatabaseConditionsManager.ENGRUN_CONFIG);
- } else if (runNumber == 0) {
- // Use the default configuration because the run number is basically meaningless.
- this.setXmlConfig(DatabaseConditionsManager.DEFAULT_CONFIG);
- }
- }
-
- // Register the converters for this initialization.
- this.registerConverters();
-
// Open the database connection.
- this.openConnection();
+ connectionSetup.openConnection();
// Reset the conditions records to trigger a re-caching.
this.conditionsRecordCollection = null;
@@ -713,19 +478,9 @@
LOGGER.fine("activating default conditions manager");
super.setDetector(detectorName, runNumber);
- // Should all conditions sets be cached?
- if (this.cacheAllConditions) {
- // Cache the conditions sets of all registered converters.
- LOGGER.fine("caching conditions sets");
- this.cacheConditionsSets();
- }
-
- if (this.closeConnectionAfterInitialize) {
- LOGGER.fine("closing connection after initialization");
- // Close the connection.
- this.closeConnection();
- }
-
+ // Close the database connection.
+ connectionSetup.closeConnection();
+
// Should the conditions system be frozen now?
if (this.freezeAfterInitialize) {
// Freeze the conditions system so subsequent updates will be ignored.
@@ -733,20 +488,9 @@
LOGGER.config("system was frozen after initialization");
}
- this.isInitialized = true;
-
LOGGER.info("conditions system initialized successfully");
}
-
- /**
- * Check if connected to the database.
- *
- * @return <code>true</code> if connected
- */
- public boolean isConnected() {
- return this.isConnected;
- }
-
+
/**
* True if conditions system is frozen
*
@@ -755,88 +499,7 @@
public boolean isFrozen() {
return this.isFrozen;
}
-
- /**
- * True if conditions manager is properly initialized.
- *
- * @return <code>true</code> if the manager is initialized
- */
- public boolean isInitialized() {
- return this.isInitialized;
- }
-
- /**
- * Return <code>true</code> if Test Run configuration is active
- *
- * @return <code>true</code> if Test Run configuration is active
- */
- public boolean isTestRun() {
- return this.isTestRun;
- }
-
- /**
- * Load configuration information from an XML document.
- *
- * @param document the XML document
- */
- private void loadConfiguration(final Document document) {
-
- final Element node = document.getRootElement().getChild("configuration");
-
- if (node == null) {
- return;
- }
-
- Element element = node.getChild("setupSvtDetector");
- if (element != null) {
- this.setupSvtDetector = Boolean.parseBoolean(element.getText());
- LOGGER.config("setupSvtDetector = " + this.setupSvtDetector);
- }
-
- element = node.getChild("ecalName");
- if (element != null) {
- this.setEcalName(element.getText());
- LOGGER.config("ecalName = " + this.getEcalName());
- }
-
- element = node.getChild("svtName");
- if (element != null) {
- this.setSvtName(element.getText());
- LOGGER.config("svtName = " + this.svtName);
- }
-
- element = node.getChild("freezeAfterInitialize");
- if (element != null) {
- this.freezeAfterInitialize = Boolean.parseBoolean(element.getText());
- LOGGER.config("freezeAfterInitialize = " + this.freezeAfterInitialize);
- }
-
- element = node.getChild("cacheAllCondition");
- if (element != null) {
- this.cacheAllConditions = Boolean.parseBoolean(element.getText());
- LOGGER.config("cacheAllConditions = " + this.cacheAllConditions);
- }
-
- element = node.getChild("isTestRun");
- if (element != null) {
- this.isTestRun = Boolean.parseBoolean(element.getText());
- LOGGER.config("isTestRun = " + this.isTestRun);
- }
-
- element = node.getChild("closeConnectionAfterInitialize");
- if (element != null) {
- this.closeConnectionAfterInitialize = Boolean.parseBoolean(element.getText());
- LOGGER.config("closeConnectionAfterInitialize = " + this.closeConnectionAfterInitialize);
- }
-
- element = node.getChild("loginTimeout");
- if (element != null) {
- final Integer timeout = Integer.parseInt(element.getText());
- DriverManager.setLoginTimeout(timeout);
- LOGGER.config("loginTimeout = " + timeout);
- }
- }
-
+
/**
* Create a new collection with the given type.
*
@@ -859,7 +522,7 @@
throw new RuntimeException("Error creating new collection.", e);
}
collection.setTableMetaData(tableMetaData);
- collection.setConnection(this.getConnection());
+ collection.setConnection(connectionSetup.getConnection());
return collection;
}
@@ -880,74 +543,10 @@
throw new RuntimeException("Error creating new collection.", e);
}
collection.setTableMetaData(tableMetaData);
- collection.setConnection(this.getConnection());
+ collection.setConnection(connectionSetup.getConnection());
return collection;
}
-
- /**
- * Open the database connection.
- *
- * @return <code>true</code> if a connection was opened; <code>false</code> if using an existing connection.
- */
- public synchronized boolean openConnection() {
- boolean openedConnection = false;
- if (!this.isConnected) {
- // Do the connection parameters need to be figured out automatically?
- if (this.connectionParameters == null) {
- // Setup the default read-only connection, which will choose a SLAC or JLab database.
- this.connectionParameters = ConnectionParameters.fromResource(DEFAULT_CONNECTION_PROPERTIES_RESOURCE);
- }
-
- if (!this.loggedConnectionParameters) {
- // Print out detailed info to the log on first connection within the job.
- LOGGER.info("opening connection ... " + '\n' + "connection: "
- + this.connectionParameters.getConnectionString() + '\n' + "host: "
- + this.connectionParameters.getHostname() + '\n' + "port: "
- + this.connectionParameters.getPort() + '\n' + "user: " + this.connectionParameters.getUser()
- + '\n' + "database: " + this.connectionParameters.getDatabase());
- this.loggedConnectionParameters = true;
- }
-
- // Create the connection using the parameters.
- this.connection = this.connectionParameters.createConnection();
- this.isConnected = true;
- openedConnection = true;
- }
-
- // Flag to indicate whether an existing connection was used or not.
- return openedConnection;
- }
-
- /**
- * Register the conditions converters with the manager.
- */
- private void registerConverters() {
- if (this.svtConverter != null) {
- // Remove old SVT converter.
- this.removeConditionsConverter(this.svtConverter);
- }
-
- if (this.ecalConverter != null) {
- // Remove old ECAL converter.
- this.registerConditionsConverter(this.ecalConverter);
- }
-
- // Is configured for TestRun?
- if (this.isTestRun()) {
- // Load Test Run specific converters.
- this.svtConverter = new TestRunSvtConditionsConverter();
- this.ecalConverter = new TestRunEcalConditionsConverter();
- LOGGER.config("registering Test Run conditions converters");
- } else {
- // Load the default converters.
- this.svtConverter = new SvtConditionsConverter();
- this.ecalConverter = new EcalConditionsConverter();
- LOGGER.config("registering default conditions converters");
- }
- this.registerConditionsConverter(this.svtConverter);
- this.registerConditionsConverter(this.ecalConverter);
- }
-
+
/**
* This method can be used to perform a database SELECT query.
*
@@ -960,7 +559,7 @@
ResultSet result = null;
Statement statement = null;
try {
- statement = this.connection.createStatement();
+ statement = connectionSetup.getConnection().createStatement();
result = statement.executeQuery(query);
} catch (final SQLException x) {
throw new RuntimeException("Error in query: " + query, x);
@@ -969,39 +568,6 @@
}
/**
- * Set the connection parameters of the conditions database.
- *
- * @param connectionParameters the connection parameters
- */
- public void setConnectionParameters(final ConnectionParameters connectionParameters) {
- this.connectionParameters = connectionParameters;
- }
-
- /**
- * Set the path to a properties file containing connection settings.
- *
- * @param file the properties file
- */
- public void setConnectionProperties(final File file) {
- LOGGER.config("setting connection properties file " + file.getPath());
- if (!file.exists()) {
- throw new IllegalArgumentException("The connection properties file does not exist: "
- + this.connectionPropertiesFile.getPath());
- }
- this.connectionParameters = ConnectionParameters.fromProperties(file);
- }
-
- /**
- * Set the connection parameters from an embedded resource location.
- *
- * @param resource the classpath resource location
- */
- public void setConnectionResource(final String resource) {
- LOGGER.config("setting connection resource " + resource);
- this.connectionParameters = ConnectionParameters.fromResource(resource);
- }
-
- /**
* This method handles changes to the detector name and run number. It is called every time an LCSim event is
* created, and so it has internal logic to figure out if the conditions system actually needs to be updated.
*/
@@ -1015,7 +581,7 @@
throw new IllegalArgumentException("The detectorName argument is null.");
}
- if (!this.isInitialized || !detectorName.equals(this.getDetector()) || runNumber != this.getRun()) {
+ if (!detectorName.equals(this.getDetector()) || runNumber != this.getRun()) {
if (!this.isFrozen) {
LOGGER.info("new detector " + detectorName + " and run #" + runNumber);
this.initialize(detectorName, runNumber);
@@ -1026,94 +592,50 @@
}
/**
- * Set the name of the ECAL sub-detector.
- *
- * @param ecalName the name of the ECAL subdetector
- */
- private void setEcalName(final String ecalName) {
- if (ecalName == null) {
- throw new IllegalArgumentException("The ecalName is null");
- }
- this.ecalName = ecalName;
- LOGGER.info("ECAL name set to " + ecalName);
- }
-
- /**
- * Set the name of the SVT subdetector.
- *
- * @param svtName the name of the SVT subdetector
- */
- private void setSvtName(final String svtName) {
- if (svtName == null) {
- throw new IllegalArgumentException("The svtName is null");
- }
- this.svtName = svtName;
- LOGGER.info("SVT name set to " + this.ecalName);
- }
-
- /**
- * Setup the database connection from a file specified by a Java system property setting. This could be overridden
- * by subsequent API calls to {@link #setConnectionProperties(File)} or {@link #setConnectionResource(String)}.
- */
- private void setupConnectionSystemPropertyFile() {
- final String systemPropertiesConnectionPath = (String) System.getProperties().get(CONNECTION_PROPERTY_FILE);
- if (systemPropertiesConnectionPath != null) {
- final File f = new File(systemPropertiesConnectionPath);
- if (!f.exists()) {
- throw new RuntimeException("Connection properties file from " + CONNECTION_PROPERTY_FILE
- + " does not exist.");
- }
- this.setConnectionProperties(f);
- LOGGER.info("connection setup from system property " + CONNECTION_PROPERTY_FILE + " = "
- + systemPropertiesConnectionPath);
- }
- }
-
- /**
- * Setup the database connection from a file specified by a Java system property setting. This could be overridden
- * by subsequent API calls to {@link #setConnectionProperties(File)} or {@link #setConnectionResource(String)}.
- */
- private void setupConnectionSystemPropertyResource() {
- final String systemPropertiesConnectionResource = (String) System.getProperties().get(
- CONNECTION_PROPERTY_RESOURCE);
- if (systemPropertiesConnectionResource != null) {
- this.setConnectionResource(systemPropertiesConnectionResource);
- }
- }
-
- /**
- * Configure some properties of this object from an XML file
- *
- * @param file the XML file
- */
- public void setXmlConfig(final File file) {
- LOGGER.config("setting XML config from file " + file.getPath());
- if (!file.exists()) {
- throw new IllegalArgumentException("The config file does not exist: " + file.getPath());
- }
- try {
- this.configure(new FileInputStream(file));
- } catch (final FileNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Configure this object from an embedded XML resource.
- *
- * @param resource the embedded XML resource
- */
- public void setXmlConfig(final String resource) {
- LOGGER.config("setting XML config from resource " + resource);
- final InputStream is = this.getClass().getResourceAsStream(resource);
- this.configure(is);
- }
-
- /**
* Un-freeze the conditions system so that updates will be received again.
*/
public synchronized void unfreeze() {
this.isFrozen = false;
LOGGER.info("conditions system unfrozen");
}
+
+ /**
+ * Open a connection to the conditions database.
+ */
+ public void openConnection() {
+ this.connectionSetup.openConnection();
+ }
+
+ /**
+ * Get a connection to the conditions database.
+ * @return the database connection
+ */
+ public Connection getConnection() {
+ return this.connectionSetup.getConnection();
+ }
+
+ /**
+ * Close the connection to the conditions database.
+ */
+ public void closeConnection() {
+ this.connectionSetup.closeConnection();
+ }
+
+ /**
+ * Set connection properties directly from a file, overriding properties in environment.
+ *
+ * @param propertiesFile the file containing connection property settings
+ */
+ public void setConnectionProperties(File propertiesFile) {
+ this.connectionSetup.setConnectionProperties(propertiesFile);
+ }
+
+ /**
+ * Set connection properties from an embedded jar resource, overriding properties in environment.
+ *
+ * @param resource the jar resource path
+ */
+ public void setConnectionResource(String resource) {
+ this.connectionSetup.setConnectionResource(resource);
+ }
}
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/api/ConditionsTagTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/api/ConditionsTagTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/api/ConditionsTagTest.java Fri Aug 26 17:25:33 2016
@@ -93,8 +93,7 @@
@Override
public void setUp() {
// Configure the conditions system.
- MANAGER = DatabaseConditionsManager.getInstance();
- MANAGER.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
+ MANAGER = DatabaseConditionsManager.getInstance();
}
/**
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/database/DatabaseConditionsManagerTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/database/DatabaseConditionsManagerTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/database/DatabaseConditionsManagerTest.java Fri Aug 26 17:25:33 2016
@@ -28,8 +28,6 @@
// Check initial state.
TestCase.assertTrue("The conditions manager instance is null.", manager != null);
- TestCase.assertFalse("The manager should not be connected.", manager.isConnected());
- TestCase.assertFalse("The manager should not be initialized.", manager.isInitialized());
TestCase.assertFalse("The manager should not be frozen.", manager.isFrozen());
TestCase.assertTrue("The manager should be setup.", ConditionsManager.isSetup());
@@ -41,19 +39,11 @@
TestCase.assertNotNull("New collection should have metadata.", newCollection.getTableMetaData());
// Check connection state.
- TestCase.assertTrue("The manager should be connected.", manager.isConnected());
TestCase.assertNotNull("The connection is null.", manager.getConnection());
-
- // Turn off SVT detector setup because some required classes are not available from this module.
- manager.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
-
+
// Initialize the conditions system.
manager.setDetector("HPS-EngRun2015-Nominal-v2", 5772);
-
- // Check basic state after initialization.
- TestCase.assertFalse("Manager should not be configured for test run.", manager.isTestRun());
- TestCase.assertTrue("The manager should be initialized.", manager.isInitialized());
-
+
// Make sure that freezing the conditions system works properly.
manager.freeze();
TestCase.assertTrue("The manager should be frozen.", manager.isFrozen());
@@ -98,12 +88,7 @@
// Un-freeze the conditions system.
manager.unfreeze();
TestCase.assertFalse("Manager should not be frozen.", manager.isFrozen());
-
- // Load Test Run setup.
- manager.setDetector("HPS-TestRun-v8-5", 1365);
- TestCase.assertEquals("Run number should have changed.", manager.getRun(), 1365);
- TestCase.assertTrue("Manager should be configured for test run.", manager.isTestRun());
-
+
// Check SLAC connection setup.
manager.closeConnection();
manager.setConnectionResource("/org/hps/conditions/config/slac_connection.prop");
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectCollectionTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectCollectionTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectCollectionTest.java Fri Aug 26 17:25:33 2016
@@ -28,7 +28,6 @@
// Configure the conditions system.
final DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
manager.setConnectionResource("/org/hps/conditions/config/jeremym_dev_connection.prop");
- manager.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
this.connection = manager.getConnection();
}
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectConverterTest.java Fri Aug 26 17:25:33 2016
@@ -18,7 +18,6 @@
final DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
manager.setConnectionResource("/org/hps/conditions/config/jeremym_dev_connection.prop");
- manager.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
manager.registerConditionsConverter(new DummyConditionsObjectConverter());
manager.setDetector("HPS-dummy-detector", 1);
manager.openConnection();
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/dummy/DummyConditionsObjectTest.java Fri Aug 26 17:25:33 2016
@@ -35,7 +35,6 @@
// Configure the conditions system. This uses a local development database that is not globally accessible.
manager = DatabaseConditionsManager.getInstance();
manager.setConnectionResource("/org/hps/conditions/config/jeremym_dev_connection.prop");
- manager.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
}
/**
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtBadChannelsTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtBadChannelsTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtBadChannelsTest.java Fri Aug 26 17:25:33 2016
@@ -49,7 +49,6 @@
public void testSvtBadChannels() throws ConditionsNotFoundException {
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
for (int i = 0; i < RUN_NUMBERS.length; i++) {
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtConditionsConverterTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtConditionsConverterTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtConditionsConverterTest.java Fri Aug 26 17:25:33 2016
@@ -23,7 +23,6 @@
*/
public void test() throws Exception {
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
conditionsManager.setDetector("HPS-TestRun-v5", RUN_NUMBER);
final TestRunSvtConditions svtConditions = conditionsManager.getCachedConditions(TestRunSvtConditions.class,
Modified: java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtDaqMappingTest.java
=============================================================================
--- java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtDaqMappingTest.java (original)
+++ java/branches/jeremy-dev/conditions/src/test/java/org/hps/conditions/svt/TestRunSvtDaqMappingTest.java Fri Aug 26 17:25:33 2016
@@ -70,7 +70,6 @@
public void test() throws Exception {
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
conditionsManager.setDetector("HPS-TestRun-v5", RUN_NUMBER);
final TestRunSvtDaqMappingCollection daqMappingCollection = conditionsManager.getCachedConditions(
Modified: java/branches/jeremy-dev/detector-model/src/test/java/org/hps/detector/svt/TestRunSvtDetectorSetupTest.java
=============================================================================
--- java/branches/jeremy-dev/detector-model/src/test/java/org/hps/detector/svt/TestRunSvtDetectorSetupTest.java (original)
+++ java/branches/jeremy-dev/detector-model/src/test/java/org/hps/detector/svt/TestRunSvtDetectorSetupTest.java Fri Aug 26 17:25:33 2016
@@ -64,7 +64,6 @@
public void test() throws Exception {
final DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
conditionsManager.setDetector("HPS-TestRun-v5", RUN_NUMBER);
// Get the detector.
Modified: java/branches/jeremy-dev/evio/src/main/java/org/hps/evio/EvioToLcio.java
=============================================================================
--- java/branches/jeremy-dev/evio/src/main/java/org/hps/evio/EvioToLcio.java (original)
+++ java/branches/jeremy-dev/evio/src/main/java/org/hps/evio/EvioToLcio.java Fri Aug 26 17:25:33 2016
@@ -700,16 +700,7 @@
* @return The LCSimEventBuilder for the Test Run or Engineering Run.
*/
private void setupEventBuilder(final int runNumber) {
- // Is this run number from the Test Run?
- if (DatabaseConditionsManager.isTestRun(runNumber)) {
- // Configure conditions system for Test Run.
- LOGGER.info("using Test Run event builder");
- eventBuilder = new LCSimTestRunEventBuilder();
- } else {
- // Configure conditions system for Eng Run or default.
- LOGGER.info("using Eng Run event builder");
- eventBuilder = new LCSimEngRunEventBuilder();
- }
+ eventBuilder = new LCSimEngRunEventBuilder();
final ConditionsManager conditions = ConditionsManager.defaultInstance();
conditions.addConditionsListener(eventBuilder);
}
Modified: java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java
=============================================================================
--- java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java (original)
+++ java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimEngRunEventBuilderTest.java Fri Aug 26 17:25:33 2016
@@ -28,7 +28,6 @@
// Setup database conditions.
DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_dev.xml");
conditionsManager.setDetector("HPS-Proposal2014-v8-6pt6", 2000);
// Configure LCIO writer.
Modified: java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimTestRunEventBuilderTest.java
=============================================================================
--- java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimTestRunEventBuilderTest.java (original)
+++ java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/LCSimTestRunEventBuilderTest.java Fri Aug 26 17:25:33 2016
@@ -21,18 +21,11 @@
* @date November 20, 2014
*/
public class LCSimTestRunEventBuilderTest extends TestCase {
-
- //-----------------//
- //--- Constants ---//
- //-----------------//
- private static final String DB_CONFIGURATION
- = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
public void testLCSimTestRunEventBuilder() throws Exception {
// Configure the conditions system to retrieve test run conditions fo run 1351.
DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig(DB_CONFIGURATION);
// Create the test run event builder
LCSimTestRunEventBuilder builder = new LCSimTestRunEventBuilder();
Modified: java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/TestRunSvtEvioReaderTest.java
=============================================================================
--- java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/TestRunSvtEvioReaderTest.java (original)
+++ java/branches/jeremy-dev/evio/src/test/java/org/hps/evio/TestRunSvtEvioReaderTest.java Fri Aug 26 17:25:33 2016
@@ -28,12 +28,8 @@
// Instantiate the EVIO reader and open the file
EvioReader evioReader = new EvioReader(evioFile);
- // Instantiate the SVT EVIO reader
- // TestRunSvtEvioReader svtReader = new TestRunSvtEvioReader();
-
// Configure conditions system
DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_testrun_2012.xml");
// Instantiate the event builder
LCSimEventBuilder eventBuilder = new LCSimTestRunEventBuilder();
Modified: java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java
=============================================================================
--- java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java (original)
+++ java/branches/jeremy-dev/job/src/main/java/org/hps/job/DatabaseConditionsManagerSetup.java Fri Aug 26 17:25:33 2016
@@ -95,7 +95,7 @@
@Override
public void postInitialize() {
LOGGER.config("conditions setup post init");
- if (DatabaseConditionsManager.getInstance().isInitialized() || this.freeze) {
+ if (this.freeze) {
LOGGER.config("Job manager is freezing the conditions system.");
DatabaseConditionsManager.getInstance().freeze();
}
Modified: java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioEventUtilities.java
=============================================================================
--- java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioEventUtilities.java (original)
+++ java/branches/jeremy-dev/record-util/src/main/java/org/hps/record/evio/EvioEventUtilities.java Fri Aug 26 17:25:33 2016
@@ -11,11 +11,9 @@
import java.util.ArrayList;
import java.util.List;
-import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.record.daqconfig.EvioDAQParser;
import org.jlab.coda.jevio.BaseStructure;
import org.jlab.coda.jevio.EvioEvent;
-import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
/**
* This is a set of basic static utility methods for <code>EvioEvent</code> objects.
@@ -250,18 +248,7 @@
// Get run number from EVIO event.
int runNumber = EvioEventUtilities.getRunNumber(evioEvent);
-
- // Initialize the conditions system if necessary as the DAQ config parsing classes use it.
- DatabaseConditionsManager conditionsManager = DatabaseConditionsManager.getInstance();
- if (!conditionsManager.isInitialized() || conditionsManager.getRun() != runNumber) {
- try {
- conditionsManager.setXmlConfig("/org/hps/conditions/config/conditions_database_no_svt.xml");
- DatabaseConditionsManager.getInstance().setDetector("HPS-dummy-detector", runNumber);
- } catch (ConditionsNotFoundException e) {
- throw new RuntimeException(e);
- }
- }
-
+
// Create the trigger config from the EVIO data.
parser.parse(
crate,
@@ -271,6 +258,7 @@
return parser;
}
+ // FIXME: Method is not called anywhere! (delete it?)
public static List<EvioDAQParser> getDAQConfig(EvioEvent evioEvent) {
List<EvioDAQParser> triggerConfig = new ArrayList<EvioDAQParser>();
outerLoop: for (BaseStructure bank : evioEvent.getChildrenList()) {
Modified: java/branches/jeremy-dev/run-database/src/main/java/org/hps/rundb/RunManager.java
=============================================================================
--- java/branches/jeremy-dev/run-database/src/main/java/org/hps/rundb/RunManager.java (original)
+++ java/branches/jeremy-dev/run-database/src/main/java/org/hps/rundb/RunManager.java Fri Aug 26 17:25:33 2016
@@ -6,6 +6,7 @@
import java.util.logging.Logger;
import org.hps.conditions.database.ConnectionParameters;
+import org.hps.conditions.database.ConnectionSetup;
import org.hps.record.daqconfig.DAQConfig;
import org.hps.record.epics.EpicsData;
import org.hps.record.scalers.ScalerData;
@@ -82,8 +83,19 @@
/**
* Class constructor using default connection parameters.
*/
- public RunManager() {
- this(DEFAULT_CONNECTION_PARAMETERS.createConnection());
+ public RunManager() {
+
+ // Setup connection from conditions system database configuration (HPSJAVA-665).
+ ConnectionSetup setup = new ConnectionSetup();
+ setup.setup();
+ ConnectionParameters parameters = setup.getConnectionParameters();
+ this.connection = new ConnectionParameters(
+ parameters.getUser(),
+ parameters.getPassword(),
+ "hps_run_db_v2",
+ parameters.getHostname()).createConnection();
+
+ factory = new DaoProvider(this.connection);
}
/**
@@ -272,5 +284,4 @@
factory.getTriggerConfigDao().deleteTriggerConfig(run);
factory.getRunSummaryDao().deleteRunSummary(run);
}
-
}
|