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

1#! /usr/bin/env python 

2############################################################################### 

3from km3dq_common.config_library import configure_defect 

4 

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. 

10 

11 === Arguments === 

12 - value : diagnosis value for a given type - [integer] 

13 - def_type: defect type ("daq", "operation"...) - [string] 

14 

15 === Output === 

16 - Single string contained all the corresponding defects separated by a 

17 slash 

18 Ex: 'missing_data_dst / jmergefitfailure /' 

19 

20 """ 

21 

22 defects0 = configure_defect() 

23 

24 result = "" 

25 

26 def_type1 = def_type0.replace("def_", "") 

27 

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} / " 

31 

32 return result 

33 

34 

35############################################################################### 

36def decode_defect_file(defect_file_dict, run_nb): 

37 """ 

38 Decode the defect file and returns 

39 

40 === Arguments === 

41 - defect_file_dict: defect dictionnary produced by the read_defect_file 

42 function - [dictionnary] 

43 - run_nb : run number - [integer] 

44 

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 / '}} 

50 

51 """ 

52 

53 run_defect_str = {"str": "", 

54 "dict": {}} 

55 

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 

63 

64 return run_defect_str