Skip to content

Commit a15e75a

Browse files
committed
optimize lookup
1 parent 190dd78 commit a15e75a

1 file changed

Lines changed: 56 additions & 60 deletions

File tree

common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java

Lines changed: 56 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ public class DetectorEventDecoder {
2929

3030
HashMap<DetectorType,String> tableTrans;
3131
HashMap<DetectorType,String> tableFitter;
32-
HashMap<DetectorType,IndexedTable> tablesFitter;
3332

34-
private int runNumber = 10;
33+
HashMap<DetectorType, IndexedTable> tablesFitter;
34+
TranslationTable translator;
3535

36-
private ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter();
37-
private MVTFitter mvtFitter = new MVTFitter();
38-
39-
private TranslationTable translator = new TranslationTable();
36+
ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter();
37+
MVTFitter mvtFitter = new MVTFitter();
4038

39+
int runNumber = 10;
40+
4141
public DetectorEventDecoder(boolean development){
4242
if(development==true){
4343
this.initDecoderDev();
@@ -100,21 +100,14 @@ public DetectorEventDecoder(){
100100
}
101101

102102
public final void initDecoderDev() {
103-
104-
keysFilter = new HashSet<>();
105-
keysMicromega= new HashSet<>();
106-
tableTrans = new HashMap<>();
107-
tableFitter = new HashMap<>();
108-
keysFilter.add(DetectorType.DC);
109-
110103
tableTrans.put(DetectorType.HTCC, "/daq/tt/clasdev/htcc");
111104
tableTrans.put(DetectorType.BST, "/daq/tt/clasdev/svt");
112105
tableTrans.put(DetectorType.RTPC, "/daq/tt/clasdev/rtpc");
113106
translationManager.init(tableTrans.values().stream().collect(Collectors.toList()));
114107

115108
tableFitter.put(DetectorType.HTCC, "/daq/fadc/clasdev/htcc");
116109
fitterManager.init(tableFitter.values().stream().collect(Collectors.toList()));
117-
110+
118111
scalerManager.init(Arrays.asList(new String[]{"/runcontrol/fcup","/runcontrol/slm","/runcontrol/hwp",
119112
"/runcontrol/helicity","/daq/config/scalers/dsc1"}));
120113
}
@@ -129,8 +122,9 @@ public final void initDecoder(boolean initializeManagers){
129122
keysMicromega= new HashSet<>();
130123
tableTrans = new HashMap<>();
131124
tableFitter = new HashMap<>();
132-
keysFilter.add(DetectorType.DC);
133-
125+
126+
keysFilter.add(DetectorType.DC);
127+
134128
keysMicromega.add(DetectorType.BMT);
135129
keysMicromega.add(DetectorType.FMT);
136130
keysMicromega.add(DetectorType.FTTRK);
@@ -199,8 +193,9 @@ public void checkTables() {
199193
}
200194

201195
/**
202-
* applies translation table to the digitized data to translate
203-
* crate,slot channel to sector layer component.
196+
* Apply CCDB /daq/tt translation tables to the digitized data to translate
197+
* crate/slot/channel to sector/layer/component/order.
198+
*
204199
* @param detectorData
205200
*/
206201
public void translate(List<DetectorDataDgtz> detectorData){
@@ -224,56 +219,59 @@ public void translate(List<DetectorDataDgtz> detectorData){
224219
}
225220
}
226221

227-
public void fitPulses(List<DetectorDataDgtz> detectorData){
222+
/**
223+
* Use CCDB /daq/fadc tables to convert waveforms to pulses.
224+
*
225+
* @param detectorData
226+
*/
227+
public void fitPulses(List<DetectorDataDgtz> detectorData) {
228228

229-
// preload CCDB tables once:
230-
HashMap<DetectorType,IndexedTable> tables = new HashMap<>();
231-
for (Map.Entry<DetectorType, String> e : tableFitter.entrySet()) {
232-
tables.put(e.getKey(), fitterManager.getConstants(runNumber, e.getValue()));
233-
}
229+
final long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0);
230+
231+
for (DetectorDataDgtz data : detectorData) {
234232

235-
for(DetectorDataDgtz data : detectorData){
236233
if (data.getADCSize() == 0) continue;
237-
int crate = data.getDescriptor().getCrate();
238-
int slot = data.getDescriptor().getSlot();
239-
int channel = data.getDescriptor().getChannel();
240-
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel);
241-
long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0);
242-
boolean ismm = keysMicromega.contains(data.getDescriptor().getType());
243-
244-
for (DetectorType type : tableFitter.keySet()) {
245-
IndexedTable daq = tables.get(type);
246-
//custom MM fitter
247-
if (ismm && data.getDescriptor().getType() == type) {
248-
short adcOffset = (short) daq.getDoubleValueByHash("adc_offset", hash0);
249-
double fineTimeStampResolution = (byte) daq.getDoubleValueByHash("dream_clock", hash0);
250-
double samplingTime = (byte) daq.getDoubleValueByHash("sampling_time", hash0);
251-
int sparseSample = daq.getIntValueByHash("sparse", hash0);
252-
ADCData adc = data.getADCData(0);
253-
mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample);
254-
adc.setHeight((short) (mvtFitter.adcMax));
255-
adc.setTime((int) (mvtFitter.timeMax));
256-
adc.setIntegral((int) (mvtFitter.integral));
257-
adc.setTimeStamp(mvtFitter.timestamp);
258-
// first one wins:
259-
break;
260-
}
261-
else if(daq.hasEntryByHash(hash)==true){
262-
int nsa = daq.getIntValueByHash("nsa", hash);
263-
int nsb = daq.getIntValueByHash("nsb", hash);
264-
int tet = daq.getIntValueByHash("tet", hash);
234+
235+
DetectorType type = data.getDescriptor().getType();
236+
if (!tablesFitter.containsKey(type)) continue;
237+
IndexedTable daqTable = tablesFitter.get(type);
238+
239+
// For MM, assume crate/slot/channel=0/0/0 for table lookup:
240+
if (keysMicromega.contains(type)) {
241+
short adcOffset = (short) daqTable.getDoubleValueByHash("adc_offset", hash0);
242+
double fineTimeStampResolution = (byte) daqTable.getDoubleValueByHash("dream_clock", hash0);
243+
double samplingTime = (byte) daqTable.getDoubleValueByHash("sampling_time", hash0);
244+
int sparseSample = daqTable.getIntValueByHash("sparse", hash0);
245+
ADCData adc = data.getADCData(0);
246+
mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample);
247+
adc.setHeight((short) (mvtFitter.adcMax));
248+
adc.setTime((int) (mvtFitter.timeMax));
249+
adc.setIntegral((int) (mvtFitter.integral));
250+
adc.setTimeStamp(mvtFitter.timestamp);
251+
}
252+
253+
// Otherwise, use crate/slot/channel to find the table entry:
254+
else {
255+
long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(
256+
data.getDescriptor().getCrate(),
257+
data.getDescriptor().getSlot(),
258+
data.getDescriptor().getChannel());
259+
if (daqTable.hasEntryByHash(hash)) {
260+
int nsa = daqTable.getIntValueByHash("nsa", hash);
261+
int nsb = daqTable.getIntValueByHash("nsb", hash);
262+
int tet = daqTable.getIntValueByHash("tet", hash);
265263
int ped = 0;
266-
if(data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) {
267-
ped = daq.getIntValueByHash("pedestal", hash);
264+
if (data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) {
265+
ped = daqTable.getIntValueByHash("pedestal", hash);
268266
}
269-
for(int i = 0; i < data.getADCSize(); i++){
267+
for (int i = 0; i < data.getADCSize(); i++) {
270268
ADCData adc = data.getADCData(i);
271269
if(adc.getPulseSize()>0){
272270
try {
273271
extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray());
274272
} catch (Exception e) {
275-
System.out.println(">>>> error : fitting pulse "
276-
+ crate + " / " + slot + " / " + channel);
273+
System.err.println(">>>> error : fitting pulse "+data.getDescriptor().getCrate()+
274+
" / "+data.getDescriptor().getSlot()+" / "+data.getDescriptor().getChannel());
277275
}
278276
int adc_corrected = extendedFitter.adc + extendedFitter.ped*(nsa+nsb);
279277
adc.setHeight((short) this.extendedFitter.pulsePeakValue);
@@ -283,8 +281,6 @@ else if(daq.hasEntryByHash(hash)==true){
283281
}
284282
data.getADCData(i).setADC(nsa, nsb);
285283
}
286-
// first one wins:
287-
break;
288284
}
289285
}
290286
}

0 commit comments

Comments
 (0)