202def _parse_ttree_summary(lines, pos):
203 """
204 Parse the TTree summary table in lines, starting from pos.
205 Returns a tuple with the dictionary with the digested informations and the
206 position of the first line after the summary.
207 """
208 result = {}
209 i = pos + 1
210 count = len(lines)
211
212 def splitcols(l):
213 return [f.strip() for f in l.strip("*\n").split(":", 2)]
214
215 def parseblock(ll):
216 r = {}
217 delta_i = 0
218 cols = splitcols(ll[0])
219
220 if len(ll) == 3:
221
222 r["Name"], r["Title"] = cols[1:]
223 elif len(ll) == 4:
224
225 delta_i = 1
226 r["Name"] = cols[1]
227 r["Title"] = ll[1].strip("*\n").split("|")[1].strip()
228 else:
229 assert False
230
231 cols = splitcols(ll[1 + delta_i])
232 r["Entries"] = int(cols[1])
233
234 sizes = cols[2].split()
235 r["Total size"] = int(sizes[2])
236 if sizes[-1] == "memory":
237 r["File size"] = 0
238 else:
239 r["File size"] = int(sizes[-1])
240
241 cols = splitcols(ll[2 + delta_i])
242 sizes = cols[2].split()
243 if cols[0] == "Baskets":
244 r["Baskets"] = int(cols[1])
245 r["Basket size"] = int(sizes[2])
246 r["Compression"] = float(sizes[-1])
247
248 return r
249
250 def nextblock(lines, i):
251 delta_i = 1
252 dots = re.compile(r"^\.+$")
253 stars = re.compile(r"^\*+$")
254 count = len(lines)
255 while (
256 i + delta_i < count
257 and not dots.match(lines[i + delta_i][1:-1])
258 and not stars.match(lines[i + delta_i])
259 ):
260 delta_i += 1
261 return i + delta_i
262
263 if i < (count - 3) and lines[i].startswith("*Tree"):
264 i_nextblock = nextblock(lines, i)
265 result = parseblock(lines[i:i_nextblock])
266 result["Branches"] = {}
267 i = i_nextblock + 1
268 while i < (count - 3) and lines[i].startswith("*Br"):
269 if i < (count - 2) and lines[i].startswith("*Branch "):
270
271 i += 3
272 continue
273 i_nextblock = nextblock(lines, i)
274 if i_nextblock >= count:
275 break
276 branch = parseblock(lines[i:i_nextblock])
277 result["Branches"][branch["Name"]] = branch
278 i = i_nextblock + 1
279
280 return (result, i)
281
282