9 parser = argparse.ArgumentParser()
11 parser.add_argument(
'-t',
'--text', action =
'store_true',
12 help =
'textual output')
13 parser.add_argument(
'-r',
'--radial', action =
'store_true',
14 help =
'pie-chart-style output')
15 parser.add_argument(
'-l',
'--linear', action =
'store_true',
16 help =
'bar-chart-style output')
17 parser.add_argument(
'-j',
'--json', action =
'store_true',
19 parser.add_argument(
'-b',
'--batch', action =
'store_true',
20 help =
'don\'t open windows for graphics')
22 parser.add_argument(
'-f',
'--focus', default=
'', metavar=
'BR', help =
'center this branch')
24 parser.add_argument(
'filename.root',
25 help =
'the CAF or ART file to analyze')
27 opts =
vars(parser.parse_args())
29 if not (opts[
'text']
or opts[
'radial']
or opts [
'linear']
or opts[
'json']):
30 print 'You must specify at least one of --text, --radial, --linear, or --json' 56 sys.stderr =
open(os.devnull,
'w')
57 f = TFile(opts[
'filename.root'],
"READ")
60 isArt = bool(f.Get(
'Events'))
63 treeNames = [
'Events',
'Runs',
'SubRuns',
64 'EventHistory',
'MetaData',
'Parentage',
65 'EventMetaData',
'SubRunMetaData',
'RunMetaData']
67 treeNames = [
'recTree',
'spillTree']
69 if not f.Get(
'recTree'):
70 print 'This doesn\'t appear to be an ART or CAF file. Aborting.' 78 title = branch.GetName()
82 m = re.match(
'(.*)_(.*)_(.*)_(.*)\\.(.*)', title)
85 if len(m.group(3)) > 0:
86 title = m.group(2)+
'.'+m.group(3)+
'.'+m.group(1)+
'.'+m.group(5)
88 title = m.group(2)+
'.'+m.group(1)+
'.'+m.group(5)
90 label = title.split(
'.')[-1]
91 nodes[title] =
Node(label, branch.GetZipBytes())
92 for b
in branch.GetListOfBranches():
AddNodes(b)
96 for b
in f.Get(n).GetListOfBranches():
AddNodes(b)
109 parentKey =
'.'.join(key.split(
'.')[:-1])
111 if parentKey.endswith(
'.obj'): parentKey = parentKey[:-4]
113 if parentKey
not in nodes:
114 label = parentKey.split(
'.')[-1]
115 newnodes[parentKey] =
Node(label, 0)
118 nodes.update(newnodes)
123 root = nodes[opts[
'focus']]
125 if opts[
'focus'] ==
'':
127 root.title =
'Events' 134 parentKey =
'.'.join(key.split(
'.')[:-1])
136 if parentKey.endswith(
'.obj'): parentKey = parentKey[:-4]
138 parent = nodes[parentKey]
139 if parent
is not node:
140 parent.children.append(node)
148 if depth == 0:
return 149 if node.FullSize() == 0:
return 150 percent =
int((100*node.FullSize())/total+.5)
152 print indent, node,
'\t('+
str(percent)+
'%)' 156 for c
in sorted(node.children, key =
lambda n: -n.FullSize()):
157 prettyPrint(c, node.FullSize(), depth-1, indent+
'\t')
163 for depth
in range(1, 7):
173 if len(node.children) == 0:
174 ret += indent+
'{"name": "'+node.title+
'", "size": '+
str(node.FullSize())+
'}' 176 ret += indent+
'{"name": "'+node.title+
'", "children": [\n' 178 ret +=
',\n'.join([
toJSON(c, indent+
' ')
for c
in sorted(node.children, key =
lambda n: -n.FullSize())
if c.FullSize() > 0])
200 span = 360.*node.FullSize()/total
201 meanang = (startang+span/2)*3.14159/180
205 arc =
New(TArc, 200, 200, 20*depth, startang, startang+span)
208 for c
in sorted(node.children, key =
lambda n: -n.FullSize()):
210 startang += (360.*c.FullSize())/total
215 if depth == 1: meanr = 0
217 label =
New(TLatex, 200+meanr*
cos(meanang),
218 200+meanr*
sin(meanang),
220 textscale = .06*span/len(node.title)
221 if textscale > 1: textscale = 1
222 label.SetTextSize(label.GetTextSize()*textscale)
223 label.SetTextAlign(22)
224 textang = meanang*180/3.14159265358979-90
225 if textang > +90: textang -= 180
226 if textang < -90: textang += 180
227 if depth > 1: label.SetTextAngle(textang)
230 label =
New(TLatex, 200+meanr*
cos(meanang),
231 200+meanr*
sin(meanang),
234 if textscale > 1: textscale = 1
235 label.SetTextSize(label.GetTextSize()*textscale)
236 label.SetTextAlign(22)
237 textang = meanang*180/3.14159265358979
238 while textang > +90: textang -= 180
239 while textang < -90: textang += 180
240 if depth > 1: label.SetTextAngle(textang)
245 def BarChart(node, total, depth = 0, startpos = 0):
246 span = 100.*node.FullSize()/total
247 meanpos = startpos+span/2
248 meany = -(depth*20+10)
252 box =
New(TBox, startpos, -depth*20, startpos+span, -(depth*20+20))
256 for c
in sorted(node.children, key =
lambda n: -n.FullSize()):
257 BarChart(c, total, depth+1, startpos)
258 startpos += (100.*c.FullSize())/total
263 label =
New(TLatex, meanpos, meany, node.title)
264 textscale = .4*
min(20, span)/len(node.title)
265 if textscale > 2: textscale = 2
266 label.SetTextSize(label.GetTextSize()*textscale)
267 label.SetTextAlign(22)
270 label =
New(TLatex, meanpos, meany, node.title)
271 textscale = .4*
min(20, span)/len(node.title)
272 if textscale > 1: textscale = 1
273 label.SetTextSize(label.GetTextSize()*textscale)
274 label.SetTextAlign(22)
275 label.SetTextAngle(90)
280 canv =
New(TCanvas,
'rings',
'rings', 1000, 1000)
282 axes =
New(TH2F,
"",
"", 100, 70, 330, 100, 70, 330)
285 axes.GetXaxis().SetTickLength(0)
286 axes.GetYaxis().SetTickLength(0)
287 gPad.SetLeftMargin(0)
288 gPad.SetRightMargin(0)
289 gPad.SetBottomMargin(0)
295 gPad.Print(
"rings.png")
296 gPad.Print(
"rings.eps")
300 canv =
New(TCanvas,
'bars',
'bars', 1000, 1000)
302 axes =
New(TH2F,
"",
"", 100, -10, 110, 100, -110, +10)
305 axes.GetXaxis().SetTickLength(0)
306 axes.GetYaxis().SetTickLength(0)
307 gPad.SetLeftMargin(0)
308 gPad.SetRightMargin(0)
309 gPad.SetBottomMargin(0)
315 gPad.Print(
"bars.png")
316 gPad.Print(
"bars.eps")
319 if (opts[
'radial']
or opts[
'linear'])
and not opts[
'batch']:
322 print 'Ctrl-D to quit' 323 code.interact(local = locals(), banner=
'')
def BarChart(node, total, depth=0, startpos=0)
procfile open("FD_BRL_v0.txt")
static float min(const float a, const float b, const float c)
def prettyPrint(node, total, depth=100, indent='')
def toJSON(node, indent='')
def RingChart(node, total, depth=1, startang=0)