ATLAS Offline Software
Loading...
Searching...
No Matches
python.TrigRootUtils Namespace Reference

Functions

 lsroot (dir)
 check_file (path)
 check_file_subproc (path)

Variables

 log = logging.getLogger(__name__)

Function Documentation

◆ check_file()

python.TrigRootUtils.check_file ( path)

Definition at line 33 of file TrigRootUtils.py.

33def 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

◆ check_file_subproc()

python.TrigRootUtils.check_file_subproc ( path)

Definition at line 49 of file TrigRootUtils.py.

49def 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

◆ lsroot()

python.TrigRootUtils.lsroot ( dir)
Return list of all keys in 'dir' (recursively)

Definition at line 6 of file TrigRootUtils.py.

6def 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

Variable Documentation

◆ log

python.TrigRootUtils.log = logging.getLogger(__name__)

Definition at line 4 of file TrigRootUtils.py.