Skip to content

Commit e8bc476

Browse files
authored
feat: add indexing translation tables by detector type (#1029)
* relax permissions * provide more access * add more hash-based accessors * remove checks from hash-based accessors, cleanup * add "translation table", with additional DetectorType index
1 parent a4f6b79 commit e8bc476

File tree

2 files changed

+119
-36
lines changed

2 files changed

+119
-36
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package org.jlab.detector.decode;
2+
3+
import org.jlab.detector.base.DetectorType;
4+
import org.jlab.detector.calib.utils.ConstantsManager;
5+
import org.jlab.utils.groups.IndexedTable;
6+
7+
/**
8+
*
9+
* @author baltzell
10+
*/
11+
public class TranslationTable extends IndexedTable {
12+
13+
public TranslationTable() {
14+
super(3,new String[]{"sector/I","layer/I","component/I","order/I","type/I"});
15+
};
16+
17+
public void add(DetectorType dt, IndexedTable it) {
18+
19+
for (Object key : it.getList().getMap().keySet()) {
20+
21+
// get the indices:
22+
long hash = (long)key;
23+
int crate = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 0);
24+
int slot = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 1);
25+
int channel = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 2);
26+
27+
if (hasEntryByHash(hash)) {
28+
System.err.print("TranslationTable: found CCDB overlap for ");
29+
System.err.println(String.format("type %d/%s versus %s and c/s/c=%d/%d/%d",
30+
getIntValueByHash("type",hash),
31+
DetectorType.getType(getIntValueByHash("type",hash)),
32+
dt,crate,slot,channel));
33+
}
34+
else {
35+
// add row to the new table:
36+
addEntry(crate, slot, channel);
37+
38+
// add each column's entry to the new row:
39+
for (int column=0; column<it.getEntryMap().values().size(); column++) {
40+
int value = it.getIntValueByHash(column, hash);
41+
setIntValueByHash(value, column, hash);
42+
}
43+
44+
// add the new detector type, as the last column:
45+
setIntValueByHash(dt.getDetectorId(), it.getEntryMap().values().size(), hash);
46+
}
47+
}
48+
}
49+
50+
51+
public static final DetectorType[] TYPES = new DetectorType[]{
52+
DetectorType.FTCAL,DetectorType.FTHODO,DetectorType.FTTRK,
53+
DetectorType.LTCC,DetectorType.ECAL,DetectorType.FTOF,
54+
DetectorType.HTCC,DetectorType.DC,DetectorType.CTOF,
55+
DetectorType.CND,DetectorType.BST,DetectorType.RF,
56+
DetectorType.BMT,DetectorType.FMT,DetectorType.RICH,
57+
DetectorType.HEL,DetectorType.BAND,DetectorType.RTPC,
58+
DetectorType.RASTER,DetectorType.ATOF,DetectorType.AHDC};
59+
60+
public static final String[] STYPES = new String[]{
61+
"/daq/tt/ftcal","/daq/tt/fthodo","/daq/tt/fttrk",
62+
"/daq/tt/ltcc","/daq/tt/ec","/daq/tt/ftof",
63+
"/daq/tt/htcc","/daq/tt/dc","/daq/tt/ctof",
64+
"/daq/tt/cnd","/daq/tt/svt","/daq/tt/rf",
65+
"/daq/tt/bmt","/daq/tt/fmt","/daq/tt/rich2",
66+
"/daq/tt/hel","/daq/tt/band","/daq/tt/rtpc",
67+
"/daq/tt/raster","/daq/tt/atof","/daq/tt/ahdc"};
68+
69+
public static void main(String[] args) {
70+
ConstantsManager conman = new ConstantsManager();
71+
conman.init(STYPES);
72+
TranslationTable tt = new TranslationTable();
73+
for (int i=0; i<STYPES.length; i++)
74+
tt.add(TYPES[i],conman.getConstants(18779,STYPES[i]));
75+
tt.show();
76+
}
77+
}

