To retrieve values from the data base, the get_config method is called. see

 

from psalg.configdb.get_config import get_config
import json

def tt_config(connect_str,cfgtype,detname,group):
    cfg = get_config(connect_str,cfgtype,detname)
    return json.dumps(cfg)

if __name__ == "__main__":
    connect_info = {}
    connect_info['body'] = {}
    connect_info['body']['control'] = {}
    connect_info['body']['control']['0'] = {}
    connect_info['body']['control']['0']['control_info'] = {}
    connect_info['body']['control']['0']['control_info']['instrument'] = 'TMO'
    connect_info['body']['control']['0']['control_info']['cfg_dbase'] = 'mcbrowne:psana@psdb-dev:9306/configDB'
    mystring = json.dumps(connect_info)                             #paste this string into the pgpread_timetool.cc as parameter for the tt_config function call
    my_config = tt_config(mystring,"BEAM", "tmotimetool",None)          

    print(my_config)




 

#where the arguments are:
#connect_json: string that is dumped into json from a python dict.  e.g. 
# 
#connect_dict = {}
#connect_dict['body'] = {}
#connect_dict['body']['control'] = {}
#connect_dict['body']['control']['0'] = {}
#connect_dict['body']['control']['0']['control_info'] = {}
#connect_dict['body']['control']['0']['control_info']['instrument'] = 'TMO'
#connect_dict['body']['control']['0']['control_info']['cfg_dbase']  = 'mcbrowne:psana@psdb-dev:9306/configDB'
#connect_json = json.dumps(connect_dict)
 
#cfgtype: string with enumerated values of "BEAM", and perhaps "NO_BEAM" as well?
 
#detname: string with detector identification.  in this case it's "tmotimetool"


from psalg.configdb.typed_json import cdict
import psalg.configdb.configdb as cdb
import sys
def write_scratch_pad(prescaling):


    create = True
    dbname = 'configDB'
    instrument = 'TMO'
    mycdb = cdb.configdb('mcbrowne:psana@psdb-dev:9306', instrument, create, dbname)
    my_dict = mycdb.get_configuration("BEAM","tmotimetool")

    top = cdict()
    top.setInfo('timetool', 'tmotimetool', 'serial1234', 'No comment')
    top.setAlg('timetoolConfig', [0,0,1])


    top.set("cl.Application.AppLane1.Prescale.ScratchPad",int(prescaling),'UINT32')
    mycdb.modify_device('BEAM', top)


if __name__ == "__main__":
	#takes one integer as an argument
    write_scratch_pad(sys.argv[1])




 

 

 

  • No labels