Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
FofbTool
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
DG
FOFB
FofbTool
Commits
d2aa6048
Commit
d2aa6048
authored
7 months ago
by
BRONES Romain
Browse files
Options
Downloads
Patches
Plain Diff
refactor configuration
* Configparser no more used in FofbTool.Configuration
parent
83953762
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
FofbTool/Configuration.py
+76
-237
76 additions, 237 deletions
FofbTool/Configuration.py
FofbTool/Operation.py
+1
-0
1 addition, 0 deletions
FofbTool/Operation.py
FofbTool/Utils.py
+134
-21
134 additions, 21 deletions
FofbTool/Utils.py
scripts/FofbTool
+4
-6
4 additions, 6 deletions
scripts/FofbTool
with
215 additions
and
264 deletions
FofbTool/Configuration.py
+
76
−
237
View file @
d2aa6048
...
...
@@ -8,120 +8,28 @@
import
tango
import
logging
import
configparser
import
numpy
as
np
import
FofbTool.Utils
import
os
# Get the module logger
logger
=
logging
.
getLogger
(
"
FofbTool
"
)
###################################################################################################
# CONFIGURATION PARSER
###################################################################################################
# Configuration
config
=
configparser
.
ConfigParser
()
# Try to load default
defconfpath
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__spec__
.
origin
),
"
default.cfg
"
))
if
len
(
config
.
read
(
defconfpath
))
<
1
:
logger
.
warning
(
"
Default configuration file not found: {}
"
.
format
(
defconfpath
))
def
logdebugconf
():
logger
.
debug
(
"
Display config:
"
)
for
s
in
config
.
sections
():
for
o
in
config
.
options
(
s
):
logger
.
debug
(
"
{:20} {:10} {}
"
.
format
(
s
,
o
,
config
[
s
][
o
]))
def
loadconfig
(
filepath
):
"""
Load a configuration file for the module.
It supersed the default configuration, if found.
PARAMETERS
----------
filepath: str
Path to the config file
"""
global
config
logger
.
info
(
"
Load configuration from file {}
"
.
format
(
filepath
))
if
len
(
config
.
read
(
filepath
))
<
1
:
logger
.
warning
(
"
Configuration file not found: {}
"
.
format
(
filepath
))
def
getconf
(
option
,
section
,
nodename
=
""
,
t
=
""
,
l
=
False
):
"""
Helper method to retrieve an option in the loaded configuration.
It tries to find a section named section.nodename and fall back to section only if fails.
PARAMETERS
----------
option: str
Name of the option to retrieve
section: str
Section in wich to search
nodename: str
Specify a particular nodename. If not found in config, fall back to section default.
t: str (
'
i
'
,
'
f
'
,
'
b
'
,
''
)
Give the type to cast, integer, float, boolean or string.
l: boolean
Cast from a list
RETURNS
-------
roption: str, int, float or boolean
Read option
"""
if
l
:
if
t
==
'
b
'
:
raise
NotImplemented
(
"
List of boolean not implemented
"
)
try
:
val
=
np
.
asarray
(
config
.
get
(
"
{}.{}
"
.
format
(
section
,
nodename
),
option
).
split
(),
dtype
=
t
)
except
(
configparser
.
NoSectionError
,
configparser
.
NoOptionError
):
val
=
np
.
asarray
(
config
.
get
(
section
,
option
).
split
(),
dtype
=
t
)
else
:
try
:
func
=
getattr
(
config
,
{
'
i
'
:
"
getint
"
,
'
f
'
:
"
getfloat
"
,
'
b
'
:
"
getboolean
"
,
''
:
"
get
"
}[
t
])
except
KeyError
as
e
:
log
.
debug
(
str
(
e
))
raise
ValueError
(
"
Allowed t argument are
'
i
'
,
'
f
'
,
'
b
'
or
''"
)
try
:
val
=
func
(
"
{}.{}
"
.
format
(
section
,
nodename
),
option
)
except
(
configparser
.
NoSectionError
,
configparser
.
NoOptionError
):
val
=
func
(
section
,
option
)
return
val
###################################################################################################
# CONFIGURE COM BPM
###################################################################################################
# Filter list depends on the cellnode. These are the default values.
bpmfilterlist
=
{
"
cellnode-c01
"
:
np
.
array
(
list
(
range
(
1
,
23
))
+
list
(
range
(
115
,
123
))),
"
cellnode-c06
"
:
np
.
array
(
range
(
23
,
53
)),
"
cellnode-c09
"
:
np
.
array
(
range
(
53
,
83
)),
"
cellnode-c14
"
:
np
.
array
(
range
(
83
,
115
)),
}
def
cellnode_configure_combpm
(
cellnodename
,
bpmallowed
=
None
):
def
cellnode_configure_combpm
(
node_tangopath
,
bpmallowed
):
"""
Configure the combpm block of a CellNode.
The BPM data allowed through are either taken in the argument, or default to configuration.
The BPM data allowed through are taken in the argument.
PARAMETERS
----------
cellnodename
: str
The target
cellnode, ie
'
cellnode-c09
'
node_tangopath
: str
The target
fofbnode tango path, ie
'
ans/dg/fofb-
cellnode-c09
'
bpmallowed: [int], None
List of BPMID allowed through the block.
If None, default to nominal values.
List of BPMID allowed through the block.
RETURN
------
...
...
@@ -131,46 +39,34 @@ def cellnode_configure_combpm(cellnodename, bpmallowed=None):
# Get device proxy
try
:
p
=
config
[
"
tangopath.fofbnodes
"
][
cellnodename
.
lower
()]
except
KeyError
:
logger
.
error
(
"
Wrong cellnodename. Possibilities are {}
"
.
format
(
list
(
config
[
'
tangopath.fofbnodes
'
].
keys
())))
return
False
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
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
# Select BPM id allowed to pass through
if
bpmallowed
is
None
:
logger
.
debug
(
"
Default to nominal values for BPM filter
"
)
bpmallowed
=
getconf
(
"
bpmfilter
"
,
"
combpm
"
,
cellnodename
.
lower
(),
'
i
'
,
True
)
logger
.
debug
(
"
Activate BPMs {} in the filter for {}
"
.
format
(
bpmallowed
,
p
))
logger
.
debug
(
"
Activate BPMs {} in the filter for {}
"
.
format
(
bpmallowed
,
node_tangopath
))
f
=
prx
[
"
combpm_filter_table
"
].
value
f
[:]
=
0
f
[
np
.
array
(
bpmallowed
)]
=
0x80
prx
[
"
combpm_filter_table
"
]
=
f
logger
.
info
(
"
Configuration of ComBpm done on {}.
"
.
format
(
p
))
logger
.
info
(
"
Configuration of ComBpm done on {}.
"
.
format
(
node_tangopath
))
return
True
###################################################################################################
# CONFIGURE COM LBP
###################################################################################################
def
cellnode_configure_comlbp
(
cellnodename
,
seqoffset
=
0
):
def
cellnode_configure_comlbp
(
node_tangopath
,
seqoffset
=
0
):
"""
Configure the comlbp block of a CellNode.
For now, nothing done
PARAMETERS
----------
cellnodename
: str
The target
cellnode, ie
'
cellnode-c09
'
node_tangopath
: str
The target
fofbnode tango path, ie
'
ans/dg/fofb-
cellnode-c09
'
seqoffset: int
Sequence offset to configure
...
...
@@ -183,24 +79,16 @@ def cellnode_configure_comlbp(cellnodename, seqoffset=0):
# Get device proxy
try
:
p
=
config
[
"
tangopath.fofbnodes
"
][
cellnodename
.
lower
()]
except
KeyError
:
logger
.
error
(
"
Wrong cellnodename. Possibilities are {}
"
.
format
(
list
(
config
[
'
tangopath.fofbnodes
'
].
keys
())))
return
False
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
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
logger
.
debug
(
"
Program sequence offset {} in {}
"
.
format
(
seqoffset
,
cellnodename
))
for
n
in
range
(
4
):
prx
[
"
comlbp{}_seqoffset
"
.
format
(
n
)]
=
seqoffset
logger
.
info
(
"
Configuration of ComLBP done on {}.
"
.
format
(
p
))
return
True
...
...
@@ -209,21 +97,19 @@ def cellnode_configure_comlbp(cellnodename, seqoffset=0):
###################################################################################################
def
cellnode_configure_ccn
(
cellnodename
,
nbpm
=
None
,
npsc
=
None
):
def
cellnode_configure_ccn
(
node_tangopath
,
nbpm
,
npsc
):
"""
Configure the ComCellNode block on a cellnode.
Automatically set the number of bpm/psc packets and MAC length.
PARAMETERS
----------
cellnodename
: str
The target
cellnode, ie
'
cellnode-c09
'
node_tangopath
: str
The target
fofbnode tango path, ie
'
ans/dg/fofb-
cellnode-c09
'
nbpm:
Number of BPM allowed by the filter, hence the number of expected BPM packets.
If None, auto detect the number from the combpm_filter_table attribute.
npsc:
Number of total PSC, hence the number of expected PSC packets.
Default to 100.
RETURN
------
...
...
@@ -233,28 +119,14 @@ def cellnode_configure_ccn(cellnodename, nbpm=None, npsc=None):
# Get device proxy
try
:
p
=
config
[
"
tangopath.fofbnodes
"
][
cellnodename
.
lower
()]
except
KeyError
:
logger
.
error
(
"
Wrong cellnodename. Possibilities are {}
"
.
format
(
list
(
config
[
'
tangopath.fofbnodes
'
].
keys
())))
return
False
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
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
if
nbpm
is
None
:
logger
.
debug
(
"
Default to nominal values for number of BPM packets
"
)
# Get number of BPM activated in the filter
nbpm
=
getconf
(
"
nbpm
"
,
"
ccn
"
,
cellnodename
,
'
i
'
)
logger
.
debug
(
"
{} bpm allowed in the ethernet frame on {}
"
.
format
(
nbpm
,
p
))
if
npsc
is
None
:
logger
.
debug
(
"
Default to nominal values for number of PSC packets
"
)
npsc
=
getconf
(
"
npsc
"
,
"
ccn
"
,
cellnodename
,
'
i
'
)
logger
.
debug
(
"
{} psc expected in the ethernet frame on {}
"
.
format
(
nbpm
,
p
))
logger
.
debug
(
"
{} bpm allowed in the ethernet frame on {}
"
.
format
(
nbpm
,
node_tangopath
))
logger
.
debug
(
"
{} psc expected in the ethernet frame on {}
"
.
format
(
nbpm
,
node_tangopath
))
maclen
=
10
*
nbpm
+
10
logger
.
debug
(
"
Configure packeter framesize (mac length) to {}
"
.
format
(
maclen
))
...
...
@@ -267,16 +139,18 @@ def cellnode_configure_ccn(cellnodename, nbpm=None, npsc=None):
logger
.
debug
(
"
Configure unpacketer framesize (mac length) to {}
"
.
format
(
maclen
))
prx
[
"
ccnunpack0_framesize
"
]
=
maclen
logger
.
info
(
"
Configuration of CCN done on {}.
"
.
format
(
p
))
logger
.
info
(
"
Configuration of CCN done on {}.
"
.
format
(
node_tangopath
))
return
True
def
centralnode_configure_ccn
(
n
bpm
=
None
,
npsc
=
None
):
def
centralnode_configure_ccn
(
n
ode_tangopath
,
nbpm
,
npsc
):
"""
Configure the ComCellNode block on the centralnode.
Automatically set the number of bpm/psc packets and MAC length.
PARAMETERS
----------
node_tangopath: str
The target fofbnode tango path, ie
'
ans/dg/fofb-centralnode
'
nbpm: list(int)
Number of BPM packet received on each interface.
npsc:
...
...
@@ -287,24 +161,13 @@ def centralnode_configure_ccn(nbpm=None, npsc=None):
success: boolean
True if configuration is a success
"""
p
=
config
[
"
tangopath.fofbnodes
"
][
"
centralnode
"
]
# Get device proxy
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
if
nbpm
is
None
:
logger
.
debug
(
"
Use default value for nbpm
"
)
nbpm
=
[
getconf
(
"
nbpm
"
,
"
ccn
"
,
n
,
'
i
'
)
for
n
in
config
[
'
tangopath.fofbnodes
'
].
keys
()
if
'
cellnode
'
in
n
]
logger
.
debug
(
"
{} bpm expected in the ethernet frame on {}
"
.
format
(
nbpm
,
p
))
if
npsc
is
None
:
logger
.
debug
(
"
Default to nominal values for number of BPM packets
"
)
# Get number of BPM activated in the filter
npsc
=
getconf
(
"
npsc
"
,
"
ccn
"
,
'
centralnode
'
,
'
i
'
)
logger
.
debug
(
"
{} psc allowed in the ethernet frame on {}
"
.
format
(
nbpm
,
p
))
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
for
n
in
range
(
len
(
nbpm
)):
maclen
=
npsc
*
6
+
10
...
...
@@ -318,14 +181,14 @@ def centralnode_configure_ccn(nbpm=None, npsc=None):
logger
.
debug
(
"
Configure unpacketer {} framesize (mac length) to {}
"
.
format
(
n
,
maclen
))
prx
[
"
ccnunpack{}_framesize
"
.
format
(
n
)]
=
maclen
logger
.
info
(
"
Configuration of CCN done on {}.
"
.
format
(
p
))
logger
.
info
(
"
Configuration of CCN done on {}.
"
.
format
(
node_tangopath
))
return
True
###################################################################################################
# CONFIGURE COM CORR
###################################################################################################
def
cellnode_configure_comcorr
(
cellnodename
,
pscid
=
None
,
enable
=
True
):
def
cellnode_configure_comcorr
(
node_tangopath
,
pscid
,
enable
):
"""
Configure the comcorr block of a CellNode.
The PSC ID either taken in the argument, or default to nominal values.
...
...
@@ -333,8 +196,8 @@ def cellnode_configure_comcorr(cellnodename, pscid=None, enable=True):
PARAMETERS
----------
cellnodename
: str
The target
cellnode, ie
'
cellnode-c09
'
node_tangopath
: str
The target
fofbnode tango path, ie
'
ans/dg/fofb-
cellnode-c09
'
pscid: [int], None
List of 32 PSCID to program on the output board. If None, default to nominal values.
...
...
@@ -346,84 +209,60 @@ def cellnode_configure_comcorr(cellnodename, pscid=None, enable=True):
success: boolean
True if configuration is a success
"""
# Get device proxy
try
:
p
=
config
[
"
tangopath.fofbnodes
"
][
cellnodename
.
lower
()]
except
KeyError
:
logger
.
error
(
"
Wrong cellnodename. Possibilities are {}
"
.
format
(
list
(
config
[
'
tangopath.fofbnodes
'
].
keys
())))
return
False
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
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
if
pscid
is
None
:
logger
.
debug
(
"
Default to nominal values for PSCID
"
)
pscid
=
getconf
(
"
pscid
"
,
"
comcorr
"
,
cellnodename
,
'
i
'
,
True
)
else
:
if
len
(
pscid
)
!=
32
:
logger
.
error
(
"
pscid shall have length 32
"
)
return
False
logger
.
debug
(
"
Set PSCIDs {} in the filter for {}
"
.
format
(
pscid
,
p
))
logger
.
debug
(
"
Set PSCIDs {} in the filter for {}
"
.
format
(
pscid
,
node_tangopath
))
f
=
prx
[
"
comcorr_line_id
"
].
value
f
[:]
=
pscid
f
[:]
=
f
+
0x10000
*
bool
(
enable
)
logger
.
debug
(
"
Set comcorr_line_id {} for {}
"
.
format
(
f
,
p
))
logger
.
debug
(
"
Set comcorr_line_id {} for {}
"
.
format
(
f
,
node_tangopath
))
prx
[
"
comcorr_line_id
"
]
=
f
logger
.
info
(
"
Configuration of ComCorr done on {}.
"
.
format
(
p
))
logger
.
info
(
"
Configuration of ComCorr done on {}.
"
.
format
(
node_tangopath
))
return
True
###################################################################################################
# CONFIGURE MATRIX CORRECTOR
###################################################################################################
def
centralnode_configure_corr
():
def
centralnode_configure_corr
(
node_tangopath
,
numbpm
,
pscid
,
k1x
,
k1y
,
k2x
,
k2y
):
"""
Configure the correction algorithm on the centralnode.
PARAMETERS
----------
node_tangopath: str
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
"""
p
=
config
[
"
tangopath.fofbnodes
"
][
"
centralnode
"
]
# Get device proxy
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
logger
.
error
(
"
Failed to get the Device proxy to
'
{}
'
. Configuration of corrector algorithm failed.
"
.
format
(
p
))
logger
.
debug
(
str
(
e
))
return
False
# Legacy
prx
[
"
corr_k1a_x
"
]
=
getconf
(
"
k1a_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1b_x
"
]
=
getconf
(
"
k1b_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1ic_x
"
]
=
getconf
(
"
k1ic_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1d_x
"
]
=
getconf
(
"
k1d_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1a_y
"
]
=
getconf
(
"
k1a_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1b_y
"
]
=
getconf
(
"
k1b_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1ic_y
"
]
=
getconf
(
"
k1ic_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k1d_y
"
]
=
getconf
(
"
k1d_y
"
,
"
corr
"
,
t
=
'
i
'
)
# Unitary
prx
[
"
corr_k2a_x
"
]
=
getconf
(
"
k2a_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2b_x
"
]
=
getconf
(
"
k2b_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2ic_x
"
]
=
getconf
(
"
k2ic_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2d_x
"
]
=
getconf
(
"
k2d_x
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2a_y
"
]
=
getconf
(
"
k2a_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2b_y
"
]
=
getconf
(
"
k2b_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2ic_y
"
]
=
getconf
(
"
k2ic_y
"
,
"
corr
"
,
t
=
'
i
'
)
prx
[
"
corr_k2d_y
"
]
=
getconf
(
"
k2d_y
"
,
"
corr
"
,
t
=
'
i
'
)
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
for
i
,
l
in
enumerate
([
"
a
"
,
"
b
"
,
"
ic
"
,
"
d
"
]):
prx
[
"
corr_k1{}_x
"
.
format
(
l
)]
=
k1x
[
i
]
prx
[
"
corr_k2{}_x
"
.
format
(
l
)]
=
k2x
[
i
]
prx
[
"
corr_k1{}_y
"
.
format
(
l
)]
=
k1y
[
i
]
prx
[
"
corr_k2{}_y
"
.
format
(
l
)]
=
k2y
[
i
]
f
=
prx
[
"
corr_pscid
"
].
value
f
[
0
:
100
]
=
getconf
(
'
pscid
'
,
'
corr
'
,
t
=
'
i
'
,
l
=
True
)
f
[
0
:
100
]
=
pscid
prx
[
"
corr_pscid
"
]
=
f
prx
[
"
corr_num_bpm
"
]
=
getconf
(
'
numbpm
'
,
'
corr
'
,
t
=
'
i
'
)
prx
[
"
corr_num_bpm
"
]
=
numbpm
logger
.
info
(
"
Configuration of Corr done on {}.
"
.
format
(
p
))
logger
.
info
(
"
Configuration of Corr done on {}.
"
.
format
(
node_tangopath
))
return
True
This diff is collapsed.
Click to expand it.
FofbTool/Operation.py
+
1
−
0
View file @
d2aa6048
...
...
@@ -310,6 +310,7 @@ def ack_combpm(node_tangopath):
time
.
sleep
(
1
)
prx
[
"
combpm_reset_error
"
]
=
False
###################################################################################################
# OPERATIONS ON COMLBP
###################################################################################################
...
...
This diff is collapsed.
Click to expand it.
FofbTool/Utils.py
+
134
−
21
View file @
d2aa6048
...
...
@@ -11,10 +11,98 @@ import logging
import
FofbTool.DeviceAttributeConfiguration
import
FofbTool.Configuration
import
FofbTool.Operation
import
configparser
import
os
import
numpy
as
np
# Get the module logger
logger
=
logging
.
getLogger
(
"
FofbTool
"
)
###################################################################################################
# CONFIGURATION PARSER
###################################################################################################
# Configuration
config
=
configparser
.
ConfigParser
()
# Try to load default
defconfpath
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__spec__
.
origin
),
"
default.cfg
"
))
if
len
(
config
.
read
(
defconfpath
))
<
1
:
logger
.
warning
(
"
Default configuration file not found: {}
"
.
format
(
defconfpath
))
def
logdebugconf
():
logger
.
debug
(
"
Display config:
"
)
for
s
in
config
.
sections
():
for
o
in
config
.
options
(
s
):
logger
.
debug
(
"
{:20} {:10} {}
"
.
format
(
s
,
o
,
config
[
s
][
o
]))
def
loadconfig
(
filepath
):
"""
Load a configuration file for the module.
It supersed the default configuration, if found.
PARAMETERS
----------
filepath: str
Path to the config file
"""
global
config
logger
.
info
(
"
Load configuration from file {}
"
.
format
(
filepath
))
if
len
(
config
.
read
(
filepath
))
<
1
:
logger
.
warning
(
"
Configuration file not found: {}
"
.
format
(
filepath
))
def
getconf
(
option
,
section
,
nodename
=
""
,
t
=
""
,
l
=
False
):
"""
Helper method to retrieve an option in the loaded configuration.
It tries to find a section named section.nodename and fall back to section only if fails.
PARAMETERS
----------
option: str
Name of the option to retrieve
section: str
Section in wich to search
nodename: str
Specify a particular nodename. If not found in config, fall back to section default.
t: str (
'
i
'
,
'
f
'
,
'
b
'
,
''
)
Give the type to cast, integer, float, boolean or string.
l: boolean
Cast from a list
RETURNS
-------
roption: str, int, float or boolean
Read option
"""
if
l
:
if
t
==
'
b
'
:
raise
NotImplemented
(
"
List of boolean not implemented
"
)
try
:
val
=
np
.
asarray
(
config
.
get
(
"
{}.{}
"
.
format
(
section
,
nodename
),
option
).
split
(),
dtype
=
t
)
except
(
configparser
.
NoSectionError
,
configparser
.
NoOptionError
):
val
=
np
.
asarray
(
config
.
get
(
section
,
option
).
split
(),
dtype
=
t
)
else
:
try
:
func
=
getattr
(
config
,
{
'
i
'
:
"
getint
"
,
'
f
'
:
"
getfloat
"
,
'
b
'
:
"
getboolean
"
,
''
:
"
get
"
}[
t
])
except
KeyError
as
e
:
log
.
debug
(
str
(
e
))
raise
ValueError
(
"
Allowed t argument are
'
i
'
,
'
f
'
,
'
b
'
or
''"
)
try
:
val
=
func
(
"
{}.{}
"
.
format
(
section
,
nodename
),
option
)
except
(
configparser
.
NoSectionError
,
configparser
.
NoOptionError
):
val
=
func
(
section
,
option
)
return
val
###################################################################################################
# INIT FUNCTIONS
###################################################################################################
def
init_opcua
(
force
=
False
):
"""
Run init on all OPCUA devices. Catch DevFailed and inform via log.
...
...
@@ -25,7 +113,7 @@ def init_opcua(force=False):
logger
.
warning
(
"
Not running because FOFB seems to be running.
"
)
return
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
logger
.
info
(
"
Perform init() on {}
'
{}
'"
.
format
(
n
,
p
))
try
:
tango
.
DeviceProxy
(
p
).
init
()
...
...
@@ -43,7 +131,7 @@ def init_watcher(force=False):
logger
.
warning
(
"
Not running because FOFB seems to be running.
"
)
return
p
=
FofbTool
.
Configuration
.
config
[
"
tangopath
"
][
"
fofb-watcher
"
]
p
=
config
[
"
tangopath
"
][
"
fofb-watcher
"
]
try
:
wprx
=
tango
.
DeviceProxy
(
p
)
wprx
.
set_timeout_millis
(
60000
)
...
...
@@ -60,7 +148,7 @@ def init_watcher(force=False):
logger
.
debug
(
str
(
e
))
logger
.
info
(
"
Perform init() on Fofb-Command.
"
)
p
=
FofbTool
.
Configuration
.
config
[
"
tangopath
"
][
"
fofb-command
"
]
p
=
config
[
"
tangopath
"
][
"
fofb-command
"
]
try
:
tango
.
DeviceProxy
(
p
).
init
()
except
tango
.
DevFailed
as
e
:
...
...
@@ -71,7 +159,7 @@ def confds_opcua():
"""
Apply attribute configuration on all OPCUA devices. Catch DevFailed and inform via log.
"""
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
...
...
@@ -89,6 +177,11 @@ def confds_opcua():
logger
.
debug
(
str
(
e
))
###################################################################################################
# OPERATE FUNCTIONS
###################################################################################################
def
check_fofbnotrunning
(
force
=
False
):
"""
Check if the FOFB is not running.
...
...
@@ -104,7 +197,7 @@ def check_fofbnotrunning(force=False):
logger
.
warning
(
"
Forced action even if FOFB might be running
"
)
return
True
p
=
FofbTool
.
Configuration
.
config
[
"
tangopath
"
][
"
fofb-watcher
"
]
p
=
config
[
"
tangopath
"
][
"
fofb-watcher
"
]
try
:
prx
=
tango
.
DeviceProxy
(
p
)
except
tango
.
DevFailed
as
e
:
...
...
@@ -135,9 +228,10 @@ def conf_all_combpm(force=False):
return
False
success
=
True
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
s
=
FofbTool
.
Configuration
.
cellnode_configure_combpm
(
n
)
bpmallowed
=
getconf
(
"
bpmfilter
"
,
"
combpm
"
,
n
.
lower
(),
'
i
'
,
True
)
s
=
FofbTool
.
Configuration
.
cellnode_configure_combpm
(
p
,
bpmallowed
)
success
=
success
and
s
return
success
...
...
@@ -164,9 +258,10 @@ def conf_all_comcorr(force=False, enable=True):
return
False
success
=
True
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
s
=
FofbTool
.
Configuration
.
cellnode_configure_comcorr
(
n
,
enable
=
enable
)
pscid
=
getconf
(
"
pscid
"
,
"
comcorr
"
,
n
,
'
i
'
,
True
)
s
=
FofbTool
.
Configuration
.
cellnode_configure_comcorr
(
p
,
pscid
,
enable
=
enable
)
success
=
success
and
s
return
success
...
...
@@ -188,12 +283,17 @@ def conf_all_ccn(force=False):
return
False
success
=
True
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
s
=
FofbTool
.
Configuration
.
cellnode_configure_ccn
(
n
)
nbpm
=
getconf
(
"
nbpm
"
,
"
ccn
"
,
n
,
'
i
'
)
npsc
=
getconf
(
"
npsc
"
,
"
ccn
"
,
n
,
'
i
'
)
s
=
FofbTool
.
Configuration
.
cellnode_configure_ccn
(
p
,
nbpm
,
npsc
)
success
=
success
and
s
s
=
FofbTool
.
Configuration
.
centralnode_configure_ccn
()
p
=
config
[
"
tangopath.fofbnodes
"
][
"
centralnode
"
]
nbpm
=
[
getconf
(
"
nbpm
"
,
"
ccn
"
,
n
,
'
i
'
)
for
n
in
config
[
'
tangopath.fofbnodes
'
].
keys
()
if
'
cellnode
'
in
n
]
npsc
=
getconf
(
"
npsc
"
,
"
ccn
"
,
'
centralnode
'
,
'
i
'
)
s
=
FofbTool
.
Configuration
.
centralnode_configure_ccn
(
p
,
nbpm
,
npsc
)
success
=
success
and
s
return
success
...
...
@@ -214,9 +314,9 @@ def get_prx_from_nodename(nodename):
"""
# Get device proxy
try
:
p
=
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
][
nodename
.
lower
()]
p
=
config
[
"
tangopath.fofbnodes
"
][
nodename
.
lower
()]
except
KeyError
:
logger
.
error
(
"
Wrong nodename. Possibilities are {}
"
.
format
(
list
(
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
keys
())))
logger
.
error
(
"
Wrong nodename. Possibilities are {}
"
.
format
(
list
(
config
[
"
tangopath.fofbnodes
"
].
keys
())))
return
None
try
:
...
...
@@ -239,7 +339,7 @@ def stop_all_combpm(force=False):
logger
.
warning
(
"
Not running stop combpm because FOFB seems to be running.
"
)
return
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
FofbTool
.
Operation
.
stop_combpm
(
p
)
...
...
@@ -255,7 +355,7 @@ def stop_all_comlbp(force=False):
logger
.
warning
(
"
Not running stop comlbp because FOFB seems to be running.
"
)
return
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
try
:
FofbTool
.
Operation
.
reset_comlbp
(
p
)
...
...
@@ -275,7 +375,7 @@ def stop_all_ccn(force=False):
logger
.
warning
(
"
Not running stop comccn because FOFB seems to be running.
"
)
return
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
FofbTool
.
Operation
.
stop_ccn
(
p
)
FofbTool
.
Operation
.
reset_ccn
(
p
)
...
...
@@ -287,7 +387,7 @@ def start_all_combpm():
"""
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
FofbTool
.
Operation
.
start_combpm
(
p
)
...
...
@@ -297,7 +397,7 @@ def start_all_comlbp():
"""
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
try
:
FofbTool
.
Operation
.
start_comlbp
(
p
)
...
...
@@ -312,7 +412,7 @@ def start_all_ccn():
"""
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
FofbTool
.
Operation
.
start_ccn
(
p
)
def
align_all_ccn
(
cellnodename
,
force
=
False
):
...
...
@@ -332,9 +432,22 @@ def align_all_ccn(cellnodename, force=False):
return
for
n
,
p
in
FofbTool
.
Configuration
.
config
[
"
tangopath.fofbnodes
"
].
items
():
for
n
,
p
in
config
[
"
tangopath.fofbnodes
"
].
items
():
if
'
cellnode
'
in
n
:
try
:
FofbTool
.
Configuration
.
cellnode_configure_comlbp
(
n
,
seqoffset
)
except
(
tango
.
DevFailed
,
TypeError
):
logger
.
error
(
"
Could not set comlbp offset on {}
"
.
format
(
n
))
def
conf_centralnode_corr
():
p
=
config
[
"
tangopath.fofbnodes
"
][
"
centralnode
"
]
FofbTool
.
Configuration
.
centralnode_configure_corr
(
p
,
getconf
(
'
numbpm
'
,
'
corr
'
,
t
=
'
i
'
),
getconf
(
'
pscid
'
,
'
corr
'
,
t
=
'
i
'
,
l
=
True
),
[
getconf
(
"
k1{}_x
"
.
format
(
l
),
"
corr
"
,
t
=
'
i
'
)
for
l
in
[
"
a
"
,
"
b
"
,
"
ic
"
,
"
d
"
]],
[
getconf
(
"
k1{}_y
"
.
format
(
l
),
"
corr
"
,
t
=
'
i
'
)
for
l
in
[
"
a
"
,
"
b
"
,
"
ic
"
,
"
d
"
]],
[
getconf
(
"
k2{}_x
"
.
format
(
l
),
"
corr
"
,
t
=
'
i
'
)
for
l
in
[
"
a
"
,
"
b
"
,
"
ic
"
,
"
d
"
]],
[
getconf
(
"
k2{}_y
"
.
format
(
l
),
"
corr
"
,
t
=
'
i
'
)
for
l
in
[
"
a
"
,
"
b
"
,
"
ic
"
,
"
d
"
]],
)
This diff is collapsed.
Click to expand it.
scripts/FofbTool
+
4
−
6
View file @
d2aa6048
...
...
@@ -17,8 +17,6 @@ if __name__ == '__main__':
sys
.
path
.
insert
(
0
,
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
..
'
)))
import
FofbTool.Utils
import
FofbTool.Operation
import
FofbTool.Configuration
# Still needs for one function, TODO
# Get the module logger
logger
=
logging
.
getLogger
(
"
FofbTool
"
)
...
...
@@ -101,11 +99,11 @@ if __name__ == '__main__':
logger
.
info
(
"
FofbTool version {}
"
.
format
(
FofbTool
.
__version__
))
if
not
args
.
fileconfig
is
None
:
FofbTool
.
Configuration
.
loadconfig
(
args
.
fileconfig
)
FofbTool
.
Configuration
.
logdebugconf
()
FofbTool
.
Utils
.
loadconfig
(
args
.
fileconfig
)
FofbTool
.
Utils
.
logdebugconf
()
if
not
args
.
dump_configuration
is
None
:
FofbTool
.
Configuration
.
config
.
write
(
args
.
dump_configuration
)
FofbTool
.
Utils
.
config
.
write
(
args
.
dump_configuration
)
args
.
dump_configuration
.
close
()
...
...
@@ -138,7 +136,7 @@ if __name__ == '__main__':
if
args
.
configure
in
(
"
ccn
"
,
"
all
"
):
FofbTool
.
Utils
.
conf_all_ccn
(
force
=
args
.
force
)
if
args
.
configure
in
(
"
corr
"
,
"
all
"
):
FofbTool
.
Configuration
.
centralnode_configur
e_corr
()
FofbTool
.
Utils
.
conf_centralnod
e_corr
()
if
args
.
sync
:
FofbTool
.
Operation
.
sync_all_bpm
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment