Other api/dybdbi/mapper

Previous topic


Next topic


This Page

Daya Bay Links

Content Skeleton


class DybDbi.Mapper(cls, csv_fields, **kwargs)

Bases: dict

Establish the mapping between sets of fields (such as csv fields) and dbi attributes, usage:

ckf = ['status', '_srcline', 'afterPulse', 'sigmaSpe', 'pmtID', 'efficiency', 'darkRate', '_hasblank', 'prePulse', 'speLow', 'timeOffset', 'timeSpread', 'speHigh', 'description']
mpr = Mapper( GCalibPmtSpec, ckf , afterPulse="AfterPulseProb", sigmaSpe="SigmaSpeHigh", prePulse="PrePulseProb", description="Describ" )
print mpr

If a mapping cannot be made, an exception is thrown that reports the partial mapping constructed.

The automapping performed is dumb by design, only case insensitively identical names are auto mapped. Other differences between csv field names and dbi attributes must be manually provided in the keyword arguments.

The string codetype from the spec is promoted into the corresponding python type, to enable conversion of the csv dict (comprised of all strings) into a dbi dict with appropriate types for the values.


Basic auto mapping, using case insensitive comparison and yielding case sensitive mapping from csv fields to dbi attributes

The index of the csv fieldname in the dbi attribute list is found with case insensitive string comparison

check_kv(kvl, expect, name)

Check the keys/values are in the expected list


Translate dict with csv fieldnames into dict with dbi attr names and appropiate types for insertion into the DBI Row cls instance