Beispiel #1
0
def reportProgress(globalEntry, iEvent, iMask):
    if iEvent and not (iEvent & (2**iMask - 1)):
        msg = "%8d %s" % (iEvent, time.ctime())
        if globalEntry != iEvent:
            msg += "  (entry %8d)" % globalEntry
        printer.gray(msg)
        return iMask + 1
    else:
        return iMask
Beispiel #2
0
def reportProgress(globalEntry, iEvent, iMask):
    if iEvent and not (iEvent & (2**iMask - 1)):
        msg = "%8d %s" % (iEvent, time.ctime())
        if globalEntry != iEvent:
            msg += "  (entry %8d)" % globalEntry
        printer.gray(msg)
        return iMask + 1
    else:
        return iMask
Beispiel #3
0
    def connect(self):
        if not self.options.logfile:
            self.options.logfile = self.rbx + ".log"
        self.logfile = open(self.options.logfile, "a")
        printer.gray("Appending to %s" % self.options.logfile)
        h = "-" * 30 + "\n"
        self.logfile.write(h)
        self.logfile.write("| %s |\n" % str(datetime.datetime.today()))
        self.logfile.write(h)

        # ngfec.survey_clients()
        # ngfec.kill_clients()
        self.server = ngfec.connect(self.options.host, self.options.port, self.logfile)
Beispiel #4
0
    def connect(self):
        self.logfile = open(self.options.logfile, "a")
        printer.gray(
            "Appending to %s (consider doing \"tail -f %s\" in another shell)"
            % (self.options.logfile, self.options.logfile))
        h = "-" * 30 + "\n"
        self.logfile.write(h)
        self.logfile.write("| %s |\n" % str(datetime.datetime.today()))
        self.logfile.write(h)

        # ngfec.survey_clients()
        ngfec.kill_clients()
        self.server = ngfec.connect(self.options.host, self.options.port,
                                    self.logfile)
Beispiel #5
0
    def connect(self, quiet=False):
        self.logfile = open(self.options.logfile, "a")
        if not quiet:
            printer.gray("Appending to %s" % self.options.logfile)
        h = "-" * 30 + "\n"
        self.logfile.write(h)
        self.logfile.write("| %s |\n" % str(datetime.datetime.today()))
        self.logfile.write(h)

        # os.system("killall ngccm >& /dev/null")
        self.server = pexpect.spawn("ngFEC.exe -z -c -t -p %d -H %s" %
                                    (self.port, self.host))
        self.server.logfile = self.logfile
        self.server.sendline("")
        self.server.expect(".*")
Beispiel #6
0
def uhtrTriggerData(d={}, dump=None, crate=None, slot=None, top="", nonMatched=[]):
    out = []
    out.append("  ".join([" TPid",
                          "Fl",
                          "  SofI",
                          "   OK",
                          "  TP(hex)",
                          "    ".join([str(i) for i in range(4)])
                          ])
               )
    for channelId, data in sorted(d.iteritems()):
        if (dump <= 8) and not any(data["TP"]):
            continue
        soi = ""
        ok = ""
        tp = ""
        for j in range(len(data["SOI"])):
            soi += str(data["SOI"][j])
            ok += str(data["OK"][j])
            tp_s = "%5x" % data["TP"][j]
            if data["SOI"][j]:
                tp_s = printer.gray(tp_s, False)
            if not data["OK"][j]:
                tp_s = printer.red(tp_s, False)
            tp += tp_s

        if dump != 10 or not all(data["OK"]):
            out.append("   ".join([" 0x%02x" % channelId,
                                   "%1d" % data["Flavor"],
                                   "%5s" % soi,
                                   "%5s" % ok,
                                   " "*2,
                                   tp]))
    return out
