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  else:
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 
dqm_interfaces.DQMcommunicator.get_root_objects
def get_root_objects(self, url="")
Definition: dqm_interfaces.py:266
dqm_interfaces.InvalidNumberOfArguments.__init__
def __init__(self, msg)
Definition: dqm_interfaces.py:52
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
dqm_interfaces.DQMRootFile
Definition: dqm_interfaces.py:475
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
dqm_interfaces.DirID.__eq__
def __eq__(self, dirid)
Definition: dqm_interfaces.py:365
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
dqm_interfaces.DirWalkerDB.black_list
black_list
Definition: dqm_interfaces.py:408
dqm_interfaces.DirID.name
name
Definition: dqm_interfaces.py:361
dqm_interfaces.DQMcommunicator
Definition: dqm_interfaces.py:57
dqm_interfaces.DQM_DB_Communication.msg
msg
Definition: dqm_interfaces.py:48
dqm_interfaces.DQMcommunicator.ls
def ls(self, url='', fetch_root=False)
Definition: dqm_interfaces.py:147
dqm_interfaces.DirWalkerFile.run
run
Definition: dqm_interfaces.py:550
dqm_interfaces.DirWalkerFile.filename1
filename1
Definition: dqm_interfaces.py:560
dqm_interfaces.DirWalkerFile.workdir
workdir
Definition: dqm_interfaces.py:552
dqm_interfaces.DirWalkerFile_thread_wrapper.__init__
def __init__(self, walker)
Definition: dqm_interfaces.py:746
dqm_interfaces.DirWalkerFile.black_list
black_list
Definition: dqm_interfaces.py:553
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
dqm_interfaces.DirFetcher.__init__
def __init__(self, comm, directory)
Definition: dqm_interfaces.py:384
dqm_interfaces.DQMcommunicator.ident
ident
Definition: dqm_interfaces.py:66
dqm_interfaces.DQMcommunicator.prevDQMpwd
prevDQMpwd
Definition: dqm_interfaces.py:70
dqm_interfaces.DirWalkerFile.stat_test
stat_test
Definition: dqm_interfaces.py:551
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
dirstructure.Comparison
Definition: dirstructure.py:334
dqm_interfaces.DirID.__repr__
def __repr__(self)
Definition: dqm_interfaces.py:377
dqm_interfaces.DirWalkerFile.filename2
filename2
Definition: dqm_interfaces.py:561
dqm_interfaces.DirID
Definition: dqm_interfaces.py:356
dqm_interfaces.DQMcommunicator.get_samples
def get_samples(self, samples_string="*")
Definition: dqm_interfaces.py:191
dqm_interfaces.DirWalkerDB
Definition: dqm_interfaces.py:394
dataset.abspath
abspath
Definition: dataset.py:55
dqm_interfaces.DirFetcher
Definition: dqm_interfaces.py:381
mps_monitormerge.items
list items
Definition: mps_monitormerge.py:29
dqm_interfaces.DirID.__init__
def __init__(self, name, depth, mother="")
Definition: dqm_interfaces.py:360
dqm_interfaces.DQMcommunicator.get_root_objects_names_list_recursive
def get_root_objects_names_list_recursive(self, url="", present_url="")
Definition: dqm_interfaces.py:302
dqm_interfaces.DQMcommunicator.get_root_objects_recursive
def get_root_objects_recursive(self, url="", present_url="")
Definition: dqm_interfaces.py:329
dqm_interfaces.DirID.mother
mother
Definition: dqm_interfaces.py:363
dqm_interfaces.DQMcommunicator.DQMpwd
DQMpwd
Definition: dqm_interfaces.py:69
dqm_interfaces.DirWalkerFile.__del__
def __del__(self)
Definition: dqm_interfaces.py:563
authentication.X509CertOpen
Definition: authentication.py:75
ROOTData.literal2root
def literal2root(literal, rootType, debug=False)
Definition: ROOTData.py:53
dqm_interfaces.DQM_DB_Communication.__init__
def __init__(self, msg)
Definition: dqm_interfaces.py:47
dqm_interfaces.DirWalkerFile.__fill_single_dir
def __fill_single_dir(self, dir_name, directory, mother_name="", depth=0)
Definition: dqm_interfaces.py:634
dqm_interfaces.DirWalkerDB.do_pngs
do_pngs
Definition: dqm_interfaces.py:405
dqm_interfaces.DQMRootFile.rootfilepwd
rootfilepwd
Definition: dqm_interfaces.py:484
dqm_interfaces.DirWalkerDB.test_threshold
test_threshold
Definition: dqm_interfaces.py:406
dqm_interfaces.DQMcommunicator.get_root_objects_list
def get_root_objects_list(self, url="")
Definition: dqm_interfaces.py:252
dqm_interfaces.DQMcommunicator.server
server
Definition: dqm_interfaces.py:67
dqm_interfaces.DQMcommunicator.cd
def cd(self, *args)
Definition: dqm_interfaces.py:161
dqm_interfaces.DirWalkerFile.dqmrootfile2
dqmrootfile2
Definition: dqm_interfaces.py:549
dqm_interfaces.DirWalkerFile_thread_wrapper.run
def run(self)
Definition: dqm_interfaces.py:749
cond::persistency::search
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
dqm_interfaces.DirWalkerFile_thread_wrapper.walker
walker
Definition: dqm_interfaces.py:748
dqm_interfaces.DirWalkerDB.depth
depth
Definition: dqm_interfaces.py:404
dqm_interfaces.DQMRootFile.cd
def cd(self, directory_name)
Definition: dqm_interfaces.py:511
dqm_interfaces.DirWalkerDB.stat_test
stat_test
Definition: dqm_interfaces.py:407
dqm_interfaces.DirWalkerFile.dqmrootfile1
dqmrootfile1
Definition: dqm_interfaces.py:548
dqm_interfaces.DQMcommunicator.get_data
def get_data(self, full_url)
Definition: dqm_interfaces.py:94
dqm_interfaces.DQMcommunicator.__init__
def __init__(self, server, is_private=False, ident="DQMToJson/1.0 python/%d.%d.%d" % version_info[:3])
Definition: dqm_interfaces.py:65
dqm_interfaces.InvalidNumberOfArguments.msg
msg
Definition: dqm_interfaces.py:53
dqm_interfaces.DQMcommunicator.ls_url
def ls_url(self, url)
Definition: dqm_interfaces.py:107
dqm_interfaces.Error
Definition: dqm_interfaces.py:40
dqm_interfaces.DirWalkerFile.name
name
Definition: dqm_interfaces.py:547
dqm_interfaces.DQMcommunicator.opener
opener
Definition: dqm_interfaces.py:71
dqm_interfaces.string2blacklist
def string2blacklist(black_list_str)
Definition: dqm_interfaces.py:754
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
dqm_interfaces.DQMRootFile.rootfile
rootfile
Definition: dqm_interfaces.py:483
Exception
dqm_interfaces.DQMRootFile.__is_null
def __is_null(self, directory, name)
Definition: dqm_interfaces.py:491
dqm_interfaces.DQMRootFile.rootfileprevpwd
rootfileprevpwd
Definition: dqm_interfaces.py:485
createfilelist.int
int
Definition: createfilelist.py:10
dqm_interfaces.DQMRootFile.ls
def ls(self, directory_name="")
Definition: dqm_interfaces.py:497
dqm_interfaces.DQMcommunicator.get_root_objects_list_recursive
def get_root_objects_list_recursive(self, url="")
Definition: dqm_interfaces.py:280
dqm_interfaces.DQM_DB_Communication
Definition: dqm_interfaces.py:44
dqm_interfaces.DirFetcher.comm
comm
Definition: dqm_interfaces.py:386
dqm_interfaces.DirWalkerFile.different_histograms
different_histograms
Definition: dqm_interfaces.py:559
dqm_interfaces.DQMRootFile.getObj
def getObj(self, objname)
Definition: dqm_interfaces.py:536
dqm_interfaces.DirWalkerFile.getObjs
def getObjs(self, name)
Definition: dqm_interfaces.py:629
dqm_interfaces.DQMcommunicator.get_dataset_runs
def get_dataset_runs(self, dataset_string)
Definition: dqm_interfaces.py:236
dqm_interfaces.DirWalkerFile.walk
def walk(self)
Definition: dqm_interfaces.py:709
dqm_interfaces.DirFetcher.run
def run(self)
Definition: dqm_interfaces.py:389
dqm_interfaces.DirWalkerDB.run
def run(self)
Definition: dqm_interfaces.py:412
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
dqm_interfaces.DQMcommunicator.get_runs_list
def get_runs_list(self, dataset_string)
Definition: dqm_interfaces.py:224
dqm_interfaces.DirID.compname
compname
Definition: dqm_interfaces.py:362
dqm_interfaces.DirWalkerDB.directory
directory
Definition: dqm_interfaces.py:403
dqm_interfaces.DQMcommunicator.get_common_runs
def get_common_runs(self, dataset_string1, dataset_string2)
Definition: dqm_interfaces.py:244
dqm_interfaces.DQMcommunicator.get_datasets_list
def get_datasets_list(self, dataset_string="")
Definition: dqm_interfaces.py:202
dqm_interfaces.DirWalkerFile.cd
def cd(self, directory_name, on_disk=False, regexp=False)
Definition: dqm_interfaces.py:566
dqm_interfaces.DirWalkerFile.directory
directory
Definition: dqm_interfaces.py:554
dqm_interfaces.DirID.depth
depth
Definition: dqm_interfaces.py:364
dqm_interfaces.DQMcommunicator.get_RelVal_CMSSW_versions
def get_RelVal_CMSSW_versions(self, query)
Definition: dqm_interfaces.py:214
dirstructure.Directory
Definition: dirstructure.py:62
dqm_interfaces.DQMcommunicator.is_private
is_private
Definition: dqm_interfaces.py:68
dqm_interfaces.DQMcommunicator.open_url
def open_url(self, url)
Definition: dqm_interfaces.py:79
dqm_interfaces.DirWalkerFile.__init__
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=[])
Definition: dqm_interfaces.py:546
dqm_interfaces.DirWalkerDB.comm2
comm2
Definition: dqm_interfaces.py:401
dqm_interfaces.DirWalkerFile
Definition: dqm_interfaces.py:545
dqm_interfaces.DQMRootFile.__init__
def __init__(self, rootfilename)
Definition: dqm_interfaces.py:481
dqm_interfaces.DirFetcher.directory
directory
Definition: dqm_interfaces.py:387
dqm_interfaces.DirWalkerDB.__init__
def __init__(self, comm1, comm2, base1, base2, directory, depth=0, do_pngs=True, stat_test="KS", test_threshold=.5, black_list=[])
Definition: dqm_interfaces.py:398
genParticles_cff.map
map
Definition: genParticles_cff.py:11
dqm_interfaces.DirWalkerDB.base2
base2
Definition: dqm_interfaces.py:402
DQMMessageLogger_cfi.Directory
Directory
Definition: DQMMessageLogger_cfi.py:8
dqm_interfaces.DirWalkerDB.comm1
comm1
Definition: dqm_interfaces.py:400
dqm_interfaces.InvalidNumberOfArguments
Definition: dqm_interfaces.py:50
dqm_interfaces.DirWalkerFile.black_list_histos
black_list_histos
Definition: dqm_interfaces.py:558
dqm_interfaces.DirWalkerFile_thread_wrapper
Definition: dqm_interfaces.py:745
dqm_interfaces.DirWalkerFile.ls
def ls(self, directory_name="")
Definition: dqm_interfaces.py:592
dqm_interfaces.DQMcommunicator.oldDQMpwd
oldDQMpwd
Definition: dqm_interfaces.py:185
dqm_interfaces.DirFetcher.contents
contents
Definition: dqm_interfaces.py:388
gpuVertexFinder::while
while(__syncthreads_or(more))
Definition: gpuClusterTracksIterative.h:109