some performance improvements

This commit is contained in:
2025-10-24 13:15:19 +02:00
parent 8fe913e125
commit 6a86b79533

View File

@@ -43,7 +43,7 @@ MISSED_PACKETS = -9 # All modules appear to miss the first time due to initialis
def print_monitor_rates():
while True:
for i in range(MONITORS):
msg = f"Monitor {i}: {time_window[i].qsize() / WINDOWSECONDS} cts/s"
msg = f"Monitor {i+1}: {time_window[i].qsize() / WINDOWSECONDS} cts/s"
try:
earliest = time_window[i].queue[0]
newest = max(time_window[i].queue)
@@ -162,7 +162,7 @@ def event_producer():
b_ptr += 1
nt = time.time()
if b_ptr == b_size or nt - st > 0.1:
if b_ptr == b_size or nt - st > 0.001:
st = nt
if b_ptr > 0:
@@ -183,8 +183,8 @@ def event_producer():
partition = 0,
)
if poll_cnt % 1000 == 0:
prod.poll(0)
# if poll_cnt % 1000 == 0:
prod.poll(0)
poll_cnt = (poll_cnt + 1) % 1000
threading.Thread(target=event_producer, daemon=True).start()
@@ -214,13 +214,13 @@ def monitor_producer():
monitor_time[d_id] = timestamp
nt = time.time()
if nt - st > 0.1:
if nt - st > 0.05:
st = nt
for i in range(MONITORS):
if monitor_buffer[d_id]:
message = streaming_data_types.serialise_f142(
source_name = f"monitor{d_id}",
source_name = f"monitor{d_id+1}",
value = monitor_buffer[d_id],
# ns resolution (supposed to be past epoch, not what the detector returns though)
timestamp_unix_ns = monitor_time[d_id] * 100 # send time of last monitor
@@ -249,6 +249,8 @@ start_time = time.time()
module_counts = [0 for i in range(10)]
EVENTS = 0
while True:
data, addr = sock.recvfrom(2056) # Buffer size is 1024 bytes
raw_header = data[:42]
@@ -296,8 +298,12 @@ while True:
x_pixels = 128
y_pixels = 128
amplitude = ( event[5] << 1 ) | ( event[4] >> 7 )
x = ( event[3] << 5 | event[2] >> 3 ) & 0x3ff
y = ( event[4] << 3 | event[3] >> 5 ) & 0x3ff
# The DMC StreamHistogrammer setup currently expects each module to
# be 128 * 128 pixels but the resolution in the packages is
# actually 10bit. We remove the lowest 3 bits.
x = (( (event[3] & 0x1f) << 5 | (event[2] & 0xf8) >> 3 ) & 0x3ff) >> 3
y = (( (event[4] & 0x7f) << 3 | (event[3] & 0xe0) >> 5 ) & 0x3ff) >> 3
event_timestamp = timestamp + ( ( event[2] << 16 ) & 0x7 ) | ( event[1] << 8 ) | event[0]
# print(f'Neutron event {event_timestamp * 1e-7}s: {amplitude}, x: {x}, y: {y}')
@@ -324,7 +330,13 @@ while True:
# event_average_rate = w * dt + event_average_rate * (1 - w)
# event_last_timestamp = event_timestamp_seconds
# EVENTS += 1
# a = (mcpd_id - 1) * x_pixels * y_pixels + x_pixels * x + y
# print((EVENTS, x, y, a, a < 128 * 128 * 9, mcpd_id))
# if not a < 128 * 128 * 9:
# print((event[3], event[3] << 5, event[2], event[2] >> 3))
event_queue.put_nowait((
(mcpd_id-1) * x_pixels * y_pixels + x_pixels * x + y,
(mcpd_id - 1) * x_pixels * y_pixels + x_pixels * x + y,
event_timestamp
))