1 added + 1 removed + 9 modified, total 11 files
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsObject.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/AbstractConditionsObject.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -57,7 +57,7 @@
throw new ConditionsObjectException("This object is not in the database and so cannot be deleted.");
}
String query = QueryBuilder.buildDelete(_tableMetaData.getTableName(), _rowId);
- DatabaseConditionsManager.getInstance().update(query);
+ DatabaseConditionsManager.getInstance().updateQuery(query);
_rowId = -1;
}
@@ -74,7 +74,7 @@
getCollectionId(),
getTableMetaData().getFieldNames(),
_fieldValues.valuesToArray());
- List<Integer> keys = DatabaseConditionsManager.getInstance().update(query);
+ List<Integer> keys = DatabaseConditionsManager.getInstance().updateQuery(query);
if (keys.size() == 0 || keys.size() > 1) {
throw new ConditionsObjectException("SQL insert returned wrong number of keys: " + keys.size());
}
@@ -88,7 +88,7 @@
String query = QueryBuilder.buildSelect(
getTableMetaData().getTableName(), _collectionId, _fieldValues.fieldsToArray(), "id ASC");
DatabaseConditionsManager manager = DatabaseConditionsManager.getInstance();
- ResultSet resultSet = manager.query(query);
+ ResultSet resultSet = manager.selectQuery(query);
try {
ResultSetMetaData metadata = resultSet.getMetaData();
int ncolumns = metadata.getColumnCount();
@@ -118,7 +118,7 @@
_rowId,
_fieldValues.fieldsToArray(),
_fieldValues.valuesToArray());
- DatabaseConditionsManager.getInstance().update(query);
+ DatabaseConditionsManager.getInstance().updateQuery(query);
setIsDirty(false);
}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -17,16 +17,69 @@
*/
public class ConditionsDriver extends Driver {
+ // Static instance of the manager.
+ static DatabaseConditionsManager _manager;
+
+ // Default conditions system XML config, which is for the Test Run 2012 database.
+ String _defaultConfigResource =
+ "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
+
+ // Default database connection parameters, which points to the SLAC development database.
+ static String _defaultConnectionResource =
+ "/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties";
+
/**
+ * Constructor which initializes the conditions manager
+ * without performing any configuration. This can be
+ * done using the {@link #setConfigResource(String)} and
+ * {@link #setConnectionResource(String)} methods.
+ */
+ public ConditionsDriver() {
+ _manager = new DatabaseConditionsManager();
+ _manager.register();
+ }
+
+ /**
+ * Set the configuration resource to be used by the manager and update it.
+ * @param resource the configuration resource
+ */
+ public void setConfigResource(String resource) {
+ _manager.configure(resource);
+ }
+
+ /**
+ * Set the connection resource to be used by the manager and update it.
+ * @param resource the connection resource
+ */
+ public void setConnectionResource(String resource) {
+ _manager.setConnectionResource(resource);
+ }
+
+ /**
+ * Hook for start of data, which will initialize the conditions
+ * system if it has not been properly setup yet.
+ */
+ // FIXME: Is this the best place for this to happen? Seems kind of kludgy.
+ public void startOfData() {
+ if (!_manager.hasConnectionParameters()) {
+ _manager.setConnectionResource(_defaultConnectionResource);
+ }
+
+ if (!_manager.wasConfigured()) {
+ _manager.configure(_defaultConfigResource);
+ }
+ }
+
+ /**
* 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.
+ * Load the SVT conditions onto the <code>Detector</code>.
* @param detector The detector to update.
*/
private void loadSvtConditions(Detector detector) {
@@ -37,7 +90,7 @@
}
/**
- * Load the ECal conditions onto the Detector.
+ * Load the ECal conditions onto the <code>Detector</code>.
* @param detector The detector to update.
*/
private void loadEcalConditions(Detector detector) {
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectConverter.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsObjectConverter.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -91,7 +91,7 @@
String query = QueryBuilder.buildSelect(tableName, collectionId, tableMetaData.getFieldNames(), "id ASC");
// Query the database.
- ResultSet resultSet = databaseConditionsManager.query(query);
+ ResultSet resultSet = databaseConditionsManager.selectQuery(query);
try {
// Loop over rows.
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsRecordConverter.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsRecordConverter.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -33,7 +33,7 @@
+ " AND run_end >= "
+ manager.getRun();
- ResultSet resultSet = databaseConditionsManager.query(query);
+ ResultSet resultSet = databaseConditionsManager.selectQuery(query);
// Create a collection to return.
ConditionsObjectCollection collection;
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionParameters.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConnectionParameters.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -2,7 +2,9 @@
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.SQLException;
@@ -118,10 +120,36 @@
* @param file The properties file.
* @return The connection parameters.
*/
- public static final ConnectionParameters fromProperties(File file) {
+ public static final ConnectionParameters fromProperties(File file) {
+ FileInputStream fin = null;
+ try {
+ fin = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
+ throw new IllegalArgumentException(file.getPath() + " does not exist.", e);
+ }
+ return fromProperties(fin);
+ }
+
+ /**
+ * Configure the connection parameters from an embedded classpath resource
+ * which should be a properties file.
+ * @param String The resource path.
+ * @return The connection parameters.
+ */
+ public static final ConnectionParameters fromResource(String resource) {
+ return fromProperties(ConnectionParameters.class.getResourceAsStream(resource));
+ }
+
+ /**
+ * Configure the connection parameters from an <code>InputStream</code> of properties.
+ * @param in The InputStream of the properties.
+ * @return The connection parameters.
+ * @throws RuntimeException if the InputStream is invalid
+ */
+ private static final ConnectionParameters fromProperties(InputStream in) {
Properties properties = new Properties();
try {
- properties.load(new FileInputStream(file));
+ properties.load(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsManager.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -25,10 +25,11 @@
import org.jdom.input.SAXBuilder;
import org.lcsim.conditions.ConditionsConverter;
import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManagerImplementation;
import org.lcsim.conditions.ConditionsReader;
import org.lcsim.conditions.readers.BaseClasspathConditionsReader;
import org.lcsim.geometry.Detector;
-import org.lcsim.util.loop.LCSimConditionsManagerImplementation;
+import org.lcsim.util.loop.DetectorConditionsConverter;
/**
* <p>
@@ -42,12 +43,12 @@
*
* @author Jeremy McCormick <[log in to unmask]>
*/
-public class DatabaseConditionsManager extends LCSimConditionsManagerImplementation {
+@SuppressWarnings("rawtypes")
+public class DatabaseConditionsManager extends ConditionsManagerImplementation {
- static DatabaseConditionsManager _instance;
int _runNumber = -1;
String _detectorName;
- List<TableMetaData> _tableMetaData;
+ List<TableMetaData> _tableMetaData;
List<ConditionsConverter> _converters;
File _connectionPropertiesFile;
ConditionsReader _baseReader;
@@ -55,12 +56,15 @@
ConnectionParameters _connectionParameters;
Connection _connection;
String _conditionsTableName;
+ boolean _wasConfigured = false;
+ boolean _isConnected = false;
/**
- * Constructor is set to private as this class should not be instantiated directly. Use
- * {@link #createInstance()} instead.
+ * Class constructor, which is only package accessible.
*/
- private DatabaseConditionsManager() {
+ DatabaseConditionsManager() {
+ registerConditionsConverter(new DetectorConditionsConverter());
+ _baseReader = new BaseClasspathConditionsReader();
}
/**
@@ -76,7 +80,7 @@
}
/**
- * Setup the logger for this class.
+ * Setup the logger for this class, with initial level of ALL.
*/
static {
_logger = Logger.getLogger(DatabaseConditionsManager.class.getSimpleName());
@@ -86,20 +90,14 @@
handler.setLevel(Level.ALL);
handler.setFormatter(new LogFormatter());
_logger.addHandler(handler);
- _logger.config("logging initialized with level " + handler.getLevel());
+ _logger.config("logger initialized with level " + handler.getLevel());
}
-
+
/**
- * Create a static instance of this class and register it as the default conditions manager.
- *
- * @return The new conditions manager.
+ * Register this conditions manager as the global default.
*/
- public static DatabaseConditionsManager createInstance() {
- _instance = new DatabaseConditionsManager();
- ConditionsManager.setDefaultConditionsManager(_instance);
- // setupLogger();
- _logger.config("created and registered " + DatabaseConditionsManager.class.getSimpleName());
- return _instance;
+ void register() {
+ ConditionsManager.setDefaultConditionsManager(this);
}
/**
@@ -107,73 +105,29 @@
* @return The static instance of the manager.
*/
public static DatabaseConditionsManager getInstance() {
- return _instance;
+ return (DatabaseConditionsManager)ConditionsManager.defaultInstance();
}
-
+
/**
- * Perform setup for the current detector and run number.
+ * This method catches changes to the detector name and run number.
*/
- public void setup() {
- try {
- try {
- // Create a new, default base ConditionsReader if one was not externally set.
- if (_baseReader == null)
- // Setup the default base reader to handle classpath resources.
- _baseReader = new BaseClasspathConditionsReader(_detectorName);
- _logger.config("using base conditions reader: " + _baseReader.getClass().getSimpleName());
-
- // Set the ConditionsReader on the manager.
- setConditionsReader(new DatabaseConditionsReader(_baseReader), _detectorName);
-
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- _logger.config("setting detector: " + _detectorName);
- _logger.config("setting run number: " + _runNumber);
-
- // Setup the manager with the detector and run number.
- setDetector(_detectorName, _runNumber);
- } catch (ConditionsNotFoundException e) {
- throw new RuntimeException(e);
+ @Override
+ public void setDetector(String detectorName, int runNumber) throws ConditionsNotFoundException {
+ _logger.fine("set detector " + detectorName);
+ _logger.fine("set run number " + runNumber);
+ _runNumber = runNumber;
+ if (_baseReader instanceof BaseClasspathConditionsReader) {
+ ((BaseClasspathConditionsReader)_baseReader).setResourcePath(detectorName);
+ _logger.config("set resource path to " + detectorName + " on conditions reader");
}
- }
+ if (!isConnected())
+ openConnection();
+ else
+ _logger.config("using existing connection " + _connectionParameters.getConnectionString());
+ super.setDetector(detectorName, runNumber);
+ }
/**
- * Set the run number. This will not trigger a conditions change until {@link #setup()} is
- * called.
- * @param runNumber The new run number.
- */
- public void setRunNumber(int runNumber) {
- _runNumber = runNumber;
- }
-
- /**
- * Set the detector name. This will not trigger a conditions change until {@link #setup()} is
- * called.
- * @param detectorName The name of the new detector.
- */
- public void setDetectorName(String detectorName) {
- _detectorName = detectorName;
- }
-
- /**
- * Get the current run number.
- * @return The current run number.
- */
- public int getRunNumber() {
- return _runNumber;
- }
-
- /**
- * Get the current detector name.
- * @return The name of the current detector.
- */
- public String getDetectorName() {
- return this.getDetector();
- }
-
- /**
* Get the lcsim compact <code>Detector</code> object from the conditions system.
* @return The detector object.
*/
@@ -217,7 +171,7 @@
* @param resource The embedded XML resource.
*/
public void configure(String resource) {
- _logger.config("configuring manager from resource: " + resource);
+ _logger.config("configuring from resource: " + resource);
InputStream in = getClass().getResourceAsStream(resource);
if (in == null)
throw new IllegalArgumentException("The resource does not exist.");
@@ -226,13 +180,21 @@
/**
* Set the path to a properties file containing connection settings.
- * @param path
+ * @param file The properties file
*/
- public void setConnectionProperties(String path) {
- _connectionPropertiesFile = new File(path);
- if (!_connectionPropertiesFile.exists())
+ public void setConnectionProperties(File file) {
+ if (!file.exists())
throw new IllegalArgumentException("The connection properties file does not exist: " + _connectionPropertiesFile.getPath());
+ _connectionParameters = ConnectionParameters.fromProperties(file);
}
+
+ /**
+ * Set the connection parameters from an embedded resource.
+ * @param resource The classpath resource
+ */
+ public void setConnectionResource(String resource) {
+ _connectionParameters = ConnectionParameters.fromResource(resource);
+ }
/**
* Set externally the base ConditionsReader that will be used to find non-database conditions
@@ -254,7 +216,7 @@
TableMetaData tableData = findTableMetaData(tableName);
if (tableData == null)
throw new IllegalArgumentException("There is no meta data for table " + tableName);
- ResultSet resultSet = query("SELECT MAX(collection_id)+1 FROM " + tableName);
+ ResultSet resultSet = selectQuery("SELECT MAX(collection_id)+1 FROM " + tableName);
int collectionId = -1;
try {
resultSet.next();
@@ -306,7 +268,7 @@
* @param query The SQL query string.
* @return The ResultSet from the query or null.
*/
- public ResultSet query(String query) {
+ public ResultSet selectQuery(String query) {
_logger.fine(query);
ResultSet result = null;
Statement statement = null;
@@ -324,7 +286,7 @@
* @param query The SQL query string.
* @return The keys of the rows affected.
*/
- public List<Integer> update(String query) {
+ public List<Integer> updateQuery(String query) {
_logger.fine(query);
List<Integer> keys = new ArrayList<Integer>();
Statement statement = null;
@@ -349,9 +311,9 @@
* @param level The log level.
*/
public void setLogLevel(Level level) {
+ _logger.config("setting log level to " + level);
_logger.setLevel(level);
_logger.getHandlers()[0].setLevel(level);
- _logger.config("set log level to " + level);
}
/**
@@ -381,16 +343,31 @@
if (foundConditionsRecords.getObjects().size() > 0) {
for (ConditionsRecord record : foundConditionsRecords.getObjects()) {
_logger.fine("found ConditionsRecord with key " + name + " ..."
- + '\n' + foundConditionsRecords.get(0).toString());
+ + '\n' + record.toString());
}
- _logger.fine("");
}
return foundConditionsRecords;
}
+
+ /**
+ * Return true if the connection parameters are valid, e.g. non-null.
+ * @return true if connection parameters are non-null
+ */
+ public boolean hasConnectionParameters() {
+ return _connectionParameters != null;
+ }
+
+ /**
+ * Return if the manager was configured e.g. from an XML configuration file.
+ * @return true if manager was configured
+ */
+ public boolean wasConfigured() {
+ return _wasConfigured;
+ }
/**
* Close a JDBC <code>Statement</code>.
- * @param statement The Statement to close.
+ * @param statement the Statement to close
*/
static void close(Statement statement) {
if (statement != null) {
@@ -407,7 +384,7 @@
/**
* Close a JDBC <code>ResultSet</code>, or rather the Statement connected to it.
- * @param resultSet The ResultSet to close.
+ * @param resultSet the ResultSet to close
*/
static void close(ResultSet resultSet) {
if (resultSet != null) {
@@ -422,25 +399,31 @@
}
}
}
+
+ private boolean isConnected() {
+ return _isConnected;
+ }
/**
* Configure this class from an <code>InputStream</code> which should point
* to an XML document.
- * @param in The InputStream.
+ * @param in the InputStream which should be in XML format
*/
private void configure(InputStream in) {
- // Create XML document.
+ // Create XML document from stream.
Document config = createDocument(in);
- // Load the table meta data from XML.
+ // Load the table meta data.
loadTableMetaData(config);
- // Load the converter classes from XML.
+ // Load the converter classes.
loadConverters(config);
// Open a connection to the database.
- openConnection();
+ //openConnection();
+
+ _wasConfigured = true;
}
/**
@@ -498,16 +481,17 @@
* Open the database connection.
*/
private void openConnection() {
- if (_connectionPropertiesFile == null)
- throw new RuntimeException("Connection properties were not set.");
- _connectionParameters = ConnectionParameters.fromProperties(_connectionPropertiesFile);
+ if (_connectionParameters == null)
+ throw new RuntimeException("The connection parameters were not configured.");
_connection = _connectionParameters.createConnection();
- _logger.config("created connection: " + _connectionParameters.getConnectionString());
+ _logger.config("created connection " + _connectionParameters.getConnectionString());
+ _isConnected = true;
}
/**
* Close the database connection.
*/
+ // FIXME: When should this be called, if ever?
private void closeConnection() {
if (_connection != null) {
try {
@@ -593,7 +577,6 @@
* @author Jeremy McCormick <[log in to unmask]>
*/
class ConditionsConverterLoader {
-
void load(Element element) {
_converters = new ArrayList<ConditionsConverter>();
for (Iterator iterator = element.getChildren("converter").iterator(); iterator.hasNext();) {
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsReader.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DatabaseConditionsReader.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -1,103 +0,0 @@
-package org.hps.conditions;
-
-import java.io.IOException;
-import java.io.InputStream;
-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;
-
-/**
- * This is more-or-less a placeholder class for a database conditions reader.
- * The {@link DatabaseConditionsManager} and the converter classes perform
- * the real work.
- *
- * @author Jeremy McCormick <[log in to unmask]>
- */
-public class DatabaseConditionsReader extends ConditionsReader {
-
- /** 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;
-
- /** 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) {
- _reader = reader;
- setupLogger();
- }
-
- /**
- * Setup the logger.
- */
- private final void setupLogger() {
- if (_logger == null) {
- _logger = Logger.getLogger(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;
- }
-
- 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);
- }
-}
java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/DefaultTestSetup.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/DefaultTestSetup.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -1,5 +1,7 @@
package org.hps.conditions;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
+
/**
* <p>
* This is a static utility class for setting up the conditions system for test cases
@@ -34,28 +36,43 @@
*/
public final class DefaultTestSetup {
+ // Default conditions manager parameters.
+ static String _connectionResource = "/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties";
+ static String _conditionsConfig = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
+
+ // Default test detector and run number for test cases not using real data.
static String _detectorName = "HPS-conditions-test";
static int _runNumber = 1351;
- static String _connectionProperties = "./src/main/config/conditions_database_testrun_2012_connection.properties";
- static String _conditionsConfig = "/org/hps/conditions/config/conditions_database_testrun_2012.xml";
DatabaseConditionsManager _conditionsManager;
boolean _wasConfigured = false;
+ /**
+ * Configure and register the {@link DatabaseConditionsManager} with default parameters.
+ * @return an instance of this class for chaining (e.g. to call {@link #setup()}.
+ */
public DefaultTestSetup configure() {
- _conditionsManager = DatabaseConditionsManager.createInstance();
- _conditionsManager.setConnectionProperties(_connectionProperties);
+ _conditionsManager = new DatabaseConditionsManager();
+ _conditionsManager.setConnectionResource(_connectionResource);
_conditionsManager.configure(_conditionsConfig);
+ _conditionsManager.register();
_wasConfigured = true;
return this;
}
+ /**
+ * Setup the detector and run number conditions for the conditions manager.
+ * This is mostly useful for test cases not using an <code>LCSimLoop</code>.
+ * @return the conditions manager
+ */
public DatabaseConditionsManager setup() {
if (!_wasConfigured)
configure();
- _conditionsManager.setDetectorName(_detectorName);
- _conditionsManager.setRunNumber(_runNumber);
- _conditionsManager.setup();
+ try {
+ _conditionsManager.setDetector(_detectorName, _runNumber);
+ } catch (ConditionsNotFoundException e) {
+ throw new RuntimeException(e);
+ }
return _conditionsManager;
}
-}
+}
\ No newline at end of file
java/trunk/conditions/src/main/resources/org/hps/conditions/config
--- java/trunk/conditions/src/main/resources/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties (rev 0)
+++ java/trunk/conditions/src/main/resources/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties 2014-03-31 22:30:49 UTC (rev 421)
@@ -0,0 +1,5 @@
+user: rd_hps_cond_ro
+password: 2jumpinphotons.
+database: rd_hps_cond
+hostname: mysql-node03.slac.stanford.edu
+port: 3306
\ No newline at end of file
java/trunk/conditions/src/test/java/org/hps/conditions
--- java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsDriverTest.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/ConditionsDriverTest.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -2,44 +2,32 @@
import java.io.File;
import java.net.URL;
-import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
import junit.framework.TestCase;
-import org.lcsim.detector.tracker.silicon.HpsSiSensor;
import org.lcsim.event.EventHeader;
-import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
import org.lcsim.util.cache.FileCache;
import org.lcsim.util.loop.LCSimLoop;
/**
- * This class tests that {@link org.lcsim.hps.conditions.ConditionsDriver} works correctly.
+ * This class tests that {@link org.lcsim.hps.conditions.ConditionsDriver} works correctly
+ * by checking the number of runs it processes.
* @author Jeremy McCormick <[log in to unmask]>
*/
public class ConditionsDriverTest extends TestCase {
- /** This test file has a few events from each of the "good runs" of the 2012 Test Run. */
+ // This test file has a few events from each of the "good runs" of the 2012 Test Run.
private static final String TEST_FILE_URL = "http://www.lcsim.org/test/hps/conditions_test.slcio";
-
- /** Answer key for number of bad channels by run. */
- static Map<Integer,Integer> badChannelAnswerKey = new HashMap<Integer,Integer>();
-
- /** Setup the bad channel answer key by run. */
- static {
- badChannelAnswerKey.put(1351, 441);
- badChannelAnswerKey.put(1353, 473);
- badChannelAnswerKey.put(1354, 474);
- badChannelAnswerKey.put(1358, 344);
- badChannelAnswerKey.put(1359, 468);
- badChannelAnswerKey.put(1360, 468);
- }
-
- /** This is the number of bad channels in the QA set for all runs. */
- static int BAD_CHANNELS_QA_ANSWER = 50;
-
+
+ // Number of runs that should be processed in the job.
+ static final int NRUNS = 9;
+
/**
* Run the test.
* @throws Exception
@@ -52,53 +40,72 @@
// Create the record loop.
LCSimLoop loop = new LCSimLoop();
-
- // Reconfigure the conditions system.
- new DefaultTestSetup().configure();
-
+
// Configure the loop.
loop.setLCIORecordSource(testFile);
loop.add(new ConditionsDriver());
- loop.add(new SvtBadChannelChecker());
+ RunNumberDriver runNumberDriver = new RunNumberDriver();
+ loop.add(runNumberDriver);
+ // Turn off the chatty conditions manager.
+ DatabaseConditionsManager.getInstance().setLogLevel(Level.OFF);
+
// Run over all events.
loop.loop(-1, null);
+
+ System.out.println("Done processing events!");
+
+ // Print out unique runs.
+ System.out.println("Unique run numbers in this job ...");
+ for (int runNumber : runNumberDriver.getUniqueRuns()) {
+ System.out.println(runNumber);
+ }
+
+ System.out.println();
+
+ // Print out runs processed.
+ System.out.println("Processed runs in order ...");
+ for (int runNumber : runNumberDriver.getRunsProcessed()) {
+ System.out.println(runNumber);
+ }
+
+ // Check that correct number of runs was processed.
+ assertEquals("Number of runs processed was incorrect.", NRUNS, runNumberDriver.getNumberOfRuns());
+
+ // Check that the number of unique runs was correct.
+ assertEquals("Number of unique runs was incorrect.", NRUNS, runNumberDriver.getUniqueRuns().size());
}
-
+
/**
- * This Driver will check the number of bad channels for a run against the answer key.
- * @author Jeremy McCormick <[log in to unmask]>
+ * Simple Driver to store information about runs processed.
*/
- class SvtBadChannelChecker extends Driver {
+ static class RunNumberDriver extends Driver {
- int currentRun = -1;
+ int _currentRun = -1;
+ int _nruns = 0;
+ List<Integer> _runsProcessed = new ArrayList<Integer>();
+ Set<Integer> _uniqueRuns = new LinkedHashSet<Integer>();
- /**
- * This method will check the number of bad channels against the answer key
- * for the first event of a new run.
- */
public void process(EventHeader event) {
- int run = event.getRunNumber();
- if (run != currentRun) {
- currentRun = run;
- Detector detector = event.getDetector();
- int badChannels = 0;
- List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class);
- for (HpsSiSensor sensor : sensors) {
- int nchannels = sensor.getNumberOfChannels();
- for (int i=0; i<nchannels; i++) {
- if (sensor.isBadChannel(i))
- ++badChannels;
- }
- }
- System.out.println("Run " + currentRun + " has " + badChannels + " SVT bad channels.");
- Integer badChannelAnswer = badChannelAnswerKey.get(run);
- if (badChannelAnswer != null) {
- TestCase.assertEquals("Wrong number of bad channels found.", (int)badChannelAnswer, (int)badChannels);
- } else {
- TestCase.assertEquals("Wrong number of bad channels found.", (int)BAD_CHANNELS_QA_ANSWER, (int)badChannels);
- }
+ int runNumber = event.getRunNumber();
+ if (runNumber != _currentRun) {
+ _currentRun = runNumber;
+ _uniqueRuns.add(_currentRun);
+ _runsProcessed.add(_currentRun);
+ _nruns++;
}
}
+
+ int getNumberOfRuns() {
+ return _nruns;
+ }
+
+ List<Integer> getRunsProcessed() {
+ return _runsProcessed;
+ }
+
+ Set<Integer> getUniqueRuns() {
+ return _uniqueRuns;
+ }
}
}
java/trunk/conditions/src/test/java/org/hps/conditions/beam
--- java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java 2014-03-31 20:28:45 UTC (rev 420)
+++ java/trunk/conditions/src/test/java/org/hps/conditions/beam/BeamCurrentTest.java 2014-03-31 22:30:49 UTC (rev 421)
@@ -9,8 +9,7 @@
import junit.framework.TestCase;
-import org.hps.conditions.DatabaseConditionsManager;
-import org.hps.conditions.DefaultTestSetup;
+import org.hps.conditions.ConditionsDriver;
import org.hps.conditions.beam.BeamCurrent.BeamCurrentCollection;
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.event.EventHeader;
@@ -55,12 +54,10 @@
// Create the LCSimLoop.
LCSimLoop loop = new LCSimLoop();
-
- // Reconfigure the conditions system to override the manager created by LCSimLoop.
- new DefaultTestSetup().configure();
-
+
// Configure and run the loop.
loop.setLCIORecordSource(testFile);
+ loop.add(new ConditionsDriver());
loop.add(new BeamCurrentChecker());
loop.loop(-1, null);
}
SVNspam 0.1