test
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 22 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 35 of file chain.py.

35 
36  def __init__(self, input, tree_name=None):
37  """
38  Create a chain.
39 
40  Parameters:
41  input = either a list of files or a wildcard (e.g. 'subdir/*.root').
42  In the latter case all files matching the pattern will be used
43  to build the chain.
44  tree_name = key of the tree in each file.
45  if None and if each file contains only one TTree,
46  this TTree is used.
47  """
48  self.files = input
49  if isinstance(input, basestring): # input is a pattern
50  self.files = glob.glob(input)
51  if len(self.files)==0:
52  raise ValueError('no matching file name: '+input)
53  else: # case of a list of files
54  if False in [
55  ((is_pfn(fnam) and os.path.isfile(fnam)) or
56  is_lfn(fnam)) or is_rootfn(fnam)
57  for fnam in self.files]:
58  err = 'at least one input file does not exist\n'
59  err += pprint.pformat(self.files)
60  raise ValueError(err)
61  if tree_name is None:
62  tree_name = self._guessTreeName(input)
63  self.chain = TChain(tree_name)
64  for file in self.files:
65  self.chain.Add(file)
def is_pfn
Definition: chain.py:9
def is_lfn
Definition: chain.py:12
def _guessTreeName
Definition: chain.py:66
def __init__
Definition: chain.py:35
def is_rootfn
Definition: chain.py:15

Member Function Documentation

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

Definition at line 92 of file chain.py.

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

92 
93  def __getattr__(self, attr):
94  """
95  All functions of the wrapped TChain are made available
96  """
97  return getattr(self.chain, attr)
def __getattr__
Definition: chain.py:92
def chain.Chain.__getitem__ (   self,
  index 
)
Returns the event at position index.

Definition at line 104 of file chain.py.

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

105  def __getitem__(self, index):
106  """
107  Returns the event at position index.
108  """
109  self.chain.GetEntry(index)
110  return self.chain
111 
112 
def __getitem__
Definition: chain.py:104
def chain.Chain.__iter__ (   self)

Definition at line 98 of file chain.py.

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

98 
99  def __iter__(self):
100  return iter(self.chain)
def __iter__
Definition: chain.py:98
def chain.Chain.__len__ (   self)

Definition at line 101 of file chain.py.

102  def __len__(self):
103  return int(self.chain.GetEntries())
def __len__
Definition: chain.py:101
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 66 of file chain.py.

References readConfig.fileINI.files, chain.Chain.files, MatrixReader.MatrixReader.files, MatrixUtil.InputInfo.files, geometryComparison.GeometryComparison.files, JsonOutputProducer::JsonConfigurationBlock.files, join(), and list().

66 
67  def _guessTreeName(self, pattern):
68  """
69  Find the set of keys of all TTrees in all files matching pattern.
70  If the set contains only one key
71  Returns: the TTree key
72  else raises ValueError.
73  """
74  names = []
75  for fnam in self.files:
76  rfile = TFile(fnam)
77  for key in rfile.GetListOfKeys():
78  obj = rfile.Get(key.GetName())
79  if type(obj) is TTree:
80  names.append( key.GetName() )
81  thename = set(names)
82  if len(thename)==1:
83  return list(thename)[0]
84  else:
85  err = [
86  'several TTree keys in {pattern}:'.format(
87  pattern=pattern
88  ),
89  ','.join(thename)
90  ]
91  raise ValueError('\n'.join(err))
def _guessTreeName
Definition: chain.py:66
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 62 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 47 of file chain.py.

Referenced by chain.Chain._guessTreeName(), dataset.BaseDataset.listOfFiles(), dataset.BaseDataset.listOfGoodFiles(), and dataset.BaseDataset.printFiles().