java/trunk/conditions/src/main/java/org/hps/conditions
--- java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-04-02 18:49:08 UTC (rev 431)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ConditionsDriver.java 2014-04-02 18:50:15 UTC (rev 432)
@@ -7,13 +7,15 @@
import org.hps.conditions.ecal.EcalConditionsLoader;
import org.hps.conditions.svt.SvtConditions;
import org.hps.conditions.svt.SvtConditionsLoader;
-import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException;
import org.lcsim.conditions.ConditionsReader;
import org.lcsim.geometry.Detector;
import org.lcsim.util.Driver;
/**
- * This {@link org.lcsim.util.Driver} loads conditions onto an HPS detector.
+ * This {@link org.lcsim.util.Driver} sets up the {@link DatabaseConditionsManager} and
+ * loads the conditions onto a detector.
+ *
* @author Jeremy McCormick <[log in to unmask]>
*/
public class ConditionsDriver extends Driver {
@@ -28,20 +30,26 @@
// Default database connection parameters, which points to the SLAC development database.
static String _defaultConnectionResource =
"/org/hps/conditions/config/conditions_database_testrun_2012_connection.properties";
+
+ // The default starting run number which should be used to setup the conditions system before
+ // events are processed.
+ int _defaultRunNumber = -1;
+
+ boolean _wasSetup = false;
/**
- * Constructor which initializes the conditions manager
- * without performing any configuration. This can be
- * done using the {@link #setConfigResource(String)} and
- * {@link #setConnectionResource(String)} methods.
+ * Constructor which initializes the conditions manager with
+ * default connection parameters and configuration.
*/
public ConditionsDriver() {
_manager = new DatabaseConditionsManager();
+ _manager.setConnectionResource(_defaultConnectionResource);
+ _manager.configure(_defaultConfigResource);
_manager.register();
}
/**
- * Set the configuration resource to be used by the manager and update it.
+ * Set the configuration XML resource to be used by the manager.
* @param resource the configuration resource
*/
public void setConfigResource(String resource) {
@@ -49,7 +57,7 @@
}
/**
- * Set the connection resource to be used by the manager and update it.
+ * Set the connection properties file resource to be used by the manager.
* @param resource the connection resource
*/
public void setConnectionResource(String resource) {
@@ -57,6 +65,14 @@
}
/**
+ * Set the default starting run number.
+ * @param defaultRunNumber the default run number
+ */
+ public void setDefaultRunNumber(int defaultRunNumber) {
+ _defaultRunNumber = defaultRunNumber;
+ }
+
+ /**
* Set the class of the conditions reader to use.
*/
public void setConditionsReaderClass(String className) {
@@ -66,31 +82,28 @@
if (reader != null)
_manager.setBaseConditionsReader(reader);
else
- throw new IllegalArgumentException("The class " + className + " does not extend ConditionsReader.");
+ throw new IllegalArgumentException("The class " + className + " is not a ConditionsReader.");
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
-
+
/**
- * Hook for start of data, which will initialize the conditions
- * system if it has not been properly setup yet.
+ * This method updates a new detector with SVT and ECal conditions data.
*/
- // FIXME: Is this the best place for this to happen? Seems kind of kludgy.
- public void startOfData() {
- if (!_manager.hasConnectionParameters()) {
- _manager.setConnectionResource(_defaultConnectionResource);
- }
+ public void detectorChanged(Detector detector) {
- if (!_manager.wasConfigured()) {
- _manager.configure(_defaultConfigResource);
+ // FIXME: This is atrocious to call from here but I'm not sure where else to put it.
+ if (!_wasSetup) {
+ try {
+ _manager.setDetector(detector.getDetectorName(), _defaultRunNumber);
+ } catch (ConditionsNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ _wasSetup = true;
}
- }
- /**
- * This method updates a new detector with SVT and ECal conditions data.
- */
- public void detectorChanged(Detector detector) {
+ // Load conditions onto the detector.
loadSvtConditions(detector);
loadEcalConditions(detector);
}
@@ -99,9 +112,8 @@
* Load the SVT conditions onto the <code>Detector</code>.
* @param detector The detector to update.
*/
- private void loadSvtConditions(Detector detector) {
- ConditionsManager manager = ConditionsManager.defaultInstance();
- SvtConditions conditions = manager.getCachedConditions(SvtConditions.class, SVT_CONDITIONS).getCachedData();
+ private void loadSvtConditions(Detector detector) {
+ SvtConditions conditions = _manager.getCachedConditions(SvtConditions.class, SVT_CONDITIONS).getCachedData();
SvtConditionsLoader loader = new SvtConditionsLoader();
loader.load(detector, conditions);
}
@@ -111,8 +123,7 @@
* @param detector The detector to update.
*/
private void loadEcalConditions(Detector detector) {
- ConditionsManager manager = ConditionsManager.defaultInstance();
- EcalConditions conditions = manager.getCachedConditions(EcalConditions.class, ECAL_CONDITIONS).getCachedData();
+ EcalConditions conditions = _manager.getCachedConditions(EcalConditions.class, ECAL_CONDITIONS).getCachedData();
EcalConditionsLoader loader = new EcalConditionsLoader();
loader.load(detector, conditions);
}