ATLAS Offline Software
Loading...
Searching...
No Matches
python.IoTestsLib Namespace Reference

Functions

 pymon ()
 comp_delta (d, verbose=False)
 import_ROOT ()
 io_test1_write (fname, nevts=1000, sz=1000, dtype='i')
 io_test1_read (fname, verbose=False)
 io_test2_write (fname, nevts=1000, sz=1000, dtype='i')
 io_test2_read (fname, verbose=False)

Variables

str __author__ = "Sebastien Binet <binet@cern.ch>"
str __version__ = "$Revision: 1.1 $"
str __doc__
int _pagesz = sysconf('SC_PAGE_SIZE') // 1024
dict _py_dtype_to_root
 ROOT = import_ROOT()
int nreads = 10
dict mon_data = {}
str fname = '/tmp/out_test1_ints.root'
 w

Function Documentation

◆ comp_delta()

python.IoTestsLib.comp_delta ( d,
verbose = False )

Definition at line 44 of file IoTestsLib.py.

44def comp_delta(d, verbose=False):
45 assert 'start' in d
46 assert 'stop' in d
47 assert len(d['start']) == 3
48 assert len(d['stop']) == 3
49 if verbose:
50 print (repr(d))
51 delta = { 'cpu' : d['stop'][0] - d['start'][0],
52 'vmem': d['stop'][1] - d['start'][1],
53 'rss' : d['stop'][2] - d['start'][2],
54 'nbytes': -1
55 }
56 if 'nbytes' in d:
57 delta['nbytes'] = d['nbytes']
58 print ("==> cpu: %(cpu)8.3f ms vmem: %(vmem)i kB rss: %(rss)i kB nbytes: %(nbytes)i kB" % delta)
59 return delta
60

◆ import_ROOT()

python.IoTestsLib.import_ROOT ( )

Definition at line 61 of file IoTestsLib.py.

61def import_ROOT():
62 import sys
63 # for ROOT...
64 if '-b' not in sys.argv:
65 sys.argv.insert(1, '-b')
66 import ROOT
67 return ROOT
68

◆ io_test1_read()

python.IoTestsLib.io_test1_read ( fname,
verbose = False )

Definition at line 97 of file IoTestsLib.py.

