Coverage for src/km3dq_common/loop_exec.py: 0%

47 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-14 11:06 +0000

1#! /usr/bin/env python 

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

3# Loop on all detectors/tag/defect tag directories to execute a shell command 

4# 

5# - -location km3dq_perf 

6# Loop on all detectors [det] km3dq_perf/[site]/[det]/ 

7# 

8# - - location km3dq_perf_dq_tag -t [dq tag] 

9# Loop on all detectors [det] km3dq_perf/[site]/[det]/[dq tag] 

10# 

11# - -location km3dq_lw_db 

12# Loop on all detectors [det] km3dq_lw_db/[site]/[det]/ 

13# 

14# - -location km3dq_lw_db_defect_tag -d [defect tag] 

15# Loop on all detectors [det] km3dq_lw_db/[site]/[det]/[defect tag] 

16 

17 

18import os 

19import sys 

20import argparse 

21 

22from .config_library import configure_dataquality_tag 

23 

24############################################################################### 

25parser = argparse.ArgumentParser(description="") 

26parser.add_argument( 

27 "-s", 

28 "--site", 

29 dest="site", 

30 required=True, 

31 help=("Site. List of detectors derived from the DQ tag"), 

32 action="store", 

33) 

34parser.add_argument( 

35 "-t", 

36 "--dq_tag", 

37 dest="dq_tag", 

38 default="", 

39 required=True, 

40 help="Data-quality tag.", 

41 action="store", 

42) 

43parser.add_argument( 

44 "-d", 

45 "--defect_tag", 

46 dest="defect_tag", 

47 default="", 

48 help="Defect tag.", 

49 action="store", 

50) 

51parser.add_argument( 

52 "-l", 

53 "--location", 

54 dest="location", 

55 default="", 

56 required=True, 

57 help=( 

58 "Location: km3dq_perf, km3dq_perf_dq_tag, " 

59 "km3dq_lw_db, km3dq_lw_db_defect_tag" 

60 ), 

61 action="store", 

62) 

63parser.add_argument( 

64 "-e", "--execute", dest="execute", help=("Execute"), action="store_true" 

65) 

66 

67 

68args = parser.parse_args() 

69options = args.__dict__ 

70site = options["site"] 

71 

72dq_tag = configure_dataquality_tag(options["dq_tag"]) 

73 

74det_list = dq_tag["det"][site] 

75 

76first = True 

77 

78for i_det in det_list: 

79 print(f"{i_det}===========") 

80 

81 if options["location"] == "km3dq_perf": 

82 dir_path = ( 

83 "/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/" f"{site}/{i_det}" 

84 ) 

85 # To be edited by hand for your purposes 

86 cmd = ( 

87 f"cd {dir_path};" 

88 "mv mass_processing mp1_0_1-d2024_1-g24;" 

89 "mv mass_processing_veto_sparks mp1_0_1-d2024_1-g24_vsparks;" 

90 ) 

91 

92 elif all((options["location"] == "km3dq_perf_dq_tag", options["dq_tag"] != "")): 

93 dir_path = ( 

94 "/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/" 

95 f"{site}/{i_det}/{options['dq_tag']}" 

96 ) 

97 # To be edited by hand for your purposes 

98 miss_dst_file = f"{dir_path}/processing/missing_dst.txt" 

99 if os.path.exists(miss_dst_file) is False: 

100 print(f"{miss_dst_file} missing") 

101 continue 

102 cmd = ( 

103 f"cd {dir_path};" 

104 f"sed -e 's/hpss/sps/g' {miss_dst_file} > tmp;" 

105 f"mv tmp {miss_dst_file}" 

106 ) 

107 

108 elif options["location"] == "km3dq_lw_db": 

109 dir_path = ( 

110 "/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/" f"{site}/{i_det}" 

111 ) 

112 # To be edited by hand for your purposes 

113 cmd = f"cd {dir_path}/Defects;mv def-neutrino2024 d2024_0" 

114 

115 elif all( 

116 (options["location"] == "km3dq_lw_db_defect_tag", options["defect_tag"] != "") 

117 ): 

118 dir_path = ( 

119 "/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/" 

120 f"{site}/{i_det}/Defects/{options['defect_tag']}" 

121 ) 

122 # To be edited by hand for your purposes 

123 cmd = f"cd {dir_path};ls" 

124 

125 else: 

126 print("Wrong -l argument") 

127 sys.exit() 

128 

129 print(f"Directory: {dir_path}") 

130 print(f"Command: {cmd}") 

131 if options["execute"]: 

132 os.popen(cmd) 

133 print("Done!") 

134 if first: 

135 confirm = input("Is it as expected [YES/NO]?)") 

136 if confirm == "YES": 

137 first = False 

138 else: 

139 sys.exit() 

140 else: 

141 print("No execution. Choose -e if you want to.")