foxsi / GSE-FOXSI-4

GSE for calibration and flight operation of FOXSI-4
Other
0 stars 1 forks source link

Write a fast, batched, log file reader #2

Open thanasipantazides opened 1 year ago

thanasipantazides commented 1 year ago

Rationale

This GSE should run in its own process, with the ListenerLogger running in the "background". This GSE will read the log file written by ListenerLogger, transform the packet contents, render plots on the screen, take user input, etc. A key part of this is reading the log file.

Description of the reader

This log file reader should ingest blocks of data (in contrast to reading the log line-by-line as it is updated), returning some structured data that informs the caller:

Since there are many packets per batch read, we should decide how packets should be sorted. Options: by detector, by time, by flag, etc. Maybe good to return a DataFrame-like structure so the caller can filter as needed.

Since the log file will be very large (several GB), we don't want to load the whole file into memory for every read operation. Instead, should use syntax like this:

batch = []
with open("log_file.log", "r") as file:
    for i, line in enumerate(file):
        if i > last_line_read:
            batch.append(line)
            # do other stuff to the line?

But figure out what happens at the end of the file. By the way, this should be safe to run while ListenerLogger is writing, since the open() is read-only.

Todo