Beispiel #7
0
def uhtrTriggerData(d={}, dump=None, crate=None, slot=None, top="", nonMatched=[]):
    out = []
    out.append("  ".join([" TPid",
                          "Fl",
                          "  SofI",
                          "   OK",
                          "  TP(hex)",
                          "    ".join([str(i) for i in range(4)])
                          ])
               )
    for channelId, data in sorted(d.items()):
        if (dump <= 8) and not any(data["TP"]):
            continue
        soi = ""
        ok = ""
        tp = ""
        for j in range(len(data["SOI"])):
            soi += str(data["SOI"][j])
            ok += str(data["OK"][j])
            tp_s = "%5x" % data["TP"][j]
            if data["SOI"][j]:
                tp_s = printer.gray(tp_s, False)
            if not data["OK"][j]:
                tp_s = printer.red(tp_s, False)
            tp += tp_s

        if dump != 10 or not all(data["OK"]):
            out.append("   ".join([" 0x%02x" % channelId,
                                   "%1d" % data["Flavor"],
                                   "%5s" % soi,
                                   "%5s" % ok,
                                   " "*2,
                                   tp]))
    return out
Beispiel #8
0
def command(p, cmd, timeout=5):
    fields = cmd.split()
    if not fields:
        return None

    if fields[0] == "jtag":
        if len(fields) < 4:
            print("COMMAND has to few fields: (%s)" % cmd)
            return None

        regexp = "(.*)%s %s %s# retcode=(.*)" % tuple(fields[1:])
    else:
        regexp = "{0}\s?#((\s|E)[^\r^\n]*)".format(re.escape(cmd))

    try:
        p.sendline(cmd)
        p.expect(regexp, timeout=timeout)
        return p.match.group(0).split("\r\n")
    except pexpect.TIMEOUT:
        tail = "tail -20 %s" % p.logfile.name

        msg = printer.msg('The command "', p=False)
        msg += printer.cyan(cmd, p=False)
        msg += printer.msg(
            '"\n       produced unexpected output.  Consult the log file, e.g.',
            p=False)
        msg += printer.msg('\n       "%s" gives this:' %
                           printer.gray(tail, p=False),
                           p=False)
        printer.error(msg)
        os.system(tail)
        sys.exit()
Beispiel #9
0
    def command(self,
                cmd,
                timeout=5,
                bail_on_timeout=False,
                only_first_line=True):
        fields = cmd.split()
        if not fields:
            return None

        if fields[0] == "jtag":
            if len(fields) < 4:
                print("COMMAND has to few fields: (%s)" % cmd)
                return None

            regexp = "(.*)%s %s %s# retcode=(.*)" % tuple(fields[1:])
        else:
            regexp = "{0}\s?#((\s|E)[^\r^\n]*)".format(re.escape(cmd))

        try:
            self.server.sendline(cmd)
            self.server.expect(regexp, timeout=timeout)
            out = self.server.match.group(0).split("\r\n")
        except pexpect.TIMEOUT:
            if not bail_on_timeout:
                out = [cmd + " # ERROR: timed out after %d seconds" % timeout]
            else:
                lines = [
                    printer.msg('The command "', p=False),
                    printer.cyan(cmd, p=False),
                    printer.msg(
                        '"\n       produced unexpected output.  Consult the log file, e.g.',
                        p=False),
                    printer.msg('\n       "%s" gives this:' %
                                printer.gray(tail, p=False),
                                p=False),
                    printer.error(msg)
                ]
                self.bail(lines, tail=True)

        if "ERROR" in out[0]:
            printer.red(out[0])
        return out[0] if only_first_line else out
Beispiel #10
0
def capIdString(caps, sois, nTsMax):
    l = []

    for i in range(nTsMax):
        if i < len(caps) and i < len(sois):
            value = caps[i]
            s = "%1x" % value
            if sois[i]:
                s = printer.gray(s, False)
            l.append(s)
        else:
            l.append(" ")

    out = "".join(l)

    if nTsMax < len(caps):
        out += printer.red("..", False)
    else:
        out += "  "
    return out
Beispiel #11
0
def capIdString(caps, sois, nTsMax):
    l = []

    for i in range(nTsMax):
        if i < len(caps) and i < len(sois):
            value = caps[i]
            s = "%1x" % value
            if sois[i]:
                s = printer.gray(s, False)
            l.append(s)
        else:
            l.append(" ")

    out = "".join(l)

    if nTsMax < len(caps):
        out += printer.red("..", False)
    else:
        out += "  "
    return out
