DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
ers
python
ers
__init__.py
Go to the documentation of this file.
1
from
._daq_ers_py
import
*
2
3
import
sys
4
import
ers
5
import
inspect
6
import
platform
7
import
os
8
import
sys
9
import
re
10
import
time
11
import
getpass
12
import
_thread
13
import
logging
14
15
class
PyContext
( object ):
16
"extracts context for an ERS issue"
17
__file = re.sub(
r'\.pyc$'
,
'.py'
, __file__ )
18
19
def
__init__
( self, issue ):
20
self.
stack
= [f[0]
for
f
in
inspect.stack() \
21
if
f[1] != self.
__file
\
22
and
(
'self'
not
in
f[0].f_locals\
23
or
not
isinstance(f[0].f_locals[
'self'
],
ers.PyIssue
))]
24
self.
package_name
= issue.__class__.__module__
25
class_name =
lambda
:
'self'
in
self.
stack
[0].f_locals \
26
and
self.
stack
[0].f_locals[
'self'
].__class__.__name__ +
'.'
\
27
or
''
28
29
self.
function_name
= class_name() + self.
stack
[0].f_code.co_name;
30
try
:
31
self.
function_name
+= inspect.formatargvalues( *inspect.getargvalues(self.
stack
[0]) )
32
except
Exception
as
exx:
33
self.
function_name
+=
'(...)'
34
35
self.
file_name
= self.
stack
[0].f_code.co_filename
36
self.
line_number
= self.
stack
[0].f_lineno
37
self.
host_name
= platform.node()
38
self.
cwd
= os.getcwd()
39
self.
process_id
= os.getpid()
40
# Need to truncate this to fit 32 bit signed int
41
self.
thread_id
= int(_thread.get_ident()%2**31)
42
self.
user_id
= os.getuid()
43
self.
user_name
= getpass.getuser()
44
self.
application_name
= os.getenv(
"DUNEDAQ_APPLICATION_NAME"
,
"Undefined"
)
45
46
47
class
PyIssue
(
Exception
):
48
"base class for Python ERS exceptions"
49
__verbosity = int( os.getenv(
"DUNEDAQ_ERS_VERBOSITY_LEVEL"
,
"2"
) )
50
51
def
__init__
( self, message, kwargs, cause ):
52
Exception.__init__( self, message, kwargs, cause )
53
self.
time
= time.time()
54
# self.severity = ers.severity.Error
55
self.
message
= message
56
self.
cause
= cause
57
self.
__context
=
PyContext
(self)
58
self.
context_parameters
= vars(self.
__context
)
59
self.
qualifiers
= [ self.
__context
.package_name ]
60
self.
__parameters
= dict([ (str(k), str(v))
for
(k,v)
in
list(kwargs.items()) ])
61
self.__dict__.update( kwargs )
62
self.
rpc
=
ers.RemoteProcessContext
(self.
__context
.host_name,self.
__context
.process_id,self.
__context
.thread_id,
63
self.
__context
.cwd,self.
__context
.user_id,self.
__context
.user_name,
64
self.
__context
.application_name)
65
self.
rc
=
ers.RemoteContext
(self.
__context
.package_name,self.
__context
.file_name,self.
__context
.line_number,self.
__context
.function_name,self.
rpc
)
66
#self.lc = ers.LocalContext(self.__context.application_name, self.__context.file_name, self.__context.line_number, self.__context.function_name, False)
67
self.
ai
=
ers.AnyIssue
( self.
__context
.function_name, self.
rc
, message )
68
69
@property
70
def
context
( self ):
71
return
self.
__context
72
73
@property
74
def
parameters
( self ):
75
return
self.
__parameters
76
77
def
isInstanceOf
( self, cname ):
78
return
self.__class__.__name__ == cname
and
True
or
False
79
80
def
__str__
( self ):
81
return
self.
message
82
83
'''Wrap a message string as an ERS issue'''
84
def
message
(message):
85
# This class collects information needed for message context
86
ct =
PyContext
(message)
87
# Still need to do something about these
88
package_name =
"erspy"
89
type=
"Warning"
90
# Create Context using the ers-python bindings
91
rpc =
ers.RemoteProcessContext
(ct.host_name,ct.process_id,ct.thread_id,ct.cwd,ct.user_id,ct.user_name,ct.application_name)
92
rc =
ers.RemoteContext
(package_name,ct.file_name,ct.line_number,ct.function_name,rpc)
93
# Create and return an ers issue
94
return
ers.AnyIssue
(type, rc, message)
95
96
97
'''Bunch of functions to wrap a text string and inject it as an ers message of different types'''
98
def
pydebug
( msg, lvl ):
99
"sends msg to the debug stream"
100
ers.debug
( isinstance( msg,
ers.AnyIssue
)
and
msg
or
message
( msg ), lvl )
101
102
def
pylog
( msg ):
103
"sends msg to the log stream"
104
ers.log
( isinstance( msg,
ers.AnyIssue
)
and
msg
or
message
( msg ) )
105
106
def
pyinfo
( msg ):
107
"sends msg to the information stream"
108
ers.info
( isinstance( msg,
ers.AnyIssue
)
and
msg
or
message
( msg ) )
109
110
'''These just inject an issue into the more serious streams.
111
The only thing these add over just calling the bound ers function directly is that they
112
warn you if you use the wrong type of argument.
113
Mainly here because the old ers.py had them, and they provide a consistency of interface
114
rather than forcing the user to use these calls for some things and direct ers calls for others'''
115
def
pywarning
( issue ):
116
"sends issue to the warning stream"
117
assert
isinstance(issue,
ers.AnyIssue
), \
118
'Only an instance of ers.Issue sub-class can be sent to the ers.warning stream'
119
ers.warning
( issue )
120
121
def
pyerror
( issue ):
122
"sends issue to the error stream"
123
assert
isinstance(issue,
ers.AnyIssue
), \
124
'Only an instance of ers.Issue sub-class can be sent to the ers.error stream'
125
ers.error
( issue )
126
127
def
pyfatal
( issue ):
128
"sends issue to the fatal stream"
129
assert
isinstance(issue,
ers.AnyIssue
), \
130
'Only an instance of ers.Issue sub-class can be sent to the ers.fatal stream'
131
ers.fatal
( issue )
ers::AnyIssue
Definition
AnyIssue.hpp:33
ers::Issue
Base class for any user define issue.
Definition
Issue.hpp:80
ers::Issue::context
const Context & context() const
Context of the issue.
Definition
Issue.hpp:111
ers::Issue::parameters
const string_map & parameters() const
return array of parameters
Definition
Issue.hpp:120
ers.PyContext
Definition
__init__.py:15
ers.PyContext.line_number
list line_number
Definition
__init__.py:36
ers.PyContext.process_id
process_id
Definition
__init__.py:39
ers.PyContext.thread_id
thread_id
Definition
__init__.py:41
ers.PyContext.file_name
list file_name
Definition
__init__.py:35
ers.PyContext.function_name
list function_name
Definition
__init__.py:29
ers.PyContext.__init__
__init__(self, issue)
Definition
__init__.py:19
ers.PyContext.stack
list stack
Definition
__init__.py:20
ers.PyContext.package_name
package_name
Definition
__init__.py:24
ers.PyContext.cwd
cwd
Definition
__init__.py:38
ers.PyContext.user_name
user_name
Definition
__init__.py:43
ers.PyContext.application_name
application_name
Definition
__init__.py:44
ers.PyContext.user_id
user_id
Definition
__init__.py:42
ers.PyContext.host_name
host_name
Definition
__init__.py:37
ers.PyContext.__file
__file
Definition
__init__.py:17
ers.PyIssue
Definition
__init__.py:47
ers.PyIssue.__init__
__init__(self, message, kwargs, cause)
Definition
__init__.py:51
ers.PyIssue.__parameters
__parameters
Definition
__init__.py:60
ers.PyIssue.context_parameters
context_parameters
Definition
__init__.py:58
ers.PyIssue.__context
__context
Definition
__init__.py:57
ers.PyIssue.isInstanceOf
isInstanceOf(self, cname)
Definition
__init__.py:77
ers.PyIssue.__str__
__str__(self)
Definition
__init__.py:80
ers.PyIssue.rc
rc
Definition
__init__.py:65
ers.PyIssue.ai
ai
Definition
__init__.py:67
ers.PyIssue.rpc
rpc
Definition
__init__.py:62
ers::RemoteContext
Definition
RemoteContext.hpp:61
ers.pywarning
pywarning(issue)
Definition
__init__.py:115
ers::warning
void warning(const Issue &issue)
Definition
ers.hpp:126
ers::info
void info(const Issue &issue)
Definition
ers.hpp:106
ers.pylog
pylog(msg)
Definition
__init__.py:102
ers::log
void log(const Issue &issue)
Definition
ers.hpp:113
ers.message
message(message)
Definition
__init__.py:84
ers.pydebug
pydebug(msg, lvl)
Definition
__init__.py:98
ers.pyfatal
pyfatal(issue)
Definition
__init__.py:127
ers::debug
void debug(const Issue &issue, int level=debug_level())
Definition
ers.hpp:85
ers.pyinfo
pyinfo(msg)
Definition
__init__.py:106
ers::fatal
void fatal(const Issue &issue)
Definition
ers.hpp:99
ers.pyerror
pyerror(issue)
Definition
__init__.py:121
ers::error
void error(const Issue &issue)
Definition
ers.hpp:92
ers::RemoteProcessContext
Definition
RemoteContext.hpp:34
Generated on
for DUNE-DAQ by
1.17.0