CMS 3D CMS Logo

dqm_interfaces.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from __future__ import absolute_import
3 
12 
13 from builtins import range
14 from copy import deepcopy
15 from os import chdir,getcwd,makedirs
16 from os.path import abspath,exists,join, basename
17 from re import sub,search
18 from re import compile as recompile
19 from sys import exit,stderr,version_info
20 from threading import Thread,activeCount
21 from time import sleep
22 if version_info[0]==2:
23  from urllib2 import Request,build_opener,urlopen
24 else:
25  from urllib.request import Request,build_opener,urlopen
26 
27 import sys
28 argv=sys.argv
29 import ROOT
30 sys.argv=argv
31 
32 ROOT.gROOT.SetBatch(True)
33 
34 from .authentication import X509CertOpen
35 from .dirstructure import Comparison,Directory,tcanvas_print_processes
36 from .utils import Chi2,KS,BinToBin,Statistical_Tests,literal2root
37 
38 #-------------------------------------------------------------------------------
39 
41  """Base class for exceptions in this module."""
42  pass
43 
45  """Exception occurs in case of problems of communication with the server.
46  """
47  def __init__(self,msg):
48  self.msg = msg
49 
51 
52  def __init__(self,msg):
53  self.msg = msg
54 
55 #-----------------------------------------------------------------------------
56 
58 
59  """Communicate with the DQM Document server"""
60 
61  #-----------------------------------------------------------------------------
62 
63  base_dir='/data/json/archive/'
64 
65  def __init__(self,
66  server,
67  is_private=False,
68  ident="DQMToJson/1.0 python/%d.%d.%d" % version_info[:3]):
69  self.ident = ident
70  self.server = server
71  self.is_private = is_private
72  self.DQMpwd=DQMcommunicator.base_dir
73  self.prevDQMpwd=self.DQMpwd
74  self.opener=None
75  if not self.is_private:
76  self.opener=build_opener(X509CertOpen())
77  #-----------------------------------------------------------------------------
78 
79  def open_url(self,url):
80  url=url.replace(' ','%20')
81  datareq = Request(url)
82  datareq.add_header('User-agent', self.ident)
83  url_obj=0
84  if not self.is_private:
85  url_obj=self.opener.open(datareq)
86  #url_obj=build_opener(X509CertOpen()).open(datareq)
87  else:
88  url_obj=urlopen(datareq)
89 
90  return url_obj
91 
92  #-----------------------------------------------------------------------------
93 
94  def get_data(self, full_url):
95  #print "getting data from %s" %full_url
96  data = self.open_url(full_url).read()
97 
98  data = sub("-inf", '0', data)
99  data = sub("\s+inf", '0', data)
100  data = sub("\s+nan", '0', data)
101  data = sub('""(CMSSW.*?)""', '"\\1"', data)
102 
103  return data
104 
105  #-----------------------------------------------------------------------------
106 
107  def ls_url(self, url):
108  url=url.replace(" ","%20")
109  url=self.server+url
110  #print "listing "+url
111  form_folder={}
112  raw_folder=None
113  try:
114  raw_folder=eval(self.get_data(url))
115  except:
116  print("Retrying..")
117  for ntrials in range(5):
118  try:
119  if ntrials!=0:
120  sleep(2)
121  #raw_folder=loads(self.get_data(url))
122  raw_folder=eval(self.get_data(url))
123  break
124  except:
125  print("Could not fetch %s. Retrying" %url)
126 
127  #raw_folder=loads(self.get_data(url))
128  for content_dict in raw_folder["contents"]:
129  if "subdir" in content_dict:
130  form_folder[content_dict["subdir"]]={"type":'dir'}
131  elif "obj" in content_dict:
132  properties=content_dict["properties"]
133  obj_name=content_dict["obj"]
134  obj_type=properties["type"]
135  obj_kind=properties["kind"]
136  obj_as_string=''
137  if "rootobj" in content_dict:
138  obj_as_string=content_dict["rootobj"]
139  form_folder[obj_name]={'type':obj_type,'obj_as_string':obj_as_string,"kind":obj_kind}
140  #for k,v in form_folder.items():
141  #print "* %s --> %s" %(k,v["type"])
142 
143  return form_folder
144 
145  #-----------------------------------------------------------------------------
146 
147  def ls(self, url='', fetch_root=False):
148  if len(url)==0:
149  url=join(self.DQMpwd,url)
150 
151  form_folder={}
152 
153  if fetch_root:
154  url='%s?rootcontent=1'%url
155  form_folder=self.ls_url(url)
156 
157  return form_folder
158 
159  #-----------------------------------------------------------------------------
160 
161  def cd(self, *args):
162  len_args=len(args)
163  full_url=""
164  if len_args!=1 and len_args!=3:
165  raise InvalidNumberOfArguments
166  if len_args==3:
167  dataset, run, folder = args
168  full_url='%s/data/json/archive/%s/%s/%s' % (self.server, dataset, run, folder)
169  if len_args==1:
170  folder=args[0]
171  if folder==self.DQMpwd:
172  full_url=self.DQMpwd
173  elif folder=="..":
174  full_url=self.DQMpwd[:self.DQMpwd.rfind("/")]
175  elif folder=="-":
176  full_url=self.oldDQMpwd
177  elif folder=="":
178  full_url=DQMcommunicator.base_dir
179  else:
180  full_url=self.DQMpwd+"/"+folder
181 
182  full_url=full_url.replace(' ','%20')
183  #print "cd: "+full_url
184 
185  self.oldDQMpwd=self.DQMpwd
186  self.DQMpwd=full_url
187  #print "In %s" %self.DQMpwd
188 
189  #-----------------------------------------------------------------------------
190 
191  def get_samples(self, samples_string="*"):
192  """
193  A sample contains, among the other things, a data type, a dataset name
194  and a run.
195  """
196  full_url='%s/data/json/samples?match=%s' % (self.server, samples_string)
197  samples_dict=eval(self.get_data(full_url))
198  return samples_dict["samples"]
199 
200  #-----------------------------------------------------------------------------
201 
202  def get_datasets_list(self, dataset_string=""):
203  samples_list=self.get_samples(dataset_string)
204  datasets_list=[]
205  for sample in samples_list:
206  temp_datasets_list = map(lambda item:item["dataset"] ,sample['items'])
207  for temp_dataset in temp_datasets_list:
208  if not temp_dataset in datasets_list:
209  datasets_list.append(temp_dataset)
210  return datasets_list
211 
212  #-----------------------------------------------------------------------------
213 
214  def get_RelVal_CMSSW_versions(self,query):
215  """Get the available cmssw versions for the relvals.
216  """
217  relvals_list=self.get_datasets_list(query)
218  # The samples are of the form /RelValTHISISMYFAVOURITECHANNEL/CMSSW_VERSION/GEN-SIM-WHATEVER-RECO
219  cmssw_versions_with_duplicates=map (lambda x: x.split("/")[2],relvals_list)
220  return list(set(cmssw_versions_with_duplicates))
221 
222  #-----------------------------------------------------------------------------
223 
224  def get_runs_list(self, dataset_string):
225  slash="/"
226  while(dataset_string.endswith(slash) or dataset_string.beginswith(slash)):
227  dataset_string=dataset_string.strip("/")
228  samples_list=self.get_samples(dataset_string)
229  runlist=[]
230  # Get all the runs in all the items which are in every sample
231  map( lambda sample: map (lambda item: runlist.append(item['run']), sample['items']), samples_list)
232  return runlist
233 
234  #-----------------------------------------------------------------------------
235 
236  def get_dataset_runs(self,dataset_string):
237  dataset_runs={}
238  for dataset in self.get_datasets_list(dataset_string):
239  dataset_runs[dataset]=self.get_runs_list(dataset)
240  return dataset_runs
241 
242  #-----------------------------------------------------------------------------
243 
244  def get_common_runs(self,dataset_string1,dataset_string2):
245  set1=set(self.get_runs_list(dataset_string1))
246  set2=set(self.get_runs_list(dataset_string2))
247  set1.intersection_update(set2)
248  return list (set2)
249 
250  #-----------------------------------------------------------------------------
251 
252  def get_root_objects_list(self, url=""):
253  if len(url)==0:
254  url=self.DQMpwd
255  else:
256  url="/"+url
257  url = url.replace(" ","%20")
258  objects=[]
259  for name,description in self.ls(url,True).items():
260  if "dir" not in description["type"] and "ROOT" in description["kind"]:
261  objects.append(literal2root(description["obj_as_string"],description["type"]))
262  return objects
263 
264  #-----------------------------------------------------------------------------
265 
266  def get_root_objects(self, url=""):
267  if len(url)==0:
268  url=self.DQMpwd
269  else:
270  url=self.server+"/"+url
271  url = url.replace(" ","%20")
272  objects={}
273  for name,description in self.ls(url,True).items():
274  if "dir" not in description["type"] and "ROOT" in description["kind"]:
275  objects[name]=literal2root(description["obj_as_string"],description["type"])
276  return objects
277 
278  #-------------------------------------------------------------------------------
279 
281  null_url = (len(url)==0)
282  if len(url)==0:
283  url=self.DQMpwd
284  else:
285  url="/"+url
286  url = url.replace(" ","%20")
287  if not null_url:
288  self.cd(url)
289  objects=[]
290  for name,description in self.ls("",True).items():
291  if "dir" in description["type"]:
292  objects+=self.get_root_objects_list_recursive(name)
293  self.cd("..")
294  elif "ROOT" in description["kind"]:
295  objects.append(literal2root(description["obj_as_string"],description["type"]))
296  if not null_url:
297  self.cd("..")
298  return objects
299 
300  #-------------------------------------------------------------------------------
301 
302  def get_root_objects_names_list_recursive(self, url="",present_url=""):
303  null_url = (len(url)==0)
304  if (not null_url):
305  if len(present_url)==0:
306  present_url=url
307  else:
308  present_url+="_%s"%url
309  if len(url)==0:
310  url=self.DQMpwd
311  else:
312  url="/"+url
313  url = url.replace(" ","%20")
314  if not null_url:
315  self.cd(url)
316  objects_names=[]
317  for name,description in self.ls("",False).items():
318  if "dir" in description["type"]:
319  objects_names+=self.get_root_objects_names_list_recursive(name,present_url)
320  self.cd("..")
321  elif "ROOT" in description["kind"]:
322  objects_names.append("%s_%s"%(present_url,name))
323  if not null_url:
324  self.cd("..")
325  return objects_names
326 
327  #-------------------------------------------------------------------------------
328 
329  def get_root_objects_recursive(self, url="",present_url=""):
330  null_url = (len(url)==0)
331  if (not null_url):
332  if len(present_url)==0:
333  present_url=url
334  else:
335  present_url+="_%s"%url
336  if len(url)==0:
337  url=self.DQMpwd
338  else:
339  url="/"+url
340  url = url.replace(" ","%20")
341  #if not null_url:
342  self.cd(url)
343  objects={}
344  for name,description in self.ls("",True).items():
345  if "dir" in description["type"]:
346  objects.update(self.get_root_objects_recursive(name,present_url))
347  self.cd("..")
348  elif "ROOT" in description["kind"]:
349  objects["%s_%s"%(present_url,name)]=literal2root(description["obj_as_string"],description["type"])
350  #if not null_url:
351  self.cd("..")
352  return objects
353 
354 #-------------------------------------------------------------------------------
355 
356 class DirID(object):
357  """Structure used to identify a directory in the walked tree,
358  It carries the name and depth information.
359  """
360  def __init__(self,name,depth,mother=""):
361  self.name=name
362  self.compname=recompile(name)
363  self.mother=mother
364  self.depth=depth
365  def __eq__(self,dirid):
366  depth2=dirid.depth
367  compname2=dirid.compname
368  name2=dirid.name
369  is_equal = False
370  #if self.name in name2 or name2 in self.name:
371  if search(self.compname,name2)!=None or search(compname2,self.name)!=None:
372  is_equal = self.depth*depth2 <0 or self.depth==depth2
373  if len(self.mother)*len(dirid.mother)>0:
374  is_equal = is_equal and self.mother==dirid.mother
375  return is_equal
376 
377  def __repr__(self):
378  return "Directory %s at level %s" %(self.name,self.depth)
379 
380 #-------------------------------------------------------------------------------
381 class DirFetcher(Thread):
382  """ Fetch the content of the single "directory" in the dqm.
383  """
384  def __init__ (self,comm,directory):
385  Thread.__init__(self)
386  self.comm = comm
387  self.directory = directory
388  self.contents=None
389  def run(self):
390  self.contents = self.comm.ls(self.directory,True)
391 
392 #-------------------------------------------------------------------------------
393 
394 class DirWalkerDB(Thread):
395  """An interface to the DQM document db. It is threaded to compensate the
396  latency introduced by the finite response time of the server.
397  """
398  def __init__ (self,comm1,comm2,base1,base2,directory,depth=0,do_pngs=True,stat_test="KS",test_threshold=.5,black_list=[]):
399  Thread.__init__(self)
400  self.comm1 = deepcopy(comm1)
401  self.comm2 = deepcopy(comm2)
402  self.base1,self.base2 = base1,base2
403  self.directory = directory
404  self.depth=depth
405  self.do_pngs=do_pngs
406  self.test_threshold=test_threshold
407  self.stat_test=stat_test
408  self.black_list=black_list
409  # name of the thread
410  self.name+="_%s" %directory.name
411 
412  def run(self):
413 
414  this_dir=DirID(self.directory.name,self.depth)
415  if this_dir in self.black_list:
416  print("Skipping %s since blacklisted!" %this_dir)
417  return 0
418 
419  self.depth+=1
420 
421  the_test=Statistical_Tests[self.stat_test](self.test_threshold)
422  #print "Test %s with threshold %s" %(self.stat_test,self.test_threshold)
423 
424  directory1=self.base1+"/"+self.directory.mother_dir+"/"+self.directory.name
425  directory2=self.base2+"/"+self.directory.mother_dir+"/"+self.directory.name
426 
427  fetchers =(DirFetcher(self.comm1,directory1),DirFetcher(self.comm2,directory2))
428  for fetcher in fetchers:
429  fetcher.start()
430  for fetcher in fetchers:
431  fetcher.join()
432 
433  contents1 = fetchers[0].contents
434  contents2 = fetchers[1].contents
435  set1= set(contents1.keys())
436  set2= set(contents2.keys())
437 
438  walkers=[]
439  self_directory_directories=self.directory.subdirs
440  self_directory_comparisons=self.directory.comparisons
441  contents_names=list(set1.intersection(set2))
442 
443  for name in contents_names:
444  content = contents1[name]
445  if "dir" in content["type"]:
446  #if this_dir not in DirWalker.white_list:continue
447  subdir=Directory(name,join(self.directory.mother_dir,self.directory.name))
448  dirwalker=DirWalkerDB(self.comm1,self.comm2,self.base1,self.base2,subdir,self.depth,
449  self.do_pngs,self.stat_test,self.test_threshold,self.black_list)
450  dirwalker.start()
451  walkers.append(dirwalker)
452  n_threads=activeCount()
453  if n_threads>5:
454  #print >> stderr, "Threads that are running: %s. Joining them." %(n_threads)
455  dirwalker.join()
456  elif content["kind"]=="ROOT":
457 # print directory1,name
458  comparison=Comparison(name,
459  join(self.directory.mother_dir,self.directory.name),
460  literal2root(content["obj_as_string"],content["type"]),
461  literal2root(contents2[name]["obj_as_string"],content["type"]),
462  deepcopy(the_test),
463  do_pngs=self.do_pngs)
464  self_directory_comparisons.append(comparison)
465 
466 
467  for walker in walkers:
468  walker.join()
469  walker_directory=walker.directory
470  if not walker_directory.is_empty():
471  self_directory_directories.append(walker_directory)
472 
473 #-------------------------------------------------------------------------------
474 
476  """ Class acting as interface between the user and the harvested DQMRootFile.
477  It skips the directories created by the DQM infrastructure so to provide an
478  interface as similar as possible to a real direcory structure and to the
479  directory structure provided by the db interface.
480  """
481  def __init__(self,rootfilename):
482  dqmdatadir="DQMData"
483  self.rootfile=ROOT.TFile(rootfilename)
484  self.rootfilepwd=self.rootfile.GetDirectory(dqmdatadir)
485  self.rootfileprevpwd=self.rootfile.GetDirectory(dqmdatadir)
486  if self.rootfilepwd == None:
487  print("Directory %s does not exist: skipping. Is this a custom rootfile?" %dqmdatadir)
488  self.rootfilepwd=self.rootfile
489  self.rootfileprevpwd=self.rootfile
490 
491  def __is_null(self,directory,name):
492  is_null = not directory
493  if is_null:
494  print("Directory %s does not exist!" %name, file=stderr)
495  return is_null
496 
497  def ls(self,directory_name=""):
498  contents={}
499  directory=None
500  if len(directory_name)==0:
501  directory=self.rootfilepwd
502 
503  directory=self.rootfilepwd.GetDirectory(directory_name)
504  if self.__is_null(directory,directory_name):
505  return contents
506 
507  for key in directory.GetListOfKeys():
508  contents[key.GetName()]=key.GetClassName()
509  return contents
510 
511  def cd(self,directory_name):
512  """Change the current TDirectoryFile. The familiar "-" and ".." directories
513  can be accessed as well.
514  """
515  if directory_name=="-":
516  tmp=self.rootfilepwd
517  self.rootfilepwd=self.rootfileprevpwd
518  self.rootfileprevpwd=tmp
519  if directory_name=="..":
520  #print "Setting prevpwd"
521  self.rootfileprevpwd=self.rootfilepwd
522  #print "The mom"
523  mom=self.rootfilepwd.GetMotherDir()
524  #print "In directory +%s+" %self.rootfilepwd
525  #print "Deleting the TFileDir"
526  if "Run " not in self.rootfilepwd.GetName():
527  self.rootfilepwd.Delete()
528  #print "Setting pwd to mom"
529  self.rootfilepwd=mom
530  else:
531  new_directory=self.rootfilepwd.GetDirectory(directory_name)
532  if not self.__is_null(new_directory,directory_name):
533  self.rootfileprevpwd=self.rootfilepwd
534  self.rootfilepwd=new_directory
535 
536  def getObj(self,objname):
537  """Get a TObject from the rootfile.
538  """
539  obj=self.rootfilepwd.Get(objname)
540  if not self.__is_null(obj,objname):
541  return obj
542 
543 #-------------------------------------------------------------------------------
544 
546  def __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=[]):
547  self.name=name
548  self.dqmrootfile1=DQMRootFile(abspath(rootfilename1))
549  self.dqmrootfile2=DQMRootFile(abspath(rootfilename2))
550  self.run=run
551  self.stat_test=Statistical_Tests[stat_test](test_threshold)
552  self.workdir=getcwd()
553  self.black_list=black_list
554  self.directory=Directory(topdirname)
555  #print "DIRWALKERFILE %s %s" %(draw_success,do_pngs)
556  self.directory.draw_success=draw_success
557  self.directory.do_pngs=do_pngs
558  self.black_list_histos = black_list_histos
560  self.filename1 = basename(rootfilename2)
561  self.filename2 = basename(rootfilename1)
562 
563  def __del__(self):
564  chdir(self.workdir)
565 
566  def cd(self,directory_name, on_disk=False, regexp=False,):
567  if regexp == True:
568  if len(directory_name)!=0:
569  if on_disk:
570  if not exists(directory_name):
571  makedirs(directory_name)
572  chdir(directory_name)
573  tmp = self.dqmrootfile2.ls().keys()
574  for elem in tmp:
575  if "Run" in elem:
576  next_dir = elem
577  self.dqmrootfile2.cd(next_dir)
578  tmp = self.dqmrootfile1.ls().keys()
579  for elem in tmp:
580  if "Run" in elem:
581  next_dir = elem
582  self.dqmrootfile1.cd(next_dir)
583  else:
584  if len(directory_name)!=0:
585  if on_disk:
586  if not exists(directory_name):
587  makedirs(directory_name)
588  chdir(directory_name)
589  self.dqmrootfile2.cd(directory_name)
590  self.dqmrootfile1.cd(directory_name)
591 
592  def ls(self,directory_name=""):
593  """Return common objects to the 2 files.
594  """
595  contents1=self.dqmrootfile1.ls(directory_name)
596  contents2=self.dqmrootfile2.ls(directory_name)
597  #print "cont1: %s"%(contents1)
598  #print "cont2: %s"%(contents2)
599  contents={}
600  self.different_histograms['file1']= {}
601  self.different_histograms['file2']= {}
602  keys = [key for key in contents2.keys() if key in contents1] #set of all possible contents from both files
603  #print " ## keys: %s" %(keys)
604  for key in keys: #iterate on all unique keys
605  if contents1[key]!=contents2[key]:
606  diff_file1 = set(contents1.keys()) - set(contents2.keys()) #set of contents that file1 is missing
607  diff_file2 = set(contents2.keys()) - set(contents1.keys()) #--'-- that file2 is missing
608  for key1 in diff_file1:
609  obj_type = contents1[key1]
610  if obj_type == "TDirectoryFile":
611  self.different_histograms['file1'][key1] = contents1[key1] #if direcory
612  #print "\n Missing inside a dir: ", self.ls(key1)
613  #contents[key] = contents1[key1]
614  if obj_type[:2]!="TH" and obj_type[:3]!="TPr" : #if histogram
615  continue
616  self.different_histograms['file1'][key1] = contents1[key1]
617  for key1 in diff_file2:
618  obj_type = contents2[key1]
619  if obj_type == "TDirectoryFile":
620  self.different_histograms['file2'][key1] = contents2[key1] #if direcory
621  #print "\n Missing inside a dir: ", self.ls(key1)
622  #contents[key] = contents2[key1]
623  if obj_type[:2]!="TH" and obj_type[:3]!="TPr" : #if histogram
624  continue
625  self.different_histograms['file2'][key1] = contents2[key1]
626  contents[key]=contents1[key]
627  return contents
628 
629  def getObjs(self,name):
630  h1=self.dqmrootfile1.getObj(name)
631  h2=self.dqmrootfile2.getObj(name)
632  return h1,h2
633 
634  def __fill_single_dir(self,dir_name,directory,mother_name="",depth=0):
635  #print "MOTHER NAME = +%s+" %mother_name
636  #print "About to study %s (in dir %s)" %(dir_name,getcwd())
637 
638  # see if in black_list
639  this_dir=DirID(dir_name,depth)
640  #print " ## this_dir: %s"%(this_dir)
641  if this_dir in self.black_list:
642  #print "Directory %s skipped because black-listed" %dir_name
643  return 0
644 
645  depth+=1
646 
647  self.cd(dir_name)
648  #if dir_name == 'HLTJETMET':
649  # print self.ls()
650 
651  #print "Test %s with thre %s" %(self.stat_test.name, self.stat_test.threshold)
652 
653  contents=self.ls()
654  if depth==1:
655  n_top_contents=len(contents)
656 
657  #print contents
658  cont_counter=1
659  comparisons=[]
660  for name,obj_type in contents.items():
661  if obj_type=="TDirectoryFile":
662  #We have a dir, launch recursion!
663  #Some feedback on the progress
664  if depth==1:
665  print("Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents))
666  cont_counter+=1
667 
668  #print "Studying directory",name
669  # ok recursion on!
670  subdir=Directory(name)
671  subdir.draw_success=directory.draw_success
672  subdir.do_pngs=directory.do_pngs
673  self.__fill_single_dir(name,subdir,join(mother_name,dir_name),depth)
674  if not subdir.is_empty():
675  if depth==1:
676  print(" ->Appending %s..." %name, end=' ')
677  directory.subdirs.append(subdir)
678  if depth==1:
679  print("Appended.")
680  elif name != '':
681  # We have probably an histo. Let's make the plot and the png.
682  if obj_type[:2]!="TH" and obj_type[:3]!="TPr" :
683  continue
684  h1,h2=self.getObjs(name)
685  #print "COMPARISON : +%s+%s+" %(mother_name,dir_name)
686  path = join(mother_name,dir_name,name)
687  if path in self.black_list_histos:
688  print(" Skipping %s" %(path))
689  directory.comparisons.append(Comparison(name,
690  join(mother_name,dir_name),
691  h1,h2,
692  deepcopy(self.stat_test),
693  draw_success=directory.draw_success,
694  do_pngs=directory.do_pngs, skip=True))
695  else:
696  directory.comparisons.append(Comparison(name,
697  join(mother_name,dir_name),
698  h1,h2,
699  deepcopy(self.stat_test),
700  draw_success=directory.draw_success,
701  do_pngs=directory.do_pngs, skip=False))
702  directory.filename1 = self.filename1
703  directory.filename2 = self.filename2
704  directory.different_histograms['file1'] = self.different_histograms['file1']
705  directory.different_histograms['file2'] = self.different_histograms['file2']
706 
707  self.cd("..")
708 
709  def walk(self):
710  # Build the top dir in the rootfile first
711  rundir=""
712  if self.run<0:
713  # change dir in the first one...
714  #print self.ls().keys()
715  first_run_dir = ""
716  try:
717  first_run_dir = list(filter(lambda k: "Run " in k, self.ls().keys()))[0]
718  except:
719  print("\nRundir not there: Is this a generic rootfile?\n")
720  rundir=first_run_dir
721  try:
722  self.run= int(rundir.split(" ")[1])
723  except:
724  print("Setting run number to 0")
725  self.run= 0
726  else:
727  rundir="Run %s"%self.run
728 
729  try:
730  self.cd(rundir, False, True) #True -> for checking the Rundir in case of different runs
731  except:
732  print("\nRundir not there: Is this a generic rootfile?\n")
733 
734  # Let's rock!
735  self.__fill_single_dir(self.directory.name,self.directory)
736  print("Finished")
737  n_left_threads=len(tcanvas_print_processes)
738  if n_left_threads>0:
739  print("Waiting for %s threads to finish..." %n_left_threads)
740  for p in tcanvas_print_processes:
741  p.join()
742 
743 #-------------------------------------------------------------------------------
744 
746  def __init__(self, walker):
747  Thread.__init__(self)
748  self.walker=walker
749  def run(self):
750  self.walker.walk()
751 
752 #-------------------------------------------------------------------------------
753 
754 def string2blacklist(black_list_str):
755  black_list=[]
756  # replace the + with " ":
757  black_list_str=black_list_str.replace("__"," ")
758  if len(black_list_str)>0:
759  for ele in black_list_str.split(","):
760  dirname,level=ele.split("@")
761  level=int(level)
762  dirid=None
763  if "/" not in dirname:
764  dirid=DirID(dirname,level)
765  else:
766  mother,daughter=dirname.split("/")
767  dirid=DirID(daughter,level,mother)
768  if not dirid in black_list:
769  black_list.append(dirid)
770 
771  return black_list
772 
773 #-------------------------------------------------------------------------------
774 
def get_datasets_list(self, dataset_string="")
def __init__(self, name, depth, mother="")
def __fill_single_dir(self, dir_name, directory, mother_name="", depth=0)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
def literal2root(literal, rootType, debug=False)
Definition: ROOTData.py:53
def ls(self, url='', fetch_root=False)
def __init__(self, comm1, comm2, base1, base2, directory, depth=0, do_pngs=True, stat_test="KS", test_threshold=.5, black_list=[])
def get_data(self, full_url)
def __init__(self, server, is_private=False, ident="DQMToJson/1.0 python/%d.%d.%d" % version_info[:3])
def __init__(self, comm, directory)
def get_root_objects(self, url="")
def __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=[])
def get_root_objects_names_list_recursive(self, url="", present_url="")
def get_common_runs(self, dataset_string1, dataset_string2)
def get_dataset_runs(self, dataset_string)
def get_root_objects_recursive(self, url="", present_url="")
abspath
Definition: dataset.py:55
def cd(self, directory_name, on_disk=False, regexp=False)
def __is_null(self, directory, name)
def ls(self, directory_name="")
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def ls(self, directory_name="")
def getObj(self, objname)
def cd(self, directory_name)
def get_root_objects_list_recursive(self, url="")
def ls(path, rec=False)
Definition: eostools.py:349
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def get_runs_list(self, dataset_string)
def get_root_objects_list(self, url="")
def get_RelVal_CMSSW_versions(self, query)
while(__syncthreads_or(more))
def __eq__(self, dirid)
def get_samples(self, samples_string="*")
def __init__(self, rootfilename)
def string2blacklist(black_list_str)
T * Get(Args... args)
Definition: Trend.h:122