Revision: | 1.4 |
Committed: | Wed Jun 10 16:28:47 2009 UTC (15 years, 10 months ago) by cplager |
Branch: | MAIN |
CVS Tags: | CMSSW_3_8_6_patch1, CMSSW_3_8_6, CMSSW_3_8_5_patch3, CMSSW_3_8_5_patch2, CMSSW_3_8_4_patch4, CMSSW_3_8_5, CMSSW_3_8_4_patch3, CMSSW_3_8_4_patch2, CMSSW_3_8_4_patch1, CMSSW_3_8_4, CMSSW_3_8_3, CMSSW_3_8_2_patch1, CMSSW_3_6_3_SLHC1, CMSSW_3_8_1_patch4, CMSSW_3_8_2, CMSSW_3_8_1_patch3, CMSSW_3_6_1_patch7, CMSSW_3_8_1_patch2, CMSSW_3_8_1_patch1, CMSSW_3_7_1, CMSSW_3_8_1, CMSSW_3_6_3_patch2, CMSSW_3_8_0_patch1, CMSSW_3_8_0, CMSSW_3_6_1_patch6, CMSSW_3_8_0_pre8, CMSSW_3_8_0_pre7, CMSSW_3_8_0_pre6, CMSSW_3_6_3_patch1, CMSSW_3_7_0_patch4, CMSSW_3_7_0_patch3, CMSSW_3_8_0_pre5, CMSSW_3_6_1_patch5, CMSSW_3_8_0_pre4, CMSSW_3_6_3, CMSSW_3_8_0_pre2, CMSSW_3_7_0_patch2, CMSSW_3_6_2, CMSSW_3_7_0_patch1, CMSSW_3_8_0_pre1, CMSSW_3_6_1_patch4, CMSSW_3_7_0, CMSSW_3_6_1_patch3, CMSSW_3_5_7_hltpatch4, CMSSW_3_7_0_pre5, CMSSW_3_6_1_patch1, CMSSW_3_5_8_patch4, CMSSW_3_7_0_pre4, CMSSW_3_6_1, CMSSW_3_7_0_pre3, CMSSW_3_6_0_patch2, CMSSW_3_6_0_patch1, CMSSW_3_5_8_patch3, CMSSW_3_5_8_patch2, CMSSW_3_5_8_patch1, CMSSW_3_7_0_pre2, CMSSW_3_5_8, CMSSW_3_7_0_pre1, CMSSW_3_5_7, CMSSW_3_6_0, CMSSW_3_6_0_pre6, CMSSW_3_6_0_pre5, CMSSW_3_5_6_patch1, CMSSW_3_5_6, CMSSW_3_5_4_patch2, CMSSW_3_5_5, CMSSW_3_6_0_pre4, CMSSW_3_5_4_patch1, CMSSW_3_6_0_pre3, CMSSW_3_5_4, CMSSW_3_5_3, CMSSW_3_6_0_pre2, CMSSW_3_5_2_patch2, CMSSW_3_5_2_patch1, CMSSW_3_6_0_pre1, CMSSW_3_5_2, CMSSW_3_5_1_patch1, CMSSW_3_3_6_patch4, CMSSW_3_3_6_patch6, CMSSW_3_5_0_patch1, CMSSW_3_4_2_patch1, CMSSW_3_5_1, CMSSW_3_4_2, CMSSW_3_5_0, CMSSW_3_3_6_patch5, CMSSW_3_5_0_pre5, CMSSW_3_3_6_patch3, CMSSW_3_3_3_TSG, CMSSW_3_5_0_pre3, V00-03-01, V00-03-00, CMSSW_3_5_0_pre2, CMSSW_3_4_1, CMSSW_3_4_0, CMSSW_3_3_6_patch2, CMSSW_3_3_6_patch1, CMSSW_3_5_0_pre1, CMSSW_3_3_6, CMSSW_3_4_0_pre7, CMSSW_3_3_5, CMSSW_3_4_0_pre6, CMSSW_3_3_4, CMSSW_3_3_3_patch1, CMSSW_3_3_3, CMSSW_3_4_0_pre5, CMSSW_3_4_0_pre4, CMSSW_3_3_2, CMSSW_3_4_0_pre3, CMSSW_3_3_1, CMSSW_3_4_0_pre2, CMSSW_3_2_8, CMSSW_3_3_0, CMSSW_3_4_0_pre1, CMSSW_3_1_4, CMSSW_3_3_0_pre6, CMSSW_3_3_0_pre5, CMSSW_3_1_3, CMSSW_3_2_7, CMSSW_3_3_0_pre4, CMSSW_3_3_0_pre3, CMSSW_3_3_0_pre2, CMSSW_3_2_6, CMSSW_3_3_0_pre1, CMSSW_3_2_5, CMSSW_3_2_4, CMSSW_3_2_3, V00-02-06, CMSSW_3_2_2_patch2, CMSSW_3_2_2_patch1, CMSSW_3_2_2, CMSSW_3_1_2, CMSSW_3_2_1, CMSSW_3_2_0, CMSSW_3_1_1, CMSSW_3_1_0_patch1, CMSSW_3_1_0, CMSSW_3_1_0_pre11, CMSSW_3_1_0_pre10, V00-02-05 |
Changes since 1.3: | +81 -26 lines |
Log Message: | added new functionality to edmDumpEventContent: branch names, options, ability to filter output |
# | User | Rev | Content |
---|---|---|---|
1 | lsexton | 1.1 | #!/usr/bin/env python |
2 | |||
3 | import sys | ||
4 | import copy | ||
5 | cplager | 1.4 | import optparse |
6 | import re | ||
7 | lsexton | 1.1 | |
8 | |||
9 | class Branch(object): | ||
10 | pass | ||
11 | |||
12 | |||
13 | def branchType(branch): | ||
14 | type = cmstools.ROOT.branchToClass(branch).GetName() | ||
15 | if "edm::Wrapper" in type: | ||
16 | type = type.replace("edm::Wrapper<","").rstrip(">") | ||
17 | return type | ||
18 | |||
19 | |||
20 | def dumpBranches(filename): | ||
21 | cplager | 1.4 | events = cmstools.EventTree (filename) |
22 | lsexton | 1.1 | listOfBranches = events._tree.GetListOfBranches() |
23 | cplager | 1.4 | trailingDotRE = re.compile (r'\.$') |
24 | lsexton | 1.1 | branches = [] |
25 | cplager | 1.4 | regexList = [] |
26 | # are we asked to filter this list? | ||
27 | for regexString in options.regex: | ||
28 | #print "adding", regexString | ||
29 | regexList.append( re.compile( regexString, re.IGNORECASE ) ) | ||
30 | lsexton | 1.1 | for branch in listOfBranches: |
31 | cplager | 1.4 | # print branch.GetName() |
32 | tmpBranch = Branch() | ||
33 | tmpBranch.fullname = branch.GetName() | ||
34 | tmpBranch.name = trailingDotRE.sub ('', tmpBranch.fullname) | ||
35 | if "EventAux" in tmpBranch.fullname: | ||
36 | continue | ||
37 | #print "found", tmpBranch.name | ||
38 | parts = tmpBranch.fullname.split("_") | ||
39 | tmpBranch.module = parts [1] | ||
40 | tmpBranch.label = parts [2] | ||
41 | tmpBranch.process = parts [3] | ||
42 | tmpBranch.type = branchType(branch) | ||
43 | tmpBranch.cpp = events.cppCode (tmpBranch.fullname) | ||
44 | # are there any matches to the regexList? | ||
45 | found = False | ||
46 | for regex in regexList: | ||
47 | # search the branch name | ||
48 | if regex.search (tmpBranch.name): | ||
49 | found = True | ||
50 | break | ||
51 | # search the type | ||
52 | if regex.search (tmpBranch.cpp): | ||
53 | found = True | ||
54 | break | ||
55 | # if there is a list and no matches | ||
56 | if regexList and not found: | ||
57 | continue | ||
58 | branches.append( copy.copy(tmpBranch) ) | ||
59 | for branch in branches: | ||
60 | #continue | ||
61 | if options.name: | ||
62 | print branch.name | ||
63 | elif options.all: | ||
64 | print '%-30s %-20s %-10s %-15s : %s' % \ | ||
65 | (branch.type, | ||
66 | '"' + branch.module + '"', | ||
67 | '"' + branch.label + '"', | ||
68 | '"' + branch.process + '"', | ||
69 | branch.name) | ||
70 | else: | ||
71 | print '%-30s %-20s %-10s %-15s' % \ | ||
72 | (branch.type, | ||
73 | '"' + branch.module + '"', | ||
74 | '"' + branch.label + '"', | ||
75 | '"' + branch.process + '"') | ||
76 | lsexton | 1.1 | |
77 | |||
78 | |||
79 | if __name__ == "__main__": | ||
80 | |||
81 | cplager | 1.4 | parser = optparse.OptionParser \ |
82 | ("usage: %prog [options] templates.root" \ | ||
83 | "\nPrints out info on edm file.") | ||
84 | parser.add_option ('--name', dest='name', action='store_true', | ||
85 | help='print out only branch names') | ||
86 | parser.add_option ('--all', dest='all', action='store_true', | ||
87 | help='Print out everything: type, module, label, '\ | ||
88 | 'process, and branch name') | ||
89 | parser.add_option ("--regex", dest='regex', action="append", | ||
90 | type="string", default=[], | ||
91 | help="Filter results based on regex") | ||
92 | options, args = parser.parse_args() | ||
93 | if not args: | ||
94 | print parser.print_usage() | ||
95 | sys.exit() | ||
96 | try: | ||
97 | import PhysicsTools.PythonAnalysis as cmstools | ||
98 | ## # to let ROOT understand we are in batch mode | ||
99 | ## sys.argv.append( '-b-' ) | ||
100 | import ROOT | ||
101 | ROOT.gROOT.SetBatch() # setting batch mode | ||
102 | ROOT.gSystem.Load("libFWCoreFWLite.so") | ||
103 | ROOT.AutoLibraryLoader.enable() | ||
104 | filename = args[0] | ||
105 | dumpBranches (filename) | ||
106 | except: | ||
107 | "Could not read %s" %filename | ||
108 | lsexton | 1.1 | |
109 |