Commit in java/branches/hps_java_trunk_HPSJAVA-251 on MAIN
conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsUtil.java+3-3994 -> 995
ecal-readout-sim/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java+72-10994 -> 995
                                                   /SimpleEcalReadoutDriver.java+13-1994 -> 995
                                                   /TimeEvolutionEcalReadoutDriver.java+11-1994 -> 995
ecal-recon/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java+12-1994 -> 995
                                           /EcalEdepToTriggerConverterDriver.java+79-8994 -> 995
                                           /EcalRawConverter.java+93-12994 -> 995
                                           /EcalRawConverterDriver.java+112-13994 -> 995
                                           /EcalReadoutToTriggerConverterDriver.java+93-6994 -> 995
                                           /EcalTriggerFilterDriver.java+81-8994 -> 995
                                           /FADCConverterDriver.java+52-3994 -> 995
                                           /HPSCalorimeterHit.java+83-2994 -> 995
evio/src/main/java/org/hps/evio/ECalEvioReader.java+74-12994 -> 995
                               /ECalHitWriter.java+106-17994 -> 995
                               /TestRunReconToEvio.java+13994 -> 995
                               /TestRunTriggeredReconToEvio.java+17-1994 -> 995
                               /TestRunTriggeredReconToLcio.java+23-51994 -> 995
users/src/main/java/org/hps/users/holly/EcalClustererCosmics.java+1-1994 -> 995
+938-150
18 modified files
Merge in the HPSJAVA-91 branched modules from ecal work to the conditions dev branch and resolve conflicts.  Compiles but not tested yet.

java/branches/hps_java_trunk_HPSJAVA-251/conditions/src/main/java/org/hps/conditions/ecal
EcalConditionsUtil.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsUtil.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/conditions/src/main/java/org/hps/conditions/ecal/EcalConditionsUtil.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -38,7 +38,7 @@
      * @param cellId The cell ID of the hit.
      * @return The corresponding ECAL channel found from the physical ID information.
      */
-    EcalChannel findChannel(IIdentifierHelper helper, long cellId) {
+    public EcalChannel findChannel(IIdentifierHelper helper, long cellId) {
 
         // Make an ID object from hit ID.
         IIdentifier id = new Identifier(cellId);
@@ -61,7 +61,7 @@
      * @param cellId The cell ID of the hit.
      * @return The crate number of the channel.
      */
-    int getCrate(IIdentifierHelper helper, long cellId) {
+    public int getCrate(IIdentifierHelper helper, long cellId) {
         return findChannel(helper, cellId).getCrate();
     }
 
@@ -71,7 +71,7 @@
      * @param cellId The cell ID of the hit.
      * @return The slot number of the channel.
      */
-    int getSlot(IIdentifierHelper helper, long cellId) {
+    public int getSlot(IIdentifierHelper helper, long cellId) {
         return findChannel(helper, cellId).getSlot();
     }
 

java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal
FADCEcalReadoutDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/FADCEcalReadoutDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -15,7 +15,16 @@
 import java.util.PriorityQueue;
 import java.util.Set;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+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.hps.recon.ecal.ECalUtils;
 import org.hps.recon.ecal.HPSRawCalorimeterHit;
 import org.lcsim.event.CalorimeterHit;
@@ -45,6 +54,9 @@
     private static final int ECAL_PULSE_INTEGRAL_MODE = 3;
     String ecalName = "Ecal";
     Subdetector ecal;
+    EcalConditions ecalConditions = null;
+    IIdentifierHelper helper = null;
+    EcalChannelCollection channels = null; 
     //buffer for preamp signals (units of volts, no pedestal)
     private Map<Long, RingBuffer> signalMap = null;
     //ADC pipeline for readout (units of ADC counts)
@@ -229,9 +241,12 @@
 
             FADCPipeline pipeline = pipelineMap.get(cellID);
             pipeline.step();
+           
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
 
             double currentValue = signalBuffer.currentValue() * ((Math.pow(2, nBit) - 1) / maxVolt); //12-bit ADC with maxVolt V range
-            int pedestal = (int) Math.round(EcalConditions.physicalToPedestal(cellID));
+            int pedestal = (int) Math.round(channelData.getCalibration().getPedestal());
             int digitizedValue = Math.min((int) Math.round(pedestal + currentValue), (int) Math.pow(2, nBit)); //ADC can't return a value larger than 4095; 4096 (overflow) is returned for any input >2V
             pipeline.writeValue(digitizedValue);
             int pedestalSubtractedValue = digitizedValue - pedestal;
@@ -285,7 +300,7 @@
         }
         while (outputQueue.peek() != null && outputQueue.peek().getTimeStamp() / 64 <= readoutCounter - delay0) {
             if (outputQueue.peek().getTimeStamp() / 64 < readoutCounter - delay0) {
-                System.out.println(this.getName() + ": Stale hit in output queue");
+                System.out.println("Stale hit in output queue");
                 outputQueue.poll();
             } else {
                 buffer.add(outputQueue.poll());
@@ -374,6 +389,10 @@
             int pointerOffset = 0;
             int numSamplesToRead = 0;
             int thresholdCrossing = 0;
+            
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
+            
             for (int i = 0; i < readoutWindow; i++) {
                 if (numSamplesToRead != 0) {
                     adcValues[adcValues.length - numSamplesToRead] = window[i - pointerOffset];
@@ -381,7 +400,7 @@
                     if (numSamplesToRead == 0) {
                         hits.add(new BaseRawTrackerHit(cellID, thresholdCrossing, adcValues));
                     }
-                } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
+                } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
                     thresholdCrossing = i;
                     pointerOffset = Math.min(numSamplesBefore, i);
                     numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -401,6 +420,10 @@
             int pointerOffset = 0;
             int numSamplesToRead = 0;
             int thresholdCrossing = 0;
+            
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(cellID);
+            
             if (window != null) {
                 for (int i = 0; i < readoutWindow; i++) {
                     if (numSamplesToRead != 0) {
@@ -412,7 +435,7 @@
                         if (numSamplesToRead == 0) {
                             hits.add(new BaseRawCalorimeterHit(cellID, adcSum, 64 * thresholdCrossing));
                         }
-                    } else if ((i == 0 || window[i - 1] <= EcalConditions.physicalToPedestal(cellID) + readoutThreshold) && window[i] > EcalConditions.physicalToPedestal(cellID) + readoutThreshold) {
+                    } else if ((i == 0 || window[i - 1] <= channelData.getCalibration().getPedestal() + readoutThreshold) && window[i] > channelData.getCalibration().getPedestal() + readoutThreshold) {
                         thresholdCrossing = i;
                         pointerOffset = Math.min(numSamplesBefore, i);
                         numSamplesToRead = pointerOffset + Math.min(numSamplesAfter, readoutWindow - i - pointerOffset - 1);
@@ -430,13 +453,15 @@
         for (CalorimeterHit hit : hits) {
             RingBuffer eDepBuffer = signalMap.get(hit.getCellID());
             double energyAmplitude = hit.getRawEnergy();
+            // Get the channel data.
+            EcalChannelConstants channelData = findChannel(hit.getCellID());
             if (addNoise) {
                 //add preamp noise and photoelectron Poisson noise in quadrature
                 double noise;
                 if (use2014Gain) {
-                    noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
+                    noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod, 2) + hit.getRawEnergy() / (ECalUtils.lightYield * ECalUtils.quantumEff * ECalUtils.surfRatio));
                 } else {
-                    noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
+                    noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
                 }
                 energyAmplitude += RandomGaussian.getGaussian(0, noise);
             }
@@ -459,6 +484,17 @@
     public void detectorChanged(Detector detector) {
         // Get the Subdetector.
         ecal = detector.getSubdetector(ecalName);
+        
+        // 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();
+        
         resetFADCBuffers();
     }
 
@@ -470,20 +506,24 @@
         pipelineMap = new HashMap<Long, FADCPipeline>();
         Set<Long> cells = ((HPSEcal3) ecal).getNeighborMap().keySet();
         for (Long cellID : cells) {
+        	EcalChannelConstants channelData = findChannel(cellID);
             signalMap.put(cellID, new RingBuffer(bufferLength));
-            pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(EcalConditions.physicalToPedestal(cellID))));
+            pipelineMap.put(cellID, new FADCPipeline(pipelineLength, (int) Math.round(channelData.getCalibration().getPedestal())));
         }
         return true;
     }
 
     private double pulseAmplitude(double time, long cellID) {
+    	
+    	EcalChannelConstants channelData = findChannel(cellID);
+    	
         if (use2014Gain) {
             //if fixedGain is set, multiply the default gain by this factor
             double corrGain;
             if (fixedGain > 0) {
                 corrGain = fixedGain;
             } else {
-                corrGain = 1.0 / EcalConditions.physicalToGain(cellID);
+                corrGain = 1.0 / channelData.getGain().getGain();
             }
 
             return corrGain * readoutGain * pulseAmplitude(time, pulseShape, tp);
@@ -493,7 +533,7 @@
             if (fixedGain > 0) {
                 gain = readoutPeriod / (fixedGain * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
             } else {
-                gain = readoutPeriod / (EcalConditions.physicalToGain(cellID) * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
+                gain = readoutPeriod / (channelData.getGain().getGain() * ECalUtils.MeV * ((Math.pow(2, nBit) - 1) / maxVolt));
             }
 
             return gain * pulseAmplitude(time, pulseShape, tp);
@@ -584,4 +624,26 @@
             return array[((ptr - pos) % size + size) % size];
         }
     }
+    
+    // Convert physical ID to gain value.
+    private 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 });
+        
+        // Find the ECAL channel.
+//        return channels.findChannel(geometryId);
+                
+        // Get the channel data.
+        return ecalConditions.getChannelConstants(channels.findChannel(geometryId));
+    }
+    
 }
+

java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal
SimpleEcalReadoutDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/SimpleEcalReadoutDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -6,6 +6,7 @@
 
 import org.hps.recon.ecal.HPSCalorimeterHit;
 import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.Detector;
 
 /**
  * Performs readout of ECal hits.
@@ -17,12 +18,21 @@
 public class SimpleEcalReadoutDriver extends EcalReadoutDriver<HPSCalorimeterHit> {
     //buffer for deposited energy
     Map<Long, Double> eDepMap = null;
+    
+    Detector detector = null;
+    
+    HPSCalorimeterHit h = null;
 
 	public SimpleEcalReadoutDriver() {
 		hitClass = HPSCalorimeterHit.class;
 	}
 
     @Override
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
+    }
+	
+    @Override
     protected void readHits(List<HPSCalorimeterHit> hits) {
         for (Long cellID : eDepMap.keySet()) {
 //            int ix = dec.getValue("ix");
@@ -32,7 +42,9 @@
 //            if (iy == 1 && ix*side >= -10 && ix*side <= -2)
 //                continue;
             if (eDepMap.get(cellID) > threshold)
-                hits.add(new HPSCalorimeterHit(eDepMap.get(cellID), readoutTime(), cellID, hitType));
+            	h = new HPSCalorimeterHit(eDepMap.get(cellID), readoutTime(), cellID, hitType); 
+                h.setDetector(detector);
+                hits.add(h);
         }
         //reset hit integration
         eDepMap = new HashMap<Long, Double>();

java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal
TimeEvolutionEcalReadoutDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-readout-sim/src/main/java/org/hps/readout/ecal/TimeEvolutionEcalReadoutDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -6,6 +6,7 @@
 
 import org.hps.recon.ecal.HPSCalorimeterHit;
 import org.lcsim.event.CalorimeterHit;
+import org.lcsim.geometry.Detector;
 
 /**
  * Performs readout of ECal hits.
@@ -16,12 +17,19 @@
  */
 public class TimeEvolutionEcalReadoutDriver extends EcalReadoutDriver<HPSCalorimeterHit> {
 
+	Detector detector = null;
+	
     //buffer for deposited energy
     Map<Long, RingBuffer> eDepMap = null;
     //length of ring buffer (in readout cycles)
     int bufferLength = 20;
     //shaper time constant in ns; negative values generate square pulses of the given width
     double t0 = 18.0;
+    
+    @Override
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
+    }
 
     public TimeEvolutionEcalReadoutDriver() {
 		hitClass = HPSCalorimeterHit.class;
@@ -45,7 +53,9 @@
 //                int iy = dec.getValue("iy");
 //                if (iy == 1 && ix == -2)
 //                    System.out.printf("Time %f, output signal %f\n", ClockSingleton.getTime(), eDepBuffer.currentValue());
-                hits.add(new HPSCalorimeterHit(eDepBuffer.currentValue(), readoutTime(), cellID, hitType));
+            	HPSCalorimeterHit h = new HPSCalorimeterHit(eDepBuffer.currentValue(), readoutTime(), cellID, hitType);
+            	h.setDetector(detector);
+            	hits.add(h);
             }
             eDepBuffer.step();
         }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalConverterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalConverterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -2,9 +2,11 @@
 
 import java.util.ArrayList;
 import java.util.List;
+
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawCalorimeterHit;
+import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 import org.lcsim.lcio.LCIOConstants;
 
@@ -14,6 +16,8 @@
  * @version $Id: EcalConverterDriver.java,v 1.1 2013/02/25 22:39:24 meeg Exp $
  */
 public class EcalConverterDriver extends Driver {
+	
+	Detector detector = null;
 
     String rawCollectionName;
     String ecalReadoutName = "EcalHits";
@@ -51,6 +55,11 @@
             throw new RuntimeException("The parameter ecalCollectionName was not set!");
         }
     }
