hps-java/src/main/java/org/lcsim/hps/conditions/svt
diff -u -r1.10 -r1.11
--- SvtConditionsLoader.java 11 Oct 2013 00:07:24 -0000 1.10
+++ SvtConditionsLoader.java 11 Oct 2013 01:27:13 -0000 1.11
@@ -1,17 +1,14 @@
package org.lcsim.hps.conditions.svt;
-import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
-import org.lcsim.detector.identifier.IIdentifier;
import org.lcsim.detector.tracker.silicon.HpsSiSensor;
-import org.lcsim.detector.tracker.silicon.SiSensor;
-import org.lcsim.detector.tracker.silicon.SiTrackerIdentifierHelper;
import org.lcsim.geometry.Detector;
import org.lcsim.hps.util.Pair;
/**
- * Load {@link SvtConditions} data onto a detector.
+ * Load {@link SvtConditions} data onto <code>HpsSiSensor</code> objects.
* @author Jeremy McCormick <[log in to unmask]>
*/
public class SvtConditionsLoader {
@@ -23,82 +20,50 @@
* @param conditions The conditions object.
*/
public void load(Detector detector, SvtConditions conditions) {
+
+ // Find sensor objects.
List<HpsSiSensor> sensors = detector.getDetectorElement().findDescendants(HpsSiSensor.class);
SvtChannelMap channelMap = conditions.getChannelMap();
+ SvtDaqMap daqMap = conditions.getDaqMap();
// Loop over sensors.
for (HpsSiSensor sensor : sensors) {
-
- // Get the sensor identifier helper in order to decode the id fields
- SiTrackerIdentifierHelper sensorHelper = (SiTrackerIdentifierHelper) sensor.getIdentifierHelper();
-
- // Get the sensor identifier
- IIdentifier sensorId = sensor.getIdentifier();
-
- // Get the sensor layer and module id
- int layerNumber = sensorHelper.getLayerValue(sensorId);
- int moduleNumber = sensorHelper.getModuleValue(sensorId);
- // Set the top or bottom flag on sensor.
- setSensorTopBottom(sensor, moduleNumber);
+ // Get the layer number.
+ int layerNumber = sensor.getLayerNumber();
- if (sensor.isTopLayer()) {
-
- } else {
-
+ // Get info from the DAQ map about this sensor.
+ Pair<Integer, Integer> daqPair = null;
+ int half = SvtDaqMap.TOP;
+ if (sensor.isBottomLayer()) {
+ half = SvtDaqMap.BOTTOM;
+ }
+ daqPair = daqMap.get(half, layerNumber);
+ if (daqPair == null) {
+ throw new RuntimeException("Failed to find DAQ pair for sensor: " + sensor.getName());
}
-
- // TODO: Load additional conditions onto Detector here. (Omar)
- //
- // From SvtUtils:
- //
- /*
- switch (module % 2) {
- case 0:
- listPosition = module / 2;
- // If the top layer DAQ map doesn't contain the layer, add it
- if (!topLayerDaqMap.containsKey(layer)) {
- topLayerDaqMap.put(layer, new ArrayList<Pair<Integer, Integer>>());
- }
- this.printDebug("\tAdding FPGA: " + daqPair.getFirstElement() + ", Hybrid: " + daqPair.getSecondElement() + " to position: " + listPosition);
- // Add the DAQ pair to the corresponding layer
- topLayerDaqMap.get(layer).add(listPosition, daqPair);
-
- // If the top layer sensor map doesn't contain the layer, add it
- if (!topLayerToSensor.containsKey(layer)) {
- topLayerToSensor.put(layer, new ArrayList<SiSensor>());
- }
- // Create room within the sensor map for the sensor
- topLayerToSensor.get(layer).add(null);
- break;
- case 1:
- listPosition = (module - 1) / 2;
- if (!bottomLayerDaqMap.containsKey(layer)) {
- bottomLayerDaqMap.put(layer, new ArrayList<Pair<Integer, Integer>>());
- }
- this.printDebug("\tAdding FPGA: " + daqPair.getFirstElement() + ", Hybrid: " + daqPair.getSecondElement() + " to position: " + listPosition);
- bottomLayerDaqMap.get(layer).add(listPosition, daqPair);
- if (!bottomLayerToSensor.containsKey(layer)) {
- bottomLayerToSensor.put(layer, new ArrayList<SiSensor>());
- }
- bottomLayerToSensor.get(layer).add(null);
- break;
- default:
- throw new RuntimeException("Invalid module number: " + module);
- */
- }
- }
-
- private static void setSensorTopBottom(HpsSiSensor sensor, int moduleNumber) {
- // Module 0 & 2 correspond to sensors which lie in the top SVT volume
- if (moduleNumber == 0 || moduleNumber == 2) {
- sensor.setTopLayer(true);
- // Module 1 & 3 correspond to sensors which lie in the bottom SVT volume
- } else if (moduleNumber == 1 || moduleNumber == 3) {
- sensor.setTopLayer(false);
- } else {
- throw new RuntimeException("Invalid module number <" + moduleNumber + "> for sensor <" + sensor.getName() + ">");
+ // Set FPGA value.
+ sensor.setFpgaNumber(daqPair.getFirstElement());
+
+ // Set hybrid value.
+ sensor.setHybridNumber(daqPair.getSecondElement());
+
+ // Find the channels for this sensor.
+ Collection<SvtChannel> channels = channelMap.find(daqPair);
+
+ // Loop over channels.
+ for (SvtChannel channel : channels) {
+ // Put conditions data onto the sensor object:
+ ChannelConstants constants = conditions.getChannelConstants(channel);
+ int channelNumber = channel.getChannel();
+ sensor.setBadChannel(channelNumber);
+ sensor.setGain(channelNumber, constants.getGain().getGain());
+ sensor.setTimeOffset(channelNumber, constants.getGain().getOffset());
+ sensor.setNoise(channelNumber, constants.getCalibration().getNoise());
+ sensor.setPedestal(channelNumber, constants.getCalibration().getPedestal());
+ sensor.setPulseParameters(channelNumber, constants.getPulseParameters().toArray());
+ }
}
}
-}
+}
\ No newline at end of file