Coverage for src/km3dq_common/loop_exec.py: 0%
47 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###############################################################################
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]
18import os
19import sys
20import argparse
22from km3dq_common.config_library import configure_dataquality_tag
24###############################################################################
25parser = argparse.ArgumentParser(description='')
26parser.add_argument('-s', '--site',
27 dest='site',
28 required=True,
29 help=('Site. List of detectors derived from the DQ tag'),
30 action='store')
31parser.add_argument("-t", "--dq_tag",
32 dest="dq_tag",
33 default="",
34 required=True,
35 help="Data-quality tag.", action="store")
36parser.add_argument("-d", "--defect_tag",
37 dest="defect_tag",
38 default="",
39 help="Defect tag.", action="store")
40parser.add_argument("-l", "--location",
41 dest="location",
42 default="",
43 required=True,
44 help=("Location: km3dq_perf, km3dq_perf_dq_tag, "
45 "km3dq_lw_db, km3dq_lw_db_defect_tag"),
46 action="store")
47parser.add_argument("-e", "--execute",
48 dest="execute",
49 help=("Execute"),
50 action="store_true")
53args = parser.parse_args()
54options = args.__dict__
55site = options['site']
57dq_tag = configure_dataquality_tag(options["dq_tag"])
59det_list = dq_tag['det'][site]
61first = True
63for i_det in det_list:
64 print(f"{i_det}===========")
66 if options["location"] == "km3dq_perf":
67 dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/"
68 f"{site}/{i_det}")
69 # To be edited by hand for your purposes
70 cmd = (f"cd {dir_path};"
71 "mv mass_processing mp1_0_1-d2024_1-g24;"
72 "mv mass_processing_veto_sparks mp1_0_1-d2024_1-g24_vsparks;")
74 elif all((options["location"] == "km3dq_perf_dq_tag",
75 options["dq_tag"] != "")):
76 dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/"
77 f"{site}/{i_det}/{options['dq_tag']}")
78 # To be edited by hand for your purposes
79 miss_dst_file = f"{dir_path}/processing/missing_dst.txt"
80 if os.path.exists(miss_dst_file) is False:
81 print(f"{miss_dst_file} missing")
82 continue
83 cmd = (f"cd {dir_path};"
84 f"sed -e 's/hpss/sps/g' {miss_dst_file} > tmp;"
85 f"mv tmp {miss_dst_file}")
87 elif options["location"] == "km3dq_lw_db":
88 dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/"
89 f"{site}/{i_det}")
90 # To be edited by hand for your purposes
91 cmd = f"cd {dir_path}/Defects;mv def-neutrino2024 d2024_0"
93 elif all((options["location"] == "km3dq_lw_db_defect_tag",
94 options["defect_tag"] != "")):
95 dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/"
96 f"{site}/{i_det}/Defects/{options['defect_tag']}")
97 # To be edited by hand for your purposes
98 cmd = f"cd {dir_path};ls"
100 else:
101 print("Wrong -l argument")
102 sys.exit()
104 print(f"Directory: {dir_path}")
105 print(f"Command: {cmd}")
106 if options["execute"]:
107 os.popen(cmd)
108 print("Done!")
109 if first:
110 confirm = input("Is it as expected [YES/NO]?)")
111 if confirm == "YES":
112 first = False
113 else:
114 sys.exit()
115 else:
116 print("No execution. Choose -e if you want to.")