+    
+    @Override
+    public void detectorChanged(Detector detector) {
+    	this.detector = detector;
+    }
 
     @Override
     public void process(EventHeader event) {
@@ -77,7 +86,9 @@
     }
 
     private CalorimeterHit HitDtoA(RawCalorimeterHit hit) {
-        return new HPSCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+    	HPSCalorimeterHit h = new HPSCalorimeterHit(DtoA(hit.getAmplitude(), hit.getCellID()), period * hit.getTimeStamp() + dt, hit.getCellID(), 0);
+        h.setDetector(detector);
+    	return h;
     }
 
 //    private RawCalorimeterHit HitAtoD(CalorimeterHit hit) {

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalEdepToTriggerConverterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalEdepToTriggerConverterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -3,20 +3,40 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.deprecated.EcalConditions;
+
+//import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+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.hps.conditions.ecal.EcalConditionsUtil;
+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.hps.util.RandomGaussian;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 
+
 /**
  *
  * @version $Id: HPSEcalRawConverterDriver.java,v 1.2 2012/05/03 00:17:54
  * phansson Exp $
  */
 public class EcalEdepToTriggerConverterDriver extends Driver {
-
+	
+	Detector detector = null;
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
+    
+    private static boolean isBadChannelLoaded = true;
+	
     private String ecalReadoutName = "EcalHits";
     private String inputCollection = "EcalHits";
     private String readoutCollection = "EcalCalHits";
@@ -75,12 +95,31 @@
         }
     }
 
+
     @Override
     public void detectorChanged(Detector detector) {
+    	
+    	//Must be set to use the database conditions
+        this.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 EcalEdepToTriggerConverterDriver.");
     }
 
     public boolean isBadCrystal(CalorimeterHit hit) {
-        return EcalConditions.badChannelsLoaded() ? EcalConditions.isBadChannel(hit.getCellID()) : false;
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+    	
+        return isBadChannelLoaded ? channelData.isBadChannel() : false;
     }
 
     @Override
@@ -141,7 +180,9 @@
 
         int truncatedIntegral = (int) Math.floor(triggerIntegral / truncateScale);
         if (truncatedIntegral > 0) {
-            return new HPSCalorimeterHit(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);
+        	HPSCalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hit.getTime(), hit.getCellID(), 0);
+        	h.setDetector(detector);
+            return h ;
         }
         return null;
     }
@@ -151,8 +192,12 @@
             return null;
         }
 
+        
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+        
 //        double integral = hit.getRawEnergy()/ECalUtils.GeV * gainScale;
-        double gain = _gain > 0 ? _gain : EcalConditions.physicalToGain(hit.getCellID());
+        double gain = _gain > 0 ? _gain : channelData.getGain().getGain();
         double integral = amplitude * gain * pulseIntegral * gainScale * ECalUtils.MeV / ECalUtils.GeV;
 
 //        double thresholdCrossingTime = 0 - hit.getTime();
@@ -176,19 +221,24 @@
 //        System.out.format("dumb: %f, full: %f\n",hit.getRawEnergy() * 1000.0,readoutIntegral * HPSEcalConditions.physicalToGain(id));
 
 //        System.out.format("readout: %f %f\n", amplitude, integral);
