-
Notifications
You must be signed in to change notification settings - Fork 0
/
prm_gui.py
executable file
·126 lines (95 loc) · 2.86 KB
/
prm_gui.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python3
'''
The main DAQ GUI driver
'''
import os
import sys
import time
import argparse
from PyQt5 import QtGui, QtWidgets
import yaml
import qdarkstyle
from sbndprmdaq.mainwindow import MainWindow
from sbndprmdaq.prmlogger import get_logging, PrMLogWidget
os.environ["QT_ENABLE_HIGHDPI_SCALING"] = "1"
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
os.environ["QT_SCALE_FACTOR"] = "1"
parser = argparse.ArgumentParser(description='SBND Purity Monitor DAQ')
parser.add_argument('--mock', action='store_true',
default=False,
help='If true, runs a mock application for debugging purposes.')
parser.add_argument('--datafiles',
default='',
help='Path where data files will be saved.')
parser.add_argument('--logfile',
default='prm_log.txt',
help='File name where logs will be saved.')
args = parser.parse_args()
print(args)
#
# Start the logger
#
logging = get_logging(args.logfile)
logger = logging.getLogger(__name__)
logger.info('SBND Purity Monitor starts.')
#
# Get the settings from the settings file
#
settings = os.path.join(os.path.dirname(__file__), 'settings.yaml')
with open(settings, encoding="utf-8") as file:
config = yaml.load(file, Loader=yaml.FullLoader)
if args.datafiles:
config["data_files_path"] = args.datafiles
if args.mock:
config['check_pmt_hv'] = False
config['check_lar_level'] = False
config['data_storage'] = False
config['populate_dataframe'] = False
config['summary_plot']['post_to_ecl'] = False
print('Config:', yaml.dump(config), sep='\n')
# logger.info(yaml.dump(config))
#
# Check Hertbeat
#
heartbeat_file_name = config['data_files_path'] + '/heartbeat.txt'
if os.path.exists(heartbeat_file_name):
with open(heartbeat_file_name, encoding="utf-8") as f:
for line in f:
time_stamp = float(line)
if abs(time_stamp - time.time()) < 5:
print('timestamp :', time_stamp)
print('time.time():', time.time())
print('Another DAQ is running on this data directory:', config['data_files_path'])
print('Either stop the other DAQ, or use a different path.')
sys.exit(0)
#
# Construct the GUI
#
app = QtWidgets.QApplication(sys.argv)
logs = PrMLogWidget()
window = MainWindow(logs=logs, config=config)
app.setStyleSheet(qdarkstyle.load_stylesheet(qt_api='pyqt5'))
window.show()
#
# Construct the manager
#
if args.mock:
from sbndprmdaq.mock_manager import MockPrMManager
manager = MockPrMManager(config, window)
else:
from sbndprmdaq.manager import PrMManager
manager = PrMManager(config, window)
# manager.test()
#
# Pass the manager to the mainwindow
#
window.set_manager(manager)
#
# Set a unique font
#
font = QtGui.QFont("Tahoma", 8)
app.setFont(font)
#
# Take it away
#
app.exec_()