-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_rse.py
56 lines (43 loc) · 1.44 KB
/
get_rse.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
import subprocess
from runDB import get_did, get_name, get_collection
import os
import numpy as np
import shlex
import argparse
collection = get_collection()
def download_raw(run_id, detector='tpc', rawdir='/scratch/midway2/ershockley/rawdata',
rse=None, dry_run=False):
did = get_did(run_id, detector)
name = get_name(run_id, detector)
path = os.path.join(rawdir, name)
os.makedirs(path, exist_ok = True)
if dry_run:
print("DRY RUN - no downloads occurring")
rse_str = "--rse %s" % rse * (rse is not None)
command = "rucio download %s --no-subdir --dir %s %s" % (did, path, rse_str)
if dry_run:
print(command)
return
subprocess.Popen(shlex.split(command)).communicate()
def get_rses(run_id, detector='tpc'):
name = get_name(run_id, detector)
doc = collection.find_one({'name': name, 'detector': detector},
{'data': 1})
for datum in doc['data']:
if datum['host'] == 'rucio-catalogue':
return datum['rse']
return []
def main():
parser = argparse.ArgumentParser(description="Downloads data from rucio")
parser.add_argument('number', type=int)
args = parser.parse_args()
rses = get_rses(args.number)
if 'UC_OSG_USERDISK' in rses:
rse = 'UC_OSG_USERDISK'
elif 'NIKHEF_USERDISK' in rses:
rse = 'NIKHEF_USERDISK'
else:
rse = ""
print(rse)
if __name__ == "__main__":
main()