Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:15:49

0001 import collections
0002 from ROOT import TChain
0003 
0004 class Event(object):
0005     '''Event class.
0006 
0007     The Looper passes the Event object to each of its Analyzers,
0008     which in turn can:
0009     - read some information
0010     - add more information
0011     - modify existing information.
0012 
0013     Attributes:
0014       iEv = event processing index, starting at 0
0015       eventWeight = a weight, set to 1 at the beginning of the processing
0016       input = input, as determined by the looper
0017     #TODO: provide a clear interface for access control (put, get, del products) - we should keep track of the name and id of the analyzer.
0018     '''
0019 
0020     def __init__(self, iEv, input_data=None, setup=None, eventWeight=1 ):
0021         self.iEv = iEv
0022         self.input = input_data
0023         self.setup = setup
0024         self.eventWeight = eventWeight
0025 
0026     def __str__(self):
0027         header = '{type}: {iEv}'.format( type=self.__class__.__name__,
0028                                          iEv = self.iEv)
0029         varlines = []
0030         for var,value in sorted(vars(self.items())):
0031             tmp = value
0032             # check for recursivity
0033             recursive = False
0034             if hasattr(value, '__getitem__') and \
0035                not isinstance(value, collections.Mapping) and \
0036                (len(value)>0 and value[0].__class__ == value.__class__):
0037                     recursive = True
0038             if hasattr(value, '__contains__') and \
0039                    not isinstance(value, (str,unicode)) and \
0040                    not isinstance(value, TChain) and \
0041                    not recursive :
0042                 tmp = map(str, value)
0043 
0044             varlines.append( '\t{var:<15}:   {value}'.format(var=var, value=tmp) )
0045         all = [ header ]
0046         all.extend(varlines)
0047         return '\n'.join( all )