#!/usr/bin/env python3
"""
to be launched like this: ipython3 --matplotlib=qt5 scanBecDbMD.py
"""
#import matplotlib
#matplotlib.use('qt5agg')
from bluesky import Msg
from bluesky.plans import scan
import blueskyDESY
from bluesky import RunEngine
from bluesky.callbacks.best_effort import BestEffortCallback
from bluesky.preprocessors import SupplementalData
from databroker import Broker
def main():
db = Broker.named('temp')
bec = BestEffortCallback()
AMG = blueskyDESY.getActiveMntGrp()
print( "testMG.main: AMG %s " % repr( AMG))
mg = blueskyDESY.Experiment( read_attrs = AMG[ 'counters'])
eh_mot65 = blueskyDESY.motorTango( name = 'eh_mot65')
RE = RunEngine()
sd = SupplementalData()
RE.preprocessors.append(sd)
sd.baseline = [mg, eh_mot65]
RE.subscribe( db.insert)
#
# matplotlib and printout
#
RE.subscribe( bec)
#
# data to pyspMonitor3.py
#
RE.subscribe(blueskyDESY.docCallback())
RE.md[ 'user'] = 'p09user' # permanent metadata, lifetime of RE
uid, = RE(scan([mg], eh_mot65, 0, 0.1, 3), sample='Gold') # metadata for this run
#header = db[uid]
header = db[-1]
# or header = db[-1]
print( "header.start %s " % repr( header.start))
print( "header.table %s " % repr( header.table()))
print( "header.table, primary %s " % repr( header.table( 'primary')))
print( "header.table, baseline %s " % repr( header.table( 'baseline')))
res = db( user='p09user')
print( "results %s" % type( res))
return
if __name__ == "__main__":
main()