Пример #1
0
def main(argv):

    # option flags
    offsetflag = 0
    octgeo = 1

    inputfile = ''
    outputfile = ''
    run = -1
    colors = visual.bcolors()
    consts = commonTrig.tconsts()
    try:
        opts, args = getopt.getopt(argv, "hi:o:r:f",
                                   ["ifile=", "ofile=", "run="])
    except getopt.GetoptError:
        print 'decodeFIND_32bit.py -i <inputfile> -o <outputfile> -r <run> [-f]'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'decodeFIND_32bit.py -i <inputfile> -o <outputfile> -r <run> [-f]'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ('-r', "--run"):
            run = int(arg)
        elif opt == '-f':
            offsetflag = 1

    if (offsetflag):
        print "Adding offsets!"
    else:
        print "No offsets!"

    if (run == -1):
        print colors.FAIL + "No run number!" + colors.ENDC
        sys.exit(2)
    if (run < 3522):
        print colors.WARNING + "Using flipped offsets!" + colors.ENDC

    num_lines = sum(1 for line in open(inputfile))
    datafile = open(inputfile, 'r')
    decodedfile = open(outputfile, 'w')

    eventnum = 0
    n = 5  #starting pt of data
    lines = []
    hits = []
    strips = []  #raw strip number after offsets
    vmms = []  #vmm number after remapping
    chs = []  #channel number

    nevent = 0
    for line in datafile:
        if str(line[0:4]) == 'TIME':
            timestamp = int(float(line[6:-1]))
            timestampsec = timestamp / pow(10, 9)
            timestampns = timestamp % pow(10, 9)
            continue
        if ((len(lines) == 0) and (line[0:2] != "A2")):
            print "\n"
            print colors.WARNING + "We can't find the header and we expect it!" + colors.ENDC
            print "\n"
            sys.exit()
        lines.append(line[:len(line) - 1])
        if len(lines) == 9:  # groups of 9
            nevent = nevent + 1
            if (nevent % (num_lines / (10 * 9)) == 0):
                visual.update_progress(float(nevent) / num_lines * 9.)
            decodedfile.write("Event " + str(nevent) + " Sec " +
                              str(timestampsec) + " NS " + str(timestampns))
            header = lines[0]  #contains constants + BCID
            occ = list(format(int(header[2:4], 16), "08b"))
            bcid = header[4:]
            for i in range(4):
                hits.append(lines[i + 1])
            iplane = 0
            for hit in hits:
                for j in range(2):
                    if (run > 3521):
                        ivmm, ich = decode(offsetflag, octgeo,
                                           consts.OVERALLOFFSET,
                                           consts.OFFSETS, hit, iplane, j,
                                           consts.FLIPPEDBOARDS, occ)
                    else:
                        ivmm, ich = decode(offsetflag, octgeo,
                                           consts.OVERALLOFFSET,
                                           consts.OLDOFFSETS, hit, iplane, j,
                                           consts.FLIPPEDBOARDS, occ)
                    vmms.append(ivmm)
                    chs.append(ich)
                    iplane = iplane + 1
            decodedfile.write('\n' + str(header)\
                              + " BCID: " + str(int(bcid,16)))
            for ib in range(8):
                decodedfile.write('\n' + str(vmms[ib]) + ' ' + str(chs[ib]))
            decodedfile.write('\n')
            lines = []
            hits = []
            strips = []
            vmms = []
            chs = []
    decodedfile.close()
    datafile.close()
    print "\n"
    print colors.ANNFAV + "\t\t\t\t\t\t\t\t\t " + colors.ENDC
    print colors.ANNFAV + "\tDone decoding, exiting! \t\t\t\t\t " + colors.ENDC
    print colors.ANNFAV + "\t\t\t\t\t\t\t\t\t " + colors.ENDC
