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