12 from __future__
import print_function
13 from optparse
import OptionParser
19 from subprocess
import call,PIPE
20 from multiprocessing
import Pool
26 if "RELMON_SA" in os.environ:
27 import definitions
as definitions
28 from dqm_interfaces
import DirWalkerFile,string2blacklist,DirWalkerFile_thread_wrapper
29 from dirstructure
import Directory
30 from directories2html
import directory2html,make_summary_table
31 from utils
import ask_ok, unpickler, make_files_pairs
34 from Utilities.RelMon.dqm_interfaces
import DirWalkerFile,string2blacklist,DirWalkerFile_thread_wrapper
35 from Utilities.RelMon.dirstructure
import Directory
36 from Utilities.RelMon.directories2html
import directory2html,make_summary_table
37 from Utilities.RelMon.utils
import ask_ok, unpickler, make_files_pairs
43 namebase=os.path.basename(filename)
44 return namebase.split(
"__")[1]
47 namebase=os.path.basename(filename)
48 return namebase.split(
"__")[2]
51 namebase=os.path.basename(filename)
52 return namebase.split(
"__")[0].
split(
"_")[2]
59 skim = skim[:skim.rfind(
'-v')]
60 return "%s_%s"%(run,skim)
63 namebase = os.path.basename(filename)
64 return namebase.split(
"__")[2].
split(
"-")[1]
70 if len(ref_filenames)*len(test_filenames)==0:
71 print(
"Empty reference and test filenames lists!")
78 for ref, test
in zip(
map(os.path.basename,ref_filenames),
map(os.path.basename,test_filenames)):
85 print(
" ## sample 1: %s vs sample 2: %s"%(ref_sample, test_sample))
87 if ref_sample!=test_sample:
88 print(
"Files %s and %s do not seem to be relative to the same sample." %(ref, test))
92 if search(
"20[01]",ref_version)!=
None:
93 ref_sample+=ref_version.split(
"_")[-1]
94 samples.append(ref_sample)
97 ref_versions.append(ref_version)
98 test_versions.append(test_version)
101 ref_versions=
list(set(ref_versions))
102 test_versions=
list(set(test_versions))
109 cmssw_version1=ref_versions[0]
110 cmssw_version2=test_versions[0]
112 return samples,cmssw_version1,cmssw_version2
118 for name
in names_list:
119 if not name.endswith(
".root"):
120 print(
"File %s does not seem to be a rootfile. Please check.")
128 int_pattern=pattern.strip()
130 if int_pattern[0]==
'!':
131 int_pattern=int_pattern[1:]
134 condition =
search(int_pattern,target)!=
None 136 condition =
not condition
142 blacklist+=blist_piece
150 """Build a blacklist for each sample accordind to a set of rules 153 for sample
in samples:
154 blacklists[sample]=
"FED@1,AlcaBeamMonitor@1,HLT@1,AlCaReco@1" 158 blacklists[sample]+=
",AlCaEcalPi0@2" 159 if not search(
"2010+|2011+|2012+|2015+",ver1):
160 print(
"We are treating MC files for the HLT")
161 for pattern,blist
in definitions.hlt_mc_pattern_blist_pairs:
162 blacklists[sample]=
add_to_blacklist(blacklists[sample],pattern,sample,blist)
164 print(
"We are treating Data files for the HLT")
169 if not search(
"2010+|2011+|2012+",ver1):
170 print(
"We are treating MC files")
172 for pattern,blist
in definitions.mc_pattern_blist_pairs:
173 blacklists[sample]=
add_to_blacklist(blacklists[sample],pattern,sample,blist)
179 print(
"We are treating Data files:")
180 blacklists[sample]+=
",By__Lumi__Section@-1,AlCaReco@1" 181 for pattern,blist
in definitions.data_pattern_blist_pairs:
192 files_list = [s
for s
in os.listdir(directory)
if s.endswith(
".root")]
193 files_list_path=
map(
lambda s: os.path.join(directory,s), files_list)
195 return files_list_path
204 if len(files_list)==0:
205 print(
"Zero files found in directory %s!" %all_samples)
209 for name
in files_list:
211 if len(files_list)%2!=0:
212 print(
"The numbuer of file is not even... Trying to recover a catastrophe.")
222 for iname
in xrange(len(files_list)):
223 filename=files_list[iname]
225 ref_filenames.append(filename)
227 test_filenames.append(filename)
229 print(
"The guess would be the following:")
230 for ref,test
in zip(ref_filenames,test_filenames):
231 refbasedir=os.path.dirname(ref)
232 testbasedir=os.path.dirname(test)
233 dir_to_print=refbasedir
234 if refbasedir!=testbasedir:
235 dir_to_print=
"%s and %s" %(refbasedir,testbasedir)
236 print(
"* Directory: %s " %dir_to_print)
237 refname=os.path.basename(ref)
238 testname=os.path.basename(test)
239 print(
" o %s" %refname)
240 print(
" o %s" %testname)
248 return ref_filenames,test_filenames
255 ref_filenames=
map(
lambda s:s.strip(),ref_samples.split(
","))
256 test_filenames=
map(
lambda s:s.strip(),test_samples.split(
","))
258 if len(ref_filenames)!=len(test_filenames):
259 print(
"The numebr of reference and test files does not seem to be the same. Please check.")
264 return ref_filenames,test_filenames
269 return len([p
for p
in p_list
if p.returncode==
None])
274 """Creates shell command to compare two files using compare_using_files.py 275 script and calls it.""" 276 sample, ref_filename, test_filename, options = args
279 command =
" compare_using_files.py " 280 command+=
"%s %s " %(ref_filename,test_filename)
284 command+=
" -o %s_%s " %(sample, gt)
286 command+=
" --specify_run " 287 if options.stat_test
in [
"Bin2Bin",
"BinToBin"]:
288 options.test_threshold = 0.9999
289 command+=
" -t %s " %options.test_threshold
290 command+=
" -s %s " %options.stat_test
296 if options.hash_name:
297 command +=
" --hash_name " 299 if options.blacklist_file:
300 command +=
" --use_black_file " 302 if options.standalone:
303 command +=
" --standalone " 304 if len(blacklists[sample]) >0:
305 command+=
'-B %s ' %blacklists[sample]
306 print(
"\nExecuting -- %s" %command)
308 process=call([x
for x
in command.split(
" ")
if len(x)>0])
316 n_processes=
int(options.n_processes)
321 if len(options.all_samples)>0:
327 ref_filenames=
map(os.path.abspath,ref_filenames)
328 test_filenames=
map(os.path.abspath,test_filenames)
330 samples,cmssw_version1,cmssw_version2=
guess_params(ref_filenames,test_filenames)
333 print(
"No Samples found... Quitting")
339 original_dir=os.getcwd()
341 outdir=options.out_dir
343 print(
"Creating automatic outdir:", end=
' ')
344 outdir=
"%sVS%s" %(cmssw_version1,cmssw_version2)
346 if len(options.input_dir)==0:
347 print(
"Creating automatic indir:", end=
' ')
348 options.input_dir=outdir
349 print(options.input_dir)
351 if not os.path.exists(outdir):
356 n_comparisons=len(ref_filenames)
357 if n_comparisons < n_processes:
358 print(
"Less comparisons than possible processes: reducing n processes to", end=
' ')
359 n_processes=n_comparisons
376 if search(
"20[01]",cmssw_version1)!=
None:
377 skim_name=cmssw_version1.split(
"_")[-1]
379 running_subprocesses=[]
384 pool = Pool(n_processes)
385 args_iterable = [
list(args) + [options]
for args
in zip(samples, ref_filenames, test_filenames)]
386 pool.map(call_compare_using_files, args_iterable)
388 os.system(
"mv */*pkl .")
395 pkl_list=[x
for x
in os.listdir(
"./")
if ".pkl" in x]
396 running_subprocesses=[]
397 n_processes=
int(options.n_processes)
399 for pklfilename
in pkl_list:
400 command =
"compare_using_files.py " 404 command+=
"-P %s " %pklfilename
405 command+=
"-o %s " %pklfilename[:-4]
406 print(
"Executing %s" %command)
407 process=call([x
for x
in command.split(
" ")
if len(x)>0])
410 running_subprocesses.append(process)
411 if process_counter>=n_processes:
413 for p
in running_subprocesses:
420 def do_html(options, hashing_flag, standalone):
423 print(
"Preparing reports for the single files...")
427 aggregation_rules_twiki={}
430 print(
"Aggregating directories according to HLT rules")
431 aggregation_rules=definitions.aggr_pairs_dict[
'HLT']
432 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict[
'HLT']
434 aggregation_rules=definitions.aggr_pairs_dict[
'reco']
435 aggregation_rules_twiki=definitions.aggr_pairs_twiki_dict[
'reco']
436 table_html =
make_summary_table(options.input_dir,aggregation_rules,aggregation_rules_twiki, hashing_flag, standalone)
439 ofile = open(
"RelMonSummary.html",
"w")
440 ofile.write(table_html)
445 if __name__ ==
"__main__":
457 test_threshold=0.00001
462 parser = OptionParser(usage=
"usage: %prog [options]")
464 parser.add_option(
"-R",
"--ref_samples ",
468 help=
"The samples that act as reference (comma separated list)")
470 parser.add_option(
"-T",
"--test_samples",
473 default=test_samples,
474 help=
"The samples to be tested (comma separated list)")
476 parser.add_option(
"-a",
"--all_samples",
480 help=
"EXPERIMENTAL: Try to sort all samples selected (wildacrds) and organise a comparison")
482 parser.add_option(
"-o",
"--out_dir",
486 help=
"The outdir other than <Version1>VS<Version2>")
488 parser.add_option(
"-p",
"--do_pngs",
492 help=
"EXPERIMENTAL!!! Do the pngs of the comparison (takes 50%% of the total running time) \n(default is %s)" %
False)
494 parser.add_option(
"-r",
"--run ",
498 help=
"The run to be checked \n(default is %s)" %run)
500 parser.add_option(
"-t",
"--test_threshold",
502 dest=
"test_threshold",
503 default=test_threshold,
504 help=
"Threshold for the statistical test \n(default is %s)" %test_threshold)
506 parser.add_option(
"-s",
"--stat_test",
510 help=
"Statistical test (KS or Chi2) \n(default is %s)" %stat_test)
512 parser.add_option(
"-N",
"--numberOfProcesses",
516 help=
"Number of parallel processes to be run. Be Polite! \n(default is %s)" %n_processes)
518 parser.add_option(
"--HLT",
522 help=
"Analyse HLT histograms\n(default is %s)" %hlt)
524 parser.add_option(
"-i",
"--input_dir",
528 help=
"Input directory for html creation \n(default is %s)" %in_dir)
530 parser.add_option(
"--reports",
534 help=
"Do the reports for the pickles \n(default is %s)" %in_dir)
536 parser.add_option(
"--hash_name",
540 help=
"Set if you want to minimize & hash the output HTML files.")
542 parser.add_option(
"--use_black_file",
544 dest=
"blacklist_file",
546 help=
"Use a black list file of histograms located @ /RelMon/data")
548 parser.add_option(
"--standalone",
552 help=
"Define that using RelMon in standalone method. Makes CSS files accessible over HTTP")
554 (options, args) = parser.parse_args()
556 if len(options.test_samples)*len(options.ref_samples)+len(options.all_samples)==0
and len(options.input_dir)==0:
557 print(
"No samples given as input.")
561 if len(options.all_samples)>0
or (len(options.ref_samples)*len(options.test_samples)>0):
563 if len(options.input_dir)>0:
564 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