Beispiel #12
0
def qieString(qies=[], sois=[], red=False, nMax=10):
    l = []

    for i in range(nMax):
        if i < len(qies):
            s = "%2x" % qies[i]
            if i < len(sois) and sois[i] and not red:
                s = printer.gray(s, False)
            l.append(s)
        else:
            l.append("  ")

    out = " ".join(l)
    if red:
        out = printer.red(out, False)

    if nMax < len(qies):
        out += printer.red("..", False)
    else:
        out += "  "
    return out
Beispiel #13
0
def qieString(qies=[], sois=[], red=False, nMax=10):
    l = []

    for i in range(nMax):
        if i < len(qies):
            s = "%2x" % qies[i]
            if i < len(sois) and sois[i] and not red:
                s = printer.gray(s, False)
            l.append(s)
        else:
            l.append("  ")

    out = " ".join(l)
    if red:
        out = printer.red(out, False)

    if nMax < len(qies):
        out += printer.red("..", False)
    else:
        out += "  "
    return out
Beispiel #14
0
    def uhtr_compare(self,
                     slot,
                     ppod,
                     first,
                     lst,
                     expected,
                     threshold=None,
                     doubled=False,
                     dec=False):
        iStart, iEnd, items = self.uhtr_range_and_items(slot, ppod, lst, first)
        n = int((len(lst) - 19) / 12)
        if doubled:
            iStart *= 2
            iEnd *= 2
            n = int(n / 2)

        msg = lst[:19]
        for i, x in enumerate(items):
            try:
                result = int(x, 10 if dec else 16)
            except ValueError:
                try:
                    result = float(x)
                except ValueError:
                    result = None

            if doubled:
                space = " " * (n - len(x) - 1)
            else:
                space = " " * (n - len(x) - 1)

            if i < iStart or iEnd <= i or result is None:
                msg += space + printer.gray(x, p=False) + " "
            elif threshold is not None and threshold < abs(result - expected):
                msg += space + printer.red(x, p=False) + " "
            else:
                msg += space + printer.green(x, p=False) + " "

        print(msg)
Beispiel #15
0
def one(inFile, options, h):
    biasMonLsb = 0.01953602  # V / ADC

    final = inFile.split("/")[-1]
    if final.startswith("HB"):
        nCh = 64
        leakLsb = 0.244  # uA / ADC
        biasMin = 0.0586081  # ADC = 0
        leakMin = 1.708  # ADC = 0
    elif final.starswith("HE"):
        nCh = 48
        leakLsb = 0.122  # uA / ADC
    else:
        sys.exit(
            "Each argument must contain either 'HB' or 'HE'.  Found '%s'" %
            inFile)

    outFile = inFile.replace(".pickle", ".pdf")
    target = inFile.replace(".pickle", "")
    g_voltages, min_bv_voltages, factor_voltages,\
    g_currents, min_bv_currents, factor_currents = graphs(inFile, nCh, options,
                                                          biasMonLsb*options.lsbFactorVoltage,
                                                          leakLsb*options.lsbFactorCurrent,
                                                          biasMin*1.001, leakMin*1.001)

    p_voltages = fits(g_voltages, min_bv_voltages, options, target, 1.0)
    p_currents = fits(g_currents, min_bv_currents, options, target, 0.15)

    if not p_voltages:
        return

    can = r.TCanvas("canvas", "canvas", 8000, 6000)
    can.Print(outFile + "[")
    draw_per_channel(g_voltages,
                     "BVmeas(V)",
                     80.0,
                     can,
                     outFile,
                     fColor1=r.kBlue + 3,
                     fColor2=r.kCyan)
    histogram_fit_results(p_voltages,
                          min_bv_voltages,
                          factor_voltages,
                          options,
                          target,
                          h["V_npoints"],
                          h["V_mins"],
                          h["V_factors"],
                          h["V_pvalues"],
                          h["V_pvalues2"],
                          h["V_delta_chi2"],
                          h["V_delta_chi2_cut_vs_ch"],
                          h["V_offsets"],
                          h["V_offsets_unc"],
                          h["V_slopes"],
                          h["V_slopes_unc_rel"],
                          warn=False)
    # histogram_fit_results_vs_channel(p_voltages, nCh, can, outFile, target=target, title="BV meas", unit="V")

    draw_per_channel(g_currents, "Ileak(uA) ", 40.0, can, outFile)
    histogram_fit_results(p_currents, min_bv_currents, factor_currents,
                          options, target, h["I_npoints"], h["I_mins"],
                          h["I_factors"], h["I_pvalues"], h["I_pvalues2"],
                          h["I_delta_chi2"], h["I_delta_chi2_cut_vs_ch"],
                          h["I_offsets"], h["I_offsets_unc"], h["I_slopes"],
                          h["I_slopes_unc_rel"])

    histogram_fit_results_vs_channel(p_currents,
                                     nCh,
                                     can,
                                     outFile,
                                     target=target,
                                     title="I leak",
                                     unit="uA")
    can.Print(outFile + "]")
    printer.gray("Wrote %s" % outFile)
    return True
