ATLAS Offline Software
Functions | Variables
python.IoTestsLib Namespace Reference

Functions

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

Variables

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

Function Documentation

◆ comp_delta()

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

Definition at line 44 of file IoTestsLib.py.

44 def 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()

def python.IoTestsLib.import_ROOT ( )

Definition at line 61 of file IoTestsLib.py.

61 def 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()

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

Definition at line 97 of file IoTestsLib.py.

97 def 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()

def 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.

72 def 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

◆ io_test2_read()

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

Definition at line 155 of file IoTestsLib.py.

155 def 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()

def 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.

126 def 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()

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

Definition at line 31 of file IoTestsLib.py.

31 def 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__

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

Definition at line 7 of file IoTestsLib.py.

◆ __doc__

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

Definition at line 9 of file IoTestsLib.py.

◆ __version__

string 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
private

Definition at line 20 of file IoTestsLib.py.

◆ _py_dtype_to_root

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

Definition at line 22 of file IoTestsLib.py.

◆ fname

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

Definition at line 197 of file IoTestsLib.py.

◆ mon_data

dictionary python.IoTestsLib.mon_data = {}

Definition at line 190 of file IoTestsLib.py.

◆ nreads

int python.IoTestsLib.nreads = 10

tests ------------------------------------------------------------------—

Definition at line 189 of file IoTestsLib.py.

◆ ROOT

def python.IoTestsLib.ROOT = import_ROOT()

Definition at line 69 of file IoTestsLib.py.

◆ w

def 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.

python.IoTestsLib.pymon
def pymon()
Definition: IoTestsLib.py:31
python.IoTestsLib.io_test2_write
def io_test2_write(fname, nevts=1000, sz=1000, dtype='i')
Definition: IoTestsLib.py:126
python.IoTestsLib.io_test1_read
def io_test1_read(fname, verbose=False)
Definition: IoTestsLib.py:97
python.IoTestsLib.import_ROOT
def import_ROOT()
Definition: IoTestsLib.py:61
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
PyAthena::repr
std::string repr(PyObject *o)
returns the string representation of a python object equivalent of calling repr(o) in python
Definition: PyAthenaUtils.cxx:106
python.IoTestsLib.comp_delta
def comp_delta(d, verbose=False)
Definition: IoTestsLib.py:44
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
lumiFormat.fill
fill
Definition: lumiFormat.py:104
python.IoTestsLib.io_test1_write
def io_test1_write(fname, nevts=1000, sz=1000, dtype='i')
Definition: IoTestsLib.py:72
python.IoTestsLib.io_test2_read
def io_test2_read(fname, verbose=False)
Definition: IoTestsLib.py:155