diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/TranslationTable.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/TranslationTable.java new file mode 100644 index 0000000000..9958969083 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/TranslationTable.java @@ -0,0 +1,77 @@ +package org.jlab.detector.decode; + +import org.jlab.detector.base.DetectorType; +import org.jlab.detector.calib.utils.ConstantsManager; +import org.jlab.utils.groups.IndexedTable; + +/** + * + * @author baltzell + */ +public class TranslationTable extends IndexedTable { + + public TranslationTable() { + super(3,new String[]{"sector/I","layer/I","component/I","order/I","type/I"}); + }; + + public void add(DetectorType dt, IndexedTable it) { + + for (Object key : it.getList().getMap().keySet()) { + + // get the indices: + long hash = (long)key; + int crate = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 0); + int slot = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 1); + int channel = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 2); + + if (hasEntryByHash(hash)) { + System.err.print("TranslationTable: found CCDB overlap for "); + System.err.println(String.format("type %d/%s versus %s and c/s/c=%d/%d/%d", + getIntValueByHash("type",hash), + DetectorType.getType(getIntValueByHash("type",hash)), + dt,crate,slot,channel)); + } + else { + // add row to the new table: + addEntry(crate, slot, channel); + + // add each column's entry to the new row: + for (int column=0; column entryMap = new LinkedHashMap<>(); + protected Map entryTypes = new LinkedHashMap<>(); + private IndexedList entries = null; - private Map entryMap = new LinkedHashMap<>(); - private Map entryTypes = new LinkedHashMap<>(); private List entryNames = new ArrayList<>(); private List indexNames = new ArrayList<>(); private String precisionFormat = "%.6f"; @@ -119,7 +121,7 @@ public void setIntValue(Integer value, String item, int... index){ } } } - + public void setDoubleValue(Double value, String item, int... index){ if(this.entries.hasItem(index)==false){ if(DEBUG_MODE>0) System.out.println( "[IndexedTable] ---> error.. entry does not exist"); @@ -133,38 +135,6 @@ public void setDoubleValue(Double value, String item, int... index){ } } - public int getIntValueByHash(int index, long hash) { - if (this.entries.hasItemByHash(hash)) - return this.entries.getItemByHash(hash).getValue(index).intValue(); - return 0; - } - - public double getDoubleValueByHash(int index, long hash) { - if (this.entries.hasItemByHash(hash)) - return this.entries.getItemByHash(hash).getValue(index).doubleValue(); - return 0; - } - - public int getIntValueByHash(String item, long hash) { - if (this.entries.hasItemByHash(hash)) { - if (this.entryMap.containsKey(item)) { - int index = this.entryMap.get(item); - return this.entries.getItemByHash(hash).getValue(index).intValue(); - } - } - return 0; - } - - public double getDoubleValueByHash(String item, long hash) { - if (this.entries.hasItemByHash(hash)) { - if (this.entryMap.containsKey(item)) { - int index = this.entryMap.get(item); - return this.entries.getItemByHash(hash).getValue(index).doubleValue(); - } - } - return 0; - } - public int getIntValue(String item, int... index){ if(this.entries.hasItem(index)==false){ if(DEBUG_MODE>0) System.out.println( "[IndexedTable] ---> error.. entry does not exist"); @@ -193,6 +163,38 @@ public double getDoubleValue(String item, int... index){ return 0; } + public void setIntValueByHash(Integer value, int column, long hash) { + this.entries.getItemByHash(hash).setValue(column, value); + } + + public int getIntValueByHash(int index, long hash) { + return entries.getItemByHash(hash).getValue(index).intValue(); + } + + public double getDoubleValueByHash(int index, long hash) { + return entries.getItemByHash(hash).getValue(index).doubleValue(); + } + + public int getIntValueByHash(String item, long hash) { + return entries.getItemByHash(hash).getValue(entryMap.get(item)).intValue(); + } + + public double getDoubleValueByHash(String item, long hash) { + return entries.getItemByHash(hash).getValue(entryMap.get(item)).doubleValue(); + } + + public List getValuesByHash(long hash) { + return this.entries.getItemByHash(hash).entryValues; + } + + public List getIntegersByHash(long hash) { + return getValuesByHash(hash).stream().map(x -> x.intValue()).collect(Collectors.toList()); + } + + public List getDoublesByHash(long hash) { + return getValuesByHash(hash).stream().map(x -> x.doubleValue()).collect(Collectors.toList()); + } + public NamedEntry getNamedEntry(int... index) { return NamedEntry.create(entries.getItem(index), entryNames, index); } @@ -200,7 +202,11 @@ public NamedEntry getNamedEntry(int... index) { public IndexedList getList(){ return this.entries; } - + + public Map getEntryMap(){ + return this.entryMap; + } + private void parseFormat(String format){ String[] tokens = format.split(":"); entryMap.clear();