Пример #2
0
def main(argv):

    colors = visual.bcolors()
    consts = commonTrig.tconsts()

    parser = argparse.ArgumentParser()
    parser.add_argument("--ifile", "-i", default="", help="input file")
    parser.add_argument("--ofile", "-o", default="", help="output file")
    args = parser.parse_args()

    num_lines = sum(1 for line in open(args.ifile))
    datafile = open(args.ifile, 'r')
    decodedfile = open(args.ofile, 'w')

    lines = []
    lastn = -1
    skips = 0
    skipped = 0

    print "\n"
    print colors.DARK + "Decoding!       " + "ψ ︿_____︿_ψ_ ☾\t " + colors.ENDC
    print "\n"
    nevent = 0
    for line in datafile:
        if str(line[0:4]) == 'TIME':
            timestamp = int(float(line[6:-1]))
            timestampsec = timestamp / pow(10, 9)
            timestampns = timestamp % pow(10, 9)
            continue
        if ((len(lines) == 0) and (line[0:2] != "A2")):
            print "\n"
            print colors.WARNING + "We can't find the header and we expect it!" + colors.ENDC
            print "\n"
            sys.exit()
        lines.append(line[:len(line) - 1])

        if len(lines) == 2:  # groups of 2
            nevent = nevent + 1
            if (nevent % (num_lines / (10 * 3)) == 0):
                visual.update_progress(float(nevent) / num_lines * 3.)
            decodedfile.write("Event " + str(nevent) + " Sec " +
                              str(timestampsec) + " NS " + str(timestampns))
            header = lines[0]  #contains constants + trigger number
            overflow = int(header[3])
            ntrig = int(header[4:8], 16)
            if (ntrig - lastn - 1) != 0 and (ntrig - lastn -
                                             1) != -65536 and lastn != -1:
                print "\nSkipped a trigger! On Event", ntrig
                print "Skipped", ntrig - lastn - 1
                skips += 1
                skipped += (ntrig - lastn - 1)

            lastn = ntrig
            timing = lines[1]
            bcid = int(timing[4:7], 16)
            phase = int(timing[7], 16)
            phasens = phase * (25 / 16.)  # phase in ns

            decodedfile.write('\n' + "BCID: " + str(bcid) + " ph: " +
                              str(phase))
            decodedfile.write('\n' + "overflow: " + str(overflow))
            decodedfile.write('\n' + "ntrig: " + str(ntrig) + "\n")
            lines = []
    decodedfile.close()
    datafile.close()
    print "\n"
    print colors.DES + "Done decoding!  " + "ψ ︿_____︿_ψ_ ☼\t " + colors.ENDC
    print "\n"
    print
    print "N(skips)   = %i" % (skips)
    print "N(skipped) = %i" % (skipped)
    print
