This commit is contained in:
2024-03-22 19:23:50 +01:00
parent a33b0a693a
commit 7c5f5198c9

View File

@ -31,10 +31,8 @@ def accumulate(_accumulator_host, accumulator_port): #TODO: accumulator_host is
poller.register(accumulator_socket, zmq.POLLIN)
run_name_before = "very_first_start"
fNameOutput = f"{OUTPUT_DIR_NAME}/{run_name_before}.dap"
if not os.path.isdir(os.path.dirname(fNameOutput)):
os.makedirs(os.path.dirname(fNameOutput))
outputDap = open(fNameOutput, "a")
fname_output = f"{OUTPUT_DIR_NAME}/{run_name_before}.dap"
output_dap = open_new_file(fname_output)
n_frames_received = 0
@ -42,29 +40,37 @@ def accumulate(_accumulator_host, accumulator_port): #TODO: accumulator_host is
events = dict(poller.poll(10)) # in accumulator check for worker output every 0.01 seconds
if accumulator_socket not in events:
outputDap.flush() # may be too intensive
output_dap.flush() # may be too intensive
continue
results = accumulator_socket.recv_json(FLAGS)
n_frames_received += 1
pulse_id = results.get("pulse_id", 0)
run_name = str(pulse_id//10000*10000)
detector = results.get("detector_name", "")
pulse_id = results.get("pulse_id", 0)
run_name = str(pulse_id // 10000 * 10000)
if run_name != run_name_before:
run_name_before = run_name
outputDap.close()
fNameOutput = f"{OUTPUT_DIR_NAME}/{detector}/{run_name_before}.dap"
if not os.path.isdir(os.path.dirname(fNameOutput)):
os.makedirs(os.path.dirname(fNameOutput))
outputDap = open(fNameOutput, "a")
fname_output = f"{OUTPUT_DIR_NAME}/{detector}/{run_name_before}.dap"
output_dap.close()
output_dap = open_new_file(fname_output)
pr_rois = results.get("roi_intensities", [])
print(pulse_id, results.get("is_good_frame", -1), results.get("is_hit_frame", False), results.get("number_of_spots", -1), results.get("laser_on", False), *pr_rois, file=outputDap)
res_is_good_frame = results.get("is_good_frame", -1)
res_is_hit_frame = results.get("is_hit_frame", False)
res_number_of_spots = results.get("number_of_spots", -1)
res_laser_on = results.get("laser_on", False)
res_roi_intensities = results.get("roi_intensities", [])
print(pulse_id, res_is_good_frame, res_is_hit_frame, res_number_of_spots, res_laser_on, *res_roi_intensities, file=output_dap)
def open_new_file(fname):
dname = os.path.dirname(fname)
os.makedirs(dname, exist_ok=True)
return open(fname, "a")