CMS 3D CMS Logo

Public Member Functions | Public Attributes | Private Member Functions

dqm_interfaces::DirWalkerFile Class Reference

List of all members.

Public Member Functions

def __del__
def __init__
def cd
def getObjs
def ls
def walk

Public Attributes

 black_list
 black_list_histos
 different_histograms
 directory
 dqmrootfile1
 dqmrootfile2
 filename1
 filename2
 name
 run
 stat_test
 workdir

Private Member Functions

def __fill_single_dir

Detailed Description

Definition at line 543 of file dqm_interfaces.py.


Constructor & Destructor Documentation

def dqm_interfaces::DirWalkerFile::__init__ (   self,
  name,
  topdirname,
  rootfilename1,
  rootfilename2,
  run = -1,
  black_list = [],
  stat_test = "KS",
  test_threshold = .5,
  draw_success = True,
  do_pngs = False,
  black_list_histos = [] 
)

Definition at line 544 of file dqm_interfaces.py.

00545                                                                                                                                                                                    :
00546     self.name=name
00547     self.dqmrootfile1=DQMRootFile(abspath(rootfilename1))
00548     self.dqmrootfile2=DQMRootFile(abspath(rootfilename2))
00549     self.run=run
00550     self.stat_test=Statistical_Tests[stat_test](test_threshold)
00551     self.workdir=getcwd()
00552     self.black_list=black_list
00553     self.directory=Directory(topdirname)
00554     #print "DIRWALKERFILE %s %s" %(draw_success,do_pngs)
00555     self.directory.draw_success=draw_success
00556     self.directory.do_pngs=do_pngs
00557     self.black_list_histos = black_list_histos
00558     self.different_histograms = {}
00559     self.filename1 = basename(rootfilename2)
00560     self.filename2 = basename(rootfilename1)

def dqm_interfaces::DirWalkerFile::__del__ (   self)

Definition at line 561 of file dqm_interfaces.py.

00562                    :
00563     chdir(self.workdir)
     

Member Function Documentation

def dqm_interfaces::DirWalkerFile::__fill_single_dir (   self,
  dir_name,
  directory,
  mother_name = "",
  depth = 0 
) [private]

Definition at line 632 of file dqm_interfaces.py.

00633                                                                        :
00634     #print "MOTHER NAME  = +%s+" %mother_name
00635    #print "About to study %s (in dir %s)" %(dir_name,getcwd())
00636         
00637     # see if in black_list
00638     this_dir=DirID(dir_name,depth)
00639     #print "  ## this_dir: %s"%(this_dir)
00640     if this_dir in self.black_list: 
00641       #print "Directory %s skipped because black-listed" %dir_name
00642       return 0        
00643         
00644     depth+=1
00645     
00646     self.cd(dir_name)
00647     #if dir_name == 'HLTJETMET':
00648     #    print self.ls()
00649     
00650     #print "Test %s with thre %s" %(self.stat_test.name, self.stat_test.threshold)
00651     
00652     contents=self.ls()
00653     if depth==1:
00654       n_top_contents=len(contents)
00655     
00656     #print contents
00657     cont_counter=1
00658     comparisons=[]
00659     for name,obj_type in contents.items():
00660       if obj_type=="TDirectoryFile":        
00661         #We have a dir, launch recursion!
00662         #Some feedback on the progress
00663         if depth==1:
00664           print "Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents)
00665           cont_counter+=1          
00666  
00667         #print "Studying directory",name
00668         # ok recursion on!
00669         subdir=Directory(name)
00670         subdir.draw_success=directory.draw_success
00671         subdir.do_pngs=directory.do_pngs
00672         self.__fill_single_dir(name,subdir,join(mother_name,dir_name),depth)
00673         if not subdir.is_empty():
00674           if depth==1:
00675             print " ->Appending %s..." %name,
00676           directory.subdirs.append(subdir)
00677           if depth==1:
00678             print "Appended."
00679       else:
00680         # We have probably an histo. Let's make the plot and the png.        
00681         if obj_type[:2]!="TH" and obj_type[:3]!="TPr" :
00682           continue
00683         h1,h2=self.getObjs(name)
00684         #print "COMPARISON : +%s+%s+" %(mother_name,dir_name)
00685         path = join(mother_name,dir_name,name)
00686         if path in self.black_list_histos:
00687           print "  Skipping %s" %(path)
00688           directory.comparisons.append(Comparison(name,
00689                               join(mother_name,dir_name),
00690                               h1,h2,
00691                               deepcopy(self.stat_test),
00692                               draw_success=directory.draw_success,
00693                               do_pngs=directory.do_pngs, skip=True))
00694         else:
00695           directory.comparisons.append(Comparison(name,
00696                                 join(mother_name,dir_name),
00697                                 h1,h2,
00698                                 deepcopy(self.stat_test),
00699                                 draw_success=directory.draw_success,
00700                                 do_pngs=directory.do_pngs, skip=False))
00701           directory.filename1 = self.filename1
00702           directory.filename2 = self.filename2
00703           directory.different_histograms['file1'] = self.different_histograms['file1']
00704           directory.different_histograms['file2'] = self.different_histograms['file2']
00705 
00706     self.cd("..")
   
