1 """Python helper tools for CMS FWLite 3 benedikt.hegner@cern.ch 6 from __future__
import absolute_import
7 from __future__
import print_function
16 readline.parse_and_bind(
'tab: complete')
18 print(
'WARNING: Could not load tab completion')
22 from .
import iterators
29 if hasattr(container,
'GetEntries'):
31 entries = container.GetEntries()
32 for entry
in xrange(entries):
35 raise cmserror(
"Looping of %s failed" %container)
38 elif hasattr(container,
'size'):
40 entries = container.size()
41 for entry
in xrange(entries):
42 yield container[entry]
48 """Convert a pair of C++ iterators into a python generator""" 50 yield begin.__deref__()
55 reColons = re.compile(
r'::')
56 reCloseTemplate =re.compile(
r'>')
57 reOpenTemplate =re.compile(
r'<')
58 branchType = ROOT.branchToClass(branch)
60 buffer = ROOT.MakeRootClass(branchType.GetName()) ()
61 if( branch.GetName()[-1] !=
'.')
and (branch.GetName()!=
"EventAuxiliary"):
62 branch.SetAddress(buffer)
64 branch.SetAddress(ROOT.AddressOf(buffer))
70 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")
72 if isinstance(obj, ROOT.TTree):
74 elif isinstance(obj, ROOT.TFile):
75 self.
_tree = obj.Get(treeName)
76 elif isinstance(obj, str):
77 self.
_tree = ROOT.TFile.Open(obj).Get(treeName)
79 raise cmserror(
"EventTree accepts only TTrees, TFiles and filenames")
85 alias = self._tree.GetAlias(name)
86 if alias !=
'': name = alias
93 """C++ code for accessing the product inside the full framework""" 94 alias = self._tree.GetAlias(name)
95 if alias !=
'': name = alias
96 tmpBranch = self._tree.GetBranch(name)
97 typeString = ROOT.branchToClass(tmpBranch).GetName()
98 if "edm::Wrapper" in typeString:
99 typeString = typeString.replace(
"<edm::Wrapper",
"")
100 typeString = typeString.rstrip(
">")
101 nameParts = name.split(
"_")
102 if nameParts[2] ==
"":
103 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", dummy);'\
104 %(typeString, nameParts[1])
106 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", "%s", dummy);'\
107 %(typeString, nameParts[1], nameParts[2])
119 branch.setIndex(self.
_index)
123 if key <0
or key > self._tree.GetEntries():
127 self._tree.GetEntry(self.
_index,0)
134 self._tree.GetEntry(self.
_index,0)
136 for entry
in xrange(self._tree.GetEntries()):
139 self._tree.GetEntry(self.
_index,0)
148 return iterators.addIterator(self._eventTree.branch(name)())
151 return iterators.addIterator(self._eventTree.branch(name)())
158 raise cmserror(
"Unknown branch "+name)
166 self._branch.GetEntry(self.
_index)
178 length = len(message)+7
180 print(
"ERROR:", message)
S & print(S &os, JobReport::InputFile const &f)