CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Member Functions
chain.Chain Class Reference
Inheritance diagram for chain.Chain:

Public Member Functions

def __getattr__
 
def __getitem__
 
def __init__
 
def __iter__
 
def __len__
 

Public Attributes

 chain
 
 files
 

Private Member Functions

def _guessTreeName
 

Detailed Description

Wrapper to TChain, with a python iterable interface.

Example of use:  #TODO make that a doctest / nose?
   from chain import Chain
   the_chain = Chain('../test/test_*.root', 'test_tree')
   event3 = the_chain[2]
   print event3.var1

   for event in the_chain:
       print event.var1

Definition at line 9 of file chain.py.

Constructor & Destructor Documentation

def chain.Chain.__init__ (   self,
  input,
  tree_name = None 
)
Create a chain.

Parameters:
  input     = either a list of files or a wildcard (e.g. 'subdir/*.root').
      In the latter case all files matching the pattern will be used
      to build the chain.
  tree_name = key of the tree in each file.
      if None and if each file contains only one TTree,
      this TTree is used.

Definition at line 22 of file chain.py.

22 
23  def __init__(self, input, tree_name=None):
24  """
25  Create a chain.
26 
27  Parameters:
28  input = either a list of files or a wildcard (e.g. 'subdir/*.root').
29  In the latter case all files matching the pattern will be used
30  to build the chain.
31  tree_name = key of the tree in each file.
32  if None and if each file contains only one TTree,
33  this TTree is used.
34  """
35  self.files = input
36  if isinstance(input, basestring): # input is a pattern
37  self.files = glob.glob(input)
38  if len(self.files)==0:
39  raise ValueError('no matching file name: '+input)
40  else: # case of a list of files
41  if False in [ os.path.isfile(fnam) for fnam in self.files ]:
42  err = 'at least one input file does not exist\n'
43  err += pprint.pformat(self.files)
44  raise ValueError(err)
45  if tree_name is None:
46  tree_name = self._guessTreeName(input)
47  self.chain = TChain(tree_name)
48  for file in self.files:
49  self.chain.Add(file)
def _guessTreeName
Definition: chain.py:50
def __init__
Definition: chain.py:22

Member Function Documentation

def chain.Chain.__getattr__ (   self,
  attr 
)
All functions of the wrapped TChain are made available

Definition at line 76 of file chain.py.

References edm::FileLocator::Rule.chain, and chain.Chain.chain.

76 
77  def __getattr__(self, attr):
78  """
79  All functions of the wrapped TChain are made available
80  """
81  return getattr(self.chain, attr)
def __getattr__
Definition: chain.py:76
def chain.Chain.__getitem__ (   self,
  index 
)
Returns the event at position index.

Definition at line 88 of file chain.py.

References edm::FileLocator::Rule.chain, and chain.Chain.chain.

88 
89  def __getitem__(self, index):
90  """
91  Returns the event at position index.
92  """
93  self.chain.GetEntry(index)
94  return self.chain
95 
def __getitem__
Definition: chain.py:88
def chain.Chain.__iter__ (   self)

Definition at line 82 of file chain.py.

References edm::FileLocator::Rule.chain, chain.Chain.chain, and getDQMSummary.iter.

82 
83  def __iter__(self):
84  return iter(self.chain)
def __iter__
Definition: chain.py:82
def chain.Chain.__len__ (   self)

Definition at line 85 of file chain.py.

85 
86  def __len__(self):
87  return int(self.chain.GetEntries())
def __len__
Definition: chain.py:85
def chain.Chain._guessTreeName (   self,
  pattern 
)
private
Find the set of keys of all TTrees in all files matching pattern.
If the set contains only one key
  Returns: the TTree key
else raises ValueError.

Definition at line 50 of file chain.py.

References readConfig.fileINI.files, chain.Chain.files, relval_steps.InputInfo.files, MatrixReader.MatrixReader.files, join(), and list().

50 
51  def _guessTreeName(self, pattern):
52  """
53  Find the set of keys of all TTrees in all files matching pattern.
54  If the set contains only one key
55  Returns: the TTree key
56  else raises ValueError.
57  """
58  names = []
59  for fnam in self.files:
60  rfile = TFile(fnam)
61  for key in rfile.GetListOfKeys():
62  obj = rfile.Get(key.GetName())
63  if type(obj) is TTree:
64  names.append( key.GetName() )
65  thename = set(names)
66  if len(thename)==1:
67  return list(thename)[0]
68  else:
69  err = [
70  'several TTree keys in {pattern}:'.format(
71  pattern=pattern
72  ),
73  ','.join(thename)
74  ]
75  raise ValueError('\n'.join(err))
def _guessTreeName
Definition: chain.py:50
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run

Member Data Documentation

chain.Chain.chain

Definition at line 46 of file chain.py.

Referenced by chain.Chain.__getattr__(), chain.Chain.__getitem__(), chain.Chain.__iter__(), chain_test.ChainTestCase.test_get(), chain_test.ChainTestCase.test_guess_treename(), chain_test.ChainTestCase.test_iterate(), and chain_test.ChainTestCase.test_load_1().

chain.Chain.files

Definition at line 34 of file chain.py.

Referenced by chain.Chain._guessTreeName().