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
 directory
 dqmrootfile1
 dqmrootfile2
 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

def dqm_interfaces::DirWalkerFile::__del__ (   self)

Definition at line 558 of file dqm_interfaces.py.

00559                    :
00560     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 604 of file dqm_interfaces.py.

00605                                                                        :
00606     #print "MOTHER NAME  = +%s+" %mother_name
00607    #print "About to study %s (in dir %s)" %(dir_name,getcwd())
00608         
00609     # see if in black_list
00610     this_dir=DirID(dir_name,depth)
00611     #print this_dir
00612     if this_dir in self.black_list: 
00613       #print "Directory %s skipped because black-listed" %dir_name
00614       return 0        
00615         
00616     depth+=1
00617     
00618     self.cd(dir_name)
00619     #print self.ls()
00620     
00621     #print "Test %s with thre %s" %(self.stat_test.name, self.stat_test.threshold)
00622     
00623     contents=self.ls()
00624     if depth==1:
00625       n_top_contents=len(contents)
00626     
00627     #print contents
00628     cont_counter=1
00629     comparisons=[]
00630     for name,obj_type in contents.items():
00631       if obj_type=="TDirectoryFile":        
00632         #We have a dir, launch recursion!
00633         #Some feedback on the progress
00634         if depth==1:
00635           print "Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents)
00636           cont_counter+=1          
00637  
00638         #print "Studying directory",name
00639         # ok recursion on!
00640         subdir=Directory(name)
00641         subdir.draw_success=directory.draw_success
00642         subdir.do_pngs=directory.do_pngs
00643         self.__fill_single_dir(name,subdir,join(mother_name,dir_name),depth)
00644         if not subdir.is_empty():
00645           if depth==1:
00646             print " ->Appending %s..." %name,
00647           directory.subdirs.append(subdir)
00648           if depth==1:
00649             print "Appended."
00650       else:
00651         # We have probably an histo. Let's make the plot and the png.        
00652         if obj_type[:2]!="TH" and obj_type[:3]!="TPr" :
00653           continue
00654         h1,h2=self.getObjs(name)
00655         #print "COMPARISON : +%s+%s+" %(mother_name,dir_name)
00656         path = join(mother_name,dir_name,name)
00657         if path in self.black_list_histos:
00658           print "  Skipping %s" %(path)
00659           directory.comparisons.append(Comparison(name,
00660                               join(mother_name,dir_name),
00661                               h1,h2,
00662                               deepcopy(self.stat_test),
00663                               draw_success=directory.draw_success,
00664                               do_pngs=directory.do_pngs, skip=True))
00665         else:
00666           directory.comparisons.append(Comparison(name,
00667                                 join(mother_name,dir_name),
00668                                 h1,h2,
00669                                 deepcopy(self.stat_test),
00670                                 draw_success=directory.draw_success,
00671                                 do_pngs=directory.do_pngs, skip=False))
00672 
00673     self.cd("..")
   
def dqm_interfaces::DirWalkerFile::cd (   self,
  directory_name,
  on_disk = False,
  regexp = False 
)

Definition at line 561 of file dqm_interfaces.py.

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

Definition at line 599 of file dqm_interfaces.py.

00600                         :
00601     h1=self.dqmrootfile1.getObj(name)
00602     h2=self.dqmrootfile2.getObj(name)
00603     return h1,h2
  
def dqm_interfaces::DirWalkerFile::ls (   self,
  directory_name = "" 
)
Return common objects to the 2 files.

Definition at line 587 of file dqm_interfaces.py.

00588                                 :
00589     """Return common objects to the 2 files.
00590     """
00591     contents1=self.dqmrootfile1.ls(directory_name)
00592     contents2=self.dqmrootfile2.ls(directory_name)
00593     contents={}
00594     keys = filter(lambda key: contents1.has_key(key),contents2.keys())
00595     for key in keys:
00596       #if contents1[key]==contents2[key]:
00597       contents[key]=contents1[key]
00598     return contents
  
def dqm_interfaces::DirWalkerFile::walk (   self)

Definition at line 674 of file dqm_interfaces.py.

00675                 :
00676     # Build the top dir in the rootfile first
00677     rundir=""
00678     if self.run<0:
00679       # change dir in the first one...
00680       #print  self.ls().keys()
00681       first_run_dir = ""
00682       try:
00683         first_run_dir = filter(lambda k: "Run " in k, self.ls().keys())[0]
00684       except:
00685          print "\nRundir not there: Is this a generic rootfile?\n"
00686       rundir=first_run_dir
00687       try:
00688         self.run= int(rundir.split(" ")[1])
00689       except:
00690         print "Setting run number to 0"
00691         self.run= 0
00692     else:
00693       rundir="Run %s"%self.run
00694     
00695     try:
00696       self.cd(rundir, False, True) #True -> for checking the Rundir in case of different runs
00697     except:
00698       print "\nRundir not there: Is this a generic rootfile?\n"
00699     
00700     # Let's rock!
00701     self.__fill_single_dir(self.directory.name,self.directory)
00702     print "Finished"
00703     n_left_threads=len(tcanvas_print_processes)
00704     if n_left_threads>0:
00705       print "Waiting for %s threads to finish..." %n_left_threads
00706       for p in tcanvas_print_processes:
00707         p.join()  
00708 
00709 #-------------------------------------------------------------------------------


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.