Other api/dybdbi/wrap

Previous topic


Next topic


This Page

Daya Bay Links

Content Skeleton


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

Assign default repr ... override later if desired


Provide pythonic instance creation classmethod:

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

Provide csv manipulations as classmethods on the Row classes


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[-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 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",)

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 ) 

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


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