def check_enc2(self, inRoot, outText):
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()
        data2 = s1.generate_sdmDataBuf()

        fout1 = TFile(inRoot, 'read')
        tree1 = fout1.Get('tree1')
        #         tree1.SetBranchAddress('ch0',data1)
        tree1.SetBranchAddress('adc', data1)
        with open(outText, 'w') as fout:
            fout.write(':'.join(
                ['sID/I', 'ch/I', 'B/F', 'dB/F', 'idx/I', 'A/F']))

            for i in range(tree1.GetEntries()):
                if i % 100 == 0: print(str(i) + ' entries processed')
                tree1.GetEntry(i)
                mxx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.])
                for ch in range(s1.nAdcCh):
                    mx = mxx[ch]
                    if isnan(mx[1]): print("xxxx")
                    fout.write('\n' + ' '.join([
                        str(i),
                        str(ch),
                        str(mx[0]),
                        str(mx[1]), '{0:d}'.format(int(mx[2])),
                        str(mx[3])
                    ]))
    def check_file(self, fname):
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()
        data2 = s1.generate_sdmDataBuf()

        s1.read_data([fname, ''], data1, data2)

        mx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.])
        d = [x[2] for x in mx]
        self.plot_data(d)
    def check_event(self, rootfile, idxs):
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()

        fout1 = TFile(rootfile, 'read')
        tree1 = fout1.Get('tree1')
        tree1.SetBranchAddress('adc', data1)
        for i in idxs:
            tree1.GetEntry(i)
            mx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.])
            d = [x[3] for x in mx]
            self.plot_data(d)

            waitRootCmdX()
    def check_enc(self, filePattern):
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()
        data2 = s1.generate_sdmDataBuf()

        files = glob.glob(filePattern)
        with open('test1bbb.dat', 'w') as fout:
            fout.write(':'.join(
                ['sID/I', 'ch/I', 'B/F', 'dB/F', 'idx/I', 'A/F']))
            for fname in files:
                s1.read_data([fname, ''], data1, data2)
                mxx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.])
                for ch in range(s1.nAdcCh):
                    mx = mxx[ch]
                    fout.write('\n' + ' '.join([
                        fname[fname.find('_') + 1:-4],
                        str(ch),
                        str(mx[0]),
                        str(mx[1]), '{0:d}'.format(int(mx[2])),
                        str(mx[3])
                    ]))
    def show_signal(self):
        s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5)
        data1 = s1.generate_adcDataBuf()
        data2 = s1.generate_sdmDataBuf()

        # FPGA internal fifo : 512 bit width x 16384 depth
        nWords = (512 // 32) * 16384
        nBytes = nWords * 4
        buf = bytearray(nBytes)

        self.s.sendall(self.cmd.send_pulse(1 << 2))
        time.sleep(0.5)

        ret = self.cmd.acquire_from_datafifo(self.s, nWords, buf)
        s1.demux_fifodata(ret, data1, data2)

        mx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.])
        for x in mx:
            for i in range(len(x)):
                print x[i]
        d = [x[1] for x in mx]
        self.plot_data(d)
        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]))
    d0 = array.array('f', data1[ich])
    d3 = array.array('f', data3)