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

# User Rev Content
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 peller 1.11 argv = sys.argv
12 bortigno 1.1
13     #get files info from config
14 nmohr 1.8 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 peller 1.9 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 peller 1.10 parser.add_option("-S", "--samples", dest="samples", default="",
26     help="List of samples")
27 peller 1.9
28    
29 peller 1.10 (opts, args) = parser.parse_args(argv)
30 peller 1.9
31 peller 1.10 SamplesList=opts.samples.split(',')
32 nmohr 1.8
33     pathIN=opts.pathIn
34     pathOUT=opts.pathOut
35    
36     print "Config is: %s" %(opts.config)
37 nmohr 1.4 config = BetterConfigParser()
38 nmohr 1.8 config.read(opts.config)
39 nmohr 1.3
40     prefix=config.get('General','prefix')
41 nmohr 1.5 newprefix=config.get('General','newprefix')
42 nmohr 1.3 lumi=float(config.get('General','lumi'))
43 nmohr 1.8 weightexpression=config.get('General','weightexpression')
44     #this is only to speed it up, remove for final trees!
45     Precut=''
46     info = []
47 nmohr 1.3
48 bortigno 1.1 for Sample in config.sections():
49 nmohr 1.3 if not config.has_option(Sample,'infile'): continue
50 peller 1.10 if not SamplesList == [''] and not config.get(Sample,'sampleName') in SamplesList: continue
51 bortigno 1.1 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 peller 1.6 #this need exception handle
56 nmohr 1.3 #if type(eval(config.get(Sample,'sampleName'))) != list:
57 peller 1.6
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 bortigno 1.1 else:
81 peller 1.6 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 peller 1.9 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 bortigno 1.1 infofile = open(pathOUT+'/samples.info','w')
98     pickle.dump(info,infofile)
99     infofile.close()