def unpacked(fedData=None, chars=None, skipHtrBlocks=False, skipTrailer=False, bcnDelta=0, utca=None, skipFlavors=[], patternParams={}): assert chars in [False, True], \ "Specify whether to unpack by words or chars." assert skipHtrBlocks or (utca in [False, True]), \ "Specify whether data is uTCA or VME (unless skipping HTR blocks)." header = {} trailer = {} htrBlocks = {} nWord64 = fedData.size()/(8 if chars else 1) iWordPayload0 = 6 if utca else 12 if skipHtrBlocks: iWords = range(iWordPayload0)+[nWord64-1] else: iWords = range(nWord64) if skipTrailer: iWords.pop() for iWord64 in iWords: if chars: offset = 8*iWord64 bytes = [fedData.at(offset+iByte) for iByte in range(8)] word64 = struct.unpack('Q', "".join(bytes))[0] #like above with 'B'*8 rather than 'Q': #b = [ord(fedData.at(offset+iByte)) for iByte in range(8)] else: word64 = fedData.at(iWord64) if iWord64 < iWordPayload0: decode.header(header, iWord64, word64, utca, bcnDelta) elif iWord64 < nWord64-1: for i in range(4): word16 = (word64 >> (16*i)) & 0xffff iWord16 = 4*iWord64+i returnCode = decode.payload(htrBlocks, iWord16=iWord16, word16=word16, word16Counts=header["word16Counts"], utca=utca, bcnDelta=bcnDelta, skipFlavors=skipFlavors, patternParams=patternParams) if returnCode is not None: print " ".join(["WARNING: skipping", "FED %d" % header["FEDid"], "event %d" % header["EvN"], "iWord16 %d" % iWord16, ]) else: if "htrIndex" in htrBlocks: del htrBlocks["htrIndex"] # fixme decode.trailer(trailer, iWord64, word64) # fixme: improve this out = {} out.update(header) out.update(trailer) out.update({"htrBlocks": htrBlocks}) return out
def unpacked_histo(fedData, fedId, nBytesPer, dump): assert fedData assert nBytesPer in [1, 4, 8], "ERROR: invalid nBytes per index (%s)." % str(nBytesPer) header = {} trailer = {} histograms = {} iPayload0 = 4 nWord64 = fedData.size() * nBytesPer // 8 for iWord64 in range(nWord64): word64 = w64(fedData, iWord64, nBytesPer) if 12 <= dump: if not iWord64: print("#iw64 w64") print("%5d" % iWord64, "%016x" % word64) if iWord64 < 2: decode.header(header, iWord64, word64) if iWord64 < iPayload0: for i in range(2): word32 = (word64 >> (32*i)) & 0xffffffff iWord32 = 2 * (iWord64 - 2) + i decode.header_histo(header, iWord32, word32) continue if iWord64 == nWord64 - 1: decode.trailer(trailer, iWord64, word64) continue nWords32PerChannel = 2 + header["nBins"] for i in range(2): word32 = (word64 >> (32*i)) & 0xffffffff iWord32 = 2 * (iWord64 - iPayload0) + i jWord32 = iWord32 % nWords32PerChannel key = iWord32 // nWords32PerChannel if key not in histograms: histograms[key] = {} d = histograms[key] decode.histo(d, jWord32, word32) return {"header": header, "trailer": trailer, "histograms": histograms, "other": {}, "nBytesSW": 8 * nWord64, "nWord16Skipped": 0, }
def CreateLaserCutData(layers): min_x = np.nan min_y = np.nan max_x = np.nan max_y = np.nan for layer in layers: for pieces in layer.pieces: for line in pieces: for point in [line.a, line.b]: min_x = np.nanmin([min_x, point.x]) min_y = np.nanmin([min_y, point.y]) max_x = np.nanmax([max_x, point.x]) max_y = np.nanmax([max_y, point.y]) layer_headers = [] for i, layer in enumerate(layers): layer_headers.append(decode.LayerData( color=layer.color, layer=i, min_power=decode.scale_power(layer.power), max_power=decode.scale_power(layer.power), speed= (layer.speed) * 1000, x_min=0, y_min=0, x_max=int((max_x - min_x) * 1000), y_max=int((max_y - min_y) * 1000))) unpacked_msgs = decode.header(int((max_x - min_x) * 1000), int((max_y - min_y) * 1000), layer_headers) for i, layer in enumerate(layers): unpacked_msgs += layer_headers[i].change_header() for x in layer.pieces: unpacked_msgs +=[decode.MoveAbs.from_values(x=int((x[0].a.x-min_x) * 1000.0), y=int((x[0].a.y - min_y) * 1000.0))] for j in x: unpacked_msgs += [ decode.CutAbs.from_values(x=int((j.b.x - min_x) * 1000.0), y=int((j.b.y - min_y) * 1000.0))] unpacked_msgs += decode.footer(80,80) repacked = [] for i in unpacked_msgs: if isinstance(i, decode.CmdMsg): repacked += i.pack() continue repacked += i return bytearray(decode.scramble(repacked))
def unpacked(fedData=None, nBytesPer=None, headerOnly=False, unpack=True, warn=True, skipWords64=[], patterns=False, dump=-99): assert nBytesPer in [ 1, 4, 8 ], "ERROR: invalid nBytes per index (%s)." % str(nBytesPer) header = { "iWordPayload0": 6, "utca": None, } # modified by decode.header trailer = {} other = {} htrBlocks = {} nWord64Trailer = 1 nWord64 = fedData.size() * nBytesPer / 8 nWord16Skipped = 0 nToSkip = len(set(skipWords64)) skipped64 = [] for jWord64 in range(nWord64): if not unpack: continue word64 = w64(fedData, jWord64, nBytesPer) if jWord64 in skipWords64: skipped64.append(word64) continue iWord64 = jWord64 - len(skipped64) if 9 <= dump: if not iWord64: print "#iw64 w64" print "%5d" % iWord64, "%016x" % word64 if iWord64 < header["iWordPayload0"]: decode.header(header, iWord64, word64) if header.get("uFoV"): nWord64Trailer = 2 # accommodate block trailer iWordTrailer0 = nWord64 - nToSkip - nWord64Trailer elif headerOnly: break elif iWord64 < iWordTrailer0: for i in range(4): word16 = (word64 >> (16 * i)) & 0xffff iWord16 = 4 * iWord64 + i returnCode = decode.payload( htrBlocks, iWord16=iWord16, word16=word16, word16Counts=header["word16Counts"], utca=header["utca"], fedId=header["FEDid"], patterns=patterns, warn=warn, dump=dump) if returnCode is None: continue # ignore VME pad words (zero) if not header["utca"] and iWord64 + 1 == iWordTrailer0: if 4 * header["iWordPayload0"] + sum( header["word16Counts"]) <= iWord16: if not word16: continue nWord16Skipped += 1 if warn: printer.warning(" ".join([ "skipping", "FED %d" % header["FEDid"], "event %d" % header["EvN"], "iWord16 %d" % iWord16, "word16 0x%04x" % word16, ])) else: if "htrIndex" in htrBlocks: del htrBlocks["htrIndex"] # fixme if header["uFoV"] and (iWord64 == nWord64 - nToSkip - 2): decode.block_trailer_ufov1(trailer, iWord64, word64) else: decode.trailer(trailer, iWord64, word64) decode.other(other, skipped64) return { "header": header, "trailer": trailer, "htrBlocks": htrBlocks, "other": other, "nBytesSW": 8 * nWord64, "nWord16Skipped": nWord16Skipped, }
def unpacked(fedData=None, nBytesPer=None, headerOnly=False, warn=True, skipWords64=[], dump=-99, lastNAmcs=0): assert fedData assert nBytesPer in [1, 4, 8], "ERROR: invalid nBytes per index (%s)." % str(nBytesPer) header = {"iWordPayload0": 6, "utca": None, } # modified by decode.header trailer = {} other = {} htrBlocks = {} nWord64Trailer = 1 nWord64 = fedData.size() * nBytesPer // 8 nWord16Skipped = 0 nToSkip = len(set(skipWords64)) skipped64 = [] for jWord64 in range(nWord64): word64 = w64(fedData, jWord64, nBytesPer) if jWord64 in skipWords64: skipped64.append(word64) continue iWord64 = jWord64 - len(skipped64) if 12 <= dump: if not iWord64: print("#iw64 w64") print("%5d" % iWord64, "%016x" % word64) if iWord64 < header["iWordPayload0"]: decode.header(header, iWord64, word64, lastNAmcs) if header.get("uFoV"): nWord64Trailer = 2 # accommodate block trailer iWordTrailer0 = nWord64 - nToSkip - nWord64Trailer if iWord64 == 1 and not header["OrN"]: if headerOnly: break else: return unpacked_sw_fed(fedData, header, nBytesPer, dump) elif headerOnly: break elif lastNAmcs and iWord64 < header["iWordPayloadn"]: continue elif iWord64 < iWordTrailer0: for i in range(4): word16 = (word64 >> (16*i)) & 0xffff iWord16 = 4*iWord64+i returnCode = decode.payload(htrBlocks, iWord16=iWord16, word16=word16, word16Counts=header["word16Counts"], utca=header["utca"], fedId=header["FEDid"], dump=dump) if returnCode is None: continue # ignore VME pad words (zero) if not header["utca"] and iWord64 + 1 == iWordTrailer0: if 4 * header["iWordPayload0"] + sum(header["word16Counts"]) <= iWord16: if not word16: continue nWord16Skipped += 1 if warn: printer.warning(" ".join(["skipping", "FED %d" % header["FEDid"], "event %d" % header["EvN"], "iWord16 %d" % iWord16, "word16 0x%04x" % word16, ])) else: if "htrIndex" in htrBlocks: del htrBlocks["htrIndex"] # fixme if header["uFoV"] and (iWord64 == nWord64 - nToSkip - 2): decode.block_trailer_ufov1(trailer, iWord64, word64) else: decode.trailer(trailer, iWord64, word64) decode.other(other, skipped64) return {"header": header, "trailer": trailer, "htrBlocks": htrBlocks, "other": other, "nBytesSW": 8*nWord64, "nWord16Skipped": nWord16Skipped, }