GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
util.py
Go to the documentation of this file.
1#!/usr/bin/env python2
2
3import re
4
5import ROOT
6ROOT.PyConfig.IgnoreCommandLineOptions = True
7
9 if tdir.GetListOfKeys():
10 for key in tdir.GetListOfKeys():
11 yield key.ReadObj()
12 else:
13 for obj in tdir.GetList():
14 yield obj
15
16def update_tcanvases(objects=None):
17 if objects is None:
18 objects = ROOT.gROOT.GetListOfCanvases()
19
20 for obj in objects:
21 if isinstance(obj, ROOT.TPad):
22 obj.Modified()
23 obj.Update()
24 update_tcanvases(obj.GetListOfPrimitives())
25
26
28 res = re.search('[0-9]+$', name)
29 if res:
30 prefix = name[:-len(res.group())]
31 number = int(res.group()) + 1
32 return prefix + str(number)
33 else:
34 return name + '_1'
35
36
37class PreserveGDir(object):
38
39 def __init__(self, directory = None):
40 self.directory = directory
41
42 def __enter__(self):
43 self.gdir = ROOT.gDirectory
44 if self.directory is not None:
45 self.directory.cd()
46 return self
47
48 def __exit__(self, exc_type, exc_val, exc_tb):
49 self.gdir.cd()
50
51
52class TKeyDict(dict):
53 def __getitem__(self, key):
54 output = super(TKeyDict,self).__getitem__(key)
55 if isinstance(output, ROOT.TKey):
56 output = output.ReadObj()
57 if (isinstance(output, ROOT.TH2) and
58 not isinstance(output, ROOT.GH2Base)):
59 output = ROOT.GH2D(output)
60 self[key] = output
61
62 return output
63
64 def is_tkey(self, key):
65 output = super(TKeyDict,self).__getitem__(key)
66 try:
67 return isinstance(output, ROOT.TKey)
68 except AttributeError:
69 return False
__init__(self, directory=None)
Definition util.py:39
__exit__(self, exc_type, exc_val, exc_tb)
Definition util.py:48
__getitem__(self, key)
Definition util.py:53
is_tkey(self, key)
Definition util.py:64
update_tcanvases(objects=None)
Definition util.py:16
increment_name(name)
Definition util.py:27
unpack_tdirectory(tdir)
Definition util.py:8