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/CodaDecoders.java b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaDecoders.java new file mode 100644 index 0000000000..9a46c55844 --- /dev/null +++ b/common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CodaDecoders.java @@ -0,0 +1,922 @@ +package org.jlab.detector.decode; + +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.jlab.coda.jevio.CompositeData; +import org.jlab.coda.jevio.DataType; +import org.jlab.coda.jevio.EvioException; +import org.jlab.coda.jevio.EvioNode; +import org.jlab.detector.decode.DetectorDataDgtz.ADCData; +import org.jlab.detector.decode.DetectorDataDgtz.TDCData; +import org.jlab.io.evio.EvioDataEvent; +import org.jlab.io.evio.EvioTreeBranch; +import org.jlab.utils.data.DataUtils; + +/** + * All static methods from CodaEventDecoder. + * + * @author baltzell + */ +public class CodaDecoders { + + /** + * Returns an array of the branches in the event. + * @param event + * @return + */ + public static List getEventBranches(EvioDataEvent event){ + ArrayList branches = new ArrayList<>(); + try { + List eventNodes = event.getStructureHandler().getNodes(); + if (eventNodes==null) { + return branches; + } + for (EvioNode node : eventNodes){ + EvioTreeBranch eBranch = new EvioTreeBranch(node.getTag(),node.getNum()); + List childNodes = node.getChildNodes(); + if (childNodes!=null){ + for (EvioNode child : childNodes){ + eBranch.addNode(child); + } + branches.add(eBranch); + } + } + } catch (EvioException ex) { + Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } + return branches; + } + + public static void printByteBuffer(ByteBuffer buffer, int max, int columns){ + int n = max; + if(buffer.capacity() + * + * c "slot number" + * m "number of channels fired" + * c "channel number" + * m "number of shorts in packed array" + * s "packed fadc data" + * + * + */ + public static void decodeComposite(ByteBuffer buffer, int offset, List ctypes, List citems){ + int position = offset; + int length = buffer.capacity(); + try { + while(position<(length-3)){ + Short slot = (short) (0x00FF&(buffer.get(position))); + position++; + citems.add(slot); + ctypes.add(DataType.SHORT16); + Short counter = (short) (0x00FF&(buffer.get(position))); + citems.add(counter); + ctypes.add(DataType.NVALUE); + position++; + + for(int i = 0; i < counter; i++){ + Short channel = (short) (0x00FF&(buffer.get(position))); + position++; + citems.add(channel); + ctypes.add(DataType.SHORT16); + Short ndata = (short) (0x00FF&(buffer.get(position))); + position++; + citems.add(ndata); + ctypes.add(DataType.NVALUE); + for(int b = 0; b < ndata; b++){ + Short data = buffer.getShort(position); + position+=2; + citems.add(data); + ctypes.add(DataType.SHORT16); + } + } + } + } catch (Exception e){ + System.out.println("Exception : Length = " + length + " position = " + position); + } + } + + /** + * SVT decoding + * @param crate + * @param node + * @param event + * @return + */ + public static ArrayList getDataEntries_57617(Integer crate, EvioNode node, EvioDataEvent event){ + + ArrayList rawdata = new ArrayList<>(); + + if(node.getTag()==57617){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + List cdataitems = compData.getItems(); + int totalSize = cdataitems.size(); + int position = 0; + while( (position + 4) < totalSize){ + Byte slot = (Byte) cdataitems.get(position); + //Integer trig = (Integer) cdataitems.get(position+1); + Long time = (Long) cdataitems.get(position+2); + Integer nchannels = (Integer) cdataitems.get(position+3); + int counter = 0; + position = position + 4; + while(counter ERROR DECODING COMPOSITE DATA FOR ONE EVENT"); + } + } + return rawdata; + } + + /** + * Bank TAG=57657 used for ATOF PETIROC TDC values + * @param crate + * @param node + * @param event + * @return + * + * + * + * c "slot number" + * i "trigger number" + * l "time stamp" + * N "number of channels fired" + * c "channel number" + * i "tdc value" + * i "width value" + * + * + */ + public static List getDataEntries_57657(Integer crate, EvioNode node, EvioDataEvent event) { + + ArrayList entries = new ArrayList<>(); + + if(node.getTag()==57657){ + try { + //System.err.println("Decoding ATOF PETIROC event!"); + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + while(position -> "bank" DetectorDataDgtz -> "tdc" TDCData + // there is a redundancy in timestamp: the same value is stored in TDCData and the DetectorDataDgz + // + bank.setTimeStamp(time_stamp); + bank.setTrigger(trig_num);; + TDCData tdc_data = new TDCData(tdc, tot); + tdc_data.setTimeStamp(time_stamp).setOrder(counter); + bank.addTDC(tdc_data); + entries.add(bank); + position += 3; // channel,tdc,tot + counter++; + //System.err.println("event: " + bank.toString()); + } + } + + return entries; + } catch (EvioException ex) { + Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } + } + return entries; + } + + /** + * Bank TAG=57636 used for RICH TDC values + * @param crate + * @param node + * @param event + * @return + */ + public static List getDataEntries_57636(Integer crate, EvioNode node, EvioDataEvent event){ + + ArrayList entries = new ArrayList<>(); + + if(node.getTag()==57636){ + try { + + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + while(position>15)&0x1; + int tdc = rawtdc&0x7FFF; + + DetectorDataDgtz bank = new DetectorDataDgtz(crate,slot.intValue(),2*(fiber*192+channel)+edge); + bank.addTDC(new TDCData(tdc)); + + entries.add(bank); + position += 3; + counter++; + } + } + + return entries; + } catch (EvioException ex) { + Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } + } + return entries; + } + + /** + * Bank TAG=57648 used for DC (Drift Chambers) TDC and ToT values. + * @param crate + * @param node + * @param event + * @return + */ + public static List getDataEntries_57648(Integer crate, EvioNode node, EvioDataEvent event){ + List entries = new ArrayList<>(); + if(node.getTag()==57648){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + //List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + int totalSize = cdataitems.size(); + int position = 0; + while( (position + 4) < totalSize){ + Byte slot = (Byte) cdataitems.get(position); + //Integer trig = (Integer) cdataitems.get(position+1); + Long time = (Long) cdataitems.get(position+2); + Integer nchannels = (Integer) cdataitems.get(position+3); + int counter = 0; + position = position + 4; + while(counter getDataEntries_57622(Integer crate, EvioNode node, EvioDataEvent event){ + List entries = new ArrayList<>(); + if(node.getTag()==57622){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + //List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + int totalSize = cdataitems.size(); + int position = 0; + while( (position + 4) < totalSize){ + Byte slot = (Byte) cdataitems.get(position); + //Integer trig = (Integer) cdataitems.get(position+1); + Long time = (Long) cdataitems.get(position+2); + Integer nchannels = (Integer) cdataitems.get(position+3); + int counter = 0; + position = position + 4; + while(counter +//             +//                  c     "slot number" (8bit) +//                  i     "trigger number" (32bit) +//                  l     "time stamp" (64bit) +//                  N     "number of channels fired" (32bit) +//                  c     "channel number" (8bit) +//                  N     "number of pulses" (32bit) +//                  s     "tdc value" (16bit) +//                  i     "adc value" (32bit) +//             +//       + public static List getDataEntries_57603(Integer crate, EvioNode node, EvioDataEvent event){ + List entries = new ArrayList<>(); + if(node.getTag()==57603){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + while((position+4) getDataEntries_57602(Integer crate, EvioNode node, EvioDataEvent event){ + List entries = new ArrayList<>(); + if(node.getTag()==57602){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + while((position+4) getDataEntries_57641(Integer crate, EvioNode node, EvioDataEvent event){ + // Micromegas packed data + // ---------------------- + + ArrayList entries = new ArrayList<>(); + if(node.getTag()==57641){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + int jdata = 0; // item counter + for( int i = 0 ; i < cdatatypes.size(); ) { // loop over data types + + Byte SLOT = (Byte)cdataitems.get( jdata++ ); i++; + Integer EV_ID = (Integer)cdataitems.get( jdata++ ); i++; + Long TIMESTAMP = (Long)cdataitems.get( jdata++ ); i++; + Short nChannels = (Short)cdataitems.get( jdata++ ); i++; + + for( int ch=0; ch>4)<<8; + } + } + i++; + + ADCData adcData = new ADCData(); + adcData.setTimeStamp(TIMESTAMP); + adcData.setPulse(samples); + adcData.setTime(firstChannel); + bank.addADC(adcData); + + entries.add(bank); + } + } // end loop on channels + } // end loop on data types + return entries; + + } catch (EvioException ex) { + Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } + } + return entries; + } + + /** + * Decoding MicroMegas Packed Data + * @param crate + * @param node + * @param event + * @return + */ + public static List getDataEntries_57640(Integer crate, EvioNode node, EvioDataEvent event){ + // Micromegas packed data + // ---------------------- + + ArrayList entries = new ArrayList<>(); + if(node.getTag()==57640){ + try { + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + int jdata = 0; // item counter + for( int i = 0 ; i < cdatatypes.size(); ) { // loop over data types + + Byte CRATE = (Byte)cdataitems.get( jdata++ ); i++; + Integer EV_ID = (Integer)cdataitems.get( jdata++ ); i++; + Long TIMESTAMP = (Long)cdataitems.get( jdata++ ); i++; + Short nChannels = (Short)cdataitems.get( jdata++ ); i++; + + for( int ch=0; ch>4)<<8; + } + + } + i++; + + ADCData adcData = new ADCData(); + adcData.setTimeStamp(TIMESTAMP); + adcData.setPulse(samples); + bank.addADC(adcData); + entries.add(bank); + } // end loop on channels + } // end loop on data types + return entries; + + } catch (EvioException ex) { + Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } + } + return entries; + } + + public static List getDataEntries_57627(Integer crate, EvioNode node, EvioDataEvent event){ + + ArrayList entries = new ArrayList<>(); + + if(node.getTag()==57627){ + try { + + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + + while(position getDataEntries_57638(Integer crate, EvioNode node, EvioDataEvent event){ + List entries = new ArrayList<>(); + if(node.getTag()==57638){ + ByteBuffer compBuffer = node.getByteData(true); + List cdatatypes = new ArrayList<>(); + List cdataitems = new ArrayList<>(); + decodeComposite(compBuffer, 24, cdatatypes, cdataitems); + + int position = 0; + + while(position18) entries.add(data); + } + } + } + return entries; + } + + /** + * decoding bank in Mode 1 - full ADC pulse. + * @param crate + * @param node + * @param event + * @return + */ + public static List getDataEntries_57601(Integer crate, EvioNode node, EvioDataEvent event){ + + ArrayList entries = new ArrayList<>(); + + if(node.getTag()==57601){ + try { + + ByteBuffer compBuffer = node.getByteData(true); + CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); + + List cdatatypes = compData.getTypes(); + List cdataitems = compData.getItems(); + + if(cdatatypes.get(3) != DataType.NVALUE){ + System.err.println("[EvioRawDataSource] ** error ** corrupted " + + " bank. tag = " + node.getTag() + " num = " + node.getNum()); + return null; + } + + int position = 0; + + while(position>>> EVENT SIZE EXCEEDS 600 kB"); - // return new ArrayList(); - //} - - // zero out the trigger bits, but let the others properties inherit - // 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){ - List list = this.getDataEntries(event,branch.getTag()); - if(list != null){ - rawEntries.addAll(list); - } - } - List tdcEntries = this.getDataEntries_TDC(event); - rawEntries.addAll(tdcEntries); - List vtpEntries = this.getDataEntries_VTP(event); - rawEntries.addAll(vtpEntries); - List scalerEntries = this.getDataEntries_Scalers(event); - rawEntries.addAll(scalerEntries); - - this.getDataEntries_EPICS(event); - - return rawEntries; - } + public CodaEventDecoder(){} public JsonObject getEpicsData(){ return this.epicsData; @@ -97,17 +50,6 @@ public List getTriggerWords(){ return this.triggerWords; } - private void printByteBuffer(ByteBuffer buffer, int max, int columns){ - int n = max; - if(buffer.capacity() tiEntries = this.getDataEntries_TI(event); - - if(tiEntries.size()==1) { - ts = tiEntries.get(0).getTimeStamp(); - } - else if(tiEntries.size()>1) { - // check sychronization - boolean tiSync=true; - int i0 = -1; - // set reference timestamp from first entry which is not the tiMaster nor PCIE: - for(int i=0; ideltaTS) { - tiSync=false; - if(this.timeStampErrors<100) { - System.err.println("WARNING: mismatch in TI time stamps: crate " - + tiEntries.get(i).getDescriptor().getCrate() + " reports " - + tiEntries.get(i).getTimeStamp() + " instead of the " + tiEntries.get(i0).getTimeStamp() - + " from crate " + tiEntries.get(i0).getDescriptor().getCrate()); - } - else if(this.timeStampErrors==100) { - System.err.println("WARNING: reached the maximum number of timeStamp errors (100), supressing future warnings."); - } - this.timeStampErrors++; - } - } - if(tiSync) ts = tiEntries.get(i0).getTimeStamp(); - } - this.timeStamp = ts ; - } - - public long getTriggerBits() { - return triggerBits; - } - - public void setTriggerBits(long triggerBits) { - this.triggerBits = triggerBits; - } - - public List getADCEntries(EvioDataEvent event){ - List entries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ - List list = this.getADCEntries(event,branch.getTag()); - if(list != null){ - entries.addAll(list); - } - } - return entries; - } - - public List getADCEntries(EvioDataEvent event, int crate){ - List entries = new ArrayList<>(); - - List branches = this.getEventBranches(event); - EvioTreeBranch cbranch = this.getEventBranch(branches, 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); - if(cbranch == null ) return null; - - for(EvioNode node : cbranch.getNodes()){ - if(node.getTag()==tagid){ - // This is regular integrated pulse mode, used for FTOF - // FTCAL and EC/PCAL - return this.getADCEntries_Tag(crate, node, event,tagid); - } - } - return adc; - } - - /** - * returns list of decoded data in the event for given crate. - * @param event - * @param crate - * @return - */ - public List getDataEntries(EvioDataEvent event, int crate){ - - List branches = this.getEventBranches(event); - List bankEntries = new ArrayList<>(); - - EvioTreeBranch cbranch = this.getEventBranch(branches, crate); - if(cbranch == null ) return null; - - for (EvioNode node : cbranch.getNodes()) { - if (node.getTag() == 57615) { - // This is regular integrated pulse mode, used for FTOF - // FTCAL and EC/PCAL - this.tiMaster = crate; - this.readHeaderBank(crate, node, event); - } - } - for(EvioNode node : cbranch.getNodes()){ - - if(node.getTag()==57617){ - // This is regular integrated pulse mode, used for FTOF - // FTCAL and EC/PCAL - return this.getDataEntries_57617(crate, node, event); - } - else if(node.getTag()==57603){ - // This is regular integrated pulse mode, used for streaming - return this.getDataEntries_57603(crate, node, event); - } - else if(node.getTag()==57602){ - // This is regular integrated pulse mode, used for FTOF - // FTCAL and EC/PCAL - return this.getDataEntries_57602(crate, node, event); - } - else if(node.getTag()==57601){ - // This is regular integrated pulse mode, used for FTOF - // FTCAL and EC/PCAL - return this.getDataEntries_57601(crate, node, event); - } - else if(node.getTag()==57627){ - // This is regular integrated pulse mode, used for MM - return this.getDataEntries_57627(crate, node, event); - } - else if(node.getTag()==57640){ - // This is bit-packed pulse mode, used for MM - return this.getDataEntries_57640(crate, node, event); - } - else if(node.getTag()==57622){ - // This is regular DCRB bank with TDCs only - return this.getDataEntries_57622(crate, node, event); - } - else if(node.getTag()==57648){ - // This is DCRB bank with TDCs and widths - return this.getDataEntries_57648(crate, node, event); - } - else if(node.getTag()==57636){ - // RICH TDC data - return this.getDataEntries_57636(crate, node, event); - } else if (node.getTag() == 57657) { - // ATOF Petiroc TDC data - return this.getDataEntries_57657(crate, node, event); - } else if (node.getTag() == 57641) { - // RTPC data decoding - return this.getDataEntries_57641(crate, node, event); - } - } - return bankEntries; - } - - /** - * Returns an array of the branches in the event. - * @param event - * @return - */ - public List getEventBranches(EvioDataEvent event){ - ArrayList branches = new ArrayList<>(); - try { - - List eventNodes = event.getStructureHandler().getNodes(); - if(eventNodes==null){ - return branches; - } - - for(EvioNode node : eventNodes){ - EvioTreeBranch eBranch = new EvioTreeBranch(node.getTag(),node.getNum()); - List childNodes = node.getChildNodes(); - if(childNodes!=null){ - for(EvioNode child : childNodes){ - eBranch.addNode(child); - } - branches.add(eBranch); - } - } - - } catch (EvioException ex) { - Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); - } - return branches; - } - /** - * returns branch with with given tag - * @param branches - * @param tag - * @return - */ - public EvioTreeBranch getEventBranch(List branches, int tag){ - for(EvioTreeBranch branch : branches){ - if(branch.getTag()==tag) return branch; - } - return null; - } - - public void readHeaderBank(Integer crate, EvioNode node, EvioDataEvent event){ - - if(node.getDataTypeObj()==DataType.INT32||node.getDataTypeObj()==DataType.UINT32){ - try { - int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); - this.runNumber = intData[3]; - this.eventNumber = intData[4]; - if(intData[5]!=0) this.unixTime = intData[5]; - this.helicityLevel3=HelicityBit.DNE.value(); - if(intData.length>7) { - if ( (intData[7] & 0x1) == 0) { - this.helicityLevel3=HelicityBit.UDF.value(); - } - else if ((intData[7]>>1 & 0x1) == 0) { - this.helicityLevel3=HelicityBit.MINUS.value(); - } - else { - this.helicityLevel3=HelicityBit.PLUS.value(); - } - } - } catch (Exception e) { - this.runNumber = 10; - this.eventNumber = 1; - } - } else { - System.out.println("[error] can not read header bank"); - } - } - - /** - * SVT decoding - * @param crate - * @param node - * @param event - * @return - */ - public ArrayList getDataEntries_57617(Integer crate, EvioNode node, EvioDataEvent event){ - - ArrayList rawdata = new ArrayList<>(); - - if(node.getTag()==57617){ - try { - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - List cdataitems = compData.getItems(); - int totalSize = cdataitems.size(); - int position = 0; - while( (position + 4) < totalSize){ - Byte slot = (Byte) cdataitems.get(position); - //Integer trig = (Integer) cdataitems.get(position+1); - Long time = (Long) cdataitems.get(position+2); - Integer nchannels = (Integer) cdataitems.get(position+3); - int counter = 0; - position = position + 4; - while(counter ERROR DECODING COMPOSITE DATA FOR ONE EVENT"); - } - } - return rawdata; - } - - public List getADCEntries_Tag(Integer crate, EvioNode node, EvioDataEvent event, int tagid){ - List entries = new ArrayList<>(); - if(node.getTag()==tagid){ - try { - - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - - List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - if(cdatatypes.get(3) != DataType.NVALUE){ - System.err.println("[EvioRawDataSource] ** error ** corrupted " - + " bank. tag = " + node.getTag() + " num = " + node.getNum()); - return null; - } - - int position = 0; - - while(position - * - * c "slot number" - * m "number of channels fired" - * c "channel number" - * m "number of shorts in packed array" - * s "packed fadc data" - * - * - */ - public void decodeComposite(ByteBuffer buffer, int offset, List ctypes, List citems){ - int position = offset; - int length = buffer.capacity(); - try { - while(position<(length-3)){ - Short slot = (short) (0x00FF&(buffer.get(position))); - position++; - citems.add(slot); - ctypes.add(DataType.SHORT16); - Short counter = (short) (0x00FF&(buffer.get(position))); - citems.add(counter); - ctypes.add(DataType.NVALUE); - position++; - - for(int i = 0; i < counter; i++){ - Short channel = (short) (0x00FF&(buffer.get(position))); - position++; - citems.add(channel); - ctypes.add(DataType.SHORT16); - Short ndata = (short) (0x00FF&(buffer.get(position))); - position++; - citems.add(ndata); - ctypes.add(DataType.NVALUE); - for(int b = 0; b < ndata; b++){ - Short data = buffer.getShort(position); - position+=2; - citems.add(data); - ctypes.add(DataType.SHORT16); - } - } - } - } catch (Exception e){ - System.out.println("Exception : Length = " + length + " position = " + position); - } - } - - public List getDataEntries_57638(Integer crate, EvioNode node, EvioDataEvent event){ - List entries = new ArrayList<>(); - if(node.getTag()==57638){ - ByteBuffer compBuffer = node.getByteData(true); - List cdatatypes = new ArrayList<>(); - List cdataitems = new ArrayList<>(); - this.decodeComposite(compBuffer, 24, cdatatypes, cdataitems); - - int position = 0; - - while(position18) entries.add(data); - } - } - } - return entries; - } - - /** - * decoding bank in Mode 1 - full ADC pulse. - * @param crate - * @param node - * @param event - * @return - */ - public List getDataEntries_57601(Integer crate, EvioNode node, EvioDataEvent event){ - - ArrayList entries = new ArrayList<>(); - - if(node.getTag()==57601){ - try { - - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - - List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - if(cdatatypes.get(3) != DataType.NVALUE){ - System.err.println("[EvioRawDataSource] ** error ** corrupted " - + " bank. tag = " + node.getTag() + " num = " + node.getNum()); - return null; - } - - int position = 0; - - while(position -//             -//                  c     "slot number" (8bit) -//                  i     "trigger number" (32bit) -//                  l     "time stamp" (64bit) -//                  N     "number of channels fired" (32bit) -//                  c     "channel number" (8bit) -//                  N     "number of pulses" (32bit) -//                  s     "tdc value" (16bit) -//                  i     "adc value" (32bit) -//             -//       - public List getDataEntries_57603(Integer crate, EvioNode node, EvioDataEvent event){ - List entries = new ArrayList<>(); - if(node.getTag()==57603){ - try { - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - - List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - if(cdatatypes.get(3) != DataType.NVALUE){ - System.err.println("[EvioRawDataSource] ** error ** corrupted " - + " bank. tag = " + node.getTag() + " num = " + node.getNum()); - return null; - } - - int position = 0; - while((position+4) getDataEntries_57622(Integer crate, EvioNode node, EvioDataEvent event){ - List entries = new ArrayList<>(); - if(node.getTag()==57622){ - try { - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - //List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - int totalSize = cdataitems.size(); - int position = 0; - while( (position + 4) < totalSize){ - Byte slot = (Byte) cdataitems.get(position); - //Integer trig = (Integer) cdataitems.get(position+1); - Long time = (Long) cdataitems.get(position+2); - Integer nchannels = (Integer) cdataitems.get(position+3); - int counter = 0; - position = position + 4; - while(counter(); + for (EvioTreeBranch branch : CodaDecoders.getEventBranches(event)) + if (!branchMap.containsKey(branch.getTag())) + branchMap.put(branch.getTag(), branch); } /** - * Bank TAG=57648 used for DC (Drift Chambers) TDC and ToT values. - * @param crate - * @param node + * returns detector digitized data entries from the event. + * all branches are analyzed and different types of digitized data + * is created for each type of ADC and TDC data. * @param event * @return */ - public List getDataEntries_57648(Integer crate, EvioNode node, EvioDataEvent event){ - List entries = new ArrayList<>(); - if(node.getTag()==57648){ - try { - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - //List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); + public List getDataEntries(EvioDataEvent event){ - int totalSize = cdataitems.size(); - int position = 0; - while( (position + 4) < totalSize){ - Byte slot = (Byte) cdataitems.get(position); - //Integer trig = (Integer) cdataitems.get(position+1); - Long time = (Long) cdataitems.get(position+2); - Integer nchannels = (Integer) cdataitems.get(position+3); - int counter = 0; - position = position + 4; - while(counter600*1024){ + // System.out.println("error: >>>> EVENT SIZE EXCEEDS 600 kB"); + // return new ArrayList(); + //} + + // zero out the trigger bits, but let the others properties inherit + // from the previous event, in the case where there's no HEAD bank: + this.setTriggerBits(0); + List rawEntries = new ArrayList<>(); + this.setTimeStamp(event); + for(EvioTreeBranch branch : branchMap.values()){ + List list = this.getDataEntries(event,branch.getTag()); + if(list != null){ + rawEntries.addAll(list); } - } - return entries; + List tdcEntries = this.getDataEntries_TDC(event); + rawEntries.addAll(tdcEntries); + List vtpEntries = this.getDataEntries_VTP(event); + rawEntries.addAll(vtpEntries); + List scalerEntries = this.getDataEntries_Scalers(event); + rawEntries.addAll(scalerEntries); + + this.getDataEntries_EPICS(event); + + return rawEntries; } /** - * Bank TAG=57636 used for RICH TDC values - * @param crate - * @param node + * returns list of decoded data in the event for given crate. * @param event + * @param crate * @return */ - public List getDataEntries_57636(Integer crate, EvioNode node, EvioDataEvent event){ - - ArrayList entries = new ArrayList<>(); - - if(node.getTag()==57636){ - try { - - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - - List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - if(cdatatypes.get(3) != DataType.NVALUE){ - System.err.println("[EvioRawDataSource] ** error ** corrupted " - + " bank. tag = " + node.getTag() + " num = " + node.getNum()); - return null; - } - - int position = 0; - while(position getDataEntries(EvioDataEvent event, int crate){ + List bankEntries = new ArrayList<>(); + EvioTreeBranch cbranch = branchMap.getOrDefault(crate, null); + if(cbranch == null ) return null; + for (EvioNode node : cbranch.getNodes()) { + if (node.getTag() == 57615) { + this.tiMaster = crate; + this.readHeaderBank(crate, node, event); + } + } + for(EvioNode node : cbranch.getNodes()){ + switch (node.getTag()) { + case 57617: + // This is regular integrated pulse mode, used for FTOF/FTCAL/ECAL + return CodaDecoders.getDataEntries_57617(crate, node, event); + case 57603: + // This is regular integrated pulse mode, used for streaming + return CodaDecoders.getDataEntries_57603(crate, node, event); + case 57602: + // This is regular integrated pulse mode, used for FTOF/FTCAL/ECAL + return CodaDecoders.getDataEntries_57602(crate, node, event); + case 57601: + // This is regular integrated pulse mode, used for FTOF/FTCAL/ECAL + return CodaDecoders.getDataEntries_57601(crate, node, event); + case 57627: + // This is regular integrated pulse mode, used for MM + return CodaDecoders.getDataEntries_57627(crate, node, event); + case 57640: + // This is bit-packed pulse mode, used for MM + return CodaDecoders.getDataEntries_57640(crate, node, event); + case 57622: + // This is regular DCRB bank with TDCs only + return CodaDecoders.getDataEntries_57622(crate, node, event); + case 57648: + // This is DCRB bank with TDCs and widths + return CodaDecoders.getDataEntries_57648(crate, node, event); + case 57636: + // RICH TDC data + return CodaDecoders.getDataEntries_57636(crate, node, event); + case 57657: + // ATOF Petiroc TDC data + return CodaDecoders.getDataEntries_57657(crate, node, event); + case 57641: + // RTPC data decoding + return CodaDecoders.getDataEntries_57641(crate, node, event); + default: + break; + } + } + return bankEntries; + } - while(counter>15)&0x1; - int tdc = rawtdc&0x7FFF; + private void setTimeStamp(EvioDataEvent event) { - DetectorDataDgtz bank = new DetectorDataDgtz(crate,slot.intValue(),2*(fiber*192+channel)+edge); - bank.addTDC(new TDCData(tdc)); + long ts = -1; - entries.add(bank); - position += 3; - counter++; + List tiEntries = this.getDataEntries_TI(event); + + if(tiEntries.size()==1) { + ts = tiEntries.get(0).getTimeStamp(); + } + else if(tiEntries.size()>1) { + // check sychronization + boolean tiSync=true; + int i0 = -1; + // set reference timestamp from first entry which is not the tiMaster nor PCIE: + for(int i=0; ideltaTS) { + tiSync=false; + if(this.timeStampErrors<100) { + System.err.println("WARNING: mismatch in TI time stamps: crate " + + tiEntries.get(i).getDescriptor().getCrate() + " reports " + + tiEntries.get(i).getTimeStamp() + " instead of the " + tiEntries.get(i0).getTimeStamp() + + " from crate " + tiEntries.get(i0).getDescriptor().getCrate()); } + else if(this.timeStampErrors==100) { + System.err.println("WARNING: reached the maximum number of timeStamp errors (100), supressing future warnings."); + } + this.timeStampErrors++; } - - return entries; - } catch (EvioException ex) { - Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); } + if(tiSync) ts = tiEntries.get(i0).getTimeStamp(); } - return entries; + this.timeStamp = ts ; } - /** - * Bank TAG=57657 used for ATOF PETIROC TDC values - * @param crate - * @param node - * @param event - * @return - * - * - * - * c "slot number" - * i "trigger number" - * l "time stamp" - * N "number of channels fired" - * c "channel number" - * i "tdc value" - * i "width value" - * - * - */ - public List getDataEntries_57657(Integer crate, EvioNode node, EvioDataEvent event){ + private void readHeaderBank(Integer crate, EvioNode node, EvioDataEvent event){ - ArrayList entries = new ArrayList<>(); - - if(node.getTag()==57657){ + if(node.getDataTypeObj()==DataType.INT32||node.getDataTypeObj()==DataType.UINT32){ try { - //System.err.println("Decoding ATOF PETIROC event!"); - ByteBuffer compBuffer = node.getByteData(true); - CompositeData compData = new CompositeData(compBuffer.array(),event.getByteOrder()); - - List cdatatypes = compData.getTypes(); - List cdataitems = compData.getItems(); - - if(cdatatypes.get(3) != DataType.NVALUE){ - System.err.println("[EvioRawDataSource] ** error ** corrupted " - + " bank. tag = " + node.getTag() + " num = " + node.getNum()); - return null; - } - - int position = 0; - while(position -> "bank" DetectorDataDgtz -> "tdc" TDCData - // there is a redundancy in timestamp: the same value is stored in TDCData and the DetectorDataDgz - // - bank.setTimeStamp(time_stamp); - bank.setTrigger(trig_num);; - TDCData tdc_data = new TDCData(tdc, tot); - tdc_data.setTimeStamp(time_stamp).setOrder(counter); - bank.addTDC(tdc_data); - entries.add(bank); - position += 3; // channel,tdc,tot - counter++; - //System.err.println("event: " + bank.toString()); + int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); + this.runNumber = intData[3]; + this.eventNumber = intData[4]; + if(intData[5]!=0) this.unixTime = intData[5]; + this.helicityLevel3=HelicityBit.DNE.value(); + if(intData.length>7) { + if ( (intData[7] & 0x1) == 0) { + this.helicityLevel3=HelicityBit.UDF.value(); + } + else if ((intData[7]>>1 & 0x1) == 0) { + this.helicityLevel3=HelicityBit.MINUS.value(); + } + else { + this.helicityLevel3=HelicityBit.PLUS.value(); } } - - return entries; - } catch (EvioException ex) { - Logger.getLogger(CodaEventDecoder.class.getName()).log(Level.SEVERE, null, ex); + } catch (Exception e) { + this.runNumber = 10; + this.eventNumber = 1; } + } else { + System.out.println("[error] can not read header bank"); } - return entries; } - - - public void getDataEntries_EPICS(EvioDataEvent event){ + private void getDataEntries_EPICS(EvioDataEvent event){ epicsData = new JsonObject(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ + for(EvioTreeBranch branch : branchMap.values()){ for(EvioNode node : branch.getNodes()){ if(node.getTag()==57620) { byte[] stringData = ByteDataTransformer.toByteArray(node.getStructureBuffer(true)); @@ -1260,8 +295,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 : branchMap.values()){ for(EvioNode node : branch.getNodes()){ if(node.getTag()==57651) { @@ -1338,13 +372,11 @@ public HelicityDecoderData getDataEntries_HelicityDecoder(EvioDataEvent event){ return data; } - public List getDataEntries_Scalers(EvioDataEvent event){ + private List getDataEntries_Scalers(EvioDataEvent event){ List scalerEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ - int crate = branch.getTag(); - for(EvioNode node : branch.getNodes()){ + for(int crate : branchMap.keySet()) { + for(EvioNode node : branchMap.get(crate).getNodes()){ if(node.getTag()==57637 || node.getTag()==57621){ int num = node.getNum(); int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); @@ -1418,13 +450,53 @@ else if(node.getTag()==57621 && loop>=5) { return scalerEntries; } - public List getDataEntries_VTP(EvioDataEvent event){ + /** + * decoding bank that contains TI time stamp. + * @param event + * @return + */ + private List getDataEntries_TI(EvioDataEvent event){ + + List tiEntries = new ArrayList<>(); + for(int crate : branchMap.keySet()) { + for(EvioNode node : branchMap.get(crate).getNodes()){ + if(node.getTag()==57610){ + long[] longData = ByteDataTransformer.toLongArray(node.getStructureBuffer(true)); + int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); + long tStamp = longData[2]&0x0000ffffffffffffL; + + // Below is endian swap if needed + //long ntStamp = (((long)(intData[5]&0x0000ffffL))<<32) | (intData[4]&0xffffffffL); + //System.out.println(longData[2]+" "+tStamp+" "+crate+" "+node.getDataLength()); + + DetectorDataDgtz entry = new DetectorDataDgtz(crate,0,0); + entry.setTimeStamp(tStamp); + if(node.getDataLength()==4) tiEntries.add(entry); + else if(node.getDataLength()==5) { // trigger supervisor crate + this.setTriggerBits(intData[6]); + } + else if(node.getDataLength()==6) { // New format Dec 1 2017 (run 1701) + this.setTriggerBits(intData[6]<<16|intData[7]); + } + else if(node.getDataLength()==7) { // New format Dec 1 2017 (run 1701) + long word = (( (long) intData[7])<<32) | (intData[6]&0xffffffffL); + this.setTriggerBits(word); + this.triggerWords.clear(); + for(int i=6; i<=8; i++) { + this.triggerWords.add(intData[i]); + } + } + } + } + } + + return tiEntries; + } + private List getDataEntries_VTP(EvioDataEvent event){ List vtpEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ - int crate = branch.getTag(); - for(EvioNode node : branch.getNodes()){ + for(int crate : branchMap.keySet()) { + for(EvioNode node : branchMap.get(crate).getNodes()){ if(node.getTag()==57634){ int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); for(int loop = 0; loop < intData.length; loop++){ @@ -1438,21 +510,17 @@ public List getDataEntries_VTP(EvioDataEvent event){ } return vtpEntries; } + /** * reads the TDC values from the bank with tag = 57607, decodes * them and returns a list of digitized detector object. * @param event * @return */ - public List getDataEntries_TDC(EvioDataEvent event){ - + private List getDataEntries_TDC(EvioDataEvent event){ List tdcEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - - for(EvioTreeBranch branch : branches){ - int crate = branch.getTag(); - EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag()); - for(EvioNode node : cbranch.getNodes()){ + for(int crate : branchMap.keySet()) { + for(EvioNode node : branchMap.get(crate).getNodes()){ if(node.getTag()==57607){ int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); for(int loop = 2; loop < intData.length; loop++){ @@ -1470,51 +538,25 @@ public List getDataEntries_TDC(EvioDataEvent event){ return tdcEntries; } + public List getADCEntries(EvioDataEvent event){ + List entries = new ArrayList<>(); + for(EvioTreeBranch branch : branchMap.values()){ + List list = this.getADCEntries(event,branch.getTag()); + if (list != null) entries.addAll(list); + } + return entries; + } - /** - * decoding bank that contains TI time stamp. - * @param event - * @return - */ - public List getDataEntries_TI(EvioDataEvent event){ - - List tiEntries = new ArrayList<>(); - List branches = this.getEventBranches(event); - for(EvioTreeBranch branch : branches){ - int crate = branch.getTag(); - EvioTreeBranch cbranch = this.getEventBranch(branches, branch.getTag()); - for(EvioNode node : cbranch.getNodes()){ - if(node.getTag()==57610){ - long[] longData = ByteDataTransformer.toLongArray(node.getStructureBuffer(true)); - int[] intData = ByteDataTransformer.toIntArray(node.getStructureBuffer(true)); - long tStamp = longData[2]&0x0000ffffffffffffL; - - // Below is endian swap if needed - //long ntStamp = (((long)(intData[5]&0x0000ffffL))<<32) | (intData[4]&0xffffffffL); - //System.out.println(longData[2]+" "+tStamp+" "+crate+" "+node.getDataLength()); - - DetectorDataDgtz entry = new DetectorDataDgtz(crate,0,0); - entry.setTimeStamp(tStamp); - if(node.getDataLength()==4) tiEntries.add(entry); - else if(node.getDataLength()==5) { // trigger supervisor crate - this.setTriggerBits(intData[6]); - } - else if(node.getDataLength()==6) { // New format Dec 1 2017 (run 1701) - this.setTriggerBits(intData[6]<<16|intData[7]); - } - else if(node.getDataLength()==7) { // New format Dec 1 2017 (run 1701) - long word = (( (long) intData[7])<<32) | (intData[6]&0xffffffffL); - this.setTriggerBits(word); - this.triggerWords.clear(); - for(int i=6; i<=8; i++) { - this.triggerWords.add(intData[i]); - } - } - } + private List getADCEntries(EvioDataEvent event, int crate){ + List entries = new ArrayList<>(); + EvioTreeBranch cbranch = branchMap.getOrDefault(crate, null); + if(cbranch == null ) return null; + for(EvioNode node : cbranch.getNodes()){ + if(node.getTag()==57638){ + return CodaDecoders.getDataEntries_57638(crate, node, event); } } - - return tiEntries; + return entries; } public static void main(String[] args){ 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..d01829726a 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 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); - int sector = t.getIntValueByHash(0, hash); - int layer = t.getIntValueByHash(1, hash); - int component = t.getIntValueByHash(2, hash); - int order = t.getIntValueByHash(3, 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){ } for(DetectorDataDgtz data : detectorData){ + if (data.getADCSize() == 0) continue; int crate = data.getDescriptor().getCrate(); int slot = data.getDescriptor().getSlot(); int channel = data.getDescriptor().getChannel(); long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(crate,slot,channel); long hash0 = IndexedTable.DEFAULT_GENERATOR.hashCode(0,0,0); + boolean ismm = keysMicromega.contains(data.getDescriptor().getType()); + for (int j=0; j 0) { - ADCData adc = data.getADCData(0); - mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample); - adc.setHeight((short) (mvtFitter.adcMax)); - adc.setTime((int) (mvtFitter.timeMax)); - adc.setIntegral((int) (mvtFitter.integral)); - adc.setTimeStamp(mvtFitter.timestamp); + ADCData adc = data.getADCData(0); + mvtFitter.fit(adcOffset, fineTimeStampResolution, samplingTime, adc.getPulseArray(), adc.getTimeStamp(), sparseSample); + adc.setHeight((short) (mvtFitter.adcMax)); + adc.setTime((int) (mvtFitter.timeMax)); + adc.setIntegral((int) (mvtFitter.integral)); + adc.setTimeStamp(mvtFitter.timestamp); + // first one wins: + //break; + } + else if(daq.hasEntryByHash(hash)==true){ + int nsa = daq.getIntValueByHash("nsa", hash); + int nsb = daq.getIntValueByHash("nsb", hash); + int tet = daq.getIntValueByHash("tet", hash); + int ped = 0; + if(data.getDescriptor().getType() == DetectorType.RF && type == DetectorType.RF) { + ped = daq.getIntValueByHash("pedestal", hash); } - } else { - if(daq.hasEntryByHash(hash)==true){ - int nsa = daq.getIntValueByHash("nsa", hash); - 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")) { - ped = daq.getIntValueByHash("pedestal", hash); - } - if(data.getADCSize()>0){ - for(int i = 0; i < data.getADCSize(); i++){ - ADCData adc = data.getADCData(i); - if(adc.getPulseSize()>0){ - try { - extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray()); - } catch (Exception e) { - System.out.println(">>>> error : fitting pulse " - + crate + " / " + slot + " / " + channel); - } - int adc_corrected = extendedFitter.adc + extendedFitter.ped*(nsa+nsb); - adc.setHeight((short) this.extendedFitter.pulsePeakValue); - adc.setIntegral(adc_corrected); - adc.setTimeWord(this.extendedFitter.t0); - adc.setPedestal((short) this.extendedFitter.ped); - } - } - } - if(data.getADCSize()>0){ - for(int i = 0; i < data.getADCSize(); i++){ - data.getADCData(i).setADC(nsa, nsb); + for(int i = 0; i < data.getADCSize(); i++){ + ADCData adc = data.getADCData(i); + if(adc.getPulseSize()>0){ + try { + extendedFitter.fit(nsa, nsb, tet, ped, adc.getPulseArray()); + } catch (Exception e) { + System.out.println(">>>> error : fitting pulse " + + crate + " / " + slot + " / " + channel); } + int adc_corrected = extendedFitter.adc + extendedFitter.ped*(nsa+nsb); + adc.setHeight((short) this.extendedFitter.pulsePeakValue); + adc.setIntegral(adc_corrected); + adc.setTimeWord(this.extendedFitter.t0); + adc.setPedestal((short) this.extendedFitter.ped); } + data.getADCData(i).setADC(nsa, nsb); } + // first one wins: + //break; } } } } - public void filterTDCs(List detectorData){ int maxMultiplicity = 1; for(DetectorType type : keysFilter){ 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-io/src/main/java/org/jlab/utils/HipoDiff.java b/common-tools/clas-io/src/main/java/org/jlab/utils/HipoDiff.java index e0341362dd..2675d84a7c 100644 --- a/common-tools/clas-io/src/main/java/org/jlab/utils/HipoDiff.java +++ b/common-tools/clas-io/src/main/java/org/jlab/utils/HipoDiff.java @@ -1,20 +1,40 @@ package org.jlab.utils; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.jlab.jnp.hipo4.io.HipoReader; import org.jlab.jnp.hipo4.data.Bank; import org.jlab.jnp.hipo4.data.Event; import org.jlab.jnp.hipo4.data.Schema; -import java.util.HashMap; +import org.jlab.jnp.hipo4.data.SchemaFactory; import org.jlab.utils.options.OptionParser; public class HipoDiff { + static int nrow = 0; + static int nevent = -1; + static int nentry = 0; + static int nbadevent = 0; + static int nbadrow = 0; + static int nbadentry = 0; + static double tolerance; + static boolean verboseMode = false; + static boolean quietMode = false; + static Bank runConfigBank = null; + static SchemaFactory schemaFactory = null; + static ArrayList banksA = new ArrayList<>(); + static ArrayList banksB = new ArrayList<>(); + static HashMap> badEntries = new HashMap<>(); + public static void main(String args[]) { OptionParser op = new OptionParser("hipo-diff"); op.addOption("-t", "0.00001", "absolute tolerance for comparisons"); op.addOption("-n", "-1", "number of events"); - op.addRequired("-b", "name of bank to diff"); + op.addOption("-q", null, "quiet mode"); + op.addOption("-Q", null, "verbose mode"); + op.addOption("-b", null,"name of bank to diff"); op.setRequiresInputList(true); op.parse(args); if (op.getInputList().size() != 2) { @@ -23,110 +43,37 @@ public static void main(String args[]) { System.exit(1); } - final String bankName = op.getOption("-b").stringValue(); - final double tolerance = op.getOption("-t").doubleValue(); + verboseMode = op.getOption("-Q").stringValue() != null; + quietMode = op.getOption("-q").stringValue() != null; final int nmax = op.getOption("-n").intValue(); + tolerance = op.getOption("-t").doubleValue(); HipoReader readerA = new HipoReader(); HipoReader readerB = new HipoReader(); readerA.open(op.getInputList().get(0)); readerB.open(op.getInputList().get(1)); - - Schema schema = readerA.getSchemaFactory().getSchema(bankName); - Bank bankA = new Bank(schema); - Bank bankB = new Bank(schema); - - Bank runConfigBank = new Bank(readerA.getSchemaFactory().getSchema("RUN::config")); - Event event = new Event(); - - int nevent = -1; - int nrow = 0; - int nentry = 0; - int nbadevent = 0; - int nbadrow = 0; - int nbadentry = 0; - HashMap badEntries = new HashMap<>(); - - while (readerA.hasNext() && readerB.hasNext() && (nmax<1 || nevent tolerance) { - element = j; - values += bankA.getFloat(name, i) + "/" + bankB.getFloat(name, i); - } - break; - } - if (element >= 0) { - System.out.println("mismatch at event " + runConfigBank.getInt("event", 0) - + " in row " + i - + " for variable " + name - + " with values " + values); - mismatch = true; - nbadentry++; - if (badEntries.containsKey(schema.getElementName(element))) { - int nbad = badEntries.get(schema.getElementName(element)) + 1; - badEntries.replace(schema.getElementName(element), nbad); - } else { - badEntries.put(schema.getElementName(element), 1); - } - } - } - if (mismatch) { - nbadrow++; - } - } - } + while (readerA.hasNext() && readerB.hasNext() && (nmax < 1 || nevent < nmax)) { + if (++nevent % 10000 == 0) System.out.println("Analyzed " + nevent + " events"); + readerA.nextEvent(eventA); + readerB.nextEvent(eventB); + eventA.read(runConfigBank); + compare(eventA, eventB); } System.out.println("\n Analyzed " + nevent + " with " + nbadevent + " bad banks"); System.out.println(nbadrow + "/" + nrow + " mismatched rows"); @@ -134,9 +81,88 @@ public static void main(String args[]) { for (String name : badEntries.keySet()) { System.out.println(name + " " + badEntries.get(name)); } + System.exit(nbadevent + nbadrow + nbadentry); + } - if (nbadevent + nbadrow + nbadentry > 0) { - System.exit(7); + public static void compare(Event a, Event b) { + for (int i=0; i tolerance) { + element = j; + values += a.getFloat(name, i) + "/" + b.getFloat(name, i); + } + break; + } + if (element >= 0) { + if (verboseMode) { + System.out.println("Bank.show "+a.getSchema().getName()); + a.show(); + b.show(); + } + if (!quietMode) { + System.out.println(a.getSchema().getName()+" mismatch at event " + runConfigBank.getInt("event", 0) + + " in row " + i + " for variable " + name + " with values " + values); + } + mismatch = true; + nbadentry++; + String bankName = a.getSchema().getName(); + String elementName = a.getSchema().getElementName(element); + if (!badEntries.containsKey(bankName)) badEntries.put(bankName, new HashMap<>()); + Map m = badEntries.get(bankName); + if (!m.containsKey(elementName)) m.put(elementName, 0); + m.put(elementName, m.get(elementName)+1); + } + } + if (mismatch) nbadrow++; + } } } + } 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