def show_sample(self,
                    fnameP='/data/Samples/TMSPlane/Dec26/sample_{0:d}.adc',
                    Ns=10,
                    ich=8):
        from ROOT import TGraph, gPad, TLatex
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()
        data2 = s1.generate_sdmDataBuf()

        data3 = ((s1.ANALYSIS_WAVEFORM_BASE_TYPE * s1.nSamples) * Ns)()
        dataList = []
        for i in range(Ns):
            fname = fnameP.format(i)
            s1.read_data([fname, ''], data1, data2)
            x = array.array('f', range(s1.nSamples))
            #             s1.filters_trapezoidal(data1[ich], data3[i], [100,100,200,-1])
            s1.filters_trapezoidal(data1[ich], data3[i],
                                   [100, 100, 100, 0.000722])
            g1 = TGraph(s1.nSamples, x, data3[i])
            #             g1 = TGraph(s1.nSamples, x, data1[ich])

            opt = 'AP' if i == 0 else "PSame"
            g1.Draw(opt + ' PLC PMC')
            dataList.append(g1)

        lt = TLatex()
        lt.DrawLatexNDC(0.2, 0.8, "Chan={0:d}".format(ich))
        gPad.Update()
        waitRootCmdX()
def get_tgraph(ch,entry,inRoot):
    s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
    data1 = s1.generate_adcDataBuf()
    fout1 = TFile(inRoot,'read')
    tree1 = fout1.Get('tree1')
    tree1.SetBranchAddress('adc',data1)
    tree1.GetEntry(entry)

    data3 = (s1.ANALYSIS_WAVEFORM_BASE_TYPE * s1.nSamples)()
    s1.filters_trapezoidal(data1[ch], data3, [100,100,200,10])

    x1 = array('f',range(s1.nSamples))
    g1 = TGraph(s1.nSamples, x1, data3)

    return g1
        nBytes = nWords * 4
        buf = bytearray(nBytes)
        print("nBytes = {:d}".format(nBytes))
        ret = cmd.acquire_from_datafifo(s, nWords, buf)
        print("Returned {:d} bytes.".format(len(ret)))
        #print(":".join("{:02x}".format(ord(c)) for c in ret))
        s1.demux_fifodata(ret, data1, data2)

        s.close()

    else:
        s1.read_data(['data/Jan03a/Jan03a_0.adc', 'xxx'], data1, data2)

    ich = 12
    data3 = (s1.ANALYSIS_WAVEFORM_BASE_TYPE * s1.nSamples)()
    s1.filters_trapezoidal(data1[ich], data3, [100, 100, 200, -1])

    a = s1.measure_pulse(data1, [100, 100, 200, -1])
    for b in a:
        for c in b:
            print(c)

#     for i in range(s1.nSamples):
#         print(i,data1[8][i],data3[i])
#         if i%20 == 0:
#             x = raw_input()
#             if x=='q': break

    x = range(s1.nSamples)
    #     x = range(1000)
    print(len(data1[ich]))