ATLAS Offline Software
PyPoolBrowser.py
Go to the documentation of this file.
1 from idlelib import TreeWidget
2 from PyKernel import PyKernel
3 from Tkinter import *
4 
5 import re
6 import time
7 
8 # import PyDataHeader and PyCLIDSvc
9 import cppyy
10 cppyy.load_library("libPyAnalysisCoreDict")
11 
12 
13 
14 # EDM item
15 class EDMItem (TreeWidget.TreeItem):
16  # name : name of the object
17  # ref : reference to the object
18  # expandable : whether the object may be a leaf object
19  # classKey : key of the class to which this obj belongs
20  def __init__ (self, name, ref, expandable, classKey=None):
21  self.name = name
22  self.ref = ref
23  self.expandable = expandable
24  self.classKey = classKey
25 
26  def GetText (self):
27  return self.name
28 
29  def IsExpandable (self):
30  return self.expandable
31 
32  def GetIconName(self):
33  if not self.IsExpandable():
34  return "python" # XXX wish there was a "file" icon
35 
36  # execute plot command when double-click
37  def OnDoubleClick(self):
38  # not a leaf
39  if self.IsExpandable():
40  return
41  # doesn't belong to a class
42  if self.classKey == None:
43  return
44  # draw histogram
45  x = eval ('PyKernel.plot ("%s#%s", "$x.%s()")' % (objList[self.classKey], self.classKey, self.name))
46  # sleep is needed to draw up canvas
47  time.sleep(1)
48  # return is also needed. see PyKernel.plot
49  return x
50 
51  # return list of items which belong to the object
52  def GetSubList (self):
53  sublist = []
54  # if a vector-like class
55  if hasattr(self.ref,'size') and hasattr(self.ref,'__getitem__'):
56  # use the fist one
57  if self.ref.size() != 0:
58  item = EDMItem ('%s constituents' % self.ref.size(),self.ref[0],True,self.classKey)
59  sublist.append(item)
60  return sublist
61  #others
62  else:
63  attrs=dir(self.ref)
64  attrs.sort()
65  for attr in attrs:
66  # private
67  if re.search("\A_",attr):
68  continue
69  # member
70  if re.search("\Am_",attr):
71  continue
72  # method
73  attrRef = getattr(self.ref,attr)
74  item = EDMItem (attr,attrRef,False,self.classKey)
75  sublist.append(item)
76  return sublist
77 
78 # Root Item
79 class RootItem (EDMItem):
80  # override GetSubList
81  def GetSubList (self):
82  sublist = []
83  # get EDM objects
84  attrs=dir(self.ref)
85  attrs.sort()
86  for attr in attrs:
87  # private
88  if re.search("\A_",attr):
89  continue
90  # else
91  attrRef = getattr(self.ref,attr)
92  item = EDMItem (attr,attrRef,True,attr)
93  sublist.append(item)
94  return sublist
95 
96 
97 
98 # run 1 event to get DataHeader
99 theApp.run(1)
100 
101 # get EDM/Key list from DataHeader
102 dh = g.PyDataHeader()
103 objList = {}
104 for i in range(dh.size()):
105  objList[dh.getKey(i)] = dh.getName(i)
106 
107 # build Root object
108 class MyRootObj:
109  pass
110 
111 rootObj = MyRootObj()
112 
113 # attach EDM objects to Root object if they are not in the ignore list
114 for key in objList.keys():
115  name = objList[key]
116  try:
117  exec 'con = PyKernel.retrieve(g.%s,"%s")' % (name, key)
118  setattr(rootObj,key, con)
119  except:
120  pass
121 
122 # start Tk session
123 root=Tk()
124 root.title(os.path.basename(sys.argv[0]))
125 root.configure(bd=0)
126 
127 sc = TreeWidget.ScrolledCanvas(root, bg="white", highlightthickness=0, takefocus=1)
128 sc.frame.pack(expand=1, fill="both")
129 item = RootItem('/',rootObj,True)
130 item.GetText()
131 node = TreeWidget.TreeNode(sc.canvas, None, item)
132 node.update()
133 
134 root.mainloop()
PyPoolBrowser.EDMItem.IsExpandable
def IsExpandable(self)
Definition: PyPoolBrowser.py:29
PyPoolBrowser.EDMItem.expandable
expandable
Definition: PyPoolBrowser.py:23
PyPoolBrowser.MyRootObj
Definition: PyPoolBrowser.py:108
PyPoolBrowser.RootItem
Definition: PyPoolBrowser.py:79
PyPoolBrowser.EDMItem.__init__
def __init__(self, name, ref, expandable, classKey=None)
Definition: PyPoolBrowser.py:20
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
PyPoolBrowser.EDMItem.GetSubList
def GetSubList(self)
Definition: PyPoolBrowser.py:52
PyPoolBrowser.EDMItem.GetText
def GetText(self)
Definition: PyPoolBrowser.py:26
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
PyPoolBrowser.EDMItem.ref
ref
Definition: PyPoolBrowser.py:22
beamspotman.dir
string dir
Definition: beamspotman.py:623
PyPoolBrowser.EDMItem.GetIconName
def GetIconName(self)
Definition: PyPoolBrowser.py:32
PyPoolBrowser.EDMItem
Definition: PyPoolBrowser.py:15
PyPoolBrowser.RootItem.GetSubList
def GetSubList(self)
Definition: PyPoolBrowser.py:81
PyPoolBrowser.EDMItem.name
name
Definition: PyPoolBrowser.py:21
PyPoolBrowser.EDMItem.classKey
classKey
Definition: PyPoolBrowser.py:24
PyPoolBrowser.EDMItem.OnDoubleClick
def OnDoubleClick(self)
Definition: PyPoolBrowser.py:37