Skip to content
Snippets Groups Projects
Commit fca988c7 authored by BRONES Romain's avatar BRONES Romain
Browse files

Add decorator to generally catch Tango Exception

* Exception Tango.DevFailed catched
* Give error message
* Exception logged to debug stream
parent 916d825b
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,21 @@ import FofbTool.Utils
# Get the module logger
logger = logging.getLogger("FofbTool")
def trycatch_tango_devfailed(func):
def inner_function(*args, **kwargs):
try:
func(*args, **kwargs)
except tango.DevFailed as e:
logger.error("DevFailed met during configuration")
logger.debug(e)
return False
return inner_function
###################################################################################################
# CONFIGURE COM BPM
###################################################################################################
@trycatch_tango_devfailed
def cellnode_configure_combpm(node_tangopath, bpmallowed):
"""
Configure the combpm block of a CellNode.
......@@ -58,6 +69,7 @@ def cellnode_configure_combpm(node_tangopath, bpmallowed):
# CONFIGURE COM LBP
###################################################################################################
@trycatch_tango_devfailed
def cellnode_configure_comlbp(node_tangopath, seqoffset=0):
"""
Configure the comlbp block of a CellNode.
......@@ -97,6 +109,7 @@ def cellnode_configure_comlbp(node_tangopath, seqoffset=0):
###################################################################################################
@trycatch_tango_devfailed
def cellnode_configure_ccn(node_tangopath, nbpm, npsc):
"""
Configure the ComCellNode block on a cellnode.
......@@ -142,6 +155,7 @@ def cellnode_configure_ccn(node_tangopath, nbpm, npsc):
logger.info("Configuration of CCN done on {}.".format(node_tangopath))
return True
@trycatch_tango_devfailed
def centralnode_configure_ccn(node_tangopath, nbpm, npsc):
"""
Configure the ComCellNode block on the centralnode.
......@@ -188,6 +202,7 @@ def centralnode_configure_ccn(node_tangopath, nbpm, npsc):
# CONFIGURE COM CORR
###################################################################################################
@trycatch_tango_devfailed
def cellnode_configure_comcorr(node_tangopath, pscid, enable):
"""
Configure the comcorr block of a CellNode.
......@@ -231,6 +246,7 @@ def cellnode_configure_comcorr(node_tangopath, pscid, enable):
# CONFIGURE MATRIX CORRECTOR
###################################################################################################
@trycatch_tango_devfailed
def centralnode_configure_corr(node_tangopath, numbpm, pscid, k1x, k1y, k2x, k2y):
"""
Configure the correction algorithm on the centralnode.
......@@ -241,6 +257,10 @@ def centralnode_configure_corr(node_tangopath, numbpm, pscid, k1x, k1y, k2x, k2y
The target fofbnode tango path, ie 'ans/dg/fofb-centralnode'
k1x, k1y, k2x, k2y: list(int)
List of coefficient for each filter. 4 coefficients : ABCD
RETURN
------
success: boolean
"""
# Get device proxy
......
......@@ -16,10 +16,21 @@ import time
logger = logging.getLogger("FofbTool")
def trycatch_tango_devfailed(func):
def inner_function(*args, **kwargs):
try:
func(*args, **kwargs)
except tango.DevFailed as e:
logger.error("DevFailed met during operation")
logger.debug(e)
return False
return inner_function
###################################################################################################
# OPERATIONS ON CCN
###################################################################################################
@trycatch_tango_devfailed
def align_ccn(node_tangopath, comlbpif=0):
"""
Align FA sequence number on a cellnode. Returns the computed offset.
......@@ -107,6 +118,7 @@ def align_ccn(node_tangopath, comlbpif=0):
return None
return seqoffset
@trycatch_tango_devfailed
def stop_ccn(node_tangopath, ccnif=[]):
"""
Stop the communication with cellnode on the specified fofbnode.
......@@ -119,6 +131,9 @@ def stop_ccn(node_tangopath, ccnif=[]):
ccnif: list(int)
List of the interface to stop. If empty, all the possible interface will be stopped.
RETURNS
-------
bool: success
"""
try:
......@@ -126,7 +141,7 @@ def stop_ccn(node_tangopath, ccnif=[]):
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
if len(ccnif) == 0:
ccnif = [int(a[7]) for a in prx.get_attribute_list() if "ccnpack" in a if "control" in a]
......@@ -140,6 +155,7 @@ def stop_ccn(node_tangopath, ccnif=[]):
prx["ccnpack{}_control".format(n)] = False
prx["ccnunpack{}_control".format(n)] = False
@trycatch_tango_devfailed
def reset_ccn(node_tangopath, ccnif=[]):
"""
Reset the communication with cellnode on the specified fofbnode.
......@@ -152,6 +168,9 @@ def reset_ccn(node_tangopath, ccnif=[]):
ccnif: list(int)
List of the interface to stop. If empty, all the possible interface will be stopped.
RETURNS
-------
bool: success
"""
try:
......@@ -159,7 +178,7 @@ def reset_ccn(node_tangopath, ccnif=[]):
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
if len(ccnif) == 0:
ccnif = [int(a[6]) for a in prx.get_attribute_list() if "ccneth" in a if "gt_reset" in a]
......@@ -177,6 +196,7 @@ def reset_ccn(node_tangopath, ccnif=[]):
ack_ccn(node_tangopath, ccnif)
@trycatch_tango_devfailed
def start_ccn(node_tangopath, ccnif=[]):
"""
Start the communication with cellnode on the specified fofbnode.
......@@ -189,13 +209,16 @@ def start_ccn(node_tangopath, ccnif=[]):
ccnif: list(int)
List of the interface to stop. If empty, all the possible interface will be stopped.
RETURNS
-------
bool: success
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
if len(ccnif) == 0:
ccnif = [int(a[7]) for a in prx.get_attribute_list() if "ccnpack" in a if "control" in a]
......@@ -212,6 +235,7 @@ def start_ccn(node_tangopath, ccnif=[]):
prx["ccnpack{}_control".format(n)] = 1
prx["ccnunpack{}_control".format(n)] = 1
@trycatch_tango_devfailed
def ack_ccn(node_tangopath, ccnif=[]):
"""
Start the communication with cellnode on the specified fofbnode.
......@@ -224,13 +248,16 @@ def ack_ccn(node_tangopath, ccnif=[]):
ccnif: list(int)
List of the interface to stop. If empty, all the possible interface will be stopped.
RETURNS
-------
bool: success
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
if len(ccnif) == 0:
ccnif = [int(a[7]) for a in prx.get_attribute_list() if "ccnpack" in a if "control" in a]
......@@ -250,6 +277,7 @@ def ack_ccn(node_tangopath, ccnif=[]):
# OPERATIONS ON COMBPM
###################################################################################################
@trycatch_tango_devfailed
def stop_combpm(node_tangopath):
"""
Stop the communication with bpm on the specified cellnode.
......@@ -259,18 +287,22 @@ def stop_combpm(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
logger.info("Stopping ComBPM on {}".format(node_tangopath))
prx["combpm_reset"] = 1
prx["combpm_gt_control"] = 0x5
@trycatch_tango_devfailed
def start_combpm(node_tangopath):
"""
Start the communication with bpm on the specified cellnode.
......@@ -280,6 +312,9 @@ def start_combpm(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
......@@ -295,6 +330,7 @@ def start_combpm(node_tangopath):
ack_combpm(node_tangopath)
@trycatch_tango_devfailed
def ack_combpm(node_tangopath):
"""
Ack errors on the communication with bpm on the specified cellnode.
......@@ -304,13 +340,16 @@ def ack_combpm(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
logger.info("Ack ComBpm on {}".format(node_tangopath))
prx["combpm_reset_error"] = True
......@@ -322,6 +361,7 @@ def ack_combpm(node_tangopath):
# OPERATIONS ON COMLBP
###################################################################################################
@trycatch_tango_devfailed
def stop_comlbp(node_tangopath):
"""
Stop the communication with LBP on the specified cellnode.
......@@ -331,13 +371,16 @@ def stop_comlbp(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
logger.info("Stopping ComLBP on {}".format(node_tangopath))
for n in range(4):
......@@ -346,6 +389,7 @@ def stop_comlbp(node_tangopath):
for n in range(4):
prx["comlbp{}_control".format(n)] = 0
@trycatch_tango_devfailed
def start_comlbp(node_tangopath):
"""
Start the communication with LBP on the specified cellnode.
......@@ -355,19 +399,23 @@ def start_comlbp(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
logger.info("Starting ComLBP on {}".format(node_tangopath))
for n in range(4):
prx["comlbp{}_control".format(n)] = 0x10
@trycatch_tango_devfailed
def reset_comlbp(node_tangopath):
"""
Reset the communication with LBP on the specified cellnode.
......@@ -377,13 +425,16 @@ def reset_comlbp(node_tangopath):
node_tangopath: str
The target fofbnode tango path, ie 'ans/dg/fofb-cellnode-c09'
RETURN
------
success: boolean
"""
try:
prx=tango.DeviceProxy(node_tangopath)
prx.ping()
except tango.DevFailed:
logger.error("Failed to obtain tango proxy or to ping to {}".format(node_tangopath))
return None
return False
logger.info("Reset ComLBP on {}".format(node_tangopath))
for n in range(4):
......@@ -557,6 +608,7 @@ def electron_stop_com(bpmlist):
# OPERATIONS FOR LBP and Electron SYNCHRONIZATION
###################################################################################################
@trycatch_tango_devfailed
def sync_bpm(bpmidlist, lbpevrx, timinglocal, timingcentral):
"""
Synchronize all BPM electronics, Electron and Brillance Plus.
......@@ -573,6 +625,9 @@ def sync_bpm(bpmidlist, lbpevrx, timinglocal, timingcentral):
timingcentral: str
Tango path of timing central
RETURN
------
success: boolean
"""
EVN=240 # Event number
bpmlist = [b[1] for b in bpmidlist]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment