ATLAS Offline Software
Loading...
Searching...
No Matches
python.dumptuple_any Namespace Reference

Functions

 topy (o)
 alleq (l)
 isint (o)
 form_list (l)
 squash_list (l)
 tostr (o)
 common_length (s1, s2)
 merge_names (blist)
 dumptree (tt, by_branch)
 dumphist (h)
 dumpdir (f, by_branch, pref='')
 dumpit (file, by_branch)

Variables

str file = 'test1.root'
bool by_branch = False

Function Documentation

◆ alleq()

python.dumptuple_any.alleq ( l)

Definition at line 55 of file dumptuple_any.py.

55def alleq (l):
56 if len(l) == 0: return True
57 for i in range(1, len(l)):
58 if l[i] != l[0]: return False
59 return True
60
61

◆ common_length()

python.dumptuple_any.common_length ( s1,
s2 )

Definition at line 120 of file dumptuple_any.py.

120def common_length (s1, s2):
121 i = 0
122 while i < len(s1) and i < len(s2) and s1[i] == s2[i]:
123 i += 1
124 return i
125

◆ dumpdir()

python.dumptuple_any.dumpdir ( f,
by_branch,
pref = '' )

Definition at line 203 of file dumptuple_any.py.

203def dumpdir (f, by_branch, pref=''):
204 kk = [k.GetName() for k in f.GetListOfKeys()]
205 kk.sort()
206 for k in kk:
207 o = f.Get (k)
208 if k == 'Schema':
209 pass
210 elif isinstance (o, ROOT.TTree):
211 print ('\n\n\nTree', pref+k)
212 dumptree (o, by_branch)
213 elif isinstance (o, ROOT.TH1):
214 print ('\n\n\nTH1', pref+k)
215 dumphist (o)
216 elif isinstance (o, ROOT.TDirectory):
217 dumpdir (o, by_branch, pref + k + '/')
218 elif isinstance (o, ROOT.TObjString):
219 print ('\n\n\nString', pref+k)
220 if k == '_pickle':
221 print ('[pickle data skipped]')
222 else:
223 print (o, end='')
224 print ('__END_OF_STRING__')
225 else:
226 print ('\n\n\nKey', pref+k)
227 print (o)
228 return
229
230
231

◆ dumphist()

python.dumptuple_any.dumphist ( h)

Definition at line 194 of file dumptuple_any.py.

194def dumphist (h):
195 print ('bins: ', [h.GetBinContent(i) for i in range(h.GetSize())])
196 if h.GetSumw2N():
197 print ('errs: ', [h.GetBinError(i) for i in range(h.GetSize())])
198 return
199
200
201
202

◆ dumpit()

python.dumptuple_any.dumpit ( file,
by_branch )

Definition at line 232 of file dumptuple_any.py.

232def dumpit (file, by_branch):
233 f=ROOT.TFile(file)
234 dumpdir (f, by_branch=by_branch)
235 return
236
237

◆ dumptree()

python.dumptuple_any.dumptree ( tt,
by_branch )

Definition at line 157 of file dumptuple_any.py.

157def dumptree (tt, by_branch):
158 n = tt.GetEntries()
159 if tt.GetName().startswith ('dum_') and n > 10000000:
160 print ('[Dummy tree skipped]')
161 return
162 bb = [b.GetName() for b in tt.GetListOfBranches()]
163 bb.sort()
164 if by_branch:
165 bb = merge_names (bb)
166 print ('\nBranches')
167 print ('-----------')
168 lasttag = ''
169 for b in bb:
170 if b[0] == ':':
171 print (b)
172 lasttag = b[1:]
173 continue
174 if b == '$':
175 bname = lasttag
176 else:
177 bname = lasttag + b
178 br = tt.GetBranch(bname)
179 data = []
180 for i in range(n):
181 br.GetEntry(i)
182 data.append (topy (getattr(tt, bname)))
183 print (b, tostr (data))
184 else:
185 for i in range(n):
186 tt.GetEntry(i)
187 print ('\nEvent', i)
188 print ('-----------')
189 for b in bb:
190 print (b, tostr (topy (getattr (tt, b))))
191 return
192
193

◆ form_list()

python.dumptuple_any.form_list ( l)

Definition at line 70 of file dumptuple_any.py.

70def form_list(l):
71 if not isinstance(l, list):
72 return l
73 return '[' + ','.join(l) + ']'

◆ isint()

python.dumptuple_any.isint ( o)

Definition at line 62 of file dumptuple_any.py.

62def isint(o):
63 try:
64 _ = int(o)
65 except ValueError:
66 return False
67 return True
68
69

◆ merge_names()

python.dumptuple_any.merge_names ( blist)

Definition at line 126 of file dumptuple_any.py.

126def merge_names (blist):
127 out = []
128 lasttag = ''
129 for (i,b) in enumerate(blist):
130 if i < len(blist)-1:
131 b2 = blist[i+1]
132 else:
133 b2 = ''
134 comm1 = common_length (lasttag, b)
135 comm2 = common_length (b, b2)
136 if comm1 >= comm2:
137 if comm1 != len(lasttag):
138 while comm1 > 0 and b[comm1-1] != '_':
139 comm1 -= 1
140 if b[:comm1] != lasttag:
141 lasttag = b[:comm1]
142 out.append (':' + lasttag)
143 else:
144 while comm2 > 0 and b[comm2-1] != '_':
145 comm2 -= 1
146 if b[:comm2] != lasttag:
147 lasttag = b[:comm2]
148 out.append (':' + lasttag)
149
150 nm = b[len(lasttag):]
151 if len(nm) == 0: nm = '$'
152 out.append (nm)
153 return out
154
155
156

◆ squash_list()

python.dumptuple_any.squash_list ( l)

Definition at line 74 of file dumptuple_any.py.

74def squash_list(l):
75 if not l: return l
76 frags=[]
77 nextfrag = []
78 i = 0
79 while i < len (l):
80 if i < len(l)-1 and l[i] == l[i+1]:
81 if nextfrag: frags.append(nextfrag)
82 nextfrag = []
83 j = i+2
84 while j < len(l) and l[i] == l[j]:
85 j += 1
86 frags.append ('%d*[%s]' % (j-i, l[i]))
87 i = j
88 #elif (i < len(l)-2 and isint(l[i]) and
89 # isint(l[i+1]) and isint(l[i+2]) and
90 # int(l[i+1]) == int(l[i])+1 and int(l[i+2]) == int(l[i])+2):
91 # nextfrag = []
92 # j = i+3
93 # while j < len(l) and isint(l[j]) and int(l[j]) == int(l[i]) + (j-i):
94 # j += 1
95 # frags.append ('range(%s,%d)' % (l[i], int(l[i]) + (j-i)))
96 # i = j
97 else:
98 nextfrag.append (l[i])
99 i += 1
100 if nextfrag: frags.append (nextfrag)
101 frags = [form_list(s) for s in frags]
102 return '+'.join (frags)
103
104
105

◆ topy()

python.dumptuple_any.topy ( o)

Definition at line 33 of file dumptuple_any.py.

33def topy (o):
34 if type(o).__name__ in ['map<string,string>',
35 'map<string,float>',
36 'map<string,int>']:
37 keys = ROOT.D3PDTest.MapDumper.keys (o)
38 values = ROOT.D3PDTest.MapDumper.values (o)
39 return OrderedDict (sorted (zip (keys, values), key=lambda t: t[0]))
40 if (type(o).__name__.startswith ('vector<char') or
41 type(o).__name__.startswith ('vector<unsigned char')):
42 ll = list(o)
43 lens = [len(x) for x in ll]
44 if lens and min(lens) == 1 and max(lens) == 1:
45 ll = [ord(x) for x in ll]
46 return ll
47 if type(o).__name__.startswith ('vector<'):
48 return [topy(x) for x in o]
49 if type(o).__name__ in ['PyFloatBuffer',
50 'PyIntBuffer']:
51 return list(o)
52 return o
53
54
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41

◆ tostr()

python.dumptuple_any.tostr ( o)

Definition at line 106 of file dumptuple_any.py.

106def tostr (o):
107 if isinstance(o, list):
108 l = [tostr(x) for x in o]
109 if len(l) > 1:
110 return squash_list(l)
111 return '[' + ', '.join (l) + ']'
112 if isinstance(o, str):
113 s = repr(o)
114 else:
115 s = str(o)
116 if s.endswith ('.0'): s = s[:-2]
117 return s
118
119

Variable Documentation

◆ by_branch

bool python.dumptuple_any.by_branch = False

Definition at line 241 of file dumptuple_any.py.

◆ file

python.dumptuple_any.file = 'test1.root'

Definition at line 240 of file dumptuple_any.py.