1 """Python helper tools for CMS FWLite 3 benedikt.hegner@cern.ch 6 from __future__
import absolute_import
7 from __future__
import print_function
8 from builtins
import range
15 readline.parse_and_bind(
'tab: complete')
17 print(
'WARNING: Could not load tab completion')
21 from .
import iterators
28 if hasattr(container,
'GetEntries'):
30 entries = container.GetEntries()
31 for entry
in range(entries):
34 raise cmserror(
"Looping of %s failed" %container)
37 elif hasattr(container,
'size'):
39 entries = container.size()
40 for entry
in range(entries):
41 yield container[entry]
47 """Convert a pair of C++ iterators into a python generator""" 49 yield begin.__deref__()
54 reColons = re.compile(
r'::')
55 reCloseTemplate =re.compile(
r'>')
56 reOpenTemplate =re.compile(
r'<')
57 branchType = ROOT.branchToClass(branch)
59 buffer = ROOT.MakeRootClass(branchType.GetName()) ()
60 if( branch.GetName()[-1] !=
'.')
and (branch.GetName()!=
"EventAuxiliary"):
61 branch.SetAddress(buffer)
63 branch.SetAddress(ROOT.AddressOf(buffer))
69 sys.stderr.write (
"WARNING: This package has been deprecated and will be removed in the near future.\nPlease switch to using FWLite.Python (https://twiki.cern.ch/twiki/bin/viewauth/CMS/WorkBookFWLitePython)\n")
71 if isinstance(obj, ROOT.TTree):
73 elif isinstance(obj, ROOT.TFile):
74 self.
_tree = obj.Get(treeName)
75 elif isinstance(obj, str):
76 self.
_tree = ROOT.TFile.Open(obj).Get(treeName)
78 raise cmserror(
"EventTree accepts only TTrees, TFiles and filenames")
84 alias = self.
_tree.GetAlias(name)
85 if alias !=
'': name = alias
92 """C++ code for accessing the product inside the full framework""" 93 alias = self.
_tree.GetAlias(name)
94 if alias !=
'': name = alias
95 tmpBranch = self.
_tree.GetBranch(name)
96 typeString = ROOT.branchToClass(tmpBranch).GetName()
97 if "edm::Wrapper" in typeString:
98 typeString = typeString.replace(
"<edm::Wrapper",
"")
99 typeString = typeString.rstrip(
">")
100 nameParts = name.split(
"_")
101 if nameParts[2] ==
"":
102 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", dummy);'\
103 %(typeString, nameParts[1])
105 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", "%s", dummy);'\
106 %(typeString, nameParts[1], nameParts[2])
118 branch.setIndex(self.
_index)
122 if key <0
or key > self.
_tree.GetEntries():
157 raise cmserror(
"Unknown branch "+name)
177 length = len(message)+7
179 print(
"ERROR:", message)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)