예제 #1
0
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
예제 #2
0
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,
    }
예제 #3
0
파일: unpack.py 프로젝트: elaird/hcalraw
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,
            }