1 |
nmohr |
1.8 |
#!/usr/bin/env python
|
2 |
bortigno |
1.1 |
from copytree import copytree
|
3 |
|
|
from printcolor import printc
|
4 |
|
|
from samplesclass import sample
|
5 |
|
|
import pickle
|
6 |
|
|
import sys
|
7 |
nmohr |
1.8 |
from optparse import OptionParser
|
8 |
nmohr |
1.4 |
from BetterConfigParser import BetterConfigParser
|
9 |
bortigno |
1.1 |
import ROOT
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
#get files info from config
|
13 |
nmohr |
1.8 |
parser = OptionParser()
|
14 |
|
|
parser.add_option("-I", "--inPath", dest="pathIn", default="",
|
15 |
|
|
help="path to the input files")
|
16 |
|
|
parser.add_option("-O", "--outPath", dest="pathOut", default="",
|
17 |
|
|
help="path to the output files")
|
18 |
|
|
parser.add_option("-C", "--config", dest="config", default="",
|
19 |
peller |
1.9 |
help="configuration of samples")
|
20 |
|
|
parser.add_option("-U", "--update", dest="update", default=False, action='store_true',
|
21 |
|
|
help="append sample to existing samples.info")
|
22 |
|
|
parser.add_option("-D", "--dry", dest="dry", default=False, action='store_true',
|
23 |
|
|
help="dry drun - just write samples. info withou copying and skimming trees")
|
24 |
|
|
|
25 |
|
|
|
26 |
nmohr |
1.8 |
argv=sys.argv
|
27 |
peller |
1.9 |
|
28 |
nmohr |
1.8 |
(opts, args) = parser.parse_args(argv)
|
29 |
|
|
|
30 |
|
|
pathIN=opts.pathIn
|
31 |
|
|
pathOUT=opts.pathOut
|
32 |
|
|
|
33 |
|
|
print "Config is: %s" %(opts.config)
|
34 |
nmohr |
1.4 |
config = BetterConfigParser()
|
35 |
nmohr |
1.8 |
config.read(opts.config)
|
36 |
nmohr |
1.3 |
|
37 |
|
|
prefix=config.get('General','prefix')
|
38 |
nmohr |
1.5 |
newprefix=config.get('General','newprefix')
|
39 |
nmohr |
1.3 |
lumi=float(config.get('General','lumi'))
|
40 |
nmohr |
1.8 |
weightexpression=config.get('General','weightexpression')
|
41 |
|
|
#this is only to speed it up, remove for final trees!
|
42 |
|
|
Precut=''
|
43 |
|
|
info = []
|
44 |
nmohr |
1.3 |
|
45 |
bortigno |
1.1 |
for Sample in config.sections():
|
46 |
nmohr |
1.3 |
if not config.has_option(Sample,'infile'): continue
|
47 |
bortigno |
1.1 |
infile = config.get(Sample,'infile')
|
48 |
|
|
if not ROOT.TFile.Open(pathIN+prefix+infile+'.root',"READ"):
|
49 |
|
|
print 'WARNING: No file ' + pathIN+prefix+infile+ ' found! '
|
50 |
|
|
continue
|
51 |
peller |
1.6 |
#this need exception handle
|
52 |
nmohr |
1.3 |
#if type(eval(config.get(Sample,'sampleName'))) != list:
|
53 |
peller |
1.6 |
|
54 |
|
|
|
55 |
|
|
#Initialize samplecalss element
|
56 |
|
|
sampleName = config.get(Sample,'sampleName')
|
57 |
|
|
sampleType = config.get(Sample,'sampleType')
|
58 |
|
|
cut = config.get(Sample, 'cut')
|
59 |
|
|
info.append(sample(sampleName,sampleType))
|
60 |
|
|
|
61 |
|
|
info[-1].addtreecut(cut)
|
62 |
|
|
info[-1].path=pathOUT
|
63 |
|
|
info[-1].identifier=infile
|
64 |
|
|
info[-1].weightexpression=weightexpression
|
65 |
|
|
info[-1].lumi=lumi
|
66 |
|
|
info[-1].prefix=newprefix
|
67 |
|
|
|
68 |
|
|
if eval(config.get(Sample,'subsamples')):
|
69 |
|
|
info[-1].subsamples=True
|
70 |
|
|
info[-1].group = eval((config.get(Sample,'sampleGroup')))
|
71 |
|
|
info[-1].subcuts = eval((config.get(Sample, 'subcuts')))
|
72 |
|
|
info[-1].subnames = eval((config.get(Sample, 'subnames')))
|
73 |
|
|
if sampleType != 'DATA':
|
74 |
|
|
info[-1].sf = eval((config.get(Sample, 'SF')))
|
75 |
|
|
info[-1].xsec = eval((config.get(Sample,'xSec')))
|
76 |
bortigno |
1.1 |
else:
|
77 |
peller |
1.6 |
info[-1].group = config.get(Sample,'sampleGroup')
|
78 |
|
|
if sampleType != 'DATA':
|
79 |
|
|
info[-1].sf = config.get(Sample, 'SF')
|
80 |
|
|
info[-1].xsec = config.get(Sample,'xSec')
|
81 |
|
|
|
82 |
peller |
1.9 |
if not opts.dry:
|
83 |
|
|
copytree(pathIN,pathOUT,prefix,newprefix,infile,'',cut+Precut)
|
84 |
|
|
|
85 |
|
|
#dump info
|
86 |
|
|
if opts.update:
|
87 |
|
|
infofile = open(pathOUT+'/samples.info','r')
|
88 |
|
|
info_old = pickle.load(infofile)
|
89 |
|
|
infofile.close()
|
90 |
|
|
|
91 |
|
|
info += info_old
|
92 |
|
|
|
93 |
bortigno |
1.1 |
infofile = open(pathOUT+'/samples.info','w')
|
94 |
|
|
pickle.dump(info,infofile)
|
95 |
|
|
infofile.close()
|