17 parser=argparse.ArgumentParser()
18 parser.add_argument(
'filename',
19 help=
'Input HIST file name')
20 parser.add_argument(
'-r',
'--rankorder', default=
'onfile',
21 choices=[
'onfile',
'uncompressed',
'name'],
22 help=
'rankorder is "onfile" (default), "uncompressed" or "name"')
23 parser.add_argument(
'-p',
'--path',
24 help=
'Only look under this directory')
25 parser.add_argument(
'--hash', action=
'store_true',
26 help=
'Print hashes of objects')
27 parser.add_argument(
'--metadata', action=
'store_true',
28 help=
'Include metadata trees')
29 args=parser.parse_args()
31 ordering = args.rankorder
37 ROOT.gInterpreter.LoadText(
"UInt_t bufferhash(TKey* key) { key->SetBuffer(); key->ReadFile(); UInt_t rv = TString::Hash(key->GetBuffer()+key->GetKeylen(), key->GetNbytes()-key->GetKeylen()); key->DeleteBuffer(); return rv; }")
38 ROOT.gInterpreter.LoadText(
"void* getbuffer(TKey* key) { key->SetBuffer(); key->ReadFile(); return (void*) (key->GetBuffer()+key->GetKeylen()); }")
39 ROOT.gInterpreter.LoadText(
"UInt_t bufferhash2(TKey* key) { TObject* obj = key->ReadObj(); TMessage msg(kMESS_OBJECT); msg.WriteObject(obj); UInt_t rv = TString::Hash(msg.Buffer(), msg.Length()); delete obj; return rv; }")
43 thispath = d.GetPath()
45 thispath = thispath.split(
':', 1)[1]
48 for k
in d.GetListOfKeys():
49 if not args.metadata
and k.GetName() ==
'metadata' and k.GetClassName() ==
'TTree':
51 if k.GetClassName().startswith(
'TDirectory'):
65 lhash = ROOT.bufferhash2(k)
70 idxname = os.path.join(thispath, k.GetName())
71 accounting[idxname] = (k.GetObjlen(), k.GetNbytes()-k.GetKeylen())
72 hashes[idxname] = lhash
73 types[idxname] = k.GetClassName()
80 f = ROOT.TFile.Open(args.filename)
82 d = f.Get(args.path.rstrip(
'/'))
84 print (
"Can't access path", args.path,
"- exiting")
91 if ordering ==
'onfile':
92 key=
lambda x: (x[1][1], x[1][0], x[0])
93 elif ordering ==
'uncompressed':
94 key=
lambda x: (x[1][0], x[1][1], x[0])
96 key=
lambda x: (x[0], x[1][1], x[1][0])
97 sortedl =
sorted(accounting.items(), key=key, reverse=
True)
99 print (
'\n'.
join(
'%s %s: %d uncompressed, %d on file (hash %s)' % (types[a], a, b, c, hashes[a])
for a, (b, c)
in sortedl))
101 print (
'\n'.
join(
'%s %s: %d uncompressed, %d on file' % (types[a], a, b, c)
for a, (b, c)
in sortedl))