ATLAS Offline Software
Loading...
Searching...
No Matches
hist_file_dump Namespace Reference

Functions

 fixprecision (x, precision=15)
 jsonfixup (instr, fuzzyarray=False)
 fuzzytreehash (tkey)
 dumpdir (d)
 key (x)

Variables

 parser = argparse.ArgumentParser()
 help
 default
 choices
 action
 args = parser.parse_args()
 ordering = args.rankorder
dict accounting = {}
 f = ROOT.TFile.Open(args.filename)
 d = f.Get(args.path.rstrip('/'))
 sortedl = sorted(accounting.items(), key=key, reverse=True)

Function Documentation

◆ dumpdir()

hist_file_dump.dumpdir ( d)

Definition at line 106 of file hist_file_dump.py.

106def dumpdir(d):
107 thispath = d.GetPath()
108 if ':' in thispath:
109 thispath = thispath.split(':', 1)[1]
110 #print thispath
111 subdirs = []
112 for k in d.GetListOfKeys():
113 if not args.metadata and k.GetName() == 'metadata' and k.GetClassName() == 'TTree':
114 continue
115 if k.GetClassName().startswith('TDirectory'):
116 subdirs.append(k)
117 else:
118 if args.tree_entries and k.GetClassName() == 'TTree':
119 lhash = fuzzytreehash(k)
120 elif args.hash:
121 if k.GetClassName() != 'TEfficiency':
122 fixedjson = jsonfixup(ROOT.getjson(k), args.fuzzy_histbins)
123 else:
124 j0 = json.loads(ROOT.getjson(k).Data())
125 for subh in ('fPassedHistogram', 'fTotalHistogram'):
126 j0[subh] = json.loads(jsonfixup(json.dumps(j0[subh])))
127 fixedjson = json.dumps(j0, sort_keys=True)
128 lhash = zlib.adler32(fixedjson.encode())
129 if lhash < 0:
130 lhash += 2**32
131 else:
132 lhash = 0
133 idxname = os.path.join(thispath, k.GetName())
134 accounting[idxname] = (k.GetObjlen(), k.GetNbytes()-k.GetKeylen())
135 hashes[idxname] = lhash
136 types[idxname] = k.GetClassName()
137 for k in subdirs:
138 dumpdir(k.ReadObj())
139
@ Data
Definition BaseObject.h:11

◆ fixprecision()

hist_file_dump.fixprecision ( x,
precision = 15 )

Definition at line 12 of file hist_file_dump.py.

12def fixprecision(x, precision=15):
13 import math
14 if not isinstance(x, float):
15 return x
16 else:
17 mantissa, exponent = math.frexp(x)
18 sm = '%.12g' % mantissa
19 return _formatFloat (float(sm[:precision]) * 2**exponent)
20

◆ fuzzytreehash()

hist_file_dump.fuzzytreehash ( tkey)

Definition at line 97 of file hist_file_dump.py.

97def fuzzytreehash(tkey):
98 t = tkey.ReadObj()
99 rv = zlib.adler32(((' '.join(_.GetName() for _ in t.GetListOfBranches()))
100 + (' '.join(_.GetName() + _.GetTypeName() for _ in t.GetListOfLeaves()))
101 + ' ' + str(t.GetEntries())).encode()
102 )
103 del t
104 return rv
105

◆ jsonfixup()

hist_file_dump.jsonfixup ( instr,
fuzzyarray = False )

Definition at line 21 of file hist_file_dump.py.

21def jsonfixup(instr, fuzzyarray=False):
22 if not isinstance(instr, str):
23 instr = instr.Data()
24 j=json.loads(instr)
25 # the following are very subject to floating point numeric effects
26 # are doubles, keep 15 decimal digits of precision
27 for badkey in ('fTsumw', 'fTsumwx', 'fTsumw2', 'fTsumwx2', 'fTsumwy', 'fTsumwy2', 'fTsumwxy',
28 'fTsumwz', 'fTsumwz2', 'fTsumwxz', 'fTsumwyz' ):
29 if badkey in j:
30 j[badkey] = fixprecision(float(j[badkey]))
31 #print(type(j["fTsumwx"]))
32 # member, digits of precision
33 arrkeys: List[Tuple[str,int,Callable]] = [('fSumw2', 15, float)]
34 if fuzzyarray:
35 arrkeys += [('fBinEntries', 15, float), ('fBinSumw2', 15, float)]
36 # apply different precision for fArray depending on object type
37 if '_typename' in j:
38 if j['_typename'] in ('TH1F', 'TH2F', 'TH3F'):
39 arrkeys.append(('fArray', 6, float))
40 elif j['_typename'] in ('TH1C', 'TH1I', 'TH1S', 'TH2C', 'TH2I', 'TH2S',
41 'TH3C', 'TH3I', 'TH3S'):
42 # precision here isn't relevant, *should* be an integer
43 arrkeys.append(('fArray', 15, lambda x: x))
44 else:
45 arrkeys.append(('fArray', 15, float))
46 else:
47 arrkeys.append(('fArray', 15, float))
48 for badkey, precision, func in arrkeys:
49 if badkey in j:
50 j[badkey] = [fixprecision(func(_), precision) for _ in j[badkey]]
51 # the following ignores small layout fluctuations in TTrees
52 if 'fBranches' in j:
53 for branch in j['fBranches']['arr']:
54 branch['fBasketSeek'] = []
55 # The formatting of the opt array changed in newer ROOT versions
56 # to be filled with instances of None rather than empty strings.
57 if 'fXaxis' in j and 'fLabels' in j['fXaxis'] and j['fXaxis']['fLabels'] is not None and 'opt' in j['fXaxis']['fLabels']:
58 opt = j['fXaxis']['fLabels']['opt']
59 for i in range(len(opt)):
60 if opt[i] is None: opt[i] = ''
61 return json.dumps(j, sort_keys=True)
62

◆ key()

hist_file_dump.key ( x)

Definition at line 151 of file hist_file_dump.py.

151 def key(x): return (x[1][1], x[1][0], x[0])

Variable Documentation

◆ accounting

dict hist_file_dump.accounting = {}

Definition at line 87 of file hist_file_dump.py.

◆ action

hist_file_dump.action

Definition at line 71 of file hist_file_dump.py.

◆ args

hist_file_dump.args = parser.parse_args()

Definition at line 83 of file hist_file_dump.py.

◆ choices

hist_file_dump.choices

Definition at line 67 of file hist_file_dump.py.

◆ d

hist_file_dump.d = f.Get(args.path.rstrip('/'))

Definition at line 142 of file hist_file_dump.py.

◆ default

hist_file_dump.default

Definition at line 66 of file hist_file_dump.py.

◆ f

hist_file_dump.f = ROOT.TFile.Open(args.filename)

Definition at line 140 of file hist_file_dump.py.

◆ help

hist_file_dump.help

Definition at line 65 of file hist_file_dump.py.

◆ ordering

hist_file_dump.ordering = args.rankorder

Definition at line 85 of file hist_file_dump.py.

◆ parser

hist_file_dump.parser = argparse.ArgumentParser()

Definition at line 63 of file hist_file_dump.py.

◆ sortedl

hist_file_dump.sortedl = sorted(accounting.items(), key=key, reverse=True)

Definition at line 156 of file hist_file_dump.py.