19from caf
import backends
20from pathlib
import Path
21from caf.utils
import IoV
24_tempdir_name =
'tmp_create_mc'
30_tag =
'Calibration_Offline_Development'
33_bg =
'/group/belle2/BGFile/OfficialBKG/15thCampaign/phase2'
36def run_job_submission(backend, mc_iov_list):
41 for mc_iov
in mc_iov_list:
42 for setNo
in range(0, _number_of_sets):
43 expNo = mc_iov.exp_low
44 runNo = mc_iov.run_low
45 job = backends.Job(f
"Create_Exp_{expNo}_Run_{runNo}_Set_{setNo}")
46 job.output_dir = str(Path(_tempdir_name, job.name).absolute())
47 job.working_dir = str(Path(_tempdir_name, job.name).absolute())
59 job.input_sandbox_files.append(
"create_mcrun.py")
64 if isinstance(backend, backends.LSF):
65 job.backend_args[
'queue'] =
's'
66 elif isinstance(backend, backends.PBS):
67 job.backend_args[
'queue'] =
'short'
75 from basf2
import B2INFO
81 ready = all(job.ready()
for job
in jobs)
82 B2INFO(
"Not finished all jobs yet")
87def main(backend_choice, mc_iov_list, output_dir):
89 if backend_choice ==
"qsub":
90 backend = backends.PBS()
91 elif backend_choice ==
"bsub":
92 backend = backends.LSF()
93 elif backend_choice ==
"local":
94 backend = backends.Local(max_processes=20)
96 print(
"How did I get here?")
98 run_job_submission(backend, mc_iov_list)
99 if backend_choice ==
'local':
105 output_files = glob.glob(str(Path(_tempdir_name).absolute()) +
'/**/beam*.root')
109 for file_name
in output_files:
110 shutil.move(file_name, output_dir)
113if __name__ ==
"__main__":
116 parser = argparse.ArgumentParser(description=
"Submit jobs for creattion of SimHits for a run with user specified ExpRuns")
117 parser.add_argument(
'--outputdir', default=
'pxd_mc_phase2', type=str,
118 help=
'Add all simulated files to this folder. Create it if it does not exist.')
119 parser.add_argument(
'--backend', default=
'local', type=str, help=
'Where <backend> is one of: local, qsub, bsub.')
120 parser.add_argument(
'--runLow', default=0, type=int, help=
'Compute mask for specific IoV')
121 parser.add_argument(
'--runHigh', default=-1, type=int, help=
'Compute mask for specific IoV')
122 parser.add_argument(
'--expNo', default=3, type=int, help=
'Compute mask for specific IoV')
123 args = parser.parse_args()
126 output_dir = str(Path(args.outputdir).absolute())
129 if not os.path.exists(output_dir):
130 os.makedirs(output_dir)
133 iov_to_calibrate = IoV(exp_low=args.expNo, run_low=args.runLow, exp_high=args.expNo, run_high=args.runHigh)
136 with open(
"file_iov_map.pkl",
'br')
as map_file:
137 files_to_iovs = pickle.load(map_file)
140 data_iov_set = set(files_to_iovs.values())
144 for data_iov
in data_iov_set:
145 if iov_to_calibrate.contains(data_iov):
146 mc_iov_list.append(data_iov)
148 print(f
'Number selected iovs for mc generation : {len(mc_iov_list)}')
150 main(args.backend, mc_iov_list, output_dir)