common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedTable.java

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.List;
1010
import java.util.Map;
1111
import java.util.Set;
12+
import java.util.stream.Collectors;
1213
import javax.swing.JTable;
1314
import javax.swing.table.DefaultTableCellRenderer;
1415
import javax.swing.table.DefaultTableModel;
@@ -22,9 +23,10 @@ public class IndexedTable extends DefaultTableModel {
2223

2324
public static final IndexGenerator DEFAULT_GENERATOR = new IndexGenerator();
2425

26+
protected Map<String,Integer> entryMap = new LinkedHashMap<>();
27+
protected Map<String,String> entryTypes = new LinkedHashMap<>();
28+
2529
private IndexedList<IndexedEntry> entries = null;
26-
private Map<String,Integer> entryMap = new LinkedHashMap<>();
27-
private Map<String,String> entryTypes = new LinkedHashMap<>();
2830
private List<String> entryNames = new ArrayList<>();
2931
private List<String> indexNames = new ArrayList<>();
3032
private String precisionFormat = "%.6f";
@@ -119,7 +121,7 @@ public void setIntValue(Integer value, String item, int... index){
119121
}
120122
}
121123
}
122-
124+
123125
public void setDoubleValue(Double value, String item, int... index){
124126
if(this.entries.hasItem(index)==false){
125127
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){
133135
}
134136
}
135137

136-
public int getIntValueByHash(int index, long hash) {
137-
if (this.entries.hasItemByHash(hash))
138-
return this.entries.getItemByHash(hash).getValue(index).intValue();
139-
return 0;
140-
}
141-
142-
public double getDoubleValueByHash(int index, long hash) {
143-
if (this.entries.hasItemByHash(hash))
144-
return this.entries.getItemByHash(hash).getValue(index).doubleValue();
145-
return 0;
146-
}
147-
148-
public int getIntValueByHash(String item, long hash) {
149-
if (this.entries.hasItemByHash(hash)) {
150-
if (this.entryMap.containsKey(item)) {
151-
int index = this.entryMap.get(item);
152-
return this.entries.getItemByHash(hash).getValue(index).intValue();
153-
}
154-
}
155-
return 0;
156-
}
157-
158-
public double getDoubleValueByHash(String item, long hash) {
159-
if (this.entries.hasItemByHash(hash)) {
160-
if (this.entryMap.containsKey(item)) {
161-
int index = this.entryMap.get(item);
162-
return this.entries.getItemByHash(hash).getValue(index).doubleValue();
163-
}
164-
}
165-
return 0;
166-
}
167-
168138
public int getIntValue(String item, int... index){
169139
if(this.entries.hasItem(index)==false){
170140
if(DEBUG_MODE>0) System.out.println( "[IndexedTable] ---> error.. entry does not exist");
@@ -193,14 +163,50 @@ public double getDoubleValue(String item, int... index){
193163
return 0;
194164
}
195165

166+
public void setIntValueByHash(Integer value, int column, long hash) {
167+
this.entries.getItemByHash(hash).setValue(column, value);
168+
}
169+
170+
public int getIntValueByHash(int index, long hash) {
171+
return entries.getItemByHash(hash).getValue(index).intValue();
172+
}
173+
174+
public double getDoubleValueByHash(int index, long hash) {
175+
return entries.getItemByHash(hash).getValue(index).doubleValue();
176+
}
177+
178+
public int getIntValueByHash(String item, long hash) {
179+
return entries.getItemByHash(hash).getValue(entryMap.get(item)).intValue();
180+
}
181+
182+
public double getDoubleValueByHash(String item, long hash) {
183+
return entries.getItemByHash(hash).getValue(entryMap.get(item)).doubleValue();
184+
}
185+
186+
public List<Number> getValuesByHash(long hash) {
187+
return this.entries.getItemByHash(hash).entryValues;
188+
}
189+
190+
public List<Integer> getIntegersByHash(long hash) {
191+
return getValuesByHash(hash).stream().map(x -> x.intValue()).collect(Collectors.toList());
192+
}
193+
194+
public List<Double> getDoublesByHash(long hash) {
195+
return getValuesByHash(hash).stream().map(x -> x.doubleValue()).collect(Collectors.toList());
196+
}
197+
196198
public NamedEntry getNamedEntry(int... index) {
197199
return NamedEntry.create(entries.getItem(index), entryNames, index);
198200
}
199201

200202
public IndexedList getList(){
201203
return this.entries;
202204
}
203-
205+
206+
public Map<String,Integer> getEntryMap(){
207+
return this.entryMap;
208+
}
209+
204210
private void parseFormat(String format){
205211
String[] tokens = format.split(":");
206212
entryMap.clear();

0 commit comments

Comments
 (0)