moved FileHandler into utils

This commit is contained in:
2025-10-15 12:16:57 +02:00
parent 65509fd17c
commit f968497895
3 changed files with 30 additions and 25 deletions

View File

@@ -1,8 +1,9 @@
import argparse
import os
import zmq
from utils import FileHandler
FLAGS = 0
OUTPUT_DIR_NAME = "/gpfs/photonics/swissfel/buffer/dap/data"
@@ -64,30 +65,6 @@ def accumulate(_accumulator_host, accumulator_port): #TODO: accumulator_host is
class FileHandler:
def __init__(self):
self.file = None
def switch(self, fname):
self.close()
self.open(fname)
def open(self, fname):
dname = os.path.dirname(fname)
os.makedirs(dname, exist_ok=True)
self.file = open(fname, "a")
def close(self):
if self.file:
self.file.close()
def flush(self):
if self.file:
self.file.flush()
if __name__ == "__main__":

View File

@@ -2,6 +2,7 @@
from .aggregator import Aggregator
from .bits import read_bit
from .bufjson import BufferedJSON
from .filehandler import FileHandler
from .randskip import randskip

27
dap/utils/filehandler.py Normal file
View File

@@ -0,0 +1,27 @@
import os
class FileHandler:
def __init__(self):
self.file = None
def switch(self, fname):
self.close()
self.open(fname)
def open(self, fname):
dname = os.path.dirname(fname)
os.makedirs(dname, exist_ok=True)
self.file = open(fname, "a")
def close(self):
if self.file:
self.file.close()
def flush(self):
if self.file:
self.file.flush()