From 70c54f431536de04fcffec626170f3b363a171f9 Mon Sep 17 00:00:00 2001 From: Erik Frojdh Date: Mon, 13 Jan 2020 18:26:24 +0100 Subject: [PATCH] added jungfrau again --- python/CMakeLists.txt | 2 +- python/scripts/basic.py | 25 ++++++++++++--- python/sls_detector/__init__.py | 3 +- python/sls_detector/dacs.py | 27 ++++++----------- python/sls_detector/eiger.py | 4 --- python/sls_detector/jungfrau.py | 54 +++++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 28 deletions(-) create mode 100644 python/sls_detector/jungfrau.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 0d7306875..dcd4effa7 100755 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -29,7 +29,7 @@ set( PYTHON_FILES eiger.py errors.py ctb.py - # jungfrau.py + jungfrau.py registers.py utils.py diff --git a/python/scripts/basic.py b/python/scripts/basic.py index 3c4c450c6..a827171b5 100755 --- a/python/scripts/basic.py +++ b/python/scripts/basic.py @@ -4,11 +4,28 @@ import numpy as np sys.path.append(os.path.join(os.getcwd(), 'bin')) # from sls_detector import Eiger, Jungfrau, Detector, defs -from sls_detector import Detector, Eiger, DetectorDacs, Dac, Ctb +from sls_detector import Detector, Eiger, Jungfrau, DetectorDacs, Dac, Ctb from sls_detector import dacIndex -d = Detector() -e = Eiger() -c = Ctb() +# d = Detector() +# e = Eiger() +# c = Ctb() +j = Jungfrau() +# def tracefunc(frame, event, arg, indent=[0]): +# if event == "call": +# indent[0] += 2 +# print("-" * indent[0] + "> call function", frame.f_code.co_name) +# elif event == "return": +# print("<" + "-" * indent[0], "exit function", frame.f_code.co_name) +# indent[0] -= 2 +# return tracefunc + +# import sys +# sys.setprofile(tracefunc) +# print('------------------------------------------------------') +# j.dacs.vb_comp[:] = 1500 +# print('------------------------------------------------------') + +# # sys.setprofile(None) \ No newline at end of file diff --git a/python/sls_detector/__init__.py b/python/sls_detector/__init__.py index 8dc9b0a23..9cc170a7e 100755 --- a/python/sls_detector/__init__.py +++ b/python/sls_detector/__init__.py @@ -3,8 +3,7 @@ from .eiger import Eiger from .ctb import Ctb from .dacs import DetectorDacs, Dac from .detector import Detector - -# from .jungfrau import Jungfrau +from .jungfrau import Jungfrau # from .jungfrau_ctb import JungfrauCTB # from _sls_detector import DetectorApi diff --git a/python/sls_detector/dacs.py b/python/sls_detector/dacs.py index d306970f7..2291f9c7b 100755 --- a/python/sls_detector/dacs.py +++ b/python/sls_detector/dacs.py @@ -2,6 +2,7 @@ from .detector_property import DetectorProperty from functools import partial import numpy as np import _sls_detector +from .detector import freeze dacIndex = _sls_detector.slsDetectorDefs.dacIndex class Dac(DetectorProperty): """ @@ -34,25 +35,12 @@ class Dac(DetectorProperty): return f'{self.__name__:10s}:{dacstr}' # a = Dac('vrf', dacIndex.VRF, 0, 4000, 2500, d ) +# @freeze class DetectorDacs: - _dacs = [('vsvp', dacIndex.SVP,0, 4000, 0), - ('vtr', dacIndex.VTR,0, 4000, 2500), - ('vrf', dacIndex.VRF,0, 4000, 3300), - ('vrs', dacIndex.VRS,0, 4000, 1400), - ('vsvn', dacIndex.SVN,0, 4000, 4000), - ('vtgstv', dacIndex.VTGSTV,0, 4000, 2556), - ('vcmp_ll', dacIndex.VCMP_LL,0, 4000, 1500), - ('vcmp_lr', dacIndex.VCMP_LR,0, 4000, 1500), - ('vcall', dacIndex.CAL,0, 4000, 4000), - ('vcmp_rl', dacIndex.VCMP_RL,0, 4000, 1500), - ('rxb_rb', dacIndex.RXB_RB,0, 4000, 1100), - ('rxb_lb', dacIndex.RXB_LB,0, 4000, 1100), - ('vcmp_rr', dacIndex.VCMP_RR,0, 4000, 1500), - ('vcp', dacIndex.VCP,0, 4000, 200), - ('vcn', dacIndex.VCN,0, 4000, 2000), - ('vis', dacIndex.VIS,0, 4000, 1550), - ('iodelay', dacIndex.IO_DELAY,0, 4000, 660)] + _dacs = [] _dacnames = [_d[0] for _d in _dacs] + _allowed_attr = ['_detector', '_current'] + _frozen = False def __init__(self, detector): # We need to at least initially know which detector we are connected to @@ -65,6 +53,8 @@ class DetectorDacs: for _d in self._dacs: setattr(self, '_'+_d[0], Dac(*_d, detector)) + self._frozen = True + def __getattr__(self, name): return self.__getattribute__('_' + name) @@ -73,8 +63,11 @@ class DetectorDacs: if name in self._dacnames: return self.__getattribute__('_' + name).__setitem__(slice(None, None, None), value) else: + if self._frozen == True and name not in self._allowed_attr: + raise AttributeError(f'Dac not found: {name}') super().__setattr__(name, value) + def __next__(self): if self._current >= len(self._dacs): self._current = 0 diff --git a/python/sls_detector/eiger.py b/python/sls_detector/eiger.py index 5beb8899e..d2c0f0a12 100755 --- a/python/sls_detector/eiger.py +++ b/python/sls_detector/eiger.py @@ -8,10 +8,6 @@ Created on Wed Dec 6 11:51:18 2017 from .detector import Detector -# import socket -# from collections.abc import Iterable -# from collections import namedtuple -# from functools import partial # from .adcs import Adc, DetectorAdcs from .dacs import DetectorDacs diff --git a/python/sls_detector/jungfrau.py b/python/sls_detector/jungfrau.py new file mode 100644 index 000000000..e05ee7b2a --- /dev/null +++ b/python/sls_detector/jungfrau.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +This file contains the specialization for the Jungfrau detector +""" + + +from .detector import Detector, freeze + +# from .adcs import Adc, DetectorAdcs +from .dacs import DetectorDacs +import _sls_detector +dacIndex = _sls_detector.slsDetectorDefs.dacIndex +from .detector_property import DetectorProperty + +# @freeze +class JungfrauDacs(DetectorDacs): + """ + Jungfrau specific DACs + """ + _dacs = [('vb_comp', dacIndex.VB_COMP, 0, 4000, 1220), + ('vdd_prot', dacIndex.VDD_PROT, 0, 4000, 3000), + ('vin_com', dacIndex.VIN_COM, 0, 4000, 1053), + ('vref_prech', dacIndex.VREF_PRECH, 0, 4000, 1450), + ('vb_pixbuff', dacIndex.VB_PIXBUF, 0, 4000, 750), + ('vb_ds', dacIndex.VB_DS, 0, 4000, 1000), + ('vref_ds', dacIndex.VREF_DS, 0, 4000, 480), + ('vref_comp', dacIndex.VREF_COMP, 0, 4000, 420), + ] + _dacnames = [_d[0] for _d in _dacs] + + + + +@freeze +class Jungfrau(Detector): + """ + Subclassing Detector to set up correct dacs and detector specific + functions. + """ + _detector_dynamic_range = [4, 8, 16, 32] + + + _settings = ['standard', 'highgain', 'lowgain', 'veryhighgain', 'verylowgain'] + """available settings for Eiger, note almost always standard""" + + def __init__(self, id=0): + super().__init__(id) + self._frozen = False + self._dacs = JungfrauDacs(self) + + @property + def dacs(self): + return self._dacs \ No newline at end of file