Belle II Software development
submit_collector.py
1#!/usr/bin/env python3
2
3
10
11import sys
12from pathlib import Path
13import time
14from caf import backends
15
16# Add timestamp to all INFO messages
17from basf2 import B2INFO, logging, LogLevel, LogInfo
18currentInfo = logging.get_info(LogLevel.INFO)
19logging.set_info(LogLevel.INFO, currentInfo | LogInfo.TIMESTAMP)
20
21
22probcut = float(sys.argv[1]) if len(sys.argv) == 2 else 0.001
23
24root_dir = 'rootfile'
25input_files = []
26with open('runlist') as runlist:
27 lines = runlist.readlines()
28 for line in lines:
29 input_files.append(line.rstrip('\n'))
30
31# data_dir = '/hsm/belle2/bdata/Data/Raw/e0002/'
32
33# input_files = glob.glob(data_dir + "*/*/cosmic.*.root")
34# print(input_files)
35# exit(1)
36
37
42job1 = backends.Job("CDC_Colllector")
43job1.output_dir = str(Path(root_dir).absolute())
44job1.working_dir = str(Path(root_dir).absolute())
45
46# This is the command that gets run inside the batch job
47job1.cmd = ['basf2', 'run_collector.py', str(probcut)]
48# Need to copy in the steering file so that each subjob has access to it in its working dir
49job1.input_sandbox_files.append("run_collector.py")
50# Your config file may be necessary for the run_collector.py in each job, so we copy it to the working directory
51# job1.input_sandbox_files.append("location")
52# You can either create a list of input files manually e.g. with glob
53# import glob
54
55# input_files = [data_dir + f for f in runs]
56# This lets us reduce the number of input files for testing purposes
57# job1.input_files = input_files[:5]
58job1.input_files = input_files
59# Or you could just give the wildcard expansions directly in the input files of the job
60# job1.input_files = [data_dir+"/cr*.root"]
61
62# You can choose how many input files to send to each subjob (-1 means all to one main job)
63job1.max_files_per_subjob = 1
64# Choose your queue
65job1.backend_args['queue'] = 's'
66
67
68# Here we submit the job to the batch system. Subjobs for the input data files are automatically created
69lsf = backends.LSF()
70lsf.submit(job1)
71# Here we start waiting for the overall job to complete
72ready = False
73while not ready:
74 B2INFO("Are we done?")
75 ready = job1.ready()
76 B2INFO("Not done yet, will sleep")
77 time.sleep(60)
78
79B2INFO("Finished")