Other api/dybdbi/physad

Previous topic

DybDbi.ILookup

Next topic

DybDbi.Context

This Page

Daya Bay Links

Content Skeleton

DybDbi.AdLogicalPhysical

class DybDbi.AdLogicalPhysical(timestamp=None, purgecache=False, DROP=False)

Bases: dict

Provides access to logical/physical mappings from the DBI table gendbi-gphysad, with functionality to read the mappings at particular timestamps and write them with validity time range.

  1. logical slots are expressed as tuples (site,subsite) such as (Site.kSAB,DetectorId.kAD1)
  2. physical AD indices 1,2,...8 corresponding to AD1,AD2,..,AD8

Mappings are stored within this dict keyed by logical slot. Reverse physical->logical lookups are provide by the __call__ method:

alp = AdLogicalPhysical()
site, subsite = alp(1)         ## find where AD1 is

An input physadid of None is used to express a vacated slot, and results in the writing of a payloadless DBI validity. Such None are not read back into this dict on reading, it being regarded as a write signal only.

For usage examples see dybgaudi:Database/DybDbi/tests/test_physad.py

Parameters:
  • timestamp – time at which to lookup mapping, defaults of None is promoted to now (UTC natually)
  • purgecache – clear cache before reading, needed when reading updates from same process that wrote them
  • DROP – drop the table and zero the LASTUSEDSEQNO (only use during development)

Read current mappings from PhysAd DB table, usage:

alp = AdLogicalPhysical()
print alp
blp = AdLogicalPhysical(timestamp=TimeStamp(2011,10,10,0,0,0))
print blp

Direct lookup:

phyadid = alp.get((site,subsite), None)
if physadid:
    print "(%(site)s,%(subsite)s) => %(physadid)s " % locals()

To update mappings in memory:

alp.update({(Site.kSAB,DetectorId.kAD1):1,(Site.kDayaBay,DetectorId.kAD2):2})

Vacating a formerly occupied slot is done using None:

alp.update({(Site.kSAB,DetectorId.kAD1):None,(Site.kDayaBay,DetectorId.kAD1):1})

To persist the update to the DB, within a particular timerange:

alp.write( timestart=TimeStamp.kNow() )

Read back by instanciating a new instance:

blp = AdLogicalPhysical( timestamp=... ) 

Reverse lookup from physical AD id 1,2,3..8 to logical slot:

sitesubsite = alp(1)          ## invokes the __call__ method for reverse lookup            
if sitesubsite: 
    site, subsite = sitesubsite 
else:
    print "not found" 
check_physical2logical()

Self consistency check Test that the call returns the expected slot, verifying that the physical2logic dict is in step

kls

alias of GPhysAd

classmethod lookup_logical2physical(timestamp, sitesubsite, simflag=1)
Parameters:
  • timestamp
  • sitesubsite
  • simflag
Return physadid, vrec:
 

Note that a payloadless DBI query result is interpreted to mean an empty logical slot resulting in the return of a physadid of None

Cannot use kAnySubSite = -1 to avoid querying every slot as DBI non-aggregate reads always correspond to a single SEQNO

write(timestart=None, timeend=None)

Writes mappings expressed in this dict into DB

Parameters:
  • timestart
  • timeend