ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tools
PROCTools
python
root_lsr_rank.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4
5
11
12
import
ROOT
13
import
sys
14
import
os
15
import
argparse
16
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()
30
31
ordering = args.rankorder
32
33
accounting = {}
34
hashes = {}
35
types = {}
36
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; }"
)
40
41
42
def
dumpdir
(d):
43
thispath = d.GetPath()
44
if
':'
in
thispath:
45
thispath = thispath.split(
':'
, 1)[1]
46
#print (thispath)
47
subdirs = []
48
for
k
in
d.GetListOfKeys():
49
if
not
args.metadata
and
k.GetName() ==
'metadata'
and
k.GetClassName() ==
'TTree'
:
50
continue
51
if
k.GetClassName().startswith(
'TDirectory'
):
52
subdirs.append(k)
53
else
:
54
if
args.hash:
55
#lhash = ROOT.bufferhash(k)
56
#objsize = (k.GetNbytes()-k.GetKeylen())/8
57
#print ((k.GetNbytes()-k.GetKeylen())/8.)
58
#buf = ROOT.getbuffer(k); buf.SetSize(objsize)
59
#print (buf[objsize-1], objsize)
60
#lhash = zlib.adler32(str(buf))
61
#k.DeleteBuffer()
62
#obj=k.ReadObj();
63
#tm=ROOT.TMessage(ROOT.TMessage.kMESS_OBJECT)
64
#tm.WriteObject(obj)
65
lhash = ROOT.bufferhash2(k)
66
#obj.IsA().Destructor(obj)
67
#lhash = 0
68
else
:
69
lhash = 0
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()
74
#print ('%s,' % os.path.join(thispath, k.GetName()), end='')
75
#obj = k.ReadObj(); obj.IsA().Destructor(obj)
76
#print ('OK')
77
for
k
in
subdirs:
78
dumpdir
(k.ReadObj())
79
80
f = ROOT.TFile.Open(args.filename)
81
if
args.path:
82
d = f.Get(args.path.rstrip(
'/'
))
83
if
not
d:
84
print
(
"Can't access path"
, args.path,
"- exiting"
)
85
sys.exit(1)
86
else
:
87
d = f
88
dumpdir
(d)
89
90
#sortedl = sorted(accounting.items(), key=operator.itemgetter(0,1), reverse=True)
91
if
ordering ==
'onfile'
:
92
key=
lambda
x: (x[1][1], x[1][0], x[0])
# noqa: E731
93
elif
ordering ==
'uncompressed'
:
94
key=
lambda
x: (x[1][0], x[1][1], x[0])
# noqa: E731
95
else
:
96
key=
lambda
x: (x[0], x[1][1], x[1][0])
# noqa: E731
97
sortedl = sorted(accounting.items(), key=key, reverse=
True
)
98
if
args.hash:
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))
100
else
:
101
print
(
'\n'
.join(
'%s %s: %d uncompressed, %d on file'
% (types[a], a, b, c)
for
a, (b, c)
in
sortedl))
102
python.root_lsr_rank.dumpdir
dumpdir(d)
Definition
root_lsr_rank.py:42
Generated on
for ATLAS Offline Software by
1.17.0