1 from __future__
import print_function
2 from __future__
import absolute_import
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 from urllib2
import Request,build_opener,urlopen
32 from .authentication
import X509CertOpen
33 from .dirstructure
import Comparison,Directory,tcanvas_print_processes
34 from .utils
import Chi2,KS,BinToBin,Statistical_Tests,literal2root
39 """Base class for exceptions in this module.""" 43 """Exception occurs in case of problems of communication with the server. 57 """Communicate with the DQM Document server""" 61 base_dir=
'/data/json/archive/' 66 ident=
"DQMToJson/1.0 python/%d.%d.%d" % version_info[:3]):
78 url=url.replace(
' ',
'%20')
79 datareq = Request(url)
80 datareq.add_header(
'User-agent', self.
ident)
83 url_obj=self.opener.open(datareq)
86 url_obj=urlopen(datareq)
94 data = self.
open_url(full_url).read()
96 data = sub(
"-inf",
'0', data)
97 data = sub(
"\s+inf",
'0', data)
98 data = sub(
"\s+nan",
'0', data)
99 data = sub(
'""(CMSSW.*?)""',
'"\\1"', data)
106 url=url.replace(
" ",
"%20")
115 for ntrials
in range(5):
123 print(
"Could not fetch %s. Retrying" %url)
126 for content_dict
in raw_folder[
"contents"]:
127 if "subdir" in content_dict:
128 form_folder[content_dict[
"subdir"]]={
"type":
'dir'}
129 elif "obj" in content_dict:
130 properties=content_dict[
"properties"]
131 obj_name=content_dict[
"obj"]
132 obj_type=properties[
"type"]
133 obj_kind=properties[
"kind"]
135 if "rootobj" in content_dict:
136 obj_as_string=content_dict[
"rootobj"]
137 form_folder[obj_name]={
'type':obj_type,
'obj_as_string':obj_as_string,
"kind":obj_kind}
145 def ls(self, url='', fetch_root=False):
152 url=
'%s?rootcontent=1'%url
153 form_folder=self.
ls_url(url)
162 if len_args!=1
and len_args!=3:
163 raise InvalidNumberOfArguments
165 dataset, run, folder = args
166 full_url=
'%s/data/json/archive/%s/%s/%s' % (self.
server, dataset, run, folder)
172 full_url=self.
DQMpwd[:self.DQMpwd.rfind(
"/")]
176 full_url=DQMcommunicator.base_dir
178 full_url=self.
DQMpwd+
"/"+folder
180 full_url=full_url.replace(
' ',
'%20')
191 A sample contains, among the other things, a data type, a dataset name 194 full_url=
'%s/data/json/samples?match=%s' % (self.
server, samples_string)
195 samples_dict=eval(self.
get_data(full_url))
196 return samples_dict[
"samples"]
203 for sample
in samples_list:
204 temp_datasets_list =
map(
lambda item:item[
"dataset"] ,sample[
'items'])
205 for temp_dataset
in temp_datasets_list:
206 if not temp_dataset
in datasets_list:
207 datasets_list.append(temp_dataset)
213 """Get the available cmssw versions for the relvals. 217 cmssw_versions_with_duplicates=map (
lambda x: x.split(
"/")[2],relvals_list)
218 return list(set(cmssw_versions_with_duplicates))
224 while(dataset_string.endswith(slash)
or dataset_string.beginswith(slash)):
225 dataset_string=dataset_string.strip(
"/")
229 map(
lambda sample: map (
lambda item: runlist.append(item[
'run']), sample[
'items']), samples_list)
245 set1.intersection_update(set2)
255 url = url.replace(
" ",
"%20")
257 for name,description
in self.
ls(url,
True).
items():
258 if "dir" not in description[
"type"]
and "ROOT" in description[
"kind"]:
259 objects.append(
literal2root(description[
"obj_as_string"],description[
"type"]))
269 url = url.replace(
" ",
"%20")
271 for name,description
in self.
ls(url,
True).
items():
272 if "dir" not in description[
"type"]
and "ROOT" in description[
"kind"]:
273 objects[name]=
literal2root(description[
"obj_as_string"],description[
"type"])
279 null_url = (len(url)==0)
284 url = url.replace(
" ",
"%20")
288 for name,description
in self.
ls(
"",
True).
items():
289 if "dir" in description[
"type"]:
292 elif "ROOT" in description[
"kind"]:
293 objects.append(
literal2root(description[
"obj_as_string"],description[
"type"]))
301 null_url = (len(url)==0)
303 if len(present_url)==0:
306 present_url+=
"_%s"%url
311 url = url.replace(
" ",
"%20")
315 for name,description
in self.
ls(
"",
False).
items():
316 if "dir" in description[
"type"]:
319 elif "ROOT" in description[
"kind"]:
320 objects_names.append(
"%s_%s"%(present_url,name))
328 null_url = (len(url)==0)
330 if len(present_url)==0:
333 present_url+=
"_%s"%url
338 url = url.replace(
" ",
"%20")
342 for name,description
in self.
ls(
"",
True).
items():
343 if "dir" in description[
"type"]:
346 elif "ROOT" in description[
"kind"]:
347 objects[
"%s_%s"%(present_url,name)]=
literal2root(description[
"obj_as_string"],description[
"type"])
355 """Structure used to identify a directory in the walked tree, 356 It carries the name and depth information. 365 compname2=dirid.compname
370 is_equal = self.
depth*depth2 <0
or self.
depth==depth2
371 if len(self.
mother)*len(dirid.mother)>0:
372 is_equal = is_equal
and self.
mother==dirid.mother
376 return "Directory %s at level %s" %(self.
name,self.
depth)
380 """ Fetch the content of the single "directory" in the dqm. 383 Thread.__init__(self)
393 """An interface to the DQM document db. It is threaded to compensate the 394 latency introduced by the finite response time of the server. 396 def __init__ (self,comm1,comm2,base1,base2,directory,depth=0,do_pngs=True,stat_test="KS",test_threshold=.5,black_list=[]):
397 Thread.__init__(self)
408 self.name+=
"_%s" %directory.name
412 this_dir=
DirID(self.directory.name,self.
depth)
414 print(
"Skipping %s since blacklisted!" %this_dir)
422 directory1=self.base1+
"/"+self.directory.mother_dir+
"/"+self.directory.name
423 directory2=self.
base2+
"/"+self.directory.mother_dir+
"/"+self.directory.name
426 for fetcher
in fetchers:
428 for fetcher
in fetchers:
431 contents1 = fetchers[0].contents
432 contents2 = fetchers[1].contents
433 set1= set(contents1.keys())
434 set2= set(contents2.keys())
437 self_directory_directories=self.directory.subdirs
438 self_directory_comparisons=self.directory.comparisons
439 contents_names=
list(set1.intersection(set2))
441 for name
in contents_names:
442 content = contents1[name]
443 if "dir" in content[
"type"]:
445 subdir=
Directory(name,
join(self.directory.mother_dir,self.directory.name))
449 walkers.append(dirwalker)
450 n_threads=activeCount()
454 elif content[
"kind"]==
"ROOT":
457 join(self.directory.mother_dir,self.directory.name),
459 literal2root(contents2[name][
"obj_as_string"],content[
"type"]),
462 self_directory_comparisons.append(comparison)
465 for walker
in walkers:
467 walker_directory=walker.directory
468 if not walker_directory.is_empty():
469 self_directory_directories.append(walker_directory)
474 """ Class acting as interface between the user and the harvested DQMRootFile. 475 It skips the directories created by the DQM infrastructure so to provide an 476 interface as similar as possible to a real direcory structure and to the 477 directory structure provided by the db interface. 485 print(
"Directory %s does not exist: skipping. Is this a custom rootfile?" %dqmdatadir)
490 is_null =
not directory
492 print(
"Directory %s does not exist!" %name, file=stderr)
495 def ls(self,directory_name=""):
498 if len(directory_name)==0:
501 directory=self.rootfilepwd.GetDirectory(directory_name)
502 if self.
__is_null(directory,directory_name):
505 for key
in directory.GetListOfKeys():
506 contents[key.GetName()]=key.GetClassName()
509 def cd(self,directory_name):
510 """Change the current TDirectoryFile. The familiar "-" and ".." directories 511 can be accessed as well. 513 if directory_name==
"-":
517 if directory_name==
"..":
521 mom=self.rootfilepwd.GetMotherDir()
524 if "Run " not in self.rootfilepwd.GetName():
525 self.rootfilepwd.Delete()
529 new_directory=self.rootfilepwd.GetDirectory(directory_name)
530 if not self.
__is_null(new_directory,directory_name):
535 """Get a TObject from the rootfile. 537 obj=self.rootfilepwd.Get(objname)
544 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=[]):
549 self.
stat_test=Statistical_Tests[stat_test](test_threshold)
554 self.directory.draw_success=draw_success
555 self.directory.do_pngs=do_pngs
564 def cd(self,directory_name, on_disk=False, regexp=False,):
566 if len(directory_name)!=0:
568 if not exists(directory_name):
569 makedirs(directory_name)
570 chdir(directory_name)
571 tmp = self.dqmrootfile2.ls().
keys()
575 self.dqmrootfile2.cd(next_dir)
576 tmp = self.dqmrootfile1.ls().
keys()
580 self.dqmrootfile1.cd(next_dir)
582 if len(directory_name)!=0:
584 if not exists(directory_name):
585 makedirs(directory_name)
586 chdir(directory_name)
587 self.dqmrootfile2.cd(directory_name)
588 self.dqmrootfile1.cd(directory_name)
590 def ls(self,directory_name=""):
591 """Return common objects to the 2 files. 593 contents1=self.dqmrootfile1.ls(directory_name)
594 contents2=self.dqmrootfile2.ls(directory_name)
600 keys = [key
for key
in contents2.keys()
if key
in contents1]
603 if contents1[key]!=contents2[key]:
604 diff_file1 = set(contents1.keys()) - set(contents2.keys())
605 diff_file2 = set(contents2.keys()) - set(contents1.keys())
606 for key1
in diff_file1:
607 obj_type = contents1[key1]
608 if obj_type ==
"TDirectoryFile":
612 if obj_type[:2]!=
"TH" and obj_type[:3]!=
"TPr" :
615 for key1
in diff_file2:
616 obj_type = contents2[key1]
617 if obj_type ==
"TDirectoryFile":
621 if obj_type[:2]!=
"TH" and obj_type[:3]!=
"TPr" :
624 contents[key]=contents1[key]
628 h1=self.dqmrootfile1.getObj(name)
629 h2=self.dqmrootfile2.getObj(name)
637 this_dir=DirID(dir_name,depth)
639 if this_dir
in self.black_list:
653 n_top_contents=len(contents)
658 for name,obj_type
in contents.items():
659 if obj_type==
"TDirectoryFile":
663 print(
"Studying directory %s, %s/%s" %(name,cont_counter,n_top_contents))
668 subdir=Directory(name)
669 subdir.draw_success=directory.draw_success
670 subdir.do_pngs=directory.do_pngs
671 self.__fill_single_dir(name,subdir,
join(mother_name,dir_name),depth)
672 if not subdir.is_empty():
674 print(
" ->Appending %s..." %name, end=
' ')
675 directory.subdirs.append(subdir)
680 if obj_type[:2]!=
"TH" and obj_type[:3]!=
"TPr" :
682 h1,h2=self.getObjs(name)
684 path =
join(mother_name,dir_name,name)
685 if path
in self.black_list_histos:
686 print(
" Skipping %s" %(path))
687 directory.comparisons.append(Comparison(name,
688 join(mother_name,dir_name),
690 deepcopy(self.stat_test),
691 draw_success=directory.draw_success,
692 do_pngs=directory.do_pngs, skip=
True))
694 directory.comparisons.append(Comparison(name,
695 join(mother_name,dir_name),
697 deepcopy(self.stat_test),
698 draw_success=directory.draw_success,
699 do_pngs=directory.do_pngs, skip=
False))
700 directory.filename1 = self.filename1
701 directory.filename2 = self.filename2
702 directory.different_histograms[
'file1'] = self.different_histograms[
'file1']
703 directory.different_histograms[
'file2'] = self.different_histograms[
'file2']
715 first_run_dir =
filter(
lambda k:
"Run " in k, self.
ls().
keys())[0]
717 print(
"\nRundir not there: Is this a generic rootfile?\n")
720 self.
run=
int(rundir.split(
" ")[1])
722 print(
"Setting run number to 0")
725 rundir=
"Run %s"%self.
run 728 self.
cd(rundir,
False,
True)
730 print(
"\nRundir not there: Is this a generic rootfile?\n")
735 n_left_threads=len(tcanvas_print_processes)
737 print(
"Waiting for %s threads to finish..." %n_left_threads)
738 for p
in tcanvas_print_processes:
745 Thread.__init__(self)
755 black_list_str=black_list_str.replace(
"__",
" ")
756 if len(black_list_str)>0:
757 for ele
in black_list_str.split(
","):
758 dirname,level=ele.split(
"@")
761 if "/" not in dirname:
762 dirid=
DirID(dirname,level)
764 mother,daughter=dirname.split(
"/")
765 dirid=
DirID(daughter,level,mother)
766 if not dirid
in black_list:
767 black_list.append(dirid)
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)
def literal2root(literal, rootType, debug=False)
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)
S & print(S &os, JobReport::InputFile const &f)
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="")
def cd(self, directory_name, on_disk=False, regexp=False)
def __is_null(self, directory, name)
def ls(self, directory_name="")
def ls(self, directory_name="")
def getObj(self, objname)
def cd(self, directory_name)
def get_root_objects_list_recursive(self, url="")
static std::string join(char **cmd)
def get_runs_list(self, dataset_string)
def __init__(self, server, is_private=False, ident="DQMToJson/1.0 python/%d.%d.%d"%version_info[:3])
def __init__(self, walker)
def get_root_objects_list(self, url="")
def get_RelVal_CMSSW_versions(self, query)
def get_samples(self, samples_string="*")
def __init__(self, rootfilename)
def string2blacklist(black_list_str)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run