Commit in hps-java/src/main/java/org/lcsim/hps/recon/ecal on MAIN | |||
HPSEcalDaqIDConverter.java | +115 | added 1.1 |
ECal ID converter class
diff -N HPSEcalDaqIDConverter.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ HPSEcalDaqIDConverter.java 4 Apr 2012 23:34:51 -0000 1.1 @@ -0,0 +1,115 @@
+/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.lcsim.hps.recon.ecal; + +import java.io.IOException; +import java.io.StreamTokenizer; +import java.util.HashMap; +import org.lcsim.conditions.ConditionsManager; + +/** + * + * @author meeg + * @version $Id: HPSEcalDaqIDConverter.java,v 1.1 2012/04/04 23:34:51 meeg Exp $ + */ +public class HPSEcalDaqIDConverter { + + private HashMap<DaqID, PhysicalID> daqToPhysicalMap; + private HashMap<PhysicalID, DaqID> physicalToDaqMap; + + public HPSEcalDaqIDConverter() { + daqToPhysicalMap = new HashMap<DaqID, PhysicalID>(); + physicalToDaqMap = new HashMap<PhysicalID, DaqID>(); + } + + public void fillDaqCellMap() { + System.out.println("reading DAQ map"); + 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 { + int[] ids = new int[5]; + do { + for (int i = 0; i < 5; i++) { + if (tok.nextToken() == StreamTokenizer.TT_NUMBER) { + ids[i] = (int) tok.nval; + } else { + throw new IOException("expected an int from DAQ map, instead got " + tok); + } + } + addMapEntry(ids[0], ids[1], ids[2], ids[3], ids[4]); + System.out.printf("x = %d, y = %d, crate = %d, slot = %d, channel = %d\n", ids[0], ids[1], ids[2], ids[3], ids[4]); + } while (tok.nextToken() != StreamTokenizer.TT_EOF); + } catch (IOException e) { + throw new RuntimeException("couldn't parse DAQ map", e); + } + } + + public DaqID physicalToDaqID(PhysicalID physicalID) { + return physicalToDaqMap.get(physicalID); + } + + public PhysicalID daqToPhysicalID(DaqID daqID) { + return daqToPhysicalMap.get(daqID); + } + + private void addMapEntry(int x, int y, int crate, int slot, int channel) { + DaqID daqID = new DaqID(crate, slot, channel); + PhysicalID physicalID = new PhysicalID(x, y); + daqToPhysicalMap.put(daqID, physicalID); + physicalToDaqMap.put(physicalID, daqID); + } + + public class DaqID { + + private int crate; + private int slot; + private int channel; + + public DaqID(int crate, int slot, int channel) { + this.crate = crate; + this.slot = slot; + this.channel = channel; + } + + public int getChannel() { + return channel; + } + + public int getCrate() { + return crate; + } + + public int getSlot() { + return slot; + } + } + + public class PhysicalID { + + private int x; + private int y; + + public PhysicalID(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + } +}
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