def one(inFile, options, h):
    vMonLsb = 0.003663  # V / ADC
    vMin = 0.0  # ADC = 0

    iLsb = 0.0006105  # A / ADC
    iMin = 0.0  # ADC = 0

    tLsb = 0.01  # FIXME
    tMin = -50.0  # FIXME

    nCh = (4 if options.rms == "[1-4]" else 1) * scan_peltier.nRbxes(
        inFile.split("_")[0])

    final = inFile.split("/")[-1]

    outFile = inFile.replace(".pickle", ".pdf")
    target = inFile.replace(".pickle", "")

    d_voltages, d_currents, d_temperatures = vi_dicts(
        inFile,
        current_string="PeltierCurrent_",
        voltage_string="PeltierVoltage_")

    settings = sorted(d_voltages.keys())
    g_voltages, min_bv_voltages, factor_voltages = graphs(
        inFile, nCh, options, settings, d_voltages, vMin * 1.001,
        vMonLsb * options.lsbFactorVoltage)

    g_currents, min_bv_currents, factor_currents = graphs(
        inFile, nCh, options, settings, d_currents, iMin * 1.001,
        iLsb * options.lsbFactorCurrent)

    g_temperatures, min_bv_temperatures, factor_temperatures = graphs(
        inFile, nCh, options, settings, d_temperatures, tMin * 1.001,
        tLsb * options.lsbFactorTemperature)

    p_voltages = fits(g_voltages, min_bv_voltages, options, target, 1.0)
    p_currents = fits(g_currents, min_bv_currents, options, target, 0.15)
    p_temperatures = fits(g_temperatures, min_bv_temperatures, options, target,
                          -7.0)

    if not p_voltages:
        return

    can = r.TCanvas("canvas", "canvas", 8000, 6000)
    can.Print(outFile + "[")

    draw_per_channel(g_voltages,
                     "PVmeas(V)",
                     can,
                     outFile,
                     options,
                     xMin=-0.5,
                     yMin=0.0,
                     yMax=(options.bvMax if options.is_voltage else 1.0),
                     fColor1=(r.kCyan if options.is_voltage else None))
    histogram_fit_results(p_voltages,
                          min_bv_voltages,
                          factor_voltages,
                          options,
                          target,
                          h["V_npoints"],
                          h["V_mins"],
                          h["V_factors"],
                          h["V_pvalues"],
                          h["V_pvalues2"],
                          h["V_delta_chi2"],
                          h["V_delta_chi2_cut_vs_ch"],
                          h["V_offsets"],
                          h["V_offsets_unc"],
                          h["V_slopes"],
                          h["V_slopes_unc_rel"],
                          h["V_curvatures"],
                          h["V_curvatures_unc"],
                          warn=False)
    # histogram_fit_results_vs_channel(p_voltages, nCh, can, outFile, target=target, title="PV meas", unit="V")

    draw_per_channel(g_currents,
                     "Imeas(A) ",
                     can,
                     outFile,
                     options,
                     xMin=-0.5,
                     yMin=0.0,
                     yMax=(7.5 / 2.0 if options.is_voltage else 0.025),
                     fColor1=(r.kCyan if options.is_voltage else None),
                     fColor2=(r.kGreen if options.is_voltage else None))
    histogram_fit_results(p_currents,
                          min_bv_currents,
                          factor_currents,
                          options,
                          target,
                          h["I_npoints"],
                          h["I_mins"],
                          h["I_factors"],
                          h["I_pvalues"],
                          h["I_pvalues2"],
                          h["I_delta_chi2"],
                          h["I_delta_chi2_cut_vs_ch"],
                          h["I_offsets"],
                          h["I_offsets_unc"],
                          h["I_slopes"],
                          h["I_slopes_unc_rel"],
                          h["I_curvatures"],
                          h["I_curvatures_unc"],
                          offset2=True,
                          slope2=True)
    # histogram_fit_results_vs_channel(p_currents, nCh, can, outFile, target=target, title="Imeas", unit="A")

    draw_per_channel(g_temperatures,
                     "T(C)",
                     can,
                     outFile,
                     options,
                     xMin=-0.5,
                     yMin=-10.0,
                     yMax=7.5 * 5.0,
                     fColor2=(r.kGreen if options.is_voltage else None))
    histogram_fit_results(p_temperatures,
                          min_bv_temperatures,
                          factor_temperatures,
                          options,
                          target,
                          h["T_npoints"],
                          h["T_mins"],
                          h["T_factors"],
                          h["T_pvalues"],
                          h["T_pvalues2"],
                          h["T_delta_chi2"],
                          h["T_delta_chi2_cut_vs_ch"],
                          h["T_offsets"],
                          h["T_offsets_unc"],
                          h["T_slopes"],
                          h["T_slopes_unc_rel"],
                          h["T_curvatures"],
                          h["T_curvatures_unc"],
                          offset2=True,
                          slope2=True)

    # histogram_fit_results_vs_channel(p_temperatures, nCh, can, outFile, target=target, title="T", unit="C")

    can.Print(outFile + "]")
    printer.gray("Wrote %s" % outFile)
    return True
