diff --git a/aidatlu/hardware/dac_controller.py b/aidatlu/hardware/dac_controller.py index 18400e3..ec4f6aa 100644 --- a/aidatlu/hardware/dac_controller.py +++ b/aidatlu/hardware/dac_controller.py @@ -9,7 +9,7 @@ class DacControl(object): """ def __init__(self, i2c: I2CCore, int_ref: bool = False) -> None: - self.log = logger.setup_derived_logger("Voltage Controller") + self.log = logger.setup_derived_logger(__class__.__name__) self.log.info("Initializing DAC Control") self.i2c = i2c @@ -30,13 +30,13 @@ def set_threshold( """ if threshold_voltage > ref_v: - self.log.warn( + self.log.warning( "Threshold larger than %s V is not supported, Threshold will default to %s V " % (ref_v, ref_v) ) threshold_voltage = ref_v if threshold_voltage < -ref_v: - self.log.warn( + self.log.warning( "Threshold smaller than %s V is not supported, Threshold will default to %s V " % (-ref_v, -ref_v) ) @@ -77,13 +77,13 @@ def set_voltage(self, pmt_channel: int, voltage: float) -> None: raise ValueError("PMT Channel has to be between 1 and 5") if voltage < 0: - self.log.warn( + self.log.warning( "A Voltage value smaller than 0 is not supported, Voltage will default to 0" ) voltage = 0 if voltage > 1: - self.log.warn( + self.log.warning( "A Voltage value higher than 1 is not supported, Voltage will default to 1" ) voltage = 1 @@ -150,13 +150,13 @@ def _set_dac_value(self, channel: int, value: int, dac: int = 0) -> None: raise ValueError("Channel has to be between 0 and 7") if value < 0x0000: - self.log.warn( + self.log.warning( "DAC value < 0x0000 not supported, value will default to 0x0000" ) value = 0 if value > 0xFFFF: - self.log.warn( + self.log.warning( "DAC value > 0xFFFF not supported, value will default to 0xFFFF" ) value = 0xFFFF diff --git a/aidatlu/hardware/dut_controller.py b/aidatlu/hardware/dut_controller.py index 21b677f..5105509 100644 --- a/aidatlu/hardware/dut_controller.py +++ b/aidatlu/hardware/dut_controller.py @@ -4,7 +4,7 @@ class DUTLogic(object): def __init__(self, i2c: I2CCore): - self.log = logger.setup_derived_logger("DUT Logic") + self.log = logger.setup_derived_logger(__class__.__name__) self.i2c = i2c def set_dut_mask(self, enable: int | str) -> None: @@ -22,7 +22,7 @@ def set_dut_mask(self, enable: int | str) -> None: raise ValueError("Enable has to be between 0 and 15 ('1111')") self.i2c.write_register("DUTInterfaces.DUTMaskW", enable & 0xF) - self.log.info("DUT mask set to %s" % self.get_dut_mask()) + self.log.debug("DUT mask set to %s" % self.get_dut_mask()) def set_dut_mask_mode(self, mode: int | str) -> None: """Sets the DUT interface mode. Mode consits of one 8-bit WORD or more specific 4 2-bit WORDs. @@ -42,7 +42,7 @@ def set_dut_mask_mode(self, mode: int | str) -> None: raise ValueError("Mode has to be between 0 and 256 ('100000000').") self.i2c.write_register("DUTInterfaces.DUTInterfaceModeW", mode) - self.log.info("DUT mask mode is set to %s" % self.get_dut_mask_mode()) + self.log.debug("DUT mask mode is set to %s" % self.get_dut_mask_mode()) def set_dut_mask_mode_modifier(self, value: int) -> None: """#TODO Only affects the EUDET mode of operation, looks like some special EUDET configuration. @@ -51,7 +51,7 @@ def set_dut_mask_mode_modifier(self, value: int) -> None: value (int): _description_ #TODO """ self.i2c.write_register("DUTInterfaces.DUTInterfaceModeModifierW", value) - self.log.info( + self.log.debug( "DUT mask mode modifier is set to %s" % self.get_dut_mask_mode_modifier() ) @@ -71,7 +71,7 @@ def set_dut_ignore_busy(self, channels: int | str) -> None: raise ValueError("Channels has to be between 0 and 16 ('10000').") self.i2c.write_register("DUTInterfaces.IgnoreDUTBusyW", channels) - self.log.info("DUT ignore busy is set to %s" % self.get_dut_ignore_busy()) + self.log.debug("DUT ignore busy is set to %s" % self.get_dut_ignore_busy()) def get_dut_mask(self) -> int: """Reads the contend in the register 'DUTMaskR'. @@ -107,7 +107,7 @@ def get_dut_ignore_busy(self) -> int: def set_dut_ignore_shutter(self, value: int) -> None: self.i2c.write_register("DUTInterfaces.IgnoreShutterVetoW", value) - self.log.info("DUT ignore shutter set to %s" % self.get_dut_ignore_shutter()) + self.log.debug("DUT ignore shutter set to %s" % self.get_dut_ignore_shutter()) def get_dut_ignore_shutter(self): return self.i2c.read_register("DUTInterfaces.IgnoreShutterVetoR") diff --git a/aidatlu/hardware/ioexpander_controller.py b/aidatlu/hardware/ioexpander_controller.py index 24d3082..4a8e042 100644 --- a/aidatlu/hardware/ioexpander_controller.py +++ b/aidatlu/hardware/ioexpander_controller.py @@ -11,7 +11,7 @@ class IOControl(object): """ def __init__(self, i2c: I2CCore) -> None: - self.log = logger.setup_derived_logger("IO Expander") + self.log = logger.setup_derived_logger(__class__.__name__) self.log.info("Initializing IO expander") self.i2c = i2c @@ -282,7 +282,7 @@ def configure_hdmi(self, hdmi_channel: int, enable: int | str) -> None: new_status = (old_status & (~mask)) | (new_nibble & mask) self._set_ioexpander_output(2, expander_id, bank, new_status) - self.log.info("HDMI Channel %i set to %s" % (hdmi_channel + 1, str(enable))) + self.log.debug("HDMI Channel %i set to %s" % (hdmi_channel + 1, str(enable))) def clock_hdmi_output(self, hdmi_channel: int, clock_source: str) -> None: """Enables the Clock output for one HDMI channel. @@ -344,11 +344,7 @@ def clock_lemo_output(self, enable: bool = True) -> None: self.switch_led(5, "off") self.log.info("Clock LEMO output %s" % ("enabled" if enable else "disabled")) - """ - - General Expander Control - - """ + """ General Expander Control """ def _set_ioexpander_polarity( self, io_exp: int, exp_id: int, cmd_byte: int, polarity: bool = False diff --git a/aidatlu/hardware/trigger_controller.py b/aidatlu/hardware/trigger_controller.py index 9c95d2b..f5d4dfd 100644 --- a/aidatlu/hardware/trigger_controller.py +++ b/aidatlu/hardware/trigger_controller.py @@ -5,7 +5,7 @@ class TriggerLogic(object): def __init__(self, i2c: I2CCore) -> None: - self.log = logger.setup_derived_logger("Trigger Controller") + self.log = logger.setup_derived_logger(__class__.__name__) self.i2c = i2c """ Internal Trigger Generation """ @@ -96,7 +96,7 @@ def set_trigger_mask(self, mask_high: int, mask_low: int) -> None: """ self.i2c.write_register("triggerLogic.TriggerPattern_lowW", mask_low) self.i2c.write_register("triggerLogic.TriggerPattern_highW", mask_high) - self.log.info("Trigger mask: %s" % self.get_trigger_mask()) + self.log.debug("Trigger mask: %s" % self.get_trigger_mask()) def get_trigger_mask(self) -> int: """Retrieves the trigger logic words from the registers. The trigger pattern represents one of the 64 possible logic combinations.""" @@ -128,7 +128,7 @@ def set_trigger_mask_from_full_word(self, value: int) -> None: mask_low = value & 0xFF self.i2c.write_register("triggerLogic.TriggerPattern_lowW", mask_low) self.i2c.write_register("triggerLogic.TriggerPattern_highW", mask_high) - self.log.info("Trigger mask: %s" % self.get_trigger_mask()) + self.log.debug("Trigger mask: %s" % self.get_trigger_mask()) """ Trigger Pulse Length and Delay """ @@ -142,7 +142,7 @@ def set_pulse_stretch_pack(self, vector: list) -> None: """ packed = _pack_bits(vector) self._set_pulse_stretch(packed) - self.log.info("Pulse stretch is set to %s" % self.get_pulse_stretch_pack()) + self.log.debug("Pulse stretch is set to %s" % self.get_pulse_stretch_pack()) def set_pulse_delay_pack(self, vector: list) -> None: """Delay word for trigger pulses. Each element of the input vector is delayed by N clock cycles. @@ -153,7 +153,7 @@ def set_pulse_delay_pack(self, vector: list) -> None: """ packed = _pack_bits(vector) self._set_pulse_delay(packed) - self.log.info("Pulse Delay is set to %s" % self.get_pulse_delay_pack()) + self.log.debug("Pulse Delay is set to %s" % self.get_pulse_delay_pack()) def get_pulse_stretch_pack(self) -> int: """Get packed word describing the input pulse stretch.""" diff --git a/aidatlu/logger.py b/aidatlu/logger.py index b26ea41..9fe919f 100644 --- a/aidatlu/logger.py +++ b/aidatlu/logger.py @@ -1,5 +1,6 @@ import logging import coloredlogs +import argparse FORMAT = "%(asctime)s [%(name)-18s] - %(levelname)-7s %(message)s" diff --git a/aidatlu/main/config_parser.py b/aidatlu/main/config_parser.py index 1a91106..8f3b869 100644 --- a/aidatlu/main/config_parser.py +++ b/aidatlu/main/config_parser.py @@ -5,7 +5,7 @@ class TLUConfigure(object): def __init__(self, TLU, io_control, config_path) -> None: - self.log = logger.setup_main_logger(__class__.__name__, logging.INFO) + self.log = logger.setup_main_logger(__class__.__name__) self.tlu = TLU self.io_control = io_control diff --git a/aidatlu/main/data_parser.py b/aidatlu/main/data_parser.py index 8d02e34..96351c1 100644 --- a/aidatlu/main/data_parser.py +++ b/aidatlu/main/data_parser.py @@ -7,7 +7,7 @@ class DataParser(object): def __init__(self) -> None: - self.log = logger.setup_main_logger(__class__.__name__, logging.INFO) + self.log = logger.setup_main_logger(__class__.__name__) self.features = np.dtype( [ ("eventnumber", "u4"), diff --git a/aidatlu/main/tlu.py b/aidatlu/main/tlu.py index 8a7fc61..e193e8a 100644 --- a/aidatlu/main/tlu.py +++ b/aidatlu/main/tlu.py @@ -21,11 +21,11 @@ class AidaTLU(object): def __init__(self, hw, config_path, clock_config_path) -> None: - self.log = logger.setup_main_logger(__class__.__name__, logging.INFO) + self.log = logger.setup_main_logger(__class__.__name__) self.i2c = I2CCore(hw) self.i2c_hw = hw - self.log.info("IPbus interface") + self.log.info("Initializing IPbus interface") self.i2c.init() if self.i2c.modules["eeprom"]: self.log.info("Found device with ID %s" % hex(self.get_device_id())) @@ -90,10 +90,6 @@ def get_device_id(self) -> int: def get_fw_version(self) -> int: return self.i2c.read_register("version") - # def reset_board(self) -> None: - # #THIS FUNCTION CRASHES THE TLU. TLU needs a power cycle afterwards. This does not work at all... - # self.i2c.write_register("logic_clocks.LogicRst", 1) - def reset_timestamp(self) -> None: """Sets bit to 'ResetTimestampW' register to reset the time stamp.""" self.i2c.write_register("Event_Formatter.ResetTimestampW", 1) @@ -264,7 +260,6 @@ def pull_fifo_event(self) -> list: list: 6 element long vector containing bitwords of the data. """ event_numb = self.get_event_fifo_fill_level() - # fifo_status = self.get_event_fifo_csr() if event_numb: if event_numb * 6 == 0xFEA: self.log.warning("FIFO is full") diff --git a/docs/source/Documentation.rst b/docs/source/Documentation.rst index 6140487..8b867f9 100644 --- a/docs/source/Documentation.rst +++ b/docs/source/Documentation.rst @@ -332,6 +332,10 @@ Tests can be run individually. pytest software_test.py +Log Level +------ +To set different log levels change the default log level in logger.py 'setup_main_logger' and 'setup_derived_logger'. + Integration into EUDAQ2 ------------------------ Due to the similarities of the python control software and the established EUDAQ TLU software diff --git a/docs/source/conf.py b/docs/source/conf.py index 3f89854..8f0001a 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -7,12 +7,12 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -with open('../../VERSION') as version_file: +with open("../../VERSION") as version_file: version = version_file.read().strip() -project = 'AIDA-TLU' -copyright = '2023, SiLab, Institute of Physics, University of Bonn' -author = 'Rasmus Partzsch' +project = "AIDA-TLU" +copyright = "2023, SiLab, Institute of Physics, University of Bonn" +author = "Rasmus Partzsch" release = version import sys @@ -21,33 +21,33 @@ # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -sys.path.insert(0, os.path.abspath('../aidatlu')) -sys.path.insert(0, os.path.abspath('../aidatlu/hardware')) -sys.path.insert(0, os.path.abspath('../aidatlu/main')) +sys.path.insert(0, os.path.abspath("../aidatlu")) +sys.path.insert(0, os.path.abspath("../aidatlu/hardware")) +sys.path.insert(0, os.path.abspath("../aidatlu/main")) # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration extensions = [ - 'sphinx.ext.napoleon', - 'sphinx.ext.doctest', - 'sphinx.ext.autodoc', - 'sphinx.ext.autosummary', - 'sphinx.ext.todo', - 'sphinx_mdinclude', - 'sphinx.ext.viewcode', - ] + "sphinx.ext.napoleon", + "sphinx.ext.doctest", + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.todo", + "sphinx_mdinclude", + "sphinx.ext.viewcode", +] autosectionlabel_prefix_document = True -templates_path = ['_templates'] +templates_path = ["_templates"] exclude_patterns = [] source_suffix = { - '.rst': 'restructuredtext', - '.txt': 'markdown', - '.md': 'markdown', + ".rst": "restructuredtext", + ".txt": "markdown", + ".md": "markdown", } autodoc_mock_imports = ["hardware", "DutLogic", "main", "uhal"] @@ -55,18 +55,16 @@ # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output -html_theme = 'pydata_sphinx_theme' -html_static_path = ['_static'] +html_theme = "pydata_sphinx_theme" +html_static_path = ["_static"] html_theme_options = { - #[...] + # [...] # "show_toc_level": 2, # "show_nav_level": 3, "primary_sidebar_end": ["indices.html", "sidebar-ethical-ads.html"], "secondary_sidebar_items": [], - #[...] + # [...] } -html_sidebars = { - '*': ["page-toc", "edit-this-page", "sourcelink"] -} +html_sidebars = {"*": ["page-toc", "edit-this-page", "sourcelink"]} diff --git a/setup.py b/setup.py index d14e81a..b14fb3a 100644 --- a/setup.py +++ b/setup.py @@ -1,23 +1,30 @@ from setuptools import setup from setuptools import find_packages -author = 'Christian Bespin, Rasmus Partzsch' -author_email = 'bespin@physik.uni-bonn.de, rasmus.partzsch@uni-bonn.de' +author = "Christian Bespin, Rasmus Partzsch" +author_email = "bespin@physik.uni-bonn.de, rasmus.partzsch@uni-bonn.de" # Requirements -install_requires = ['pytest', 'numpy', 'tables', 'coloredlogs', 'pyzmq', 'online_monitor', 'tqdm' - ] +install_requires = [ + "pytest", + "numpy", + "tables", + "coloredlogs", + "pyzmq", + "online_monitor", + "tqdm", +] -with open('VERSION') as version_file: +with open("VERSION") as version_file: version = version_file.read().strip() setup( - name='aidatlu', + name="aidatlu", version=version, - description='Control software for AIDA-2020 TLU', - url='https://github.com/Silab-Bonn/aidatlu', - license='License AGPL-3.0 license', - long_description='Repository for controlling the AIDA-2020 Trigger Logic Unit (TLU) with Python using uHAL bindings from IPbus.', + description="Control software for AIDA-2020 TLU", + url="https://github.com/Silab-Bonn/aidatlu", + license="License AGPL-3.0 license", + long_description="Repository for controlling the AIDA-2020 Trigger Logic Unit (TLU) with Python using uHAL bindings from IPbus.", author=author, maintainer=author, author_email=author_email, @@ -26,5 +33,5 @@ python_requires=">=3.8", packages=find_packages(), include_package_data=True, - platforms='posix', + platforms="posix", )