Coverage for src/km3dq_common/lw_db_library.py: 0%
18 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-25 11:58 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-25 11:58 +0000
1#! /usr/bin/env python
2###############################################################################
3from km3dq_common.config_library import configure_defect
5###############################################################################
6def decode_defect_diag_byte(value, def_type0):
7 """
8 Decodes the assigned defect (integer) for a given type and returns a single
9 string.
11 === Arguments ===
12 - value : diagnosis value for a given type - [integer]
13 - def_type: defect type ("daq", "operation"...) - [string]
15 === Output ===
16 - Single string contained all the corresponding defects separated by a
17 slash
18 Ex: 'missing_data_dst / jmergefitfailure /'
20 """
22 defects0 = configure_defect()
24 result = ""
26 def_type1 = def_type0.replace("def_", "")
28 for i_bit in defects0['bit'][def_type1]:
29 if (int(value) >> defects0['bit'][def_type1][i_bit]) & 1:
30 result += f"{i_bit} / "
32 return result
35###############################################################################
36def decode_defect_file(defect_file_dict, run_nb):
37 """
38 Decode the defect file and returns
40 === Arguments ===
41 - defect_file_dict: defect dictionnary produced by the read_defect_file
42 function - [dictionnary]
43 - run_nb : run number - [integer]
45 === Output ===
46 - Defects assigned to this run. Both a dict and string (to be used
47 in html - See qaqcprocessing/dst-process.py) are returned.
48 Ex: {'str': '<b> def_data_processing </b>: missing_data_dst / ',
49 'dict': {'def_data_processing': 'missing_data_dst / '}}
51 """
53 run_defect_str = {"str": "",
54 "dict": {}}
56 for i_def_type in defect_file_dict.keys():
57 if run_nb not in defect_file_dict[i_def_type]:
58 continue
59 diag = decode_defect_diag_byte(defect_file_dict[i_def_type][run_nb],
60 i_def_type)
61 run_defect_str['str'] += (f"<b> {i_def_type} </b>: {diag}")
62 run_defect_str['dict'][i_def_type] = diag
64 return run_defect_str