forked from pseyfert/gangascripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerge.py
56 lines (49 loc) · 1.52 KB
/
merge.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 os
import subprocess
from Ganga.GPI import DiracFile
def create_lfn_list(j):
'''
Takes a job as input and returns two lists. The first list contains the
lfns of all DiracFiles the job created and the second the grid site they
are on.
'''
lfns = []
locations = []
for sj in j.subjobs:
for df in sj.outputfiles.get(DiracFile):
lfns.append(df.lfn)
locations.append(df.locations[0])
return lfns
def create_txt_for_hadd(j, name):
'''
Takes a job and a name as input.
Creates a txt file called name and adds all DiracFiles the job craeted
to the file, such that it can be passed to hadd
'''
if not name.endswith('.txt'):
if '.' in name:
print('Name needs to end in .txt')
return
name = name + '.txt'
lfns, locations = create_lfn_list(j)
gangascriptdir = os.path.abspath(__file__)
lfn_urls = subprocess.check_output(
[
"lb-run",
"LHCbDirac",
"prod",
"python",
gangascriptdir + "/get_access_urls.py"
] + lfns
).split('\n')
for line in lfn_urls[:]:
if 'SRM_FILE_UNAVAILABLE' in line:
print(line)
if not line.startswith('root://'):
lfn_urls.remove(line)
with open(name, 'w') as f:
for lfn in lfn_urls:
f.write(lfn + '\n')
print('Done. Now run')
print('hadd -ff <taget> @{}'.format(name))
print('Make sure to have a valid grid token at all time')