12 if 'DISPLAY' in os.environ:
13 del os.environ[
'DISPLAY']
14 os.environ[
'TERM'] =
'dumb'
19 from PyUtils.Helpers
import ROOT6Setup
26 cppyy.load_library(
'libAtlasSTLAddReflexDict')
27 ROOT.TClass(
'vector<float>')
28 ROOT.TClass(
'vector<vector<unsigned int> >')
29 from ordereddict
import OrderedDict
33 ROOT.D3PDTest.MapDumper
36 if type(o).__name__
in [
'map<string,string>',
39 keys = ROOT.D3PDTest.MapDumper.keys (o)
40 values = ROOT.D3PDTest.MapDumper.values (o)
41 return OrderedDict (sorted (zip (keys, values), key=
lambda t: t[0]))
42 if (
type(o).__name__.startswith (
'vector<char')
or
43 type(o).__name__.startswith (
'vector<unsigned char')):
45 lens = [len(x)
for x
in ll]
46 if lens
and min(lens) == 1
and max(lens) == 1:
47 ll = [ord(x)
for x
in ll]
49 if type(o).__name__.startswith (
'vector<'):
50 return [
topy(x)
for x
in o]
51 if type(o).__name__
in [
'PyFloatBuffer',
58 if len(l) == 0:
return True
59 for i
in range(1, len(l)):
60 if l[i] != l[0]:
return False
73 if not isinstance(l, list):
75 return '[' +
','.
join(l) +
']'
82 if i < len(l)-1
and l[i] == l[i+1]:
83 if nextfrag: frags.append(nextfrag)
86 while j < len(l)
and l[i] == l[j]:
88 frags.append (
'%d*[%s]' % (j-i, l[i]))
100 nextfrag.append (l[i])
102 if nextfrag: frags.append (nextfrag)
104 return '+'.join (frags)
109 if isinstance(o, list):
110 l = [
tostr(x)
for x
in o]
113 return '[' +
', '.join (l) +
']'
114 if isinstance(o, str):
118 if s.endswith (
'.0'): s = s[:-2]
124 while i < len(s1)
and i < len(s2)
and s1[i] == s2[i]:
131 for (i,b)
in enumerate(blist):
136 comm1 = common_length (lasttag, b)
137 comm2 = common_length (b, b2)
139 if comm1 != len(lasttag):
140 while comm1 > 0
and b[comm1-1] !=
'_':
142 if b[:comm1] != lasttag:
144 out.append (
':' + lasttag)
146 while comm2 > 0
and b[comm2-1] !=
'_':
148 if b[:comm2] != lasttag:
150 out.append (
':' + lasttag)
152 nm = b[len(lasttag):]
153 if len(nm) == 0: nm =
'$'
161 if tt.GetName().startswith (
'dum_')
and n > 10000000:
162 print (
'[Dummy tree skipped]')
164 bb = [b.GetName()
for b
in tt.GetListOfBranches()]
167 bb = merge_names (bb)
169 print (
'-----------')
180 br = tt.GetBranch(bname)
184 data.append (topy (getattr(tt, bname)))
185 print (b, tostr (data))
190 print (
'-----------')
192 print (b, tostr (topy (getattr (tt, b))))
197 print (
'bins: ', [h.GetBinContent(i)
for i
in range(h.GetSize())])
199 print (
'errs: ', [h.GetBinError(i)
for i
in range(h.GetSize())])
206 kk = [k.GetName()
for k
in f.GetListOfKeys()]
212 elif isinstance (o, ROOT.TTree):
213 print (
'\n\n\nTree', pref+k)
214 dumptree (o, by_branch)
215 elif isinstance (o, ROOT.TH1):
216 print (
'\n\n\nTH1', pref+k)
218 elif isinstance (o, ROOT.TDirectory):
219 dumpdir (o, by_branch, pref + k +
'/')
220 elif isinstance (o, ROOT.TObjString):
221 print (
'\n\n\nString', pref+k)
223 print (
'[pickle data skipped]')
226 print (
'__END_OF_STRING__')
228 print (
'\n\n\nKey', pref+k)
236 dumpdir (f, by_branch=by_branch)
240 if __name__ ==
'__main__':
244 if len(sys.argv) > 1
and sys.argv[1] ==
'--by-branch':
247 if len(sys.argv) > 1:
249 dumpit (file, by_branch)