1 """Python helper tools for CMS FWLite
3 benedikt.hegner@cern.ch
13 readline.parse_and_bind(
'tab: complete')
15 print 'WARNING: Could not load tab completion'
26 if hasattr(container,
'GetEntries'):
28 entries = container.GetEntries()
29 for entry
in xrange(entries):
32 raise cmserror(
"Looping of %s failed" %container)
35 elif hasattr(container,
'size'):
37 entries = container.size()
38 for entry
in xrange(entries):
39 yield container[entry]
45 """Convert a pair of C++ iterators into a python generator"""
47 yield begin.__deref__()
52 reColons = re.compile(
r'::')
53 reCloseTemplate =re.compile(
r'>')
54 reOpenTemplate =re.compile(
r'<')
55 branchType = ROOT.branchToClass(branch)
57 buffer = ROOT.MakeRootClass(branchType.GetName()) ()
58 if( branch.GetName()[-1] !=
'.')
and (branch.GetName()!=
"EventAuxiliary"):
59 branch.SetAddress(buffer)
61 branch.SetAddress(ROOT.AddressOf(buffer))
67 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")
69 if isinstance(obj, ROOT.TTree):
71 elif isinstance(obj, ROOT.TFile):
72 self.
_tree = obj.Get(treeName)
73 elif isinstance(obj, str):
74 self.
_tree = ROOT.TFile.Open(obj).Get(treeName)
76 raise cmserror(
"EventTree accepts only TTrees, TFiles and filenames")
82 alias = self._tree.GetAlias(name)
83 if alias !=
'': name = alias
90 """C++ code for accessing the product inside the full framework"""
91 alias = self._tree.GetAlias(name)
92 if alias !=
'': name = alias
93 tmpBranch = self._tree.GetBranch(name)
94 typeString = ROOT.branchToClass(tmpBranch).GetName()
95 if "edm::Wrapper" in typeString:
96 typeString = typeString.replace(
"<edm::Wrapper",
"")
97 typeString = typeString.rstrip(
">")
98 nameParts = name.split(
"_")
99 if nameParts[2] ==
"":
100 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", dummy);'\
101 %(typeString, nameParts[1])
103 cppCode =
'edm::Handle<%s > dummy;\nevent.getByLabel("%s", "%s", dummy);'\
104 %(typeString, nameParts[1], nameParts[2])
115 for branch
in self._usedBranches.itervalues():
116 branch.setIndex(self.
_index)
120 if key <0
or key > self._tree.GetEntries():
124 self._tree.GetEntry(self.
_index,0)
131 self._tree.GetEntry(self.
_index,0)
133 for entry
in xrange(self._tree.GetEntries()):
136 self._tree.GetEntry(self.
_index,0)
145 return iterators.addIterator(self._eventTree.branch(name)())
148 return iterators.addIterator(self._eventTree.branch(name)())
155 raise cmserror(
"Unknown branch "+name)
163 self._branch.GetEntry(self.
_index)
175 length = len(message)+7
177 print "ERROR:", message
perl if(1 lt scalar(@::datatypes))