Beispiel #17
0
    def uhtr(self, check=True):
        iEnd = "MP".find(self.end)

        if self.rbx == "lasermon":
            crate = 38
            slot1 = 7
            slot2 = 9
        elif self.usc:  # USC
            if self.hf:
                sys.exit("'--uhtr' is not yet supported for HF.")
            else:  # HBHE
                try:
                    # http://cmsdoc.cern.ch/cms/HCAL/document/CountingHouse/Crates/Crate_interfaces_2017.htm
                    crates = [30, 24, 20, 21, 25, 31, 35, 37, 34,
                              30]  # 30 serves sectors 18 and 1
                    crate = crates[int(self.sector / 2)]
                    slot1 = 6 * iEnd + 3 * (self.sector % 2) + 1 + int(self.he)
                    slot2 = slot1 + 1
                except IndexError:
                    printer.error("Could not find uHTR reading out %s" %
                                  self.rbx)
                    return
        elif not self.sector:  # 904
            crate = 63
            slot1 = 4 if self.hb else 5
            slot2 = slot1 + 1
        else:
            ss = self.sector - 1
            crate = 61 + int(ss / 9)
            if 9 <= ss:
                ss -= 9
            slot1 = 1 + int(4 * ss / 3)
            slot2 = slot1 + 1

        out = []
        link_status = uhtr_tool_link_status(crate,
                                            slot1,
                                            slot2,
                                            three=(self.usc
                                                   or not self.sector),
                                            he=self.he)
        for (crate, slot, ppod), lines in sorted(link_status.iteritems()):
            first = slot == slot1
            link, power, bad8b10b, bc0, h1, write_delay, read_delay, fifo_occ, bprv, h2, bad_full, invalid, h3 = lines.split(
                "\n")
            iStart, iEnd, items = self.uhtr_range_and_items(
                slot, ppod, fifo_occ, first)
            # iStart, iEnd, items = self.uhtr_range_and_items(slot, ppod, write_delay, first)
            out.append((self.sector, crate, slot, ppod, items[iStart:iEnd]))
            if not check:
                continue

            print("Crate %d Slot %2d" % (crate, slot))
            link_headers = link[19:]
            # https://github.com/elaird/hcalraw/blob/master/data/ref_2019.txt
            if self.hb or self.he:
                if self.usc or not self.sector:
                    s3 = slot % 3
                    if s3 == 1:
                        if ppod:
                            link_headers = " rx12(1-6) rx13(2-6) rx14(3-6) rx15(4-6) rx16(1-7) rx17(2-7) rx18(3-7) rx19(4-7) rx20(1-8) rx21(2-8) rx22(3-8) rx23(4-8)"
                        else:
                            link_headers = " rx00(1-1) rx01(2-1) rx02(3-1) rx03(4-1) rx04(1-4) rx05(2-4) rx06(3-4) rx07(4-4) rx08(1-5) rx09(2-5) rx10(3-5) rx11(4-5)"
                    elif s3 == 2:
                        if ppod:
                            link_headers = " rx12(1-2) rx13(1-4) rx14(1-6) rx15(2-4) rx16(2-5) rx17(2-7) rx18(3-2) rx19(3-4) rx20(3-6) rx21(4-4) rx22(4-5) rx23(4-7)"
                        else:
                            link_headers = " rx00      rx01      rx02(1-2) rx03(1-3) rx04(2-2) rx05(2-3) rx06(3-2) rx07(3-3) rx08(4-2) rx09(4-3) rx10(5-1) rx11     "
                    elif not s3:
                        if ppod:
                            link_headers = " rx12      rx13(3-1) rx14(3-3) rx15(3-5) rx16(3-7) rx17(3-8) rx18(4-1) rx19(4-2) rx20(4-3) rx21(4-6) rx22(4-8) rx23(5-1)"
                        else:
                            link_headers = " rx00      rx01(1-1) rx02(1-3) rx03(1-5) rx04(1-7) rx05(1-8) rx06(2-1) rx07(2-2) rx08(2-3) rx09(2-6) rx10(2-8) rx11(5-2)"
                else:
                    rm0 = [2, 1, 4, 3][slot % 4]
                    rm1 = rm0 + 1
                    if 4 < rm1:
                        rm1 -= 4
                    rm2 = rm0 + 2
                    if 4 < rm2:
                        rm2 -= 4

                    if ppod:
                        link_headers = " rx12(%d-5) rx13(%d-6) rx14(%d-7) rx15(%d-8) rx16(%d-1) rx17(%d-2) rx18(%d-3) rx19(%d-4) rx20(%d-5) rx21(%d-6) rx22(%d-7) rx23(%d-8)" % tuple(
                            [rm1] * 4 + [rm2] * 8)
                    else:
                        link_headers = " rx00(%d-1) rx01(%d-2) rx02(%d-3) rx03(%d-4) rx04(%d-5) rx05(%d-6) rx06(%d-7) rx07(%d-8) rx08(%d-1) rx09(%d-2) rx10(%d-3) rx11(%d-4)" % tuple(
                            [rm0] * 8 + [rm1] * 4)

            elif self.hf:
                if ppod:
                    link_headers = " rx12      rx13      rx14      rx15      rx16      rx17      rx18      rx19      rx20      rx21      rx22      rx23     "
                else:
                    link_headers = " rx00      rx01      rx02      rx03      rx04      rx05      rx06      rx07      rx08      rx09      rx10      rx11     "

            print(link[:19] + link_headers)
            self.uhtr_compare(slot, ppod, first, power, 330.0, threshold=120.0)
            self.uhtr_compare(slot, ppod, first, bad8b10b, 0, threshold=0)
            self.uhtr_compare(slot, ppod, first, bc0, 11.2, threshold=0.1)
            printer.gray(h1)
            self.uhtr_compare(slot,
                              ppod,
                              first,
                              write_delay,
                              300,
                              threshold=100000,
                              dec=True)
            self.uhtr_compare(slot,
                              ppod,
                              first,
                              read_delay,
                              300,
                              threshold=100000,
                              dec=True)
            self.uhtr_compare(slot,
                              ppod,
                              first,
                              fifo_occ,
                              12,
                              threshold=9,
                              dec=True)
            self.uhtr_compare(slot, ppod, first, bprv, 0x1111, threshold=0)
            printer.gray(h2)
            self.uhtr_compare(slot,
                              ppod,
                              first,
                              bad_full,
                              0,
                              threshold=1,
                              doubled=True)
            self.uhtr_compare(slot, ppod, first, invalid, 0, threshold=1)
            printer.gray(h3)

        return out