21def jsonfixup(instr, fuzzyarray=False):
22 if not isinstance(instr, str):
23 instr = instr.Data()
24 j=json.loads(instr)
25
26
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
32
33 arrkeys: List[Tuple[str,int,Callable]] = [('fSumw2', 15, float)]
34 if fuzzyarray:
35 arrkeys += [('fBinEntries', 15, float), ('fBinSumw2', 15, float)]
36
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
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
52 if 'fBranches' in j:
53 for branch in j['fBranches']['arr']:
54 branch['fBasketSeek'] = []
55
56
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