6 from __future__
import print_function
8 __author__ =
"Sebastien Binet <binet@cern.ch>"
9 __version__ =
"$Revision: 1.1 $"
11 a set of simple minded functions to test ROOT I/O (from python)
14 from array
import array
as carray
15 from builtins
import range
21 from os
import sysconf
22 _pagesz = sysconf(
'SC_PAGE_SIZE') // 1024
28 """translates the usual python 'dtype' codes to the ROOT/CINT ones
31 from PyUtils.Decorators
import forking
34 """returns (cpu[ms], vmem[kb], rss[kb])
36 from resource
import getrusage, RUSAGE_SELF
37 from string
import split
as ssplit
38 cpu = getrusage(RUSAGE_SELF)
39 mem =
open(
'/proc/self/statm',
'r')
40 cpu = (cpu.ru_utime+cpu.ru_stime) * 1e3
41 mem = ssplit(mem.readlines()[0])
42 vmem =
int(mem[0])*_pagesz
43 rss =
int(mem[1])*_pagesz
49 assert len(d[
'start']) == 3
50 assert len(d[
'stop']) == 3
53 delta = {
'cpu' : d[
'stop'][0] - d[
'start'][0],
54 'vmem': d[
'stop'][1] - d[
'start'][1],
55 'rss' : d[
'stop'][2] - d[
'start'][2],
59 delta[
'nbytes'] = d[
'nbytes']
60 print (
"==> cpu: %(cpu)8.3f ms vmem: %(vmem)i kB rss: %(rss)i kB nbytes: %(nbytes)i kB" % delta)
66 if '-b' not in sys.argv:
67 sys.argv.insert(1,
'-b')
75 """testing writing 1000 evts with arrays of 1000- integers
77 f = ROOT.TFile.Open(fname,
'RECREATE')
78 t = ROOT.TTree(
't',
't')
82 data = carray(dtype, imax*[ 0 ] )
84 t.Branch(
'i', data,
'data[%d]/%s'%(imax, _py_dtype_to_root[dtype]) )
86 from random
import randint
89 for i
in range(nevts):
91 data[j] = randint(0, sz)
100 f = ROOT.TFile.Open(fname,
'READ')
102 assert t,
"could not find tree 't'"
103 nevts = t.GetEntries()
105 print (
"::: reading [%s] (%i events) [sz=%s kB]" % (fname, nevts,
108 get_entry = t.GetEntry
110 for ievt
in range(nevts):
117 assert len(t.data) > 0
123 return {
'start' : start,
125 'nbytes': tot_bytes//1024}
129 """testing writing 1000 evts with arrays of (variable length) 1000- ints
131 f = ROOT.TFile.Open(fname,
'RECREATE')
132 t = ROOT.TTree(
't',
't')
137 n = carray(
'i', [ 0 ] )
138 data = carray( dtype, imax*[ 0 ] )
139 t.Branch(
'sz', n,
'sz/I' )
140 t.Branch(
'data', data,
'data[sz]/%s'%_py_dtype_to_root[dtype])
142 from random
import randint
145 for i
in range(nevts):
146 jmax = randint(1, sz)
148 for j
in range(jmax):
149 data[j] = randint(0, sz)
158 f = ROOT.TFile.Open(fname,
'READ')
160 assert t,
"could not find tree 't'"
161 nevts = t.GetEntries()
163 print (
"::: reading [%s] (%i events) [sz=%s kB]" % (fname, nevts,
166 get_entry = t.GetEntry
168 for ievt
in range(nevts):
175 assert len(t.data) > 0
181 return {
'start' : start,
183 'nbytes': tot_bytes//1024}
187 if __name__ ==
"__main__":
189 print (
"::: running all tests...")
199 fname =
'/tmp/out_test1_ints.root'
201 nevts=100000, sz=1000,
203 mon_data[
'io_test1-ints'] = []
204 for _
in range(nreads):
208 fname =
'/tmp/out_test1_flts.root'
210 nevts=100000, sz=1000,
212 mon_data[
'io_test1-flts'] = []
213 for _
in range(nreads):
221 fname =
'/tmp/out_test2_ints.root'
223 nevts=100000, sz=1000,
225 mon_data[
'io_test2-ints'] = []
226 for _
in range(nreads):
230 fname =
'/tmp/out_test2_floats.root'
232 nevts=100000, sz=1000,
234 mon_data[
'io_test2-flts'] = []
235 for _
in range(nreads):