| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

genrepr.py

Go to the documentation of this file.
00001 """
00002     importing this module interposes customized methods for
00003         __repr__
00004         __str__
00005     into the below customized classes
00006     
00007     The below functions are interposed as __props__ methods into the 
00008     correspondingly named classes, that supply  a dict based structure 
00009     of the properties of the object 
00010     used by the __repr__
00011 
00012 """
00013 
00014 
00015 from DybPython.Util import irange, dress_classes
00016 
00017 
00018 import ROOT
00019 import PyCintex as pc
00020 
00021 #pc.loadDictionary("libBaseEventDict")
00022 pc.loadDictionary("libGenEventDict")
00023 #pc.loadDictionary("libSimEventDict")
00024 pc.loadDictionary("libHepMCRflx")
00025 pc.loadDictionary("libCLHEPRflx")
00026 
00027 def reload_():
00028     import sys
00029     reload(sys.modules[__name__])
00030 
00031 def _hdr(self):
00032     return { '_class':self.__class__.__name__ }
00033 
00034 
00035 def _IRegistry(self):
00036     assert self.__class__.__name__ == 'IRegistry'
00037     d = _hdr(self)
00038     d.update( name=self.name() , identifier=self.identifier() )
00039     return d
00040 
00041 
00042 def _vector__unsigned_long(self):
00043     assert self.__class__.__name__ ==  'vector<unsigned long>'
00044     d = _hdr(self)
00045     d.update( length=len(self) , items=[e for e in self])
00046     return d
00047 
00048 def _CLHEP__HepLorentzVector(self):
00049     assert self.__class__.__name__ == 'CLHEP::HepLorentzVector'
00050     d = _hdr(self)
00051     d.update( px=self.px() , py=self.py() , pz=self.pz() , e=self.e() )
00052     return d
00053 
00054 
00055 def _HepMC__GenVertex(self):
00056     assert self.__class__.__name__ == 'HepMC::GenVertex'
00057     d = _hdr(self) 
00058     d.update( position=_CLHEP__HepLorentzVector(self.position()) )
00059     return d
00060 
00061 
00062 def _HepMC__GenParticle(self):
00063     assert self.__class__.__name__ == 'HepMC::GenParticle'
00064     d = _hdr(self)
00065     d.update( 
00066               pdg_id=self.pdg_id() ,
00067             momentum=_CLHEP__HepLorentzVector(self.momentum()) ,
00068    production_vertex=_HepMC__GenVertex(self.production_vertex()) 
00069            )
00070     return d
00071 
00072 
00073 def _HepMC__GenEvent(self):
00074     assert self.__class__.__name__ == 'HepMC::GenEvent', "got %s " % self.__class__.__name__
00075     d = _hdr(self)
00076     d.update( event_number=self.event_number() )
00077     
00078     particles = []
00079     for prt in irange(self.particles_begin(),self.particles_end()):
00080         particles.append( _HepMC__GenParticle(prt) )
00081     d.update( particles=particles )
00082     
00083     vertices = []
00084     for vtx in irange(self.vertices_begin(),self.vertices_end()):
00085         vertices.append( _HepMC__GenVertex(vtx) )
00086     d.update( vertices=vertices )
00087     
00088     return d
00089 
00090 
00091 def _DayaBay__HepMCEvent(self):
00092 
00093     assert self.__class__.__name__ == 'DayaBay::HepMCEvent'
00094     d = _hdr(self)
00095     d.update( 
00096         generatorName=self.generatorName() , 
00097         event=_HepMC__GenEvent(self.event()) 
00098         )
00099     return d
00100 
00101 
00102 def _Context(self):
00103     assert self.__class__.__name__ == 'Context'
00104     d = _hdr(self)
00105     d.update(
00106          site=self.GetSite(),
00107          simFlag=self.GetSimFlag(),
00108          detId=self.GetDetId(),
00109          timeStamp=_TimeStamp(self.GetTimeStamp()), 
00110       )
00111     return d  
00112 
00113         
00114 def _DayaBay_GenHeader(self):
00115     """
00116         introspective method calling can be dangerous !!
00117         ... hitting the "release" method decrements the ref count causing the 
00118         count down to segmentation problem #49
00119               
00120               dybgaudi/InstallArea/include/Event/HepMCEvent.h
00121               gaudi/GaudiKernel/GaudiKernel/KeyedObject.h
00122     """
00123     assert self.__class__.__name__ == 'DayaBay::GenHeader'
00124     d = _hdr(self)
00125     
00126     skips = { 
00127                 'serialize':"too complex",
00128                'fillStream':"handeled in str ",
00129              'inputHeaders':"too complex",
00130                   'linkMgr':"too complex" , 
00131                   'release':"causes decrement of ref count ... countdown to segmentation error" ,
00132                  'earliest':"prevents consistency", 
00133                    'latest':"prevents consistency" ,
00134             }
00135                 
00136     times = [ 'earliest','latest','timeStamp' ]
00137     
00138     meths = [x for x in dir(self) if callable(getattr(self,x))]
00139     for meth in meths:
00140         if meth[0:3] not in ['add','set'] and meth not in skips and not meth[0].isupper() and not meth[0] == "_" :
00141             if meth == "event":
00142                 d[meth] = _HepMC__GenEvent( self.event() )
00143             elif meth == "randomState":
00144                 d[meth] = _vector__unsigned_long( self.randomState() )
00145             elif meth == "context":
00146                 d[meth] = _Context( self.context() )
00147             elif meth in times:
00148                 its = ROOT.TimeStamp()
00149                 its = getattr(self,meth)()
00150                 d[meth] = its.AsString()
00151                 del its
00152             else:
00153                 r = getattr(self , meth )()
00154                 d[meth]=repr(r) 
00155     return d
00156           
00157 def _TimeStamp(self):
00158     assert self.__class__.__name__ == 'TimeStamp'
00159     d = _hdr(self)
00160     d.update(
00161         asString=self.AsString() 
00162      )
00163     return d
00164                                     
00165         
00166 def _KeyedContainer_DayaBay__HepMCEvent(self):
00167     assert self.__class__.__name__ == 'KeyedContainer<DayaBay::HepMCEvent,Containers::KeyedObjectManager<Containers::hashmap> >'
00168     d = _hdr(self)
00169     d.update( clID=self.clID() , name=self.name() , len=len(self) )
00170     child = []
00171     for itm in self:
00172         assert itm.parent() == self
00173         child.append( _DayaBay__HepMCEvent(itm) )
00174     d.update( child=child )
00175     return d
00176 
00177 
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 dress_classes( 
00186    {
00187      # 'DayaBay::HepMCEvent':_DayaBay__HepMCEvent,
00188          'HepMC::GenEvent':_HepMC__GenEvent,
00189      'vector<unsigned long>':_vector__unsigned_long,
00190       'HepMC::GenParticle':_HepMC__GenParticle,
00191         'HepMC::GenVertex':_HepMC__GenVertex,
00192  'CLHEP::HepLorentzVector':_CLHEP__HepLorentzVector,
00193      #'KeyedContainer<DayaBay::HepMCEvent,Containers::KeyedObjectManager<Containers::hashmap> >': _KeyedContainer_DayaBay__HepMCEvent,
00194         'DayaBay::GenHeader':_DayaBay_GenHeader ,
00195         'IRegistry':_IRegistry,
00196    }
00197 )
00198 
00199 
00200 
00201 
00202 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:13:00 2011 for DybPython by doxygen 1.4.7