diff --git a/script/EnergyScan-beforeThread.py b/script/EnergyScan-beforeThread.py index 8fc9dae..7d8de29 100644 --- a/script/EnergyScan-beforeThread.py +++ b/script/EnergyScan-beforeThread.py @@ -71,10 +71,6 @@ def _startPlot(type): MCP2 = [] a1r = [] a2r = [] - output_file_MCP1 = output_path+"MCP1"+file_prefix+"_" + suffix + ".dat" - output_file_MCP2 = output_path+"MCP2"+file_prefix+"_" + suffix + ".dat" - MCP1out = open(output_file_MCP1, "a+") - MCP2out = open(output_file_MCP2, "a+") #MCP1out.write("rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep) #MCP2out.write("rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep) while running: @@ -108,8 +104,6 @@ def _startPlot(type): if Save_array_data == 1: MCP1.append(a1r) a1r = [] - sMCP1 = sep.join(str(x) for x in MCP1) + line_sep # MCP1.write("%s" + sep % i) - MCP1out.write(sep + "rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep + sMCP1) for j in a2: a2r.append(j) Sum1a2 = 0 @@ -133,8 +127,6 @@ def _startPlot(type): if Save_array_data == 1: MCP2.append(a2r) a2r = [] - sMCP2 = sep.join(str(y) for y in MCP2) + line_sep - MCP2out.write(sep + "rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep + sMCP2) time.sleep(SamplingTime.read()*0.001) if (abs(e-cur)) > 0.00001: v = abs((keithley_2a.read() / ((keithley_1a if (type==1) else keithley_3a).read() ))) @@ -145,7 +137,15 @@ def _startPlot(type): pass print "Done Plotting" if (MCP_1 == 1 or MCP_2 == 1): + output_file_MCP1 = output_path+"MCP1"+file_prefix+"_" + suffix + ".dat" + MCP1out = open(output_file_MCP1, "a+") + sMCP1 = sep.join(str(x) for x in MCP1) + line_sep # MCP1.write("%s" + sep % i) + MCP1out.write(sep + "rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep + sMCP1) MCP1out.close() + output_file_MCP2 = output_path+"MCP2"+file_prefix+"_" + suffix + ".dat" + MCP2out = open(output_file_MCP2, "a+") + sMCP2 = sep.join(str(y) for y in MCP2) + line_sep + MCP2out.write(sep + "rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep + sMCP2) MCP2out.close() def startPlot(type = 1): global task diff --git a/script/EnergyScan-withThreading.py b/script/EnergyScan-withThreading.py index 7b7ae62..a89dd77 100644 --- a/script/EnergyScan-withThreading.py +++ b/script/EnergyScan-withThreading.py @@ -1,6 +1,6 @@ import os import traceback -import thread +import threading ############################PGM+ID1+ID2################################################### if str(SET_OFFSETS) == "1": @@ -57,10 +57,9 @@ task = None running = False def readMCP1(): + global MCP1out MCP1 = [] a1r = [] - output_file_MCP1 = output_path+"MCP1"+file_prefix+"_" + suffix + ".dat" - MCP1out = open(output_file_MCP1, "a+") a1=MCPArray1.read() for i in a1: a1r.append(i) @@ -68,13 +67,13 @@ def readMCP1(): Cam1a1 = 0 Sum2a1 = 0 Cam2a1 = 0 - for i in xrange(0,479): + for i in range(0,479): Sum1a1 = Sum1a1 + a1r[i] - for i in xrange(Cam_start,Cam_end): + for i in range(Cam_start,Cam_end): Cam1a1 = Cam1a1 + a1r[i] - for i in xrange(480,959): + for i in range(480,959): Sum2a1 = Sum2a1 + a1r[i] - for i in xrange(Cam_start+480,Cam_end+480): + for i in range(Cam_start+480,Cam_end+480): Cam2a1 = Cam2a1 + a1r[i] MCP1.append(line_sep) MCP1.append(e) @@ -89,10 +88,9 @@ def readMCP1(): MCP1out.write(sep + "rbkenergy" + sep + "Sum1" + sep + "Sum2" + sep + "Cam1" + sep + "Cam2" + sep + "Array" + line_sep + sMCP1) def readMCP2(): + global MCP2out MCP2 = [] a2r = [] - output_file_MCP2 = output_path+"MCP2"+file_prefix+"_" + suffix + ".dat" - MCP2out = open(output_file_MCP2, "a+") a2=MCPArray2.read() for j in a2: a2r.append(j) @@ -100,13 +98,13 @@ def readMCP2(): Cam1a2 = 0 Sum2a2 = 0 Cam2a2 = 0 - for j in xrange(0,479): + for j in range(0,479): Sum1a2 = Sum1a2 + a2r[j] - for j in xrange(Cam_start,Cam_end): + for j in range(Cam_start,Cam_end): Cam1a2 = Cam1a2 + a2r[j] - for j in xrange(480,959): + for j in range(480,959): Sum2a2 = Sum2a2 + a2r[j] - for j in xrange(Cam_start+480,Cam_end+480): + for j in range(Cam_start+480,Cam_end+480): Cam2a2 = Cam2a2 + a2r[j] MCP2.append(line_sep) MCP2.append(e) @@ -137,10 +135,14 @@ def _startPlot(type): break e = energy.read() if (MCP_1 == 1 or MCP_2 == 1): - threadA = Thread(target = readMCP1) - threadB = Thread(target = readMCP2) - threadA.run() - threadB.run() + output_file_MCP1 = output_path+"MCP1"+file_prefix+"_" + suffix + ".dat" + MCP1out = open(output_file_MCP1, "a+") + output_file_MCP2 = output_path+"MCP2"+file_prefix+"_" + suffix + ".dat" + MCP2out = open(output_file_MCP2, "a+") + threadA = threading.Thread(target=readMCP1) + threadB = threading.Thread(target=readMCP2) + threadA.start() + threadB.start() time.sleep(SamplingTime.read()*0.001) threadA.join() threadB.join()