Commit 0b1f1694 authored by Matias Guijarro's avatar Matias Guijarro
Browse files

mapping: properly build map from controllers

common/log.py: remove old file
parent 5b871459
......@@ -6,10 +6,12 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from warnings import warn
import logging
from .embl import ExporterClient
from bliss.common.logtools import LogMixin
from bliss.common import session
import gevent
from gevent.queue import Queue
from .embl import ExporterClient
exporter_clients = {}
......@@ -25,7 +27,7 @@ def start_exporter(address, port, timeout=3, retries=1):
return exporter_clients[(address, port)]
class Exporter(ExporterClient.ExporterClient):
class Exporter(ExporterClient.ExporterClient, LogMixin):
STATE_EVENT = "State"
STATUS_EVENT = "Status"
VALUE_EVENT = "Value"
......@@ -57,6 +59,10 @@ class Exporter(ExporterClient.ExporterClient):
self.events_queue = Queue()
self.events_processing_task = None
session.get_current().map.register(
self, parents_list=["comms"], tag=f"exporter: {address}:{port}"
)
def start(self):
pass
# self.started=True
......@@ -139,7 +145,7 @@ class Exporter(ExporterClient.ExporterClient):
try:
cb(self._to_python_value(value))
except:
logging.exception(
self._logger.exception(
"Exception while executing callback %s for event %s", cb, name
)
continue
......
......@@ -21,7 +21,6 @@ __all__ = [
import re
import enum
import logging
import gevent
from gevent import lock
import numpy
......
......@@ -15,7 +15,6 @@ from bliss.common import event
import gevent
import weakref
import types
import logging
(DOREG, DONTREG, WAITREG) = (0, 1, 2)
......
......@@ -16,7 +16,6 @@ SpecCommandA
import sys
import types
import logging
import gevent
from gevent.event import Event
from .connection import SpecConnection
......
......@@ -17,8 +17,9 @@ import gevent
import gevent.socket
import socket
import weakref
import logging
from bliss.common import event
from bliss.common import session
from bliss.common.logtools import LogMixin
from .error import SpecClientNotConnectedError
from .channel import SpecChannel
from .message import *
......@@ -118,7 +119,7 @@ def connectionHandler(conn, socket_to_spec):
try:
reply = conn.registeredReplies[replyID]
except BaseException:
logging.getLogger("SpecClient").exception(
conn._logger.exception(
"Unexpected error while receiving a message from server"
)
else:
......@@ -142,7 +143,7 @@ def connectionHandler(conn, socket_to_spec):
receivedStrings = [s[offset:]]
class SpecConnection:
class SpecConnection(LogMixin):
"""SpecConnection class
Signals:
connected() -- emitted when the required Spec version gets connected
......@@ -183,6 +184,8 @@ class SpecConnection:
self.port = None
self.scanport = True
session.get_current().map.register(self, parents_list=["comms"], tag=str(self))
def __str__(self):
return "<connection to Spec, host=%s, port=%s>" % (
self.host,
......@@ -226,7 +229,7 @@ class SpecConnection:
# we received a value, so emit an update signal
channel.update(channelValue, force=True)
except BaseException:
logging.getLogger("SpecClient").exception(
self._logger.exception(
"Uncaught exception in SpecConnection.registerChannel"
)
......@@ -260,7 +263,7 @@ class SpecConnection:
def error(self, error):
"""Emit the 'error' signal when the remote Spec version signals an error."""
logging.getLogger("SpecClient").error("Error from Spec: %s", error)
self._logger.error("Error from Spec: %s", error)
event.send(self, "error", (error,))
......@@ -273,7 +276,7 @@ class SpecConnection:
old_state = self.state
self.state = CONNECTED
if old_state != CONNECTED:
logging.getLogger("SpecClient").info(
self._logger.info(
"Connected to %s:%s",
self.host,
(self.scanport and self.scanname) or self.port,
......@@ -290,7 +293,7 @@ class SpecConnection:
old_state = self.state
self.state = DISCONNECTED
if old_state == CONNECTED:
logging.getLogger("SpecClient").info(
self._logger.info(
"Disconnected from %s:%s",
self.host,
(self.scanport and self.scanname) or self.port,
......@@ -347,7 +350,7 @@ class SpecConnection:
cmd -- command string
"""
if self.serverVersion < 3:
logging.getLogger("SpecClient").error(
self._logger.error(
"Cannot execute command in Spec : feature is available since Spec server v3 only"
)
else:
......@@ -369,7 +372,7 @@ class SpecConnection:
cmd -- command string
"""
if self.serverVersion < 3:
logging.getLogger("SpecClient").error(
self._logger.error(
"Cannot execute command in Spec : feature is available since Spec server v3 only"
)
else:
......
......@@ -5,7 +5,6 @@
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from bliss.common import log as elog
from bliss.common.motor_config import StaticConfig
from bliss.common import event
import time
......
......@@ -9,12 +9,13 @@
how to use motion hooks in your system"""
import weakref
from bliss.common import session
from bliss.common.logtools import LogMixin
__all__ = ["MotionHook"]
class MotionHook(object):
class MotionHook(LogMixin):
"""
Base motion hook. Executed before a motion starts and after motion ends.
"""
......@@ -22,6 +23,10 @@ class MotionHook(object):
def __init__(self):
self.__axes = weakref.WeakValueDictionary()
session.get_current().map.register(
self, parents_list=["motion hooks"], tag=self.__class__.__name__
)
def add_axis(self, axis):
"""Add a new axis to the hook. Called by bliss when an axis is created
which is linked to this hook
......
......@@ -13,9 +13,9 @@ import math
import gevent
import gevent.event
from bliss.common import session
from bliss.common.task import task
from bliss.common import log
from bliss.common.logtools import LogMixin
from bliss.common.utils import with_custom_members
from bliss.common.measurement import SamplingCounter, counter_namespace
......@@ -37,19 +37,22 @@ class TempControllerCounter(SamplingCounter):
@with_custom_members
class Input(object):
class Input(LogMixin):
""" Implements the access to temperature sensors
"""
def __init__(self, controller, config):
""" Constructor """
log.debug("On Input")
# log.debug(" config type is: %s" % type(config))
# log.debug(" controller type is: %s" % type(controller))
self.__controller = controller
self.__name = config["name"]
self.__config = config
session.get_current().map.register(
self, parents_list=[controller, "counters"], tag=f"{self.name}"
)
# useful attribute for a temperature controller writer
self._attr_dict = {}
......@@ -80,22 +83,21 @@ class Input(object):
def read(self):
""" returns the sensor value """
log.debug("On Input:read")
self._logger.debug("On Input:read")
return self.controller.read_input(self)
def state(self):
""" returns the sensor state """
log.debug("On Input:state")
self._logger.debug("On Input:state")
return self.controller.state_input(self)
@with_custom_members
class Output(object):
class Output(LogMixin):
""" Implements the access to temperature heaters """
def __init__(self, controller, config):
""" Constructor """
log.debug("On Output")
self.__controller = controller
self.__name = config["name"]
try:
......@@ -118,6 +120,10 @@ class Output(object):
# useful attribute for a temperature controller writer
self._attr_dict = {}
session.get_current().map.register(
self, parents_list=[controller, "counters"], tag=f"{self.name}"
)
@property
def controller(self):
""" returns the temperature controller """
......@@ -158,7 +164,7 @@ class Output(object):
def read(self):
""" returns the heater value """
log.debug("On Output:read")
self._logger.debug("On Output:read")
return self.controller.read_output(self)
def ramp(self, new_setpoint=None, wait=False, **kwargs):
......@@ -173,7 +179,7 @@ class Output(object):
- setpoint_abort
- start_ramp
"""
log.debug("On Output:ramp %s" % new_setpoint)
self._logger.debug("On Output:ramp %s" % new_setpoint)
self.__mode = 1
return self._ramp(new_setpoint, wait, **kwargs)
......@@ -189,14 +195,14 @@ class Output(object):
- setpoint_abort
- set
"""
log.debug("On Output:set %s" % new_setpoint)
self._logger.debug("On Output:set %s" % new_setpoint)
self.__mode = 0
return self._ramp(new_setpoint, wait, **kwargs)
def _ramp(self, new_setpoint=None, wait=False, **kwargs):
""" starts the ramp tasks.
"""
log.debug("On Output:_ramp %s" % new_setpoint)
self._logger.debug("On Output:_ramp %s" % new_setpoint)
if new_setpoint is not None:
ll, hl = self.limits
if ll is not None and new_setpoint < ll:
......@@ -218,7 +224,7 @@ class Output(object):
def wait(self):
""" Waits on a setpoint task
"""
log.debug("On Output:wait")
self._logger.debug("On Output:wait")
try:
self.__setpoint_task.get()
except KeyboardInterrupt:
......@@ -243,7 +249,7 @@ class Output(object):
"""
deadband = self.deadband if deadband is None else deadband
log.debug("On output:_setpoint_state: %s" % (deadband))
self._logger.debug("On output:_setpoint_state: %s" % (deadband))
if deadband is None:
return "READY"
mysp = self.controller.get_setpoint(self)
......@@ -258,7 +264,7 @@ class Output(object):
""" Stops a setpoint task.
Calls the controller method setpoint_stop
"""
log.debug("On Output: stop")
self._logger.debug("On Output: stop")
if self.__setpoint_task and not self.__setpoint_task.ready():
self.__setpoint_task.kill()
self.controller.setpoint_stop(self)
......@@ -267,7 +273,7 @@ class Output(object):
""" Aborts a setpoint task.
Calls the controller method setpoint_abort
"""
log.debug("On Output: abort")
self._logger.debug("On Output: abort")
if self.__setpoint_task and not self.__setpoint_task.ready():
self.__setpoint_task.kill()
self.controller.setpoint_abort(self)
......@@ -290,7 +296,7 @@ class Output(object):
Polls until setpoint is reached
Is a gevent coroutine
"""
log.debug("On Output:_do_setpoint : mode = %s" % (self.__mode))
self._logger.debug("On Output:_do_setpoint : mode = %s" % (self.__mode))
try:
while self._setpoint_state() == "RUNNING":
gevent.sleep(self.__setpoint_event_poll)
......@@ -300,7 +306,7 @@ class Output(object):
def _start_setpoint(self, setpoint, **kwargs):
""" launches the coroutine doing the setpoint
"""
log.debug("On Output:_start_setpoint")
self._logger.debug("On Output:_start_setpoint")
sync_event = gevent.event.Event()
@task
......@@ -319,7 +325,7 @@ class Output(object):
def state(self):
""" returns the the state of a heater """
log.debug("On Output:state")
self._logger.debug("On Output:state")
return self.controller.state_output(self)
def pollramp(self, new_poll=None):
......@@ -338,7 +344,7 @@ class Output(object):
Setting/reading the setpoint ramp rate value
"""
log.debug("On Output:ramprate: %s " % (new_ramp))
self._logger.debug("On Output:ramprate: %s " % (new_ramp))
if new_ramp:
self.controller.set_ramprate(self, new_ramp)
else:
......@@ -349,7 +355,7 @@ class Output(object):
Setting/reading the setpoint step value (for step mode ramping)
"""
log.debug("On Output:step: %s " % (new_step))
self._logger.debug("On Output:step: %s " % (new_step))
if new_step:
self.controller.set_step(self, new_step)
else:
......@@ -360,7 +366,7 @@ class Output(object):
Setting/reading the setpoint dwell value (for step mode ramping)
"""
log.debug("On Output:setpoint dwell: %s " % (new_dwell))
self._logger.debug("On Output:setpoint dwell: %s " % (new_dwell))
if new_dwell:
self.controller.set_dwell(self, new_dwell)
else:
......@@ -373,12 +379,11 @@ class Output(object):
@with_custom_members
class Loop(object):
class Loop(LogMixin):
""" Implements the access to temperature regulation loop """
def __init__(self, controller, config):
""" Constructor """
log.debug("On Loop")
self.__controller = controller
self.__name = config["name"]
self.__config = config
......@@ -391,6 +396,13 @@ class Loop(object):
# useful attribute for a temperature controller writer
self._attr_dict = {}
session.get_current().map.register(
self,
parents_list=[controller],
children_list=[self.__input, self.__output],
tag=f"{self.name}",
)
@property
def controller(self):
""" returns the temperature controller """
......@@ -418,31 +430,31 @@ class Loop(object):
def set(self, new_setpoint=None, wait=False, **kwargs):
""" same as a call to the the method set on its output object """
log.debug(("On Loop: set %s") % new_setpoint)
self._logger.debug(("On Loop: set %s") % new_setpoint)
return self.__output.set(new_setpoint, wait, **kwargs)
def ramp(self, new_setpoint=None, wait=False, **kwargs):
""" same as the call to the method ramp on its output object """
log.debug(("On Loop: ramp %s") % new_setpoint)
self._logger.debug(("On Loop: ramp %s") % new_setpoint)
return self.__output.ramp(new_setpoint, wait, **kwargs)
def stop(self):
""" same as the call to the method stop on its output object """
log.debug("On Loop: stop")
self._logger.debug("On Loop: stop")
self.__output.stop()
def on(self):
""" Sets the regulation on
- call to the method 'on' of the controller
"""
log.debug("On Loop: on")
self._logger.debug("On Loop: on")
self.controller.on(self)
def off(self):
""" Sets the regulation off
- call to the method 'off' of the controller
"""
log.debug("On Loop: off")
self._logger.debug("On Loop: off")
self.controller.off(self)
def kp(self, new_kp=None):
......@@ -450,7 +462,7 @@ class Loop(object):
Setting/reading the P value (for PID)
"""
log.debug("On Loop: kp (PID): ")
self._logger.debug("On Loop: kp (PID): ")
if new_kp:
self.controller.set_kp(self, new_kp)
else:
......@@ -461,7 +473,7 @@ class Loop(object):
Setting/reading the I value (for PID)
"""
log.debug("On Loop: ki (PID): ")
self._logger.debug("On Loop: ki (PID): ")
if new_ki:
self.controller.set_ki(self, new_ki)
else:
......@@ -472,7 +484,7 @@ class Loop(object):
Setting/reading the D value (for PID)
"""
log.debug("On Loop: kd (PID): ")
self._logger.debug("On Loop: kd (PID): ")
if new_kd:
self.controller.set_kd(self, new_kd)
else:
......
......@@ -6,8 +6,6 @@
# Distributed under the GNU LGPLv3. See LICENSE for more info.
import logging
from bliss.common import log
from bliss.config.plugins.utils import find_class
......
......@@ -5,6 +5,7 @@
# Copyright (c) 2015-2019 Beamline Control Unit, ESRF
# Distributed under the GNU LGPLv3. See LICENSE for more info.
from bliss.common import session
from bliss.comm.util import UDP, get_comm_type, get_comm
from bliss.comm.tcp import SocketTimeout
from bliss.common.utils import object_method
......@@ -202,6 +203,8 @@ class Elmo(Controller):
opt = {"baudrate": 115200, "eol": ";"}
self._cnx = get_comm(config, **opt)
session.get_current().map.register(self, children_list=[self._cnx])
self._elmostate = AxisState()
for state, human in (
("SLAVESWITCH", "Slave switch activate"),
......
<
......@@ -11,10 +11,10 @@ from bliss.common.utils import object_method
from bliss.common.axis import AxisState
from bliss.config.channels import Cache
from bliss.controllers.motor import Controller
from bliss.common import session
import logging
import time
import traceback
import sys
class Elmo_whistle(Controller):
......@@ -199,20 +199,7 @@ class Elmo_whistle(Controller):
Controller.__init__(self, *args, **kwargs)
self._cnx = None
# init logging
self.logger = logging.getLogger("elmo")
self.handler = logging.StreamHandler()
self.handler.setLevel("DEBUG")
self.formatter = logging.Formatter(
"%(levelname)s -- %(funcName)s -- %(message)s"
)
self.handler.setFormatter(self.formatter)
self.logger.addHandler(self.handler)
self.logger.propagate = False
def initialize(self):
self.logger.info("Entering")
config = self.config.config_dict
if get_comm_type(config) == SERIAL:
......@@ -221,6 +208,12 @@ class Elmo_whistle(Controller):
raise RuntimeError("Serial line is not configured!")
self._cnx = get_comm(config, **opt)
session.get_current().map.register(self, children_list=[self._cnx])
def initialize(self):
self._logger.info("Entering")
self._elmostate = AxisState()
for state, human in (
("INHIBITSWITCH", "Inhibit switch active"),
......@@ -235,7 +228,7 @@ class Elmo_whistle(Controller):
self.stopped = False
def initialize_hardware(self):
self.logger.info("Entering")
self._logger.info("Entering")
# Check that the controller is alive
try:
......@@ -246,11 +239,11 @@ class Elmo_whistle(Controller):
)
def initialize_axis(self, axis):
self.logger.info("Entering for %s" % axis.name)
self._logger.info("Entering for %s" % axis.name)
axis._mode = Cache(axis, "mode", default_value=None)
def initialize_hardware_axis(self, axis):
self.logger.info("Entering for %s" % axis.name)
self._logger.info("Entering for %s" % axis.name)
# Check user-mode
mode = int(self._query("UM"))
......@@ -263,22 +256,22 @@ class Elmo_whistle(Controller):
self.set_on(axis)
mode = self._query("UM")
axis._mode.value = int(mode)
self.logger.info("%s init done!" % axis.name)
self._logger.info("%s init done!" % axis.name)
def set_on(self, axis):
self.logger.info("Entering for %s" % axis.name)
self._logger.info("Entering for %s" % axis.name)
self._set_power(axis, True)
def set_off(self, axis):
self.logger.info("Entering for %s" % axis.name)
self._logger.info("Entering for %s" % axis.name)
self._set_power(axis, False)
def _set_power(self, axis, activate):
self.logger.info("Entering for %s" % axis.name)
self._logger.info("Entering for %s" % axis.name)
self._query("MO=%d" % activate)
def _query(self, msg, in_error_code=False, **keys):
self.logger.debug("Entering for cmd = %s" % msg)
self._logger.debug("Entering for cmd = %s" % msg)
send_message = msg + "\r"
......@@ -303,7 +296,7 @@ class Elmo_whistle(Controller):
except (SerialTimeout, RuntimeError) as e:
retry = retry + 1
# print exception and number of tries done
traceback.print_exc(limit=1)
sys.excepthook(*sys.exc_info())
if retry >= 3:
# re-throw the caught exception
......@@ -324,11 +317,11 @@ class Elmo_whistle(Controller):
"Error %d (%s), Query (%s)" % (error_code, human_error, msg)
)
self.logger.debug("Leaving with reply = %s" % reply)
self._logger.debug("Leaving with reply = %s" % reply)
return reply
def _check_move_conditions(self):
self.logger.info("Entering")
self._logger.info("Entering")
sleep = False