def dqm_interfaces::DirWalkerFile::cd (   self,
  directory_name,
  on_disk = False,
  regexp = False 
)

Definition at line 564 of file dqm_interfaces.py.

00565                                                            :
00566     if regexp == True:
00567         if len(directory_name)!=0:
00568             if on_disk:
00569                 if not exists(directory_name):
00570                     makedirs(directory_name)
00571                     chdir(directory_name)  
00572             tmp = self.dqmrootfile2.ls().keys()
00573             for elem in tmp:
00574                 if "Run" in elem:
00575                     next_dir = elem
00576             self.dqmrootfile2.cd(next_dir)
00577             tmp = self.dqmrootfile1.ls().keys()
00578             for elem in tmp:
00579                 if "Run" in elem:
00580                     next_dir = elem
00581             self.dqmrootfile1.cd(next_dir)
00582     else:
00583         if len(directory_name)!=0:
00584             if on_disk:
00585                 if not exists(directory_name):
00586                     makedirs(directory_name)
00587                     chdir(directory_name)
00588             self.dqmrootfile2.cd(directory_name)
00589             self.dqmrootfile1.cd(directory_name)
    
def dqm_interfaces::DirWalkerFile::getObjs (   self,
  name 
)

Definition at line 627 of file dqm_interfaces.py.

00628                         :
00629     h1=self.dqmrootfile1.getObj(name)
00630     h2=self.dqmrootfile2.getObj(name)
00631     return h1,h2
  
def dqm_interfaces::DirWalkerFile::ls (   self,
  directory_name = "" 
)
Return common objects to the 2 files.

Definition at line 590 of file dqm_interfaces.py.

00591                                 :
00592     """Return common objects to the 2 files.
00593     """
00594     contents1=self.dqmrootfile1.ls(directory_name)
00595     contents2=self.dqmrootfile2.ls(directory_name)
00596     #print "cont1: %s"%(contents1)
00597     #print "cont2: %s"%(contents2)
00598     contents={}
00599     self.different_histograms['file1']= {}
00600     self.different_histograms['file2']= {}
00601     keys = filter(lambda key: contents1.has_key(key),contents2.keys()) #set of all possible contents from both files
00602     #print " ## keys: %s" %(keys)
00603     for key in keys:  #iterate on all unique keys
00604       if contents1[key]!=contents2[key]:
00605         diff_file1 = set(contents1.keys()) - set(contents2.keys()) #set of contents that file1 is missing
00606         diff_file2 = set(contents2.keys()) - set(contents1.keys()) #--'-- that file2 is missing
00607         for key1 in diff_file1:
00608             obj_type = contents1[key1]
00609             if obj_type == "TDirectoryFile":
00610               self.different_histograms['file1'][key1] = contents1[key1] #if direcory
00611               #print "\n Missing inside a dir: ", self.ls(key1)
00612               #contents[key] = contents1[key1]
00613             if obj_type[:2]!="TH" and obj_type[:3]!="TPr" : #if histogram
00614               continue
00615             self.different_histograms['file1'][key1] = contents1[key1]
00616         for key1 in diff_file2:
00617             obj_type = contents2[key1]
00618             if obj_type == "TDirectoryFile":
00619               self.different_histograms['file2'][key1] = contents2[key1] #if direcory
00620               #print "\n Missing inside a dir: ", self.ls(key1)
00621               #contents[key] = contents2[key1]
00622             if obj_type[:2]!="TH" and obj_type[:3]!="TPr" : #if histogram
00623               continue
00624             self.different_histograms['file2'][key1] = contents2[key1]
00625       contents[key]=contents1[key]
00626     return contents
  
def dqm_interfaces::DirWalkerFile::walk (   self)

Definition at line 707 of file dqm_interfaces.py.

00708                 :
00709     # Build the top dir in the rootfile first
00710     rundir=""
00711     if self.run<0:
00712       # change dir in the first one...
00713       #print  self.ls().keys()
00714       first_run_dir = ""
00715       try:
00716         first_run_dir = filter(lambda k: "Run " in k, self.ls().keys())[0]
00717       except:
00718          print "\nRundir not there: Is this a generic rootfile?\n"
00719       rundir=first_run_dir
00720       try:
00721         self.run= int(rundir.split(" ")[1])
00722       except:
00723         print "Setting run number to 0"
00724         self.run= 0
00725     else:
00726       rundir="Run %s"%self.run
00727     
00728     try:
00729       self.cd(rundir, False, True) #True -> for checking the Rundir in case of different runs
00730     except:
00731       print "\nRundir not there: Is this a generic rootfile?\n"
00732     
00733     # Let's rock!
00734     self.__fill_single_dir(self.directory.name,self.directory)
00735     print "Finished"
00736     n_left_threads=len(tcanvas_print_processes)
00737     if n_left_threads>0:
00738       print "Waiting for %s threads to finish..." %n_left_threads
00739       for p in tcanvas_print_processes:
00740         p.join()  
00741 
00742 #-------------------------------------------------------------------------------


Member Data Documentation

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.

Definition at line 544 of file dqm_interfaces.py.