mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-04 00:50:42 +02:00
errors are now logged to console instead of log file
This commit is contained in:
parent
015b4add65
commit
4174ccba5f
@ -47,11 +47,15 @@ class Logger {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
Logger() = default;
|
Logger() = default;
|
||||||
explicit Logger(TLogLevel level) : level(level){};
|
explicit Logger(TLogLevel level) : level(level) {};
|
||||||
~Logger() {
|
~Logger() {
|
||||||
// output in the destructor to allow for << syntax
|
// output in the destructor to allow for << syntax
|
||||||
os << RESET << '\n';
|
os << RESET << '\n';
|
||||||
std::clog << os.str() << std::flush; // Single write
|
if (level == TLogLevel::logERROR)
|
||||||
|
std::clog << os.str() << std::flush; // Single write
|
||||||
|
else {
|
||||||
|
std::cout << os.str() << std::flush;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TLogLevel &ReportingLevel() { // singelton eeh
|
static TLogLevel &ReportingLevel() { // singelton eeh
|
||||||
|
@ -28,6 +28,7 @@ from utils_for_test import (
|
|||||||
LOG_PREFIX_FNAME = '/tmp/slsFrameSynchronizer_test'
|
LOG_PREFIX_FNAME = '/tmp/slsFrameSynchronizer_test'
|
||||||
MAIN_LOG_FNAME = LOG_PREFIX_FNAME + '_log.txt'
|
MAIN_LOG_FNAME = LOG_PREFIX_FNAME + '_log.txt'
|
||||||
PULL_SOCKET_PREFIX_FNAME = LOG_PREFIX_FNAME + '_pull_socket_'
|
PULL_SOCKET_PREFIX_FNAME = LOG_PREFIX_FNAME + '_pull_socket_'
|
||||||
|
FRAME_SYNCHRONIZER_PREFIX_FNAME = LOG_PREFIX_FNAME + "_framesynchronizer_"
|
||||||
|
|
||||||
|
|
||||||
def startFrameSynchronizerPullSocket(name, fp):
|
def startFrameSynchronizerPullSocket(name, fp):
|
||||||
@ -36,23 +37,23 @@ def startFrameSynchronizerPullSocket(name, fp):
|
|||||||
startProcessInBackgroundWithLogFile(cmd, fp, fname)
|
startProcessInBackgroundWithLogFile(cmd, fp, fname)
|
||||||
|
|
||||||
|
|
||||||
def startFrameSynchronizer(num_mods, fp):
|
def startFrameSynchronizer(name, num_mods, fp):
|
||||||
cmd = ['slsFrameSynchronizer', str(DEFAULT_TCP_RX_PORTNO), str(num_mods)]
|
cmd = ['slsFrameSynchronizer', str(DEFAULT_TCP_RX_PORTNO), str(num_mods)]
|
||||||
# in 10.0.0
|
# in 10.0.0
|
||||||
#cmd = ['slsFrameSynchronizer', '-p', str(DEFAULT_TCP_RX_PORTNO), '-n', str(num_mods)]
|
#cmd = ['slsFrameSynchronizer', '-p', str(DEFAULT_TCP_RX_PORTNO), '-n', str(num_mods)]
|
||||||
startProcessInBackground(cmd, fp)
|
#startProcessInBackground(cmd, fp)
|
||||||
|
fname = FRAME_SYNCHRONIZER_PREFIX_FNAME + name + '.txt'
|
||||||
|
startProcessInBackgroundWithLogFile(cmd, fp, fname)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
def acquire(fp):
|
def acquire(fp, d):
|
||||||
Log(LogLevel.INFO, 'Acquiring')
|
Log(LogLevel.INFO, 'Acquiring')
|
||||||
Log(LogLevel.INFO, 'Acquiring', fp)
|
Log(LogLevel.INFO, 'Acquiring', fp)
|
||||||
d = Detector()
|
|
||||||
d.acquire()
|
d.acquire()
|
||||||
|
|
||||||
|
|
||||||
def testFramesCaught(name, num_frames):
|
def testFramesCaught(name, d, num_frames):
|
||||||
d = Detector()
|
|
||||||
fnum = d.rx_framescaught[0]
|
fnum = d.rx_framescaught[0]
|
||||||
if fnum != num_frames:
|
if fnum != num_frames:
|
||||||
raise RuntimeException(f"{name} caught only {fnum}. Expected {num_frames}")
|
raise RuntimeException(f"{name} caught only {fnum}. Expected {num_frames}")
|
||||||
@ -61,7 +62,7 @@ def testFramesCaught(name, num_frames):
|
|||||||
Log(LogLevel.INFOGREEN, f'Frames caught test passed for {name}', fp)
|
Log(LogLevel.INFOGREEN, f'Frames caught test passed for {name}', fp)
|
||||||
|
|
||||||
|
|
||||||
def testZmqHeadetTypeCount(name, num_mods, num_frames, fp):
|
def testZmqHeadetTypeCount(name, d, num_mods, num_frames, fp):
|
||||||
|
|
||||||
Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}")
|
Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}")
|
||||||
Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}", fp)
|
Log(LogLevel.INFO, f"Testing Zmq Header type count for {name}", fp)
|
||||||
@ -88,7 +89,6 @@ def testZmqHeadetTypeCount(name, num_mods, num_frames, fp):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
# test if file contents matches expected counts
|
# test if file contents matches expected counts
|
||||||
d = Detector()
|
|
||||||
num_ports_per_module = 1 if name == "gotthard2" else d.numinterfaces
|
num_ports_per_module = 1 if name == "gotthard2" else d.numinterfaces
|
||||||
total_num_frame_parts = num_ports_per_module * num_mods * num_frames
|
total_num_frame_parts = num_ports_per_module * num_mods * num_frames
|
||||||
for htype, expected_count in [("header", num_mods), ("series_end", num_mods), ("module", total_num_frame_parts)]:
|
for htype, expected_count in [("header", num_mods), ("series_end", num_mods), ("module", total_num_frame_parts)]:
|
||||||
@ -110,13 +110,14 @@ def startTestsForAll(args, fp):
|
|||||||
cleanup(fp)
|
cleanup(fp)
|
||||||
startDetectorVirtualServer(server, args.num_mods, fp)
|
startDetectorVirtualServer(server, args.num_mods, fp)
|
||||||
startFrameSynchronizerPullSocket(server, fp)
|
startFrameSynchronizerPullSocket(server, fp)
|
||||||
startFrameSynchronizer(args.num_mods, fp)
|
startFrameSynchronizer(server, args.num_mods, fp)
|
||||||
loadConfig(name=server, rx_hostname=args.rx_hostname, settingsdir=args.settingspath, fp=fp, num_mods=args.num_mods, num_frames=args.num_frames)
|
d = loadConfig(name=server, rx_hostname=args.rx_hostname, settingsdir=args.settingspath, fp=fp, num_mods=args.num_mods, num_frames=args.num_frames)
|
||||||
acquire(fp)
|
acquire(fp, d)
|
||||||
testFramesCaught(server, args.num_frames)
|
testFramesCaught(server, d, args.num_frames)
|
||||||
testZmqHeadetTypeCount(server, args.num_mods, args.num_frames, fp)
|
testZmqHeadetTypeCount(server, d, args.num_mods, args.num_frames, fp)
|
||||||
Log(LogLevel.INFO, '\n')
|
Log(LogLevel.INFO, '\n')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Log(LogLevel.ERROR, f"error msg: {str(e)}")
|
||||||
raise RuntimeException(f'Synchronizer Tests failed') from e
|
raise RuntimeException(f'Synchronizer Tests failed') from e
|
||||||
|
|
||||||
Log(LogLevel.INFOGREEN, 'Passed all synchronizer tests for all detectors \n' + str(args.servers))
|
Log(LogLevel.INFOGREEN, 'Passed all synchronizer tests for all detectors \n' + str(args.servers))
|
||||||
|
@ -109,8 +109,9 @@ def startProcessInBackgroundWithLogFile(cmd, fp, log_file_name):
|
|||||||
Log(LogLevel.INFOBLUE, 'Starting up ' + ' '.join(cmd) + '. Log: ' + log_file_name, fp)
|
Log(LogLevel.INFOBLUE, 'Starting up ' + ' '.join(cmd) + '. Log: ' + log_file_name, fp)
|
||||||
try:
|
try:
|
||||||
with open(log_file_name, 'w') as log_fp:
|
with open(log_file_name, 'w') as log_fp:
|
||||||
subprocess.Popen(cmd, stdout=log_fp, stderr=log_fp, text=True)
|
subprocess.Popen(cmd, stdout=log_fp, stderr=sys.stderr, text=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Log(LogLevel.ERROR, f"error msg: {str(e)}")
|
||||||
raise RuntimeException(f'Failed to start {cmd}:{str(e)}') from e
|
raise RuntimeException(f'Failed to start {cmd}:{str(e)}') from e
|
||||||
|
|
||||||
|
|
||||||
@ -120,7 +121,7 @@ def runProcessWithLogFile(name, cmd, fp, log_file_name):
|
|||||||
Log(LogLevel.INFOBLUE, 'Cmd: ' + ' '.join(cmd), fp)
|
Log(LogLevel.INFOBLUE, 'Cmd: ' + ' '.join(cmd), fp)
|
||||||
try:
|
try:
|
||||||
with open(log_file_name, 'w') as log_fp:
|
with open(log_file_name, 'w') as log_fp:
|
||||||
subprocess.run(cmd, stdout=log_fp, stderr=log_fp, check=True, text=True)
|
subprocess.run(cmd, stdout=log_fp, stderr=sys.stderr, check=True, text=True)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -138,6 +139,8 @@ def runProcessWithLogFile(name, cmd, fp, log_file_name):
|
|||||||
|
|
||||||
def startDetectorVirtualServer(name :str, num_mods, fp):
|
def startDetectorVirtualServer(name :str, num_mods, fp):
|
||||||
for i in range(num_mods):
|
for i in range(num_mods):
|
||||||
|
subprocess.run(["which", name + "DetectorServer_virtual"])
|
||||||
|
|
||||||
port_no = SERVER_START_PORTNO + (i * 2)
|
port_no = SERVER_START_PORTNO + (i * 2)
|
||||||
cmd = [name + 'DetectorServer_virtual', '-p', str(port_no)]
|
cmd = [name + 'DetectorServer_virtual', '-p', str(port_no)]
|
||||||
startProcessInBackground(cmd, fp)
|
startProcessInBackground(cmd, fp)
|
||||||
@ -156,7 +159,7 @@ def connectToVirtualServers(name, num_mods):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeException(f'Could not create Detector object for {name}. Error: {str(e)}') from e
|
raise RuntimeException(f'Could not create Detector object for {name}. Error: {str(e)}') from e
|
||||||
|
|
||||||
counts_sec = 5
|
counts_sec = 100
|
||||||
while (counts_sec != 0):
|
while (counts_sec != 0):
|
||||||
try:
|
try:
|
||||||
d.virtual = [num_mods, SERVER_START_PORTNO]
|
d.virtual = [num_mods, SERVER_START_PORTNO]
|
||||||
@ -201,6 +204,8 @@ def loadConfig(name, rx_hostname, settingsdir, fp, num_mods = 1, num_frames = 1)
|
|||||||
d.frames = num_frames
|
d.frames = num_frames
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise RuntimeException(f'Could not load config for {name}. Error: {str(e)}') from e
|
raise RuntimeException(f'Could not load config for {name}. Error: {str(e)}') from e
|
||||||
|
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def ParseArguments(description, default_num_mods=1):
|
def ParseArguments(description, default_num_mods=1):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user