-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
94 lines (86 loc) · 2.73 KB
/
__init__.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
"""
samples:
A collection of samples, grouped by production.
"""
# import p1130
# import p1286
import p1344
import p1443
import p1462
import copy
import sys
def fatal(message):
sys.exit("Fatal error in %s: %s" % (__file__, message))
def get(ptag, inputs):
"""
Function to convert string to list of samples.
Example string: data.Muons.periodA,mc.ZeeNpXs,mc.ttbar,embedding.periodB
"""
if not ptag : fatal("Need production tag.")
if not inputs : fatal("Need list of inputs.")
if not isinstance(inputs, list):
inputs = inputs.split(',') # now a list
# build list of samples
samples = []
for inp in inputs:
# retrieve sample
try:
sample = eval("%s.%s" % (ptag, inp))
except:
try:
# check for runs
stream = '.'.join(inp.split('.')[:-1])
run = inp.split('.')[-1]
sample = eval("%s.%s.runs['%s']" % (ptag, stream, run))
except:
fatal("Unrecognized sample '%s'" % inp)
# add sample
if isinstance(sample, list):
samples.extend(copy.copy(sample))
else:
samples.append(copy.copy(sample))
return samples
def find_replicas(d3pd):
import os
os.system("dq2-list-dataset-replicas-container %s" % d3pd)
def size(dataset):
import subprocess
cmd = "rucio-ls -pfL UPENN_LOCALGROUPDISK %s" % dataset
print "> %s" % cmd
print
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
stdout,stderr = proc.communicate()
firstline = True
for line in stdout.split("\n"):
line = line.strip()
if line and firstline:
# first line contains DSname
print line
firstline = False
if line.startswith("total files:"):
print line
if line.startswith("local files:"):
print line
if line.startswith("total size:" ):
bytesize = float(line.split("total size:")[1])
print "total size: %15i B" % (bytesize)
print "total size: %15.2f GB" % (bytesize/pow(1024, 3))
print "total size: %15.2f TB" % (bytesize/pow(1024, 4))
print
def eventsAMI(d3pd, usr=None, pw=None):
import pyAMI.pyAMI as AMI
if not usr:
usr = raw_input(" AMI username: ")
if not pw:
import getpass
pw = getpass.getpass(" AMI password: ")
client = AMI.AMI(False)
cmd = []
cmd += ['getDatasetInfo']
cmd += ['logicalDatasetName=%s' % d3pd]
cmd += ['AMIUser=%s' % usr]
cmd += ['AMIPass=%s' % pw]
exe = client.execute(cmd)
outdict = exe.getDict()
return int(outdict['Element_Info']['row_1']['totalEvents'])
# EOF