Author: [log in to unmask]
Date: Wed Feb 25 15:00:53 2015
New Revision: 2207
Log:
Fix problem where EcalChannelCollection would sometimes not be fully intialized.
Modified:
java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java
java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/database/DatabaseConditionsManager.java Wed Feb 25 15:00:53 2015
@@ -38,6 +38,8 @@
import org.lcsim.conditions.ConditionsManager;
import org.lcsim.conditions.ConditionsManagerImplementation;
import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.Subdetector;
+import org.lcsim.util.log.DefaultLogFormatter;
import org.lcsim.util.log.LogUtil;
import org.lcsim.util.loop.DetectorConditionsConverter;
@@ -59,11 +61,8 @@
@SuppressWarnings("rawtypes")
public class DatabaseConditionsManager extends ConditionsManagerImplementation {
- protected static Logger logger = LogUtil.create(DatabaseConditionsManager.class);
- static {
- logger.setLevel(Level.FINE);
- logger.getHandlers()[0].setLevel(Level.FINE);
- }
+ // Initialize logger.
+ protected static Logger logger = LogUtil.create(DatabaseConditionsManager.class.getName(), new DefaultLogFormatter(), Level.FINER);
// Registry of conditions converters.
protected ConverterRegistry converters = ConverterRegistry.create();
@@ -142,6 +141,17 @@
}
/**
+ * Set the log level.
+ * @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);
+ svtSetup.setLogLevel(level);
+ }
+
+ /**
* Get the static instance of this class.
* @return The static instance of the manager.
*/
@@ -149,11 +159,11 @@
// Is there no manager installed yet?
if (!ConditionsManager.isSetup()) {
- // Perform default setup if necessary.
+ // Create a new instance if necessary.
new DatabaseConditionsManager();
}
- // Get the instance of the manager from the conditions system and check that the type is valid.
+ // Get the instance back from the default conditions system and check that the type is correct.
ConditionsManager manager = ConditionsManager.defaultInstance();
if (!(manager instanceof DatabaseConditionsManager)) {
throw new RuntimeException("The default ConditionsManager has the wrong type.");
@@ -272,6 +282,17 @@
CollectionType conditionsCollection = getCachedConditions(type, tableName).getCachedData();
return conditionsCollection;
}
+
+ /**
+ * Get conditions data by class and name.
+ * @param type The class of the conditions.
+ * @param name The name of the conditions set.
+ * @return The conditions or null if does not exist.
+ */
+ public <T> T getConditionsData(Class<T> type, String name) {
+ logger.info("getting conditions " + name + " of type " + type.getSimpleName());
+ return getCachedConditions(type, name).getCachedData();
+ }
/**
* This method handles changes to the detector name and run number.
@@ -324,7 +345,6 @@
// Is not configured yet?
if (!isConfigured) {
if (isTestRun(runNumber)) {
- logger.config("using Test Run configuration");
// This looks like the Test Run so use the custom configuration for it.
setXmlConfig(DatabaseConditionsManager.TEST_RUN_CONFIG);
} else if (runNumber > TEST_RUN_MAX_RUN) {
@@ -336,14 +356,16 @@
}
}
+ // Register the converters for this initialization.
registerConverters();
+ // Enable or disable the setup of the SVT detector.
svtSetup.setEnabled(setupSvtDetector);
// Open the database connection.
openConnection();
- // Call the super class's setDetector method to construct the detector object and activate listeners.
+ // Call the super class's setDetector method to construct the detector object and activate conditions listeners.
super.setDetector(detectorName, runNumber);
// Should all conditions sets be cached?
@@ -406,17 +428,6 @@
*/
public Detector getDetectorObject() {
return getCachedConditions(Detector.class, "compact.xml").getCachedData();
- }
-
- /**
- * Get conditions data by class and name.
- * @param type The class of the conditions.
- * @param name The name of the conditions set.
- * @return The conditions or null if does not exist.
- */
- public <T> T getConditionsData(Class<T> type, String name) {
- logger.info("getting conditions " + name + " of type " + type.getSimpleName());
- return getCachedConditions(type, name).getCachedData();
}
/**
@@ -569,18 +580,7 @@
closeConnection(openedConnection);
return keys;
}
-
- /**
- * Set the log level.
- * @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);
- svtSetup.setLogLevel(level);
- }
-
+
/**
* Find a collection of conditions validity records by key name. The key
* name is distinct from the table name, but they are usually set to the
@@ -808,6 +808,8 @@
* @return The Logger for this class.
*/
public static Logger getLogger() {
+ //System.out.println("DatabaseConditionsManager.getLogger called from");
+ //new RuntimeException().printStackTrace();
return logger;
}
@@ -829,8 +831,20 @@
return tableRegistry.findByCollectionType(type);
}
+ /**
+ * Get the name of the ECAL in the detector geometry.
+ * @return The name of the ECAL.
+ */
public String getEcalName() {
return ecalName;
+ }
+
+ /**
+ * Get the subdetector object of the ECAL.
+ * @return The ECAL subdetector.
+ */
+ public Subdetector getEcalSubdetector() {
+ return this.getDetectorObject().getSubdetector(ecalName);
}
/*
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalChannel.java Wed Feb 25 15:00:53 2015
@@ -10,13 +10,17 @@
import org.hps.conditions.api.AbstractConditionsObject;
import org.hps.conditions.api.AbstractConditionsObjectCollection;
import org.hps.conditions.api.AbstractIdentifier;
+import org.hps.conditions.database.ConditionsObjectConverter;
import org.hps.conditions.database.Converter;
+import org.hps.conditions.database.DatabaseConditionsManager;
import org.hps.conditions.database.Field;
import org.hps.conditions.database.MultipleCollectionsAction;
import org.hps.conditions.database.Table;
+import org.lcsim.conditions.ConditionsManager;
import org.lcsim.detector.identifier.ExpandedIdentifier;
import org.lcsim.detector.identifier.IExpandedIdentifier;
import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.geometry.Subdetector;
/**
* This class encapsulates all the information about a single ECal channel,
@@ -25,9 +29,25 @@
* @author Jeremy McCormick <[log in to unmask]>
*/
@Table(names = {"ecal_channels"})
-@Converter(multipleCollectionsAction = MultipleCollectionsAction.LAST_CREATED)
+@Converter(multipleCollectionsAction = MultipleCollectionsAction.LAST_CREATED, converter = EcalChannel.EcalChannelConverter.class)
public final class EcalChannel extends AbstractConditionsObject {
-
+
+ public static final class EcalChannelConverter extends ConditionsObjectConverter<EcalChannelCollection> {
+
+ @Override
+ public EcalChannelCollection getData(ConditionsManager conditionsManager, String name) {
+ EcalChannelCollection collection = super.getData(conditionsManager, name);
+ Subdetector ecal = DatabaseConditionsManager.getInstance().getEcalSubdetector();
+ collection.buildGeometryMap(ecal.getDetectorElement().getIdentifierHelper(), ecal.getSystemID());
+ return collection;
+ }
+
+ @Override
+ public Class<EcalChannelCollection> getType() {
+ return EcalChannelCollection.class;
+ }
+ }
+
/**
* The <code>DaqId</code> is the combination of crate, slot and channel that
* specify the channel's DAQ configuration.
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/ecal/EcalConditions.java Wed Feb 25 15:00:53 2015
@@ -20,10 +20,10 @@
public final class EcalConditions {
/** Channel map. */
- EcalChannelCollection channelMap = new EcalChannelCollection();
+ EcalChannelCollection channelCollection = new EcalChannelCollection();
/** Map between channels and conditions data. */
- Map<EcalChannel, EcalChannelConstants> channelData = new HashMap<EcalChannel, EcalChannelConstants>();
+ Map<EcalChannel, EcalChannelConstants> channelConstants = new HashMap<EcalChannel, EcalChannelConstants>();
Subdetector subdetector;
@@ -41,15 +41,8 @@
* Set the channel map.
* @param channels The channel map.
*/
- void setChannelCollection(EcalChannelCollection channelMap) {
-
- this.channelMap = channelMap;
-
- // Get the full channel map created by the conditions system.
- channelMap = getChannelCollection();
-
- // Build the map of geometry IDs.
- channelMap.buildGeometryMap(subdetector.getDetectorElement().getIdentifierHelper(), subdetector.getSystemID());
+ void setChannelCollection(EcalChannelCollection channelCollection) {
+ this.channelCollection = channelCollection;
}
/**
@@ -57,7 +50,7 @@
* @return The channel map.
*/
public EcalChannelCollection getChannelCollection() {
- return channelMap;
+ return channelCollection;
}
/**
@@ -71,15 +64,14 @@
*/
public EcalChannelConstants getChannelConstants(EcalChannel channel) {
// This channel must come from the map.
- if (!channelMap.contains(channel)) {
+ if (!channelCollection.contains(channel)) {
System.err.println("Channel not found in map: " + channel);
throw new IllegalArgumentException("Channel was not found in map.");
}
// If channel has no data yet, then add it.
- // FIXME: I'm not sure this should happen at all!
- if (!channelData.containsKey(channel))
- channelData.put(channel, new EcalChannelConstants());
- return channelData.get(channel);
+ if (!channelConstants.containsKey(channel))
+ channelConstants.put(channel, new EcalChannelConstants());
+ return channelConstants.get(channel);
}
/**
@@ -123,7 +115,7 @@
buff.append('\n');
// Loop over all channels.
- for (EcalChannel channel : channelMap) {
+ for (EcalChannel channel : channelCollection) {
EcalChannelConstants constants = getChannelConstants(channel);
|