Пример #3
0
def main(argv):

    # option flags
    offsetflag = 0
    octgeo = 1
    fulldata = 0  #prints crap like roi, dtheta, etc
    stripflag = 0
    slopeflag = 0

    inputfile = ''
    outputfile = ''
    dumpfile = ''
    run = -1
    colors = visual.bcolors()
    consts = commonTrig.tconsts()
    start_time = time.time()

    try:
        opts, args = getopt.getopt(
            argv, "hi:o:d:r:f",
            ["ifile=", "ofile=", "dfile=", "run=", 'st', 'sl'])
    except getopt.GetoptError:
        print 'decodeFIT_uvr.py -i <inputfile> -o <outputfile> -d <dumpfile> -r <run> [-f] [--sl] [--st]'
        sys.exit(2)
    for opt, arg in opts:
        if opt == '-h':
            print 'decodeFIT_uvr.py -i <inputfile> -o <outputfile> -d <dumpfile> -r <run> [-f] [--sl] [--st]'
            sys.exit()
        elif opt in ("-i", "--ifile"):
            inputfile = arg
        elif opt in ("-o", "--ofile"):
            outputfile = arg
        elif opt in ("-d", "--dfile"):
            dumpfile = arg
        elif opt in ("-r", "--run"):
            run = int(arg)
        elif opt == '-f':
            offsetflag = 1
        elif opt == "--sl":
            slopeflag = 1
        elif opt == "--st":
            print
            print "ARE YOU SURE YOU WANT TO DECODE STRIPS? USUALLY WE DO SLOPES."
            print
            stripflag = 1

    if not (slopeflag or stripflag):
        print "Please provide --st and/or --sl to decode strips and/or slopes, respectively."
        sys.exit(2)

    if (offsetflag):
        print "Adding offsets!"
    else:
        print colors.WARNING + "No offsets!" + colors.ENDC

    if (run == -1):
        print colors.FAIL + "No run number!" + colors.ENDC
        sys.exit(2)

    if (run < 3522):
        print colors.WARNING + "Using flipped offsets!" + colors.ENDC

    num_lines = sum(1 for line in open(inputfile))
    datafile = open(inputfile, 'r')
    decodedfile = open(outputfile, 'w')

    # option to dump raw event
    if dumpfile:
        dfile = open(dumpfile, 'r').readlines()
        events_to_dump = []
        for df in dfile:
            if not df:
                continue
            df = df.strip()
            events_to_dump.append(int(df))
        events_to_dump = sorted(list(set(events_to_dump)))

    n = 5  #starting pt of data
    lines = []
    hits = []
    slopes = []  #raw strip number after offsets
    vmms = []  #vmm number
    chs = []  #channel number
    svmms = []
    schs = []

    print "\n"
    print colors.DARK + "Decoding!       " + "ψ ︿_____︿_ψ_ ☾\t " + colors.ENDC
    print "\n"
    for iline, line in enumerate(datafile):

        if iline % 50000 == 0 and iline > 0:
            visual.pbftp(time.time() - start_time, iline, num_lines)

        if str(line[0:4]) == 'TIME':
            timestamp = int(float(line[6:-1]))
            timestampsec = timestamp / pow(10, 9)
            timestampns = timestamp % pow(10, 9)
            continue
        if ((len(lines) == 0) and (line[0:2] != "A3")):
            print "\n"
            print colors.WARNING + "We can't find the header and we expect it!" + colors.ENDC
            print "\n"
            sys.exit()
        lines.append(line[:len(line) - 1])

        if len(lines) == 13:  # groups of 13
            global nevent
            nevent = nevent + 1
            write_me = "Event " + str(nevent) + " Sec " + str(
                timestampsec) + " NS " + str(timestampns)
            decodedfile.write(write_me)
            if dumpfile and nevent in events_to_dump:
                print write_me
                print "\n".join(lines)
            header = lines[0]  #contains constants + BCID
            occ = list(format(int(header[2:4], 16), "08b"))
            bcid = header[4:]
            for i in range(4):
                hits.append(lines[i + 1])
            iplane = 0
            if (stripflag):
                for hit in hits:
                    for j in range(2):
                        if (run > 3521):
                            ivmm, ich = decode(offsetflag, octgeo,
                                               consts.OVERALLOFFSET,
                                               consts.OFFSETS, hit, iplane, j,
                                               consts.FLIPPEDBOARDS, occ)
                        else:
                            ivmm, ich = decode(offsetflag, octgeo,
                                               consts.OVERALLOFFSET,
                                               consts.OLDOFFSETS, hit, iplane,
                                               j, consts.FLIPPEDBOARDS, occ)
                        vmms.append(ivmm)
                        chs.append(ich)
                        iplane = iplane + 1
            if (slopeflag):
                for i in range(4, 8):
                    slopes.append(lines[i + 1])
                iplane = 0
                for slope in slopes:
                    for j in range(2):
                        if (run > 3521):
                            ivmm, ich = decode(offsetflag,
                                               octgeo,
                                               consts.OVERALLOFFSET,
                                               consts.OFFSETS,
                                               slope,
                                               iplane,
                                               j,
                                               consts.FLIPPEDBOARDS,
                                               occ,
                                               sl=True)
                        else:
                            ivmm, ich = decode(offsetflag,
                                               octgeo,
                                               consts.OVERALLOFFSET,
                                               consts.OLDOFFSETS,
                                               slope,
                                               iplane,
                                               j,
                                               consts.FLIPPEDBOARDS,
                                               occ,
                                               sl=True)
                        svmms.append(ivmm)
                        schs.append(ich)
                        iplane = iplane + 1

            # trigger calcs
            roi = lines[9][0:4]
            roi_dec = int(lines[9][0:4], 16)
            dtheta = lines[9][4:]
            dtheta_dec = int(lines[9][4:], 16)
            mx_roi = lines[10][0:4]
            mx_roi_dec = int(lines[10][0:4], 16)
            mx_local = lines[10][4:]
            mx_local_dec = int(mx_local, 16)
            #            mx_local_dec = (mx_local_dec & 0x7FFF) - (mx_local_dec & 0x8000)
            if (mx_local_dec > 0x7fff):
                mx_local_dec -= 0x10000
            mv_global = lines[11][0:4]
            mv_global_dec = int(lines[11][0:4], 16)
            mu_global = lines[11][4:]
            mu_global_dec = int(lines[11][4:], 16)
            mx_global = lines[12][0:4]
            mx_global_dec = int(lines[12][0:4], 16)
            counter = int(lines[12][4:], 16)

            decodedfile.write('\n' + str(header) + " BCID: " +
                              str(int(bcid, 16)))
            for ib in range(8):
                decodedfile.write('\n')
                if (stripflag):
                    if (vmms[ib] > 7 and chs[ib] != 0):
                        decodedfile.write(
                            str(vmms[ib] - 8) + ' ' + str(chs[ib]) + ' 1')
                    else:
                        decodedfile.write(str(vmms[ib]) + ' ' + str(chs[ib]))
                if slopeflag and stripflag:
                    decodedfile.write(' ')
                if (slopeflag):
                    if (svmms[ib] > 7 and schs[ib] != 0):
                        decodedfile.write(
                            str(svmms[ib] - 8) + ' ' + str(schs[ib]) + ' 1')
                    else:
                        decodedfile.write(str(svmms[ib]) + ' ' + str(schs[ib]))
            decodedfile.write('\n' + 'mx_local ' + str(mx_local) + ' ' +
                              str(mx_local_dec / pow(2, 14.)))
            if (fulldata):
                decodedfile.write('\n' + 'roi ' + str(roi_dec))
                decodedfile.write('\n' + 'dtheta ' +
                                  str(dtheta_dec / pow(2, 30)))
                decodedfile.write('\n' + 'mx_roi ' +
                                  str(mx_roi_dec / pow(2, 16)))
                decodedfile.write('\n' + 'mv_global ' +
                                  str(mv_global_dec / pow(2, 16)))
                decodedfile.write('\n' + 'mu_global ' +
                                  str(mu_global_dec / pow(2, 16)))
                decodedfile.write('\n' + 'mx_global ' +
                                  str(mx_global_dec / pow(2, 16)))
            decodedfile.write('\n' + 'cntr ' + str(counter))
            decodedfile.write('\n')
            lines = []
            hits = []
            slopes = []
            vmms = []
            chs = []
            svmms = []
            schs = []
    decodedfile.close()
    datafile.close()
    print "\n"
    print colors.DES + "Done decoding!  " + "ψ ︿_____︿_ψ_ ☼\t " + colors.ENDC
    print "\n"
