Other api/dybdbi/wrap

Previous topic

DybDbi

Next topic

DybDbi.CSV

This Page

Daya Bay Links

Content Skeleton

DybDbi.Wrap

Wrapping is the principal technique used by DybDbi to provide simple pythonic usage of the underlying C++ classes (actually PyROOT proxies).

class DybDbi.Wrap(kls, attfn={})

Bases: object

Control center for application of generic class manipulations based on the names of methods in contained kls. The manipulations do not require the classes to be imported into this scope.

Wrapping is applied to:

  • all genDbi generated DbiTableRow subclasses and corresponding templated DbiRpt and DbiWrt (readers and writers)
  • a selection of other Dbi classes that are useful interactively
define__repr__()

Assign default repr ... override later if desired

define_create()

Provide pythonic instance creation classmethod:

i = GTableName.Create( AttributeName=100. , ... ) 
define_csv()

Provide csv manipulations as classmethods on the Row classes

define_listlike()

Application of function RPT to DbiRpt<T> classes provides instances of that class with a list-like interface supporting access by index and slice, indices can be negative to provide access to the end.:

r[0]      first
r[-1]     last
          
r[0:9]    first 10  
r[-3:]    last 3   


r[0:2000:500]  
r[-10:-1:2]    2-step thru the last 10 

for x in r[2540:]:
    print x

for x in r[-10:]:
    print x 

THOUGHTS : * no need for generator implementation for large result set as already all in memory anyhow

define_properties()

Define properties corresponding to Get* and Set* methods in the contained kls, providing attribute style access and setting

g = i.x
i.x = s

NB “getters” which take arguments GetWithArg(Int_t naughty) have to be skipped via:

cls.__skip__ = ("WithArg",)
define_update()

Provide dict like updating for DbiTableRow subclasses, eg:

from DybDbi import GCalibPmtSpec
r = GCalibPmtSpec.Rpt()
z = r[0]
print z.asdict        
print z.keys             
z.update( Status=10 ) 
get_attfn(m)

Returns function than when applied to an object returns (m,obj.Get<m>() ) where m is the attribute name

make__repr__()

Provide a default __repr__ function that presents the attribute names and values as a dict