2 |
|
|
3 |
|
import sys |
4 |
|
import copy |
5 |
+ |
import optparse |
6 |
+ |
import re |
7 |
|
|
8 |
|
|
9 |
|
class Branch(object): |
18 |
|
|
19 |
|
|
20 |
|
def dumpBranches(filename): |
21 |
< |
events = cmstools.EventTree(filename) |
21 |
> |
events = cmstools.EventTree (filename) |
22 |
|
listOfBranches = events._tree.GetListOfBranches() |
23 |
+ |
trailingDotRE = re.compile (r'\.$') |
24 |
|
branches = [] |
25 |
+ |
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 |
|
for branch in listOfBranches: |
31 |
< |
tmpBranch = Branch() |
32 |
< |
tmpBranch.name = branch.GetName() |
33 |
< |
if not "EventAux" in tmpBranch.name: |
34 |
< |
tmpBranch.process = tmpBranch.name.split("_")[3] |
35 |
< |
tmpBranch.label = tmpBranch.name.split("_")[2] |
36 |
< |
tmpBranch.type = branchType(branch) |
37 |
< |
tmpBranch.module = tmpBranch.name.split("_")[1] |
38 |
< |
tmpBranch.cpp = events.cppCode(tmpBranch.name) |
39 |
< |
branches.append(copy.copy(tmpBranch)) |
40 |
< |
|
31 |
> |
# 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 |
< |
print '%s "%s" "%s" "%s"' %(branch.type, branch.module, branch.label, branch.process) |
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 |
> |
|
77 |
|
|
78 |
|
|
79 |
|
if __name__ == "__main__": |
80 |
|
|
81 |
< |
args = sys.argv |
82 |
< |
if 2 == len(args): |
83 |
< |
try: |
84 |
< |
import PhysicsTools.PythonAnalysis as cmstools |
85 |
< |
import ROOT |
86 |
< |
ROOT.gSystem.Load("libFWCoreFWLite.so") |
87 |
< |
ROOT.AutoLibraryLoader.enable() |
88 |
< |
filename = args[1] |
89 |
< |
dumpBranches(filename) |
90 |
< |
except: |
91 |
< |
"Could not read %s" %filename |
92 |
< |
else: |
93 |
< |
print "Usage: EdmDumpEventContent filename.root" |
81 |
> |
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 |
|
|
109 |
|
|