72 lines
2.0 KiB
Python
72 lines
2.0 KiB
Python
import numpy as np
|
|
import yaml
|
|
import os
|
|
|
|
import epics
|
|
|
|
# things to do:
|
|
# 1. Read a snapshot file (not request file)
|
|
# 2. Save a snapshot file
|
|
# 3. add parameters and performance channels (e.g. AT photon energies)
|
|
|
|
def parseSnapShotReqYAML(filename):
|
|
# read the snapshot request file
|
|
# returns a list of PV names
|
|
if not filename:
|
|
filename = '/sf/data/applications/snapshot/req/op/SF_settings.yaml'
|
|
pvs = []
|
|
path = os.path.dirname(filename)
|
|
with open(filename) as f:
|
|
try:
|
|
content = yaml.load(f, Loader=yaml.SafeLoader)
|
|
if 'include' in content.keys():
|
|
if len(content['include']) > 0:
|
|
for cont in content['include']:
|
|
retpv = parseSnapShotReqYAML(path+'/'+cont['name'])
|
|
if 'macros' in cont.keys():
|
|
retpv = applyReqMacro(retpv,cont['macros'])
|
|
pvs = pvs + retpv
|
|
if 'pvs' in content.keys():
|
|
if 'list' in content['pvs']:
|
|
for pv in content['pvs']['list']:
|
|
pvs.append(pv['name'])
|
|
return pvs
|
|
return None
|
|
except yaml.YAMLError as e:
|
|
print(e)
|
|
return None
|
|
return None
|
|
|
|
def applyReqMacro(pvs_in,macros):
|
|
pvs = []
|
|
for macro in macros:
|
|
for key in macro:
|
|
tag='$('+key+')'
|
|
for pv in pvs_in:
|
|
if tag in pv:
|
|
pvs.append(pv.replace(tag,macro[key]))
|
|
for pv in pvs_in: # copy the ones without macro
|
|
if not '$(' in pv:
|
|
pvs.append(pv)
|
|
return pvs
|
|
|
|
def getSnap(pvs=None):
|
|
if not isinstance(pvs,list):
|
|
pvs = parseSnapShotReqYAML(pvs)
|
|
if not pvs:
|
|
return
|
|
ret={}
|
|
val = epics.caget_many(pvs)
|
|
for i,pv in enumerate(pvs):
|
|
if val[i]: # filter out None values
|
|
ret[pv]=float(val[i])
|
|
epics.ca.clear_cache()
|
|
return ret
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|