97def io_test1_read(fname, verbose=False):
98 f = ROOT.TFile.Open(fname, 'READ')
99 t = f.Get('t')
100 assert t, "could not find tree 't'"
101 nevts = t.GetEntries()
102 if verbose:
103 print ("::: reading [%s] (%i events) [sz=%s kB]" % (fname, nevts,
104 f.GetSize()//1024))
105 tot_bytes = 0
106 get_entry = t.GetEntry
107 start = pymon()
108 for ievt in range(nevts):
109 # copy next entry into memory and verify
110 nb = get_entry(ievt)
111 if nb <= 0:
112 continue
113 tot_bytes += nb
114 # use the values directly from the tree
115 assert len(t.data) > 0
116 stop = pymon()
117
118 del t
119 f.Close()
120
121 return {'start' : start,
122 'stop' : stop,
123 'nbytes': tot_bytes//1024}
124
125@forking

◆ io_test1_write()

python.IoTestsLib.io_test1_write ( fname,
nevts = 1000,
sz = 1000,
dtype = 'i' )
testing writing 1000 evts with arrays of 1000- integers

Definition at line 72 of file IoTestsLib.py.

72def io_test1_write(fname, nevts=1000, sz=1000, dtype='i'):
73 """testing writing 1000 evts with arrays of 1000- integers
74 """
75 f = ROOT.TFile.Open(fname, 'RECREATE')
76 t = ROOT.TTree('t', 't')
77
78 nevts= nevts
79 imax = sz
80 data = carray(dtype, imax*[ 0 ] )
81 #t.Branch( 'mynum', n, 'mynum/I' )
82 t.Branch( 'i', data, 'data[%d]/%s'%(imax, _py_dtype_to_root[dtype]) )
83
84 from random import randint
85
86 fill = t.Fill
87 for i in range(nevts):
88 for j in range(sz):
89 data[j] = randint(0, sz)
90 fill()
91
92 f.Write()
93 f.Close()
94 return
95
96@forking
void fill(H5::Group &out_file, size_t iterations)

◆ io_test2_read()

python.IoTestsLib.io_test2_read ( fname,
verbose = False )

Definition at line 155 of file IoTestsLib.py.

155def io_test2_read(fname, verbose=False):
156 f = ROOT.TFile.Open(fname, 'READ')
157 t = f.Get('t')
158 assert t, "could not find tree 't'"
159 nevts = t.GetEntries()
160 if verbose:
161 print ("::: reading [%s] (%i events) [sz=%s kB]" % (fname, nevts,
162 f.GetSize()//1024))
163 tot_bytes = 0
164 get_entry = t.GetEntry
165 start = pymon()
166 for ievt in range(nevts):
167 # copy next entry into memory and verify
168 nb = get_entry(ievt)
169 if nb <= 0:
170 continue
171 tot_bytes += nb
172 # use the values directly from the tree
173 assert len(t.data) > 0
174 stop = pymon()
175
176 del t
177 f.Close()
178
179 return {'start' : start,
180 'stop' : stop,
181 'nbytes': tot_bytes//1024}
182
183

◆ io_test2_write()

python.IoTestsLib.io_test2_write ( fname,
nevts = 1000,
sz = 1000,
dtype = 'i' )
testing writing 1000 evts with arrays of (variable length) 1000- ints

Definition at line 126 of file IoTestsLib.py.

126def io_test2_write(fname, nevts=1000, sz=1000, dtype='i'):
127 """testing writing 1000 evts with arrays of (variable length) 1000- ints
128 """
129 f = ROOT.TFile.Open(fname, 'RECREATE')
130 t = ROOT.TTree('t', 't')
131
132 nevts= nevts
133 imax = sz
134
135 n = carray( 'i', [ 0 ] )
136 data = carray( dtype, imax*[ 0 ] )
137 t.Branch( 'sz', n, 'sz/I' )
138 t.Branch( 'data', data, 'data[sz]/%s'%_py_dtype_to_root[dtype])
139
140 from random import randint
141
142 fill = t.Fill
143 for i in range(nevts):
144 jmax = randint(1, sz)
145 n[0] = jmax
146 for j in range(jmax):
147 data[j] = randint(0, sz)
148 fill()
149
150 f.Write()
151 f.Close()
152 return
153
154@forking

◆ pymon()

python.IoTestsLib.pymon ( )
returns (cpu[ms], vmem[kb], rss[kb])

Definition at line 31 of file IoTestsLib.py.

31def pymon():
32 """returns (cpu[ms], vmem[kb], rss[kb])
33 """
34 from resource import getrusage, RUSAGE_SELF
35 from string import split as ssplit
36 cpu = getrusage(RUSAGE_SELF)
37 mem = open('/proc/self/statm','r')
38 cpu = (cpu.ru_utime+cpu.ru_stime) * 1e3 # in milliseconds
39 mem = ssplit(mem.readlines()[0])
40 vmem = int(mem[0])*_pagesz
41 rss = int(mem[1])*_pagesz
42 return cpu,vmem,rss
43

Variable Documentation

◆ __author__

str python.IoTestsLib.__author__ = "Sebastien Binet <binet@cern.ch>"
private

Definition at line 7 of file IoTestsLib.py.

◆ __doc__

str python.IoTestsLib.__doc__
private
Initial value:
1= """
2a set of simple minded functions to test ROOT I/O (from python)
3"""

Definition at line 9 of file IoTestsLib.py.

◆ __version__

str python.IoTestsLib.__version__ = "$Revision: 1.1 $"
private

Definition at line 8 of file IoTestsLib.py.

◆ _pagesz

int python.IoTestsLib._pagesz = sysconf('SC_PAGE_SIZE') // 1024
protected

Definition at line 20 of file IoTestsLib.py.

◆ _py_dtype_to_root

dict python.IoTestsLib._py_dtype_to_root
protected
Initial value:
1= {
2 'i' : 'I',
3 'f' : 'F',
4 }

Definition at line 22 of file IoTestsLib.py.

◆ fname

str python.IoTestsLib.fname = '/tmp/out_test1_ints.root'

Definition at line 197 of file IoTestsLib.py.

◆ mon_data

dict python.IoTestsLib.mon_data = {}

Definition at line 190 of file IoTestsLib.py.

◆ nreads

int python.IoTestsLib.nreads = 10

Definition at line 189 of file IoTestsLib.py.

◆ ROOT

python.IoTestsLib.ROOT = import_ROOT()

Definition at line 69 of file IoTestsLib.py.

◆ w

python.IoTestsLib.w
Initial value:
1= io_test1_write(fname=fname,
2 nevts=100000, sz=1000,
3 dtype='i')

Definition at line 198 of file IoTestsLib.py.