1 |
peller |
1.1 |
import os, sys
|
2 |
|
|
from optparse import OptionParser
|
3 |
|
|
from BetterConfigParser import BetterConfigParser
|
4 |
|
|
from samplesclass import sample
|
5 |
|
|
|
6 |
|
|
def parse_info(samples_config,samples_path):
|
7 |
|
|
try:
|
8 |
|
|
os.stat(samples_config)
|
9 |
|
|
except:
|
10 |
|
|
raise Exception('config file is wrong/missing')
|
11 |
|
|
|
12 |
|
|
if '/pnfs/psi.ch/cms/' in samples_path:
|
13 |
|
|
T3 = True
|
14 |
|
|
_,p2=samples_path.split('/pnfs/')
|
15 |
|
|
t3_path = '/pnfs/'+p2.strip('\n')
|
16 |
|
|
else:
|
17 |
|
|
T3 = False
|
18 |
|
|
|
19 |
|
|
config = BetterConfigParser()
|
20 |
|
|
config.read(samples_config)
|
21 |
|
|
|
22 |
|
|
newprefix=config.get('General','newprefix')
|
23 |
|
|
lumi=float(config.get('General','lumi'))
|
24 |
|
|
weightexpression=config.get('General','weightexpression')
|
25 |
|
|
|
26 |
|
|
info = []
|
27 |
|
|
|
28 |
|
|
fileslist=[]
|
29 |
|
|
if T3:
|
30 |
|
|
ls = os.popen("lcg-ls -b -D srmv2 -l srm://t3se01.psi.ch:8443/srm/managerv2?SFN="+t3_path)
|
31 |
|
|
else:
|
32 |
|
|
ls = os.popen("ls -l "+samples_path)
|
33 |
|
|
|
34 |
|
|
for line in ls.readlines():
|
35 |
|
|
fileslist.append(line)
|
36 |
|
|
|
37 |
|
|
|
38 |
|
|
for Sample in config.sections():
|
39 |
|
|
|
40 |
|
|
if not config.has_option(Sample,'infile'): continue
|
41 |
|
|
#if not SamplesList == [''] and not config.get(Sample,'sampleName') in SamplesList: continue
|
42 |
|
|
infile = config.get(Sample,'infile')
|
43 |
|
|
sampleName = config.get(Sample,'sampleName')
|
44 |
|
|
|
45 |
|
|
if any(infile in file for file in fileslist):
|
46 |
|
|
print 'Sample %s is present'%(sampleName)
|
47 |
|
|
else:
|
48 |
|
|
print 'Sample %s is NOT! present'%(sampleName)
|
49 |
|
|
raise Exception("File %s not present"%(infile))
|
50 |
|
|
#Initialize samplecalss element
|
51 |
|
|
sampleType = config.get(Sample,'sampleType')
|
52 |
|
|
cut = config.get(Sample, 'cut')
|
53 |
|
|
info.append(sample(sampleName,sampleType))
|
54 |
|
|
|
55 |
|
|
info[-1].addtreecut(cut)
|
56 |
|
|
info[-1].path=samples_path
|
57 |
|
|
info[-1].identifier=infile
|
58 |
|
|
info[-1].weightexpression=weightexpression
|
59 |
|
|
info[-1].lumi=lumi
|
60 |
|
|
info[-1].prefix=newprefix
|
61 |
|
|
|
62 |
|
|
if eval(config.get(Sample,'subsamples')):
|
63 |
|
|
info[-1].subsamples=True
|
64 |
|
|
info[-1].group = eval((config.get(Sample,'sampleGroup')))
|
65 |
|
|
info[-1].subcuts = eval((config.get(Sample, 'subcuts')))
|
66 |
|
|
info[-1].subnames = eval((config.get(Sample, 'subnames')))
|
67 |
|
|
if sampleType != 'DATA':
|
68 |
|
|
info[-1].sf = eval((config.get(Sample, 'SF')))
|
69 |
|
|
info[-1].xsec = eval((config.get(Sample,'xSec')))
|
70 |
|
|
else:
|
71 |
|
|
info[-1].group = config.get(Sample,'sampleGroup')
|
72 |
|
|
if sampleType != 'DATA':
|
73 |
|
|
info[-1].sf = config.get(Sample, 'SF')
|
74 |
|
|
info[-1].xsec = config.get(Sample,'xSec')
|
75 |
|
|
|
76 |
|
|
return info
|