7 from ROOT
import TChain, TFile, TTree, gSystem
13 return fn.startswith(
"/store")
17 To open files like root://, file:// which os.isfile won't find. 23 """Wrapper to TChain, with a python iterable interface. 25 Example of use: #TODO make that a doctest / nose? 26 from chain import Chain 27 the_chain = Chain('../test/test_*.root', 'test_tree') 31 for event in the_chain: 40 input = either a list of files or a wildcard (e.g. 'subdir/*.root'). 41 In the latter case all files matching the pattern will be used 43 tree_name = key of the tree in each file. 44 if None and if each file contains only one TTree, 48 if isinstance(input, str):
49 self.
files = glob.glob(input)
50 if len(self.
files)==0:
51 raise ValueError(
'no matching file name: '+input)
54 ((
is_pfn(fnam)
and os.path.isfile(fnam))
or 56 for fnam
in self.
files]:
57 err =
'at least one input file does not exist\n' 58 err += pprint.pformat(self.
files)
63 for file
in self.
files:
68 Find the set of keys of all TTrees in all files matching pattern. 69 If the set contains only one key 70 Returns: the TTree key 71 else raises ValueError. 74 for fnam
in self.
files:
76 for key
in rfile.GetListOfKeys():
77 obj = rfile.Get(key.GetName())
78 if isinstance(obj, TTree):
79 names.append( key.GetName() )
82 return list(thename)[0]
85 'several TTree keys in {pattern}:'.
format(
90 raise ValueError(
'\n'.
join(err))
94 All functions of the wrapped TChain are made available 96 return getattr(self.
chain, attr)
99 return iter(self.
chain)
106 Returns the event at position index. 108 self.
chain.GetEntry(index)
def __getattr__(self, attr)
def __getitem__(self, index)
def __init__(self, input, tree_name=None)
static std::string join(char **cmd)
def _guessTreeName(self, pattern)