-        CalorimeterHit h = new HPSCalorimeterHit(integral, hit.getTime(), hit.getCellID(), 0);
+        HPSCalorimeterHit h = new HPSCalorimeterHit(integral, hit.getTime(), hit.getCellID(), 0);
+        h.setDetector(detector);
         return h;
     }
 
     private double hitAmplitude(CalorimeterHit hit) {
         double energyAmplitude = hit.getRawEnergy();
+        
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+        
         if (addNoise) {
             //add preamp noise and photoelectron Poisson noise in quadrature
-            double noise = Math.sqrt(Math.pow(EcalConditions.physicalToNoise(hit.getCellID()) * EcalConditions.physicalToGain(hit.getCellID()) * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
+            double noise = Math.sqrt(Math.pow(channelData.getCalibration().getNoise() * channelData.getGain().getGain() * ECalUtils.MeV, 2) + hit.getRawEnergy() * ECalUtils.MeV / pePerMeV);
             energyAmplitude += RandomGaussian.getGaussian(0, noise);
         }
 
-        double gain = _gain > 0 ? _gain : EcalConditions.physicalToGain(hit.getCellID());
+        double gain = _gain > 0 ? _gain : channelData.getGain().getGain();
 //        System.out.format("amplitude: %f %f %f %f\n", hit.getRawEnergy(), energyAmplitude, gain, (energyAmplitude / ECalUtils.MeV) / (gain * pulseIntegral));
         return (energyAmplitude / ECalUtils.MeV) / (gain * pulseIntegral);
     }
@@ -207,4 +257,25 @@
             }
         }
     }
+    
+    /** 
+     * 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));    
+    }
 }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalRawConverter.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalRawConverter.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalRawConverter.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -1,10 +1,22 @@
 package org.hps.recon.ecal;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.DatabaseConditionsManager;
+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.hps.conditions.ecal.EcalConditionsUtil;
+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.CalorimeterHit;
 import org.lcsim.event.RawCalorimeterHit;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.base.BaseRawCalorimeterHit;
+import org.lcsim.geometry.Detector;
 
 /**
  *
@@ -17,8 +29,17 @@
     private boolean constantGain = false;
     private double gain;
     private boolean use2014Gain = true;
+    
+    //get the database condition manager
+    
+//    Detector detector = DatabaseConditionsManager.getInstance().getDetectorObject();
+    Detector detector = null;
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
 
-    public EcalRawConverter() {
+
+    public EcalRawConverter() {	
     }
 
     public void setGain(double gain) {
@@ -36,7 +57,11 @@
         if (debug) {
             System.out.println("Summing ADC for hit: " + hit.toString());
         }
-        double pedestal = EcalConditions.physicalToPedestal(hit.getCellID());
+        
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+        
+        double pedestal = channelData.getCalibration().getPedestal();
         short sum = 0;
         short samples[] = hit.getADCValues();
         for (int isample = 0; isample < samples.length; ++isample) {
@@ -52,10 +77,12 @@
         double time = hit.getTime();
         long id = hit.getCellID();
         double rawEnergy = adcToEnergy(sumADC(hit), id);
+        HPSCalorimeterHit h1 = new HPSCalorimeterHit(rawEnergy + 0.0000001, time, id, 0);
+        h1.setDetector(detector);
+        
 //        double[] pos = hit.getDetectorElement().getGeometry().getPosition().v();
-        CalorimeterHit h = new HPSCalorimeterHit(rawEnergy + 0.0000001, time, id, 0);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
-        return h;
+        return h1;
     }
 
     public CalorimeterHit HitDtoA(RawCalorimeterHit hit, int window, double timeOffset) {
@@ -64,21 +91,26 @@
         }
         double time = hit.getTimeStamp() / 16.0;
         long id = hit.getCellID();
-        double adcSum = hit.getAmplitude() - window * EcalConditions.physicalToPedestal(id);
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(id);
+        double adcSum = hit.getAmplitude() - window * channelData.getCalibration().getPedestal();
         double rawEnergy = adcToEnergy(adcSum, id);
-        CalorimeterHit h = new HPSCalorimeterHit(rawEnergy + 0.0000001, time + timeOffset, id, 0);
+        HPSCalorimeterHit h2 = new HPSCalorimeterHit(rawEnergy + 0.0000001, time + timeOffset, id, 0);
+        h2.setDetector(detector);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
-        return h;
+        return h2;
     }
 
     public RawCalorimeterHit HitAtoD(CalorimeterHit hit, int window) {
         int time = (int) (Math.round(hit.getTime() / 4.0) * 64.0);
         long id = hit.getCellID();
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(id);
         int amplitude;
         if (constantGain) {
-            amplitude = (int) Math.round((hit.getRawEnergy() / ECalUtils.MeV) / gain + window * EcalConditions.physicalToPedestal(id));
+            amplitude = (int) Math.round((hit.getRawEnergy() / ECalUtils.MeV) / gain + window * channelData.getCalibration().getPedestal());
         } else {
-            amplitude = (int) Math.round((hit.getRawEnergy() / ECalUtils.MeV) / EcalConditions.physicalToGain(id) + window * EcalConditions.physicalToPedestal(id));
+            amplitude = (int) Math.round((hit.getRawEnergy() / ECalUtils.MeV) / channelData.getGain().getGain() + window * channelData.getCalibration().getPedestal());
         }
         RawCalorimeterHit h = new BaseRawCalorimeterHit(id, amplitude, time);
         return h;
@@ -88,17 +120,21 @@
      * return energy (units of GeV) corresponding to the ADC sum and crystal ID
      */
     private double adcToEnergy(double adcSum, long cellID) {
+    	
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(cellID);
+    	
         if (use2014Gain) {
             if (constantGain) {
                 return adcSum * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod;
             } else {
-                return EcalConditions.physicalToGain(cellID) * adcSum * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod; // should not be used for the moment (2014/02)
+                return channelData.getGain().getGain() * adcSum * ECalUtils.gainFactor * ECalUtils.ecalReadoutPeriod; // should not be used for the moment (2014/02)
             }
         } else {
             if (constantGain) {
                 return gain * adcSum * ECalUtils.MeV;
             } else {
-                return EcalConditions.physicalToGain(cellID) * adcSum * ECalUtils.MeV; //gain is defined as MeV/integrated ADC
+                return channelData.getGain().getGain() * adcSum * ECalUtils.MeV; //gain is defined as MeV/integrated ADC
             }
         }
     }
@@ -115,4 +151,49 @@
      return h;
      }
      */
