From 3edbcb3ebf8f16174efc6fcd03080f7df7abf1c8 Mon Sep 17 00:00:00 2001 From: Roman Mankowsky Date: Tue, 20 Mar 2018 15:55:42 +0100 Subject: [PATCH] started lazy import --- devices_general/detectors.py | 9 ++- devices_general/smaract.py | 21 +++-- instruments/bernina.py | 9 ++- instruments/bernina_dev.py | 114 +++++++++++++++++++++++++++ instruments/utilities_instruments.py | 66 ++++++++++++++++ loptics/bernina_experiment.py | 24 ++++++ timing/lasertiming.py | 2 +- 7 files changed, 232 insertions(+), 13 deletions(-) create mode 100644 instruments/bernina_dev.py create mode 100644 instruments/utilities_instruments.py diff --git a/devices_general/detectors.py b/devices_general/detectors.py index 8ca5986..b5c3749 100755 --- a/devices_general/detectors.py +++ b/devices_general/detectors.py @@ -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: diff --git a/devices_general/smaract.py b/devices_general/smaract.py index b2ec673..afcf569 100644 --- a/devices_general/smaract.py +++ b/devices_general/smaract.py @@ -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) diff --git a/instruments/bernina.py b/instruments/bernina.py index 3a75816..0d641da 100755 --- a/instruments/bernina.py +++ b/instruments/bernina.py @@ -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() diff --git a/instruments/bernina_dev.py b/instruments/bernina_dev.py new file mode 100644 index 0000000..5c62cb1 --- /dev/null +++ b/instruments/bernina_dev.py @@ -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