started lazy import

This commit is contained in:
2018-03-20 15:55:42 +01:00
parent 9872e00b43
commit 3edbcb3ebf
7 changed files with 232 additions and 13 deletions
+5 -4
View File
@@ -283,18 +283,19 @@ class DIAClient:
def acquire(self, file_name=None, Npulses=100, JF_factor=1, bsread_padding=0):
"""
JF_factor?
JF_factor?
bsread_padding?
"""
file_rootdir = '/sf/%s/data/raw/p%d/' % (self.instrument, self.pgroup)
if file_name is None:
# FIXME /dev/null crashes the data taking (h5py can't close /dev/null and crashes)
print("Not saving any data, as file_name is not set")
file_name_JF = "/dev/null"
file_name_bsread = "/dev/null"
file_name_JF = file_rootdir + "DelMe" + '_JF1p5M.h5'
file_name_bsread = file_rootdir + "DelMe" + '.h5'
else:
# FIXME hardcoded
file_name_JF = file_rootdir +file_name + '_JF1p5M.h5'
file_name_JF = file_rootdir + file_name + '_JF1p5M.h5'
file_name_bsread = file_rootdir + file_name + '.h5'
if self.pgroup == 0:
+14 -7
View File
@@ -224,15 +224,22 @@ class SmarActRecord:
""" Adjustable convention"""
return self._llm.get('VAL'), self._hlm.get('VAL')
# def gui(self, guiType='xdm'):
# """ Adjustable convention"""
# cmd = ['caqtdm','-macro']
#
# cmd.append('\"P=%s:,M=%s\"'%tuple(self.Id.split(':')))
def gui(self, guiType='xdm'):
""" Adjustable convention"""
cmd = ['caqtdm','-macro']
for i in range(len(self.Id)-1):
if self.Id[-i-1].isnumeric() is False:
M = self.Id[-i:]
P = self.Id[:-i]
print(P, M)
break
cmd.append('\"P=%s,M=%s\"'%(P, M))
# #cmd.append('/sf/common/config/qt/motorx_more.ui')
# cmd.append('motorx_more.ui')
cmd.append('ESB_MX_SMARACT_mot_exp.ui')
# #os.system(' '.join(cmd))
# return subprocess.Popen(' '.join(cmd),shell=True)
return subprocess.Popen(' '.join(cmd),shell=True)
+8 -1
View File
@@ -126,7 +126,7 @@ def checker_function(limits):
checker = {}
checker['checker_call'] = checker_function
checker['args'] = [[100,300]]
checker['args'] = [[100,700]]
checker['kwargs'] = {}
checker['wait_time'] = 3
@@ -138,6 +138,13 @@ scansBsreadLocal = _scan.Scans(data_base_dir='/sf/bernina/config/com/data/scan_d
########### ADHOC IMPLEMENTED ########################
bsdaqJF.gain_file = "/sf/bernina/config/com/data/gains_I0.h5"
import glob
list_of_files = glob.glob('/sf/bernina/data/p17247/res/JF_pedestal/pedestal_*_res.h5')
latest_file = max(list_of_files, key=os.path.getctime)
bsdaqJF.pede_file = latest_file
from ..timing.lasertiming import Lxt as _Lxt
lxt = _Lxt()
+114
View File
@@ -0,0 +1,114 @@
from ..aliases.bernina import elog as _elog_info
from ..utilities.elog import Elog as _Elog
from ..utilities.elog import Screenshot as _Screenshot
from ..utilities.config import loadConfig
from epics import PV
import sys,os
from colorama import Fore as _color
import traceback
elog = _Elog(_elog_info['url'],user='gac-bernina',screenshot_directory=_elog_info['screenshot_directory'])
screenshot = _Screenshot(screenshot_directory=_elog_info['screenshot_directory'])
########### configurations ########################
currexp_file_path = '/sf/bernina/config/current_experiment.json'
if os.path.exists(currexp_file_path):
exp_config = loadConfig(currexp_file_path)
else:
print('NB: Could not load experiment config in path %s .'%currexp_file_path)
########### GENERAL IMPLEMENTATIONS ##################
from ..aliases.bernina import aliases as _aliases
from .utilities_instruments import initDeviceAliasList
_devices,_problems = initDeviceAliasList(_aliases,verbose=True,lazy=True)
for tdev_id,talias,tdev in _devices:
globals().update([(talias,tdev)])
if _problems:
print('Found errors when configuring %s'%[te[1] for te in _problems])
if input('Would you like to see error traces? (y/n)')=='y':
for error in _problems:
print('---> Error when configuring %s (%s)'%(error[0],error[1]))
print(error[2])
########### DAQ SECTION ########################
# configuring bs daq
def parseChannelListFile(fina):
out = []
with open(fina,'r') as f:
done = False
while not done:
d = f.readline()
if not d:
done=True
if len(d)>0:
if not d.isspace():
if not d[0]=='#':
out.append(d.strip())
return out
from ..acquisition.bs_data import BStools
from ..acquisition import scan as _scan
from ..acquisition.ioxos_data import Ioxostools
channellist = dict(bernina_channel_list=
parseChannelListFile('/sf/bernina/config/com/channel_lists/default_channel_list'))
bsdaq = BStools(default_channel_list=channellist,default_file_path='%s')
channellistioxos = dict(bernina_channel_list=
parseChannelListFile('/sf/bernina/config/default_channels/default_channel_list_ioxos'))
ioxosdaq = Ioxostools(default_channel_list=channellistioxos,default_file_path='%s')
#from eco.devices_general.detectors import JF_BS_writer
#bsdaqJF = JF_BS_writer('bsdaqJF') d
from eco.devices_general.detectors import DIAClient
bsdaqJF = DIAClient('bsdaqJF', instrument="bernina", api_address = "http://sf-daq-1:10000")
try:
bsdaqJF.pgroup = int(exp_config['pgroup'][1:])
except:
print('Could not set p group in bsdaqJF !!')
checkerPV=PV('SARFE10-PBPG050:HAMP-INTENSITY-CAL')
def checker_function(limits):
cv = checkerPV.get()
if cv>limits[0] and cv<limits[1]:
return True
else:
return False
checker = {}
checker['checker_call'] = checker_function
checker['args'] = [[100,700]]
checker['kwargs'] = {}
checker['wait_time'] = 3
scansIoxos = _scan.Scans(data_base_dir='/sf/bernina/config/com/data/scan_data',scan_info_dir='/sf/bernina/config/com/data/scan_info',default_counters=[ioxosdaq])
scansJF = _scan.Scans(data_base_dir='scan_data',scan_info_dir='/sf/bernina/data/%s/res/scan_info'%exp_config['pgroup'],default_counters=[bsdaqJF],checker=checker,scan_directories=True)
scansBsreadLocal = _scan.Scans(data_base_dir='/sf/bernina/config/com/data/scan_data',scan_info_dir='/sf/bernina/config/com/data/scan_info',default_counters=[bsdaq])
########### ADHOC IMPLEMENTED ########################
bsdaqJF.gain_file = "/sf/bernina/config/com/data/gains_I0.h5"
import glob
list_of_files = glob.glob('/sf/bernina/data/p17247/res/JF_pedestal/pedestal_*_res.h5')
latest_file = max(list_of_files, key=os.path.getctime)
bsdaqJF.pede_file = latest_file
from ..timing.lasertiming import Lxt as _Lxt
lxt = _Lxt()
+66
View File
@@ -0,0 +1,66 @@
import traceback
from colorama import Fore as _color
try:
from lazy_object_proxy import Proxy as LazyProxy
except:
print('Could not find package lazy-object-proxy for lazy initialisation of devices!')
pass
def init_device(devDict,devId,args,kwargs,verbose=True):
imp_p = devDict['eco_type'].split(sep='.')
dev_alias = devDict['alias']
dev_alias = dev_alias[0].lower() + dev_alias[1:]
eco_type_name = imp_p[-1]
istr = 'from ..'+'.'.join(imp_p[:-1])+' import '
istr += '%s as _%s'%(eco_type_name,eco_type_name)
#print(istr)
if verbose:
print(('Configuring %s '%(dev_alias)).ljust(25), end='')
print(('(%s)'%(devId)).ljust(25), end='')
error = None
try:
exec(istr)
tdev = eval('_%s(Id=\'%s\',*args,**kwargs)'%(eco_type_name,devId))
tdev.name = dev_alias
tdev._z_und = devDict['z_und']
if verbose:
print((_color.GREEN+'OK'+_color.RESET).rjust(5))
return tdev
except Exception as expt:
#tb = traceback.format_exc()
if verbose:
print((_color.RED+'FAILED'+_color.RESET).rjust(5))
#print(sys.exc_info())
raise expt
def initDeviceAliasList(aliases,lazy=False,verbose=True):
devices = []
problems = []
for device_Id in aliases.keys():
alias = aliases[device_Id]['alias']
alias = alias[0].lower() + alias[1:]
if 'eco_type' in aliases[device_Id].keys() \
and aliases[device_Id]['eco_type']:
if 'args' in aliases[device_Id].keys() \
and aliases[device_Id]['args']:
args = aliases[device_Id]['args']
else:
args = tuple()
if 'kwargs' in aliases[device_Id].keys() \
and aliases[device_Id]['kwargs']:
kwargs = aliases[device_Id]['kwargs']
else:
kwargs = dict()
try:
if lazy:
dev = LazyProxy(lambda:init_device(aliases[device_Id],device_Id,args,kwargs,verbose=verbose))
else:
dev = init_device(aliases[device_Id],device_Id,args,kwargs,verbose=verbose)
devices.append((device_Id,alias,dev))
except:
problems.append((device_Id,alias,traceback.format_exc()))
return devices, problems
+24
View File
@@ -65,3 +65,27 @@ class Laser_Exp:
except:
print('No Smaract ParZ')
pass
def get_adjustable_positions_str(self):
ostr = '*****SmarAct motor positions******\n'
for tkey,item in self.__dict__.items():
if hasattr(item,'get_current_value'):
pos = item.get_current_value()
ostr += ' ' + tkey.ljust(10) + ' : % 14g\n'%pos
return ostr
#def pos(self):
# s = []
# for i in sorted(self.__dict__.keys()):
# s.append[i]
# for n, mo^tor in enumerate (s):
# s[n] += ': ' + str(self.__dict__[motor])
# return s
def __repr__(self):
return self.get_adjustable_positions_str()
+1 -1
View File
@@ -5,7 +5,7 @@ import time
from ..devices_general.utilities import Changer
_basefolder = "/sf/bernina/config/com/data/src/lasertiming"
_basefolder = "/sf/bernina/config/src/python/devel/eco/timing"
def timeToStr(value,n=12):
fmt = "%%+.%df" % n