def run(self):
     global startBtnClicked
     global calBtnClicked
     global pmt_data
     global filter_block
     global time_block
     global pmt_filtered
     global pmt_calibrate
     global pmt_baseline
     global pmt_threshold
     global sample_detected
     global high_start
     while (startBtnClicked):
         while(not pmt_data):
             pass
         
         filter_block.append(pmt_data.popleft())
         
         if len(filter_block) >= udsp.FILTBLK_SIZE:
             graph_sema.acquire()
             filter_block = udsp.filter_signal(filter_block)
             if calBtnClicked:
                 pmt_calibrate.extend(filter_block)
             filter_block[:] = [x - pmt_baseline for x in filter_block]
             pmt_filtered.extend(filter_block)
             filter_block[:] = [x > pmt_threshold for x in filter_block]
             filter_block = udsp.filter_threshold(filter_block)
             pmt_thresholded.extend(filter_block)
             detections, high_start = udsp.detect_sample(filter_block, time_block, high_start)
             filter_block = []
             time_block = []
             graph_sema.release()
             
             while detections:
                 peak, width = detections.pop()
                 if saveData:
                     logFile.write("Sample Detected: " + str(peak))
                 print("Sample Detected: " + str(peak))
                 if saveData:
                     logFile.write("Sample Width: " + str(width))
                 print("Sample Width: " + str(width))
         
         if calBtnClicked and pmt_calibrate:
             if len(pmt_calibrate) >= udsp.CALIBRATION_WIDTH:
                 pmt_baseline, pmt_threshold = udsp.calibrate(pmt_calibrate)
                 pmt_calibrate = []
                 calBtnClicked = False
                 print "PMT Baseline:", pmt_baseline, "PMT Threshold:", pmt_threshold
 def run(self):
     global startBtnClicked
     global calBtnClicked
     global pmt_data
     global running_block
     global time_block
     global pmt_filtered
     global pmt_calibrate
     global pmt_baseline
     global pmt_threshold
     global sample_detected
     global high_start
     while (startBtnClicked):
         while(not pmt_data):
             pass
         
         running_block.append(pmt_data.popleft())
         
         if len(running_block) >= RUNBLK_SIZE:
             graph_sema.acquire()
             running_block = 0 #data_conv500 = np.convolve(data[:,1], np.ones((N,))/N, mode='valid')
             if calBtnClicked:
                 pass
             running_block[:] = [x - pmt_baseline for x in running_block]
             pmt_filtered.extend(running_block)
             running_block[:] = [x > pmt_threshold for x in running_block]
             running_block = udsp.filter_threshold(running_block)
             pmt_thresholded.extend(running_block)
             detections, high_start = udsp.detect_sample(running_block, time_block, high_start)
             running_block = []
             time_block = []
             graph_sema.release()
             
             while detections:
                 peak, width = detections.pop()
                 if saveData:
                     logFile.write("Sample Detected: " + str(peak))
                 print("Sample Detected: " + str(peak))
                 if saveData:
                     logFile.write("Sample Width: " + str(width))
                 print("Sample Width: " + str(width))
         
         if calBtnClicked and pmt_calibrate:
             if len(pmt_calibrate) >= udsp.CALIBRATION_WIDTH:
                 pmt_baseline, pmt_threshold = udsp.calibrate(pmt_calibrate)
                 pmt_calibrate = []
                 calBtnClicked = False
                 print "PMT Baseline:", pmt_baseline, "PMT Threshold:", pmt_threshold