示例#1
0
def calc_terminal(template_def, config, nodenum, terminal_id, return_type='full'):
    """ json-rpc wrapper for calc_single
    template_def = 
    {"name": "template_name",
     "description": "template description!",
     "modules": ["list of modules"],
     "wires": ["list of wires"],
     "instrument": "facility.instrument_name",
     "version": "2.7.3"
    }
    
    where modules in list of modules above have structure:
    module = 
    {"module": "facility.instrument_name.module_name",
     "version": "0.3.2"
    }
    
    and wires have structure:
    [["wire_start_module_id:wire_start_terminal_id", "wire_end_module_id:wire_end_terminal_id"],
     ["1:output", "2:input"],
     ["0:xslice", "3:input"]
    ]
    
    config = 
    [{"param": "value"}, ...]
    
    nodenum is the module number from the template for which you wish to get the calculated value
    
    terminal_id is the id of the terminal for that module, that you want to get the value from
    (output terminals only).
    """
    template = Template(**template_def)
    #print "template_def:", template_def, "config:", config, "target:",nodenum,terminal_id
    #print "modules","\n".join(m for m in df._module_registry.keys())
    try:
        retval = process_template(template, config, target=(nodenum, terminal_id))
    except:
        print "==== template ===="; pprint(template_def)
        print "==== config ===="; pprint(config)
        traceback.print_exc()
        raise
    if return_type == 'full':
        return sanitizeForJSON(retval.todict())
    elif return_type == 'plottable':
        return sanitizeForJSON(retval.get_plottable())
    elif return_type == 'metadata':
        return sanitizeForJSON(retval.get_metadata())
    elif return_type == 'export':
        return retval.get_export()
    else:
        raise KeyError(return_type + " not a valid return_type (should be one of ['full', 'plottable', 'metadata', 'export'])")
示例#2
0
def refl_load(file_descriptors):
    """ 
    file_descriptors will be a list of dicts like 
    [{"path": "ncnrdata/cgd/201511/21066/data/HMDSO_17nm_dry14.nxz.cgd", "mtime": 1447353278}, ...]
    """
    modules = [{"module": "ncnr.refl.load", "version": "0.1", "config": {}}]
    template = Template("test", "test template", modules, [], "ncnr.magik", version='0.0')
    retval = process_template(template, {0: {"files": file_descriptors}}, target=(0, "output"))
    return sanitizeForJSON(retval.todict())
示例#3
0
 def wrapper(*args, **kwds):
     print ":::reflweb.api."+action.__name__
     try:
         if use_msgpack:
             import msgpack, base64
             retval = {"serialization": "msgpack", "encoding": "base64"}
             retval['value'] = base64.b64encode(msgpack.dumps(action(*args, **kwds)))
         else:
             retval = {"serialization": "json", "encoding": "string"}
             retval['value'] = sanitizeForJSON(action(*args, **kwds))
     except Exception as exc:
         traceback.print_exc()
         print ">>> :::refweb.api."+action.__name__
         raise
     #print "leaving :::reflweb.api."+action.__name__
     return retval
示例#4
0
def calc_template(template_def, config):
    """ json-rpc wrapper for process_template """
    template = Template(**template_def)
    #print "template_def:", template_def, "config:", config
    try:
        retvals = process_template(template, config, target=(None,None))
    except:
        print "==== template ===="; pprint(template_def)
        print "==== config ===="; pprint(config)
        traceback.print_exc()
        raise
    output = {}
    for rkey, rv in retvals.items():
        module_id, terminal_id = rkey
        module_key = str(module_id)
        output.setdefault(module_key, {})
        output[module_key][terminal_id] = sanitizeForJSON(rv.todict())
    return output