ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigValidation
TrigValTools
python
TrigRootUtils.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2
3
import
logging
4
log = logging.getLogger(__name__)
5
6
def
lsroot
(dir):
7
"""Return list of all keys in 'dir' (recursively)"""
8
9
import
ROOT
10
11
def
dols(dir, keys):
12
"""Do the recursive traversal"""
13
dirList = dir.GetListOfKeys()
14
for
k
in
dirList:
15
kname = k.GetName()
16
if
k.GetClassName()==
"TDirectoryFile"
or
k.GetClassName()==
"TDirectory"
:
17
dir.cd(kname)
18
dols(ROOT.gDirectory, keys)
19
else
:
20
keys += [dir.GetPath()+
"/"
+kname]
21
22
dir.cd(
".."
)
23
return
24
25
keys = []
26
basedir = dir.GetPath().rstrip(
"/"
) +
"/"
27
dols(dir,keys)
28
29
# Return sorted list with base directory removed
30
return
sorted([k.replace(basedir,
""
)
for
k
in
keys])
31
32
33
def
check_file
(path):
34
import
ROOT
35
log.info(
'Checking file {}'
.format(path))
36
rfile = ROOT.TFile.Open(path,
"READ"
)
37
if
not
rfile:
38
log.error(
'ERROR: {}: Failed to open file'
.format(path))
39
return
1
40
if
rfile.IsZombie():
41
log.error(
'ERROR: {}: Zombie'
.format(path))
42
return
1
43
if
rfile.TestBit(ROOT.TFile.kRecovered):
44
log.error(
'ERROR: {}: Recovered'
.format(path))
45
return
1
46
rfile.Close()
47
return
0
48
49
def
check_file_subproc
(path):
50
# Open Root file in a clean subprocess and parse error messages
51
from
subprocess
import
Popen, PIPE
52
import
time
53
time.sleep(5)
54
# Need to check the file in a clean environment, such that the classes in memory don't hide problems with classes in the file
55
p = Popen([
'python'
,
"-c"
,
"from TrigValTools.TrigRootUtils import check_file; check_file('{}')"
.format(path)], stdout=PIPE, stderr=PIPE)
56
# Wait till finished
57
stdout, stderr = p.communicate()
58
rc = p.returncode
59
time.sleep(5)
60
# Detect error messages printed by ROOT when the file is opened
61
if
"error"
in
stdout.decode(
'utf-8'
).lower()
or
"error"
in
stderr.decode(
'utf-8'
).lower():
62
rc = 1
63
log.error(
'ERROR: Detected errors when opening root file'
)
64
65
log.error(stdout.decode(
'utf-8'
))
66
log.error(stderr.decode(
'utf-8'
))
67
return
rc
python.TrigRootUtils.check_file
check_file(path)
Definition
TrigRootUtils.py:33
python.TrigRootUtils.lsroot
lsroot(dir)
Definition
TrigRootUtils.py:6
python.TrigRootUtils.check_file_subproc
check_file_subproc(path)
Definition
TrigRootUtils.py:49
Generated on
for ATLAS Offline Software by
1.17.0