12 from __future__
import print_function
13 from builtins
import range
14 from optparse
import OptionParser
20 from subprocess
import call,PIPE
21 from multiprocessing
import Pool
27 if "RELMON_SA" in os.environ:
28 import definitions
as definitions
29 from dqm_interfaces
import DirWalkerFile,string2blacklist,DirWalkerFile_thread_wrapper
30 from dirstructure
import Directory
31 from directories2html
import directory2html,make_summary_table
32 from utils
import ask_ok, unpickler, make_files_pairs
35 from Utilities.RelMon.dqm_interfaces
import DirWalkerFile,string2blacklist,DirWalkerFile_thread_wrapper
36 from Utilities.RelMon.dirstructure
import Directory
37 from Utilities.RelMon.directories2html
import directory2html,make_summary_table
38 from Utilities.RelMon.utils
import ask_ok, unpickler, make_files_pairs
44 namebase=os.path.basename(filename)
45 return namebase.split(
"__")[1]
48 namebase=os.path.basename(filename)
49 return namebase.split(
"__")[2]
52 namebase=os.path.basename(filename)
53 return namebase.split(
"__")[0].
split(
"_")[2]
60 skim = skim[:skim.rfind(
'-v')]
61 return "%s_%s"%(run,skim)
64 namebase = os.path.basename(filename)
65 return namebase.split(
"__")[2].
split(
"-")[1]
71 if len(ref_filenames)*len(test_filenames)==0:
72 print(
"Empty reference and test filenames lists!")
79 for ref, test
in zip(
map(os.path.basename,ref_filenames),
map(os.path.basename,test_filenames)):
86 print(
" ## sample 1: %s vs sample 2: %s"%(ref_sample, test_sample))
88 if ref_sample!=test_sample:
89 print(
"Files %s and %s do not seem to be relative to the same sample." %(ref, test))
93 if search(
"20[01]",ref_version)!=
None:
94 ref_sample+=ref_version.split(
"_")[-1]
95 samples.append(ref_sample)
98 ref_versions.append(ref_version)
99 test_versions.append(test_version)
102 ref_versions=
list(set(ref_versions))
103 test_versions=
list(set(test_versions))
110 cmssw_version1=ref_versions[0]
111 cmssw_version2=test_versions[0]
113 return samples,cmssw_version1,cmssw_version2
119 for name
in names_list:
120 if not name.endswith(
".root"):
121 print(
"File %s does not seem to be a rootfile. Please check.")
129 int_pattern=pattern.strip()
131 if int_pattern[0]==
'!':
132 int_pattern=int_pattern[1:]
135 condition =
search(int_pattern,target)!=
None 137 condition =
not condition
143 blacklist+=blist_piece
151 """Build a blacklist for each sample accordind to a set of rules 154 for sample
in samples:
155 blacklists[sample]=
"FED@1,AlcaBeamMonitor@1,HLT@1,AlCaReco@1" 159 blacklists[sample]+=
",AlCaEcalPi0@2" 160 if not search(
"2010+|2011+|2012+|2015+",ver1):
161 print(
"We are treating MC files for the HLT")
162 for pattern,blist
in definitions.hlt_mc_pattern_blist_pairs:
163 blacklists[sample]=
add_to_blacklist(blacklists[sample],pattern,sample,blist)
165 print(
"We are treating Data files for the HLT")
170 if not search(
"2010+|2011+|2012+",ver1):
171 print(
"We are treating MC files")
173 for pattern,blist
in definitions.mc_pattern_blist_pairs:
174 blacklists[sample]=
add_to_blacklist(blacklists[sample],pattern,sample,blist)
180 print(
"We are treating Data files:")
181 blacklists[sample]+=
",By__Lumi__Section@-1,AlCaReco@1" 182 for pattern,blist
in definitions.data_pattern_blist_pairs:
193 files_list = [s
for s
in os.listdir(directory)
if s.endswith(
".root")]
194 files_list_path=
map(
lambda s: os.path.join(directory,s), files_list)
196 return files_list_path
205 if len(files_list)==0:
206 print(
"Zero files found in directory %s!" %all_samples)
210 for name
in files_list:
212 if len(files_list)%2!=0:
213 print(
"The numbuer of file is not even... Trying to recover a catastrophe.")
223 for iname
in range(len(files_list)):
224 filename=files_list[iname]
226 ref_filenames.append(filename)
228 test_filenames.append(filename)
230 print(
"The guess would be the following:")
231 for ref,test
in zip(ref_filenames,test_filenames):
232 refbasedir=os.path.dirname(ref)
233 testbasedir=os.path.dirname(test)
234 dir_to_print=refbasedir
235 if refbasedir!=testbasedir:
236 dir_to_print=
"%s and %s" %(refbasedir,testbasedir)
237 print(
"* Directory: %s " %dir_to_print)
238 refname=os.path.basename(ref)
239 testname=os.path.basename(test)
240 print(
" o %s" %refname)
241 print(
" o %s" %testname)
249 return ref_filenames,test_filenames
256 ref_filenames=
map(
lambda s:s.strip(),ref_samples.split(
","))
257 test_filenames=
map(
lambda s:s.strip(),test_samples.split(
","))
259 if len(ref_filenames)!=len(test_filenames):
260 print(
"The numebr of reference and test files does not seem to be the same. Please check.")
265 return ref_filenames,test_filenames
270 return len([p
for p
in p_list
if p.returncode==
None])
275 """Creates shell command to compare two files using compare_using_files.py 276 script and calls it.""" 277 sample, ref_filename, test_filename, options = args
280 command =
" compare_using_files.py " 281 command+=
"%s %s " %(ref_filename,test_filename)
285 command+=
" -o %s_%s " %(sample, gt)
287 command+=
" --specify_run " 288 if options.stat_test
in [
"Bin2Bin",
"BinToBin"]:
289 options.test_threshold = 0.9999
290 command+=
" -t %s " %options.test_threshold
291 command+=
" -s %s " %options.stat_test
297 if options.hash_name:
298 command +=
" --hash_name " 300 if options.blacklist_file:
301 command +=
" --use_black_file " 303 if options.standalone:
304 command +=
" --standalone " 305 if len(blacklists[sample]) >0:
306 command+=
'-B %s ' %blacklists[sample]
307 print(
"\nExecuting -- %s" %command)
309 process=call([x
for x
in command.split(
" ")
if len(x)>0])
317 n_processes=
int(options.n_processes)
322 if len(options.all_samples)>0:
328 ref_filenames=
map(os.path.abspath,ref_filenames)
329 test_filenames=
map(os.path.abspath,test_filenames)
331 samples,cmssw_version1,cmssw_version2=
guess_params(ref_filenames,test_filenames)
334 print(
"No Samples found... Quitting")
340 original_dir=os.getcwd()
342 outdir=options.out_dir
344 print(
"Creating automatic outdir:", end=
' ')
345 outdir=
"%sVS%s" %(cmssw_version1,cmssw_version2)
347 if len(options.input_dir)==0:
348 print(
"Creating automatic indir:", end=
' ')
349 options.input_dir=outdir
350 print(options.input_dir)
352 if not os.path.exists(outdir):
357 n_comparisons=len(ref_filenames)
358 if n_comparisons < n_processes:
359 print(
"Less comparisons than possible processes: reducing n processes to", end=
' ')
360 n_processes=n_comparisons
377 if search(
"20[01]",cmssw_version1)!=
None:
378 skim_name=cmssw_version1.split(
"_")[-1]
380 running_subprocesses=[]
385 pool = Pool(n_processes)
386 args_iterable = [
list(args) + [options]
for args
in zip(samples, ref_filenames, test_filenames)]
387 pool.map(call_compare_using_files, args_iterable)
389 os.system(
"mv */*pkl .")
396 pkl_list=[x
for x
in os.listdir(
"./")
if ".pkl" in x]
397 running_subprocesses=[]
398 n_processes=
int(options.n_processes)
400 for pklfilename
in pkl_list:
401 command =
"compare_using_files.py " 405 command+=
"-P %s " %pklfilename
406 command+=
"-o %s " %pklfilename[:-4]
407 print(
"Executing %s" %command)
408 process=call([x
for x
in command.split(
" ")
if len(x)>0])
411 running_subprocesses.append(process)
412 if process_counter>=n_processes:
414 for p
in running_subprocesses:
421 def do_html(options, hashing_flag, standalone):
424 print(
"Preparing reports for the single files...")
428 aggregation_rules_twiki={}
431 print(
"Aggregating directories according to HLT rules")
432 aggregation_rules=definitions.aggr_pairs_dict[
'HLT']
433 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict[
'HLT']
435 aggregation_rules=definitions.aggr_pairs_dict[
'reco']
436 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict[
'reco']
437 table_html =
make_summary_table(options.input_dir,aggregation_rules,aggregation_rules_twiki, hashing_flag, standalone)
440 ofile = open(
"RelMonSummary.html",
"w")
441 ofile.write(table_html)
446 if __name__ ==
"__main__":
458 test_threshold=0.00001
463 parser = OptionParser(usage=
"usage: %prog [options]")
465 parser.add_option(
"-R",
"--ref_samples ",
469 help=
"The samples that act as reference (comma separated list)")
471 parser.add_option(
"-T",
"--test_samples",
474 default=test_samples,
475 help=
"The samples to be tested (comma separated list)")
477 parser.add_option(
"-a",
"--all_samples",
481 help=
"EXPERIMENTAL: Try to sort all samples selected (wildacrds) and organise a comparison")
483 parser.add_option(
"-o",
"--out_dir",
487 help=
"The outdir other than <Version1>VS<Version2>")
489 parser.add_option(
"-p",
"--do_pngs",
493 help=
"EXPERIMENTAL!!! Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %
False)
495 parser.add_option(
"-r",
"--run ",
499 help=
"The run to be checked \n(default is %s)" %run)
501 parser.add_option(
"-t",
"--test_threshold",
503 dest=
"test_threshold",
504 default=test_threshold,
505 help=
"Threshold for the statistical test \n(default is %s)" %test_threshold)
507 parser.add_option(
"-s",
"--stat_test",
511 help=
"Statistical test (KS or Chi2) \n(default is %s)" %stat_test)
513 parser.add_option(
"-N",
"--numberOfProcesses",
517 help=
"Number of parallel processes to be run. Be Polite! \n(default is %s)" %n_processes)
519 parser.add_option(
"--HLT",
523 help=
"Analyse HLT histograms\n(default is %s)" %hlt)
525 parser.add_option(
"-i",
"--input_dir",
529 help=
"Input directory for html creation \n(default is %s)" %in_dir)
531 parser.add_option(
"--reports",
535 help=
"Do the reports for the pickles \n(default is %s)" %in_dir)
537 parser.add_option(
"--hash_name",
541 help=
"Set if you want to minimize & hash the output HTML files.")
543 parser.add_option(
"--use_black_file",
545 dest=
"blacklist_file",
547 help=
"Use a black list file of histograms located @ /RelMon/data")
549 parser.add_option(
"--standalone",
553 help=
"Define that using RelMon in standalone method. Makes CSS files accessible over HTTP")
555 (options, args) = parser.parse_args()
557 if len(options.test_samples)*len(options.ref_samples)+len(options.all_samples)==0
and len(options.input_dir)==0:
558 print(
"No samples given as input.")
562 if len(options.all_samples)>0
or (len(options.ref_samples)*len(options.test_samples)>0):
564 if len(options.input_dir)>0:
565 do_html(options, options.hash_name, options.standalone)
def guess_params(ref_filenames, test_filenames)
def name2globaltag(filename)
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
def name2sample(filename)
S & print(S &os, JobReport::InputFile const &f)
def get_roofiles_in_dir(directory)
def do_html(options, hashing_flag, standalone)
def make_summary_table(indir, aggregation_rules, aggregation_rules_twiki, hashing_flag, standalone_flag)
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def get_filenames_from_pool(all_samples)
def check_root_files(names_list)
def get_clean_fileanames(ref_samples, test_samples)
def call_compare_using_files(args)
def make_files_pairs(files, verbose=True)
def do_comparisons_threaded(options)
def name2version(filename)
def guess_blacklists(samples, ver1, ver2, hlt)
def add_to_blacklist(blacklist, pattern, target, blist_piece)
def name2runskim(filename)
def count_alive_processes(p_list)
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