Пример #4
0
def main(argv):

    colors = visual.bcolors()
    consts = commonTrig.tconsts()

    args = options()
    
    num_lines = sum(1 for line in open(args.ifile))
    datafile = open(args.ifile, 'r')
    decodedfile = open(args.ofile, 'w')

    # option to dump raw events
    if args.dfile:
        dfile = open(args.dfile, 'r').readlines()
        events_to_dump = []
        for df in dfile:
            if not df:
                continue
            df = df.strip()
            events_to_dump.append(int(df))
        events_to_dump = sorted(list(set(events_to_dump)))

    lines = []

    # previous bcids
    (addc1,addc2) = (-1,-1)
    
    Aflag = True
    win = 30 # expected buffer length
    buflen = win-1
    oldtime = -1
    (nexcess, nshort, dropped) = (0,0,0)
    badgbt = []
    gbtlen = []
    times = []

    print "\n"
    print colors.DARK + "Decoding!       " + "ψ ︿_____︿_ψ_ ☾\t "+ colors.ENDC
    print "\n"

    print "Will not catch > 15+ bugs!"
    start_time = time.time()
    
    nevent = 0
    (timestamp,timestampsec,timestampns) = (-1,-1,-1)

    for iline,line in enumerate(datafile):
        if str(line[0:4]) == 'TIME' :
            timestamp = int(float(line[6:-1]))
            timestampsec = timestamp/pow(10,9)
            timestampns = timestamp%pow(10,9)
            continue
        lines.append(line[:len(line)-1])

        if iline % 50000 == 0 and iline > 0 and not args.dfile:
            visual.pbftp(time.time() - start_time, iline, num_lines)

        n = 5 # start pt of data
        if len(lines) == 4: # groups of 4
            strobe = "".join(map(str,lines))
            artdata = strobe[n+15:n+27]
            parity = strobe[n+13:n+15]
            hitmap = strobe[n+5:n+13]
            hitmap = "{0:032b}".format(int(hitmap,16))
            error = strobe[n+3:n+5]
            bcid = strobe[n:n+3]
            artdata = "{0:048b}".format(int(artdata,16))

            vmmdata = []
            vmmlist = []
            boardlist = []

            buflen += 1
            #print buflen, int(bcid, 16)

            for i in range(8):
                vmmdata.append(int(artdata[i*6:i*6+6],2))

            for i in range(32):
                if (hitmap[i] is "1"):
                    boardlist.append((31-i)/8)
                    vmmlist.append((31-i)%8)

            excluded = [286202,306851,446152,532552,570143,757921,825138,1038996,1134297,
                        1155745,1169477,1170888,1177961]
            
            #######################################################################################################
            # alternative implementation of logic for starting new event:
            # jumps in bcid and we expect it to jump
            # or it jumps a lot in bcid (>2) and we don't expect it to
            # or it doesn't jump but we expect it to and the timestamp changed, at least
            # or it was one of those stupid events where it doesn't jump but we are pretty sure it's a new trigger
            # if ((int(bcid,16)-addc1) != 1 and addc1-int(bcid,16) != 4095 and Aflag and buflen == win)\
            #    or (abs(int(bcid,16)-addc1) > 2 and abs(addc1-int(bcid,16)) < 4095 and Aflag)\
            #    or (((int(bcid,16)-addc1) == 1 or addc1-int(bcid,16) == 4095) and Aflag and timestamp != oldtime and buflen == win)\
            #    or (((int(bcid,16)-addc1) == 1 or addc1-int(bcid,16) == 4095) and Aflag and nevent in excluded and buflen == win):
            #######################################################################################################
            
            # current implementation of logic for starting new event
            # we collect 15 packets
            # or it jumps a lot in bcid and we don't expect it to
            if (buflen == win) or (abs(int(bcid,16)-addc1) > 2 and abs(addc1-int(bcid,16)) < 4095 and Aflag):
                if (buflen < win):
                    nshort += 1
                    badgbt.append(nevent)
                    gbtlen.append(buflen)
                    times.append(int(timestamp))
                    #print colors.WARNING + "Event " + str(nevent) + " has fewer than 15 GBT packets!" + colors.ENDC
                    
                    
                # starting new event
                nevent += 1
                #print "Event", nevent
                Aflag = True
                buflen = 0

                write_me = "Event " + str(nevent) +" Sec " + str(timestampsec) + " NS " + str(timestampns) + "\n"
                decodedfile.write(write_me)
                if args.dfile and nevent in events_to_dump:
                    print write_me.rstrip("\n")

            if (Aflag):
                addc1 = int(bcid,16)
                Aflag = False
            else:
                addc2 = int(bcid,16)
                Aflag = True
            oldtime = timestamp
            if (buflen >= win):
                if (buflen == (win)):
                    nexcess += 1
                    print "\n"
                    print colors.WARNING + "Event " + str(nevent) + " has more than 15 GBT packets!" + colors.ENDC
            else:
                decodedfile.write("BCID: %4i Hits: %i\n" % (int(bcid,16),len(vmmlist)))
                for ibo in xrange(4):
                    arts = []
                    for board,vmm,art in zip(boardlist[::-1][0:8],vmmlist[::-1][0:8],vmmdata[::-1]):
                        if int(board) == ibo:
                            arts.append([vmm,art])
                    write_me = "%s %s" % (ibo, " ".join(["%s,%s" % (vmm, art) for vmm,art in arts]))
                    decodedfile.write(write_me+"\n")
                if args.dfile and nevent in events_to_dump:
                    print "\n".join(lines)
            lines = []
            
    decodedfile.close()
    datafile.close()
    print "\n"
    print colors.DES + "Done decoding!  " + "ψ ︿_____︿_ψ_ ☼\t "+ colors.ENDC
    print "Found " + str(nshort)+ " bad GBT buffers, writing into gbterr.txt"
    print "\n"

    errfile = open("gbterr.txt", 'w')
    for x in zip(badgbt,gbtlen,times):
          errfile.write(str(x) + "\n")
    errfile.close()