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
17 readline.parse_and_bind(
'tab: complete')
19 print(
'WARNING: Could not load tab completion')
23 from .
import iterators
30 if hasattr(container,
'GetEntries'):
32 entries = container.GetEntries()
33 for entry
in range(entries):
36 raise cmserror(
"Looping of %s failed" %container)
39 elif hasattr(container,
'size'):
41 entries = container.size()
42 for entry
in range(entries):
43 yield container[entry]
49 """Convert a pair of C++ iterators into a python generator""" 51 yield begin.__deref__()
56 reColons = re.compile(
r'::')
57 reCloseTemplate =re.compile(
r'>')
58 reOpenTemplate =re.compile(
r'<')
59 branchType = ROOT.branchToClass(branch)
61 buffer = ROOT.MakeRootClass(branchType.GetName()) ()
62 if( branch.GetName()[-1] !=
'.')
and (branch.GetName()!=
"EventAuxiliary"):
63 branch.SetAddress(buffer)
65 branch.SetAddress(ROOT.AddressOf(buffer))
71 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")
73 if isinstance(obj, ROOT.TTree):
75 elif isinstance(obj, ROOT.TFile):
76 self.
_tree = obj.Get(treeName)
77 elif isinstance(obj, str):
78 self.
_tree = ROOT.TFile.Open(obj).Get(treeName)
80 raise cmserror(
"EventTree accepts only TTrees, TFiles and filenames")
86 alias = self._tree.GetAlias(name)
87 if alias !=
'': name = alias
94 """C++ code for accessing the product inside the full framework""" 95 alias = self._tree.GetAlias(name)
96 if alias !=
'': name = alias
97 tmpBranch = self._tree.GetBranch(name)
98 typeString = ROOT.branchToClass(tmpBranch).GetName()
99 if "edm::Wrapper" in typeString:
100 typeString = typeString.replace(
"<edm::Wrapper",
"")
101 typeString = typeString.rstrip(
">")
102 nameParts = name.split(
"_")
103 if nameParts[2] ==
"":
104 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", dummy);'\
105 %(typeString, nameParts[1])
107 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", "%s", dummy);'\
108 %(typeString, nameParts[1], nameParts[2])
120 branch.setIndex(self.
_index)
124 if key <0
or key > self._tree.GetEntries():
128 self._tree.GetEntry(self.
_index,0)
135 self._tree.GetEntry(self.
_index,0)
137 for entry
in range(self._tree.GetEntries()):
140 self._tree.GetEntry(self.
_index,0)
149 return iterators.addIterator(self._eventTree.branch(name)())
152 return iterators.addIterator(self._eventTree.branch(name)())
159 raise cmserror(
"Unknown branch "+name)
167 self._branch.GetEntry(self.
_index)
179 length = len(message)+7
181 print(
"ERROR:", message)
S & print(S &os, JobReport::InputFile const &f)