14 return id(self)==
id(other)
16 return id(self)!=
id(other)
20 if hasattr(container,
'GetEntries'):
22 entries = container.GetEntries()
23 for entry
in xrange(entries):
26 raise cmserror(
"Looping of %s failed" %container)
28 elif hasattr(container,
'size'):
30 if hasattr(container,
'ids'):
31 container = container.ids()
33 entries = container.size()
34 for entry
in xrange(entries):
35 yield container[entry]
53 logging.debug(__name__ +
": __init__")
77 if not id(object)
in self._edmChildrenObjects.keys():
79 if levels>1
and id(object)
in self._edmChildren.keys():
81 if not self.
isRead(child, levels-1):
86 """ Get children of an object """ 87 if id(object)
in self._edmChildren.keys()
and self.
isRead(object):
93 """ Get children of an object """ 94 if id(object)
in self._edmChildren.keys()
and self.
isRead(object):
100 """ Get motherRelations of an object """ 101 if id(object)
in self._edmMotherRelations.keys():
107 """ Get daughterRelations of an object """ 108 if id(object)
in self._edmDaughterRelations.keys():
117 if id(object)
in self._edmLabel.keys():
119 return splitlabel[len(splitlabel)-1]
128 return ".".
join(splitlabel[1:-1])
131 typ=
str(object.__class__)
133 typ=typ.split(
"\'")[1]
135 typ=typ.split(
".")[len(typ.split(
"."))-1]
136 return typ.strip(
" ")
144 while id(entry)
in self._edmParent.keys()
and self.
_edmParent[
id(entry)]!=
None:
151 while id(entry)
in self._edmParent.keys()
and self.
_edmParent[
id(entry)]!=
None:
157 """ get all method properties of an object """ 159 for attr
in dir(object):
160 prop=getattr(object,attr)
161 if not attr.startswith(
"__")
and (self.
_underscore or attr.strip(
"_")==attr):
162 objects+=[(attr,prop)]
166 """ get object and resolve references """ 168 ref_types=[
"edm::Ref",
"edm::RefProd",
"edm::RefToBase",
"edm::RefToBaseProd",
"edm::Ptr"]
171 if typshort
in ref_types:
173 if hasattr(object,
"isNull")
and object.isNull():
174 value=
"ERROR: "+self.
getType(object)+
" object is null" 175 elif hasattr(object,
"isAvailable")
and not object.isAvailable():
176 value=
"ERROR: "+self.
getType(object)+
" object is not available" 179 if type(value)==type(
None):
180 value=
"ERROR: Could not get "+self.
getType(object)
183 except Exception
as message:
184 value=
"ERROR: "+
str(message)
188 """ get string value of a method """ 189 if not callable(object):
193 if not object.__doc__
or str(object.__doc__)==
"":
194 return "ERROR: Empty __doc__ string" 195 docs=
str(object.__doc__).
split(
"\n")
198 for p
in doc[doc.find(
"(")+1:doc.find(
")")].
split(
","):
199 if p!=
"" and not "=" in p:
201 if len(parameters)!=0:
203 typestring=doc[:doc.find(
"(")]
204 split_typestring=typestring.split(
" ")
207 for i
in reversed(range(len(split_typestring))):
208 templates+=split_typestring[i].
count(
"<")
209 templates-=split_typestring[i].
count(
">")
213 typ=
" ".
join(split_typestring[:end_typestring])
214 hidden_types=[
"iterator",
"Iterator"]
215 root_types=[
"ROOT::"]
216 if typ==
"" or "void" in typ
or True in [t
in typ
for t
in hidden_types]:
218 from ROOT
import TClass
219 if True in [t
in typ
for t
in root_types]
and TClass.GetClass(typ)==
None:
220 return "ERROR: Cannot display object of type "+typ
224 except Exception
as message:
225 value=
"ERROR: "+
str(message)
226 if "Buffer" in str(type(value)):
227 return "ERROR: Cannot display object of type "+typ
233 return typ==
"list" or typ[-6:].lower()==
"vector" or typ[-3:].lower()==
"map" or typ[-10:].lower()==
"collection" or hasattr(object,
"size")
237 if hasattr(a,
"px")
and hasattr(a,
"py")
and hasattr(a,
"pz")
and hasattr(a,
"energy")
and \
238 hasattr(b,
"px")
and hasattr(b,
"py")
and hasattr(b,
"pz")
and hasattr(b,
"energy"):
239 same=a.px()==b.px()
and a.py()==b.py()
and a.pz()==b.pz()
and a.energy()==b.energy()
243 """ get list of daughter objects from properties """ 247 hidden_attr=[
"front",
"back",
"IsA",
"clone",
"masterClone",
"masterClonePtr",
"mother",
"motherRef",
"motherPtr",
"daughter",
"daughterRef",
"daughterPtr",
"is_back_safe"]
250 if attr1
in hidden_attr:
252 elif attr1
in broken_attr:
253 objectdict[attr1]=(
"ERROR: Cannot read property",
False)
257 objectdict[attr1]=(value,ref)
258 for name
in sorted(objectdict.keys()):
259 objects+=[(name,objectdict[name][0],objectdict[name][1],self.
_propertyType(objectdict[name][0]))]
263 for o
in all(object):
268 elif "GenParticle" in str(value):
269 name=defaultParticleDataList.getNameFromId(value.pdgId())
272 objects+=[(name,value,ref,typ)]
275 for name,mother,ref,propertyType
in objects:
276 if hasattr(mother,
"numberOfDaughters")
and hasattr(mother,
"daughter"):
278 for n
in range(mother.numberOfDaughters()):
279 daughter=mother.daughter(n)
281 for na,da,re,st
in objects:
285 if not id(mother)
in self._edmDaughterRelations.keys():
288 if not id(daughter)
in self._edmMotherRelations.keys():
291 except Exception
as message:
292 logging.error(
"Cannot read candidate relations: "+
str(message))
296 if type(value)
in (bool,):
298 elif type(value)
in (int, long):
300 elif type(value)
in (float,):
302 elif type(value)
in (complex,str,unicode):
308 """ Make list of all properties """ 309 logging.debug(__name__ +
": properties: "+self.
label(object))
313 objectproperties_sorted=[]
314 if id(object)
in self._edmChildrenObjects.keys():
316 if propertyType!=
None:
317 objectproperties[name]=(value,propertyType)
318 objectproperties_sorted+=[name]
320 properties+=[(
"Category",
"Object info",
"")]
322 properties+=[(
"String",
"label",shortlabel)]
323 properties+=[(
"String",
"type",self.
getType(object))]
326 properties+=[(
"String",
"object",objectlabel)]
328 if shortlabel.strip(
".")!=branchlabel.strip(
"."):
329 properties+=[(
"String",
"branch",branchlabel)]
331 properties+=[(
"Category",
"Branch info",
"")]
332 properties+=[(
"String",
"Type",branchlabel.split(
"_")[0])]
333 properties+=[(
"String",
"Label",branchlabel.split(
"_")[1])]
334 properties+=[(
"String",
"Product",branchlabel.split(
"_")[2])]
335 properties+=[(
"String",
"Process",branchlabel.split(
"_")[3])]
337 for property
in [
"pdgId",
"charge",
"status"]:
338 if property
in objectproperties.keys():
339 properties+=[(objectproperties[property][1],property,objectproperties[property][0])]
340 del objectproperties[property]
342 if "px" in objectproperties.keys():
343 properties+=[(
"Category",
"Vector",
"")]
344 for property
in [
"energy",
"px",
"py",
"pz",
"mass",
"pt",
"eta",
"phi",
"p",
"theta",
"y",
"rapidity",
"et",
"mt",
"mtSqr",
"massSqr"]:
345 if property
in objectproperties.keys():
346 properties+=[(objectproperties[property][1],property,objectproperties[property][0])]
347 del objectproperties[property]
349 if "x" in objectproperties.keys():
350 properties+=[(
"Category",
"Vector",
"")]
351 for property
in [
"x",
"y",
"z"]:
352 if property
in objectproperties.keys():
353 properties+=[(objectproperties[property][1],property,objectproperties[property][0])]
354 del objectproperties[property]
356 if False in [
str(value[0]).startswith(
"ERROR")
for value
in objectproperties.values()]:
357 properties+=[(
"Category",
"Values",
"")]
358 for property
in objectproperties_sorted:
359 if property
in objectproperties.keys():
360 if not str(objectproperties[property][0]).startswith(
"ERROR"):
361 properties+=[(objectproperties[property][1],property,objectproperties[property][0])]
362 del objectproperties[property]
364 if len(objectproperties.keys())>0:
365 properties+=[(
"Category",
"Errors",
"")]
366 for property
in objectproperties_sorted:
367 if property
in objectproperties.keys():
368 properties+=[(objectproperties[property][1],property,objectproperties[property][0])]
370 return tuple(properties)
373 """ read edm objects recursive """ 374 logging.debug(__name__ +
": readObjectsRecursive (levels="+
str(levels)+
"): "+label)
376 if not id(edmobject)
in self._edmLabel.keys():
377 if not isinstance(edmobject,(int,float,long,complex,str,unicode,bool)):
380 type(edmobject).__eq__=eq
381 type(edmobject).__ne__=ne
387 if not id(mother)
in self._edmChildren.keys():
392 return [edmobject],
True 398 """ read daughter objects of an edmobject """ 399 logging.debug(__name__ +
": readDaughtersRecursive (levels="+
str(levels)+
"): "+
str(edmobject))
401 if not id(edmobject)
in self._edmChildrenObjects.keys():
407 for name,daughter,ref,propertyType
in daughters:
409 if propertyType==
None:
414 if id(edmobject)
in self._edmLabel.keys()
and self.
_edmLabel[
id(edmobject)]!=
"":
420 logging.warning(
"Did not read all daughter objects. Maximum is set to "+
str(self.
maxDaughters)+
".")
424 def read(self,object,levels=1):
425 """ reads contents of a branch """ 426 logging.debug(__name__ +
": read")
427 if isinstance(object,BranchDummy):
428 if hasattr(object,
"product"):
429 return object.product
433 self._events.getByLabel(object.branchtuple[2],object.branchtuple[3],object.branchtuple[4],object.branchtuple[1])
434 if object.branchtuple[1].isValid():
435 product=object.branchtuple[1].product()
436 if not isinstance(product,(int,float,long,complex,str,unicode,bool)):
439 type(product).__eq__=eq
440 type(product).__ne__=ne
443 self._dataObjects.insert(self._dataObjects.index(object),product)
444 self._dataObjects.remove(object)
446 object.product=product
450 logging.info(
"Branch is not valid: "+object.branchtuple[0]+
".")
453 except Exception
as e:
455 object.unreadable=
True 456 logging.warning(
"Unable to read branch "+object.branchtuple[0]+
" : "+
exception_traceback())
458 if self.
isRead(object,levels):
465 """ Goto event number index in file. 498 """ Open edm file and show first event """ 501 if os.path.splitext(filename)[1].lower()==
".txt":
502 file =
open(filename)
503 for line
in file.readlines():
505 linecontent=[l.strip(
" \n").rstrip(
".")
for l
in line.split(
"\"")]
506 self.
_branches+=[(linecontent[0]+
"_"+linecontent[1]+
"_"+linecontent[3]+
"_"+linecontent[5],
None,linecontent[1],linecontent[3],linecontent[5])]
508 linecontent=line.strip(
"\n").
split(
" ")[0].
split(
"_")
509 if len(linecontent)>3:
510 self.
_branches+=[(linecontent[0]+
"_"+linecontent[1]+
"_"+linecontent[2]+
"_"+linecontent[3],
None,linecontent[1],linecontent[2],linecontent[3])]
511 elif os.path.splitext(filename)[1].lower()==
".root":
512 from DataFormats.FWLite
import Events, Handle
515 branches=self._events.object().getBranchDescriptions()
516 for branch
in branches:
518 branchname=branch.friendlyClassName()+
"_"+branch.moduleLabel()+
"_"+branch.productInstanceName()+
"_"+branch.processName()
519 handle=
Handle(branch.fullClassName())
520 self.
_branches+=[(branchname,handle,branch.moduleLabel(),branch.productInstanceName(),branch.processName())]
521 except Exception
as e:
522 logging.warning(
"Cannot read branch "+branchname+
":"+
str(e))
523 self._branches.sort(
lambda x, y: cmp(x[0], y[0]))
528 charge=self.
property(object,
"pdgId")
537 return defaultParticleDataList.isQuarkId(particleId)
543 return defaultParticleDataList.isLeptonId(particleId)
549 return defaultParticleDataList.isGluonId(particleId)
555 return defaultParticleDataList.isBosonId(particleId)
561 if not hasattr(defaultParticleDataList,
"isPhotonId"):
563 return defaultParticleDataList.isPhotonId(particleId)
569 if not hasattr(defaultParticleDataList,
"isHiggsId"):
571 return defaultParticleDataList.isHiggsId(particleId)
575 if hasattr(defaultParticleDataList,
"isPhotonId")
and defaultParticleDataList.isPhotonId(particleId):
576 return self.LINE_STYLE_WAVE
577 elif defaultParticleDataList.isGluonId(particleId):
578 return self.LINE_STYLE_SPIRAL
579 elif defaultParticleDataList.isBosonId(particleId):
580 return self.LINE_STYLE_DASH
581 return self.LINE_STYLE_SOLID
585 if defaultParticleDataList.isLeptonId(particleId):
586 return QColor(244, 164, 96)
587 elif defaultParticleDataList.isQuarkId(particleId):
588 return QColor(0, 100, 0)
589 elif hasattr(defaultParticleDataList,
"isHiggsId")
and defaultParticleDataList.isHiggsId(particleId):
590 return QColor(247, 77, 251)
591 elif defaultParticleDataList.isBosonId(particleId):
592 return QColor(253, 74, 74)
593 return QColor(176, 179, 177)
596 charge=self.
property(object,
"charge")
608 return self._underscore
622 result=self.
read(branch,0)
623 if isinstance(result,BranchDummy):
624 self._dataObjects.remove(result)
625 if hasattr(result,
"invalid"):
626 self._filteredBranches.remove(result.branchtuple)
def daughterRelations(self, object)
def getShortType(self, object)
def getObjectRef(self, object)
def properties(self, object)
def isBoson(self, object)
def getDaughterObjects(self, object)
def isPhoton(self, object)
def getShortLabel(self, object)
def children(self, object)
def isRead(self, object, levels=1)
def isContainer(self, object)
def getObjectProperties(self, object)
def underscoreProperties(self)
def exception_traceback()
def readObjectsRecursive(self, mother, label, edmobject, levels=1)
def getObjectContent(self, object)
def isVectorObject(self, object)
def lineStyle(self, object)
def linkDaughter(self, object, daughter)
def setFilterBranches(self, check)
def topLevelObjects(self)
def getObjectLabel(self, object)
def isGluon(self, object)
def __init__(self, branchtuple)
def readDaughtersRecursive(self, edmobject, objects, levels=1)
def getDepth(self, object)
def linkMother(self, object, mother)
def getType(self, object)
def getBranch(self, object)
def open(self, filename=None)
def property(self, object, name)
def isHiggs(self, object)
def particleId(self, object)
def compareObjects(self, a, b)
static std::string join(char **cmd)
def setUnderscoreProperties(self, check)
def getShortLabelWithType(self, object)
def isQuark(self, object)
def motherRelations(self, object)
def _propertyType(self, value)
def read(self, object, levels=1)
def isLepton(self, object)
def filteredBranches(self)