Commit in hps-java on MAIN | |||
scripts/.cvsignore | +1 | added 1.1 | |
/make_ecal.sh | +5 | -3 | 1.1 -> 1.2 |
src/main/java/org/lcsim/hps/evio/ECalEvioWriter.java | +368 | -371 | 1.3 -> 1.4 |
/ECalEvioReader.java | +36 | -37 | 1.7 -> 1.8 |
/TestRunTriggeredReconToEvio.java | +2 | -2 | 1.8 -> 1.9 |
src/main/java/org/lcsim/hps/monitoring/ecal/EcalDaqPlots.java | +10 | -12 | 1.2 -> 1.3 |
/EcalPedestalPlots.java | -4 | 1.1 -> 1.2 | |
/EcalWindowPlotsXY.java | -4 | 1.1 -> 1.2 | |
/EcalWindowPlots.java | +6 | -8 | 1.1 -> 1.2 |
src/main/java/org/lcsim/hps/recon/ecal/HPSEcalConditions.java | +162 | added 1.1 | |
/HPSEcalDaqIDConverter.java | -103 | 1.3 removed | |
+590 | -544 |
add ECal pedestal cals
diff -N .cvsignore --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ .cvsignore 2 May 2012 00:39:40 -0000 1.1 @@ -0,0 +1 @@
+.meeg.swp
diff -u -r1.1 -r1.2 --- make_ecal.sh 5 Apr 2012 19:05:23 -0000 1.1 +++ make_ecal.sh 2 May 2012 00:39:40 -0000 1.2 @@ -1,14 +1,16 @@
#!/bin/bash #prints the ECal physicalID-daqID conversion table, as found in daqmap/ecal.txt in hps-detectors.
-echo "# x y crate slot channel"
+echo "#x y crate slot channel" +topslots=( 10 13 9 14 8 15 7 16 6 17 5 18 4 -1 ) +botslots=( 10 13 9 14 8 15 7 16 6 17 5 18 -1 -2 )
x=-23 y=1 slot=0 channel=0 while true do
- echo "$x $y 1 $slot $channel" - echo "$x -$y 2 $slot $channel"
+ echo "$x $y 1 ${topslots[slot]} $channel" + echo "$x -$y 2 ${botslots[slot]} $channel"
channel=$((channel+1)) if [ "$channel" -eq 16 ] then
diff -u -r1.3 -r1.4 --- ECalEvioWriter.java 10 Apr 2012 01:00:13 -0000 1.3 +++ ECalEvioWriter.java 2 May 2012 00:39:40 -0000 1.4 @@ -18,7 +18,7 @@
import org.lcsim.event.EventHeader.LCMetaData; import org.lcsim.event.RawCalorimeterHit; import org.lcsim.geometry.IDDecoder;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import static org.lcsim.hps.evio.EventConstants.ECAL_BANK_NUMBER; import static org.lcsim.hps.evio.EventConstants.ECAL_BOTTOM_BANK_TAG;
@@ -29,386 +29,383 @@
/** * * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioWriter.java,v 1.3 2012/04/10 01:00:13 meeg Exp $
+ * @version $Id: ECalEvioWriter.java,v 1.4 2012/05/02 00:39:40 meeg Exp $
*/ public class ECalEvioWriter implements EvioWriter {
- private String hitCollectionName = "EcalReadoutHits"; - private String ecalName = "Ecal"; - private HPSEcalDaqIDConverter ecalIDConverter = null; - private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE; - - public ECalEvioWriter() { - } - - public void setEcalName(String ecalName) { - this.ecalName = ecalName; - ecalIDConverter = null; - } - - public void setHitCollectionName(String hitCollectionName) { - this.hitCollectionName = hitCollectionName; - } - - public void setMode(int mode) { - this.mode = mode; - if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) { - throw new IllegalArgumentException("invalid mode " + mode); - } - } - - public boolean hasData(EventHeader event) { - switch (mode) { - case EventConstants.ECAL_WINDOW_MODE: - return event.hasCollection(RawTrackerHit.class, hitCollectionName); - case EventConstants.ECAL_PULSE_MODE: - return event.hasCollection(RawTrackerHit.class, hitCollectionName); - case EventConstants.ECAL_PULSE_INTEGRAL_MODE: - return event.hasCollection(RawCalorimeterHit.class, hitCollectionName); - default: - return false; - } - } - - public void writeData(EventHeader event, EventBuilder builder) { - if (ecalIDConverter == null) { - ecalIDConverter = new HPSEcalDaqIDConverter(); - ecalIDConverter.fillDaqCellMap(event.getDetector().getSubdetector(ecalName)); - } - LCMetaData meta; - List<RawCalorimeterHit> rawCalorimeterHits; - List<RawTrackerHit> rawTrackerHits; - switch (mode) { - case EventConstants.ECAL_WINDOW_MODE: - rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName); - meta = event.getMetaData(rawTrackerHits); - writeWindowHits(meta, rawTrackerHits, builder); - break; - case EventConstants.ECAL_PULSE_MODE: - rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName); - meta = event.getMetaData(rawTrackerHits); - writePulseHits(meta, rawTrackerHits, builder); - break; - case EventConstants.ECAL_PULSE_INTEGRAL_MODE: - rawCalorimeterHits = event.get(RawCalorimeterHit.class, hitCollectionName); - meta = event.getMetaData(rawCalorimeterHits); - writeIntegralHits(meta, rawCalorimeterHits, builder); - break; - default: - break; - } - } - - private void writeIntegralHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) { - System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in integral format"); - - // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. - List<RawCalorimeterHit> topHits = new ArrayList<RawCalorimeterHit>(); - List<RawCalorimeterHit> bottomHits = new ArrayList<RawCalorimeterHit>(); - for (RawCalorimeterHit hit : rawCalorimeterHits) { - Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqID); - if (crate == ECAL_BOTTOM_BANK_TAG) { - bottomHits.add(hit); - } else { - topHits.add(hit); - } - } - - // Write the two collections for top and bottom hits to separate EVIO banks. - writeIntegralHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); - writeIntegralHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); - } - - private void writeIntegralHitCollection(List<RawCalorimeterHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { - // Get the ID decoder. - IDDecoder dec = meta.getIDDecoder(); - - // Make a hit map; allow for multiple hits in a crystal. - Map<Long, List<RawCalorimeterHit>> hitMap = new HashMap<Long, List<RawCalorimeterHit>>(); - for (RawCalorimeterHit hit : hits) { - if (hitMap.get(hit.getCellID()) == null) { - hitMap.put(hit.getCellID(), new ArrayList<RawCalorimeterHit>()); - } - List<RawCalorimeterHit> channelHits = hitMap.get(hit.getCellID()); - channelHits.add(hit); - } - - // Make map of slot number to hit IDs. - Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); - for (Long id : hitMap.keySet()) { - dec.setID(id);
+ private String hitCollectionName = "EcalReadoutHits"; + private String ecalName = "Ecal"; + private int mode = EventConstants.ECAL_PULSE_INTEGRAL_MODE; + + public ECalEvioWriter() { + } + + public void setEcalName(String ecalName) { + this.ecalName = ecalName; + } + + public void setHitCollectionName(String hitCollectionName) { + this.hitCollectionName = hitCollectionName; + } + + public void setMode(int mode) { + this.mode = mode; + if (mode != EventConstants.ECAL_WINDOW_MODE && mode != EventConstants.ECAL_PULSE_MODE && mode != EventConstants.ECAL_PULSE_INTEGRAL_MODE) { + throw new IllegalArgumentException("invalid mode " + mode); + } + } + + public boolean hasData(EventHeader event) { + switch (mode) { + case EventConstants.ECAL_WINDOW_MODE: + return event.hasCollection(RawTrackerHit.class, hitCollectionName); + case EventConstants.ECAL_PULSE_MODE: + return event.hasCollection(RawTrackerHit.class, hitCollectionName); + case EventConstants.ECAL_PULSE_INTEGRAL_MODE: + return event.hasCollection(RawCalorimeterHit.class, hitCollectionName); + default: + return false; + } + } + + public void writeData(EventHeader event, EventBuilder builder) { + if (!HPSEcalConditions.mapLoaded()) { + HPSEcalConditions.fillDaqCellMap(event.getDetector().getSubdetector(ecalName)); + } + LCMetaData meta; + List<RawCalorimeterHit> rawCalorimeterHits; + List<RawTrackerHit> rawTrackerHits; + switch (mode) { + case EventConstants.ECAL_WINDOW_MODE: + rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName); + meta = event.getMetaData(rawTrackerHits); + writeWindowHits(meta, rawTrackerHits, builder); + break; + case EventConstants.ECAL_PULSE_MODE: + rawTrackerHits = event.get(RawTrackerHit.class, hitCollectionName); + meta = event.getMetaData(rawTrackerHits); + writePulseHits(meta, rawTrackerHits, builder); + break; + case EventConstants.ECAL_PULSE_INTEGRAL_MODE: + rawCalorimeterHits = event.get(RawCalorimeterHit.class, hitCollectionName); + meta = event.getMetaData(rawCalorimeterHits); + writeIntegralHits(meta, rawCalorimeterHits, builder); + break; + default: + break; + } + } + + private void writeIntegralHits(LCMetaData meta, List<RawCalorimeterHit> rawCalorimeterHits, EventBuilder builder) { + System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in integral format"); + + // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. + List<RawCalorimeterHit> topHits = new ArrayList<RawCalorimeterHit>(); + List<RawCalorimeterHit> bottomHits = new ArrayList<RawCalorimeterHit>(); + for (RawCalorimeterHit hit : rawCalorimeterHits) { + Long daqID = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqID); + if (crate == ECAL_BOTTOM_BANK_TAG) { + bottomHits.add(hit); + } else { + topHits.add(hit); + } + } + + // Write the two collections for top and bottom hits to separate EVIO banks. + writeIntegralHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); + writeIntegralHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); + } + + private void writeIntegralHitCollection(List<RawCalorimeterHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { + // Get the ID decoder. + IDDecoder dec = meta.getIDDecoder(); + + // Make a hit map; allow for multiple hits in a crystal. + Map<Long, List<RawCalorimeterHit>> hitMap = new HashMap<Long, List<RawCalorimeterHit>>(); + for (RawCalorimeterHit hit : hits) { + if (hitMap.get(hit.getCellID()) == null) { + hitMap.put(hit.getCellID(), new ArrayList<RawCalorimeterHit>()); + } + List<RawCalorimeterHit> channelHits = hitMap.get(hit.getCellID()); + channelHits.add(hit); + } + + // Make map of slot number to hit IDs. + Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); + for (Long id : hitMap.keySet()) { + dec.setID(id);
// System.out.println(dec.getIDDescription()); // System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
- Long daqID = ecalIDConverter.physicalToDaqID(id);
+ Long daqID = HPSEcalConditions.physicalToDaqID(id);
// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
- int slot = HPSEcalDaqIDConverter.getSlot(daqID); - if (slotMap.get(slot) == null) { - slotMap.put(slot, new ArrayList<Long>()); - } - List<Long> slots = slotMap.get(slot); - slots.add(id); - } - - // Make a new bank for this crate. - EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); - - // Loop over the slots in the map. - for (int slot : slotMap.keySet()) { - - // New bank for this slot. - EvioBank slotBank = new EvioBank(ECAL_PULSE_INTEGRAL_BANK_TAG, DataType.COMPOSITE, slot); - - // Create composite data for this slot and its channels. - CompositeData.Data data = new CompositeData.Data(); - data.addUchar((byte) slot); // slot # - data.addUint(0); // trigger # - data.addUlong(0); // timestamp - List<Long> hitIDs = slotMap.get(slot); - int nhits = hitIDs.size(); - data.addN(nhits); // number of channels - for (Long id : hitIDs) { - dec.setID(id); - int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id)); - data.addUchar((byte) channel); // channel # - List<RawCalorimeterHit> channelHits = hitMap.get(id); - data.addN(channelHits.size()); // number of pulses - for (RawCalorimeterHit hit : channelHits) { - data.addUshort((short) hit.getTimeStamp()); // pulse time - data.addUint((int) hit.getAmplitude()); // pulse integral - } - } - - // Add CompositeData to bank. - CompositeData cdata = null; - try { - cdata = new CompositeData(ECAL_PULSE_INTEGRAL_FORMAT, 1, data, ECAL_PULSE_INTEGRAL_BANK_TAG, slot); - slotBank.appendCompositeData(cdata); - } catch (EvioException e) { - throw new RuntimeException(e); - } - - // Add slot bank to crate bank. - slotBank.setAllHeaderLengths(); - try { - builder.addChild(crateBank, slotBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - } - try { - crateBank.setAllHeaderLengths(); - builder.addChild(builder.getEvent(), crateBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - } - - private void writePulseHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) { - System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in pulse format"); - - // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. - List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>(); - List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>(); - for (RawTrackerHit hit : rawCalorimeterHits) { - Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqID); - if (crate == ECAL_BOTTOM_BANK_TAG) { - bottomHits.add(hit); - } else { - topHits.add(hit); - } - } - - // Write the two collections for top and bottom hits to separate EVIO banks. - writePulseHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); - writePulseHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); - } - - private void writePulseHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { - // Get the ID decoder. - IDDecoder dec = meta.getIDDecoder(); - - // Make a hit map; allow for multiple hits in a crystal. - Map<Long, List<RawTrackerHit>> hitMap = new HashMap<Long, List<RawTrackerHit>>(); - for (RawTrackerHit hit : hits) { - if (hitMap.get(hit.getCellID()) == null) { - hitMap.put(hit.getCellID(), new ArrayList<RawTrackerHit>()); - } - List<RawTrackerHit> channelHits = hitMap.get(hit.getCellID()); - channelHits.add(hit); - } - - // Make map of slot number to hit IDs. - Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); - for (Long id : hitMap.keySet()) { - dec.setID(id);
+ int slot = HPSEcalConditions.getSlot(daqID); + if (slotMap.get(slot) == null) { + slotMap.put(slot, new ArrayList<Long>()); + } + List<Long> slots = slotMap.get(slot); + slots.add(id); + } + + // Make a new bank for this crate. + EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); + + // Loop over the slots in the map. + for (int slot : slotMap.keySet()) { + + // New bank for this slot. + EvioBank slotBank = new EvioBank(ECAL_PULSE_INTEGRAL_BANK_TAG, DataType.COMPOSITE, slot); + + // Create composite data for this slot and its channels. + CompositeData.Data data = new CompositeData.Data(); + data.addUchar((byte) slot); // slot # + data.addUint(0); // trigger # + data.addUlong(0); // timestamp + List<Long> hitIDs = slotMap.get(slot); + int nhits = hitIDs.size(); + data.addN(nhits); // number of channels + for (Long id : hitIDs) { + dec.setID(id); + int channel = HPSEcalConditions.getChannel(HPSEcalConditions.physicalToDaqID(id)); + data.addUchar((byte) channel); // channel # + List<RawCalorimeterHit> channelHits = hitMap.get(id); + data.addN(channelHits.size()); // number of pulses + for (RawCalorimeterHit hit : channelHits) { + data.addUshort((short) hit.getTimeStamp()); // pulse time + data.addUint((int) hit.getAmplitude()); // pulse integral + } + } + + // Add CompositeData to bank. + CompositeData cdata = null; + try { + cdata = new CompositeData(ECAL_PULSE_INTEGRAL_FORMAT, 1, data, ECAL_PULSE_INTEGRAL_BANK_TAG, slot); + slotBank.appendCompositeData(cdata); + } catch (EvioException e) { + throw new RuntimeException(e); + } + + // Add slot bank to crate bank. + slotBank.setAllHeaderLengths(); + try { + builder.addChild(crateBank, slotBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + } + try { + crateBank.setAllHeaderLengths(); + builder.addChild(builder.getEvent(), crateBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + } + + private void writePulseHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) { + System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in pulse format"); + + // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. + List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>(); + List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>(); + for (RawTrackerHit hit : rawCalorimeterHits) { + Long daqID = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqID); + if (crate == ECAL_BOTTOM_BANK_TAG) { + bottomHits.add(hit); + } else { + topHits.add(hit); + } + } + + // Write the two collections for top and bottom hits to separate EVIO banks. + writePulseHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); + writePulseHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); + } + + private void writePulseHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { + // Get the ID decoder. + IDDecoder dec = meta.getIDDecoder(); + + // Make a hit map; allow for multiple hits in a crystal. + Map<Long, List<RawTrackerHit>> hitMap = new HashMap<Long, List<RawTrackerHit>>(); + for (RawTrackerHit hit : hits) { + if (hitMap.get(hit.getCellID()) == null) { + hitMap.put(hit.getCellID(), new ArrayList<RawTrackerHit>()); + } + List<RawTrackerHit> channelHits = hitMap.get(hit.getCellID()); + channelHits.add(hit); + } + + // Make map of slot number to hit IDs. + Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); + for (Long id : hitMap.keySet()) { + dec.setID(id);
// System.out.println(dec.getIDDescription()); // System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
- Long daqID = ecalIDConverter.physicalToDaqID(id);
+ Long daqID = HPSEcalConditions.physicalToDaqID(id);
// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
- int slot = HPSEcalDaqIDConverter.getSlot(daqID); - if (slotMap.get(slot) == null) { - slotMap.put(slot, new ArrayList<Long>()); - } - List<Long> slots = slotMap.get(slot); - slots.add(id); - } - - // Make a new bank for this crate. - EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); - - // Loop over the slots in the map. - for (int slot : slotMap.keySet()) { - - // New bank for this slot. - EvioBank slotBank = new EvioBank(EventConstants.ECAL_PULSE_BANK_TAG, DataType.COMPOSITE, slot); - - // Create composite data for this slot and its channels. - CompositeData.Data data = new CompositeData.Data(); - data.addUchar((byte) slot); // slot # - data.addUint(0); // trigger # - data.addUlong(0); // timestamp - List<Long> hitIDs = slotMap.get(slot); - int nhits = hitIDs.size(); - data.addN(nhits); // number of channels - for (Long id : hitIDs) { - dec.setID(id); - int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id)); - data.addUchar((byte) channel); // channel # - List<RawTrackerHit> channelHits = hitMap.get(id); - data.addN(channelHits.size()); // number of pulses - for (RawTrackerHit hit : channelHits) { - data.addUchar((byte) channelHits.indexOf(hit)); // pulse number - data.addN(hit.getADCValues().length); // number of samples - for (short val : hit.getADCValues()) { - data.addUshort(val); // sample - } - } - } - - // Add CompositeData to bank. - CompositeData cdata = null; - try { - cdata = new CompositeData(EventConstants.ECAL_PULSE_FORMAT, 1, data, EventConstants.ECAL_PULSE_BANK_TAG, slot); - slotBank.appendCompositeData(cdata); - } catch (EvioException e) { - throw new RuntimeException(e); - } - - // Add slot bank to crate bank. - slotBank.setAllHeaderLengths(); - try { - builder.addChild(crateBank, slotBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - } - try { - crateBank.setAllHeaderLengths(); - builder.addChild(builder.getEvent(), crateBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - } - - private void writeWindowHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) { - System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in window format"); - - // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. - List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>(); - List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>(); - for (RawTrackerHit hit : rawCalorimeterHits) { - Long daqID = ecalIDConverter.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqID); - if (crate == ECAL_BOTTOM_BANK_TAG) { - bottomHits.add(hit); - } else { - topHits.add(hit); - } - } - - // Write the two collections for top and bottom hits to separate EVIO banks. - writeWindowHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); - writeWindowHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); - } - - private void writeWindowHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { - // Get the ID decoder. - IDDecoder dec = meta.getIDDecoder(); - - // Make a hit map; allow for multiple hits in a crystal. - Map<Long, RawTrackerHit> hitMap = new HashMap<Long, RawTrackerHit>(); - for (RawTrackerHit hit : hits) { - hitMap.put(hit.getCellID(), hit); - } - - // Make map of slot number to hit IDs. - Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); - for (Long id : hitMap.keySet()) { - dec.setID(id);
+ int slot = HPSEcalConditions.getSlot(daqID); + if (slotMap.get(slot) == null) { + slotMap.put(slot, new ArrayList<Long>()); + } + List<Long> slots = slotMap.get(slot); + slots.add(id); + } + + // Make a new bank for this crate. + EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); + + // Loop over the slots in the map. + for (int slot : slotMap.keySet()) { + + // New bank for this slot. + EvioBank slotBank = new EvioBank(EventConstants.ECAL_PULSE_BANK_TAG, DataType.COMPOSITE, slot); + + // Create composite data for this slot and its channels. + CompositeData.Data data = new CompositeData.Data(); + data.addUchar((byte) slot); // slot # + data.addUint(0); // trigger # + data.addUlong(0); // timestamp + List<Long> hitIDs = slotMap.get(slot); + int nhits = hitIDs.size(); + data.addN(nhits); // number of channels + for (Long id : hitIDs) { + dec.setID(id); + int channel = HPSEcalConditions.getChannel(HPSEcalConditions.physicalToDaqID(id)); + data.addUchar((byte) channel); // channel # + List<RawTrackerHit> channelHits = hitMap.get(id); + data.addN(channelHits.size()); // number of pulses + for (RawTrackerHit hit : channelHits) { + data.addUchar((byte) channelHits.indexOf(hit)); // pulse number + data.addN(hit.getADCValues().length); // number of samples + for (short val : hit.getADCValues()) { + data.addUshort(val); // sample + } + } + } + + // Add CompositeData to bank. + CompositeData cdata = null; + try { + cdata = new CompositeData(EventConstants.ECAL_PULSE_FORMAT, 1, data, EventConstants.ECAL_PULSE_BANK_TAG, slot); + slotBank.appendCompositeData(cdata); + } catch (EvioException e) { + throw new RuntimeException(e); + } + + // Add slot bank to crate bank. + slotBank.setAllHeaderLengths(); + try { + builder.addChild(crateBank, slotBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + } + try { + crateBank.setAllHeaderLengths(); + builder.addChild(builder.getEvent(), crateBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + } + + private void writeWindowHits(LCMetaData meta, List<RawTrackerHit> rawCalorimeterHits, EventBuilder builder) { + System.out.println("Writing " + rawCalorimeterHits.size() + " ECal hits in window format"); + + // Make two lists containing the hits from top and bottom sections, which go into separate EVIO data banks. + List<RawTrackerHit> topHits = new ArrayList<RawTrackerHit>(); + List<RawTrackerHit> bottomHits = new ArrayList<RawTrackerHit>(); + for (RawTrackerHit hit : rawCalorimeterHits) { + Long daqID = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqID); + if (crate == ECAL_BOTTOM_BANK_TAG) { + bottomHits.add(hit); + } else { + topHits.add(hit); + } + } + + // Write the two collections for top and bottom hits to separate EVIO banks. + writeWindowHitCollection(topHits, meta, ECAL_TOP_BANK_TAG, builder); + writeWindowHitCollection(bottomHits, meta, ECAL_BOTTOM_BANK_TAG, builder); + } + + private void writeWindowHitCollection(List<RawTrackerHit> hits, LCMetaData meta, int bankTag, EventBuilder builder) { + // Get the ID decoder. + IDDecoder dec = meta.getIDDecoder(); + + // Make a hit map; allow for multiple hits in a crystal. + Map<Long, RawTrackerHit> hitMap = new HashMap<Long, RawTrackerHit>(); + for (RawTrackerHit hit : hits) { + hitMap.put(hit.getCellID(), hit); + } + + // Make map of slot number to hit IDs. + Map<Integer, List<Long>> slotMap = new HashMap<Integer, List<Long>>(); + for (Long id : hitMap.keySet()) { + dec.setID(id);
// System.out.println(dec.getIDDescription()); // System.out.printf("ix = %d, iy = %d\n", dec.getValue("ix"), dec.getValue("iy"));
- Long daqID = ecalIDConverter.physicalToDaqID(id);
+ Long daqID = HPSEcalConditions.physicalToDaqID(id);
// System.out.printf("physicalID %d, daqID %d\n", id, daqID);
- int slot = HPSEcalDaqIDConverter.getSlot(daqID); - if (slotMap.get(slot) == null) { - slotMap.put(slot, new ArrayList<Long>()); - } - List<Long> slots = slotMap.get(slot); - slots.add(id); - } - - // Make a new bank for this crate. - EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); - - // Loop over the slots in the map. - for (int slot : slotMap.keySet()) { - - // New bank for this slot. - EvioBank slotBank = new EvioBank(EventConstants.ECAL_WINDOW_BANK_TAG, DataType.COMPOSITE, slot); - - // Create composite data for this slot and its channels. - CompositeData.Data data = new CompositeData.Data(); - data.addUchar((byte) slot); // slot # - data.addUint(0); // trigger # - data.addUlong(0); // timestamp - List<Long> hitIDs = slotMap.get(slot); - int nhits = hitIDs.size(); - data.addN(nhits); // number of channels - for (Long id : hitIDs) { - dec.setID(id); - int channel = HPSEcalDaqIDConverter.getChannel(ecalIDConverter.physicalToDaqID(id)); - data.addUchar((byte) channel); // channel # - RawTrackerHit hit = hitMap.get(id); - data.addN(hit.getADCValues().length); // number of samples - for (short val : hit.getADCValues()) { - data.addUshort(val); // sample - } - } - - // Add CompositeData to bank. - CompositeData cdata = null; - try { - cdata = new CompositeData(EventConstants.ECAL_WINDOW_FORMAT, 1, data, EventConstants.ECAL_WINDOW_BANK_TAG, slot); - slotBank.appendCompositeData(cdata); - } catch (EvioException e) { - throw new RuntimeException(e); - } - - // Add slot bank to crate bank. - slotBank.setAllHeaderLengths(); - try { - builder.addChild(crateBank, slotBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - } - try { - crateBank.setAllHeaderLengths(); - builder.addChild(builder.getEvent(), crateBank); - } catch (EvioException e) { - throw new RuntimeException(e); - } - }
+ int slot = HPSEcalConditions.getSlot(daqID); + if (slotMap.get(slot) == null) { + slotMap.put(slot, new ArrayList<Long>()); + } + List<Long> slots = slotMap.get(slot); + slots.add(id); + } + + // Make a new bank for this crate. + EvioBank crateBank = new EvioBank(bankTag, DataType.BANK, ECAL_BANK_NUMBER); + + // Loop over the slots in the map. + for (int slot : slotMap.keySet()) { + + // New bank for this slot. + EvioBank slotBank = new EvioBank(EventConstants.ECAL_WINDOW_BANK_TAG, DataType.COMPOSITE, slot); + + // Create composite data for this slot and its channels. + CompositeData.Data data = new CompositeData.Data(); + data.addUchar((byte) slot); // slot # + data.addUint(0); // trigger # + data.addUlong(0); // timestamp + List<Long> hitIDs = slotMap.get(slot); + int nhits = hitIDs.size(); + data.addN(nhits); // number of channels + for (Long id : hitIDs) { + dec.setID(id); + int channel = HPSEcalConditions.getChannel(HPSEcalConditions.physicalToDaqID(id)); + data.addUchar((byte) channel); // channel # + RawTrackerHit hit = hitMap.get(id); + data.addN(hit.getADCValues().length); // number of samples + for (short val : hit.getADCValues()) { + data.addUshort(val); // sample + } + } + + // Add CompositeData to bank. + CompositeData cdata = null; + try { + cdata = new CompositeData(EventConstants.ECAL_WINDOW_FORMAT, 1, data, EventConstants.ECAL_WINDOW_BANK_TAG, slot); + slotBank.appendCompositeData(cdata); + } catch (EvioException e) { + throw new RuntimeException(e); + } + + // Add slot bank to crate bank. + slotBank.setAllHeaderLengths(); + try { + builder.addChild(crateBank, slotBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + } + try { + crateBank.setAllHeaderLengths(); + builder.addChild(builder.getEvent(), crateBank); + } catch (EvioException e) { + throw new RuntimeException(e); + } + }
}
diff -u -r1.7 -r1.8 --- ECalEvioReader.java 29 Apr 2012 23:05:26 -0000 1.7 +++ ECalEvioReader.java 2 May 2012 00:39:40 -0000 1.8 @@ -12,18 +12,17 @@
import org.lcsim.event.RawTrackerHit; import org.lcsim.event.base.BaseRawCalorimeterHit; import org.lcsim.event.base.BaseRawTrackerHit;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
/** * * @author Sho Uemura <[log in to unmask]>
- * @version $Id: ECalEvioReader.java,v 1.7 2012/04/29 23:05:26 meeg Exp $
+ * @version $Id: ECalEvioReader.java,v 1.8 2012/05/02 00:39:40 meeg Exp $
*/ public class ECalEvioReader extends EvioReader { // Names of subdetectors. private String ecalName = "Ecal";
- private HPSEcalDaqIDConverter ecalIDConverter = null;
private int bankTag = EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG; private Class hitClass = RawCalorimeterHit.class;
@@ -33,15 +32,13 @@
public void setEcalName(String ecalName) { this.ecalName = ecalName;
- ecalIDConverter = null;
} @Override public boolean makeHits(EvioEvent event, EventHeader lcsimEvent) { boolean foundHits = false;
- if (ecalIDConverter == null) { - ecalIDConverter = new HPSEcalDaqIDConverter(); - ecalIDConverter.fillDaqCellMap(lcsimEvent.getDetector().getSubdetector(ecalName));
+ if (!HPSEcalConditions.mapLoaded()) { + HPSEcalConditions.fillDaqCellMap(lcsimEvent.getDetector().getSubdetector(ecalName));
} List<Object> hits = new ArrayList<Object>(); hitClass = Object.class;
@@ -56,31 +53,33 @@
} for (BaseStructure slotBank : bank.getChildren()) { CompositeData cdata = null;
- try { - cdata = slotBank.getCompositeData(); - } catch (EvioException e) { - throw new RuntimeException(e); - } - if (slotBank.getHeader().getTag() != bankTag) { - bankTag = slotBank.getHeader().getTag(); - System.out.printf("ECal format tag: 0x%x\n", bankTag); - } - switch (slotBank.getHeader().getTag()) { - case EventConstants.ECAL_WINDOW_BANK_TAG: - hits.addAll(makeWindowHits(cdata, crateBankTag)); - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_BANK_TAG: - hits.addAll(makePulseHits(cdata, crateBankTag)); - hitClass = RawTrackerHit.class; - break; - case EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG: - hits.addAll(makeIntegralHits(cdata, crateBankTag)); - hitClass = RawCalorimeterHit.class; - break; - default: - throw new RuntimeException("Unsupported ECal format - bank tag " + slotBank.getHeader().getTag());
+ while (true) { + try { + cdata = slotBank.getCompositeData(); + } catch (EvioException e) { + throw new RuntimeException(e); + } + if (slotBank.getHeader().getTag() != bankTag) { + bankTag = slotBank.getHeader().getTag(); + System.out.printf("ECal format tag: 0x%x\n", bankTag); + } + switch (slotBank.getHeader().getTag()) { + case EventConstants.ECAL_WINDOW_BANK_TAG: + hits.addAll(makeWindowHits(cdata, crateBankTag)); + hitClass = RawTrackerHit.class; + break; + case EventConstants.ECAL_PULSE_BANK_TAG: + hits.addAll(makePulseHits(cdata, crateBankTag)); + hitClass = RawTrackerHit.class; + break; + case EventConstants.ECAL_PULSE_INTEGRAL_BANK_TAG: + hits.addAll(makeIntegralHits(cdata, crateBankTag)); + hitClass = RawCalorimeterHit.class; + break; + default: + throw new RuntimeException("Unsupported ECal format - bank tag " + slotBank.getHeader().getTag());
+ }
} } }
@@ -118,8 +117,8 @@
if (debug) { System.out.println(" channel=" + channel + "; nSamples=" + nSamples); }
- long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID);
+ long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); + Long id = HPSEcalConditions.daqToPhysicalID(daqID);
short[] adcValues = new short[nSamples]; for (int i = 0; i < nSamples; i++) {
@@ -160,8 +159,8 @@
if (debug) { System.out.println(" channel=" + channel + "; npulses=" + npulses); }
- long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID);
+ long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); + Long id = HPSEcalConditions.daqToPhysicalID(daqID);
for (int k = 0; k < npulses; k++) { short pulseNum = cdata.getByte();
@@ -206,8 +205,8 @@
if (debug) { System.out.println(" channel=" + channel + "; npulses=" + npulses); }
- long daqID = HPSEcalDaqIDConverter.getDaqID(crate, slot, channel); - Long id = ecalIDConverter.daqToPhysicalID(daqID);
+ long daqID = HPSEcalConditions.getDaqID(crate, slot, channel); + Long id = HPSEcalConditions.daqToPhysicalID(daqID);
for (int k = 0; k < npulses; k++) { short pulseTime = cdata.getShort();
diff -u -r1.8 -r1.9 --- TestRunTriggeredReconToEvio.java 27 Apr 2012 22:13:53 -0000 1.8 +++ TestRunTriggeredReconToEvio.java 2 May 2012 00:39:40 -0000 1.9 @@ -8,7 +8,7 @@
import java.util.Queue; import org.jlab.coda.jevio.*; import org.lcsim.event.EventHeader;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.util.Driver; /**
@@ -27,7 +27,7 @@
Queue<QueuedEtEvent> builderQueue = null; private int eventsWritten = 0; public static boolean triggerBit = false;
- HPSEcalDaqIDConverter ecalIDConverter = null;
+ HPSEcalConditions ecalIDConverter = null;
ECalEvioWriter ecalWriter = null; SVTEvioWriter svtWriter = null; List<EvioWriter> writers = null;
diff -u -r1.2 -r1.3 --- EcalDaqPlots.java 30 Apr 2012 18:46:59 -0000 1.2 +++ EcalDaqPlots.java 2 May 2012 00:39:40 -0000 1.3 @@ -15,7 +15,7 @@
import org.lcsim.geometry.Detector; import org.lcsim.geometry.compact.Subdetector; import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
@@ -23,7 +23,6 @@
private String subdetectorName = "Ecal"; private String inputCollection = "EcalReadoutHits";
- private HPSEcalDaqIDConverter idMap;
private IPlotter plotter; private AIDA aida; private Detector detector;
@@ -53,8 +52,7 @@
} Subdetector subdetector = detector.getSubdetector(subdetectorName);
- idMap = new HPSEcalDaqIDConverter(); - idMap.fillDaqCellMap(subdetector);
+ HPSEcalConditions.fillDaqCellMap(subdetector);
setupPlots(); }
@@ -106,10 +104,10 @@
if (event.hasCollection(RawCalorimeterHit.class, inputCollection)) { List<RawCalorimeterHit> hits = event.get(RawCalorimeterHit.class, inputCollection); for (RawCalorimeterHit hit : hits) {
- Long daqId = idMap.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqId); - int slot = HPSEcalDaqIDConverter.getSlot(daqId); - int channel = HPSEcalDaqIDConverter.getChannel(daqId);
+ Long daqId = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqId); + int slot = HPSEcalConditions.getSlot(daqId); + int channel = HPSEcalConditions.getChannel(daqId);
//System.out.println("crate="+crate+"; slot="+slot+"; channel="+channel); //System.out.println("filling plot: " + "ECAL: Crate " + crate + "; Slot " + slot); aida.histogram1D("ECAL: Crate " + crate + "; Slot " + slot).fill(channel);
@@ -118,10 +116,10 @@
if (event.hasCollection(RawTrackerHit.class, inputCollection)) { List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollection); for (RawTrackerHit hit : hits) {
- Long daqId = idMap.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqId); - int slot = HPSEcalDaqIDConverter.getSlot(daqId); - int channel = HPSEcalDaqIDConverter.getChannel(daqId);
+ Long daqId = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqId); + int slot = HPSEcalConditions.getSlot(daqId); + int channel = HPSEcalConditions.getChannel(daqId);
//System.out.println("crate="+crate+"; slot="+slot+"; channel="+channel); //System.out.println("filling plot: " + "ECAL: Crate " + crate + "; Slot " + slot); aida.histogram1D("ECAL: Crate " + crate + "; Slot " + slot).fill(channel);
diff -u -r1.1 -r1.2 --- EcalPedestalPlots.java 29 Apr 2012 23:17:24 -0000 1.1 +++ EcalPedestalPlots.java 2 May 2012 00:39:40 -0000 1.2 @@ -20,7 +20,6 @@
import org.lcsim.geometry.compact.Subdetector; import org.lcsim.hps.monitoring.AIDAFrame; import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
@@ -29,7 +28,6 @@
private String subdetectorName; private Subdetector subdetector; private String inputCollection;
- private HPSEcalDaqIDConverter idMap;
private IPlotter plotter; private AIDA aida = AIDA.defaultInstance(); private AIDAFrame plotterFrame;
@@ -83,8 +81,6 @@
} subdetector = detector.getSubdetector(subdetectorName);
- idMap = new HPSEcalDaqIDConverter(); - idMap.fillDaqCellMap(subdetector);
dec = subdetector.getReadout().getIDDecoder(); setupPlots();
diff -u -r1.1 -r1.2 --- EcalWindowPlotsXY.java 29 Apr 2012 23:17:24 -0000 1.1 +++ EcalWindowPlotsXY.java 2 May 2012 00:39:40 -0000 1.2 @@ -17,7 +17,6 @@
import org.lcsim.geometry.compact.Subdetector; import org.lcsim.hps.monitoring.AIDAFrame; import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
@@ -25,7 +24,6 @@
private String subdetectorName; private String inputCollection;
- private HPSEcalDaqIDConverter idMap;
private IPlotter plotter; private AIDAFrame plotterFrame; private AIDA aida;
@@ -86,8 +84,6 @@
} Subdetector subdetector = detector.getSubdetector(subdetectorName);
- idMap = new HPSEcalDaqIDConverter(); - idMap.fillDaqCellMap(subdetector);
dec = subdetector.getReadout().getIDDecoder(); setupPlots();
diff -u -r1.1 -r1.2 --- EcalWindowPlots.java 29 Apr 2012 23:17:24 -0000 1.1 +++ EcalWindowPlots.java 2 May 2012 00:39:40 -0000 1.2 @@ -16,7 +16,7 @@
import org.lcsim.geometry.compact.Subdetector; import org.lcsim.hps.monitoring.AIDAFrame; import org.lcsim.hps.monitoring.Resettable;
-import org.lcsim.hps.recon.ecal.HPSEcalDaqIDConverter;
+import org.lcsim.hps.recon.ecal.HPSEcalConditions;
import org.lcsim.util.Driver; import org.lcsim.util.aida.AIDA;
@@ -24,7 +24,6 @@
private String subdetectorName; private String inputCollection;
- private HPSEcalDaqIDConverter idMap;
private IPlotter plotter; private AIDAFrame plotterFrame; private AIDA aida;
@@ -89,8 +88,7 @@
} Subdetector subdetector = detector.getSubdetector(subdetectorName);
- idMap = new HPSEcalDaqIDConverter(); - idMap.fillDaqCellMap(subdetector);
+ HPSEcalConditions.fillDaqCellMap(subdetector);
setupPlots(); }
@@ -145,10 +143,10 @@
if (event.hasCollection(RawTrackerHit.class, inputCollection)) { List<RawTrackerHit> hits = event.get(RawTrackerHit.class, inputCollection); for (RawTrackerHit hit : hits) {
- Long daqId = idMap.physicalToDaqID(hit.getCellID()); - int crate = HPSEcalDaqIDConverter.getCrate(daqId); - int slot = HPSEcalDaqIDConverter.getSlot(daqId); - int channel = HPSEcalDaqIDConverter.getChannel(daqId);
+ Long daqId = HPSEcalConditions.physicalToDaqID(hit.getCellID()); + int crate = HPSEcalConditions.getCrate(daqId); + int slot = HPSEcalConditions.getSlot(daqId); + int channel = HPSEcalConditions.getChannel(daqId);
// System.out.println("got hit: crate " + crate + ", slot " + slot + ", channel " + channel); if (hit.getADCValues().length != window) { throw new RuntimeException("Hit has unexpected window length " + hit.getADCValues().length + ", not " + window);
diff -N HPSEcalConditions.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ HPSEcalConditions.java 2 May 2012 00:39:40 -0000 1.1 @@ -0,0 +1,162 @@
+package org.lcsim.hps.recon.ecal; + +import java.io.BufferedReader; +import org.lcsim.geometry.Subdetector; +import java.io.IOException; +import java.io.Reader; +import java.io.StreamTokenizer; +import java.util.HashMap; +import java.util.StringTokenizer; +import org.lcsim.conditions.ConditionsManager; +import org.lcsim.geometry.util.IDEncoder; +import static org.lcsim.hps.evio.EventConstants.ECAL_LAYER; + +/** + * + * @author meeg + * @version $Id: HPSEcalConditions.java,v 1.1 2012/05/02 00:39:40 meeg Exp $ + */ +public class HPSEcalConditions { + + //DAQ channel map + private static HashMap<Long, Long> daqToPhysicalMap = new HashMap<Long, Long>(); + private static HashMap<Long, Long> physicalToDaqMap = new HashMap<Long, Long>(); + private static boolean mapLoaded = false; + //pedestals + private static HashMap<Long, Integer> daqToPedestalMap = new HashMap<Long, Integer>(); + private static HashMap<Long, Double> daqToNoiseMap = new HashMap<Long, Double>(); + private static boolean pedestalsLoaded = false; + + private HPSEcalConditions() { + } + + public static boolean mapLoaded() { + return mapLoaded; + } + + public static boolean pedestalsLoaded() { + return pedestalsLoaded; + } + + public static void loadPedestals() { + ConditionsManager conditions = ConditionsManager.defaultInstance(); + try { + Reader pedestalsReader = conditions.getRawConditions("calibECal/fadc01.ped").getReader(); + loadPedestals(pedestalsReader,1); + pedestalsReader = conditions.getRawConditions("calibECal/fadc02.ped").getReader(); + loadPedestals(pedestalsReader,2); + } catch (IOException e) { + throw new RuntimeException("couldn't get pedestals file", e); + } + pedestalsLoaded = true; + } + + public static void loadPedestals(Reader pedestalsReader, int crate) { + BufferedReader bufferedPedestals = new BufferedReader(pedestalsReader); + String line; + while (true) { + try { + line = bufferedPedestals.readLine(); + } catch (IOException e) { + throw new RuntimeException("couldn't parse pedestals file", e); + } + if (line == null) { + break; + } + + if (line.indexOf("#") != -1) { + line = line.substring(0, line.indexOf("#")); + } + + StringTokenizer lineTok = new StringTokenizer(line); + + if (lineTok.countTokens() != 0) { + if (lineTok.countTokens() != 5) { + throw new RuntimeException("Invalid line in pedestals file: " + line); + } else { + short slot = Short.valueOf(lineTok.nextToken()); + short channel = Short.valueOf(lineTok.nextToken()); + int pedestal = Integer.valueOf(lineTok.nextToken()); + double noise = Double.valueOf(lineTok.nextToken()); + daqToPedestalMap.put(getDaqID(crate, slot, channel), pedestal); + daqToNoiseMap.put(getDaqID(crate, slot, channel), noise); + } + } + } + } + + public static void fillDaqCellMap(Subdetector ecal) { + + System.out.println("reading DAQ map"); + + IDEncoder enc = new IDEncoder(ecal.getIDDecoder().getIDDescription()); + enc.setValue("system", ecal.getSystemID()); + enc.setValue("layer", ECAL_LAYER); + + ConditionsManager conditions = ConditionsManager.defaultInstance(); + StreamTokenizer tok = null; + try { + tok = new StreamTokenizer(conditions.getRawConditions("daqmap/ecal.txt").getReader()); + } catch (IOException e) { + throw new RuntimeException("couldn't get DAQ map from conditions manager", e); + } + tok.commentChar('#'); + tok.eolIsSignificant(false); + tok.parseNumbers(); + try { + while (tok.nextToken() != StreamTokenizer.TT_EOF) { + tok.pushBack(); + int x = (int) getNumber(tok); + int y = (int) getNumber(tok); + enc.setValue("ix", x); + enc.setValue("iy", y); + int crate = (int) getNumber(tok); + short slot = (short) getNumber(tok); + short channel = (short) getNumber(tok); + addMapEntry(enc.getID(), getDaqID(crate, slot, channel)); +// System.out.printf("x = %d, y = %d, crate = %d, slot = %d, channel = %d\n", x, y, crate, slot, channel); +// System.out.printf("physicalID = %d, daqID = %d\n",enc.getID(), getDaqID(crate, slot, channel)); + } + } catch (IOException e) { + throw new RuntimeException("couldn't parse DAQ map", e); + } + mapLoaded = true; + } + + private static double getNumber(StreamTokenizer tok) throws IOException { + if (tok.nextToken() == StreamTokenizer.TT_NUMBER) { + return tok.nval; + } else { + throw new IOException("expected an int from DAQ map, instead got " + tok); + } + } + + private static void addMapEntry(long physicalID, long daqID) { + daqToPhysicalMap.put(daqID, physicalID); + physicalToDaqMap.put(physicalID, daqID); + } + + public static long getDaqID(int crate, short slot, short channel) { + return (((long) crate) << 32) | ((long) slot << 16) | (long) channel; + } + + public static int getCrate(long physicalID) { + return (int) (physicalID >>> 32); + } + + public static short getSlot(long physicalID) { + return (short) ((physicalID >>> 16) & 0xFFFF); + } + + public static short getChannel(long physicalID) { + return (short) (physicalID & 0xFFFF); + } + + public static Long physicalToDaqID(long physicalID) { + return physicalToDaqMap.get(physicalID); + } + + public static Long daqToPhysicalID(long daqID) { + return daqToPhysicalMap.get(daqID); + } +}
diff -N HPSEcalDaqIDConverter.java --- HPSEcalDaqIDConverter.java 5 Apr 2012 19:05:23 -0000 1.3 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,103 +0,0 @@
-/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package org.lcsim.hps.recon.ecal; - -import org.lcsim.geometry.Subdetector; -import java.io.IOException; -import java.io.StreamTokenizer; -import java.util.HashMap; -import org.lcsim.conditions.ConditionsManager; -import org.lcsim.geometry.util.IDEncoder; -import static org.lcsim.hps.evio.EventConstants.ECAL_LAYER; - -/** - * - * @author meeg - * @version $Id: HPSEcalDaqIDConverter.java,v 1.3 2012/04/05 19:05:23 meeg Exp $ - */ -public class HPSEcalDaqIDConverter { - - private HashMap<Long, Long> daqToPhysicalMap; - private HashMap<Long, Long> physicalToDaqMap; - - public HPSEcalDaqIDConverter() { - daqToPhysicalMap = new HashMap<Long, Long>(); - physicalToDaqMap = new HashMap<Long, Long>(); - } - - public void fillDaqCellMap(Subdetector ecal) { - - System.out.println("reading DAQ map"); - - IDEncoder enc = new IDEncoder(ecal.getIDDecoder().getIDDescription()); - enc.setValue("system", ecal.getSystemID()); - enc.setValue("layer", ECAL_LAYER); - - ConditionsManager conditions = ConditionsManager.defaultInstance(); - StreamTokenizer tok = null; - try { - tok = new StreamTokenizer(conditions.getRawConditions("daqmap/ecal.txt").getReader()); - } catch (IOException e) { - throw new RuntimeException("couldn't get DAQ map from conditions manager", e); - } - tok.commentChar('#'); - tok.eolIsSignificant(false); - tok.parseNumbers(); - try { - while (tok.nextToken() != StreamTokenizer.TT_EOF) { - tok.pushBack(); - int x = (int) getNumber(tok); - int y = (int) getNumber(tok); - enc.setValue("ix", x); - enc.setValue("iy", y); - int crate = (int) getNumber(tok); - short slot = (short) getNumber(tok); - short channel = (short) getNumber(tok); - addMapEntry(enc.getID(), getDaqID(crate, slot, channel)); -// System.out.printf("x = %d, y = %d, crate = %d, slot = %d, channel = %d\n", x, y, crate, slot, channel); -// System.out.printf("physicalID = %d, daqID = %d\n",enc.getID(), getDaqID(crate, slot, channel)); - } - } catch (IOException e) { - throw new RuntimeException("couldn't parse DAQ map", e); - } - } - - private static double getNumber(StreamTokenizer tok) throws IOException { - if (tok.nextToken() == StreamTokenizer.TT_NUMBER) { - return tok.nval; - } else { - throw new IOException("expected an int from DAQ map, instead got " + tok); - } - } - - private void addMapEntry(long physicalID, long daqID) { - daqToPhysicalMap.put(daqID, physicalID); - physicalToDaqMap.put(physicalID, daqID); - } - - public static long getDaqID(int crate, short slot, short channel) { - return (((long) crate) << 32) | ((long) slot << 16) | (long) channel; - } - - public static int getCrate(long physicalID) { - return (int) (physicalID >>> 32); - } - - public static short getSlot(long physicalID) { - return (short) ((physicalID >>> 16) & 0xFFFF); - } - - public static short getChannel(long physicalID) { - return (short) (physicalID & 0xFFFF); - } - - public Long physicalToDaqID(long physicalID) { - return physicalToDaqMap.get(physicalID); - } - - public Long daqToPhysicalID(long daqID) { - return daqToPhysicalMap.get(daqID); - } -}
Use REPLY-ALL to reply to list
To unsubscribe from the LCD-CVS list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCD-CVS&A=1