Belle II Software  release-08-01-10
b2file-normalize.py
1 #!/usr/bin/env python3
2 
3 
10 
11 import tempfile
12 import subprocess
13 import ROOT
14 import hashlib
15 
16 testFile = tempfile.NamedTemporaryFile()
17 fileName = testFile.name
18 
19 rootfile = ROOT.TFile.Open(fileName, 'RECREATE')
20 hist = ROOT.TH1F('hist', 'TextHistogram', 100, 0, 1)
21 ROOT.gRandom.SetSeed(42)
22 for i in range(1000):
23  hist.Fill(ROOT.gRandom.Uniform())
24 hist.Write()
25 oldHist = hist.Clone()
26 oldHist.SetDirectory(0)
27 del(rootfile)
28 
29 subprocess.run(['b2file-normalize', '-i', '-n', 'NormalizedRootFile', '-r', '61408', fileName], check=True)
30 
31 newRootFile = ROOT.TFile.Open(fileName)
32 newHist = newRootFile.Get('hist')
33 assert 0 == newHist.Chi2Test(oldHist, 'PCHI2')
34 del(newRootFile)
35 
36 checksum = hashlib.md5()
37 checksum.update(open(fileName, 'rb').read())
38 print(checksum.digest().hex())
39 assert checksum.digest().hex() == '4b616ad813c35498f6f8aa09f2bcebda'
40 del(testFile)