ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/myutils/copytree.py
Revision: 1.2
Committed: Thu Feb 28 16:38:50 2013 UTC (12 years, 2 months ago) by nmohr
Content type: text/x-python
Branch: MAIN
CVS Tags: lhcp_UnblindFix, hcp_Unblind, lhcp_11April, LHCP_PreAppFixAfterFreeze, LHCP_PreAppFreeze, HEAD
Changes since 1.1: +2 -8 lines
Log Message:
Prepare split jobs

File Contents

# User Rev Content
1 peller 1.1 import ROOT
2     from printcolor import printc
3    
4     def copytree(pathIN,pathOUT,prefix,newprefix,file,Aprefix,Acut):
5    
6     print "##### COPY TREE - BEGIN ######"
7     print "Input File : %s/%s%s.root " %(pathIN,prefix,file)
8     print "Output File : %s/%s%s%s.root" %(pathOUT,newprefix,Aprefix,file)
9    
10 nmohr 1.2 input = ROOT.TFile.Open("%s/%s%s.root" %(pathIN,prefix,file),'read')
11     output = ROOT.TFile.Open("%s/%s%s%s.root" %(pathOUT,newprefix,Aprefix,file),'recreate')
12 peller 1.1
13     input.cd()
14     obj = ROOT.TObject
15     for key in ROOT.gDirectory.GetListOfKeys():
16     input.cd()
17     obj = key.ReadObj()
18     #print obj.GetName()
19     if obj.GetName() == 'tree':
20     continue
21     output.cd()
22     #print key.GetName()
23     obj.Write(key.GetName())
24    
25     inputTree = input.Get("tree")
26     nEntries = inputTree.GetEntries()
27     output.cd()
28     print '\n\t copy file: %s with cut: %s' %(file,Acut)
29     outputTree = inputTree.CopyTree(Acut)
30     kEntries = outputTree.GetEntries()
31     printc('blue','',"\t before cuts\t %s" %nEntries)
32     printc('green','',"\t survived\t %s" %kEntries)
33     outputTree.AutoSave()
34     output.ls()
35     print "Writing output file"
36     output.Write()
37     print "Closing output file"
38     output.Close()
39     print "Closing input file"
40     input.Close()
41    
42     print "##### COPY TREE - END ######"