Source code for km3dq_common.loop_exec

#! /usr/bin/env python
###############################################################################
# Loop on all detectors/tag/defect tag directories to execute a shell command
#
# - -location km3dq_perf
# Loop on all detectors [det] km3dq_perf/[site]/[det]/
#
# - - location km3dq_perf_dq_tag -t [dq tag]
# Loop on all detectors [det] km3dq_perf/[site]/[det]/[dq tag]
#
# - -location km3dq_lw_db
# Loop on all detectors [det] km3dq_lw_db/[site]/[det]/
#
# - -location km3dq_lw_db_defect_tag -d [defect tag]
# Loop on all detectors [det] km3dq_lw_db/[site]/[det]/[defect tag]


import os
import sys
import argparse

from km3dq_common.config_library import configure_dataquality_tag

###############################################################################
[docs] parser = argparse.ArgumentParser(description='')
parser.add_argument('-s', '--site', dest='site', required=True, help=('Site. List of detectors derived from the DQ tag'), action='store') parser.add_argument("-t", "--dq_tag", dest="dq_tag", default="", required=True, help="Data-quality tag.", action="store") parser.add_argument("-d", "--defect_tag", dest="defect_tag", default="", help="Defect tag.", action="store") parser.add_argument("-l", "--location", dest="location", default="", required=True, help=("Location: km3dq_perf, km3dq_perf_dq_tag, " "km3dq_lw_db, km3dq_lw_db_defect_tag"), action="store") parser.add_argument("-e", "--execute", dest="execute", help=("Execute"), action="store_true")
[docs] args = parser.parse_args()
[docs] options = args.__dict__
[docs] site = options['site']
[docs] dq_tag = configure_dataquality_tag(options["dq_tag"])
[docs] det_list = dq_tag['det'][site]
[docs] first = True
for i_det in det_list: print(f"{i_det}===========") if options["location"] == "km3dq_perf":
[docs] dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/" f"{site}/{i_det}")
# To be edited by hand for your purposes cmd = (f"cd {dir_path};" "mv mass_processing mp1_0_1-d2024_1-g24;" "mv mass_processing_veto_sparks mp1_0_1-d2024_1-g24_vsparks;") elif all((options["location"] == "km3dq_perf_dq_tag", options["dq_tag"] != "")): dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_perf/" f"{site}/{i_det}/{options['dq_tag']}") # To be edited by hand for your purposes miss_dst_file = f"{dir_path}/processing/missing_dst.txt" if os.path.exists(miss_dst_file) is False: print(f"{miss_dst_file} missing") continue cmd = (f"cd {dir_path};" f"sed -e 's/hpss/sps/g' {miss_dst_file} > tmp;" f"mv tmp {miss_dst_file}") elif options["location"] == "km3dq_lw_db": dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/" f"{site}/{i_det}") # To be edited by hand for your purposes cmd = f"cd {dir_path}/Defects;mv def-neutrino2024 d2024_0" elif all((options["location"] == "km3dq_lw_db_defect_tag", options["defect_tag"] != "")): dir_path = ("/pbs/home/t/trocme/KM3Net/infrastructure/km3dq_lw_db/" f"{site}/{i_det}/Defects/{options['defect_tag']}") # To be edited by hand for your purposes cmd = f"cd {dir_path};ls" else: print("Wrong -l argument") sys.exit() print(f"Directory: {dir_path}") print(f"Command: {cmd}") if options["execute"]: os.popen(cmd) print("Done!") if first: confirm = input("Is it as expected [YES/NO]?)") if confirm == "YES": first = False else: sys.exit() else: print("No execution. Choose -e if you want to.")