ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/prepare_environment_with_config.py
Revision: 1.11
Committed: Fri Oct 5 11:58:18 2012 UTC (12 years, 7 months ago) by peller
Content type: text/x-python
Branch: MAIN
CVS Tags: hcpApproval, HCP_unblinding, hcpPreApp, hcpPreAppFreeze
Changes since 1.10: +1 -0 lines
Log Message:
plot and other fixes

File Contents

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