ATLAS Offline Software
Loading...
Searching...
No Matches
Control
AthenaConfiguration
python
DebuggingContext.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2
3
4
# set of utilities allowing to get a better context information when issues with CA occur
5
class
Context
(
object
):
6
"""
7
Keeps the context info as a stack
8
Usage:
9
context = Context("context string") # this is it
10
"""
11
hint=
"Unknown context (enable it with ComponentAccumulator.debugMode = \"trackCA trackEventAlgo etc. see ComponentAccumulator documentation\")"
12
__context = []
13
14
def
__init__
(self, c):
15
Context.__context.append(c)
16
17
def
__del__
(self):
18
Context.__context.pop()
19
20
@classmethod
21
def
current
(cls):
22
return
Context.__context[-1]
23
24
@classmethod
25
def
complete
(cls):
26
return
Context.hint
if
not
Context.__context
else
"\n"
.join(Context.__context)
27
28
29
def
shortCallStack
():
30
"""
31
Obtains (a very abbreviated) context of the current call stack (from the top, excluding the code using this function)
32
"""
33
import
inspect
34
compact =
' >>> '
35
for
frameInfo
in
inspect.stack()[2:][::-1]:
36
compact +=
"{}:{}({}) "
.format(frameInfo.filename.split(
'/'
)[-1], frameInfo.frame.f_lineno, frameInfo.function)
37
return
compact
38
39
40
def
createContextForDeduplication
(message, compName, destContext):
41
return
Context
(f
"{message} : {compName} : {destContext.get(compName, Context.hint)}"
)
42
43
44
def
raiseWithCurrentContext
(exception):
45
"""
46
Raises the exception with the message supplemented with context information
47
"""
48
raise
type
(exception)(str(exception) +
'\nWith the context:\n{}'
.format(Context.complete()) )
python.DebuggingContext.Context
Definition
DebuggingContext.py:5
python.DebuggingContext.Context.__init__
__init__(self, c)
Definition
DebuggingContext.py:14
python.DebuggingContext.Context.complete
complete(cls)
Definition
DebuggingContext.py:25
python.DebuggingContext.Context.current
current(cls)
Definition
DebuggingContext.py:21
python.DebuggingContext.Context.__del__
__del__(self)
Definition
DebuggingContext.py:17
python.DebuggingContext.raiseWithCurrentContext
raiseWithCurrentContext(exception)
Definition
DebuggingContext.py:44
python.DebuggingContext.shortCallStack
shortCallStack()
Definition
DebuggingContext.py:29
python.DebuggingContext.createContextForDeduplication
createContextForDeduplication(message, compName, destContext)
Definition
DebuggingContext.py:40
type
object
Generated on
for ATLAS Offline Software by
1.14.0