This repository has been archived by the owner on Dec 2, 2022. It is now read-only.
forked from hschellman/LArWrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_dd_jobs.py
137 lines (117 loc) · 4.9 KB
/
submit_dd_jobs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
from metacat.webapi import MetaCatClient
import sys
from time import sleep
import os
from data_dispatcher.api import DataDispatcherClient
from argparse import ArgumentParser as ap
import subprocess
if __name__ == '__main__':
parser = ap()
parser.add_argument('--project_only', action='store_true')
parser.add_argument('--dataset', type=str, default=None)
parser.add_argument('--namespace', type=str, default=None)
parser.add_argument('--query_limit', type=str, default=None)
parser.add_argument('--query_skip', type=str, default=None)
parser.add_argument('--njobs', type=int, default=1)
parser.add_argument('--load_limit', type=int, default=None)
parser.add_argument('--fcl', type=str, default='evd_protoDUNE.fcl')
parser.add_argument('--nevents', type=int, default=-1)
parser.add_argument('--output_str', type=str, default='"*reco.root"')
parser.add_argument('--output_dataset', type=str, default='dd-interactive-tests')
parser.add_argument('--output_namespace', type=str, default='dc4-hd-protodune')
parser.add_argument('--metacat_user', type=str, default='calcuttj')
parser.add_argument('--blacklist', type=str, nargs='+')
parser.add_argument('--project', type=int, default=None)
parser.add_argument('--dry_run', action='store_true')
args = parser.parse_args()
mc_client = MetaCatClient('https://metacat.fnal.gov:9443/dune_meta_demo/app')
dd_client = DataDispatcherClient(
server_url='https://metacat.fnal.gov:9443/dune/dd/data',
auth_server_url='https://metacat.fnal.gov:8143/auth/dune')
dd_client.login_x509(os.environ['USER'],
os.environ['X509_USER_PROXY'])
print(args.blacklist)
if (not args.project) and args.dataset and args.namespace:
##build up query
query = 'files from %s where namespace="%s" ordered'%(args.dataset, args.namespace)
if args.query_skip: query += ' skip %s'%args.query_skip
if args.query_limit: query += ' limit %s'%args.query_limit
print(query)
#query metacat
query_files = [i for i in mc_client.query(query)]
#print(query_files)
#check size
nfiles_in_dataset = len(query_files)
if nfiles_in_dataset == 0:
sys.stderr.write("Ignoring launch request on empty metacat query")
sys.stderr.write("Query: %s"%query)
sys.exit(1)
#make project in data dispatcher
proj_dict = dd_client.create_project(query_files, query=query)
dd_proj_id = proj_dict['project_id']
print('Project ID:', dd_proj_id)
if args.project_only:
print('Only making project. Exiting now')
exit()
elif args.project and not (args.dataset and args.namespace):
dd_proj_id = args.project
else:
sys.stderr.write("Need to provide project OR dataset & namespace\n")
sys.exit(1)
if args.njobs > 10000:
njobs = [10000]*int(args.njobs/10000) + [args.njobs%10000]
else:
njobs = [args.njobs]
print(njobs)
count = 0
for nj in njobs:
cmd = 'fife_launch -c byhand.cfg ' \
f'-Oglobal.load_limit={args.load_limit} ' \
f'-Oglobal.project={dd_proj_id} ' \
f'-Oglobal.nevents={args.nevents} ' \
f'-Oglobal.output_str={args.output_str} ' \
f'-Oglobal.output_dataset={args.output_dataset} ' \
f'-Oglobal.output_namespace={args.output_namespace} ' \
f'-Osubmit.N={nj} ' \
f'-Oglobal.metacat_user={args.metacat_user} '
if args.blacklist:
cs_blacklist = ','.join(args.blacklist)
cmd += f'-Osubmit.blacklist={cs_blacklist} '
if args.dry_run:
cmd += '--dry_run '
print(cmd)
#cmd2 = ('fife_launch -c byhand.cfg '
# '-Oglobal.load_limit=%i '
# '-Oglobal.project=%s '
# '-Oglobal.nevents=%i '
# '-Oglobal.output_str=%s '
# '-Oglobal.output_dataset=%s '
# '-Oglobal.output_namespace=%s '
# '-Osubmit.N=%i '
# '-Oglobal.metacat_user=%s '
# )%(args.load_limit, dd_proj_id, args.nevents,
# args.output_str, args.output_dataset, args.output_namespace,
# nj, args.metacat_user)
#print(cmd == cmd2)
#print(cmd)
#print(cmd2)
subprocess.run(cmd, shell=True)
#subprocess.run(('fife_launch -c byhand.cfg '
# '-Oglobal.load_limit=%i '
# '-Oglobal.project=%s '
# '-Oglobal.nevents=%i '
# '-Oglobal.output_str=%s '
# '-Oglobal.output_dataset=%s '
# '-Oglobal.output_namespace=%s '
# '-Osubmit.N=%i '
# '-Oglobal.metacat_user=%s '
# )%(args.load_limit, dd_proj_id, args.nevents,
# args.output_str, args.output_dataset, args.output_namespace,
# nj, args.metacat_user),
# shell=True)
if count < len(njobs)-1:
print('Sleeping')
for i in range(60):
sleep(2)
print(f'{i*2}/120', end='\r')
count += 1