CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/PhysicsTools/PythonAnalysis/python/diffProv.py

Go to the documentation of this file.
00001 
00002 class difference :
00003     
00004     def __init__(self,v):
00005         self.verbose = v
00006         self._diffprocess=[]
00007         self._sameprocess=()
00008     def list_diff(self,aList1, aList2, string1, string2):
00009         "Searches for differences between two modules of the same kind"
00010         differences=[]
00011         for i in range(2,len(aList1)):
00012             for j in range(2,len(aList2)):
00013                 if (i==j) and (aList1[i]!=aList2[j]):
00014                     if aList1[i][:(aList1[i].index('=')+1)] == aList2[j][:(aList2[j].index('=')+1)]:
00015                         if self.verbose==str(2) or self.verbose==str(1):
00016                             str1 = aList1[i][2:aList1[i].index('=')+1] + aList1[i][aList1[i].index('=')+1:]+'  ['+ string1+']'
00017                             str2 = len(aList1[i][2:aList1[i].index('=')+1])*' '+aList2[j][aList2[j].index('=')+1:]+'  ['+string2+']'
00018                             print str1,'\n',str2,'\n'
00019                             differences.append(str1)
00020                             differences.append(str2)
00021                    
00022         return differences 
00023                                                     
00024     def module_diff(self,module1,module2, string1, string2):
00025         "Searches for modules which are in both the files but whose parameters are setted at different values"
00026         print '\nList of modules present in both the files with different parameter values\n'
00027         for i in module1.keys():
00028             for j in module2.keys():
00029                 if (i==j) and (i=='Processing'):
00030                     list= module1[i]
00031                     for k in range(len(list)):
00032                         process1=module1[i][k].split()
00033                         process2=module2[i][k].split()
00034                         if process1[0]!= process2[0]:
00035                             key1=process1[0]
00036                             key2=process2[0]
00037                             self._diffprocess.append( (key1,key2) )
00038                             
00039                     if len(self._diffprocess)>1:
00040                         print 'Differences in the processing history'
00041                         for l,m in self._diffprocess:         
00042                             print l+'  ['+string1+']'
00043                             print m+'  ['+string2+']'
00044                             print ''
00045                     if len(self._diffprocess)==1:
00046                         self._sameprocess=self._diffprocess[0]
00047                                                              
00048                 elif ( (i==j)or (i,j)==self._sameprocess ) and (i!='Processing'):
00049                     for name1,value1 in module1[i]:
00050                         for name2,value2 in module2[j]:
00051                             if  (name1==name2) and (value1[1:]!=value2[1:]):
00052                                 print 'Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name1+'"'+'\n'
00053                                 d=difference(self.verbose) 
00054                                 d.firstvalue=value1
00055                                 d.secondvalue=value2
00056                                 self.list_diff(d.firstvalue,d.secondvalue, string1, string2)
00057                     
00058         self.onefilemodules(module1,module2,'first')
00059         self.onefilemodules(module2,module1,'second')
00060     
00061 
00062     def onefilemodules(self,module1,module2,string):
00063         "Searches for modules present only in one of the two files"
00064         print '\nModules run only on the '+string+ ' edmfile:'+'\n'
00065         for i in module1.keys():
00066             labelList=[]
00067             if (i not in module2.keys())and (i not in self._sameprocess):
00068                 print '\n Process '+i+' not run on edmfile '+string +'\n'
00069             elif i!='Processing':
00070                 k=i
00071                 if i in self._sameprocess:
00072                     if i==self._sameprocess[0]:
00073                         k= self._sameprocess[1]
00074                     elif i==self._sameprocess[1]:
00075                         k= self._sameprocess[0]
00076                 labelList2=[module[0] for module in module2[k]]
00077                 labelList1=[module[0] for module in module1[i]]
00078                 for name, value in module1[i] :
00079                     if (name not in labelList2):
00080                         print 'Process: '+'"'+i+'"'+'\n'+'Module: '+'"'+name+'"'
00081                         if  self.verbose==str(2):
00082                             for k in value[1:]:
00083                                 print k
00084                                 
00085 
00086