diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java index 6cb753f016..fd37e060fa 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/base/DetectorDescriptor.java @@ -88,6 +88,14 @@ public final void setSectorLayerComponent(int sector, int layer, int comp){ this.dt_COMPONENT = comp; } + public final void setSectorLayerComponentOrderType(int sector, int layer, int comp, int order, int type) { + this.dt_SECTOR = sector; + this.dt_LAYER = layer; + this.dt_COMPONENT = comp; + this.dt_ORDER = order; + this.detectorType = DetectorType.getType(type); + } + public static int generateHashCode(int s, int l, int c){ return ((s<<24)&0xFF000000)| ((l<<16)&0x00FF0000)|(c&0x0000FFFF); @@ -99,7 +107,6 @@ public int getHashCode(){ (this.dt_COMPONENT&0x00000FFF); return hash; } - public void copy(DetectorDescriptor desc){ this.hw_SLOT = desc.hw_SLOT; @@ -119,7 +126,6 @@ public boolean compare(DetectorDescriptor desc){ return false; } - public static String getName(String base, int... ids){ StringBuilder str = new StringBuilder(); str.append(base); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder.java index 380a7169f3..ef766698d8 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder.java @@ -719,6 +719,8 @@ public void initEvent(DataEvent event){ if(evioEvent.getHandler().getStructure()!=null){ try { + codaDecoder.cacheBranches(evioEvent); + dataList = codaDecoder.getDataEntries( (EvioDataEvent) event); List fadcPacked = codaDecoder.getADCEntries((EvioDataEvent) event); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaEventDecoder.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaEventDecoder.java index 13d3c4fa8d..a6a8d13bbd 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaEventDecoder.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaEventDecoder.java @@ -39,15 +39,29 @@ public class CodaEventDecoder { private byte helicityLevel3 = HelicityBit.UDF.value(); private final List triggerWords = new ArrayList<>(); JsonObject epicsData = new JsonObject(); + List branchList = null; private int tiMaster = -1; // FIXME: move this to CCDB, e.g., meanwhile cannot reuse ROC id private static final List PCIE_ROCS = Arrays.asList(new Integer[]{78}); - public CodaEventDecoder(){ + public CodaEventDecoder(){} + /** + * Load map by crate(?). + * + * @param event + */ + void cacheBranches(EvioDataEvent event) { + branchList = getEventBranches(event); + //branchMap = new TreeMap<>(); + //for (EvioTreeBranch branch : branchList) { + // if (!branchMap.containsKey(branch.getTag())) + // branchMap.put(branch.getTag(), branch); + //} } + /** * returns detector digitized data entries from the event. * all branches are analyzed and different types of digitized data @@ -69,9 +83,8 @@ public List getDataEntries(EvioDataEvent event){ // from the previous event, in the case where there's no HEAD bank: this.setTriggerBits(0); List rawEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); this.setTimeStamp(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ List list = this.getDataEntries(event,branch.getTag()); if(list != null){ rawEntries.addAll(list); @@ -186,8 +199,7 @@ public void setTriggerBits(long triggerBits) { public List getADCEntries(EvioDataEvent event){ List entries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ List list = this.getADCEntries(event,branch.getTag()); if(list != null){ entries.addAll(list); @@ -198,29 +210,20 @@ public List getADCEntries(EvioDataEvent event){ public List getADCEntries(EvioDataEvent event, int crate){ List entries = new ArrayList<>(); - - List branches = this.getEventBranches(event); - EvioTreeBranch cbranch = this.getEventBranch(branches, crate); - + EvioTreeBranch cbranch = this.getEventBranch(branchList, crate); if(cbranch == null ) return null; - for(EvioNode node : cbranch.getNodes()){ if(node.getTag()==57638){ return this.getDataEntries_57638(crate, node, event); } } - return entries; } public List getADCEntries(EvioDataEvent event, int crate, int tagid){ - List adc = new ArrayList<>(); - List branches = this.getEventBranches(event); - - EvioTreeBranch cbranch = this.getEventBranch(branches, crate); + EvioTreeBranch cbranch = this.getEventBranch(branchList, crate); if(cbranch == null ) return null; - for(EvioNode node : cbranch.getNodes()){ if(node.getTag()==tagid){ // This is regular integrated pulse mode, used for FTOF @@ -238,13 +241,9 @@ public List getADCEntries(EvioDataEvent event, int crate, int tagid){ * @return */ public List getDataEntries(EvioDataEvent event, int crate){ - - List branches = this.getEventBranches(event); List bankEntries = new ArrayList<>(); - - EvioTreeBranch cbranch = this.getEventBranch(branches, crate); + EvioTreeBranch cbranch = this.getEventBranch(branchList, crate); if(cbranch == null ) return null; - for (EvioNode node : cbranch.getNodes()) { if (node.getTag() == 57615) { // This is regular integrated pulse mode, used for FTOF @@ -1233,8 +1232,7 @@ public List getDataEntries_57657(Integer crate, EvioNode node public void getDataEntries_EPICS(EvioDataEvent event){ epicsData = new JsonObject(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ for(EvioNode node : branch.getNodes()){ if(node.getTag()==57620) { byte[] stringData = ByteDataTransformer.toByteArray(node.getStructureBuffer(true)); @@ -1260,8 +1258,7 @@ public void getDataEntries_EPICS(EvioDataEvent event){ public HelicityDecoderData getDataEntries_HelicityDecoder(EvioDataEvent event){ HelicityDecoderData data = null; - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ for(EvioNode node : branch.getNodes()){ if(node.getTag()==57651) { @@ -1341,8 +1338,7 @@ public HelicityDecoderData getDataEntries_HelicityDecoder(EvioDataEvent event){ public List getDataEntries_Scalers(EvioDataEvent event){ List scalerEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ int crate = branch.getTag(); for(EvioNode node : branch.getNodes()){ if(node.getTag()==57637 || node.getTag()==57621){ @@ -1421,8 +1417,7 @@ else if(node.getTag()==57621 && loop>=5) { public List getDataEntries_VTP(EvioDataEvent event){ List vtpEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ int crate = branch.getTag(); for(EvioNode node : branch.getNodes()){ if(node.getTag()==57634){ @@ -1447,11 +1442,10 @@ public List getDataEntries_VTP(EvioDataEvent event){ public List getDataEntries_TDC(EvioDataEvent event){ List tdcEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ int crate = branch.getTag(); - EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag()); + EvioTreeBranch cbranch = this.getEventBranch(branchList, branch.getTag()); for(EvioNode node : cbranch.getNodes()){ if(node.getTag()==57607){ int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); @@ -1479,10 +1473,9 @@ public List getDataEntries_TDC(EvioDataEvent event){ public List getDataEntries_TI(EvioDataEvent event){ List tiEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchList){ int crate = branch.getTag(); - EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag()); + EvioTreeBranch cbranch = this.getEventBranch(branchList, branch.getTag()); for(EvioNode node : cbranch.getNodes()){ if(node.getTag()==57610){ long[] longData = ByteDataTransformer.toLongArray(node.getStructureBuffer(true)); diff --git a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java index 4f726283a8..0560a64a70 100644 --- a/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/DetectorEventDecoder.java @@ -28,12 +28,15 @@ public class DetectorEventDecoder { List keysTrans = null; List keysFitter = null; List keysFilter = null; + List keysMicromega= null; private int runNumber = 10; private ExtendedFADCFitter extendedFitter = new ExtendedFADCFitter(); private MVTFitter mvtFitter = new MVTFitter(); + private TranslationTable translator = new TranslationTable(); + public DetectorEventDecoder(boolean development){ if(development==true){ this.initDecoderDev(); @@ -55,6 +58,11 @@ public void setVariation(String variation) { } public void setRunNumber(int run){ + if (run != this.runNumber) { + translator = new TranslationTable(); + for (int i=0; i detectorData){ - // Preload CCDB tables: - ArrayList tables = new ArrayList<>(); - for (String name : tablesTrans) { - tables.add(translationManager.getConstants(runNumber, name)); - } + for (DetectorDataDgtz d : detectorData) { - for (DetectorDataDgtz data : detectorData) { + // Get the hardware indexing for this detector data object: + long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(d.getDescriptor().getCrate(), + d.getDescriptor().getSlot(), d.getDescriptor().getChannel()); - // Get the hardware indexing for this detector hit: - int crate = data.getDescriptor().getCrate(); - int slot = data.getDescriptor().getSlot(); - int channel = data.getDescriptor().getChannel(); - long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel); - - // Try to find it in the translation tables: - for (int j=0; j x = translator.getIntegersByHash(hash); - data.getDescriptor().setSectorLayerComponent(sector, layer, component); - data.getDescriptor().setOrder(order); - data.getDescriptor().setType(keysTrans.get(j)); - - for(int i = 0; i < data.getADCSize(); i++) data.getADCData(i).setOrder(order); - for(int i = 0; i < data.getTDCSize(); i++) data.getTDCData(i).setOrder(order); - - // Assume there's only one instance of this crate/slot/channel - // in all translation tables, and we found it, so stop: - break; - } + // Set the translated detector indexing: + d.getDescriptor().setSectorLayerComponentOrderType(x.get(0),x.get(1),x.get(2),x.get(3),x.get(4)); + for (int i=0; i detectorData){ IndexedTable daq = tables.get(j); DetectorType type = keysFitter.get(j); //custom MM fitter - if( ( (type == DetectorType.BMT)&&(data.getDescriptor().getType().getName().equals("BMT")) ) - || ( (type == DetectorType.FMT)&&(data.getDescriptor().getType().getName().equals("FMT")) ) - //|| ( (type == DetectorType.AHDC)&&(data.getDescriptor().getType().getName().equals("AHDC")) ) - || ( (type == DetectorType.FTTRK)&&(data.getDescriptor().getType().getName().equals("FTTRK")) ) ){ + if (data.getDescriptor().getType() == type && keysMicromega.contains(keysFitter.get(j))) { short adcOffset = (short) daq.getDoubleValueByHash("adc_offset", hash0); double fineTimeStampResolution = (byte) daq.getDoubleValueByHash("dream_clock", hash0); double samplingTime = (byte) daq.getDoubleValueByHash("sampling_time", hash0); @@ -222,7 +206,7 @@ public void fitPulses(List detectorData){ int nsb = daq.getIntValueByHash("nsb", hash); int tet = daq.getIntValueByHash("tet", hash); int ped = 0; - if(type == DetectorType.RF&&data.getDescriptor().getType().getName().equals("RF")) { + if(data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) { ped = daq.getIntValueByHash("pedestal", hash); } if(data.getADCSize()>0){ 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 index 9958969083..da1c3512b4 100644 --- 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 @@ -1,8 +1,9 @@ package org.jlab.detector.decode; +import java.util.stream.Collectors; +import org.jlab.utils.groups.IndexedTable; import org.jlab.detector.base.DetectorType; import org.jlab.detector.calib.utils.ConstantsManager; -import org.jlab.utils.groups.IndexedTable; /** * @@ -24,6 +25,7 @@ public void add(DetectorType dt, IndexedTable it) { int slot = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 1); int channel = IndexedTable.DEFAULT_GENERATOR.getIndex(hash, 2); + // first one wins, print error message for loser: 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", @@ -36,10 +38,8 @@ public void add(DetectorType dt, IndexedTable it) { addEntry(crate, slot, channel); // add each column's entry to the new row: - for (int column=0; column getPulses(int n, IndexedTable it, DataBank wfBank) { diff --git a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedList.java b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedList.java index e23f799f83..6dce281502 100644 --- a/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedList.java +++ b/common-tools/clas-utils/src/main/java/org/jlab/utils/groups/IndexedList.java @@ -326,11 +326,23 @@ public int getIndex(long hashcode, int order) { return (int) ((hashcode >> this.byteShifts[order]) & mask); } + /** + * Retrieves an array of the requested indices. + * + * @param indices + * @return + */ + public int[] getIndices(long hashcode, int... indices) { + int[] ret = new int[indices.length]; + for (int i=0; i