+    /** 
+     * Must be set when an object EcalRawConverter is created.
+     * @param detector (long)
+     */   
+    void setDetector(Detector detector) {
+    	
+//    	h1.setDetector(detector);
+//    	h2.setDetector(detector);
+    	
+        this.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 EcalRawConverter.");
+    }
+    
+    /** 
+     * 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));    
+    }   
+    
 }
\ No newline at end of file

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalRawConverterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalRawConverterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -3,7 +3,19 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+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.hps.conditions.ecal.EcalConditionsUtil;
+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.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.GenericObject;
@@ -20,6 +32,13 @@
  */
 public class EcalRawConverterDriver extends Driver {
 
+	// To import database conditions
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
+    
+    Detector detector = null;
+    
     EcalRawConverter converter = null;
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
@@ -32,9 +51,10 @@
     private boolean runBackwards = false;
     private boolean useTimestamps = false;
     private boolean useTruthTime = false;
+    private static boolean isBadChannelLoaded = true;
 
     public EcalRawConverterDriver() {
-        converter = new EcalRawConverter();
+    	converter = new EcalRawConverter();    	
     }
 
     public void setUse2014Gain(boolean use2014Gain) {
@@ -94,17 +114,43 @@
 
     @Override
     public void detectorChanged(Detector detector) {
+    	
+    	converter.setDetector(detector);
+    	
+    	// set the detector for the converter
+        this.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 EcalRawConverterDriver.");
     }
-
-    public static boolean isBadCrystal(CalorimeterHit hit) {
-        return EcalConditions.badChannelsLoaded() ? EcalConditions.isBadChannel(hit.getCellID()) : false;
+    /**
+     * @return false if the channel is a good one, true if it is a bad one
+     * @param CalorimeterHit
+     */
+    public static boolean isBadCrystal(CalorimeterHit hit) {   	
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+    	
+        return isBadChannelLoaded ? channelData.isBadChannel() : false;
     }
-
-    public static boolean isBadFADC(CalorimeterHit hit) {
-        long daqID = EcalConditions.physicalToDaqID(hit.getCellID());
-        return (EcalConditions.getCrate(daqID) == 1 && EcalConditions.getSlot(daqID) == 3);
+    
+    /**
+     * @return false if the ADC is a good one, true if it is a bad one
+     * @param CalorimeterHit
+     */
+    public boolean isBadFADC(CalorimeterHit hit) {    	
+        return (getCrate(hit.getCellID()) == 1 && getSlot(hit.getCellID()) == 3);
     }
-
+    
     private static double getTimestamp(int system, EventHeader event) { //FIXME: copied from org.hps.readout.ecal.ReadoutTimestamp
         if (event.hasCollection(GenericObject.class, "ReadoutTimestamps")) {
             List<GenericObject> timestamps = event.get(GenericObject.class, "ReadoutTimestamps");
@@ -135,8 +181,8 @@
             double t0ECal = getTimestamp(SYSTEM_ECAL, event);
             timeOffset += ((t0ECal + 250.0) % 500.0) - 250.0;
         }
-
-
+    	
+    	
         int flags = 0;
         flags += 1 << LCIOConstants.RCHBIT_TIME; //store hit time
         flags += 1 << LCIOConstants.RCHBIT_LONG; //store hit position; this flag has no effect for RawCalorimeterHits
@@ -150,7 +196,11 @@
 
                 for (RawTrackerHit hit : hits) {
                     CalorimeterHit newHit = converter.HitDtoA(hit);
-                    if (applyBadCrystalMap && isBadCrystal(newHit)) {
+             
+                    // Get the channel data.
+                    EcalChannelConstants channelData = findChannel(newHit.getCellID());
+                    
+                    if (applyBadCrystalMap && channelData.isBadChannel()) {
                         continue;
                     }
                     if (dropBadFADC && isBadFADC(newHit)) {
@@ -170,6 +220,7 @@
                         System.out.format("old hit energy %d\n", hit.getAmplitude());
                     }
                     CalorimeterHit newHit = converter.HitDtoA(hit, integralWindow, timeOffset);
+                    
                     if (newHit.getRawEnergy() > threshold) {
                         if (applyBadCrystalMap && isBadCrystal(newHit)) {
                             continue;
@@ -206,4 +257,52 @@
             }
         }
     }
+    
+    
+    /** 
+     * 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));    
+    }
+    
+    /**
+     * Return crate number from cellID
+     * @param cellID (long)
+     * @return Crate number (int)
+     */
+    private int getCrate(long cellID) {
+        
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getCrate(helper, cellID);
+    }
+    
+    /**
+     * Return slot number from cellID
+     * @param cellID (long)
+     * @return Slot number (int)
+     */
+    private int getSlot(long cellID) {
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getSlot(helper, cellID);         
+    }
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalReadoutToTriggerConverterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalReadoutToTriggerConverterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -3,7 +3,19 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+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.hps.conditions.ecal.EcalConditionsUtil;
+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.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.base.BaseRawCalorimeterHit;
@@ -17,6 +29,12 @@
  */
 public class EcalReadoutToTriggerConverterDriver extends Driver {
 
+	// To import database conditions
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null;
+	Detector detector = null;
+	
     String rawCollectionName = "EcalReadoutHits";
     String ecalReadoutName = "EcalHits";
     String ecalCollectionName = "EcalCalHits";
@@ -31,6 +49,7 @@
     private int triggerThreshold = 80;
     private double timeShift = 0;
     private int truncateScale = 128;
+    private static boolean isBadChannelLoaded = true;
 
     public EcalReadoutToTriggerConverterDriver() {
     }
@@ -76,15 +95,30 @@
 
     @Override
     public void detectorChanged(Detector detector) {
+    	this.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 EcalReadoutToTriggerConverterDriver.");
     }
 
     public boolean isBadCrystal(CalorimeterHit hit) {
-        return EcalConditions.badChannelsLoaded() ? EcalConditions.isBadChannel(hit.getCellID()) : false;
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+    	
+        return isBadChannelLoaded ? channelData.isBadChannel() : false;
     }
 
     public boolean isBadFADC(CalorimeterHit hit) {
-        long daqID = EcalConditions.physicalToDaqID(hit.getCellID());
-        return (EcalConditions.getCrate(daqID) == 1 && EcalConditions.getSlot(daqID) == 3);
+        return (getCrate(hit.getCellID()) == 1 && getSlot(hit.getCellID()) == 3);
     }
 
     @Override
@@ -112,8 +146,12 @@
     }
 
     public CalorimeterHit HitDtoA(BaseRawCalorimeterHit hit, int window) {
+    	
+        // Get the channel data.
+        EcalChannelConstants channelData = findChannel(hit.getCellID());
+    	
         double integral = tp * Math.E / readoutPeriod;
-        double readoutIntegral = (hit.getAmplitude() - window * EcalConditions.physicalToPedestal(hit.getCellID()));
+        double readoutIntegral = (hit.getAmplitude() - window * channelData.getCalibration().getPedestal());
         double amplitude = readoutIntegral / integral;
 
 //        double time = readoutPeriod * (Math.random() - 1);
@@ -168,7 +206,8 @@
         if (truncatedIntegral <= 0) {
             truncatedIntegral = 0;
         }
-        CalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hitTime, id, 0);
+        HPSCalorimeterHit h = new HPSCalorimeterHit(truncatedIntegral, hitTime, id, 0);
+        h.setDetector(detector);
 //        CalorimeterHit h = new HPSRawCalorimeterHit(triggerIntegral + 0.0000001, hit.getPosition(), hitTime, id, 0);
         //+0.0000001 is a horrible hack to ensure rawEnergy!=BaseCalorimeterHit.UNSET_CORRECTED_ENERGY
         return h;
@@ -188,4 +227,52 @@
             }
         }
     }
+
+    /** 
+     * 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));    
+    }  
+    
+    /**
+     * Return crate number from cellID
+     * @param cellID (long)
+     * @return Crate number (int)
+     */
+    private int getCrate(long cellID) {
+        
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getCrate(helper, cellID);
+    }
+    
+    /**
+     * Return slot number from cellID
+     * @param cellID (long)
+     * @return Slot number (int)
+     */
+    private int getSlot(long cellID) {
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getSlot(helper, cellID);         
+    }
+    
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
EcalTriggerFilterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/EcalTriggerFilterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -5,7 +5,18 @@
 import java.util.Queue;
 import java.util.concurrent.ArrayBlockingQueue;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.DaqId;
+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.hps.conditions.ecal.EcalConditionsUtil;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.EventHeader;
 import org.lcsim.geometry.Detector;
@@ -18,6 +29,13 @@
  */
 public class EcalTriggerFilterDriver extends Driver {
 
+	// To import database conditions
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null;
+    int systemId;
+    Detector detector = null;
+    
     private String ecalReadoutName = "EcalHits";
     private String inputCollection = "EcalReadoutHits";
     private String outputCollection = "EcalCalHits";
@@ -55,6 +73,22 @@
 
     @Override
     public void detectorChanged(Detector detector) {
+    	
+    	this.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();
+
+        systemId = detector.getSubdetector("Ecal").getSystemID();
+        
+        System.out.println("You are now using the database conditions for EcalTriggerFilterDriver.");
     }
 
     @Override
@@ -85,15 +119,19 @@
         }
     }
 
+    /**
+     * This method takes input hits and makes new hits with different ix
+     * @param CalorimeterHit hit
+     * @return new HPSCalorimeterHit
+     */
     private CalorimeterHit filterHit(CalorimeterHit hit) {
         int ix = hit.getIdentifierFieldValue("ix");
         int iy = hit.getIdentifierFieldValue("iy");
-        long daqID = EcalConditions.physicalToDaqID(hit.getCellID());
-        int crate = EcalConditions.getCrate(daqID);
-        short slot = EcalConditions.getSlot(daqID);
-        short channel = EcalConditions.getChannel(daqID);
+        int crate = getCrate(hit.getCellID());
+        int slot = getSlot(hit.getCellID());
 
-        int delay = iy>0?topDelay:bottomDelay;
+        int delay = iy>0?topDelay:bottomDelay;  
+        
         // no triggers from crate 1, slot 3 
         if (crate == 1 && slot == 3) {
             return null;
@@ -103,8 +141,43 @@
         if (ix > 0 && iy > 0) {
             ix = 24 - ix;
         }
-        long newID = EcalConditions.makePhysicalID(ix, iy);
+     
+        int values[] = {systemId, ix, iy};
+        GeometryId geomId = new GeometryId(helper, values);       
+        // Creating the new channel from cell id, ix and iy, then reading its ID       
+        long newID = geomId.encode();      
+        
         //make new hit; set position to null so it gets recalculated
-        return new HPSCalorimeterHit(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
+        HPSCalorimeterHit h = new HPSCalorimeterHit(hit.getRawEnergy(), hit.getTime()+delay*4, newID, hit.getType());
+        h.setDetector(detector);
+        return h;
     }
+    
+    /**
+     * Return crate number from cellID
+     * @param cellID (long)
+     * @return Crate number (int)
+     */
+    private int getCrate(long cellID) {
+        
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getCrate(helper, cellID);
+    }
+    
+    /**
+     * Return slot number from cellID
+     * @param cellID (long)
+     * @return Slot number (int)
+     */
+    private int getSlot(long cellID) {
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getSlot(helper, cellID);         
+    } 
+ 
+    
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
FADCConverterDriver.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/FADCConverterDriver.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -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 {
 
+    EcalConditions ecalConditions = null;
+    IIdentifierHelper helper = null;
+    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,26 @@
         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 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));    
+    }
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal
HPSCalorimeterHit.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/ecal-recon/src/main/java/org/hps/recon/ecal/HPSCalorimeterHit.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -4,11 +4,21 @@
 
 import java.util.Comparator;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ConditionsDriver;
+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.hps.conditions.ecal.EcalConditionsUtil;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifier;
+import org.lcsim.detector.identifier.IIdentifierHelper;
 import org.lcsim.detector.IDetectorElement;
 import org.lcsim.detector.IDetectorElementContainer;
 import org.lcsim.event.CalorimeterHit;
 import org.lcsim.event.base.BaseCalorimeterHit;
+import org.lcsim.geometry.Detector;
 
 /**
  * An implementation of CalorimeterHit, with a constructor that sets rawEnergy
@@ -19,6 +29,11 @@
  */
 public class HPSCalorimeterHit extends BaseCalorimeterHit {
 
+    Detector detector = null;    
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
+
     /**
      * Fully qualified constructor that sets rawEnergy
      *
@@ -27,9 +42,53 @@
      * @param time     Time of energy deposition
      * @param id       Cell ID
      * @param type     Type
+     * WARNING: setDetector(detector° must be called after initialization
      */
     public HPSCalorimeterHit(double energy, double time, long id, int type) {
         this.rawEnergy = energy;
+//      if (position != null) {
+//          this.positionVec = new BasicHep3Vector(position);
+//      } else {
+//          positionVec = null;
+//      }
+      this.time = time;
+      this.id = id;
+      this.type = type;
+    }
+    
+    /**
+     * Fully qualified constructor that sets rawEnergy
+     *
+     * @param energy   Raw energy for this cell
+     * @param position Global Cartesian coordinate for this cell
+     * @param time     Time of energy deposition
+     * @param id       Cell ID
+     * @param type     Type
+     * WARNING: setDetector(detector) must be called after initialization
+     */
+    public HPSCalorimeterHit(CalorimeterHit hit) {
+        this.rawEnergy = hit.getRawEnergy();
+//      if (position != null) {
+//          this.positionVec = new BasicHep3Vector(position);
+//      } else {
+//          positionVec = null;
+//      }
+      this.time = hit.getTime();
+      this.id = hit.getCellID();
+      this.type = hit.getType();
+    }
+    
+    /**
+     * Fully qualified constructor that sets rawEnergy
+     *
+     * @param energy   Raw energy for this cell
+     * @param position Global Cartesian coordinate for this cell
+     * @param time     Time of energy deposition
+     * @param id       Cell ID
+     * @param type     Type
+     */
+    public void setParameters(double energy, double time, long id, int type) {
+        this.rawEnergy = energy;
 //        if (position != null) {
 //            this.positionVec = new BasicHep3Vector(position);
 //        } else {
@@ -44,7 +103,7 @@
     public IDetectorElement getDetectorElement() {
         if (de == null) {
 //            findDetectorElementByPosition();
-            IDetectorElementContainer detectorElements = EcalConditions.getSubdetector().getDetectorElement().findDetectorElement(getIdentifier());
+            IDetectorElementContainer detectorElements = detector.getDetectorElement().findDetectorElement(getIdentifier());
             if (detectorElements.size() != 1) {
                 throw new RuntimeException("Expected exactly one DetectorElement matching ID " + getIdentifier() + ", got " + detectorElements.size());
             } else {
@@ -72,4 +131,26 @@
             return Double.compare(o1.getTime(), o2.getTime());
         }
     }
+    
+    /** 
+     * Must be set when an object HPSCalorimeterHit is created.
+     * @param detector (long)
+     */
+    public void setDetector(Detector detector) {
+        this.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 HPSCalorimeterHit.");
+    }
+    
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio
ECalEvioReader.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/ECalEvioReader.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/ECalEvioReader.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -3,18 +3,32 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ConditionsDriver;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannel;
+import org.hps.conditions.ecal.EcalChannel.DaqId;
+import org.hps.conditions.ecal.EcalChannel.GeometryId;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
+import org.lcsim.conditions.ConditionsManager;
+import org.lcsim.detector.identifier.IIdentifierHelper;
+import org.lcsim.detector.identifier.Identifier;
+//import org.hps.conditions.deprecated.EcalConditions;
 import org.jlab.coda.jevio.BaseStructure;
 import org.jlab.coda.jevio.BaseStructureHeader;
 import org.jlab.coda.jevio.CompositeData;
 import org.jlab.coda.jevio.EvioEvent;
 import org.jlab.coda.jevio.EvioException;
-import org.lcsim.detector.identifier.Identifier;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.RawTrackerHit;
 import org.lcsim.event.SimTrackerHit;
 import org.lcsim.event.base.BaseRawCalorimeterHit;
 import org.lcsim.event.base.BaseRawTrackerHit;
+import org.lcsim.geometry.Detector;
+import org.lcsim.geometry.Subdetector;
 import org.lcsim.lcio.LCIOConstants;
 
 /**
@@ -27,9 +41,35 @@
 
     private int bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG;
     private Class hitClass = BaseRawCalorimeterHit.class;
+    
+    // FIXME: Hard-coded detector names.
+    private static String readoutName = "EcalHits";
+    private static String subdetectorName = "Ecal";
+    Detector detector;
+    Subdetector subDetector;
+    
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null; 
 
     public ECalEvioReader() {
         hitCollectionName = "EcalReadoutHits";
+        
+        detector = DatabaseConditionsManager.getInstance().getDetectorObject();
+        subDetector = detector.getSubdetector(subdetectorName);
+        
+        // ECAL combined conditions object.
+        ecalConditions = ConditionsManager.defaultInstance()
+                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+        
+        // List of channels.
+        channels = ecalConditions.getChannelCollection();
+        
+        helper = subDetector.getDetectorElement().getIdentifierHelper();
+        
+        System.out.println("You are now using the database conditions for ECalEvioReader.java");
+        // ID helper.
+//        helper = detector.getSubdetector("Ecal").getDetectorElement().getIdentifierHelper();
     }
 
     @Override
@@ -91,7 +131,7 @@
                 }
             }
         }
-        String readoutName = EcalConditions.getSubdetector().getReadout().getName();
+//        String readoutName = ;
         lcsimEvent.put(hitCollectionName, hits, hitClass, flags, readoutName);
 //        for (Object hit : hits) {
 //            System.out.println(((RawTrackerHit) hit).getIDDecoder().getIDDescription().toString());
@@ -126,22 +166,44 @@
                 if (debug) {
                     System.out.println("  channel=" + channel + "; nSamples=" + nSamples);
                 }
-                Long id = EcalConditions.daqToPhysicalID(crate, slot, channel);
 
+                
+                 long id = daqToGeometryId(crate, slot, channel);
+//                Long id = EcalConditions.daqToPhysicalID(crate, slot, channel);
+
+                 System.out.println("The long id is: " + id);
+                 
                 short[] adcValues = new short[nSamples];
                 for (int i = 0; i < nSamples; i++) {
                     adcValues[i] = cdata.getShort();
                 }
-                if (id == null) {
-                    System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel);
-                } else {
-                    hits.add(new BaseRawTrackerHit(0, id, adcValues, new ArrayList<SimTrackerHit>(), EcalConditions.getSubdetector().getDetectorElement().findDetectorElement(new Identifier(id)).get(0)));
-                }
+//                if (id == null) {
+//                    System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel);
+//                } else {
+                    hits.add(new BaseRawTrackerHit(
+                    		0, 
+                    		id, 
+                    		adcValues, 
+                    		new ArrayList<SimTrackerHit>(), 
+                    		subDetector
+                    		    .getDetectorElement().findDetectorElement(new Identifier(id)).get(0)));
+//                }
             }
         }
         return hits;
     }
 
+	private long daqToGeometryId(int crate, short slot, short channel) {
+		DaqId daqId = new DaqId(new int[]{crate,slot,channel});
+		 EcalChannel ecalChannel = channels.findChannel(daqId);
+		 if(ecalChannel == null) throw new RuntimeException("Daq Id not found.");
+		 int ix = ecalChannel.getX();
+		 int iy = ecalChannel.getY();
+		 GeometryId geometryId = new GeometryId(helper, new int[]{subDetector.getSystemID(),ix,iy});
+		 long id = geometryId.encode();
+		return id;
+	}
+
     private List<BaseRawTrackerHit> makePulseHits(CompositeData cdata, int crate) {
         List<BaseRawTrackerHit> hits = new ArrayList<BaseRawTrackerHit>();
         if (debug) {
@@ -168,7 +230,7 @@
                 if (debug) {
                     System.out.println("  channel=" + channel + "; npulses=" + npulses);
                 }
-                Long id = EcalConditions.daqToPhysicalID(crate, slot, channel);
+                Long id = daqToGeometryId(crate, slot, channel);
                 for (int k = 0; k < npulses; k++) {
                     short pulseNum = cdata.getByte();
                     int sampleCount = cdata.getNValue();
@@ -179,7 +241,7 @@
                     if (id == null) {
                         System.out.printf("Crate %d, slot %d, channel %d not found in map\n", crate, slot, channel);
                     } else {
-                        hits.add(new BaseRawTrackerHit(pulseNum, id, adcValues, new ArrayList<SimTrackerHit>(), EcalConditions.getSubdetector().getDetectorElement().findDetectorElement(new Identifier(id)).get(0)));
+                        hits.add(new BaseRawTrackerHit(pulseNum, id, adcValues, new ArrayList<SimTrackerHit>(), subDetector.getDetectorElement().findDetectorElement(new Identifier(id)).get(0)));
                     }
                 }
             }
@@ -213,7 +275,7 @@
                 if (debug) {
                     System.out.println("  channel=" + channel + "; npulses=" + npulses);
                 }
-                Long id = EcalConditions.daqToPhysicalID(crate, slot, channel);
+                Long id = daqToGeometryId(crate, slot, channel);
 
                 for (int k = 0; k < npulses; k++) {
                     short pulseTime = cdata.getShort();

java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio
ECalHitWriter.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/ECalHitWriter.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/ECalHitWriter.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -5,17 +5,30 @@
 import java.util.List;
 import java.util.Map;
 
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.DatabaseConditionsManager;
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalChannelConstants;
+import org.hps.conditions.ecal.EcalConditions;
+import org.hps.conditions.ecal.EcalConditionsUtil;
+import org.hps.conditions.ecal.EcalChannel.EcalChannelCollection;
+import org.hps.conditions.ecal.EcalChannel.GeometryId;
+//import org.hps.conditions.deprecated.EcalConditions;
 import org.jlab.coda.jevio.BaseStructure;
 import org.jlab.coda.jevio.CompositeData;
 import org.jlab.coda.jevio.DataType;
 import org.jlab.coda.jevio.EventBuilder;
 import org.jlab.coda.jevio.EvioBank;
 import org.jlab.coda.jevio.EvioException;
+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.RawCalorimeterHit;
 import org.lcsim.event.RawTrackerHit;
+import org.lcsim.geometry.Detector;
 import org.lcsim.geometry.IDDecoder;
+import org.lcsim.geometry.Subdetector;
 import org.lcsim.lcio.LCIOConstants;
 
 import static org.hps.evio.EventConstants.*;
@@ -30,8 +43,38 @@
     private String hitCollectionName = "EcalReadoutHits";
     private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
 
-    public ECalHitWriter() {
+    // FIXME: Hard-coded detector names.
+    private static String subdetectorName = "Ecal";
+    Detector detector = null;
+    public Subdetector subDetector;
+    
+    static EcalConditions ecalConditions = null;
+    static IIdentifierHelper helper = null;
+    static EcalChannelCollection channels = null;     
+    
+    public ECalHitWriter() { 	
     }
+    
+    /** 
+     * Must be set when an object EcalHitWriter is created.
+     * @param detector (long)
+     */   
+    void setDetector(Detector detector) {
+    	
+        this.detector = detector;
+        subDetector = detector.getSubdetector(subdetectorName);
+        
+        // ECAL combined conditions object.
+        ecalConditions = ConditionsManager.defaultInstance()
+                .getCachedConditions(EcalConditions.class, TableConstants.ECAL_CONDITIONS).getCachedData();
+        
+        // List of channels.
+        channels = ecalConditions.getChannelCollection();
+        
+        helper = subDetector.getDetectorElement().getIdentifierHelper();
+        
+        System.out.println("You are now using the database conditions for ECalHitWriter.java");   
+    }
 
     public void setHitCollectionName(String hitCollectionName) {
         this.hitCollectionName = hitCollectionName;
@@ -86,8 +129,8 @@
         List<Object> topHits = new ArrayList<Object>();
         List<Object> bottomHits = new ArrayList<Object>();
         for (Object hit : rawCalorimeterHits) {
-            Long daqID = EcalConditions.physicalToDaqID(getCellID(hit));
-            int crate = EcalConditions.getCrate(daqID);
+//            Long daqID = EcalConditions.physicalToDaqID(getCellID(hit));
+            int crate = getCrate(getCellID(hit));
             if (crate == ECAL_BOTTOM_BANK_TAG) {
                 bottomHits.add(hit);
             } else {
@@ -150,6 +193,7 @@
 
     private long getCellID(Object hit) {
         if (RawCalorimeterHit.class.isInstance(hit)) {
+        	System.out.println("hit.getCellID() " + ((RawCalorimeterHit) hit).getCellID());
             return ((RawCalorimeterHit) hit).getCellID();
         } else if (RawTrackerHit.class.isInstance(hit)) {
             return ((RawTrackerHit) hit).getCellID();
@@ -163,7 +207,7 @@
         }
 
         // Get the ID decoder.
-        IDDecoder dec = EcalConditions.getSubdetector().getIDDecoder();
+        IDDecoder dec = subDetector.getIDDecoder();
 
         // Make a hit map; allow for multiple hits in a crystal.
         Map<Long, List<RawCalorimeterHit>> hitMap = new HashMap<Long, List<RawCalorimeterHit>>();
@@ -182,9 +226,9 @@
             dec.setID(id);
 //			System.out.println(dec.getIDDescription());
 //			System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
-            Long daqID = EcalConditions.physicalToDaqID(id);
+//            Long daqID = EcalConditions.physicalToDaqID(id);
 //			System.out.printf("physicalID %d, daqID %d\n", id, daqID);
-            int slot = EcalConditions.getSlot(daqID);
+            int slot = getSlot(id);
             if (slotMap.get(slot) == null) {
                 slotMap.put(slot, new ArrayList<Long>());
             }
@@ -205,7 +249,7 @@
             data.addN(nhits); // number of channels
             for (Long id : hitIDs) {
                 dec.setID(id);
-                int channel = EcalConditions.getChannel(EcalConditions.physicalToDaqID(id));
+                int channel = getChannel(id);
                 data.addUchar((byte) channel); // channel #
                 List<RawCalorimeterHit> channelHits = hitMap.get(id);
                 data.addN(channelHits.size()); // number of pulses
@@ -236,7 +280,7 @@
         }
 
         // Get the ID decoder.
-        IDDecoder dec = EcalConditions.getSubdetector().getIDDecoder();
+        IDDecoder dec = subDetector.getIDDecoder();
 
         // Make a hit map; allow for multiple hits in a crystal.
         Map<Long, List<RawTrackerHit>> hitMap = new HashMap<Long, List<RawTrackerHit>>();
@@ -255,9 +299,9 @@
             dec.setID(id);
 //			System.out.println(dec.getIDDescription());
 //			System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
-            Long daqID = EcalConditions.physicalToDaqID(id);
+//            Long daqID = EcalConditions.physicalToDaqID(id);
 //			System.out.printf("physicalID %d, daqID %d\n", id, daqID);
-            int slot = EcalConditions.getSlot(daqID);
+            int slot = getSlot(id);
             if (slotMap.get(slot) == null) {
                 slotMap.put(slot, new ArrayList<Long>());
             }
@@ -278,7 +322,7 @@
             data.addN(nhits); // number of channels
             for (Long id : hitIDs) {
                 dec.setID(id);
-                int channel = EcalConditions.getChannel(EcalConditions.physicalToDaqID(id));
+                int channel = getChannel(id);
                 data.addUchar((byte) channel); // channel #
                 List<RawTrackerHit> channelHits = hitMap.get(id);
                 data.addN(channelHits.size()); // number of pulses
@@ -313,7 +357,7 @@
         }
 
         // Get the ID decoder.
-        IDDecoder dec = EcalConditions.getSubdetector().getIDDecoder();
+        IDDecoder dec = subDetector.getIDDecoder();
 
         // Make a hit map; allow for multiple hits in a crystal.
         Map<Long, RawTrackerHit> hitMap = new HashMap<Long, RawTrackerHit>();
@@ -328,9 +372,9 @@
             dec.setID(id);
 //			System.out.println(dec.getIDDescription());
 //			System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
-            Long daqID = EcalConditions.physicalToDaqID(id);
+//            Long daqID = EcalConditions.physicalToDaqID(id);
 //			System.out.printf("physicalID %d, daqID %d\n", id, daqID);
-            int slot = EcalConditions.getSlot(daqID);
+            int slot = getSlot(id);
             if (slotMap.get(slot) == null) {
                 slotMap.put(slot, new ArrayList<Long>());
             }
@@ -355,7 +399,7 @@
             data.addN(nhits); // number of channels
             for (Long id : hitIDs) {
                 dec.setID(id);
-                int channel = EcalConditions.getChannel(EcalConditions.physicalToDaqID(id));
+                int channel = getChannel(id);
                 data.addUchar((byte) channel); // channel #
                 RawTrackerHit hit = hitMap.get(id);
                 data.addN(hit.getADCValues().length); // number of samples
@@ -382,7 +426,7 @@
 
     @Override
     public void writeData(EventHeader event, EventHeader toEvent) {
-        String readoutName = EcalConditions.getSubdetector().getReadout().getName();
+        String readoutName = ((org.lcsim.geometry.compact.Subdetector) subDetector).getReadout().getName();   
         switch (mode) {
             case EventConstants.ECAL_WINDOW_MODE:
             case EventConstants.ECAL_PULSE_MODE:
@@ -401,4 +445,49 @@
                 break;
         }
     }
+    
+ 
+    
+    /**
+     * Return crate number from cellID
+     * @param cellID (long)
+     * @return Crate number (int)
+     */
+    private int getCrate(long cellID) {
+        
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getCrate(helper, cellID);
+    }
+    
+    /**
+     * Return slot number from cellID
+     * @param cellID (long)
+     * @return Slot number (int)
+     */
+    private int getSlot(long cellID) {
+        EcalConditionsUtil util = new EcalConditionsUtil();
+
+        // Find the ECAL channel and return the crate number.
+        return util.getSlot(helper, cellID);         
+    }  
+    
+    private int getChannel(long cellID){
+      // Make an ID object from hit ID.
+      IIdentifier idd = new Identifier(cellID);
+    
+      // Get physical field values.
+      int system = helper.getValue(idd, "system");
+      int x = helper.getValue(idd, "ix");
+      int y = helper.getValue(idd, "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 channels.findChannel(geometryId).getChannelId(); 
+    
+    }
+    
 }

java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio
TestRunReconToEvio.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunReconToEvio.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunReconToEvio.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -2,12 +2,16 @@
 
 import java.io.IOException;
 
+import org.hps.conditions.TableConstants;
+import org.hps.conditions.ecal.EcalConditions;
 import org.jlab.coda.jevio.DataType;
 import org.jlab.coda.jevio.EventBuilder;
 import org.jlab.coda.jevio.EventWriter;
 import org.jlab.coda.jevio.EvioBank;
 import org.jlab.coda.jevio.EvioException;
+import org.lcsim.conditions.ConditionsManager;
 import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 
 /**
@@ -26,9 +30,17 @@
 	private int eventsWritten = 0;
 	ECalHitWriter ecalWriter = null;
 	SVTHitWriter svtWriter = null;
+	
+	Detector detector = null;
 
 	public TestRunReconToEvio() {
 	}
+	
+    @Override
+    public void detectorChanged(Detector detector) {    	
+    	// set the detector
+        this.detector = detector;
+    }
 
 	public void setEvioOutputFile(String evioOutputFile) {
 		this.evioOutputFile = evioOutputFile;
@@ -49,6 +61,7 @@
 		}
 
 		ecalWriter = new ECalHitWriter();
+		ecalWriter.setDetector(detector);
 		ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
 
 		svtWriter = new SVTHitWriter();

java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio
TestRunTriggeredReconToEvio.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunTriggeredReconToEvio.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunTriggeredReconToEvio.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -5,8 +5,9 @@
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
+import org.hps.conditions.DatabaseConditionsManager;
 import org.hps.conditions.deprecated.CalibrationDriver;
-import org.hps.conditions.deprecated.EcalConditions;
+import org.hps.conditions.ecal.EcalConditions;
 import org.hps.readout.ecal.ReadoutTimestamp;
 import org.hps.readout.ecal.TriggerDriver;
 import org.hps.readout.ecal.TriggerableDriver;
@@ -16,6 +17,7 @@
 import org.jlab.coda.jevio.EvioBank;
 import org.jlab.coda.jevio.EvioException;
 import org.lcsim.event.EventHeader;
+import org.lcsim.geometry.Detector;
 import org.lcsim.util.Driver;
 
 /**
@@ -39,10 +41,19 @@
     TriggerDataWriter triggerWriter = null;
     List<HitWriter> writers = null;
     private int ecalMode = EventConstants.ECAL_PULSE_INTEGRAL_MODE;
+    
+    Detector detector;
 
     public TestRunTriggeredReconToEvio() {
         setTriggerDelay(0);
     }
+    
+    @Override
+    public void detectorChanged(Detector detector) {    	
+    	//ecalWriter.setDetector(detector);
+        if(detector == null) System.out.println("detectorChanged, Detector == null");
+        else System.out.println("detectorChanged, Detector != null");
+    }
 
     public void setEcalMode(int ecalMode) {
         this.ecalMode = ecalMode;
@@ -75,12 +86,17 @@
         }
 
         writePrestartEvent();
+        this.detector = DatabaseConditionsManager.getInstance().getDetectorObject();
 
         writers = new ArrayList<HitWriter>();
 
         ecalWriter = new ECalHitWriter();
+        if(detector == null) System.out.println("Detector == null");
+        else System.out.println("Detector != null");
+        //ecalWriter.setDetector(detector);
         ecalWriter.setMode(ecalMode);
         ecalWriter.setHitCollectionName(rawCalorimeterHitCollectionName);
+        ecalWriter.setDetector(detector);
         writers.add(ecalWriter);
 
         svtWriter = new SVTHitWriter();

java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio
TestRunTriggeredReconToLcio.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunTriggeredReconToLcio.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/evio/src/main/java/org/hps/evio/TestRunTriggeredReconToLcio.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -1,18 +1,19 @@
 package org.hps.evio;
 
 import hep.physics.event.generator.MCEvent;
+
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Queue;
+
 import org.hps.conditions.deprecated.CalibrationDriver;
 import org.hps.conditions.deprecated.QuietBaseLCSimEvent;
 import org.hps.readout.ecal.ClockSingleton;
 import org.hps.readout.ecal.ReadoutTimestamp;
 import org.hps.readout.ecal.TriggerDriver;
-import org.hps.readout.ecal.TriggerableDriver;
 import org.lcsim.event.EventHeader;
 import org.lcsim.event.LCRelation;
 import org.lcsim.event.MCParticle;
@@ -27,10 +28,8 @@
  * the test run.
  *
  * @author Jeremy McCormick <[log in to unmask]>
- * @version $Id: TestRunTriggeredReconToLcio.java 779 2014-07-16 16:24:34Z
- * omoreno $
  */
-public class TestRunTriggeredReconToLcio extends TriggerableDriver {
+public class TestRunTriggeredReconToLcio extends Driver {
 
     String rawCalorimeterHitCollectionName = "EcalReadoutHits";
     String outputFile = "TestRunData.slcio";
@@ -50,19 +49,15 @@
     List<MCParticle> mcParticles = null;
     List<SimTrackerHit> trackerHits = null;
     List<SimCalorimeterHit> ecalHits = null;
-    List<SimTrackerHit> ecalScoringPlaneHits = null;
     //MC collections from the last 500n'th event (trident or preselected trigger event)
     List<MCParticle> triggerMCParticles = null;
     List<SimTrackerHit> triggerTrackerHits = null;
     List<SimCalorimeterHit> triggerECalHits = null;
-    List<SimTrackerHit> triggerECalScoringPlaneHits = null;
     static final String ecalCollectionName = "EcalHits";
     static final String trackerCollectionName = "TrackerHits";
     private String relationCollectionName = "SVTTrueHitRelations";
-    String ecalScoringPlaneHitsCollectionName = "TrackerHitsECal";
 
     public TestRunTriggeredReconToLcio() {
-        setTriggerDelay(0);
     }
 
     public void setEcalMode(int ecalMode) {
@@ -96,7 +91,6 @@
 
     @Override
     protected void startOfData() {
-        super.startOfData();
         writers = new ArrayList<HitWriter>();
 
         ecalWriter = new ECalHitWriter();
@@ -134,28 +128,39 @@
             mcParticles = event.getMCParticles();
             ecalHits = event.getSimCalorimeterHits(ecalCollectionName);
             trackerHits = event.getSimTrackerHits(trackerCollectionName);
-            if (event.hasCollection(SimTrackerHit.class, ecalScoringPlaneHitsCollectionName)) {
-                ecalScoringPlaneHits = event.get(SimTrackerHit.class, ecalScoringPlaneHitsCollectionName);
-            }
         }
         if (ClockSingleton.getClock() % triggerSpacing == 0) {
             if (event.hasCollection(MCParticle.class)) {
                 triggerMCParticles = event.getMCParticles();
                 triggerECalHits = event.getSimCalorimeterHits(ecalCollectionName);
                 triggerTrackerHits = event.getSimTrackerHits(trackerCollectionName);
-                if (event.hasCollection(SimTrackerHit.class, ecalScoringPlaneHitsCollectionName)) {
-                    triggerECalScoringPlaneHits = event.get(SimTrackerHit.class, ecalScoringPlaneHitsCollectionName);
-                }
             } else {
                 triggerMCParticles = null;
                 triggerECalHits = null;
                 triggerTrackerHits = null;
-                triggerECalScoringPlaneHits = null;
             }
         }
 
-        checkTrigger(event);
 
+        if (TriggerDriver.triggerBit()) {
+            EventHeader lcsimEvent = new QuietBaseLCSimEvent(CalibrationDriver.runNumber(), event.getEventNumber(), event.getDetectorName());
+            events.add(lcsimEvent);
+            System.out.println("Creating LCIO event " + eventNum);
+            if (triggerMCParticles == null || triggerMCParticles.isEmpty()) {
+                lcsimEvent.put(MCEvent.MC_PARTICLES, mcParticles);
+                lcsimEvent.put(ecalCollectionName, ecalHits, SimCalorimeterHit.class, 0xe0000000);
+                lcsimEvent.put(trackerCollectionName, trackerHits, SimTrackerHit.class, 0xc0000000);
+                System.out.println("Adding " + mcParticles.size() + " MCParticles, " + ecalHits.size() + " SimCalorimeterHits, " + trackerHits.size() + " SimTrackerHits");
+            } else {
+                lcsimEvent.put(MCEvent.MC_PARTICLES, triggerMCParticles);
+                lcsimEvent.put(ecalCollectionName, triggerECalHits, SimCalorimeterHit.class, 0xe0000000);
+                lcsimEvent.put(trackerCollectionName, triggerTrackerHits, SimTrackerHit.class, 0xc0000000);
+                System.out.println("Adding " + triggerMCParticles.size() + " MCParticles, " + triggerECalHits.size() + " SimCalorimeterHits, " + triggerTrackerHits.size() + " SimTrackerHits");
+            }
+            lcsimEvent.put(ReadoutTimestamp.collectionName, event.get(ReadoutTimestamp.class, ReadoutTimestamp.collectionName));
+            ++eventNum;
+        }
+
         writerLoop:
         for (HitWriter hitWriter : writers) {
             if (hitWriter.hasData(event)) {
@@ -210,37 +215,4 @@
             }
         }
     }
-
-    @Override
-    protected void processTrigger(EventHeader event) {
-        EventHeader lcsimEvent = new QuietBaseLCSimEvent(CalibrationDriver.runNumber(), event.getEventNumber(), event.getDetectorName());
-        events.add(lcsimEvent);
-        System.out.println("Creating LCIO event " + eventNum);
-        if (triggerMCParticles == null || triggerMCParticles.isEmpty()) {
-            lcsimEvent.put(MCEvent.MC_PARTICLES, mcParticles);
-            lcsimEvent.put(ecalCollectionName, ecalHits, SimCalorimeterHit.class, 0xe0000000);
-            lcsimEvent.put(trackerCollectionName, trackerHits, SimTrackerHit.class, 0xc0000000);
-            System.out.println("Adding " + mcParticles.size() + " MCParticles, " + ecalHits.size() + " SimCalorimeterHits, " + trackerHits.size() + " SimTrackerHits");
-            if (ecalScoringPlaneHits != null) {
-                lcsimEvent.put(ecalScoringPlaneHitsCollectionName, ecalScoringPlaneHits, SimTrackerHit.class, 0);
-                System.out.println("Adding " + ecalScoringPlaneHits.size() + " ECalTrackerHits");
-            }
-        } else {
-            lcsimEvent.put(MCEvent.MC_PARTICLES, triggerMCParticles);
-            lcsimEvent.put(ecalCollectionName, triggerECalHits, SimCalorimeterHit.class, 0xe0000000);
-            lcsimEvent.put(trackerCollectionName, triggerTrackerHits, SimTrackerHit.class, 0xc0000000);
-            System.out.println("Adding " + triggerMCParticles.size() + " MCParticles, " + triggerECalHits.size() + " SimCalorimeterHits, " + triggerTrackerHits.size() + " SimTrackerHits");
-            if (triggerECalScoringPlaneHits != null) {
-                lcsimEvent.put(ecalScoringPlaneHitsCollectionName, triggerECalScoringPlaneHits, SimTrackerHit.class, 0);
-                System.out.println("Adding " + triggerECalScoringPlaneHits.size() + " ECalTrackerHits");
-            }
-        }
-        lcsimEvent.put(ReadoutTimestamp.collectionName, event.get(ReadoutTimestamp.class, ReadoutTimestamp.collectionName));
-        ++eventNum;
-    }
-
-    @Override
-    public int getTimestampType() {
-        return ReadoutTimestamp.SYSTEM_TRIGGERTIME;
-    }
-}
+}
\ No newline at end of file

java/branches/hps_java_trunk_HPSJAVA-251/users/src/main/java/org/hps/users/holly
EcalClustererCosmics.java 994 -> 995
--- java/branches/hps_java_trunk_HPSJAVA-251/users/src/main/java/org/hps/users/holly/EcalClustererCosmics.java	2014-09-11 18:12:48 UTC (rev 994)
+++ java/branches/hps_java_trunk_HPSJAVA-251/users/src/main/java/org/hps/users/holly/EcalClustererCosmics.java	2014-09-11 18:52:34 UTC (rev 995)
@@ -179,4 +179,4 @@
         }
         return clusters;
     }
-}
\ No newline at end of file
+}
SVNspam 0.1