Commit in java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal on MAIN
FADCConverterDriver.java+53-3572 -> 573
FADCConverterDriver now uses the new conditions, tested

java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal
FADCConverterDriver.java 572 -> 573
--- java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-05-13 09:47:47 UTC (rev 572)
+++ java/branches/ecal-recon_HPSJAVA-93/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-05-13 09:49:30 UTC (rev 573)
@@ -3,7 +3,15 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalChannel.GeometryId;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.base.BaseRawCalorimeterHit;
@@ -16,6 +24,10 @@
  */
 public class FADCConverterDriver extends Driver {
 
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
+    EcalRawConverter converter = null;
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
     String ecalCollectionName = "EcalIntegralHits";
@@ -59,7 +71,18 @@
     }
 
     @Override
-    public void detectorChanged(Detector detector) {
+    public void detectorChanged(Detector detector) {        
+        // ECAL combined conditions object.
+        ecalConditions = ConditionsManager.defaultInstance()
+                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+        
+        // List of channels.
+        channels = ecalConditions.getChannelCollection();
+        
+        // ID helper.
+        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
+        
+        System.out.println("You are now using the database conditions for FADCConverterDriver");
     }
 
     @Override
@@ -74,8 +97,12 @@
             for (RawTrackerHit hit : hits) {
                 short[] window = hit.getADCValues();
                 long id = hit.getCellID();
+                
+                // Get the channel data.
+                EcalChannelConstants channelData = findChannel(id);
+                
                 //do DAQ readout
-                double crystalThreshold = EcalConditions.physicalToPedestal(id) + threshold;
+                double crystalThreshold = channelData.getCalibration().getPedestal() + threshold;
                 int adcSum = 0;
                 int pointerOffset = 0;
                 int numSamplesToRead = 0;
@@ -100,4 +127,27 @@
         int flags = 0;
         event.put(ecalCollectionName, readoutHits, BaseRawCalorimeterHit.class, flags, ecalReadoutName);
     }
+    
+    /** 
+     * Convert physical ID to gain value.
+     * @param cellID (long)
+     * @return channel constants (EcalChannelConstants)
+     */
+    private static EcalChannelConstants findChannel(long cellID) {
+        // Make an ID object from raw hit ID.
+        IIdentifier id = new Identifier(cellID);
+        
+        // Get physical field values.
+        int system = helper.getValue(id, "system");
+        int x = helper.getValue(id, "ix");
+        int y = helper.getValue(id, "iy");
+        
+        // Create an ID to search for in channel collection.
+        GeometryId geometryId = new GeometryId(helper, new int[] { system, x, y });
+                
+        // Get the channel data.
+        return ecalConditions.getChannelConstants(channels.findChannel(geometryId));    
+    }
+    
 }
+
SVNspam 0.1